]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Modify the styles of multiple selected dependencies. (refs #4554)
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 19 Nov 2013 10:58:55 +0000 (10:58 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 19 Nov 2013 10:58:55 +0000 (10:58 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28322 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java

diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java
new file mode 100644 (file)
index 0000000..247d1d5
--- /dev/null
@@ -0,0 +1,277 @@
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.properties;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Group;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.util.ObjectUtils;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.elements.connections.DependencyNode;\r
+import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.datastructures.Triple;\r
+\r
+/**\r
+ * Tab for multiple dependencies.\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class ArrayDependencyTab  extends LabelPropertyTabContributor {\r
+\r
+    Button none, plus, minus, other, inside, outside;\r
+    TrackedText polarityText, polarityLocationText;\r
+    \r
+    @Override\r
+    public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+        Composite composite = new Composite(body, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(composite);\r
+        \r
+        /* Add a dummy button at the begin to suck in the nonsense selection events that\r
+         * the first radio button in the group of ALL the radio buttons receives when no\r
+         * radio is selected and then one is selected in other group than where the first \r
+         * radio button lies.  \r
+         */\r
+        Group hiddenDefaultbuttonGroup = new Group(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().exclude(true).applyTo(hiddenDefaultbuttonGroup);\r
+        GridLayoutFactory.fillDefaults().applyTo(hiddenDefaultbuttonGroup);\r
+        new Button(hiddenDefaultbuttonGroup, support, SWT.RADIO);\r
+        \r
+        Group polarityGroup = new Group(composite, SWT.NONE);\r
+        polarityGroup.setText("Polarity");\r
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityGroup);\r
+        GridLayoutFactory.fillDefaults().numColumns(5).applyTo(polarityGroup);\r
+        \r
+        none = new Button(polarityGroup, support, SWT.RADIO);\r
+        none.setText("None");\r
+        none.setSelectionFactory(new PolarityRadioSelectionFactory(""));\r
+        none.addSelectionListener(new PolaritySelectionListener(context, ""));\r
+        \r
+        plus = new Button(polarityGroup, support, SWT.RADIO);\r
+        plus.setText("+");\r
+        plus.setSelectionFactory(new PolarityRadioSelectionFactory("+"));\r
+        plus.addSelectionListener(new PolaritySelectionListener(context, "+"));\r
+        \r
+        minus = new Button(polarityGroup, support, SWT.RADIO);\r
+        minus.setText("-");\r
+        minus.setSelectionFactory(new PolarityRadioSelectionFactory("-"));\r
+        minus.addSelectionListener(new PolaritySelectionListener(context, "-"));\r
+        \r
+        other = new Button(polarityGroup, support, SWT.RADIO);\r
+        other.setText("other");\r
+        other.setSelectionFactory(new OtherPolaritySelectionFactory(new String[] {null, "+", "-", ""}));\r
+        \r
+        polarityText = new TrackedText(polarityGroup, support, SWT.BORDER);\r
+        polarityText.setTextFactory(new OtherPolarityStringPropertyFactory());\r
+        polarityText.addModifyListener(new OtherPolarityStringPropertyModifier());\r
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityText.getWidget());\r
+        \r
+        Group locationGroup = new Group(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().applyTo(locationGroup);\r
+        GridLayoutFactory.fillDefaults().applyTo(locationGroup);\r
+        locationGroup.setText("Location");\r
+        \r
+        inside = new Button(locationGroup, support, SWT.RADIO);\r
+        inside.setText("Inside");\r
+        inside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.INSIDE));\r
+        inside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.INSIDE));\r
+        \r
+        outside = new Button(locationGroup, support, SWT.RADIO);\r
+        outside.setText("Outside");\r
+        outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE));\r
+        outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE));\r
+    }\r
+    \r
+    class OtherPolarityStringPropertyFactory extends ReadFactoryImpl<ArrayList<Resource>, String> {\r
+\r
+           private final String propertyURI;\r
+\r
+           public OtherPolarityStringPropertyFactory() {\r
+               this.propertyURI = SysdynResource.URIs.DependencyConnection_polarity;\r
+           }\r
+\r
+           @SuppressWarnings("unchecked")\r
+               @Override\r
+           public Object getIdentity(Object inputContents) {\r
+               return new Triple<ArrayList<Resource>, String, Object>((ArrayList<Resource>) inputContents, propertyURI, getClass());\r
+           }\r
+\r
+           @Override\r
+           public String perform(ReadGraph graph, ArrayList<Resource> resources) throws DatabaseException {\r
+               String value = graph.getPossibleRelatedValue(resources.get(0), graph.getResource(propertyURI));;\r
+               if (value == null)\r
+                       return "";\r
+               for (Resource r : resources) {\r
+                       String s = graph.getPossibleRelatedValue(r, graph.getResource(propertyURI));\r
+                       if (!value.equals(s))\r
+                               return "";\r
+               }\r
+               return value;\r
+           }           \r
+    }\r
+    \r
+    class OtherPolarityStringPropertyModifier extends TextModifyListenerImpl<ArrayList<Resource>> {\r
+\r
+       final private String propertyURI;\r
+       \r
+       public OtherPolarityStringPropertyModifier() {\r
+               this.propertyURI = SysdynResource.URIs.DependencyConnection_polarity;\r
+       }\r
+\r
+       @Override\r
+       public void applyText(WriteGraph graph, ArrayList<Resource> resources, String text) throws DatabaseException {\r
+               for (Resource r : resources)\r
+                       graph.claimLiteral(r, graph.getResource(propertyURI), text, Bindings.STRING);\r
+       }\r
+       \r
+    }\r
+\r
+    class PolarityLocationSelectionListener extends SelectionListenerImpl<ArrayList<Resource>> {\r
+        private String location;\r
+\r
+        public PolarityLocationSelectionListener(ISessionContext context, String location) {\r
+            super(context);\r
+            this.location = location;\r
+        }\r
+        \r
+        @Override\r
+        public void apply(WriteGraph graph, ArrayList<Resource> connectionElements) throws DatabaseException {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            for (Resource r : connectionElements)\r
+               graph.claimLiteral(r, sr.DependencyConnection_polarityLocation, location);\r
+        }\r
+        \r
+    }\r
+    \r
+    class PolarityLocationRadioSelectionFactory extends ReadFactoryImpl<ArrayList<Resource>, Boolean> {\r
+        private String location;\r
+\r
+        public PolarityLocationRadioSelectionFactory(String location) {\r
+            this.location = location;\r
+        }\r
+\r
+        @Override\r
+        public Object getIdentity(Object inputContents) {\r
+            return new Triple<Object, Object, Class<?>>(inputContents, location, getClass());\r
+        }\r
+\r
+        @Override\r
+        public Boolean perform(ReadGraph graph, ArrayList<Resource> dependencyConnections) throws DatabaseException {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            for (Resource r : dependencyConnections) {\r
+               String location = graph.getPossibleRelatedValue(r, sr.DependencyConnection_polarityLocation, Bindings.STRING);  \r
+               if (DependencyNode.OUTSIDE.equals(this.location)) {\r
+                       if (ObjectUtils.objectEquals(this.location, location))\r
+                               continue;\r
+               } else {\r
+                       if (location == null) {\r
+                           continue;\r
+                       } else {\r
+                           if (ObjectUtils.objectEquals(this.location, location))\r
+                               continue;\r
+                       }\r
+               }\r
+               return false;\r
+            }\r
+            return true;\r
+        }\r
+    }\r
+    \r
+    class PolaritySelectionListener extends SelectionListenerImpl<ArrayList<Resource>> {\r
+        private String polarity;\r
+\r
+        public PolaritySelectionListener(ISessionContext context, String polarity) {\r
+            super(context);\r
+            this.polarity = polarity;\r
+        }\r
+        \r
+        @Override\r
+        public void apply(WriteGraph graph, ArrayList<Resource> connectionElements) throws DatabaseException {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            for (Resource r : connectionElements)\r
+               graph.claimLiteral(r, sr.DependencyConnection_polarity, polarity.trim());\r
+        }\r
+        \r
+    }\r
+    \r
+    class PolarityRadioSelectionFactory extends ReadFactoryImpl<ArrayList<Resource>, Boolean> {\r
+        private String polarity;\r
+\r
+        public PolarityRadioSelectionFactory(String polarity) {\r
+            this.polarity = polarity;\r
+        }\r
+\r
+        @Override\r
+        public Object getIdentity(Object inputContents) {\r
+            return new Triple<Object, Object, Class<?>>(inputContents, polarity, getClass());\r
+        }\r
+\r
+        @Override\r
+        public Boolean perform(ReadGraph graph, ArrayList<Resource> dependencyConnections) throws DatabaseException {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            for (Resource r : dependencyConnections) {\r
+               String polarity = graph.getPossibleRelatedValue(r, sr.DependencyConnection_polarity, Bindings.STRING);     \r
+               if (polarity == null && this.polarity.equals(""))\r
+                       continue;\r
+               if (ObjectUtils.objectEquals(polarity, this.polarity))\r
+                       continue;\r
+               return false;\r
+            }\r
+            return true;\r
+        }\r
+    }\r
+    \r
+    class OtherPolaritySelectionFactory extends ReadFactoryImpl<ArrayList<Resource>, Boolean> {\r
+\r
+        String[] limits;\r
+        \r
+        public OtherPolaritySelectionFactory(String[] limits) {\r
+            this.limits = limits;\r
+        }\r
+        \r
+        @Override\r
+        public Object getIdentity(Object inputContents) {\r
+            return new Pair<Object, Class<?>>(inputContents, getClass());\r
+        }\r
+\r
+        @Override\r
+        public Boolean perform(ReadGraph graph, ArrayList<Resource> dependencyConnections) throws DatabaseException {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            for (Resource r : dependencyConnections) {\r
+               String polarity = graph.getPossibleRelatedValue(r, sr.DependencyConnection_polarity, Bindings.STRING);\r
+                for(String s : limits) {\r
+                    if(ObjectUtils.objectEquals(polarity, s))\r
+                        return false;\r
+                }\r
+            }\r
+            return true;\r
+        }\r
+    }\r
+\r
+}\r
index 3b516bbbdead660fe3684b107a42f516b68604c1..20adbc434ed8dd4379db7ad7b46a56e8f22d7b58 100644 (file)
@@ -75,7 +75,8 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
         try {\r
             // Many elements \r
             if (selection instanceof ArrayList<?> && ((ArrayList<?>) selection).size() > 1) {\r
-                List<Resource> variables = new ArrayList<Resource>();\r
+               List<Resource> variables = new ArrayList<Resource>();\r
+               List<Resource> dependencies = new ArrayList<Resource>();\r
                 Resource model = null;\r
                 for(Object o : (ArrayList<?>)selection) {\r
                     Resource r = AdaptionUtils.adaptToSingle(o, Resource.class);\r
@@ -84,21 +85,42 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                     Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
                     if (component != null) {\r
                         r = component;\r
-                    } \r
-                    if(r != null && backend.isInstanceOf(r, sr.Variable)) {\r
+                    } else {\r
+                       // Try connection\r
+                        Resource connection = backend.getPossibleObject(r, mr.DiagramConnectionToConnection);\r
+                        if(connection != null)\r
+                            r = connection;\r
+                    }\r
+                    \r
+                    if(r != null) {\r
                         if(model == null)\r
                             model = backend.getSingleObject(r, Layer0.getInstance(backend).PartOf);\r
-                        if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf)))\r
-                            variables.add(r);\r
+                        if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf))) {\r
+                               if (backend.isInstanceOf(r, sr.Variable)) {\r
+                                       variables.add(r);\r
+                               } else if (backend.isInstanceOf(r, sr.Dependency)) {\r
+                                       Resource diaConnection = backend.getPossibleObject(r, ModelingResources.getInstance(backend).ConnectionToDiagramConnection);\r
+                                       dependencies.add(diaConnection);\r
+                               }\r
+                        }\r
                     }\r
                 }\r
-\r
-                tabs.add(new ComparableTabContributor(\r
-                        new ArrayIndexesTab(),\r
-                        1,\r
-                        variables,\r
-                        "Indexes"));\r
-\r
+                \r
+                if (!variables.isEmpty())\r
+                       // Do we have at least one variable\r
+                       tabs.add(new ComparableTabContributor(\r
+                               new ArrayIndexesTab(),\r
+                               1,\r
+                               variables,\r
+                               "Indexes"));\r
+                else if (!dependencies.isEmpty()) {\r
+                    // Dependencies only\r
+                       tabs.add(new ComparableTabContributor(\r
+                            new ArrayDependencyTab(),\r
+                            1,\r
+                            dependencies,\r
+                            "Dependency Properties"));\r
+                }\r
                 return tabs;\r
             }\r
 \r