import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-
/**
* Dialog field containing a label, text control and a button control.
*/
public class StringButtonDialogField extends StringDialogField {
-
+
private Button fBrowseButton;
+
private String fBrowseButtonLabel;
+
private IStringButtonAdapter fStringButtonAdapter;
-
+
private boolean fButtonEnabled;
-
+
public StringButtonDialogField(IStringButtonAdapter adapter) {
super();
- fStringButtonAdapter= adapter;
- fBrowseButtonLabel= "!Browse...!"; //$NON-NLS-1$
- fButtonEnabled= true;
+ fStringButtonAdapter = adapter;
+ fBrowseButtonLabel = "!Browse...!"; //$NON-NLS-1$
+ fButtonEnabled = true;
}
/**
* Sets the label of the button.
*/
public void setButtonLabel(String label) {
- fBrowseButtonLabel= label;
+ fBrowseButtonLabel = label;
}
-
+
// ------ adapter communication
/**
* Programmatical pressing of the button
- */
+ */
public void changeControlPressed() {
fStringButtonAdapter.changeControlPressed(this);
}
-
+
// ------- 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 - 2));
- Button button= getChangeControl(parent);
+ Button button = getChangeControl(parent);
button.setLayoutData(gridDataForButton(button, 1));
-
+
return new Control[] { label, text, button };
- }
+ }
/*
* @see DialogField#getNumberOfControls
- */
+ */
public int getNumberOfControls() {
- return 3;
+ return 3;
}
-
+
protected static GridData gridDataForButton(Button button, int span) {
- GridData gd= new GridData();
- gd.horizontalAlignment= GridData.FILL;
- gd.grabExcessHorizontalSpace= false;
- gd.horizontalSpan= span;
- gd.heightHint = SWTUtil.getButtonHeigthHint(button);
- gd.widthHint = SWTUtil.getButtonWidthHint(button);
+ GridData gd = new GridData();
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = false;
+ gd.horizontalSpan = span;
+ gd.heightHint = SWTUtil.getButtonHeightHint(button);
+ gd.widthHint = SWTUtil.getButtonWidthHint(button);
return gd;
- }
-
- // ------- ui creation
+ }
+
+ // ------- ui creation
/**
* Creates or returns the created buttom widget.
- * @param parent The parent composite or <code>null</code> if the widget has
- * already been created.
- */
+ *
+ * @param parent
+ * The parent composite or <code>null</code> if the widget has
+ * already been created.
+ */
public Button getChangeControl(Composite parent) {
if (fBrowseButton == null) {
assertCompositeNotNull(parent);
-
- fBrowseButton= new Button(parent, SWT.PUSH);
+
+ fBrowseButton = new Button(parent, SWT.PUSH);
fBrowseButton.setText(fBrowseButtonLabel);
fBrowseButton.setEnabled(isEnabled() && fButtonEnabled);
fBrowseButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
changeControlPressed();
}
+
public void widgetSelected(SelectionEvent e) {
changeControlPressed();
}
- });
-
+ });
+
}
return fBrowseButton;
}
-
+
// ------ enable / disable management
-
+
/**
* Sets the enable state of the button.
*/
if (isOkToUse(fBrowseButton)) {
fBrowseButton.setEnabled(isEnabled() && enable);
}
- fButtonEnabled= enable;
+ fButtonEnabled = enable;
}
/*
* @see DialogField#updateEnableState
- */
+ */
protected void updateEnableState() {
super.updateEnableState();
if (isOkToUse(fBrowseButton)) {
fBrowseButton.setEnabled(isEnabled() && fButtonEnabled);
}
- }
+ }
}