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=74ae599e3797f6a06d9c07f2c9ed6bc7d4789843;hp=0afdb03b7222c1f0d5f95fb8cc3c51c0d082bdb1;hb=4e402f51b0e34d40c3f9d33a4bec7feffeb8d339;hpb=1dfeb7d5c49b1391cd9d877e1eddab18995cb151 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 0afdb03b7..74ae599e3 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 @@ -11,8 +11,6 @@ *******************************************************************************/ package org.simantics.modeling.userComponent; -import gnu.trove.map.hash.THashMap; - import java.util.Map; import org.simantics.databoard.Bindings; @@ -47,6 +45,8 @@ import org.simantics.structural2.utils.StructuralUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import gnu.trove.map.hash.THashMap; + public class ComponentTypeCommands { private static final Logger LOGGER = LoggerFactory.getLogger(ComponentTypeCommands.class); @@ -334,24 +334,28 @@ public class ComponentTypeCommands { return; } - Datatype dt = graph.getDataType(object); - if (dt instanceof NumberType) { - NumberType nt = (NumberType) dt; - Binding ntb = Bindings.getBindingUnchecked(Datatype.class); - nt.setUnit(unit); - - Layer0 L0 = Layer0.getInstance(graph); - Layer0X L0X = Layer0X.getInstance(graph); - - String oldUnit = graph.getPossibleRelatedValue2(relation, L0X.HasUnit, Bindings.STRING); + Layer0 L0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + boolean hasRequiresDataType = graph.hasStatement(relation, L0X.RequiresDataType); + if (hasRequiresDataType) { + Datatype dt = graph.getDataType(object); + if (dt instanceof NumberType) { + NumberType nt = (NumberType) Bindings.DATATYPE.cloneUnchecked(dt); + nt.setUnit(unit); + graph.claimLiteral(object, L0.HasDataType, L0.DataType, nt, Bindings.DATATYPE); + graph.claimLiteral(relation, L0X.RequiresDataType, L0.DataType, nt, Bindings.DATATYPE); + } + } - graph.claimLiteral(object, L0.HasDataType, L0.DataType, nt, ntb); - graph.claimLiteral(relation, L0X.RequiresDataType, L0.DataType, nt, ntb); - graph.claimLiteral(relation, L0X.HasUnit, unit, Bindings.STRING); - - CommentMetadata cm = graph.getMetadata(CommentMetadata.class); - graph.addMetadata(cm.add("Setted unit from " + oldUnit + " to " + unit + " for component/annotation " + type)); + String oldUnit = graph.getPossibleRelatedValue2(relation, L0X.HasUnit, Bindings.STRING); + if (unit != null) { + graph.claimLiteral(relation, L0X.HasUnit, L0.String, unit, Bindings.STRING); + } else { + graph.denyValue(relation, L0X.HasUnit); } + + CommentMetadata cm = graph.getMetadata(CommentMetadata.class); + graph.addMetadata(cm.add("Set unit from " + oldUnit + " to " + unit + " for component/annotation " + type + " property " + relation)); } /**