]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added editable unit for derived properties 70/2370/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 27 Oct 2018 20:20:29 +0000 (23:20 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 27 Oct 2018 20:21:06 +0000 (20:21 +0000)
gitlab #161

Change-Id: I81a7dc60fa0c4d4173dbfa128a509e7e2bfa18e9

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

index e1f17996505f6d34ec2131f489f97552f0743327..ea3f61e80fe0904251ac2cd4af2a44581717f392 100644 (file)
@@ -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;
index 57ba4c462e09f7c0000846e38a3b19be982dcc4a..c5e77383f4be7330063696ca84807d28d3a6d3f7 100644 (file)
@@ -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<ComponentTypeViewerPropertyInfo> {
     public Resource resource;
@@ -135,6 +136,16 @@ public class ComponentTypeViewerPropertyInfo implements Comparable<ComponentType
             return false;
         return true;
     }
-    
-    
+
+    public String unitString() {
+        String result = numberType == null ? null : numberType.getUnit();
+        if (result == null)
+            result = unit;
+        return StringUtils.safeString(result);
+    }
+
+    public String rangeString() {
+        return StringUtils.safeString(numberType == null ? null : numberType.getRangeStr());
+    }
+
 }
\ No newline at end of file
index 9a2a713df0fa8807ddd55ac48935343ad824bb5f..e919aa71f00d01a8fa27b926a022aef077609e38 100644 (file)
@@ -530,8 +530,8 @@ public class ConfigurationPropertiesSection implements ComponentTypeViewerSectio
             item.setText(0, info.name);
             item.setText(1, info.type);
             item.setText(2, info.defaultValue);
-            item.setText(3, unitStr(info));
-            item.setText(4, rangeStr(info));
+            item.setText(3, info.unitString());
+            item.setText(4, info.rangeString());
             item.setText(5, info.label);
             item.setText(6, info.description);
 
@@ -574,18 +574,6 @@ public class ConfigurationPropertiesSection implements ComponentTypeViewerSectio
         }
     }
 
-    private String unitStr(ComponentTypeViewerPropertyInfo info) {
-        String unit = info.numberType == null ? null : info.numberType.getUnit();
-        if (unit == null)
-            unit = info.unit;
-        return unit != null ? unit : "";
-    }
-
-    private String rangeStr(ComponentTypeViewerPropertyInfo info) {
-        String range = info.numberType == null ? null : info.numberType.getRangeStr();
-        return range != null ? range : "";
-    }
-    
     @Override
     public void setReadOnly(boolean readOnly) {
         boolean e = !readOnly;
index 1fa503515b4e840c8bd5c55a7b1ae8729fa2626b..19d9e6f29dc5c0f7e12b8e18844cb1d8999f6561 100644 (file)
@@ -43,11 +43,11 @@ import org.simantics.structural.stubs.StructuralResource2;
 
 public class DerivedPropertiesSection implements ComponentTypeViewerSection {
     private static final String[] COLUMN_NAMES = 
-            new String[] {"Name", "Type", "Expression", "Label", "Description"};
+            new String[] {"Name", "Type", "Expression", "Unit", "Label", "Description"};
     private static final int[] COLUMN_LENGTHS =
-            new int[] { 120, 100, 100, 100, 100 };
+            new int[] { 120, 100, 100, 70, 100, 100 };
     private static final int[] COLUMN_WEIGHTS =
-            new int[] { 0, 0, 100, 0, 0 };
+            new int[] { 0, 0, 100, 0, 0, 0 };
     private static Function4<RequestProcessor, Resource, Resource, String, String> VALIDATE_MONITOR_EXPRESSION =
             new Function4<RequestProcessor, Resource, Resource, String, String>() {
         @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
index 0afdb03b7222c1f0d5f95fb8cc3c51c0d082bdb1..ea4de26b22da5fe935c6153093ed476304278954 100644 (file)
@@ -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));
     }
 
     /**