01: /*******************************************************************************
02: * Copyright (c) 2004, 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.registry;
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.core.runtime.IStatus;
16: import org.eclipse.ui.IWorkbenchPage;
17: import org.eclipse.ui.IWorkbenchWindow;
18: import org.eclipse.ui.PartInitException;
19: import org.eclipse.ui.handlers.HandlerUtil;
20: import org.eclipse.ui.internal.misc.StatusUtil;
21: import org.eclipse.ui.statushandlers.StatusManager;
22:
23: /**
24: * Command handler to show a particular view.
25: *
26: * @since 3.0
27: */
28: public final class ShowViewHandler extends AbstractHandler {
29:
30: /**
31: * The identifier of the view this handler should open. This value should
32: * never be <code>null</code>.
33: */
34: private final String viewId;
35:
36: /**
37: * Constructs a new instance of <code>ShowViewHandler</code>.
38: *
39: * @param viewId
40: * The identifier of the view this handler should open; must not
41: * be <code>null</code>.
42: */
43: public ShowViewHandler(final String viewId) {
44: this .viewId = viewId;
45: }
46:
47: public final Object execute(final ExecutionEvent event)
48: throws ExecutionException {
49: final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil
50: .getActiveWorkbenchWindowChecked(event);
51:
52: final IWorkbenchPage activePage = activeWorkbenchWindow
53: .getActivePage();
54: if (activePage == null) {
55: return null;
56: }
57:
58: try {
59: activePage.showView(viewId);
60: } catch (PartInitException e) {
61: IStatus status = StatusUtil.newStatus(e.getStatus(), e
62: .getMessage());
63: StatusManager.getManager().handle(status,
64: StatusManager.SHOW);
65: }
66:
67: return null;
68: }
69: }
|