]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Checkbox to dependencies to show or hide the arrow head (refs #4619).
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 7 Jan 2014 06:26:14 +0000 (06:26 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 7 Jan 2014 06:26:14 +0000 (06:26 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28591 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyEdgeClass.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrowHeadWidget.java [new file with mode: 0644]

index c232a28f6253e314aac5c7dcd21086ccda985812..9e2864947eb09db68b92b09fca9cf5630fb97f7f 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index 8ccf63a5d0abab16cfcdb419b7ea2f855d6c19ce..ce5012f75ba21f0997ba5e4ad99f431219701cef 100644 (file)
@@ -581,6 +581,8 @@ SYSDYN.DependencyConnection <T DIA.Connection <T DIA.FontProvider <T DIA.ColorPr
     @L0.singleProperty SYSDYN.Dependency.angle
     >-- SYSDYN.DependencyConnection.polarity --> L0.String <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.DependencyConnection.polarityLocation --> L0.String <R L0.HasProperty : L0.FunctionalRelation    
+    >-- SYSDYN.DependencyConnection.hideArrow --> SYSDYN.DependencyConnection <R L0.HasProperty : L0.Tag
+        @L0.symmetric
     >-- SYSDYN.DependencyConnection.delayMark --> SYSDYN.DependencyConnection <R L0.HasProperty : L0.Tag
         @L0.symmetric
     @L0.assert SYSDYN.Dependency.angle 0.1
index c1ce13f6d067e42465e1e84e685d6f1d091af249..c0505d6e8a7d3ef8ab92f18b15597d5e301f00a1 100644 (file)
@@ -344,6 +344,7 @@ public class SysdynResource {
     public final Resource Dependency;\r
     public final Resource DependencyConnection;\r
     public final Resource DependencyConnection_delayMark;\r
+    public final Resource DependencyConnection_hideArrow;\r
     public final Resource DependencyConnection_polarity;\r
     public final Resource DependencyConnection_polarityLocation;\r
     public final Resource DependencyConnection_polarityLocation_Inverse;\r
@@ -1099,6 +1100,7 @@ public class SysdynResource {
         public static final String Dependency = "http://www.simantics.org/Sysdyn-1.1/Dependency";\r
         public static final String DependencyConnection = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection";\r
         public static final String DependencyConnection_delayMark = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/delayMark";\r
+        public static final String DependencyConnection_hideArrow = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/hideArrow";\r
         public static final String DependencyConnection_polarity = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/polarity";\r
         public static final String DependencyConnection_polarityLocation = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/polarityLocation";\r
         public static final String DependencyConnection_polarityLocation_Inverse = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/polarityLocation/Inverse";\r
@@ -1864,6 +1866,7 @@ public class SysdynResource {
         Dependency = getResourceOrNull(graph, URIs.Dependency);\r
         DependencyConnection = getResourceOrNull(graph, URIs.DependencyConnection);\r
         DependencyConnection_delayMark = getResourceOrNull(graph, URIs.DependencyConnection_delayMark);\r
+        DependencyConnection_hideArrow = getResourceOrNull(graph, URIs.DependencyConnection_hideArrow);\r
         DependencyConnection_polarity = getResourceOrNull(graph, URIs.DependencyConnection_polarity);\r
         DependencyConnection_polarityLocation = getResourceOrNull(graph, URIs.DependencyConnection_polarityLocation);\r
         DependencyConnection_polarityLocation_Inverse = getResourceOrNull(graph, URIs.DependencyConnection_polarityLocation_Inverse);\r
index 2a78ac2be23afc88cdbc65a6f9c77f05d86ac577..668509e8bd6b787b7b7172269fbcfae11de43ba5 100644 (file)
@@ -131,6 +131,7 @@ public class DependencyEdgeClass {
             Pair<?, ?> polarityPair =  (Pair<?, ?>)properties.get("polarity");\r
             Pair<?, ?> polarityLocationPair =  (Pair<?, ?>)properties.get("polarityLocation");\r
             boolean delayMark = properties.containsKey("delayMark");\r
+            boolean arrowHead = !properties.containsKey("hideArrow");\r
             \r
             String location;\r
             if(polarityLocationPair == null)\r
@@ -139,7 +140,7 @@ public class DependencyEdgeClass {
                 location = (String) polarityLocationPair.second;\r
 \r
             String text = polarityPair != null ? (String)  polarityPair.second : "";\r
-            node.init(text, location, delayMark, font, color, 0, 0, 0.235);\r
+            node.init(text, location, delayMark, arrowHead, font, color, 0, 0, 0.235);\r
             \r
             update(e);\r
         }\r
index ec84bbdeb3e5e930e19bb7f9b35d08ba1764e020..3b2bea29d13d6980545197206976f43b4ac8cf6c 100644 (file)
@@ -66,13 +66,14 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
     private double angle = 0.1;\r
     private String side;\r
     private boolean delayMark = false;\r
+    private boolean arrowHead = true;\r
     private transient Triple<Arc2D, Path2D, Path2D> shapes = new Triple<Arc2D, Path2D, Path2D>(new Arc2D.Double(), new Path2D.Double(), new Path2D.Double());\r
 \r
     transient public boolean hover = false;\r
     private boolean dragging = false;\r
 \r
     private transient PropertyChangeListener fieldListener = null;\r
-\r
+       \r
     @Override\r
     public void init() {\r
         super.init();\r
@@ -91,10 +92,11 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
      * @param y Text initial location y\r
      * @param scale Scale\r
      */\r
-    public void init(String text, String side, boolean delayMark, Font font, Color color, double x, double y, double scale) {\r
+    public void init(String text, String side, boolean delayMark, boolean arrowHead, Font font, Color color, double x, double y, double scale) {\r
         super.init(text, font, color, x, y, scale);\r
         this.side = side;\r
         this.delayMark = delayMark;\r
+        this.arrowHead = arrowHead;\r
         setHorizontalAlignment((byte) Alignment.CENTER.ordinal());\r
         setVerticalAlignment((byte) Alignment.CENTER.ordinal());\r
     }\r
@@ -196,7 +198,7 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
             if(color != null) g.setColor(color);\r
             g.setStroke(stroke);\r
             g.draw(shapes.first);\r
-            g.fill(shapes.second);\r
+            if (arrowHead) g.fill(shapes.second);\r
             if (delayMark) g.draw(shapes.third);\r
         } else if (hover){\r
             g.setColor(Color.LIGHT_GRAY);\r
@@ -206,13 +208,13 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
             if(color != null) g.setColor(color);\r
             g.setStroke(stroke);\r
             g.draw(shapes.first);\r
-            g.fill(shapes.second);\r
+            if (arrowHead) g.fill(shapes.second);\r
             if (delayMark) g.draw(shapes.third);\r
         } else {\r
             if(color != null) g.setColor(color);\r
             if(stroke != null) g.setStroke(stroke);\r
             g.draw(shapes.first);\r
-            g.fill(shapes.second);\r
+            if (arrowHead) g.fill(shapes.second);\r
             if (delayMark) g.draw(shapes.third);\r
         }\r
 \r
index b31a23ea8093dd331b9344157aa0b9f426410e3b..95b66dce288cab8cb629575494680ac080e68ae1 100644 (file)
@@ -34,6 +34,7 @@ import org.simantics.db.exception.DatabaseException;
 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.sysdyn.ui.properties.widgets.ArrowHeadWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.DelayMarkWidget;\r
 import org.simantics.utils.datastructures.Pair;\r
 import org.simantics.utils.datastructures.Triple;\r
@@ -48,6 +49,7 @@ public class ArrayDependencyTab  extends LabelPropertyTabContributor {
     Button none, plus, minus, other, inside, outside;\r
     TrackedText polarityText, polarityLocationText;\r
     private DelayMarkWidget delayMark;\r
+    private ArrowHeadWidget arrowhead;\r
     \r
     @Override\r
     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
@@ -109,7 +111,13 @@ public class ArrayDependencyTab  extends LabelPropertyTabContributor {
         outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE));\r
         outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE));\r
 \r
-        delayMark = new DelayMarkWidget(composite, support, SWT.NULL);\r
+        Composite misc = new Composite(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(misc);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).applyTo(misc);\r
+        \r
+        arrowhead = new ArrowHeadWidget(misc, support, SWT.NULL);\r
+        GridDataFactory.fillDefaults().applyTo(arrowhead.getWidget());\r
+        delayMark = new DelayMarkWidget(misc, support, SWT.NULL);\r
         GridDataFactory.fillDefaults().applyTo(delayMark.getWidget());\r
     }\r
     \r
index 659180bb09f6688561b50b6e2bbbe45832f5b7a4..615c7ad4e36c4417c2afb567138c021cfc780553 100644 (file)
@@ -33,6 +33,7 @@ import org.simantics.db.exception.DatabaseException;
 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.sysdyn.ui.properties.widgets.ArrowHeadWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.DelayMarkWidget;\r
 import org.simantics.utils.datastructures.Pair;\r
 import org.simantics.utils.datastructures.Triple;\r
@@ -42,6 +43,7 @@ public class DependencyTab  extends LabelPropertyTabContributor {
     Button none, plus, minus, other, inside, outside;\r
     TrackedText polarityText, polarityLocationText;\r
     private DelayMarkWidget delayMark;\r
+    private ArrowHeadWidget arrowhead;\r
     \r
     @Override\r
     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
@@ -93,7 +95,13 @@ public class DependencyTab  extends LabelPropertyTabContributor {
         outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE));\r
         outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE));\r
         \r
-        delayMark = new DelayMarkWidget(composite, support, SWT.NULL);\r
+        Composite misc = new Composite(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(misc);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).applyTo(misc);\r
+        \r
+        arrowhead = new ArrowHeadWidget(misc, support, SWT.NULL);\r
+        GridDataFactory.fillDefaults().applyTo(arrowhead.getWidget());\r
+        delayMark = new DelayMarkWidget(misc, support, SWT.NULL);\r
         GridDataFactory.fillDefaults().applyTo(delayMark.getWidget());\r
     }\r
     \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrowHeadWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrowHeadWidget.java
new file mode 100644 (file)
index 0000000..7698135
--- /dev/null
@@ -0,0 +1,169 @@
+/*******************************************************************************\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.widgets;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+/**\r
+ * Widget for showing arrow head in dependencies.\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class ArrowHeadWidget implements Widget{\r
+\r
+    List<Resource> variables = null; \r
+    org.simantics.browsing.ui.swt.widgets.Button arrowheadButton;\r
+    \r
+    public ArrowHeadWidget(Composite parent, WidgetSupport support, int style) {\r
+        support.register(this);\r
+        arrowheadButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+        arrowheadButton.setText("Arrowhead");\r
+    }\r
+\r
+    @SuppressWarnings({ "rawtypes", "unchecked" })\r
+       @Override\r
+    public void setInput(ISessionContext context, Object input) {\r
+        if(input instanceof ISelection) {\r
+            ISelection selection = (ISelection)input;\r
+            if(selection instanceof IStructuredSelection) {\r
+               List<Resource> resources = ISelectionUtils.filterSelection(selection, Resource.class);\r
+                if(resources != null && !resources.isEmpty()) {\r
+                    variables = resources;\r
+                } else {\r
+                       List<ArrayList> resourceLists = ISelectionUtils.filterSelection(selection, ArrayList.class);\r
+                       variables = resourceLists.get(0);\r
+                }\r
+            }\r
+        }\r
+\r
+        if(variables == null) return;\r
+        \r
+        try {\r
+            context.getSession().syncRequest(new ReadRequest() {\r
+                \r
+                @Override\r
+                public void run(ReadGraph graph) throws DatabaseException {\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    \r
+                    // Determine if there are arrowheads in some of the variables.\r
+                    boolean hasArrowheads = false, hasNotArrowheads = false;\r
+                    for (Resource variable : variables) {\r
+                       if (!graph.hasStatement(variable, sr.DependencyConnection_hideArrow)) {\r
+                               hasArrowheads = true;\r
+                       } else {\r
+                               hasNotArrowheads = true;\r
+                       }\r
+                    }\r
+                    \r
+                    // If some have arrowheads but others don't, the check box is grayed.\r
+                    final Button button = getWidget();\r
+                    final boolean arrowhead = hasArrowheads;\r
+                    final boolean mixedArrowheads = hasArrowheads && hasNotArrowheads;\r
+                       button.getDisplay().asyncExec(new Runnable() {\r
+                               \r
+                        @Override\r
+                        public void run() {\r
+                            if(button.isDisposed()) return;\r
+                            button.setSelection(arrowhead);\r
+                            button.setGrayed(mixedArrowheads);\r
+                        }\r
+                    });\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+        \r
+        // Multiple selections\r
+        arrowheadButton.addSelectionListener(new SelectionListenerImpl<ArrayList<Resource>>(context) {\r
+\r
+            @Override\r
+            public void apply(WriteGraph graph, ArrayList<Resource> inputs) throws DatabaseException {\r
+                if (inputs == null)\r
+                       return;\r
+                \r
+                final SysdynResource sr =  SysdynResource.getInstance(graph);\r
+                boolean nextState = true; // The next state of the checkbox\r
+                for (Resource variable : variables) {\r
+                       if (!graph.hasStatement(variable, sr.DependencyConnection_hideArrow)) {\r
+                               nextState = false; // The next state is true iff all have hideArrow.\r
+                               break;\r
+                       }\r
+                }\r
+\r
+               try {\r
+                       if (nextState) {\r
+                                               for (Resource input : inputs) {\r
+                                                       graph.deny(input, sr.DependencyConnection_hideArrow);\r
+                                               }\r
+                                       } else {\r
+                                               for (Resource input : inputs) {\r
+                                                       graph.claim(input, SysdynResource.getInstance(graph).DependencyConnection_hideArrow, null, input);\r
+                                               }\r
+                                       }\r
+               } catch (DatabaseException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
+                \r
+               // Get the button out of the grayed state.\r
+               final Button button = getWidget();\r
+                button.getDisplay().asyncExec(new Runnable() {\r
+                    \r
+                    @Override\r
+                    public void run() {\r
+                       button.setGrayed(false);\r
+                    }\r
+                });\r
+            }\r
+        });\r
+        \r
+        // One selection\r
+        arrowheadButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+            @Override\r
+            public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+                if (input == null)\r
+                       return;\r
+                \r
+                final SysdynResource sr =  SysdynResource.getInstance(graph);\r
+                if(graph.hasStatement(input, sr.DependencyConnection_hideArrow)) {\r
+                           graph.deny(input, sr.DependencyConnection_hideArrow);\r
+                       } else {\r
+                           graph.claim(input, SysdynResource.getInstance(graph).DependencyConnection_hideArrow, null, input);\r
+                       }\r
+            }  \r
+        });\r
+    }\r
+    \r
+    public Button getWidget() {\r
+        return arrowheadButton.getWidget();\r
+    }\r
+\r
+}\r