KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > OpenPreferencesAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.preference.PreferenceDialog;
15 import org.eclipse.ui.IWorkbenchWindow;
16 import org.eclipse.ui.PlatformUI;
17 import org.eclipse.ui.actions.ActionFactory;
18 import org.eclipse.ui.dialogs.PreferencesUtil;
19
20 /**
21  * Open the preferences dialog
22  */

23 public class OpenPreferencesAction extends Action implements 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 JavaDoc();
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.createPreferenceDialogOn(null, null, null, null);
65         dialog.open();
66     }
67
68     /* (non-Javadoc)
69      * Method declared on ActionFactory.IWorkbenchAction.
70      */

71     public void dispose() {
72         workbenchWindow = null;
73     }
74
75 }
76
Popular Tags