KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > handlers > ShowPreferencePageHandler


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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
12 package org.eclipse.ui.internal.handlers;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.jface.preference.PreferenceDialog;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.dialogs.PreferencesUtil;
21 import org.eclipse.ui.handlers.HandlerUtil;
22
23 /**
24  * <p>
25  * Shows the given preference page. If no preference page id is specified in the
26  * parameters, then this opens the preferences dialog to whatever page was
27  * active the last time the dialog was shown.
28  * </p>
29  * <p>
30  * This class is not intended for use outside of the
31  * <code>org.eclipse.ui.workbench</code> plug-in.
32  * </p>
33  *
34  * @since 3.2
35  */

36 public final class ShowPreferencePageHandler extends AbstractHandler {
37
38     /**
39      * The name of the parameter providing the view identifier.
40      */

41     private static final String JavaDoc PARAMETER_ID_PREFERENCE_PAGE_ID = "preferencePageId"; //$NON-NLS-1$
42

43     public final Object JavaDoc execute(final ExecutionEvent event)
44             throws ExecutionException {
45         final String JavaDoc preferencePageId = event
46                 .getParameter(PARAMETER_ID_PREFERENCE_PAGE_ID);
47         final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil
48                 .getActiveWorkbenchWindowChecked(event);
49
50         final Shell shell = activeWorkbenchWindow.getShell();
51         if (shell == null) {
52             throw new ExecutionException("no shell for active workbench window"); //$NON-NLS-1$
53
}
54
55         final PreferenceDialog dialog = PreferencesUtil
56                 .createPreferenceDialogOn(shell, preferencePageId, null, null);
57         dialog.open();
58
59         return null;
60     }
61
62 }
63
Popular Tags