01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.jface.preference.PreferenceDialog;
14: import org.eclipse.ui.IWorkbenchWindow;
15: import org.eclipse.ui.PlatformUI;
16: import org.eclipse.ui.actions.ActionFactory;
17: import org.eclipse.ui.dialogs.PreferencesUtil;
18:
19: /**
20: * Open the preferences dialog
21: */
22: public class OpenPreferencesAction extends Action implements
23: ActionFactory.IWorkbenchAction {
24:
25: /**
26: * The workbench window; or <code>null</code> if this
27: * action has been <code>dispose</code>d.
28: */
29: private IWorkbenchWindow workbenchWindow;
30:
31: /**
32: * Create a new <code>OpenPreferenceAction</code>
33: * This default constructor allows the the action to be called from the welcome page.
34: */
35: public OpenPreferencesAction() {
36: this (PlatformUI.getWorkbench().getActiveWorkbenchWindow());
37: }
38:
39: /**
40: * Create a new <code>OpenPreferenceAction</code> and initialize it
41: * from the given resource bundle.
42: * @param window
43: */
44: public OpenPreferencesAction(IWorkbenchWindow window) {
45: super (WorkbenchMessages.OpenPreferences_text);
46: if (window == null) {
47: throw new IllegalArgumentException();
48: }
49: this .workbenchWindow = window;
50: // @issue action id not set
51: setToolTipText(WorkbenchMessages.OpenPreferences_toolTip);
52: window.getWorkbench().getHelpSystem().setHelp(this ,
53: IWorkbenchHelpContextIds.OPEN_PREFERENCES_ACTION);
54: }
55:
56: /* (non-Javadoc)
57: * Method declared on Action.
58: */
59: public void run() {
60: if (workbenchWindow == null) {
61: // action has been dispose
62: return;
63: }
64: PreferenceDialog dialog = PreferencesUtil
65: .createPreferenceDialogOn(null, null, null, null);
66: dialog.open();
67: }
68:
69: /* (non-Javadoc)
70: * Method declared on ActionFactory.IWorkbenchAction.
71: */
72: public void dispose() {
73: workbenchWindow = null;
74: }
75:
76: }
|