]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/ComponentTypeCommands.java
Merge changes I78c3a258,I7bf72f04
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / userComponent / ComponentTypeCommands.java
index c92d80c848cec727999d467fefa167ee792fd3a5..9cf93fac5ce83d9067b99d7ebbb7e0da6a272f63 100644 (file)
@@ -223,7 +223,7 @@ public class ComponentTypeCommands {
         // We assert the range of the property only if we are given a dedicated graph value type
         if(g.hasStatement(property, L0.HasRange))
             g.deny(property, L0.HasRange);
-        
+
         if(possibleType != null) {
             // We have a dedicated graph type for this SCL value type
             if(g.hasStatement(possibleType, L0.Enumeration)) {
@@ -297,28 +297,28 @@ public class ComponentTypeCommands {
             return;
         }
 
-       Layer0 L0 = Layer0.getInstance(g);
-       Resource range = g.getPossibleObject(relation, L0.HasRange);
-       if (range != null) {
+        Layer0 L0 = Layer0.getInstance(g);
+        Resource range = g.getPossibleObject(relation, L0.HasRange);
+        if (range != null) {
             if(g.hasStatement(range, L0.Enumeration)) {
-                   Map<String,Resource> values = g.syncRequest(new EnumerationMap(range));
-                   Resource value = values.get(valueText);
-                   if (value != null) {
-                       for(Resource assertion : g.getObjects(type, L0.Asserts)) {
-                           Resource p = g.getSingleObject(assertion, L0.HasPredicate);
-                           if (p.equals(relation)) {
-                               g.deny(assertion, L0.HasObject, object);
-                               g.claim(assertion, L0.HasObject, value);
-                           }
-                       }
-                   }
-                   return;
+                Map<String,Resource> values = g.syncRequest(new EnumerationMap(range));
+                Resource value = values.get(valueText);
+                if (value != null) {
+                    for(Resource assertion : g.getObjects(type, L0.Asserts)) {
+                        Resource p = g.getSingleObject(assertion, L0.HasPredicate);
+                        if (p.equals(relation)) {
+                            g.deny(assertion, L0.HasObject, object);
+                            g.claim(assertion, L0.HasObject, value);
+                        }
+                    }
+                }
+                return;
             }
         }
         
         if(valueText.length() > 0 && valueText.charAt(0) == '=') {
                
-            String expression = valueText.substring(1);
+               String expression = valueText.substring(1);
                ModelingResources MOD = ModelingResources.getInstance(g);
                if(!g.isInstanceOf(object, MOD.SCLValue)) {
                        Resource assertion = g.getSingleObject(object, L0.HasObjectInverse);
@@ -477,7 +477,7 @@ public class ComponentTypeCommands {
         }
         return null;
     }
-    
+
     public static void convertDefaultValue(WriteGraph g,
             Resource type, Resource relation, String newSCLType, Resource possibleType) throws DatabaseException {
         Resource object = getAssertedObject(g, type, relation);
@@ -494,7 +494,7 @@ public class ComponentTypeCommands {
                     Map<String, Resource> enumMap = g.syncRequest(new EnumerationMap(possibleType));
                     String firstKey = Collections.min(enumMap.keySet(), AlphanumComparator.COMPARATOR);
                     Resource defaultValue = enumMap.get(firstKey);
-                    
+
                     if (defaultValue != null) {
                         Resource assertion = findAssertionWithPO(g, type, relation, object);
                         if(assertion != null) {
@@ -506,6 +506,8 @@ public class ComponentTypeCommands {
                             return;
                         }
                     }
+                } else {
+                       return;
                 }
             }
         }
@@ -514,6 +516,16 @@ public class ComponentTypeCommands {
         if (tuple == null)
             return;
 
+        if(g.sync(new IsEnumeratedValue(object))) {
+            Resource assertion = findAssertionWithPO(g, type, relation, object);
+            object = g.newResource();
+            g.claim(object, L0.InstanceOf, L0.Literal);
+            if(assertion != null) {
+                g.deny(assertion, L0.HasObject);
+                g.claim(assertion, L0.HasObject, object);
+            }
+        }
+
         g.claimLiteral(object, L0.HasDataType, L0.DataType, tuple.get(0), Bindings.getBindingUnchecked(Datatype.class));
         g.claimLiteral(object, L0.HasValueType, g.<String>getRelatedValue(relation, L0.RequiresValueType, Bindings.STRING), Bindings.STRING);
         g.claimValue(object, tuple.get(1), (Binding)tuple.get(2));
@@ -523,7 +535,7 @@ public class ComponentTypeCommands {
     public static void convertInstantiatedValue(WriteGraph g, Resource instance, Resource relation, String newSCLType) throws DatabaseException {
        convertInstantiatedValue(g, instance, relation, newSCLType, null);
     }
-    
+
     public static void convertInstantiatedValue(WriteGraph g, Resource instance, Resource relation, String newSCLType, Resource possibleType)
             throws DatabaseException {
 
@@ -531,14 +543,14 @@ public class ComponentTypeCommands {
         if(stm != null && !stm.isAsserted(instance)) {
 
             Layer0 L0 = Layer0.getInstance(g);
-               Resource object = stm.getObject();
+            Resource object = stm.getObject();
 
-               if(g.sync(new IsEnumeratedValue(object))) {
-                       if(!g.isInstanceOf(object, possibleType)) {
-                               g.deny(instance, relation);
-                       }
-                       return;
-               }
+            if(g.sync(new IsEnumeratedValue(object))) {
+                if(!g.isInstanceOf(object, possibleType)) {
+                    g.deny(instance, relation);
+                }
+                return;
+            }
 
             // We can only convert literals
             if(!g.isInstanceOf(object, L0.Literal)) return;