]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Special handling to retain the range of derived properties on type edit
authorJussi Koskela <jussi.koskela@semantum.fi>
Tue, 20 Oct 2020 08:53:33 +0000 (11:53 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 20 Oct 2020 10:19:32 +0000 (13:19 +0300)
gitlab #621

(cherry picked from commit 29134895c5e5ff382d765afda633170d567935cd)

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java
bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/ComponentTypeCommands.java

index 73b09f7bf431776352fc30dc6ad540b5a5255dff..4b9ffbe801f6785e8782a006684b15f191db8b27 100644 (file)
@@ -53,6 +53,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.function.DbConsumer;
 import org.simantics.db.layer0.QueryIndexUtils;
 import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
 import org.simantics.modeling.userComponent.ComponentTypeCommands;
 import org.simantics.modeling.utils.ComponentTypeViewerPropertyInfo;
 import org.simantics.scl.runtime.function.Function2;
@@ -265,34 +266,43 @@ public class ComponentTypeViewerData {
                         String newValue2 = newValue;
 
                         Resource possibleGraphType = null;
-                        Resource root = graph.syncRequest(new IndexRoot(componentType));
 
-                        Resource L0Res = graph.getResource("http://www.simantics.org/Layer0-1.1");
                         Layer0 L0 = Layer0.getInstance(graph);
-
-                        Collection<Resource> graphTypes1 = QueryIndexUtils.searchByTypeAndName(graph, L0Res, L0.ValueType, newValue);
-                        Collection<Resource> graphTypes2 = QueryIndexUtils.searchByTypeAndName(graph, root, L0.ValueType, newValue);
-
-                        Collection<Resource> graphTypes = new HashSet<>(graphTypes1);
-                        graphTypes.addAll(graphTypes2);
-
-                        Set<Pair<Resource, String>> candidates = new HashSet<>();
-                        for (Resource graphType : graphTypes) {
-                            Collection<Statement> stms = graph.getAssertedStatements(graphType, L0.HasValueType);
-                            if(stms.size() == 1) {
-                                // Only accept valueType if it asserts HasValueType with the same name
-                                String hasValueType = graph.getValue(stms.iterator().next().getObject(), Bindings.STRING);
-                                if (hasValueType.equals(newValue)) {
-                                    candidates.add(new Pair<>(graphType, hasValueType));
+                        ModelingResources MOD = ModelingResources.getInstance(graph);
+
+                        Resource previousRange = graph.getPossibleObject(propertyInfo.resource, L0.HasRange);
+                        if (previousRange != null && graph.isInheritedFrom(previousRange, MOD.MonitorValue)) {
+                            // Do not override range of derived properties
+                            possibleGraphType = previousRange;
+                        } else {
+                            Resource root = graph.syncRequest(new IndexRoot(componentType));
+
+                            Resource L0Res = graph.getResource("http://www.simantics.org/Layer0-1.1");
+
+                            Collection<Resource> graphTypes1 = QueryIndexUtils.searchByTypeAndName(graph, L0Res, L0.ValueType, newValue);
+                            Collection<Resource> graphTypes2 = QueryIndexUtils.searchByTypeAndName(graph, root, L0.ValueType, newValue);
+
+                            Collection<Resource> graphTypes = new HashSet<>(graphTypes1);
+                            graphTypes.addAll(graphTypes2);
+
+                            Set<Pair<Resource, String>> candidates = new HashSet<>();
+                            for (Resource graphType : graphTypes) {
+                                Collection<Statement> stms = graph.getAssertedStatements(graphType, L0.HasValueType);
+                                if(stms.size() == 1) {
+                                    // Only accept valueType if it asserts HasValueType with the same name
+                                    String hasValueType = graph.getValue(stms.iterator().next().getObject(), Bindings.STRING);
+                                    if (hasValueType.equals(newValue)) {
+                                        candidates.add(new Pair<>(graphType, hasValueType));
+                                    }
                                 }
                             }
-                        }
 
-                        // We support only graph types with unique name at this point. Later we could implement UI to let the user to select from multiple graph types.
-                        if (candidates.size() == 1) {
-                            Pair<Resource, String> result = candidates.iterator().next();
-                            possibleGraphType = result.first;
-                            newValue2 = result.second;
+                            // We support only graph types with unique name at this point. Later we could implement UI to let the user to select from multiple graph types.
+                            if (candidates.size() == 1) {
+                                Pair<Resource, String> result = candidates.iterator().next();
+                                possibleGraphType = result.first;
+                                newValue2 = result.second;
+                            }
                         }
 
                         ComponentTypeCommands.editType(graph, componentType, propertyInfo.resource, convertDefaultValue, newValue2, possibleGraphType);
index 9cf93fac5ce83d9067b99d7ebbb7e0da6a272f63..de8591d5f5e037e96d97055ed01a66808bfd3b9f 100644 (file)
@@ -209,6 +209,7 @@ public class ComponentTypeCommands {
     public static void setRequiredType(WriteGraph g, Resource componentType, Resource property,
             String requiredType, Resource possibleType) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(g);
+        ModelingResources MOD = ModelingResources.getInstance(g);
         g.claimLiteral(property, L0.RequiresValueType, requiredType);
 
         if (componentType != null) {
@@ -229,6 +230,9 @@ public class ComponentTypeCommands {
             if(g.hasStatement(possibleType, L0.Enumeration)) {
                 // This value type is an enumeration - let's constrain the range of this predicate to match the enumeration type only
                 g.claim(property, L0.HasRange, possibleType);
+            } else if (g.isInheritedFrom(possibleType, MOD.MonitorValue)) {
+                // Support derived properties
+                g.claim(property, L0.HasRange, possibleType);
             }
         }