KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.swt.SWT;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.ui.IWorkbenchPreferencePage;
21 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
23 import org.eclipse.ui.internal.dialogs.StartupPreferencePage;
24 import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
25 import org.eclipse.ui.internal.ide.IDEInternalPreferences;
26 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
27 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
28
29 /**
30  * Extends the Startup and Shutdown preference page with IDE-specific settings.
31  *
32  * Note: want IDE settings to appear in main Workbench preference page (via subclassing),
33  * however the superclass, StartupPreferencePage, is internal
34  * @since 3.0
35  */

36 public class IDEStartupPreferencePage extends StartupPreferencePage implements
37         IWorkbenchPreferencePage {
38
39     private Button refreshButton;
40
41     private Button launchPromptButton;
42
43     private Button exitPromptButton;
44
45     /*
46      * (non-Javadoc)
47      *
48      * @see org.eclipse.jface.preference.PreferencePage
49      */

50     protected Control createContents(Composite parent) {
51
52         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
53                 IWorkbenchHelpContextIds.STARTUP_PREFERENCE_PAGE);
54
55         Composite composite = createComposite(parent);
56
57         createLaunchPromptPref(composite);
58         createRefreshWorkspaceOnStartupPref(composite);
59         createExitPromptPref(composite);
60
61         Label space = new Label(composite,SWT.NONE);
62         space.setLayoutData(new GridData());
63         
64         createEarlyStartupSelection(composite);
65
66         return composite;
67     }
68
69     /**
70      * The default button has been pressed.
71      */

72     protected void performDefaults() {
73         IPreferenceStore store = getIDEPreferenceStore();
74
75         launchPromptButton.setSelection(true);
76
77         refreshButton
78                 .setSelection(store
79                         .getDefaultBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
80         exitPromptButton
81                 .setSelection(store
82                         .getDefaultBoolean(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW));
83
84         super.performDefaults();
85     }
86
87     /**
88      * The user has pressed Ok. Store/apply this page's values appropriately.
89      */

90     public boolean performOk() {
91         IPreferenceStore store = getIDEPreferenceStore();
92
93         // store the refresh workspace on startup setting
94
store.setValue(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP,
95                 refreshButton.getSelection());
96
97         // TODO: This should get the value from the configuration preference
98
// area, but dj said we shouldn't use it yet; some final details are
99
// being worked out. Hopefully it will be available soon, at which time
100
// the entire recentWorkspaces.xml file can be removed. But until then,
101
// this preference reads/writes the file each time.
102
ChooseWorkspaceData.setShowDialogValue(launchPromptButton
103                 .getSelection());
104
105         // store the exit prompt on last window close setting
106
store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW,
107                 exitPromptButton.getSelection());
108
109         IDEWorkbenchPlugin.getDefault().savePluginPreferences();
110
111         return super.performOk();
112     }
113
114     protected void createRefreshWorkspaceOnStartupPref(Composite composite) {
115         refreshButton = new Button(composite, SWT.CHECK);
116         refreshButton.setText(IDEWorkbenchMessages.StartupPreferencePage_refreshButton);
117         refreshButton.setFont(composite.getFont());
118         refreshButton.setSelection(getIDEPreferenceStore().getBoolean(
119                 IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
120     }
121
122     protected void createLaunchPromptPref(Composite composite) {
123         launchPromptButton = new Button(composite, SWT.CHECK);
124         launchPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_launchPromptButton);
125         launchPromptButton.setFont(composite.getFont());
126
127         // TODO: This should get the value from the configuration preference
128
// area, but dj said we shouldn't use it yet; some final details are
129
// being worked out. Hopefully it will be available soon, at which time
130
// the entire recentWorkspaces.xml file can be removed. But until then,
131
// this preference reads/writes the file each time.
132
launchPromptButton.setSelection(ChooseWorkspaceData
133                 .getShowDialogValue());
134     }
135
136     protected void createExitPromptPref(Composite composite) {
137         exitPromptButton = new Button(composite, SWT.CHECK);
138         exitPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_exitPromptButton);
139         exitPromptButton.setFont(composite.getFont());
140         exitPromptButton.setSelection(getIDEPreferenceStore().getBoolean(
141                 IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW));
142     }
143
144     /**
145      * Returns the IDE preference store.
146      */

147     protected IPreferenceStore getIDEPreferenceStore() {
148         return IDEWorkbenchPlugin.getDefault().getPreferenceStore();
149     }
150 }
151
Popular Tags