* Dialog field containing a label and a text control.
*/
public class StringDialogField extends DialogField {
-
+
private String fText;
+
private Text fTextControl;
+
private ModifyListener fModifyListener;
-
+
public StringDialogField() {
super();
- fText= ""; //$NON-NLS-1$
+ fText = ""; //$NON-NLS-1$
}
-
+
// ------- layout helpers
-
+
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
assertEnoughColumns(nColumns);
-
- Label label= getLabelControl(parent);
+
+ Label label = getLabelControl(parent);
label.setLayoutData(gridDataForLabel(1));
- Text text= getTextControl(parent);
+ Text text = getTextControl(parent);
text.setLayoutData(gridDataForText(nColumns - 1));
-
+
return new Control[] { label, text };
- }
+ }
/*
* @see DialogField#getNumberOfControls
*/
public int getNumberOfControls() {
- return 2;
+ return 2;
}
-
+
protected static GridData gridDataForText(int span) {
- GridData gd= new GridData();
- gd.horizontalAlignment= GridData.FILL;
- gd.grabExcessHorizontalSpace= false;
- gd.horizontalSpan= span;
+ GridData gd = new GridData();
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = false;
+ gd.horizontalSpan = span;
return gd;
- }
-
+ }
+
// ------- focus methods
-
+
/*
* @see DialogField#setFocus
*/
}
return true;
}
-
- // ------- ui creation
+
+ // ------- ui creation
/**
* Creates or returns the created text control.
- * @param parent The parent composite or <code>null</code> when the widget has
- * already been created.
- */
+ *
+ * @param parent
+ * The parent composite or <code>null</code> when the widget
+ * has already been created.
+ */
public Text getTextControl(Composite parent) {
if (fTextControl == null) {
assertCompositeNotNull(parent);
- fModifyListener= new ModifyListener() {
+ fModifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
doModifyText(e);
}
};
-
- fTextControl= new Text(parent, SWT.SINGLE | SWT.BORDER);
+
+ fTextControl = new Text(parent, SWT.SINGLE | SWT.BORDER);
// moved up due to 1GEUNW2
fTextControl.setText(fText);
fTextControl.setFont(parent.getFont());
fTextControl.addModifyListener(fModifyListener);
-
+
fTextControl.setEnabled(isEnabled());
}
return fTextControl;
}
-
+
private void doModifyText(ModifyEvent e) {
if (isOkToUse(fTextControl)) {
- fText= fTextControl.getText();
+ fText = fTextControl.getText();
}
dialogFieldChanged();
- }
-
+ }
+
// ------ enable / disable management
-
+
/*
* @see DialogField#updateEnableState
- */
+ */
protected void updateEnableState() {
- super.updateEnableState();
+ super.updateEnableState();
if (isOkToUse(fTextControl)) {
fTextControl.setEnabled(isEnabled());
- }
- }
-
- // ------ text access
-
+ }
+ }
+
+ // ------ text access
+
/**
* Gets the text. Can not be <code>null</code>
- */
+ */
public String getText() {
return fText;
}
-
+
/**
* Sets the text. Triggers a dialog-changed event.
*/
public void setText(String text) {
- fText= text;
+ fText = text;
if (isOkToUse(fTextControl)) {
fTextControl.setText(text);
} else {
dialogFieldChanged();
- }
+ }
}
/**
* Sets the text without triggering a dialog-changed event.
*/
public void setTextWithoutUpdate(String text) {
- fText= text;
+ fText = text;
if (isOkToUse(fTextControl)) {
fTextControl.removeModifyListener(fModifyListener);
fTextControl.setText(text);
fTextControl.addModifyListener(fModifyListener);
}
}
-
+
}