KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > dialogs > IDEPerspectivesPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.ide.dialogs;
12
13 import org.eclipse.jface.preference.IPreferenceStore;
14 import org.eclipse.jface.preference.RadioGroupFieldEditor;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage;
21 import org.eclipse.ui.internal.ide.IDEInternalPreferences;
22 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
23 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
24
25 /**
26  * Extends the Perspectives preference page with IDE-specific settings.
27  *
28  * Note: want IDE settings to appear in main Perspectives preference page (via
29  * subclassing), however the superclass, PerspectivesPreferencePage, is
30  * internal
31  */

32 public class IDEPerspectivesPreferencePage extends PerspectivesPreferencePage {
33     private final String JavaDoc PROJECT_SWITCH_PERSP_MODE_TITLE = IDEWorkbenchMessages.ProjectSwitchPerspectiveMode_optionsTitle;
34
35     private final String JavaDoc PSPM_ALWAYS_TEXT = IDEWorkbenchMessages.ProjectSwitchPerspectiveMode_always;
36
37     private final String JavaDoc PSPM_NEVER_TEXT = IDEWorkbenchMessages.ProjectSwitchPerspectiveMode_never;
38
39     private final String JavaDoc PSPM_PROMPT_TEXT = IDEWorkbenchMessages.ProjectSwitchPerspectiveMode_prompt;
40
41     private RadioGroupFieldEditor projectSwitchField;
42
43     /**
44      * Creates the page's UI content.
45      */

46     protected Control createContents(Composite parent) {
47         // @issue if the product subclasses this page, then it should provide
48
// the help content
49
PlatformUI
50                 .getWorkbench()
51                 .getHelpSystem()
52                 .setHelp(
53                         parent,
54                         org.eclipse.ui.internal.IWorkbenchHelpContextIds.PERSPECTIVES_PREFERENCE_PAGE);
55
56         Composite composite = createComposite(parent);
57
58         createOpenPerspButtonGroup(composite);
59         createOpenViewButtonGroup(composite);
60         createProjectPerspectiveGroup(composite);
61         createCustomizePerspective(composite);
62
63         return composite;
64     }
65
66     /**
67      * Creates a composite that contains buttons for selecting the preference
68      * opening new project selections.
69      */

70     private void createProjectPerspectiveGroup(Composite composite) {
71
72         Composite projectComposite = new Composite(composite, SWT.NONE);
73         projectComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
74         projectComposite.setFont(composite.getFont());
75
76         String JavaDoc[][] namesAndValues = {
77                 { PSPM_ALWAYS_TEXT, IDEInternalPreferences.PSPM_ALWAYS },
78                 { PSPM_NEVER_TEXT, IDEInternalPreferences.PSPM_NEVER },
79                 { PSPM_PROMPT_TEXT, IDEInternalPreferences.PSPM_PROMPT } };
80         projectSwitchField = new RadioGroupFieldEditor(
81                 IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE,
82                 PROJECT_SWITCH_PERSP_MODE_TITLE, namesAndValues.length,
83                 namesAndValues, projectComposite, true);
84         projectSwitchField.setPreferenceStore(getIDEPreferenceStore());
85         projectSwitchField.setPage(this);
86         projectSwitchField.load();
87     }
88
89     /**
90      * Returns the IDE preference store.
91      */

92     protected IPreferenceStore getIDEPreferenceStore() {
93         return IDEWorkbenchPlugin.getDefault().getPreferenceStore();
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage#performDefaults()
100      */

101     protected void performDefaults() {
102         projectSwitchField.loadDefault();
103         super.performDefaults();
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage#performOk()
110      */

111     public boolean performOk() {
112         projectSwitchField.store();
113         IDEWorkbenchPlugin.getDefault().savePluginPreferences();
114         return super.performOk();
115     }
116
117 }
118
Popular Tags