From: lehtonen Date: Tue, 15 Jun 2010 20:21:07 +0000 (+0000) Subject: Prevent eternal looping in ModifyListener X-Git-Tag: simantics-1.2.0~215 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=af18be2eebd45e80eed427dc89cca1cf6866c817;p=simantics%2Fsysdyn.git Prevent eternal looping in ModifyListener git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16168 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java index fc478d78..f5418efa 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java @@ -43,7 +43,7 @@ import org.simantics.ui.workbench.ResourceEditorInput; public class NameComposite extends Composite { Text nameText; - String originalName; + String originalName = ""; public NameComposite(Composite parent, int style) { @@ -59,7 +59,7 @@ public class NameComposite extends Composite { @Override public void verifyText(VerifyEvent e) { e.doit = false; - char c = e.character; + char c = e.character; if(c != ' ') { e.doit = true; } @@ -70,8 +70,11 @@ public class NameComposite extends Composite { @Override public void modifyText(ModifyEvent e) { - if(((Text)e.widget).getText().contains(" ")) { - ((Text)e.widget).setText(originalName); + Text t = (Text) e.widget; + String txt = t.getText(); + // Don't allow this to produce an eternal loop + if (!txt.equals(originalName) && txt.contains(" ")) { + t.setText(originalName); } } }); @@ -88,12 +91,14 @@ public class NameComposite extends Composite { if(e.keyCode == SWT.ESC && originalName != null) { ((Text)e.widget).setText(originalName); ((Text)e.widget).setSelection(originalName.length()); - } + } } }); } public void setName(String name) { + if (name == null) + throw new NullPointerException("null name"); this.originalName = name; this.nameText.setText(name); } @@ -101,8 +106,8 @@ public class NameComposite extends Composite { public void save(final Resource variable) { final String nameNew = this.nameText.getText(); if(nameNew != null && !nameNew.equals(this.originalName) && variable != null) { - - final IEditorPart editor = + + final IEditorPart editor = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().getActiveEditor(); IEditorInput input = editor.getEditorInput(); @@ -122,9 +127,9 @@ public class NameComposite extends Composite { } } } - - - + + + try { SimanticsUI.getSession().syncRequest(new WriteRequest() {