import org.simantics.sysdyn.ui.properties.EquationTab;\r
\r
public class NameWidget implements Widget {\r
- \r
+\r
final private org.eclipse.swt.widgets.Text nameText;\r
- String originalName;\r
+ String originalName = "";\r
private ReadFactory<?, String> textFactory;\r
- \r
+\r
public NameWidget(Composite parent, WidgetSupport support, int style) {\r
support.register(this);\r
nameText = new org.eclipse.swt.widgets.Text(parent, style);\r
nameText.setFont(EquationTab.FONT);\r
- \r
+\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText);\r
\r
nameText.addVerifyListener(new VerifyListener() {\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
});\r
- \r
+\r
nameText.addModifyListener(new ModifyListener() {\r
\r
@Override\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
@Override\r
public void setInput(Object input) {\r
- \r
+\r
if(textFactory != null) {\r
textFactory.listen(input, new Listener<String>() {\r
\r
public void execute(final String text) {\r
\r
if(text == null) return;\r
- \r
+\r
nameText.getDisplay().asyncExec(new Runnable() {\r
\r
@Override\r
public void run() {\r
- \r
+\r
if(isDisposed()) return;\r
nameText.setText(text);\r
- \r
+\r
}\r
\r
});\r
\r
});\r
}\r
- \r
+\r
}\r
- \r
+\r
public void setTextFactory(ReadFactory<?, String> textFactory) {\r
this.textFactory = textFactory;\r
}\r
- \r
+\r
\r
}\r