]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Enumeration issue source for checking that an enumeration is not empty (refs #3048)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 10 Oct 2012 10:32:47 +0000 (10:32 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 10 Oct 2012 10:32:47 +0000 (10:32 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25965 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Validation.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/EnumerationFunction.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/Functions.java

index cbaba95479de9af40b8d2f579f32b74a5948d811..0475c6b5589ce60083775c487e276ca8a6701b57 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index 72162a7601048e64da26613d792ea70e5a5a70df..363c9d29ffe398eab743b4ee2d4bb1e5add97430 100644 (file)
@@ -10,17 +10,21 @@ SYSDYN.SysdynIssue <T ISSUE.Issue
 // BASEFUNCTION\r
 VALIDATIONS.Functions : L0.Library\r
 VALIDATIONS.Functions.baseRealizationFunction : L0.Function\r
+VALIDATIONS.Functions.path : L0.Function\r
+   L0.HasValueType "String"  \r
 \r
 // DEPENDENCIES\r
 VALIDATIONS.Dependencies : L0.Library\r
 VALIDATIONS.Dependencies.dependencyValidator : L0.Function\r
 VALIDATIONS.Dependencies.missingDependencyValidator : L0.Function\r
-VALIDATIONS.Dependencies.dependencySynchronizer : L0.Function\r
   \r
 // EXPRESSIONS  \r
 VALIDATIONS.Expressions : L0.Library\r
 VALIDATIONS.Expressions.expressionValidator : L0.Function\r
-VALIDATIONS.Expressions.expressionSynchronizer : L0.Function\r
+\r
+// ENUMERATIONS\r
+VALIDATIONS.Enumerations : L0.Library\r
+VALIDATIONS.Enumerations.enumerationIndexValidator : L0.Function\r
 \r
 SYSDYN.Variable\r
     @VALIDATIONS.constraint\r
@@ -35,6 +39,13 @@ SYSDYN.Variable
         VALIDATIONS.Dependencies.DependencyConnectionsIssueSource\r
         VALIDATIONS.Dependencies.dependencyValidator \r
         VALIDATIONS.Functions.baseRealizationFunction \r
+        \r
+SYSDYN.Enumeration\r
+    @VALIDATIONS.constraint\r
+        VALIDATIONS.EnumerationConstraint\r
+        VALIDATIONS.Enumerations.EnumerationIssueSource \r
+        VALIDATIONS.Enumerations.enumerationIndexValidator \r
+        VALIDATIONS.Functions.baseRealizationFunction         \r
 \r
 SYSDYN.Variable\r
     @VALIDATIONS.listeningConstraint\r
@@ -48,24 +59,35 @@ VALIDATIONS.ExpressionIssue
         ISSUE.Severity.Error\r
         VALIDATIONS.Expressions.expressionIssueDescription : L0.Function\r
             L0.HasValueType "String"\r
+        VALIDATIONS.Functions.path\r
                     \r
 VALIDATIONS.MissingLinkIssue\r
     @VALIDATIONS.issue\r
         ISSUE.Severity.Warning\r
         VALIDATIONS.Dependencies.missingLinkIssueDescription : L0.Function\r
             L0.HasValueType "String"\r
+        VALIDATIONS.Functions.path\r
                     \r
 VALIDATIONS.UnusedDependencyIssue\r
     @VALIDATIONS.issue\r
         ISSUE.Severity.Warning\r
         VALIDATIONS.Dependencies.unusedDependencyIssueDescription : L0.Function   \r
             L0.HasValueType "String"\r
+        VALIDATIONS.Functions.path\r
                     \r
 VALIDATIONS.NoSuchVariableIssue\r
     @VALIDATIONS.issue\r
         ISSUE.Severity.Error\r
         VALIDATIONS.Dependencies.noSuchVariableIssueDescription : L0.Function     \r
-            L0.HasValueType "String"         \r
+            L0.HasValueType "String"\r
+        VALIDATIONS.Functions.path\r
+            \r
+VALIDATIONS.EmptyEnumerationIssue\r
+    @VALIDATIONS.issue\r
+        ISSUE.Severity.Error\r
+        VALIDATIONS.Enumerations.emptyEnumerationIssueDescription : L0.Function\r
+            L0.HasValueType "String"\r
+        VALIDATIONS.Functions.path                 \r
 \r
 // IssueSource template\r
 VALIDATIONS.constraint : L0.Template\r
@@ -103,11 +125,14 @@ VALIDATIONS.listeningConstraint : L0.Template
 \r
 // Issue template\r
 VALIDATIONS.issue : L0.Template\r
-    @template %issue %severity %description\r
+    @template %issue %severity %description %path\r
         %issue <T ISSUE.Sources.DependencyTracker.Issue\r
             L0.Asserts _ : L0.Assertion\r
                 L0.HasPredicate ISSUE.Issue.HasSeverity\r
                 L0.HasObject %severity\r
             L0.Asserts _ : L0.Assertion\r
                 L0.HasPredicate L0.HasDescription\r
-                L0.HasObject %description
\ No newline at end of file
+                L0.HasObject %description\r
+            L0.Asserts _ : L0.Assertion\r
+                L0.HasPredicate ISSUE.Issue.path\r
+                L0.HasObject %path                
\ No newline at end of file
index 9f5769ef8d10569f2ae925126f9fc622dafe3a60..4f061c5198fe9bc482704c842ff4319dca121ca4 100644 (file)
@@ -320,22 +320,27 @@ public class SysdynResource {
     public final Resource Validations_Dependencies;\r
     public final Resource Validations_Dependencies_DependencyConnectionsIssueSource;\r
     public final Resource Validations_Dependencies_MissingDependencyConnectionsIssueSource;\r
-    public final Resource Validations_Dependencies_dependencySynchronizer;\r
     public final Resource Validations_Dependencies_dependencyValidator;\r
     public final Resource Validations_Dependencies_missingDependencyValidator;\r
     public final Resource Validations_Dependencies_missingLinkIssueDescription;\r
     public final Resource Validations_Dependencies_noSuchVariableIssueDescription;\r
     public final Resource Validations_Dependencies_unusedDependencyIssueDescription;\r
     public final Resource Validations_DependencyConstraint;\r
+    public final Resource Validations_EmptyEnumerationIssue;\r
+    public final Resource Validations_EnumerationConstraint;\r
+    public final Resource Validations_Enumerations;\r
+    public final Resource Validations_Enumerations_EnumerationIssueSource;\r
+    public final Resource Validations_Enumerations_emptyEnumerationIssueDescription;\r
+    public final Resource Validations_Enumerations_enumerationIndexValidator;\r
     public final Resource Validations_ExpressionConstraint;\r
     public final Resource Validations_ExpressionIssue;\r
     public final Resource Validations_Expressions;\r
     public final Resource Validations_Expressions_ExpressionIssueSource;\r
     public final Resource Validations_Expressions_expressionIssueDescription;\r
-    public final Resource Validations_Expressions_expressionSynchronizer;\r
     public final Resource Validations_Expressions_expressionValidator;\r
     public final Resource Validations_Functions;\r
     public final Resource Validations_Functions_baseRealizationFunction;\r
+    public final Resource Validations_Functions_path;\r
     public final Resource Validations_MissingDependencyConstraint;\r
     public final Resource Validations_MissingLinkIssue;\r
     public final Resource Validations_NoSuchVariableIssue;\r
@@ -697,22 +702,27 @@ public class SysdynResource {
         public static final String Validations_Dependencies = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies";\r
         public static final String Validations_Dependencies_DependencyConnectionsIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/DependencyConnectionsIssueSource";\r
         public static final String Validations_Dependencies_MissingDependencyConnectionsIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/MissingDependencyConnectionsIssueSource";\r
-        public static final String Validations_Dependencies_dependencySynchronizer = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/dependencySynchronizer";\r
         public static final String Validations_Dependencies_dependencyValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/dependencyValidator";\r
         public static final String Validations_Dependencies_missingDependencyValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/missingDependencyValidator";\r
         public static final String Validations_Dependencies_missingLinkIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/missingLinkIssueDescription";\r
         public static final String Validations_Dependencies_noSuchVariableIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/noSuchVariableIssueDescription";\r
         public static final String Validations_Dependencies_unusedDependencyIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/unusedDependencyIssueDescription";\r
         public static final String Validations_DependencyConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/DependencyConstraint";\r
+        public static final String Validations_EmptyEnumerationIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/EmptyEnumerationIssue";\r
+        public static final String Validations_EnumerationConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/EnumerationConstraint";\r
+        public static final String Validations_Enumerations = "http://www.simantics.org/Sysdyn-1.1/Validations/Enumerations";\r
+        public static final String Validations_Enumerations_EnumerationIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Enumerations/EnumerationIssueSource";\r
+        public static final String Validations_Enumerations_emptyEnumerationIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Enumerations/emptyEnumerationIssueDescription";\r
+        public static final String Validations_Enumerations_enumerationIndexValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Enumerations/enumerationIndexValidator";\r
         public static final String Validations_ExpressionConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/ExpressionConstraint";\r
         public static final String Validations_ExpressionIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/ExpressionIssue";\r
         public static final String Validations_Expressions = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions";\r
         public static final String Validations_Expressions_ExpressionIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions/ExpressionIssueSource";\r
         public static final String Validations_Expressions_expressionIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions/expressionIssueDescription";\r
-        public static final String Validations_Expressions_expressionSynchronizer = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions/expressionSynchronizer";\r
         public static final String Validations_Expressions_expressionValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions/expressionValidator";\r
         public static final String Validations_Functions = "http://www.simantics.org/Sysdyn-1.1/Validations/Functions";\r
         public static final String Validations_Functions_baseRealizationFunction = "http://www.simantics.org/Sysdyn-1.1/Validations/Functions/baseRealizationFunction";\r
+        public static final String Validations_Functions_path = "http://www.simantics.org/Sysdyn-1.1/Validations/Functions/path";\r
         public static final String Validations_MissingDependencyConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/MissingDependencyConstraint";\r
         public static final String Validations_MissingLinkIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/MissingLinkIssue";\r
         public static final String Validations_NoSuchVariableIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/NoSuchVariableIssue";\r
@@ -1084,22 +1094,27 @@ public class SysdynResource {
         Validations_Dependencies = getResourceOrNull(graph, URIs.Validations_Dependencies);\r
         Validations_Dependencies_DependencyConnectionsIssueSource = getResourceOrNull(graph, URIs.Validations_Dependencies_DependencyConnectionsIssueSource);\r
         Validations_Dependencies_MissingDependencyConnectionsIssueSource = getResourceOrNull(graph, URIs.Validations_Dependencies_MissingDependencyConnectionsIssueSource);\r
-        Validations_Dependencies_dependencySynchronizer = getResourceOrNull(graph, URIs.Validations_Dependencies_dependencySynchronizer);\r
         Validations_Dependencies_dependencyValidator = getResourceOrNull(graph, URIs.Validations_Dependencies_dependencyValidator);\r
         Validations_Dependencies_missingDependencyValidator = getResourceOrNull(graph, URIs.Validations_Dependencies_missingDependencyValidator);\r
         Validations_Dependencies_missingLinkIssueDescription = getResourceOrNull(graph, URIs.Validations_Dependencies_missingLinkIssueDescription);\r
         Validations_Dependencies_noSuchVariableIssueDescription = getResourceOrNull(graph, URIs.Validations_Dependencies_noSuchVariableIssueDescription);\r
         Validations_Dependencies_unusedDependencyIssueDescription = getResourceOrNull(graph, URIs.Validations_Dependencies_unusedDependencyIssueDescription);\r
         Validations_DependencyConstraint = getResourceOrNull(graph, URIs.Validations_DependencyConstraint);\r
+        Validations_EmptyEnumerationIssue = getResourceOrNull(graph, URIs.Validations_EmptyEnumerationIssue);\r
+        Validations_EnumerationConstraint = getResourceOrNull(graph, URIs.Validations_EnumerationConstraint);\r
+        Validations_Enumerations = getResourceOrNull(graph, URIs.Validations_Enumerations);\r
+        Validations_Enumerations_EnumerationIssueSource = getResourceOrNull(graph, URIs.Validations_Enumerations_EnumerationIssueSource);\r
+        Validations_Enumerations_emptyEnumerationIssueDescription = getResourceOrNull(graph, URIs.Validations_Enumerations_emptyEnumerationIssueDescription);\r
+        Validations_Enumerations_enumerationIndexValidator = getResourceOrNull(graph, URIs.Validations_Enumerations_enumerationIndexValidator);\r
         Validations_ExpressionConstraint = getResourceOrNull(graph, URIs.Validations_ExpressionConstraint);\r
         Validations_ExpressionIssue = getResourceOrNull(graph, URIs.Validations_ExpressionIssue);\r
         Validations_Expressions = getResourceOrNull(graph, URIs.Validations_Expressions);\r
         Validations_Expressions_ExpressionIssueSource = getResourceOrNull(graph, URIs.Validations_Expressions_ExpressionIssueSource);\r
         Validations_Expressions_expressionIssueDescription = getResourceOrNull(graph, URIs.Validations_Expressions_expressionIssueDescription);\r
-        Validations_Expressions_expressionSynchronizer = getResourceOrNull(graph, URIs.Validations_Expressions_expressionSynchronizer);\r
         Validations_Expressions_expressionValidator = getResourceOrNull(graph, URIs.Validations_Expressions_expressionValidator);\r
         Validations_Functions = getResourceOrNull(graph, URIs.Validations_Functions);\r
         Validations_Functions_baseRealizationFunction = getResourceOrNull(graph, URIs.Validations_Functions_baseRealizationFunction);\r
+        Validations_Functions_path = getResourceOrNull(graph, URIs.Validations_Functions_path);\r
         Validations_MissingDependencyConstraint = getResourceOrNull(graph, URIs.Validations_MissingDependencyConstraint);\r
         Validations_MissingLinkIssue = getResourceOrNull(graph, URIs.Validations_MissingLinkIssue);\r
         Validations_NoSuchVariableIssue = getResourceOrNull(graph, URIs.Validations_NoSuchVariableIssue);\r
index 0bc575095aee9c58f57ed5a95da7b69b6a2da0d8..1d503d025d6c3dc6b57ab5c02030192108fecd15 100644 (file)
@@ -86,24 +86,6 @@ public class NewModuleTypeAction implements ActionFactory{
                             }\r
                         }\r
 \r
-                        GraphUtils.create2(g,\r
-                                sr.Validations_Dependencies_MissingDependencyConnectionsIssueSource,\r
-                                L0X.IsActivatedBy, model,\r
-                                l0.PartOf, moduleType\r
-                                );\r
-\r
-                        GraphUtils.create2(g,\r
-                                sr.Validations_Dependencies_DependencyConnectionsIssueSource,\r
-                                L0X.IsActivatedBy, model,\r
-                                l0.PartOf, moduleType\r
-                                );\r
-\r
-                        GraphUtils.create2(g,\r
-                                sr.Validations_Expressions_ExpressionIssueSource,\r
-                                L0X.IsActivatedBy, model,\r
-                                l0.PartOf, moduleType\r
-                                );\r
-\r
                         Resource mapping = g.newResource();\r
                         g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
                         g.claim(diagram, L0X.HasTrigger, mapping);\r
index c86acfa803830c671d28c84b69eea250f49f30af..2a1296e7377e98959a266bf75c8a2c1b5c783e03 100644 (file)
@@ -42,6 +42,8 @@ import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.operation.Layer0X;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -157,6 +159,7 @@ public class ImportModelHandler extends AbstractHandler {
                                                } else {\r
                                                        fixHasTailAndHasHead(graph, ModelRoot);\r
                                                        addDependencies(graph, ModelRoot);\r
+                                                       addEnumerationIssueSource(graph, ModelRoot);\r
                                                }\r
                                        }\r
 \r
@@ -191,6 +194,19 @@ public class ImportModelHandler extends AbstractHandler {
                }\r
        }\r
 \r
+       protected void addEnumerationIssueSource(WriteGraph graph, Resource modelRoot) throws DatabaseException {\r
+           Layer0 L0 = Layer0.getInstance(graph);\r
+           Layer0X L0X = Layer0X.getInstance(graph); \r
+           SysdynResource sr = SysdynResource.getInstance(graph);\r
+           Collection<Resource> enumerationIssueSources = graph.syncRequest(new ObjectsWithType(modelRoot, L0.ConsistsOf, sr.Validations_Enumerations_EnumerationIssueSource));\r
+        if(enumerationIssueSources.isEmpty()) {\r
+            GraphUtils.create2(graph,\r
+                    sr.Validations_Enumerations_EnumerationIssueSource,\r
+                    L0X.IsActivatedBy, modelRoot,\r
+                    L0.PartOf, modelRoot\r
+                    );  \r
+        }      }\r
+\r
        protected void fixHasTailAndHasHead(WriteGraph graph, Resource modelRoot) throws DatabaseException {\r
                Layer0 L0 = Layer0.getInstance(graph);\r
                SysdynResource sr = SysdynResource.getInstance(graph);\r
@@ -214,20 +230,36 @@ public class ImportModelHandler extends AbstractHandler {
        }\r
        \r
        private Collection<Resource> findAllConfigurations(ReadGraph graph, Resource modelRoot) throws DatabaseException {\r
-               Layer0 L0 = Layer0.getInstance(graph);\r
                SysdynResource sr = SysdynResource.getInstance(graph);\r
                StructuralResource2 SR2 = StructuralResource2.getInstance(graph);\r
+               Collection<Resource> modulesAndModels = findAllModelsAndModules(graph, modelRoot);\r
                Collection<Resource> configurations = new ArrayList<Resource>();\r
-               configurations.add(graph.getPossibleObject(modelRoot, SimulationResource.getInstance(graph).HasConfiguration));\r
 \r
-               for(Resource r : graph.getObjects(modelRoot, L0.ConsistsOf)) {\r
+               for(Resource r : modulesAndModels) {\r
                        if(graph.isInheritedFrom(r, sr.Module)) {\r
                                configurations.add(graph.getPossibleObject(r, SR2.IsDefinedBy));\r
+                       } else if(graph.isInstanceOf(r, sr.SysdynModel)) {\r
+                        configurations.add(graph.getPossibleObject(modelRoot, SimulationResource.getInstance(graph).HasConfiguration));\r
                        }\r
                }\r
                \r
                return configurations;\r
        }\r
+       \r
+          private Collection<Resource> findAllModelsAndModules(ReadGraph graph, Resource modelRoot) throws DatabaseException {\r
+               Layer0 L0 = Layer0.getInstance(graph);\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Collection<Resource> modelsAndModules = new ArrayList<Resource>();\r
+               modelsAndModules.add(modelRoot);\r
+\r
+               for(Resource r : graph.getObjects(modelRoot, L0.ConsistsOf)) {\r
+                   if(graph.isInheritedFrom(r, sr.Module)) {\r
+                       modelsAndModules.add(r);\r
+                   }\r
+               }\r
+               \r
+               return modelsAndModules;\r
+           }\r
  \r
        private void displayErrorMessage(Shell shell, String message) {\r
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
index 6bfc3767f2c9d135d7027e8b9658874efac03d54..3aa9e5f7977062bb31cc7f373d6640f8ba9d18c7 100644 (file)
@@ -99,24 +99,6 @@ public class NewModuleNodeHandler extends AbstractHandler {
                        }\r
                 }\r
                 \r
-                GraphUtils.create2(g,\r
-                        sr.Validations_Dependencies_MissingDependencyConnectionsIssueSource,\r
-                        L0X.IsActivatedBy, model,\r
-                        l0.PartOf, moduleType\r
-                        );\r
-                \r
-                GraphUtils.create2(g,\r
-                        sr.Validations_Dependencies_DependencyConnectionsIssueSource,\r
-                        L0X.IsActivatedBy, model,\r
-                        l0.PartOf, moduleType\r
-                        );\r
-                \r
-                GraphUtils.create2(g,\r
-                        sr.Validations_Expressions_ExpressionIssueSource,\r
-                        L0X.IsActivatedBy, model,\r
-                        l0.PartOf, moduleType\r
-                        );\r
-                \r
                 Resource mapping = g.newResource();\r
                 g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
                 g.claim(diagram, L0X.HasTrigger, mapping);\r
index b0d6197beb31b58a1dcf03137b25e306582e64aa..60b4280de5bdfdaf9b73eadacfc6805e1b6a53d2 100644 (file)
@@ -90,6 +90,12 @@ public class ModelUtils {
                     L0X.IsActivatedBy, model,\r
                     l0.PartOf, model\r
                     );\r
+            \r
+            GraphUtils.create2(g,\r
+                    sr.Validations_Enumerations_EnumerationIssueSource,\r
+                    L0X.IsActivatedBy, model,\r
+                    l0.PartOf, model\r
+                    );            \r
 \r
             Resource conf = GraphUtils.create2(g,\r
                     sr.Configuration,\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/EnumerationFunction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/EnumerationFunction.java
new file mode 100644 (file)
index 0000000..21e9bb9
--- /dev/null
@@ -0,0 +1,66 @@
+/*******************************************************************************\r
+ * Copyright (c) 2012 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.validation;\r
+\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import org.simantics.db.Issue;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\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.issues.common.StandardIssue;\r
+import org.simantics.scl.reflection.annotations.SCLValue;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Functions for checking issues in Enumerations\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class EnumerationFunction  {\r
+\r
+    private static String NO_INDEXES = "Enumeration does not contain indexes.";\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> [Issue]")\r
+    public static List<Issue> enumerationIndexValidator(ReadGraph graph, Resource component) throws DatabaseException {\r
+\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+        if(!graph.isInstanceOf(component, sr.Enumeration)) {\r
+            return Collections.emptyList();\r
+        }\r
+\r
+        boolean noIndexes = false;\r
+\r
+        try {\r
+            Resource indexList = graph.getPossibleObject(component, sr.Enumeration_enumerationIndexes);\r
+            List<Resource> indexes = OrderedSetUtils.toList(graph, indexList);\r
+            if(indexes.size() == 0)\r
+                noIndexes = true;\r
+        } catch (DatabaseException e) {\r
+            noIndexes = true;\r
+        }\r
+\r
+        if(noIndexes)\r
+            return Collections.<Issue>singletonList(new StandardIssue(sr.Validations_EmptyEnumerationIssue, component));\r
+        else\r
+            return Collections.emptyList();\r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+    public static String emptyEnumerationIssueDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {\r
+        return NO_INDEXES;\r
+    }\r
+}\r
index 78128ff2608c7c2c8b7fb2ba192a5fbc7b1864ba..d53a9128b2127af7c690a4af9d239365e65109ac 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.validation;\r
 \r
+import java.util.List;\r
+\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.db.layer0.variable.Variable;\r
+import org.simantics.issues.common.IssueUtils;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.project.ontology.ProjectResource;\r
 import org.simantics.scl.reflection.annotations.SCLValue;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
@@ -37,4 +44,35 @@ public class Functions {
         else return null;\r
 \r
     }\r
+\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+    public static String path(ReadGraph graph, Resource source, Variable property) throws DatabaseException {\r
+        List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);\r
+        if (contexts.size() > 0) {\r
+            Resource component = contexts.get(0);\r
+            Layer0 L0 = Layer0.getInstance(graph);\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            ProjectResource PROJECT = ProjectResource.getInstance(graph);\r
+            StringBuilder sb = new StringBuilder("");\r
+            Resource parent = graph.getPossibleObject(component, L0.PartOf);\r
+            boolean first = true;\r
+            while(parent != null && !graph.isInstanceOf(parent, PROJECT.Project)) {\r
+                if(!graph.isInstanceOf(parent, sr.Configuration)) {\r
+                    String name = NameUtils.getSafeName(graph, parent);\r
+                    if(first) {\r
+                        sb.append(name);\r
+                        first = false;\r
+                    } else {\r
+                        sb.insert(0, "/");\r
+                        sb.insert(0, name);\r
+                    }\r
+                }\r
+                parent = graph.getPossibleObject(parent, L0.PartOf);\r
+            }\r
+            return sb.toString();\r
+        } else {\r
+            return "";\r
+        }\r
+    }\r
 }\r