X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/wizards/dialogfields/SelectionButtonDialogField.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/wizards/dialogfields/SelectionButtonDialogField.java index a97e525..57b9cd2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/wizards/dialogfields/SelectionButtonDialogField.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/wizards/dialogfields/SelectionButtonDialogField.java @@ -20,54 +20,56 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; - - /** * Dialog Field containing a single button such as a radio or checkbox button. */ public class SelectionButtonDialogField extends DialogField { - + private Button fButton; + private boolean fIsSelected; + private DialogField[] fAttachedDialogFields; + private int fButtonStyle; /** - * Creates a selection button. - * Allowed button styles: SWT.RADIO, SWT.CHECK, SWT.TOGGLE, SWT.PUSH + * Creates a selection button. Allowed button styles: SWT.RADIO, SWT.CHECK, + * SWT.TOGGLE, SWT.PUSH */ public SelectionButtonDialogField(int buttonStyle) { super(); - fIsSelected= false; - fAttachedDialogFields= null; - fButtonStyle= buttonStyle; + fIsSelected = false; + fAttachedDialogFields = null; + fButtonStyle = buttonStyle; } - + /** - * Attaches a field to the selection state of the selection button. - * The attached field will be disabled if the selection button is not selected. + * Attaches a field to the selection state of the selection button. The + * attached field will be disabled if the selection button is not selected. */ public void attachDialogField(DialogField dialogField) { attachDialogFields(new DialogField[] { dialogField }); } /** - * Attaches fields to the selection state of the selection button. - * The attached fields will be disabled if the selection button is not selected. - */ + * Attaches fields to the selection state of the selection button. The + * attached fields will be disabled if the selection button is not selected. + */ public void attachDialogFields(DialogField[] dialogFields) { - fAttachedDialogFields= dialogFields; - for (int i= 0; i < dialogFields.length; i++) { + fAttachedDialogFields = dialogFields; + for (int i = 0; i < dialogFields.length; i++) { dialogFields[i].setEnabled(fIsSelected); } - } - + } + /** - * Returns true is teh gived field is attached to the selection button. + * Returns true is teh gived field is attached to the + * selection button. */ public boolean isAttached(DialogField editor) { if (fAttachedDialogFields != null) { - for (int i=0; i < fAttachedDialogFields.length; i++) { + for (int i = 0; i < fAttachedDialogFields.length; i++) { if (fAttachedDialogFields[i] == editor) { return true; } @@ -75,49 +77,52 @@ public class SelectionButtonDialogField extends DialogField { } return false; } - + // ------- layout helpers - + /* * @see DialogField#doFillIntoGrid */ public Control[] doFillIntoGrid(Composite parent, int nColumns) { assertEnoughColumns(nColumns); - - Button button= getSelectionButton(parent); - GridData gd= new GridData(); - gd.horizontalSpan= nColumns; - gd.horizontalAlignment= GridData.FILL; + + Button button = getSelectionButton(parent); + GridData gd = new GridData(); + gd.horizontalSpan = nColumns; + gd.horizontalAlignment = GridData.FILL; if (fButtonStyle == SWT.PUSH) { gd.heightHint = SWTUtil.getButtonHeightHint(button); gd.widthHint = SWTUtil.getButtonWidthHint(button); - } - + } + button.setLayoutData(gd); - + return new Control[] { button }; - } + } /* * @see DialogField#getNumberOfControls - */ + */ public int getNumberOfControls() { - return 1; - } - - // ------- ui creation + return 1; + } + + // ------- ui creation /** - * Returns the selection button widget. When called the first time, the widget will be created. - * @param The parent composite when called the first time, or null - * after. - */ + * Returns the selection button widget. When called the first time, the + * widget will be created. + * + * @param The + * parent composite when called the first time, or + * null after. + */ public Button getSelectionButton(Composite group) { if (fButton == null) { assertCompositeNotNull(group); - - fButton= new Button(group, fButtonStyle); - fButton.setFont(group.getFont()); + + fButton = new Button(group, fButtonStyle); + fButton.setFont(group.getFont()); fButton.setText(fLabelText); fButton.setEnabled(isEnabled()); fButton.setSelection(fIsSelected); @@ -125,29 +130,30 @@ public class SelectionButtonDialogField extends DialogField { public void widgetDefaultSelected(SelectionEvent e) { doWidgetSelected(e); } + public void widgetSelected(SelectionEvent e) { doWidgetSelected(e); } - }); + }); } return fButton; } - + private void doWidgetSelected(SelectionEvent e) { if (isOkToUse(fButton)) { changeValue(fButton.getSelection()); } - } - + } + private void changeValue(boolean newState) { if (fIsSelected != newState) { - fIsSelected= newState; + fIsSelected = newState; if (fAttachedDialogFields != null) { - boolean focusSet= false; - for (int i= 0; i < fAttachedDialogFields.length; i++) { + boolean focusSet = false; + for (int i = 0; i < fAttachedDialogFields.length; i++) { fAttachedDialogFields[i].setEnabled(fIsSelected); if (fIsSelected && !focusSet) { - focusSet= fAttachedDialogFields[i].setFocus(); + focusSet = fAttachedDialogFields[i].setFocus(); } } } @@ -155,10 +161,10 @@ public class SelectionButtonDialogField extends DialogField { } else if (fButtonStyle == SWT.PUSH) { dialogFieldChanged(); } - } + } + + // ------ model access - // ------ model access - /** * Returns the selection state of the button. */ @@ -168,7 +174,7 @@ public class SelectionButtonDialogField extends DialogField { /** * Sets the selection state of the button. - */ + */ public void setSelection(boolean selected) { changeValue(selected); if (isOkToUse(fButton)) { @@ -180,15 +186,12 @@ public class SelectionButtonDialogField extends DialogField { /* * @see DialogField#updateEnableState - */ + */ protected void updateEnableState() { super.updateEnableState(); if (isOkToUse(fButton)) { fButton.setEnabled(isEnabled()); - } + } } - - - - + }