]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Better support for enumerations: Enumerations in module can be created and replaced
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 16 Feb 2011 13:59:11 +0000 (13:59 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 16 Feb 2011 13:59:11 +0000 (13:59 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19792 ac1ea38d-2e2b-0410-8846-a27921b304fc

30 files changed:
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/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/BrowserSelection.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynBrowser.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleType.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ColumnKeys.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ComboBoxModifier.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/Keys.java [deleted file]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/RedeclarationNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerationsLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java
org.simantics.sysdyn/META-INF/MANIFEST.MF
org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java

index 5c8dceda7e934ccaf1577f4a1043883b8cd54274..b2891c38be54e85b220531ec00ef71f718216505 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index 0193a7a516b224a57b4aed2f6933d0654b5d8646..04b8db89960459c81c5021e235ab016269ff56d9 100644 (file)
@@ -128,6 +128,7 @@ SYSDYN.Input <T SYSDYN.Variable
 SYSDYN.Enumeration <T SYSDYN.Variable
     @L0.singleProperty SYSDYN.HasEnumerationIndexes
     @L0.assert L0.HasType "type"
+    @L0.assert SYSDYN.IsReplaceable false
     
 
 //#####################################################################
@@ -137,6 +138,7 @@ SYSDYN.Enumeration <T SYSDYN.Variable
 SYSDYN.Module <T STR.Component
     // TODO [STR.IsDefinedBy all Configuration]
     @L0.singleProperty L0.HasLabel
+    @L0.property SYSDYN.HasRedeclaration 
 
 SYSDYN.ModuleSymbol <T DIA.FontProvider <T DIA.ColorProvider
     @MOD.defSymbol "ModuleSymbol" SYSDYN.Module
@@ -255,7 +257,7 @@ SYSDYN.HasActiveExpression <R L0.HasProperty : L0.FunctionalRelation
 
 SYSDYN.HasArrayIndexes <R L0.DependsOn : L0.FunctionalRelation
     L0.HasDomain SYSDYN.Variable
-    L0.HasRange SYSDYN.Enumeration
+    L0.HasRange SYSDYN.ArrayIndexes
     
 SYSDYN.ArrayIndexes <T L0.OrderedSet <R L0.HasNext
 
@@ -266,12 +268,36 @@ SYSDYN.HasEnumerationIndexes <R L0.DependsOn : L0.FunctionalRelation
 SYSDYN.EnumerationIndexes <T L0.OrderedSet <R L0.HasNext
 
 SYSDYN.EnumerationIndex <T L0.Entity
-    L0.singleProperty L0.HasName
+    @L0.singleProperty L0.HasName
     @L0.assert SYSDYN.ShowEnumerationIndexInCharts true
     
 SYSDYN.ShowEnumerationIndexInCharts <R L0.HasProperty : L0.FunctionalRelation
     L0.HasRange L0.Boolean
     
+//#####################################################################
+// Redeclarations
+//#####################################################################
+    
+SYSDYN.IsReplaceable <R L0.HasProperty : L0.FunctionalRelation
+    L0.HasDomain SYSDYN.Enumeration
+    L0.HasRange L0.Boolean
+    
+SYSDYN.ReplacedEnumeration <R L0.HasProperty : L0.FunctionalRelation
+    L0.HasDomain SYSDYN.Redeclaration
+    L0.HasRange SYSDYN.Enumeration
+
+SYSDYN.ReplacingEnumeration  <R L0.HasProperty : L0.FunctionalRelation
+    L0.HasDomain SYSDYN.Redeclaration
+    L0.HasRange SYSDYN.Enumeration
+    
+SYSDYN.Redeclaration <T L0.Entity
+    @L0.singleProperty SYSDYN.ReplacedEnumeration
+    @L0.singleProperty SYSDYN.ReplacingEnumeration
+    
+SYSDYN.HasRedeclaration <R L0.IsComposedOf
+    L0.HasRange SYSDYN.Redeclaration
+
+    
 //#####################################################################
 // Experiments
 //#####################################################################
index 32292aead56c141df1d47f42a809034bdc696d03..789b2e70ed89ffa3a8581cbef0a085060612630b 100644 (file)
@@ -182,6 +182,8 @@ public class SysdynResource {
     public final Resource HasRangeStart_Inverse;\r
     public final Resource HasRangeStep;\r
     public final Resource HasRangeStep_Inverse;\r
+    public final Resource HasRedeclaration;\r
+    public final Resource HasRedeclaration_Inverse;\r
     public final Resource HasResult;\r
     public final Resource HasResultFile;\r
     public final Resource HasResultFile_Inverse;\r
@@ -206,6 +208,8 @@ public class SysdynResource {
     public final Resource IsHeadOf;\r
     public final Resource IsHeadOfTerminal;\r
     public final Resource IsOutput;\r
+    public final Resource IsReplaceable;\r
+    public final Resource IsReplaceable_Inverse;\r
     public final Resource IsTailOf;\r
     public final Resource IsTailOfTerminal;\r
     public final Resource LookupExpression;\r
@@ -213,7 +217,12 @@ public class SysdynResource {
     public final Resource ModuleSymbol;\r
     public final Resource NormalExpression;\r
     public final Resource ParameterExpression;\r
+    public final Resource Redeclaration;\r
     public final Resource RefersTo;\r
+    public final Resource ReplacedEnumeration;\r
+    public final Resource ReplacedEnumeration_Inverse;\r
+    public final Resource ReplacingEnumeration;\r
+    public final Resource ReplacingEnumeration_Inverse;\r
     public final Resource Result;\r
     public final Resource ShowEnumerationIndexInCharts;\r
     public final Resource ShowEnumerationIndexInCharts_Inverse;\r
@@ -410,6 +419,8 @@ public class SysdynResource {
         public static final String HasRangeStart_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasRangeStart/Inverse";\r
         public static final String HasRangeStep = "http://www.simantics.org/Sysdyn-1.0/HasRangeStep";\r
         public static final String HasRangeStep_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasRangeStep/Inverse";\r
+        public static final String HasRedeclaration = "http://www.simantics.org/Sysdyn-1.0/HasRedeclaration";\r
+        public static final String HasRedeclaration_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasRedeclaration/Inverse";\r
         public static final String HasResult = "http://www.simantics.org/Sysdyn-1.0/HasResult";\r
         public static final String HasResultFile = "http://www.simantics.org/Sysdyn-1.0/HasResultFile";\r
         public static final String HasResultFile_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasResultFile/Inverse";\r
@@ -434,6 +445,8 @@ public class SysdynResource {
         public static final String IsHeadOf = "http://www.simantics.org/Sysdyn-1.0/IsHeadOf";\r
         public static final String IsHeadOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsHeadOfTerminal";\r
         public static final String IsOutput = "http://www.simantics.org/Sysdyn-1.0/IsOutput";\r
+        public static final String IsReplaceable = "http://www.simantics.org/Sysdyn-1.0/IsReplaceable";\r
+        public static final String IsReplaceable_Inverse = "http://www.simantics.org/Sysdyn-1.0/IsReplaceable/Inverse";\r
         public static final String IsTailOf = "http://www.simantics.org/Sysdyn-1.0/IsTailOf";\r
         public static final String IsTailOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsTailOfTerminal";\r
         public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.0/LookupExpression";\r
@@ -441,7 +454,12 @@ public class SysdynResource {
         public static final String ModuleSymbol = "http://www.simantics.org/Sysdyn-1.0/ModuleSymbol";\r
         public static final String NormalExpression = "http://www.simantics.org/Sysdyn-1.0/NormalExpression";\r
         public static final String ParameterExpression = "http://www.simantics.org/Sysdyn-1.0/ParameterExpression";\r
+        public static final String Redeclaration = "http://www.simantics.org/Sysdyn-1.0/Redeclaration";\r
         public static final String RefersTo = "http://www.simantics.org/Sysdyn-1.0/RefersTo";\r
+        public static final String ReplacedEnumeration = "http://www.simantics.org/Sysdyn-1.0/ReplacedEnumeration";\r
+        public static final String ReplacedEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.0/ReplacedEnumeration/Inverse";\r
+        public static final String ReplacingEnumeration = "http://www.simantics.org/Sysdyn-1.0/ReplacingEnumeration";\r
+        public static final String ReplacingEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.0/ReplacingEnumeration/Inverse";\r
         public static final String Result = "http://www.simantics.org/Sysdyn-1.0/Result";\r
         public static final String ShowEnumerationIndexInCharts = "http://www.simantics.org/Sysdyn-1.0/ShowEnumerationIndexInCharts";\r
         public static final String ShowEnumerationIndexInCharts_Inverse = "http://www.simantics.org/Sysdyn-1.0/ShowEnumerationIndexInCharts/Inverse";\r
@@ -648,6 +666,8 @@ public class SysdynResource {
         HasRangeStart_Inverse = getResourceOrNull(graph, URIs.HasRangeStart_Inverse);\r
         HasRangeStep = getResourceOrNull(graph, URIs.HasRangeStep);\r
         HasRangeStep_Inverse = getResourceOrNull(graph, URIs.HasRangeStep_Inverse);\r
+        HasRedeclaration = getResourceOrNull(graph, URIs.HasRedeclaration);\r
+        HasRedeclaration_Inverse = getResourceOrNull(graph, URIs.HasRedeclaration_Inverse);\r
         HasResult = getResourceOrNull(graph, URIs.HasResult);\r
         HasResultFile = getResourceOrNull(graph, URIs.HasResultFile);\r
         HasResultFile_Inverse = getResourceOrNull(graph, URIs.HasResultFile_Inverse);\r
@@ -672,6 +692,8 @@ public class SysdynResource {
         IsHeadOf = getResourceOrNull(graph, URIs.IsHeadOf);\r
         IsHeadOfTerminal = getResourceOrNull(graph, URIs.IsHeadOfTerminal);\r
         IsOutput = getResourceOrNull(graph, URIs.IsOutput);\r
+        IsReplaceable = getResourceOrNull(graph, URIs.IsReplaceable);\r
+        IsReplaceable_Inverse = getResourceOrNull(graph, URIs.IsReplaceable_Inverse);\r
         IsTailOf = getResourceOrNull(graph, URIs.IsTailOf);\r
         IsTailOfTerminal = getResourceOrNull(graph, URIs.IsTailOfTerminal);\r
         LookupExpression = getResourceOrNull(graph, URIs.LookupExpression);\r
@@ -679,7 +701,12 @@ public class SysdynResource {
         ModuleSymbol = getResourceOrNull(graph, URIs.ModuleSymbol);\r
         NormalExpression = getResourceOrNull(graph, URIs.NormalExpression);\r
         ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression);\r
+        Redeclaration = getResourceOrNull(graph, URIs.Redeclaration);\r
         RefersTo = getResourceOrNull(graph, URIs.RefersTo);\r
+        ReplacedEnumeration = getResourceOrNull(graph, URIs.ReplacedEnumeration);\r
+        ReplacedEnumeration_Inverse = getResourceOrNull(graph, URIs.ReplacedEnumeration_Inverse);\r
+        ReplacingEnumeration = getResourceOrNull(graph, URIs.ReplacingEnumeration);\r
+        ReplacingEnumeration_Inverse = getResourceOrNull(graph, URIs.ReplacingEnumeration_Inverse);\r
         Result = getResourceOrNull(graph, URIs.Result);\r
         ShowEnumerationIndexInCharts = getResourceOrNull(graph, URIs.ShowEnumerationIndexInCharts);\r
         ShowEnumerationIndexInCharts_Inverse = getResourceOrNull(graph, URIs.ShowEnumerationIndexInCharts_Inverse);\r
index 68d404b58d754ab63a526904c59104cee9136cee..5c0e8ccc676334ef289b6bda5ed0fcacf4ed66b8 100644 (file)
                   style="push">\r
                <visibleWhen\r
                      checkEnabled="true">\r
-                  <with\r
-                        variable="selection">\r
-                     <test\r
-                           args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
-                           property="org.simantics.sysdyn.ui.nodeClass">\r
-                     </test>\r
-                  </with>\r
                </visibleWhen>\r
             </command>\r
          </menu>\r
                   checkEnabled="true">\r
             </visibleWhen>\r
          </command>\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.importMdl"\r
+               label="Import .mdl"\r
+               style="push">\r
+            <visibleWhen\r
+                  checkEnabled="true">\r
+            </visibleWhen>\r
+         </command>\r
       </menuContribution>\r
       <menuContribution\r
             locationURI="popup:#SysdynDiagramPopup?after=wbStart">\r
             name="Import...">\r
       </command>\r
       <command\r
-            defaultHandler="org.simantics.sysdyn.ui.handlers.NewEnumerationNodeHandler"\r
             id="org.simantics.sysdyn.ui.newEnumeration"\r
             name="New Enumeration">\r
       </command>\r
+      <command\r
+            id="org.simantics.sysdyn.ui.importMdl"\r
+            name="Import .mdl">\r
+      </command>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.handlers">\r
             </with>\r
          </activeWhen>\r
       </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.ImportMdlHandler"\r
+            commandId="org.simantics.sysdyn.ui.importMdl">\r
+      </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.NewEnumerationNodeHandler"\r
+            commandId="org.simantics.sysdyn.ui.newEnumeration">\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <or>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </or>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
                preference="2.0">\r
          </implementation>\r
       </binding>\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/EnumerationReplacement">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableEnumerations"\r
+               preference="2.0">\r
+         </implementation>\r
+      </binding>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.labelerBinding">\r
                preference="2.0">\r
          </implementation>\r
       </binding>\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/EnumerationReplacement">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableEnumerationsLabeler"\r
+               preference="2.0">\r
+         </implementation>\r
+      </binding>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.imagerBinding">\r
index 60ab9fefe1499f98acb0377566ebcb5a7bc0aefd..b891e2ad4603b58712b6da2b2ddd2dcdbce64b61 100644 (file)
 package org.simantics.sysdyn.ui.browser;\r
 \r
 import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.jface.viewers.ISelection;\r
 import org.simantics.browsing.ui.NodeContext;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
 \r
-public class BrowserSelection implements IAdaptable {\r
+public class BrowserSelection implements IAdaptable, ISelection {\r
        private Resource resource;\r
        private Resource model;\r
        private String URI;\r
@@ -55,5 +56,12 @@ public class BrowserSelection implements IAdaptable {
        public String getURI() {\r
                return this.URI;\r
        }\r
+\r
+       @Override\r
+       public boolean isEmpty() {\r
+               if(originalInput == null)\r
+                       return true;\r
+               return false;\r
+       }\r
        \r
 }\r
index fdd38f713b97720515bc1f958d197e2755bed21c..8edb5a7bac61e9b9fbfbe119881089a9c14ee7e5 100644 (file)
@@ -51,7 +51,7 @@ public class SysdynBrowser extends GraphExplorerView {
                    @SuppressWarnings("unchecked")\r
                                VariableNode<Resource> vn = (VariableNode<Resource>) ctx.getAdapter(VariableNode.class);\r
                    IHintContext context;\r
-                   if(vn != null) {\r
+                   if(vn != null && vn.getResource() != null) {\r
                        context = new AdaptableHintContext(SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY);\r
                        context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], vn));\r
                        context.setHint(SelectionHints.KEY_SELECTION_PROPERTY, vn.getVariable());\r
index 9a6e1440f4e665d2d25377ca3d86270ff18a2749..ed5a9ead174ae68949b9724168521b740d9107d8 100644 (file)
@@ -24,6 +24,7 @@ import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode;\r
@@ -52,6 +53,9 @@ public class ModuleType extends ViewpointContributor<ModuleTypeNode> {
                for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Module))) {\r
                        result.add(new ModuleNode(r));\r
                }\r
+               for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Enumeration))) {\r
+                       result.add(new EnumerationNode(r));\r
+               }\r
                return result;\r
        }\r
 \r
index a069acbbe7175027c7ca9e93e6e49c67a61527eb..1d296b629785fbf395b81ae73c86de32f8883e6e 100644 (file)
@@ -5,9 +5,11 @@ import org.simantics.browsing.ui.common.node.IDeletableNode;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.CancelTransactionException;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ExceptionUtils;\r
 \r
@@ -24,7 +26,20 @@ public class EnumerationNode extends VariableNode<Resource> implements IDeletabl
                 @Override\r
                 public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
                     Layer0 l0 = Layer0.getInstance(graph);\r
-                    graph.deny(resource, l0.PartOf);                \r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    graph.deny(resource, l0.PartOf);       \r
+                    for(Resource redeclaration : graph.getObjects(resource, sr.ReplacedEnumeration_Inverse)) {\r
+                       graph.deny(redeclaration, sr.HasRedeclaration_Inverse);\r
+                    }\r
+                    \r
+                    for(Resource redeclaration : graph.getObjects(resource, sr.ReplacingEnumeration_Inverse)) {\r
+                       graph.deny(redeclaration, sr.HasRedeclaration_Inverse);\r
+                    }\r
+                    \r
+                    for(Resource list : OrderedSetUtils.getOwnerLists(graph, resource, sr.ArrayIndexes)) {\r
+                       OrderedSetUtils.remove(graph, list, resource);\r
+                    }\r
+                    \r
                 }\r
             });\r
         } catch (DatabaseException e) {\r
index a3e270168efd0ce3a3f355c0fe0d484d51c13c9a..e002cb23fd4e4791f9b4a8bef5bbeb26e921b73f 100644 (file)
@@ -202,7 +202,7 @@ public class FlowEdgeClass {
                                                                .getCenterX() - FlowRouter.OFFSET, bounds\r
                                                                .getCenterY() - FlowRouter.OFFSET,\r
                                                                FlowRouter.OFFSET * 2, FlowRouter.OFFSET * 2);\r
-//                                             c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG;\r
+                                               c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG;\r
                                        } else {\r
                                                c.parentObstacle = ElementUtils\r
                                                                .getElementBoundsOnDiagram(connection.node)\r
index bbccf0b77ad8e5c0c84608f840b800efb532de9e..60a45356415bb1ad2c206ecdec11625cb90ead65 100644 (file)
@@ -12,6 +12,8 @@ import org.simantics.db.common.utils.OrderedSetUtils;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
@@ -23,7 +25,7 @@ public class NewEnumerationNodeHandler extends AbstractHandler {
 \r
         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
         \r
-               final Resource configuration = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+               final Resource resource = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
         \r
         SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
 \r
@@ -32,6 +34,20 @@ public class NewEnumerationNodeHandler extends AbstractHandler {
                SysdynResource sr = SysdynResource.getInstance(g);\r
                Layer0 l0 = Layer0.getInstance(g);\r
                \r
+               Resource configuration = null;\r
+               if(g.isInstanceOf(resource, sr.Configuration)) {\r
+                       configuration = resource;\r
+               } else if(g.isInheritedFrom(resource, sr.ModuleSymbol)) {\r
+                       Resource module = g.getPossibleObject(resource,ModelingResources.getInstance(g).SymbolToComponentType);\r
+                       configuration = g.getPossibleObject(module, StructuralResource2.getInstance(g).IsDefinedBy);\r
+               } else {\r
+                       Resource instanceOf = g.getSingleObject(resource, l0.InstanceOf);\r
+                       if(g.isInheritedFrom(instanceOf, sr.Module)) {\r
+                               configuration = g.getPossibleObject(instanceOf, StructuralResource2.getInstance(g).IsDefinedBy);\r
+                       } else {\r
+                               return;\r
+                       }\r
+               }\r
 \r
                                Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes);\r
                                \r
index effe57de0474a688477850d646631412a48c3721..2e61a13aa0dfee9e244c327bf4de0fcda6dfaca9 100644 (file)
@@ -28,7 +28,7 @@ import org.simantics.db.common.utils.OrderedSetUtils;
 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.properties.widgets.arrays.Keys;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
 import org.simantics.utils.datastructures.ArrayMap;\r
 \r
 public class ArrayIndexesTab extends PropertyTabContributorImpl implements Widget{\r
@@ -54,7 +54,7 @@ public class ArrayIndexesTab extends PropertyTabContributorImpl implements Widge
                \r
                availableEnumerationsExplorer\r
                .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/AvailableVariableIndexes");\r
-               availableEnumerationsExplorer.setColumns(Keys.ENUMERATION_TABLE_COLUMNS);\r
+               availableEnumerationsExplorer.setColumns(ColumnKeys.ENUMERATION_TABLE_COLUMNS);\r
                availableEnumerationsExplorer.setInputSource(new SingleSelectionInputSource(\r
                                Resource.class));\r
 \r
@@ -103,7 +103,7 @@ public class ArrayIndexesTab extends PropertyTabContributorImpl implements Widge
                \r
                usedEnumerationsExplorer\r
                .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/UsedVariableIndexes");\r
-               usedEnumerationsExplorer.setColumns(Keys.ENUMERATION_TABLE_COLUMNS);\r
+               usedEnumerationsExplorer.setColumns(ColumnKeys.ENUMERATION_TABLE_COLUMNS);\r
                usedEnumerationsExplorer.setInputSource(new SingleSelectionInputSource(\r
                                Resource.class));\r
 \r
index 8573747f87f928f29a56c1c587524d8c2b624362..0b210465ab542e7b684ee5332d1917d64636b81e 100644 (file)
@@ -4,7 +4,6 @@ import java.util.List;
 \r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
-import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.jface.viewers.ISelectionProvider;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.SWT;\r
@@ -36,45 +35,47 @@ import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.SysdynModel;\r
 import org.simantics.sysdyn.manager.SysdynModelManager;\r
 import org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationIndexNode;\r
+import org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableIndexesWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
 import org.simantics.utils.datastructures.ArrayMap;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
 \r
-public class EnumerationTab extends PropertyTabContributorImpl {\r
+public class EnumerationTab extends PropertyTabContributorImpl implements Widget {\r
 \r
        GraphExplorerComposite indexExplorer;\r
        \r
        Button showAll;\r
-\r
+       Variable variable;\r
        \r
        Table table;\r
        @Override\r
        public void createControls(Composite body, IWorkbenchSite site,\r
                        final ISessionContext context, WidgetSupport support) {\r
 \r
+               support.register(this);\r
+               \r
                Composite container = new Composite(body, SWT.None);\r
                GridDataFactory.fillDefaults().grab(true, true).applyTo(container);\r
-               GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(container);\r
+               GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(container);\r
 \r
         TrackedText nameText = new TrackedText(container, support, SWT.BORDER);\r
         nameText.setTextFactory(new StringPropertyFactory(Builtins.URIs.HasName));\r
         nameText.addModifyListener(new VariableNamePropertyModifier(context, Builtins.URIs.HasName));\r
         nameText.setInputValidator(new VariableNameValidator(support));\r
-        GridDataFactory.fillDefaults().grab(true, false).span(3,1).applyTo(nameText.getWidget());\r
-\r
-\r
-        \r
+        GridDataFactory.fillDefaults().grab(true, false).span(4,1).applyTo(nameText.getWidget());\r
         \r
         indexExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
                                "displaySelectors", "displayFilter").values(false, false), site, container, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.CHECK);\r
@@ -97,12 +98,15 @@ public class EnumerationTab extends PropertyTabContributorImpl {
                     SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
                                                @Override\r
                                                public void run(ReadGraph graph) throws DatabaseException {\r
-                                                       Layer0 l0 = Layer0.getInstance(graph);\r
-                                                       Resource enumeration = (Resource)indexExplorer.getExplorer().getRoot().getAdapter(Resource.class);\r
-                                                       Resource configuration = graph.getSingleObject(enumeration, l0.PartOf);\r
-                                                       SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
-                                                       // update results in graphs\r
-                                                       model.resultChanged();\r
+                                                       Resource modelResource = Variables.getModel(graph, variable);\r
+                                                       if(modelResource != null) {\r
+                                                               Resource configuration = graph.getSingleObject(\r
+                                                                               modelResource, \r
+                                                                               SimulationResource.getInstance(graph).HasConfiguration);\r
+                                                               SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+                                                               // update results in graphs\r
+                                                               model.resultChanged();\r
+                                                       }\r
                                                }\r
                                        });\r
                 }\r
@@ -112,7 +116,7 @@ public class EnumerationTab extends PropertyTabContributorImpl {
 \r
         indexExplorer.finish();\r
 \r
-               GridDataFactory.fillDefaults().grab(true, true).span(3, 1).applyTo(\r
+               GridDataFactory.fillDefaults().grab(true, true).span(4, 1).applyTo(\r
                                indexExplorer);\r
                \r
                Control c = indexExplorer.getExplorerControl();\r
@@ -120,17 +124,21 @@ public class EnumerationTab extends PropertyTabContributorImpl {
                        ((Tree) c).setLinesVisible(true);\r
 \r
 \r
-               Button add = new Button(container, support, SWT.None);\r
+               final Button add = new Button(container, support, SWT.None);\r
                add.setText("Add");\r
                add.addSelectionListener(new addEnumerationIndexListener(support));\r
 \r
-               Button remove = new Button(container, support, SWT.None);\r
+               final Button remove = new Button(container, support, SWT.None);\r
                remove.setText("Remove");\r
                remove.addSelectionListener(new removeEnumerationIndexListener(support));\r
                \r
+               ReplaceableIndexesWidget externalIndexes = new ReplaceableIndexesWidget(container, support, SWT.NULL);\r
+               GridDataFactory.fillDefaults().applyTo(externalIndexes.getWidget());\r
+               \r
                showAll = new Button(container, support, SWT.CHECK);\r
                showAll.setText("Show all in charts");\r
                showAll.addSelectionListener(new ShowAllIndexesListener(support));\r
+               \r
        }\r
 \r
        private class addEnumerationIndexListener implements SelectionListener, Widget {\r
@@ -143,7 +151,7 @@ public class EnumerationTab extends PropertyTabContributorImpl {
 \r
                @Override\r
                public void setInput(ISessionContext context, Object input) {\r
-                       final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+                       final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class);\r
                        try {\r
                                context.getSession().syncRequest(new ReadRequest() {\r
 \r
@@ -197,7 +205,7 @@ public class EnumerationTab extends PropertyTabContributorImpl {
 \r
                @Override\r
                public void setInput(ISessionContext context, Object input) {\r
-                       final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+                       final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class);\r
                        try {\r
                                context.getSession().syncRequest(new ReadRequest() {\r
 \r
@@ -253,7 +261,7 @@ public class EnumerationTab extends PropertyTabContributorImpl {
 \r
                        @Override\r
                        public void setInput(ISessionContext context, Object input) {\r
-                               final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+                               final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class);\r
                                \r
                                context.getSession().asyncRequest(new Read<Boolean>() {\r
 \r
@@ -319,11 +327,16 @@ public class EnumerationTab extends PropertyTabContributorImpl {
                                                                }\r
                                                        }\r
                                                        \r
-                                                       Resource enumeration = graph.getSingleObject(enumerationIndexes, sr.HasEnumerationIndexes_Inverse);\r
-                                                       Resource configuration = graph.getSingleObject(enumeration, Layer0.getInstance(graph).PartOf);\r
-                                                       SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
-                                                       // update results in graphs\r
-                                                       model.resultChanged();\r
+                                                       \r
+                                                       Resource modelResource = Variables.getModel(graph, variable);\r
+                                                       if(modelResource != null) {\r
+                                                               Resource configuration = graph.getSingleObject(\r
+                                                                               modelResource, \r
+                                                                               SimulationResource.getInstance(graph).HasConfiguration);\r
+                                                               SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+                                                               // update results in graphs\r
+                                                               model.resultChanged();\r
+                                                       }\r
 \r
                                                }\r
                                        });\r
@@ -340,4 +353,9 @@ public class EnumerationTab extends PropertyTabContributorImpl {
                        }\r
 \r
                }\r
+\r
+       @Override\r
+       public void setInput(ISessionContext context, Object input) {\r
+               variable = AdaptionUtils.adaptToSingle(input, Variable.class);\r
+       }\r
 }\r
index 7312ff441df819452026c38105af5e562d5dd090..a3bd4b5370ba89154d710fcc2c9fd79fea2df4bd 100644 (file)
@@ -15,25 +15,65 @@ import org.eclipse.jface.layout.GridDataFactory;
 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.Label;\r
+import org.eclipse.swt.widgets.Tree;\r
 import org.eclipse.ui.IWorkbenchSite;\r
 import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedText;\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.Builtins;\r
+import org.simantics.db.Resource;\r
 import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 \r
-public class ModuleTab extends PropertyTabContributorImpl {\r
+public class ModuleTab extends PropertyTabContributorImpl implements Widget {\r
 \r
+       GraphExplorerComposite enumerationRedeclarationExplorer;\r
+       \r
     @Override\r
     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+       support.register(this);\r
+       \r
         Composite composite = new Composite(body, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
-        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(composite);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite);\r
         TrackedText nameText = new TrackedText(composite, support, SWT.BORDER);\r
         nameText.setTextFactory(new StringPropertyFactory(Builtins.URIs.HasName));\r
         nameText.addModifyListener(new StringPropertyModifier(context, Builtins.URIs.HasName));\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget());\r
+        \r
+        Label label = new Label(composite, SWT.NONE);\r
+               label.setText("Replaceable enumerations");\r
+               enumerationRedeclarationExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                               "displaySelectors", "displayFilter").values(false, false), site, composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI);\r
+               \r
+               enumerationRedeclarationExplorer\r
+               .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/EnumerationReplacement");\r
+               enumerationRedeclarationExplorer.setColumns(ColumnKeys.ENUMERATION_REDECLARATION_COLUMNS);\r
+               enumerationRedeclarationExplorer.setInputSource(new SingleSelectionInputSource(\r
+                               Resource.class));\r
+\r
+               enumerationRedeclarationExplorer.finish();\r
+\r
+               GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+                               enumerationRedeclarationExplorer);\r
+               \r
+               Control c = enumerationRedeclarationExplorer.getExplorerControl();\r
+               if (c instanceof Tree)\r
+                       ((Tree) c).setLinesVisible(true);\r
+        \r
     }\r
+    \r
+    \r
+       @Override\r
+       public void setInput(ISessionContext context, Object input) {\r
+               enumerationRedeclarationExplorer.setInput(context, input);\r
+       }\r
 }\r
index 1e07c5b187cdb76dad7af00142541aee5fe41611..b46e3d6393dbdab1b0852e536eb1787c84b4d250 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collection;
 import java.util.Collections;\r
 import java.util.List;\r
 \r
+import org.eclipse.jface.viewers.ISelection;\r
 import org.simantics.browsing.ui.SelectionProcessor;\r
 import org.simantics.browsing.ui.swt.ComparableTabContributor;\r
 import org.simantics.db.ReadGraph;\r
@@ -68,6 +69,7 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
 \r
                        // Single element\r
                        Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class);\r
+                       \r
                        if(r == null) \r
                                return Collections.emptyList();\r
 \r
@@ -124,17 +126,30 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                                return tabs;\r
                        }\r
                        if (backend.isInstanceOf(r, sr.Input)) {\r
-                               return Collections.singleton(new ComparableTabContributor(\r
+                               tabs.add(new ComparableTabContributor(\r
                                                new InputVariableTab(),\r
                                                2,\r
                                                r,\r
                                "Input"));\r
+                               \r
+                               tabs.add(new ComparableTabContributor(\r
+                                               new ArrayIndexesTab(),\r
+                                               1,\r
+                                               r,\r
+                               "Indexes"));\r
+\r
+                               tabs.add(new ComparableTabContributor(\r
+                                               new VariableInformationTab(),\r
+                                               0,\r
+                                               r,\r
+                               "Additional Information"));\r
+                               return tabs;\r
                        }\r
                        if (backend.isInstanceOf(r, sr.Enumeration)) {\r
                                return Collections.singleton(new ComparableTabContributor(\r
                                                new EnumerationTab(),\r
                                                2,\r
-                                               r,\r
+                                               AdaptionUtils.adaptToSingle(selection, ISelection.class),\r
                                "Enumeration"));\r
                        }\r
                        if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) {\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ColumnKeys.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ColumnKeys.java
new file mode 100644 (file)
index 0000000..06168d1
--- /dev/null
@@ -0,0 +1,43 @@
+/*******************************************************************************\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.simantics.browsing.ui.Column;\r
+import org.simantics.browsing.ui.Column.Align;\r
+\r
+public class ColumnKeys {\r
+       \r
+       public static final String   ENUMERATION        = "Enumeration";\r
+       public static final String   INDEXES            = "Indexes";\r
+       public static final String   SHOW_IN_CHARTS = "ShowInCharts";\r
+       public static final String   REPLACED_WITH = "Replaced with";\r
+       \r
+       public static String[] ENUMERATION_COLUMNS_KEYS = { ENUMERATION, INDEXES };\r
+    public static Column[] ENUMERATION_TABLE_COLUMNS = new Column[] {\r
+        new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", false),\r
+        new Column(INDEXES, Align.LEFT, 100, "Indexes", true),\r
+    };\r
+    \r
+\r
+       public static String[] ENUMERATION_INDEX_COLUMNS_KEYS = { ENUMERATION, SHOW_IN_CHARTS };\r
+    public static Column[] ENUMERATION_INDEX_TABLE_COLUMNS = new Column[] {\r
+        new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", true),\r
+        new Column(SHOW_IN_CHARTS, Align.LEFT, 20, "Show in charts", false),\r
+    };\r
+    \r
+       public static String[] ENUMERATION_REDECLARATION_KEYS = { ENUMERATION, REPLACED_WITH };\r
+    public static Column[] ENUMERATION_REDECLARATION_COLUMNS = new Column[] {\r
+        new Column(ENUMERATION, Align.LEFT, 200, "Enumeration in module", false),\r
+        new Column(REPLACED_WITH, Align.LEFT, 200, "Replaced with", true),\r
+    };\r
+    \r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ComboBoxModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ComboBoxModifier.java
new file mode 100644 (file)
index 0000000..d45b1a2
--- /dev/null
@@ -0,0 +1,136 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.widgets.Combo;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.common.modifiers.EnumeratedValue;\r
+import org.simantics.browsing.ui.common.modifiers.Enumeration;\r
+import org.simantics.browsing.ui.content.Labeler.CustomModifier;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.utils.ObjectUtils;\r
+\r
+public abstract class ComboBoxModifier<T> implements CustomModifier {\r
+\r
+       private final Enumeration<T> enumeration;\r
+       private final EnumeratedValue<T> value;\r
+       private final List<String> values;\r
+       private final Session session;\r
+       private Combo combo;\r
+       int select;\r
+\r
+       public ComboBoxModifier(Session session, Enumeration<T> enumeration, T value) {\r
+               this(session, enumeration, enumeration.find(value));\r
+       }\r
+\r
+       public ComboBoxModifier(Session session, Enumeration<T> enumeration,\r
+                       EnumeratedValue<T> value) {\r
+               if (session == null)\r
+                       throw new NullPointerException("null session");\r
+               if (enumeration == null)\r
+                       throw new NullPointerException("null enumeration");\r
+               if (enumeration.size() == 0)\r
+                       throw new IllegalArgumentException("");\r
+\r
+               this.enumeration = enumeration;\r
+               this.value = value;\r
+               this.session = session;\r
+\r
+               select = 0;\r
+               boolean found = false;\r
+               \r
+               this.values = new ArrayList<String>();\r
+               for (EnumeratedValue<T> v : enumeration.values()) {\r
+                       values.add(v.getName());\r
+                       \r
+                       if(v == value) \r
+                               found = true;\r
+                       \r
+                       if(found == false)\r
+                               select++;\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Object createControl(Object parentControl, Object controlItem,\r
+                       int columnIndex, NodeContext context) {\r
+\r
+               combo = new Combo((Composite) parentControl, SWT.DROP_DOWN\r
+                               | SWT.BORDER | SWT.READ_ONLY);\r
+\r
+               for (String item : values) {\r
+                       combo.add(item);\r
+               }\r
+               \r
+               combo.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               String index = ((Combo) e.getSource()).getText();\r
+                               modify(index);\r
+                       }\r
+               });\r
+               \r
+               combo.select(select);\r
+               \r
+               return combo;\r
+\r
+       }\r
+\r
+       @Override\r
+       public String getValue() {\r
+               return enumeration.values().get(0).getName();\r
+       }\r
+\r
+    @Override\r
+    public final String isValid(String label) {\r
+        if (enumeration.findByName(label) == null)\r
+            return "Value '" + label + "' is not among the enumerated values " + enumeration.values();\r
+        return null;\r
+    }\r
+\r
+       @Override\r
+       public void modify(String label) {\r
+               \r
+        int index = values.indexOf(label);\r
+        if (index == -1)\r
+            throw new IllegalArgumentException("Cannot modify enumeration with value '" + label + "', not among the enumerated values " + values);\r
+               \r
+        EnumeratedValue<T> oldEnumValue = value;\r
+        EnumeratedValue<T> newEnumValue = enumeration.values().get(index);\r
+        \r
+        final T oldObject = oldEnumValue != null ? oldEnumValue.getObject() : null;\r
+        final T newObject = newEnumValue != null ? newEnumValue.getObject() : null;\r
+        \r
+        if (ObjectUtils.objectEquals(oldObject, newObject))\r
+            return;\r
+\r
+        try {\r
+            session.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException {\r
+                    modifyWithObject(graph, oldObject, newObject);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            handleException(e);\r
+        }\r
+        \r
+               combo.dispose();                \r
+       }\r
+       \r
+       protected abstract void modifyWithObject(WriteGraph graph, T oldEnumObject, T enumObject) throws DatabaseException;\r
+       \r
+    protected void handleException(DatabaseException e) {\r
+        throw new RuntimeException(e);\r
+    }\r
+\r
+}\r
index d55a10f36cd213946a2304975d4a0a800b21fc3f..bbaaa54a72995ec173564f3eabdc062eecafdf76 100644 (file)
@@ -11,6 +11,7 @@ import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
 \r
 public class EnumerationLabeler extends ColumnLabelerContributorImpl<EnumerationNode>{\r
 \r
@@ -20,9 +21,10 @@ public class EnumerationLabeler extends ColumnLabelerContributorImpl<Enumeration
                \r
                String name =  NameUtils.getSafeName(graph, input.data);\r
                HashMap<String, String> map = new HashMap<String, String>();\r
-               map.put(Keys.ENUMERATION, name);\r
+               map.put(ColumnKeys.ENUMERATION, name);\r
                \r
                SysdynResource sr = SysdynResource.getInstance(graph);\r
+               \r
                Resource enumerationIndexes = graph.getPossibleObject(input.data, sr.HasEnumerationIndexes);\r
                ListIterator<Resource> indexes = OrderedSetUtils.iterator(graph, enumerationIndexes);\r
                StringBuilder sb = new StringBuilder();\r
@@ -34,7 +36,14 @@ public class EnumerationLabeler extends ColumnLabelerContributorImpl<Enumeration
                                sb.append(", ");\r
                }\r
                sb.append("]");\r
-               map.put(Keys.INDEXES, sb.toString());\r
+               \r
+               Boolean relaceable = graph.getPossibleRelatedValue(input.data, sr.IsReplaceable);\r
+               if(Boolean.TRUE.equals(relaceable)) {\r
+                       sb.append(" Replaceable");\r
+               }\r
+               \r
+               map.put(ColumnKeys.INDEXES, sb.toString());\r
+               \r
                return map;\r
        }\r
 \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/Keys.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/Keys.java
deleted file mode 100644 (file)
index 993723d..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
-\r
-import org.simantics.browsing.ui.Column;\r
-import org.simantics.browsing.ui.Column.Align;\r
-\r
-public class Keys {\r
-       \r
-       public static final String   ENUMERATION        = "Enumeration";\r
-       public static final String   INDEXES            = "Indexes";\r
-       public static final String   SHOW_IN_CHARTS = "ShowInCharts";\r
-        \r
-       public static String[] ENUMERATION_COLUMNS_KEYS = { ENUMERATION, INDEXES };\r
-    public static Column[] ENUMERATION_TABLE_COLUMNS = new Column[] {\r
-        new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", false),\r
-        new Column(INDEXES, Align.LEFT, 100, "Indexes", true),\r
-    };\r
-    \r
-\r
-       public static String[] ENUMERATION_INDEX_COLUMNS_KEYS = { ENUMERATION, SHOW_IN_CHARTS };\r
-    public static Column[] ENUMERATION_INDEX_TABLE_COLUMNS = new Column[] {\r
-        new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", true),\r
-        new Column(SHOW_IN_CHARTS, Align.LEFT, 20, "Show in charts", false),\r
-    };\r
-    \r
-}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/RedeclarationNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/RedeclarationNode.java
new file mode 100644 (file)
index 0000000..0d5f3fb
--- /dev/null
@@ -0,0 +1,172 @@
+/*******************************************************************************\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.arrays;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.browsing.ui.common.modifiers.EnumeratedValue;\r
+import org.simantics.browsing.ui.common.modifiers.Enumeration;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\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.ObjectsWithType;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class RedeclarationNode  extends AbstractNode<Resource> implements IModifiableNode {\r
+\r
+       private Resource module;\r
+       \r
+       public RedeclarationNode(ReadGraph graph, final Resource module, Resource enumeration) {\r
+               super(enumeration);\r
+               this.module = module;\r
+       }\r
+       \r
+       /**\r
+        * \r
+        * @param graph\r
+        * @return\r
+        */\r
+       public Resource getReplacingEnumeration(ReadGraph graph) {\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Resource result = null;\r
+               try {\r
+                       Resource redeclaration = getRedeclaration(graph);\r
+                       if(redeclaration != null) {\r
+                               result = graph.getSingleObject(redeclaration, sr.ReplacingEnumeration);\r
+                       }\r
+               } catch(DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+\r
+       public Resource getModule() {\r
+               return module;\r
+       }\r
+\r
+       public void setModule(Resource module) {\r
+               this.module = module;\r
+       }\r
+\r
+       public Resource getRedeclaration(ReadGraph graph) {\r
+               try {\r
+                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+                       for(Resource redeclaration : graph.syncRequest(new ObjectsWithType(module, sr.HasRedeclaration, sr.Redeclaration))) {\r
+                               Resource replacedEnumeration = graph.getPossibleObject(redeclaration, sr.ReplacedEnumeration);\r
+                               if(replacedEnumeration != null && replacedEnumeration.equals(getReplacedEnumeration())) {\r
+                                       return redeclaration;\r
+                               }\r
+                       }\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               return null;\r
+       }\r
+\r
+       public void setRedeclaration(WriteGraph graph, Resource redeclaration) {\r
+               try {\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Resource oldRedeclaration = getRedeclaration(graph);\r
+               if(oldRedeclaration != null || redeclaration == null) {\r
+                       graph.deny(module, sr.HasRedeclaration, oldRedeclaration);\r
+               }\r
+               \r
+               if(redeclaration != null)\r
+                       graph.claim(module, sr.HasRedeclaration, redeclaration);\r
+               \r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+\r
+       public Resource getReplacedEnumeration() {\r
+               return this.data;\r
+       }\r
+\r
+       @Override\r
+       public Modifier getModifier(String columnId) {\r
+               \r
+               if(!ColumnKeys.REPLACED_WITH.equals(columnId))\r
+                       return null;\r
+               \r
+               ComboBoxModifier<Resource> cbm = null;\r
+               \r
+               try {\r
+                       cbm = SimanticsUI.getSession().syncRequest(new Read<ComboBoxModifier<Resource>>() {\r
+                               \r
+                               @Override\r
+                               public ComboBoxModifier<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+                                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                       Layer0 l0 = Layer0.getInstance(graph);\r
+                                       \r
+                                       ArrayList<EnumeratedValue<Resource>> values = new ArrayList<EnumeratedValue<Resource>>();\r
+                                       \r
+                                       \r
+                               Resource configuration = graph.getSingleObject(module, l0.PartOf);\r
+                               \r
+                                       for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
+                                               String name = NameUtils.getSafeName(graph, enumeration);\r
+                                               values.add(new EnumeratedValue<Resource>(name, enumeration));                                   \r
+                                       }\r
+\r
+                                       if(values.size() == 0)\r
+                                               return null;\r
+                                       \r
+                                       values.add(0, new EnumeratedValue<Resource>("", null));\r
+                                       Enumeration<Resource> enumeration = new Enumeration<Resource>(values);  \r
+                                       \r
+                                       ComboBoxModifier<Resource> cbm = new ComboBoxModifier<Resource>(graph.getSession(), enumeration, getReplacingEnumeration(graph)) {\r
+                                               \r
+                                               @Override\r
+                                               protected void modifyWithObject(WriteGraph graph, Resource oldEnumObject,\r
+                                                               Resource enumObject) throws DatabaseException {\r
+                                                       \r
+                                                       if(enumObject == null) {\r
+                                                               setRedeclaration(graph, null);\r
+                                                       } else if(!enumObject.equals(oldEnumObject)) {\r
+                                                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                                               Resource redeclaration = GraphUtils.create2(graph, \r
+                                                                               sr.Redeclaration, \r
+                                                                               sr.ReplacedEnumeration, getReplacedEnumeration(),\r
+                                                                               sr.ReplacingEnumeration, enumObject);\r
+                                                               setRedeclaration(graph, redeclaration);\r
+                                                       }\r
+                                                       \r
+                                               }\r
+                                       };\r
+                                       \r
+                                       return cbm;\r
+                                       \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       // TODO Auto-generated catch block\r
+                       e.printStackTrace();\r
+               }\r
+\r
+               return cbm;\r
+       }\r
+       \r
+       \r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java
new file mode 100644 (file)
index 0000000..91afda9
--- /dev/null
@@ -0,0 +1,53 @@
+/*******************************************************************************\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.arrays;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class ReplaceableEnumerations  extends ViewpointContributorImpl<Resource> {\r
+       \r
+       @Override\r
+       public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+                       throws DatabaseException {\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+        StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+        \r
+        Resource moduleType = graph.getSingleObject(input, l0.InstanceOf);\r
+        Resource configuration = graph.getSingleObject(moduleType, sr2.IsDefinedBy);\r
+        \r
+        ArrayList<RedeclarationNode> result = new ArrayList<RedeclarationNode>();\r
+        \r
+               for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
+                       if(Boolean.TRUE.equals(graph.getRelatedValue(r, sr.IsReplaceable)))\r
+                               result.add(new RedeclarationNode(graph, input, r));\r
+               }\r
+               \r
+        return result;\r
+       }\r
+\r
+       @Override\r
+       public String getViewpointId() {\r
+               return "Replaceable enumerations";\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerationsLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerationsLabeler.java
new file mode 100644 (file)
index 0000000..68a44db
--- /dev/null
@@ -0,0 +1,43 @@
+/*******************************************************************************\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.arrays;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.ColumnLabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
+\r
+public class ReplaceableEnumerationsLabeler extends ColumnLabelerContributorImpl<RedeclarationNode>{\r
+\r
+       @Override\r
+       public Map<String, String> getLabel(ReadGraph graph, RedeclarationNode input)\r
+                       throws DatabaseException {\r
+               HashMap<String, String> map = new HashMap<String, String>();\r
+               \r
+               String name = NameUtils.getSafeName(graph, input.data);\r
+               map.put(ColumnKeys.ENUMERATION, name);\r
+               \r
+               Resource replacingEnumeration = input.getReplacingEnumeration(graph); \r
+               String replacingEnumerationName = "";\r
+               if(replacingEnumeration != null)\r
+                       replacingEnumerationName = NameUtils.getSafeName(graph, replacingEnumeration);\r
+               \r
+               map.put(ColumnKeys.REPLACED_WITH, replacingEnumerationName);\r
+               return map;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java
new file mode 100644 (file)
index 0000000..06caf4d
--- /dev/null
@@ -0,0 +1,117 @@
+/*******************************************************************************\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.arrays;\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.events.SelectionListener;\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
+public class ReplaceableIndexesWidget implements Widget {\r
+       \r
+    Resource variable = null; \r
+    boolean selected = false;\r
+    org.simantics.browsing.ui.swt.widgets.Button isReplaceableButton;\r
+    \r
+    public ReplaceableIndexesWidget(Composite parent, WidgetSupport support, int style) {\r
+        support.register(this);\r
+        isReplaceableButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+        isReplaceableButton.setText("Can be replaced by parent module");\r
+    }\r
+\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
+                Resource resource = ISelectionUtils.filterSingleSelection(selection, Resource.class);\r
+                if(resource != null) {\r
+                    variable = resource;\r
+                }\r
+            }\r
+        }\r
+        \r
+        if(variable == 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
+                    final Boolean replaceable = graph.getPossibleRelatedValue(variable, sr.IsReplaceable);\r
+                    if(replaceable != null)\r
+                       selected = replaceable;\r
+                    final Button button = getWidget();\r
+                    button.getDisplay().asyncExec(new Runnable() {\r
+                        \r
+                        @Override\r
+                        public void run() {\r
+                            if(button.isDisposed()) return;\r
+                            \r
+                            if(replaceable)\r
+                                button.setSelection(true);\r
+                            else\r
+                                button.setSelection(false);\r
+                        }\r
+                    });\r
+\r
+                        \r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+        \r
+        isReplaceableButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+            @Override\r
+            public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+                SysdynResource sr =  SysdynResource.getInstance(graph);\r
+                Boolean replaceable = graph.getPossibleRelatedValue(input, sr.IsReplaceable);\r
+                if(Boolean.TRUE.equals(replaceable)) {\r
+                    graph.claimLiteral(input, sr.IsReplaceable, false);\r
+                    selected = false;\r
+                } else {\r
+                       graph.claimLiteral(input, sr.IsReplaceable, true);\r
+                       selected = true;\r
+                }\r
+            }\r
+        });\r
+    }\r
+    \r
+    public Button getWidget() {\r
+        return isReplaceableButton.getWidget();\r
+    }\r
+    \r
+    public boolean getSelection() {\r
+       return selected;\r
+    }\r
+    \r
+    public void addSelectionListener(SelectionListener listener) {\r
+       isReplaceableButton.addSelectionListener(listener);\r
+    }\r
+\r
+}\r
index f82f517e0017f3d77e45390a550c12985605b168..4425ce9c596605678e5cafa19ead3ad9ff86c309 100644 (file)
@@ -145,7 +145,6 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
        protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Variable variable) throws DatabaseException {\r
                ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
                HashMap<String, String> rvis = new HashMap<String, String>();\r
-               \r
                String rvi = Variables.getRVI(g, variable);\r
                if (rvi == null) \r
                        return dataSets;\r
index 802f3295b171ee0b16a38967ce311cc9d83d51b8..cbd4948c59a20618e70c45a716546bf618d38f00 100644 (file)
@@ -17,10 +17,15 @@ Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
  org.simantics.layer0.utils;bundle-version="0.8.0",
  org.simantics.layer0;bundle-version="1.0.0",
  org.simantics.structural.ontology;bundle-version="1.0.0",
- org.simantics.sysdyn.ontology;bundle-version="1.0.0"
+ org.simantics.sysdyn.ontology;bundle-version="1.0.0",
+ org.simantics.modeling;bundle-version="1.1.1",
+ org.simantics.diagram;bundle-version="1.1.1",
+ org.simantics.diagram.ontology;bundle-version="1.1.1"
 Export-Package: org.simantics.sysdyn,
  org.simantics.sysdyn.expressionParser,
  org.simantics.sysdyn.manager,
+ org.simantics.sysdyn.mdlImport,
+ org.simantics.sysdyn.mdlImport.mdlElements,
  org.simantics.sysdyn.modelica,
  org.simantics.sysdyn.representation,
  org.simantics.sysdyn.representation.visitors,
index 9f2c93e8b42fbdbfc9a592f4381eba7a1986ce7c..d12f7b40d54d663825a521c9fda49ea379f6e6bc 100644 (file)
@@ -160,14 +160,14 @@ public class ModelicaWriter {
         if(!modules.isEmpty()) {\r
             b.append("// Module definitions\n");\r
             for(Module m : modules) {\r
-                b.append("    " + m.getType().getName() + " " + m.getName() + ";\n");\r
+                b.append(m.getDeclaration());\r
             }\r
         }\r
 \r
         if(!inputs.isEmpty()) {\r
             b.append("// Input definitions\n");\r
             for(Input i : inputs) {\r
-                b.append("    " + i.getType() + " " + i.getName() + ";\n");\r
+                b.append(i.getDeclaration());\r
             }\r
         }\r
         \r
index 33dc5760d3e80e5c301de127e98d84c2691c5af1..ebde6003c7f90ed0bab161263341922931f5d219 100644 (file)
@@ -4,6 +4,7 @@ import java.util.ArrayList;
 \r
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
 \r
 @GraphType("http://www.simantics.org/Sysdyn-1.0/Enumeration")\r
@@ -11,6 +12,9 @@ public class Enumeration extends Variable {
        \r
     @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasEnumerationIndexes")\r
     private EnumerationIndexes enumerationIndexes;\r
+    \r
+    @RelatedValue("http://www.simantics.org/Sysdyn-1.0/IsReplaceable")\r
+    private Boolean isReplaceable;\r
 \r
        @Override\r
        public void accept(IElementVisitorVoid v) {\r
@@ -19,20 +23,35 @@ public class Enumeration extends Variable {
        \r
        public String getDeclaration() {\r
                StringBuilder sb = new StringBuilder();\r
-               sb.append("    " + this.getType());\r
+               sb.append("    ");\r
+               if(isReplaceable())\r
+                       sb.append("replaceable ");\r
+               sb.append(this.getType());\r
                sb.append(" " + this.name);\r
-               sb.append(" = enumeration(");\r
+               sb.append(" = ");\r
+               sb.append(getEnumerationDefinition());\r
+               sb.append(";\n");\r
+               return sb.toString();\r
+       }\r
+       \r
+       public ArrayList<EnumerationIndex> getEnumerationIndexes() {\r
+       return enumerationIndexes.getEnumerationIndexes();\r
+       }\r
+       \r
+       public boolean isReplaceable() {\r
+               return Boolean.TRUE.equals(isReplaceable);\r
+       }\r
+       \r
+       public String getEnumerationDefinition() {\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("enumeration(");\r
                for(int i = 0; i < enumerationIndexes.getEnumerationIndexes().size(); i++) {\r
                        sb.append(enumerationIndexes.getEnumerationIndexes().get(i).getName());\r
                        if(i < enumerationIndexes.getEnumerationIndexes().size() - 1)\r
                                sb.append(", ");\r
                }\r
-               sb.append(");\n");\r
+               sb.append(")");\r
                return sb.toString();\r
        }\r
-       \r
-       public ArrayList<EnumerationIndex> getEnumerationIndexes() {\r
-       return enumerationIndexes.getEnumerationIndexes();\r
-       }\r
 \r
 }\r
index ceb8fef4006278cced6e8f3cae43098efa3c634a..8a2a543c18bc5d2b22a489e62d025c60671d6771 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation;\r
 \r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
 import java.util.List;\r
 \r
 import org.simantics.objmap.annotations.GraphType;\r
@@ -26,16 +28,58 @@ public class Input extends Variable {
     @RelatedElements("http://www.simantics.org/Sysdyn-1.0/IsHeadOf")\r
     private List<IElement> isHeadOf;\r
     \r
+    \r
+    \r
     @Override\r
     public void accept(IElementVisitorVoid v) {\r
         v.visit(this);\r
     }\r
 \r
     public String getDefaultInputValue() {\r
-        return defaultInputValue.toString();\r
+        if( getArrayIndexes() == null || getArrayIndexes().getEnumerations().isEmpty()) {\r
+               return defaultInputValue.toString();\r
+        } else {\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("fill(");\r
+               sb.append(defaultInputValue);\r
+               sb.append(", ");\r
+               Iterator<Enumeration> i = getArrayIndexes().getEnumerations().iterator();\r
+               while(i.hasNext()) {\r
+                       Enumeration e = i.next();\r
+                       sb.append(e.getEnumerationIndexes().size());\r
+                       if(i.hasNext())\r
+                               sb.append(", ");\r
+               }\r
+               sb.append(")");\r
+               return sb.toString();\r
+        }\r
     }\r
 \r
     public boolean isHeadOfDependency() {\r
         return !isHeadOf.isEmpty();\r
     }\r
+    \r
+    public String getDeclaration() {\r
+       ArrayIndexes ai = getArrayIndexes();\r
+       ArrayList<Enumeration> enumerations = null;\r
+       if(ai != null) \r
+               enumerations = ai.getEnumerations();\r
+       \r
+       String range = "";\r
+       if(enumerations != null && enumerations.size() > 0) {\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("[");\r
+               Iterator<Enumeration> iterator = enumerations.iterator();\r
+               while(iterator.hasNext()) {\r
+                       sb.append(iterator.next().getName());\r
+                       if(iterator.hasNext()) {\r
+                               sb.append(", ");\r
+                       }\r
+               }\r
+               sb.append("]");\r
+               range = sb.toString();\r
+       }\r
+       \r
+        return "    " + getType() + " " + getName() + range + ";\n";\r
+    }\r
 }\r
index 003f456efa00da9141c3fcd8983caf7907ec976f..02fa9e8d008b394295187597b9d888565a6f4dd0 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation;\r
 \r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.objmap.annotations.RelatedElements;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
 \r
@@ -28,6 +33,9 @@ public class Module implements IElement {
     @RelatedElement("http://www.simantics.org/Layer0-1.0/InstanceOf")\r
     private ModuleType type;\r
     \r
+    @RelatedElements("http://www.simantics.org/Sysdyn-1.0/HasRedeclaration")\r
+    private List<Redeclaration> redeclarations;\r
+    \r
     @Override\r
     public void accept(IElementVisitorVoid v) {\r
         v.visit(this);\r
@@ -40,9 +48,49 @@ public class Module implements IElement {
     public ModuleType getType() {\r
        return type;\r
     }\r
+    \r
+    /**\r
+     * Returns the declaration of a module with possible redeclared enumerations\r
+     * \r
+     * Module m(redeclare type E1 = enumeration(i1, i2, i3), redeclare type E2 = enumeration(i4, i5, i6));\r
+     * \r
+     * @return Declaration of a module instance\r
+     */\r
+    public String getDeclaration() {\r
+       StringBuilder sb = new StringBuilder();\r
+       sb.append("    ");\r
+       sb.append(getType().getName());\r
+       sb.append(" ");\r
+       sb.append(getName());\r
+       if(!getRedeclarations().isEmpty()) {\r
+               sb.append("(");\r
+               Iterator<Redeclaration> i = getRedeclarations().iterator();\r
+               while(i.hasNext()) {\r
+                       Redeclaration rd = i.next();\r
+                       sb.append(rd.getRedeclaration());\r
+                       if(i.hasNext())\r
+                               sb.append(",");\r
+               }\r
+               sb.append(")");\r
+       }\r
+       sb.append(";\n");\r
+       return sb.toString();\r
+    }\r
 \r
     public Configuration getParentConfiguration() {\r
         return this.parentConfiguration;\r
     }\r
+    \r
+    /**\r
+     * Return the list of the defined redeclarations for this module instance.\r
+     * \r
+     * @return List of the defined redeclarations or an empty list if redeclarations have not been set \r
+     */\r
+    public List<Redeclaration> getRedeclarations() {\r
+       if(redeclarations == null) {\r
+               redeclarations = new ArrayList<Redeclaration>();\r
+       }\r
+       return redeclarations;\r
+    }\r
 \r
 }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java
new file mode 100644 (file)
index 0000000..7cddf5a
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************************************\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.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElement;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/Redeclaration")\r
+public class Redeclaration {\r
+       \r
+    @RelatedElement("http://www.simantics.org/Sysdyn-1.0/ReplacedEnumeration")\r
+    private Enumeration replacedEnumeration;\r
+    \r
+    @RelatedElement("http://www.simantics.org/Sysdyn-1.0/ReplacingEnumeration")\r
+    private Enumeration replacingEnumeration;\r
+    \r
+    public String getRedeclaration() {\r
+       if(replacedEnumeration == null || replacingEnumeration == null) {\r
+               return "";\r
+       }\r
+       StringBuilder sb = new StringBuilder();\r
+       sb.append("redeclare type ");\r
+       sb.append(replacedEnumeration.getName());\r
+       sb.append(" = ");\r
+       sb.append(replacingEnumeration.getEnumerationDefinition());\r
+       \r
+       return sb.toString();\r
+    }\r
+\r
+}\r
index ed8e9f8dda70277052314b43c2c4ae5e1a9ead39..29a78badef08efb1ea7a6fbe70a6d961b7294c7a 100644 (file)
@@ -49,6 +49,7 @@ public class SysdynSchema extends SimpleSchema {
             addLinkType(MappingSchemas.fromAnnotations(g, ConstantExpression.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, WithLookupExpression.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, LookupExpression.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, Redeclaration.class));\r
             \r
             \r
         } catch (DatabaseException e) {\r