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=1c4b22ee0762cbc2f6f2a2b248d4b7d53e4ce895;hp=048e0840eaa55f07a79da6f82f6620d15b06957d;hb=e6e555f4c17e686c44d0681a01eab17d0ec6f2aa;hpb=3260b37ec9ce61bc8a1383a5fc9ab8d8ab9d1fae 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 048e0840e..1c4b22ee0 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 @@ -3,6 +3,8 @@ package org.simantics.modeling.ui.componentTypeEditor; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -47,6 +49,7 @@ 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.threads.ThreadUtils; import org.simantics.utils.ui.ErrorLogger; public class ComponentTypeViewerData { @@ -373,18 +376,32 @@ public class ComponentTypeViewerData { if (validator != null) { org.eclipse.swt.widgets.Listener validationListener = new org.eclipse.swt.widgets.Listener() { + + private ScheduledFuture future; + @Override public void handleEvent(Event e) { final String newValue = text.getText(); - String error = validator.apply(Simantics.getSession(), componentType, propertyInfo.resource, newValue); - if (error != null) { - text.setBackground(text.getDisplay().getSystemColor(SWT.COLOR_RED)); - text.setToolTipText(error); - return; - } else { - text.setBackground(null); - text.setToolTipText(null); - } + if (future != null && !future.isCancelled()) + future.cancel(true); + future = ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> { + String error = validator.apply(Simantics.getSession(), componentType, propertyInfo.resource, newValue); + if (!text.isDisposed()) { + text.getDisplay().asyncExec(() -> { + if (!text.isDisposed()) { + if (error != null) { + text.setBackground(text.getDisplay().getSystemColor(SWT.COLOR_RED)); + text.setToolTipText(error); + return; + } else { + text.setBackground(null); + text.setToolTipText(null); + } + } + + }); + } + }, 500, TimeUnit.MILLISECONDS); } }; text.addListener(SWT.Modify, validationListener);