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;
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;
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
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);
}
}
- 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;
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
}, 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 {
}, 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 {
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);
return 100.0;
}
-}
+}
\ No newline at end of file
*******************************************************************************/
package org.simantics.modeling.userComponent;
-import gnu.trove.map.hash.THashMap;
-
import java.util.Map;
import org.simantics.databoard.Bindings;
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);
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));
}
/**