X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FuserComponent%2FComponentTypeCommands.java;h=9cf93fac5ce83d9067b99d7ebbb7e0da6a272f63;hp=c92d80c848cec727999d467fefa167ee792fd3a5;hb=b000e272429e157638c0384878b07b8dcd758472;hpb=a175b74181c4841b403170f03e1ad9caac946f53 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/ComponentTypeCommands.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/ComponentTypeCommands.java index c92d80c84..9cf93fac5 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/ComponentTypeCommands.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/ComponentTypeCommands.java @@ -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 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 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 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.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;