]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Valve horizontal and vertical orientation and text locations
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 1 Nov 2011 14:15:28 +0000 (14:15 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 1 Nov 2011 14:15:28 +0000 (14:15 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23151 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/elements2/SysdynElementHints.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveTextLocation.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveOrientationGroup.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java [new file with mode: 0644]

index 1d3d856bc069ef1d6a7a6853e5e7435103a9011e..3863b84b4a9f1d2979d965ee940157ce643d8136 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index e35c30e6acaef898e4c9d216ceb278db41bfd4c5..35980897d5d91fadd66a3fbe4e84f85a64c89fb7 100644 (file)
@@ -400,15 +400,26 @@ SYSDYN.Valve <T STR.Component
     @MOD.connection SYSDYN.IsHeadOf
     
 SYSDYN.HasValveOrientation <R L0.HasProperty : L0.FunctionalRelation
-    L0.HasRange L0.Boolean    
+    L0.HasRange SYSDYN.Orientation    
     
 SYSDYN.Orientation <T L0.Entity    
 SYSDYN.Horizontal <T SYSDYN.Orientation
 SYSDYN.Vertical <T SYSDYN.Orientation   
 
+SYSDYN.HasTextLocation <R L0.HasProperty : L0.FunctionalRelation
+    L0.HasRange SYSDYN.Location    
+    
+SYSDYN.Location <T L0.Entity
+SYSDYN.Left <T SYSDYN.Location
+SYSDYN.Right <T SYSDYN.Location
+SYSDYN.Top <T SYSDYN.Location
+SYSDYN.Bottom <T SYSDYN.Location
+SYSDYN.Center <T SYSDYN.Location
+
 SYSDYN.ValveSymbol <T DIA.FontProvider <T DIA.ColorProvider
     @MOD.defSymbol "Valve" SYSDYN.Valve
     @L0.assert SYSDYN.Orientation SYSDYN.Horizontal
+    @L0.optionalProperty SYSDYN.HasTextLocation
     L0.IsDependencyOf BasicSymbols
     STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext 
         @L0.orderedSet 
index 674f69a0b4bf3e6510e6b0b4b73850ce9a4b1a81..2260b23f8842d12ae7a3f9f296ff947bb85e03c5 100644 (file)
@@ -18,6 +18,7 @@ public class SysdynResource {
     public final Resource AvailableSharedFunctionLibraries;\r
     public final Resource AvailableVariableIndexes;\r
     public final Resource BasicExperiment;\r
+    public final Resource Bottom;\r
     public final Resource Browser;\r
     public final Resource Built$in_Functions;\r
     public final Resource Built$in_Functions_Vensim_Functions;\r
@@ -44,6 +45,7 @@ public class SysdynResource {
     public final Resource Built$in_Functions_interpolateFull;\r
     public final Resource Built$in_Functions_xidz;\r
     public final Resource Built$in_Functions_zidz;\r
+    public final Resource Center;\r
     public final Resource Cloud;\r
     public final Resource CloudSymbol;\r
     public final Resource Configuration;\r
@@ -130,6 +132,8 @@ public class SysdynResource {
     public final Resource HasStopTime_Inverse;\r
     public final Resource HasTail;\r
     public final Resource HasTailTerminal;\r
+    public final Resource HasTextLocation;\r
+    public final Resource HasTextLocation_Inverse;\r
     public final Resource HasTolerance;\r
     public final Resource HasTolerance_Inverse;\r
     public final Resource HasUnit;\r
@@ -151,6 +155,8 @@ public class SysdynResource {
     public final Resource IsTailOf;\r
     public final Resource IsTailOfTerminal;\r
     public final Resource IssueStyle;\r
+    public final Resource Left;\r
+    public final Resource Location;\r
     public final Resource LookupExpression;\r
     public final Resource ModelBrowser;\r
     public final Resource Module;\r
@@ -190,6 +196,7 @@ public class SysdynResource {
     public final Resource ReplacingEnumeration;\r
     public final Resource ReplacingEnumeration_Inverse;\r
     public final Resource Result;\r
+    public final Resource Right;\r
     public final Resource SelectedSharedFunctionLibraries;\r
     public final Resource SharedFunctionOntology;\r
     public final Resource SharedModuleOntolofgy;\r
@@ -215,6 +222,7 @@ public class SysdynResource {
     public final Resource SysdynModuleLibrary;\r
     public final Resource SysdynOperationBrowser;\r
     public final Resource SysdynTerminal;\r
+    public final Resource Top;\r
     public final Resource UsedVariableIndexes;\r
     public final Resource Validations;\r
     public final Resource Validations_Dependencies;\r
@@ -249,6 +257,7 @@ public class SysdynResource {
         public static final String AvailableSharedFunctionLibraries = "http://www.simantics.org/Sysdyn-1.1/AvailableSharedFunctionLibraries";\r
         public static final String AvailableVariableIndexes = "http://www.simantics.org/Sysdyn-1.1/AvailableVariableIndexes";\r
         public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.1/BasicExperiment";\r
+        public static final String Bottom = "http://www.simantics.org/Sysdyn-1.1/Bottom";\r
         public static final String Browser = "http://www.simantics.org/Sysdyn-1.1/Browser";\r
         public static final String Built$in_Functions = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions";\r
         public static final String Built$in_Functions_Vensim_Functions = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions";\r
@@ -275,6 +284,7 @@ public class SysdynResource {
         public static final String Built$in_Functions_interpolateFull = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/interpolateFull";\r
         public static final String Built$in_Functions_xidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/xidz";\r
         public static final String Built$in_Functions_zidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/zidz";\r
+        public static final String Center = "http://www.simantics.org/Sysdyn-1.1/Center";\r
         public static final String Cloud = "http://www.simantics.org/Sysdyn-1.1/Cloud";\r
         public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.1/CloudSymbol";\r
         public static final String Configuration = "http://www.simantics.org/Sysdyn-1.1/Configuration";\r
@@ -361,6 +371,8 @@ public class SysdynResource {
         public static final String HasStopTime_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasStopTime/Inverse";\r
         public static final String HasTail = "http://www.simantics.org/Sysdyn-1.1/HasTail";\r
         public static final String HasTailTerminal = "http://www.simantics.org/Sysdyn-1.1/HasTailTerminal";\r
+        public static final String HasTextLocation = "http://www.simantics.org/Sysdyn-1.1/HasTextLocation";\r
+        public static final String HasTextLocation_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasTextLocation/Inverse";\r
         public static final String HasTolerance = "http://www.simantics.org/Sysdyn-1.1/HasTolerance";\r
         public static final String HasTolerance_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasTolerance/Inverse";\r
         public static final String HasUnit = "http://www.simantics.org/Sysdyn-1.1/HasUnit";\r
@@ -382,6 +394,8 @@ public class SysdynResource {
         public static final String IsTailOf = "http://www.simantics.org/Sysdyn-1.1/IsTailOf";\r
         public static final String IsTailOfTerminal = "http://www.simantics.org/Sysdyn-1.1/IsTailOfTerminal";\r
         public static final String IssueStyle = "http://www.simantics.org/Sysdyn-1.1/IssueStyle";\r
+        public static final String Left = "http://www.simantics.org/Sysdyn-1.1/Left";\r
+        public static final String Location = "http://www.simantics.org/Sysdyn-1.1/Location";\r
         public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.1/LookupExpression";\r
         public static final String ModelBrowser = "http://www.simantics.org/Sysdyn-1.1/ModelBrowser";\r
         public static final String Module = "http://www.simantics.org/Sysdyn-1.1/Module";\r
@@ -421,6 +435,7 @@ public class SysdynResource {
         public static final String ReplacingEnumeration = "http://www.simantics.org/Sysdyn-1.1/ReplacingEnumeration";\r
         public static final String ReplacingEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.1/ReplacingEnumeration/Inverse";\r
         public static final String Result = "http://www.simantics.org/Sysdyn-1.1/Result";\r
+        public static final String Right = "http://www.simantics.org/Sysdyn-1.1/Right";\r
         public static final String SelectedSharedFunctionLibraries = "http://www.simantics.org/Sysdyn-1.1/SelectedSharedFunctionLibraries";\r
         public static final String SharedFunctionOntology = "http://www.simantics.org/Sysdyn-1.1/SharedFunctionOntology";\r
         public static final String SharedModuleOntolofgy = "http://www.simantics.org/Sysdyn-1.1/SharedModuleOntolofgy";\r
@@ -446,6 +461,7 @@ public class SysdynResource {
         public static final String SysdynModuleLibrary = "http://www.simantics.org/Sysdyn-1.1/SysdynModuleLibrary";\r
         public static final String SysdynOperationBrowser = "http://www.simantics.org/Sysdyn-1.1/SysdynOperationBrowser";\r
         public static final String SysdynTerminal = "http://www.simantics.org/Sysdyn-1.1/SysdynTerminal";\r
+        public static final String Top = "http://www.simantics.org/Sysdyn-1.1/Top";\r
         public static final String UsedVariableIndexes = "http://www.simantics.org/Sysdyn-1.1/UsedVariableIndexes";\r
         public static final String Validations = "http://www.simantics.org/Sysdyn-1.1/Validations";\r
         public static final String Validations_Dependencies = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies";\r
@@ -490,6 +506,7 @@ public class SysdynResource {
         AvailableSharedFunctionLibraries = getResourceOrNull(graph, URIs.AvailableSharedFunctionLibraries);\r
         AvailableVariableIndexes = getResourceOrNull(graph, URIs.AvailableVariableIndexes);\r
         BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
+        Bottom = getResourceOrNull(graph, URIs.Bottom);\r
         Browser = getResourceOrNull(graph, URIs.Browser);\r
         Built$in_Functions = getResourceOrNull(graph, URIs.Built$in_Functions);\r
         Built$in_Functions_Vensim_Functions = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions);\r
@@ -516,6 +533,7 @@ public class SysdynResource {
         Built$in_Functions_interpolateFull = getResourceOrNull(graph, URIs.Built$in_Functions_interpolateFull);\r
         Built$in_Functions_xidz = getResourceOrNull(graph, URIs.Built$in_Functions_xidz);\r
         Built$in_Functions_zidz = getResourceOrNull(graph, URIs.Built$in_Functions_zidz);\r
+        Center = getResourceOrNull(graph, URIs.Center);\r
         Cloud = getResourceOrNull(graph, URIs.Cloud);\r
         CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol);\r
         Configuration = getResourceOrNull(graph, URIs.Configuration);\r
@@ -602,6 +620,8 @@ public class SysdynResource {
         HasStopTime_Inverse = getResourceOrNull(graph, URIs.HasStopTime_Inverse);\r
         HasTail = getResourceOrNull(graph, URIs.HasTail);\r
         HasTailTerminal = getResourceOrNull(graph, URIs.HasTailTerminal);\r
+        HasTextLocation = getResourceOrNull(graph, URIs.HasTextLocation);\r
+        HasTextLocation_Inverse = getResourceOrNull(graph, URIs.HasTextLocation_Inverse);\r
         HasTolerance = getResourceOrNull(graph, URIs.HasTolerance);\r
         HasTolerance_Inverse = getResourceOrNull(graph, URIs.HasTolerance_Inverse);\r
         HasUnit = getResourceOrNull(graph, URIs.HasUnit);\r
@@ -623,6 +643,8 @@ public class SysdynResource {
         IsTailOf = getResourceOrNull(graph, URIs.IsTailOf);\r
         IsTailOfTerminal = getResourceOrNull(graph, URIs.IsTailOfTerminal);\r
         IssueStyle = getResourceOrNull(graph, URIs.IssueStyle);\r
+        Left = getResourceOrNull(graph, URIs.Left);\r
+        Location = getResourceOrNull(graph, URIs.Location);\r
         LookupExpression = getResourceOrNull(graph, URIs.LookupExpression);\r
         ModelBrowser = getResourceOrNull(graph, URIs.ModelBrowser);\r
         Module = getResourceOrNull(graph, URIs.Module);\r
@@ -662,6 +684,7 @@ public class SysdynResource {
         ReplacingEnumeration = getResourceOrNull(graph, URIs.ReplacingEnumeration);\r
         ReplacingEnumeration_Inverse = getResourceOrNull(graph, URIs.ReplacingEnumeration_Inverse);\r
         Result = getResourceOrNull(graph, URIs.Result);\r
+        Right = getResourceOrNull(graph, URIs.Right);\r
         SelectedSharedFunctionLibraries = getResourceOrNull(graph, URIs.SelectedSharedFunctionLibraries);\r
         SharedFunctionOntology = getResourceOrNull(graph, URIs.SharedFunctionOntology);\r
         SharedModuleOntolofgy = getResourceOrNull(graph, URIs.SharedModuleOntolofgy);\r
@@ -687,6 +710,7 @@ public class SysdynResource {
         SysdynModuleLibrary = getResourceOrNull(graph, URIs.SysdynModuleLibrary);\r
         SysdynOperationBrowser = getResourceOrNull(graph, URIs.SysdynOperationBrowser);\r
         SysdynTerminal = getResourceOrNull(graph, URIs.SysdynTerminal);\r
+        Top = getResourceOrNull(graph, URIs.Top);\r
         UsedVariableIndexes = getResourceOrNull(graph, URIs.UsedVariableIndexes);\r
         Validations = getResourceOrNull(graph, URIs.Validations);\r
         Validations_Dependencies = getResourceOrNull(graph, URIs.Validations_Dependencies);\r
index bbe07794619504bf43ebca9f4e979657ee053c53..8873c23fadc0b51bf4dfabe1e9bb57529ead4edb 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
 public class SysdynElementHints {\r
 \r
     public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE");\r
-    public static final Key KEY_ORIENTATION = new KeyOf(String.class, "ORIENTATION");    \r
+    public static final Key KEY_ORIENTATION = new KeyOf(String.class, "ORIENTATION");   \r
+    public static final Key KEY_LOCATION = new KeyOf(String.class, "LOCATION");       \r
     \r
 }\r
index 1837728caaee7002a05089c7944f4b50c3dceebc..1a80e6825f15ba4ebb531cfdfd3e0a7d14781f23 100644 (file)
@@ -47,5 +47,21 @@ public class SysdynElementUtils {
         else\r
             return null;\r
     }\r
+    \r
+    public static void setValveTextLocation(IElement e, String location)\r
+    {\r
+        ValveTextLocation v = e.getElementClass().getSingleItem(ValveTextLocation.class);\r
+        if(v != null)\r
+            v.setTextLocation(e, location);\r
+    }\r
+\r
+    public static String getValveTextLocation(IElement e)\r
+    {\r
+        ValveTextLocation v = e.getElementClass().getSingleItem(ValveTextLocation.class);\r
+        if(v != null)\r
+            return v.getTextLocation(e);\r
+        else\r
+            return null;\r
+    }\r
 \r
 }\r
index c154c1dc8ed393ad4ed72e6cb570181561355f7c..28314a22668c0ca4d0e7428bf9632d0be1d43062 100644 (file)
@@ -83,6 +83,7 @@ public class ValveFactory extends SysdynElementFactory {
                 ValveSceneGraph.INSTANCE,\r
                 BoundsOutline.INSTANCE,\r
                 Orientation.INSTANCE,\r
+                ValveTextLocation.INSTANCE,\r
                 new WholeElementTerminals(terminals)\r
         ).setId(ValveFactory.class.getSimpleName());\r
     }\r
@@ -102,7 +103,20 @@ public class ValveFactory extends SysdynElementFactory {
             orientationText = "Horizontal";\r
         } \r
         SysdynElementUtils.setOrientation(e, orientationText);\r
-            \r
+\r
+        Resource location = graph.getPossibleObject(element, sr.HasTextLocation);\r
+        String locationText;\r
+        if(location == null || sr.Bottom.equals(location)) {\r
+            locationText = "Bottom";\r
+        } else if(sr.Top.equals(location)) {\r
+            locationText = "Top";\r
+        } else if(sr.Left.equals(location)) {\r
+            locationText = "Left";\r
+        } else {\r
+            locationText = "Right";\r
+        }\r
+        SysdynElementUtils.setValveTextLocation(e, locationText);    \r
+        \r
     }\r
     \r
     /**\r
@@ -161,12 +175,30 @@ public class ValveFactory extends SysdynElementFactory {
             if(at != null) {\r
                 node.setTransform(at);\r
             \r
-                // Use affinetransform to move the name of the valve below the valve symbol\r
                 TextNode name = (TextNode) e.getHint(SG_NODE);\r
                 if(name != null) {\r
+                    \r
                     AffineTransform at2 = (AffineTransform) at.clone();\r
-                    at2.translate(0, VALVE_SIZE + 3.0);\r
+                    Alignment alignment = null;\r
+                    \r
+                    String location = e.getHint(SysdynElementHints.KEY_LOCATION);\r
+                    if(location != null) {\r
+                        if(location.equals("Bottom")) {\r
+                            at2.translate(0, VALVE_SIZE + 3.0);\r
+                        } else if(location.equals("Top")) {\r
+                            at2.translate(0, -VALVE_SIZE - 1);\r
+                        } else if(location.equals("Left")) {\r
+                            at2.translate(0, 0);\r
+                            alignment = Alignment.TRAILING;\r
+                        } else {\r
+                            at2.translate(VALVE_SIZE + 1, 0);\r
+                            alignment = Alignment.LEADING;\r
+                        }\r
+                    }\r
+                    \r
                     name.setTransform(at2);\r
+                    if(alignment != null)\r
+                        name.setHorizontalAlignment((byte) alignment.ordinal());\r
                 }\r
             }\r
 \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveTextLocation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveTextLocation.java
new file mode 100644 (file)
index 0000000..8361eec
--- /dev/null
@@ -0,0 +1,35 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.elements2;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.ElementHandler;\r
+\r
+public class ValveTextLocation implements ElementHandler {\r
+\r
+    private static final long serialVersionUID = 7123851901569461658L;\r
+    \r
+    public static final ValveTextLocation INSTANCE = new ValveTextLocation();\r
+    \r
+    public String getTextLocation(IElement e) {\r
+        return e.getHint(SysdynElementHints.KEY_LOCATION);\r
+    }\r
+\r
+    \r
+    public void setTextLocation(IElement e, String location) {\r
+        if (location != null)\r
+            e.setHint(SysdynElementHints.KEY_LOCATION, location);\r
+        else\r
+            e.removeHint(SysdynElementHints.KEY_LOCATION);\r
+    }\r
+\r
+}\r
index 17bcb250998dd656e98c1228777dc5b8137ae4f4..e7e57bcd257d8d6e0a52c85ec527c6d0ec8eaf5b 100644 (file)
@@ -27,6 +27,7 @@ import org.simantics.db.management.ISessionContext;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.properties.widgets.ValveOrientationGroup;\r
+import org.simantics.sysdyn.ui.properties.widgets.ValveTextLocationGroup;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 \r
@@ -82,8 +83,11 @@ public class VariableInformationTab extends LabelPropertyTabContributor {
         rangeStep.setInputValidator(new DoubleValidator());\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeStep.getWidget());\r
         \r
-        \r
-        new ValveOrientationGroup(composite, context, support, SWT.NONE);\r
+        Composite valveComposite = new Composite(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().applyTo(valveComposite);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).margins(3,3).applyTo(valveComposite);\r
+        new ValveOrientationGroup(valveComposite, context, support, SWT.NONE);\r
+        new ValveTextLocationGroup(valveComposite, context, support, SWT.NONE);\r
 \r
     }\r
 \r
index 436e8ba8dec1cc5f6fd5b90ca9798ecc46f86cc3..9b3ff468b45ac9711b7232647c7a7f66b4a40d4d 100644 (file)
@@ -29,7 +29,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.utils.datastructures.Triple;\r
+import org.simantics.utils.datastructures.Quad;\r
 \r
 public class ValveOrientationGroup extends WidgetImpl {\r
 \r
@@ -46,12 +46,12 @@ public class ValveOrientationGroup extends WidgetImpl {
         \r
         horizontal = new Button(group, support, SWT.RADIO);\r
         horizontal.setText("Horizontal");\r
-        horizontal.setSelectionFactory(new OrientationSelectionFactory(SysdynResource.URIs.Horizontal, true));\r
+        horizontal.setSelectionFactory(new OrientationSelectionFactory(horizontal, SysdynResource.URIs.Horizontal, true));\r
         horizontal.addSelectionListener(new OrientationSelectionListener(context, SysdynResource.URIs.Horizontal));\r
         \r
         vertical = new Button(group, support, SWT.RADIO);\r
         vertical.setText("Vertical");\r
-        vertical.setSelectionFactory(new OrientationSelectionFactory(SysdynResource.URIs.Vertical));\r
+        vertical.setSelectionFactory(new OrientationSelectionFactory(vertical, SysdynResource.URIs.Vertical));\r
         vertical.addSelectionListener(new OrientationSelectionListener(context, SysdynResource.URIs.Vertical));\r
     }\r
 \r
@@ -70,18 +70,20 @@ public class ValveOrientationGroup extends WidgetImpl {
         \r
         boolean defaultSelected;\r
         String uri;\r
+        Button button;\r
         \r
-        public OrientationSelectionFactory(String uri) {\r
-            this(uri, false);\r
+        public OrientationSelectionFactory(Button button, String uri) {\r
+            this(button, uri, false);\r
         }\r
 \r
-        public OrientationSelectionFactory(String uri, boolean defaultSelected) {\r
+        public OrientationSelectionFactory(Button button, String uri, boolean defaultSelected) {\r
             this.uri = uri;\r
             this.defaultSelected = defaultSelected;\r
+            this.button = button;\r
         }\r
         \r
         public Object getIdentity(Object inputContents) {\r
-            return new Triple<Object, Object, Class<?>>(uri, defaultSelected, getClass());\r
+            return new Quad<Object, Object, Object, Class<?>>(button, uri, defaultSelected, getClass());\r
         }\r
 \r
         @Override\r
@@ -129,6 +131,12 @@ public class ValveOrientationGroup extends WidgetImpl {
             if(graph.hasStatement(symbol, sr.HasValveOrientation))\r
                 graph.deny(symbol, sr.HasValveOrientation);\r
             graph.claim(symbol, sr.HasValveOrientation, graph.getResource(uri));\r
+            \r
+            if(graph.hasStatement(symbol, sr.HasTextLocation))\r
+                graph.deny(symbol, sr.HasTextLocation);\r
+            if(sr.Vertical.equals(graph.getResource(uri)))\r
+                graph.claim(symbol, sr.HasTextLocation, sr.Right);\r
+                \r
         }\r
         \r
     }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java
new file mode 100644 (file)
index 0000000..04252f0
--- /dev/null
@@ -0,0 +1,150 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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 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.Control;\r
+import org.eclipse.swt.widgets.Group;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.WidgetImpl;\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.WidgetSupport;\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.modeling.ModelingResources;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.datastructures.Quad;\r
+\r
+public class ValveTextLocationGroup extends WidgetImpl {\r
+\r
+    Group group;\r
+    Button top, bottom, left, right;\r
+    \r
+    public ValveTextLocationGroup(Composite parent, ISessionContext context, WidgetSupport support, int style) {\r
+        super(support);\r
+        \r
+        group = new Group(parent, SWT.NONE);\r
+        group.setText("Text location");\r
+        GridDataFactory.fillDefaults().applyTo(group);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(group);\r
+        \r
+        top = new Button(group, support, SWT.RADIO);\r
+        top.setText("Top");\r
+        top.setSelectionFactory(new LocationSelectionFactory(top, SysdynResource.URIs.Top));\r
+        top.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Top));\r
+        \r
+        bottom = new Button(group, support, SWT.RADIO);\r
+        bottom.setText("Bottom");\r
+        bottom.setSelectionFactory(new LocationSelectionFactory(bottom, SysdynResource.URIs.Bottom, true));\r
+        bottom.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Bottom));\r
+        \r
+        left = new Button(group, support, SWT.RADIO);\r
+        left.setText("Left");\r
+        left.setSelectionFactory(new LocationSelectionFactory(left, SysdynResource.URIs.Left));\r
+        left.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Left));\r
+        \r
+        right = new Button(group, support, SWT.RADIO);\r
+        right.setText("Right");\r
+        right.setSelectionFactory(new LocationSelectionFactory(right, SysdynResource.URIs.Right));\r
+        right.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Right));\r
+        \r
+    }\r
+\r
+    @Override\r
+    public void setInput(ISessionContext context, Object input) {\r
+        // TODO Auto-generated method stub\r
+        \r
+    }\r
+\r
+    @Override\r
+    public Control getControl() {\r
+        return this.group;\r
+    }\r
+    \r
+    \r
+    private class LocationSelectionFactory extends ReadFactoryImpl<Resource, Boolean> {\r
+        \r
+        boolean defaultSelected;\r
+        String uri;\r
+        Button button;\r
+        \r
+        public LocationSelectionFactory(Button button, String uri) {\r
+            this(button, uri, false);\r
+        }\r
+\r
+        public LocationSelectionFactory(Button button, String uri, boolean defaultSelected) {\r
+            this.uri = uri;\r
+            this.defaultSelected = defaultSelected;\r
+            this.button = button;\r
+        }\r
+        \r
+        public Object getIdentity(Object inputContents) {\r
+            return new Quad<Object, Object, Object, Class<?>>(button, uri, defaultSelected, getClass());\r
+        }\r
+\r
+        @Override\r
+        public Boolean perform(ReadGraph graph, Resource valve) throws DatabaseException {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            ModelingResources mr = ModelingResources.getInstance(graph);\r
+            if(!graph.isInstanceOf(valve, sr.Valve))\r
+                return Boolean.FALSE;\r
+            \r
+            Resource symbol = graph.getPossibleObject(valve, mr.ComponentToElement);\r
+            if(symbol == null)\r
+                return Boolean.FALSE;\r
+            \r
+            Resource location = graph.getPossibleObject(symbol, sr.HasTextLocation);\r
+            \r
+            if(location == null)\r
+                return defaultSelected;\r
+            \r
+            return location.equals(graph.getResource(uri));\r
+        }\r
+        \r
+    }\r
+    \r
+    \r
+    private class LocationSelectionListener extends SelectionListenerImpl<Resource> {\r
+        \r
+        String uri;\r
+        \r
+        public LocationSelectionListener(ISessionContext context, String uri) {\r
+            super(context);\r
+            this.uri = uri;\r
+        }\r
+\r
+        @Override\r
+        public void apply(WriteGraph graph, Resource valve) throws DatabaseException {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            ModelingResources mr = ModelingResources.getInstance(graph);\r
+            if(!graph.isInstanceOf(valve, sr.Valve))\r
+                return;\r
+            \r
+            Resource symbol = graph.getPossibleObject(valve, mr.ComponentToElement);\r
+            if(symbol == null)\r
+                return;\r
+            \r
+            if(graph.hasStatement(symbol, sr.HasTextLocation))\r
+                graph.deny(symbol, sr.HasTextLocation);\r
+            graph.claim(symbol, sr.HasTextLocation, graph.getResource(uri));\r
+        }\r
+        \r
+    }\r
+\r
+}\r