X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FcomponentTypeEditor%2FComponentTypeViewerData.java;h=e1f17996505f6d34ec2131f489f97552f0743327;hp=a3e29debd21348990b8286a31727799428e837a2;hb=6bf51de1941aa1dc5ee0a3aa8c50d53168b0c068;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 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 a3e29debd..e1f179965 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 @@ -40,8 +40,10 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.NamedResource; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.function.DbConsumer; import org.simantics.layer0.Layer0; import org.simantics.modeling.userComponent.ComponentTypeCommands; +import org.simantics.scl.runtime.function.Function2; import org.simantics.scl.runtime.function.Function4; import org.simantics.utils.ui.ErrorLogger; @@ -86,9 +88,27 @@ public class ComponentTypeViewerData { this.componentType = componentType; this.form = form; } - + public void editName(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column, Pattern namePattern) { + editName(table, editor, propertyInfo, selectedItem, column, namePattern, null); + } + + public void editName(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column, + Pattern namePattern, DbConsumer extraWriter) { + editName(table, editor, propertyInfo, selectedItem, column, + (pInfo, name) -> validatePropertyName(pInfo, name, namePattern), + extraWriter); + } + + public void editName(Table table, TableEditor editor, ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column, + Function2 nameValidator) + { + editName(table, editor, propertyInfo, selectedItem, column, nameValidator, null); + } + + public void editName(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column, + Function2 nameValidator, DbConsumer extraWriter) { int extraStyle = propertyInfo.immutable ? SWT.READ_ONLY : 0; final Text text = new Text(table, SWT.NONE | extraStyle); org.eclipse.swt.widgets.Listener listener = @@ -102,7 +122,7 @@ public class ComponentTypeViewerData { if (e.type == SWT.Modify) { // validate current name - String error = validatePropertyName(propertyInfo, text.getText(), namePattern); + String error = nameValidator.apply(propertyInfo, text.getText()); if (error != null) { text.setBackground(text.getDisplay().getSystemColor(SWT.COLOR_RED)); form.setMessage(error, IMessageProvider.ERROR); @@ -126,7 +146,7 @@ public class ComponentTypeViewerData { final String newValue = text.getText(); text.dispose(); - String error = validatePropertyName(propertyInfo, newValue, namePattern); + String error = nameValidator.apply(propertyInfo, newValue); if (error != null) return; @@ -150,6 +170,9 @@ public class ComponentTypeViewerData { ComponentTypeCommands.rename(graph, propertyInfo.resource, newValue); if (setLabel) ComponentTypeCommands.setLabel(graph, propertyInfo.resource, ComponentTypeCommands.camelCaseNameToLabel(newValue)); + + if (extraWriter != null) + extraWriter.accept(graph); } }); } @@ -302,6 +325,12 @@ public class ComponentTypeViewerData { } text.dispose(); + if (validator != null) { + String error = validator.apply(Simantics.getSession(), componentType, propertyInfo.resource, newValue); + if (error != null) + return; + } + if (writer != null) { Simantics.getSession().async(new WriteRequest() { @Override