001: /*******************************************************************************
002: * Copyright (c) 2004, 2007 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.application.dialogs;
011:
012: import org.eclipse.jface.preference.IPreferenceStore;
013: import org.eclipse.swt.SWT;
014: import org.eclipse.swt.layout.GridData;
015: import org.eclipse.swt.widgets.Button;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Control;
018: import org.eclipse.swt.widgets.Label;
019: import org.eclipse.ui.IWorkbenchPreferencePage;
020: import org.eclipse.ui.PlatformUI;
021: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
022: import org.eclipse.ui.internal.dialogs.StartupPreferencePage;
023: import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
024: import org.eclipse.ui.internal.ide.IDEInternalPreferences;
025: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
026: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
027:
028: /**
029: * Extends the Startup and Shutdown preference page with IDE-specific settings.
030: *
031: * Note: want IDE settings to appear in main Workbench preference page (via subclassing),
032: * however the superclass, StartupPreferencePage, is internal
033: * @since 3.0
034: */
035: public class IDEStartupPreferencePage extends StartupPreferencePage
036: implements IWorkbenchPreferencePage {
037:
038: private Button refreshButton;
039:
040: private Button launchPromptButton;
041:
042: private Button exitPromptButton;
043:
044: /*
045: * (non-Javadoc)
046: *
047: * @see org.eclipse.jface.preference.PreferencePage
048: */
049: protected Control createContents(Composite parent) {
050:
051: PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
052: IWorkbenchHelpContextIds.STARTUP_PREFERENCE_PAGE);
053:
054: Composite composite = createComposite(parent);
055:
056: createLaunchPromptPref(composite);
057: createRefreshWorkspaceOnStartupPref(composite);
058: createExitPromptPref(composite);
059:
060: Label space = new Label(composite, SWT.NONE);
061: space.setLayoutData(new GridData());
062:
063: createEarlyStartupSelection(composite);
064:
065: return composite;
066: }
067:
068: /**
069: * The default button has been pressed.
070: */
071: protected void performDefaults() {
072: IPreferenceStore store = getIDEPreferenceStore();
073:
074: launchPromptButton.setSelection(true);
075:
076: refreshButton
077: .setSelection(store
078: .getDefaultBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
079: exitPromptButton
080: .setSelection(store
081: .getDefaultBoolean(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW));
082:
083: super .performDefaults();
084: }
085:
086: /**
087: * The user has pressed Ok. Store/apply this page's values appropriately.
088: */
089: public boolean performOk() {
090: IPreferenceStore store = getIDEPreferenceStore();
091:
092: // store the refresh workspace on startup setting
093: store.setValue(
094: IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP,
095: refreshButton.getSelection());
096:
097: // TODO: This should get the value from the configuration preference
098: // area, but dj said we shouldn't use it yet; some final details are
099: // 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
107: .setValue(
108: IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW,
109: exitPromptButton.getSelection());
110:
111: IDEWorkbenchPlugin.getDefault().savePluginPreferences();
112:
113: return super .performOk();
114: }
115:
116: protected void createRefreshWorkspaceOnStartupPref(
117: Composite composite) {
118: refreshButton = new Button(composite, SWT.CHECK);
119: refreshButton
120: .setText(IDEWorkbenchMessages.StartupPreferencePage_refreshButton);
121: refreshButton.setFont(composite.getFont());
122: refreshButton.setSelection(getIDEPreferenceStore().getBoolean(
123: IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
124: }
125:
126: protected void createLaunchPromptPref(Composite composite) {
127: launchPromptButton = new Button(composite, SWT.CHECK);
128: launchPromptButton
129: .setText(IDEWorkbenchMessages.StartupPreferencePage_launchPromptButton);
130: launchPromptButton.setFont(composite.getFont());
131:
132: // TODO: This should get the value from the configuration preference
133: // area, but dj said we shouldn't use it yet; some final details are
134: // being worked out. Hopefully it will be available soon, at which time
135: // the entire recentWorkspaces.xml file can be removed. But until then,
136: // this preference reads/writes the file each time.
137: launchPromptButton.setSelection(ChooseWorkspaceData
138: .getShowDialogValue());
139: }
140:
141: protected void createExitPromptPref(Composite composite) {
142: exitPromptButton = new Button(composite, SWT.CHECK);
143: exitPromptButton
144: .setText(IDEWorkbenchMessages.StartupPreferencePage_exitPromptButton);
145: exitPromptButton.setFont(composite.getFont());
146: exitPromptButton
147: .setSelection(getIDEPreferenceStore()
148: .getBoolean(
149: IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW));
150: }
151:
152: /**
153: * Returns the IDE preference store.
154: */
155: protected IPreferenceStore getIDEPreferenceStore() {
156: return IDEWorkbenchPlugin.getDefault().getPreferenceStore();
157: }
158: }
|