01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 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.handlers;
11:
12: import org.eclipse.core.commands.AbstractHandler;
13: import org.eclipse.core.commands.ExecutionEvent;
14: import org.eclipse.core.commands.ExecutionException;
15: import org.eclipse.jface.preference.PreferenceDialog;
16: import org.eclipse.swt.widgets.Shell;
17: import org.eclipse.ui.IWorkbenchWindow;
18: import org.eclipse.ui.dialogs.PreferencesUtil;
19: import org.eclipse.ui.handlers.HandlerUtil;
20:
21: /**
22: * <p>
23: * Shows the given preference page. If no preference page id is specified in the
24: * parameters, then this opens the preferences dialog to whatever page was
25: * active the last time the dialog was shown.
26: * </p>
27: * <p>
28: * This class is not intended for use outside of the
29: * <code>org.eclipse.ui.workbench</code> plug-in.
30: * </p>
31: *
32: * @since 3.2
33: */
34: public final class ShowPreferencePageHandler extends AbstractHandler {
35:
36: /**
37: * The name of the parameter providing the view identifier.
38: */
39: private static final String PARAMETER_ID_PREFERENCE_PAGE_ID = "preferencePageId"; //$NON-NLS-1$
40:
41: public final Object execute(final ExecutionEvent event)
42: throws ExecutionException {
43: final String preferencePageId = event
44: .getParameter(PARAMETER_ID_PREFERENCE_PAGE_ID);
45: final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil
46: .getActiveWorkbenchWindowChecked(event);
47:
48: final Shell shell = activeWorkbenchWindow.getShell();
49: if (shell == null) {
50: throw new ExecutionException(
51: "no shell for active workbench window"); //$NON-NLS-1$
52: }
53:
54: final PreferenceDialog dialog = PreferencesUtil
55: .createPreferenceDialogOn(shell, preferencePageId,
56: null, null);
57: dialog.open();
58:
59: return null;
60: }
61:
62: }
|