/** * Add buttons to the dialog's button bar. * * <p>Subclasses should override. * * @param parent the button bar composite */ protected void createButtonsForButtonBar(Composite parent) { parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); if (!field.getPreferencesLevel().equals(IPreferencesService.DEFAULT_LEVEL)) { copyButton = createButton(parent, COPY_ID, PreferenceDialogConstants.COPY_LABEL, false); copyButton.setEnabled( field.getPreferencesLevel() != null && field.isInherited() && field.getComboBoxControl().isEnabled()); } // emptyButton = createButton(parent, EMPTY_ID, PreferenceDialogConstants.EMPTY_LABEL, // false); // emptyButton.setEnabled(field.getPreferencesLevel() != null && // field.isEmptyStringAllowed() && field.getComboBoxControl(parent).isEnabled()); removeButton = createButton(parent, REMOVE_ID, PreferenceDialogConstants.REMOVE_LABEL, false); removeButton.setEnabled( (field.getPreferencesLevel() != null) && !field.isInherited() && field.isRemovable() && field.getComboBoxControl().isEnabled()); Label l = new Label(parent, SWT.NONE); l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = (GridLayout) parent.getLayout(); layout.numColumns++; layout.makeColumnsEqualWidth = false; Button b = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); b.setFocus(); }
/* * Method declared on Dialog. * * The main result is to set the preference field in a particular way, * according to the particular button pressed, but without updating the * underlying preferences node. Thus the effect of this method is to * change the field in the display without making the new value visible * to other fields. For th e new value to take effect it must be later * stored into the preferences node by some oher action (typically the * pressing of an Apply or OK button). * */ protected void buttonPressed(int buttonId) { switch (buttonId) { case COPY_ID: if (!field.isInherited()) break; String value = field.getComboBoxControl().getText(); prefUtils.setField(field, fieldHolder, value); break; case REMOVE_ID: // Can't clear a field that doesn't have a preference stored to start with; // the following is one way to check that. // Why would you do this if there weren't a preference stored? May want to // clear a field that was edited (or otherwise set) locally but not yet stored. if (field.getPreferencesLevel().equals(field.getLevelFromWhichLoaded())) { preferencesService.clearPreferenceAtLevel( field.getPreferencesLevel(), field.getPreferenceName()); } prefUtils.setField(field, fieldHolder); break; // case EMPTY_ID: // prefUtils.setField(field, fieldHolder, field.getEmptyValue()); // break; default: super.buttonPressed(buttonId); break; } close(); }