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
@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
\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
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
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
}\r
}\r
}\r
- \r
- \r
- \r
+\r
+\r
+\r
try {\r
SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
\r