KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > registry > ShowViewHandler


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.registry;
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.core.runtime.IStatus;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.handlers.HandlerUtil;
22 import org.eclipse.ui.internal.misc.StatusUtil;
23 import org.eclipse.ui.statushandlers.StatusManager;
24
25 /**
26  * Command handler to show a particular view.
27  *
28  * @since 3.0
29  */

30 public final class ShowViewHandler extends AbstractHandler {
31     
32     /**
33      * The identifier of the view this handler should open. This value should
34      * never be <code>null</code>.
35      */

36     private final String JavaDoc viewId;
37
38     /**
39      * Constructs a new instance of <code>ShowViewHandler</code>.
40      *
41      * @param viewId
42      * The identifier of the view this handler should open; must not
43      * be <code>null</code>.
44      */

45     public ShowViewHandler(final String JavaDoc viewId) {
46         this.viewId = viewId;
47     }
48
49     public final Object JavaDoc execute(final ExecutionEvent event)
50             throws ExecutionException {
51         final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil
52                 .getActiveWorkbenchWindowChecked(event);
53
54         final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
55         if (activePage == null) {
56             return null;
57         }
58
59         try {
60             activePage.showView(viewId);
61         } catch (PartInitException e) {
62             IStatus status = StatusUtil
63                     .newStatus(e.getStatus(), e.getMessage());
64             StatusManager.getManager().handle(status, StatusManager.SHOW);
65         }
66
67         return null;
68     }
69 }
70
Popular Tags