]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java
Added alternatives taking RequestProcessor to WorkbenchSelectionUtils.
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / componentTypeEditor / ComponentTypeViewerData.java
index a3e29debd21348990b8286a31727799428e837a2..7fd6340cfbc859770bf889ed36fd5e2074f28367 100644 (file)
@@ -42,6 +42,7 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 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 +87,15 @@ 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,
+                (pInfo, name) -> validatePropertyName(pInfo, name, namePattern));
+    }
+
+    public void editName(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column,
+            Function2<ComponentTypeViewerPropertyInfo, String, String> nameValidator) {
         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 +109,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 +133,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;
 
@@ -302,6 +309,10 @@ public class ComponentTypeViewerData {
                 }
                 text.dispose();
 
+                String error = validator.apply(Simantics.getSession(), componentType, propertyInfo.resource, newValue);
+                if (error != null)
+                    return;
+
                 if (writer != null) {
                     Simantics.getSession().async(new WriteRequest() {
                         @Override