From: Tuukka Lehtonen Date: Fri, 2 Nov 2018 13:32:20 +0000 (+0200) Subject: Added inline filtering support for property name editing in UC editor X-Git-Tag: v1.43.0~136^2~298^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=bbe9703c72de21f7d8349bc4d51b23282a8cb6cf;p=simantics%2Fplatform.git Added inline filtering support for property name editing in UC editor This makes it easier to implement filters like uppercasing and replacing certain characters as one types. gitlab #161 Change-Id: Ic7785c78d51660654e2afe26fd524a96179ceafc --- 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 ea3f61e80..b64380b28 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 @@ -97,6 +97,14 @@ public class ComponentTypeViewerData { public void editName(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column, Pattern namePattern, DbConsumer 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 nameFilter, Pattern namePattern, DbConsumer 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 nameValidator, DbConsumer 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 nameFilter, + 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 = @@ -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) {