From 72d52b5910e1ed0141b6768ef700e7321ac05553 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Sat, 27 Oct 2018 23:20:29 +0300 Subject: [PATCH] Added editable unit for derived properties gitlab #161 Change-Id: I81a7dc60fa0c4d4173dbfa128a509e7e2bfa18e9 --- .../ComponentTypeViewerData.java | 2 +- .../ComponentTypeViewerPropertyInfo.java | 15 ++++++-- .../ConfigurationPropertiesSection.java | 16 ++------- .../DerivedPropertiesSection.java | 24 ++++++------- .../userComponent/ComponentTypeCommands.java | 36 +++++++++---------- 5 files changed, 46 insertions(+), 47 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java index e1f179965..ea3f61e80 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java @@ -235,7 +235,7 @@ public class ComponentTypeViewerData { combo.addListener(SWT.Traverse, listener); } - protected void editUnit(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column) { + public void editUnit(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column) { // Disallow unit editing for non-numeric configuration properties if (propertyInfo.numberType == null && propertyInfo.sectionSpecificData == null) return; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerPropertyInfo.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerPropertyInfo.java index 57ba4c462..c5e77383f 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerPropertyInfo.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerPropertyInfo.java @@ -4,6 +4,7 @@ import org.simantics.databoard.annotations.Optional; import org.simantics.databoard.type.NumberType; import org.simantics.db.Resource; import org.simantics.utils.strings.AlphanumComparator; +import org.simantics.utils.strings.StringUtils; public class ComponentTypeViewerPropertyInfo implements Comparable { public Resource resource; @@ -135,6 +136,16 @@ public class ComponentTypeViewerPropertyInfo implements Comparable VALIDATE_MONITOR_EXPRESSION = new Function4() { @Override @@ -155,11 +155,11 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection { }, VALIDATE_MONITOR_EXPRESSION); break; -// case 3: -// editUnit(table2, editor2, propertyInfo, selectedItem, column); -// break; - case 3: + data.editUnit(table, editor, propertyInfo, selectedItem, column); + break; + + case 4: data.editValue(table, editor, propertyInfo, selectedItem, column, propertyInfo.immutable ? null : new StringWriter() { @Override public void perform(WriteGraph graph, String newValue) throws DatabaseException { @@ -170,7 +170,7 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection { }, null); break; - case 4: + case 5: data.editMultilineText(table, editor, propertyInfo, selectedItem, selectedItemBounds, column, new StringWriter() { @Override public void perform(WriteGraph graph, String newValue) throws DatabaseException { @@ -330,9 +330,9 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection { item.setText(0, info.valid != null ? info.name + " (!)" : info.name); item.setText(1, info.type); item.setText(2, info.expression); - //item.setText(3, unitStr(info)); - item.setText(3, info.label); - item.setText(4, info.description); + item.setText(3, info.unitString()); + item.setText(4, info.label); + item.setText(5, info.description); item.setForeground(fg); @@ -376,4 +376,4 @@ public class DerivedPropertiesSection implements ComponentTypeViewerSection { return 100.0; } -} +} \ No newline at end of file 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..ea4de26b2 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,24 @@ 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); + Layer0X L0X = Layer0X.getInstance(graph); + boolean hasRequiresDataType = graph.hasStatement(relation, L0X.RequiresDataType); + if (hasRequiresDataType) { + Datatype dt = graph.getDataType(object); + if (dt instanceof NumberType) { + Layer0 L0 = Layer0.getInstance(graph); + 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); + } + } - Layer0 L0 = Layer0.getInstance(graph); - Layer0X L0X = Layer0X.getInstance(graph); - - String oldUnit = graph.getPossibleRelatedValue2(relation, L0X.HasUnit, Bindings.STRING); + String oldUnit = graph.getPossibleRelatedValue2(relation, L0X.HasUnit, Bindings.STRING); + graph.claimLiteral(relation, L0X.HasUnit, unit, Bindings.STRING); - 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)); - } + CommentMetadata cm = graph.getMetadata(CommentMetadata.class); + graph.addMetadata(cm.add("Set unit from " + oldUnit + " to " + unit + " for component/annotation " + type + " property " + relation)); } /** -- 2.47.1