]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added inline filtering support for property name editing in UC editor 16/2416/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 2 Nov 2018 13:32:20 +0000 (15:32 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 2 Nov 2018 13:59:57 +0000 (13:59 +0000)
This makes it easier to implement filters like uppercasing and replacing
certain characters as one types.

gitlab #161

Change-Id: Ic7785c78d51660654e2afe26fd524a96179ceafc
(cherry picked from commit bbe9703c72de21f7d8349bc4d51b23282a8cb6cf)

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java

index ea3f61e80fe0904251ac2cd4af2a44581717f392..b64380b285d7b76593060b2e40a6a7d09f502b8f 100644 (file)
@@ -97,6 +97,14 @@ public class ComponentTypeViewerData {
     public void editName(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column,
             Pattern namePattern, DbConsumer<WriteGraph> extraWriter) {
         editName(table, editor, propertyInfo, selectedItem, column,
+                null,
+                (pInfo, name) -> validatePropertyName(pInfo, name, namePattern),
+                extraWriter);
+    }
+
+    public void editName(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column,
+            Function2<ComponentTypeViewerPropertyInfo, String, String> nameFilter, Pattern namePattern, DbConsumer<WriteGraph> extraWriter) {
+        editName(table, editor, propertyInfo, selectedItem, column, nameFilter,
                 (pInfo, name) -> validatePropertyName(pInfo, name, namePattern),
                 extraWriter);
     }
@@ -109,6 +117,18 @@ public class ComponentTypeViewerData {
 
     public void editName(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column,
             Function2<ComponentTypeViewerPropertyInfo, String, String> nameValidator, DbConsumer<WriteGraph> extraWriter) {
+        editName(table, editor, propertyInfo, selectedItem, column, null, nameValidator, extraWriter);
+    }
+
+    public void editName(
+            Table table,
+            TableEditor editor,
+            final ComponentTypeViewerPropertyInfo propertyInfo,
+            TableItem selectedItem,
+            int column,
+            Function2<ComponentTypeViewerPropertyInfo, String, String> nameFilter,
+            Function2<ComponentTypeViewerPropertyInfo, String, String> nameValidator,
+            DbConsumer<WriteGraph> extraWriter) {
         int extraStyle = propertyInfo.immutable ? SWT.READ_ONLY : 0;
         final Text text = new Text(table, SWT.NONE | extraStyle);
         org.eclipse.swt.widgets.Listener listener = 
@@ -118,9 +138,11 @@ public class ComponentTypeViewerData {
                 if (e.type == SWT.Dispose) {
                     form.setMessage(null);
                     return;
-                }
-
-                if (e.type == SWT.Modify) {
+                } else if (e.type == SWT.Verify) {
+                    // Filter input if necessary
+                    e.text = nameFilter != null ? nameFilter.apply(propertyInfo, e.text) : e.text;
+                    return;
+                } else if (e.type == SWT.Modify) {
                     // validate current name
                     String error = nameValidator.apply(propertyInfo, text.getText());
                     if (error != null) {
@@ -131,9 +153,7 @@ public class ComponentTypeViewerData {
                         form.setMessage(null);
                     }
                     return;
-                }
-
-                if (e.type == SWT.Traverse) {
+                } else if (e.type == SWT.Traverse) {
                     if (e.detail == SWT.TRAVERSE_ESCAPE) {
                         text.dispose();
                         e.doit = false;
@@ -177,6 +197,8 @@ public class ComponentTypeViewerData {
                 });
             }
         };
+        if (nameFilter != null)
+            text.addListener(SWT.Verify, listener);
         text.addListener(SWT.Modify, listener);
         text.addListener(SWT.Deactivate, listener);
         text.addListener(SWT.Traverse, listener);
@@ -497,7 +519,7 @@ public class ComponentTypeViewerData {
         shell.open();
     }
 
-    protected void editMultilineText(Table table, TableEditor editor,
+    public void editMultilineText(Table table, TableEditor editor,
             final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem,
             Rectangle selectedItemBounds, int column, final StringWriter writer)
     {