001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.ide.dialogs;
011:
012: import org.eclipse.jface.preference.IPreferenceStore;
013: import org.eclipse.jface.preference.RadioGroupFieldEditor;
014: import org.eclipse.swt.SWT;
015: import org.eclipse.swt.layout.GridData;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Control;
018: import org.eclipse.ui.PlatformUI;
019: import org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage;
020: import org.eclipse.ui.internal.ide.IDEInternalPreferences;
021: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
022: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
023:
024: /**
025: * Extends the Perspectives preference page with IDE-specific settings.
026: *
027: * Note: want IDE settings to appear in main Perspectives preference page (via
028: * subclassing), however the superclass, PerspectivesPreferencePage, is
029: * internal
030: */
031: public class IDEPerspectivesPreferencePage extends
032: PerspectivesPreferencePage {
033: private final String PROJECT_SWITCH_PERSP_MODE_TITLE = IDEWorkbenchMessages.ProjectSwitchPerspectiveMode_optionsTitle;
034:
035: private final String PSPM_ALWAYS_TEXT = IDEWorkbenchMessages.ProjectSwitchPerspectiveMode_always;
036:
037: private final String PSPM_NEVER_TEXT = IDEWorkbenchMessages.ProjectSwitchPerspectiveMode_never;
038:
039: private final String PSPM_PROMPT_TEXT = IDEWorkbenchMessages.ProjectSwitchPerspectiveMode_prompt;
040:
041: private RadioGroupFieldEditor projectSwitchField;
042:
043: /**
044: * Creates the page's UI content.
045: */
046: protected Control createContents(Composite parent) {
047: // @issue if the product subclasses this page, then it should provide
048: // the help content
049: PlatformUI
050: .getWorkbench()
051: .getHelpSystem()
052: .setHelp(
053: parent,
054: org.eclipse.ui.internal.IWorkbenchHelpContextIds.PERSPECTIVES_PREFERENCE_PAGE);
055:
056: Composite composite = createComposite(parent);
057:
058: createOpenPerspButtonGroup(composite);
059: createOpenViewButtonGroup(composite);
060: createProjectPerspectiveGroup(composite);
061: createCustomizePerspective(composite);
062:
063: return composite;
064: }
065:
066: /**
067: * Creates a composite that contains buttons for selecting the preference
068: * opening new project selections.
069: */
070: private void createProjectPerspectiveGroup(Composite composite) {
071:
072: Composite projectComposite = new Composite(composite, SWT.NONE);
073: projectComposite.setLayoutData(new GridData(
074: GridData.FILL_HORIZONTAL));
075: projectComposite.setFont(composite.getFont());
076:
077: String[][] namesAndValues = {
078: { PSPM_ALWAYS_TEXT, IDEInternalPreferences.PSPM_ALWAYS },
079: { PSPM_NEVER_TEXT, IDEInternalPreferences.PSPM_NEVER },
080: { PSPM_PROMPT_TEXT, IDEInternalPreferences.PSPM_PROMPT } };
081: projectSwitchField = new RadioGroupFieldEditor(
082: IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE,
083: PROJECT_SWITCH_PERSP_MODE_TITLE, namesAndValues.length,
084: namesAndValues, projectComposite, true);
085: projectSwitchField.setPreferenceStore(getIDEPreferenceStore());
086: projectSwitchField.setPage(this );
087: projectSwitchField.load();
088: }
089:
090: /**
091: * Returns the IDE preference store.
092: */
093: protected IPreferenceStore getIDEPreferenceStore() {
094: return IDEWorkbenchPlugin.getDefault().getPreferenceStore();
095: }
096:
097: /*
098: * (non-Javadoc)
099: *
100: * @see org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage#performDefaults()
101: */
102: protected void performDefaults() {
103: projectSwitchField.loadDefault();
104: super .performDefaults();
105: }
106:
107: /*
108: * (non-Javadoc)
109: *
110: * @see org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage#performOk()
111: */
112: public boolean performOk() {
113: projectSwitchField.store();
114: IDEWorkbenchPlugin.getDefault().savePluginPreferences();
115: return super.performOk();
116: }
117:
118: }
|