]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Prevent eternal looping in ModifyListener
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 15 Jun 2010 20:21:07 +0000 (20:21 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 15 Jun 2010 20:21:07 +0000 (20:21 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16168 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java

index fc478d78606a2f4295eb90313857dc3c6353ae50..f5418efa72d3154f52237bcc574c8c50b937fc95 100644 (file)
@@ -43,7 +43,7 @@ import org.simantics.ui.workbench.ResourceEditorInput;
 public class NameComposite extends Composite {\r
 \r
     Text nameText;\r
-    String originalName;\r
+    String originalName = "";\r
 \r
 \r
     public NameComposite(Composite parent, int style) {\r
@@ -59,7 +59,7 @@ public class NameComposite extends Composite {
             @Override\r
             public void verifyText(VerifyEvent e) {\r
                 e.doit = false;\r
-                char c = e.character;   \r
+                char c = e.character;\r
                 if(c != ' ') {\r
                     e.doit = true;\r
                 }\r
@@ -70,8 +70,11 @@ public class NameComposite extends Composite {
 \r
             @Override\r
             public void modifyText(ModifyEvent e) {\r
-                if(((Text)e.widget).getText().contains(" ")) {\r
-                    ((Text)e.widget).setText(originalName);\r
+                Text t = (Text) e.widget;\r
+                String txt = t.getText();\r
+                // Don't allow this to produce an eternal loop\r
+                if (!txt.equals(originalName) && txt.contains(" ")) {\r
+                    t.setText(originalName);\r
                 }\r
             }\r
         });\r
@@ -88,12 +91,14 @@ public class NameComposite extends Composite {
                 if(e.keyCode == SWT.ESC && originalName != null) {\r
                     ((Text)e.widget).setText(originalName);\r
                     ((Text)e.widget).setSelection(originalName.length());\r
-                }                \r
+                }\r
             }\r
         });\r
     }\r
 \r
     public void setName(String name) {\r
+        if (name == null)\r
+            throw new NullPointerException("null name");\r
         this.originalName = name;\r
         this.nameText.setText(name);\r
     }\r
@@ -101,8 +106,8 @@ public class NameComposite extends Composite {
     public void save(final Resource variable) {\r
         final String nameNew = this.nameText.getText();\r
         if(nameNew != null && !nameNew.equals(this.originalName) && variable != null) {\r
-            \r
-            final IEditorPart editor = \r
+\r
+            final IEditorPart editor =\r
                 PlatformUI.getWorkbench()\r
                 .getActiveWorkbenchWindow().getActivePage().getActiveEditor();\r
             IEditorInput input =  editor.getEditorInput();\r
@@ -122,9 +127,9 @@ public class NameComposite extends Composite {
                     }\r
                 }\r
             }\r
-    \r
-            \r
-            \r
+\r
+\r
+\r
             try {\r
                 SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
 \r