KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.ui.internal;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.dialogs.ErrorDialog;
15 import org.eclipse.ui.IPluginContribution;
16 import org.eclipse.ui.IViewPart;
17 import org.eclipse.ui.IViewReference;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.internal.registry.ViewDescriptor;
22 import org.eclipse.ui.views.IViewDescriptor;
23
24 /**
25  * Show a View.
26  */

27 public class ShowViewAction extends Action implements IPluginContribution {
28     private IWorkbenchWindow window;
29
30     private IViewDescriptor desc;
31     private boolean makeFast = false;
32     
33     
34     /**
35      * ShowViewAction constructor comment.
36      */

37     protected ShowViewAction(IWorkbenchWindow window, IViewDescriptor desc, boolean makeFast) {
38         super(""); //$NON-NLS-1$
39

40         // TODO: is this wart still needed?
41
String JavaDoc accel = desc instanceof ViewDescriptor ? ((ViewDescriptor) desc)
42                 .getAccelerator() : null;
43         String JavaDoc label = desc.getLabel();
44         setText(accel == null ? label : label + "@" + accel); //$NON-NLS-1$
45
setImageDescriptor(desc.getImageDescriptor());
46         setToolTipText(label);
47         window.getWorkbench().getHelpSystem().setHelp(this,
48                 IWorkbenchHelpContextIds.SHOW_VIEW_ACTION);
49         this.window = window;
50         this.desc = desc;
51         this.makeFast = makeFast;
52     }
53
54     /**
55      * Implementation of method defined on <code>IAction</code>.
56      */

57     public void run() {
58         IWorkbenchPage page = window.getActivePage();
59         if (page != null) {
60             try {
61                 if (makeFast) {
62                     WorkbenchPage wp = (WorkbenchPage) page;
63                     Perspective persp = wp.getActivePerspective();
64
65                     // If we're making a fast view then use the new mechanism directly
66
boolean useNewMinMax = Perspective.useNewMinMax(persp);
67                     if (useNewMinMax) {
68                         IViewReference ref = persp.getViewReference(desc.getId(), null);
69                         if (ref == null)
70                             return;
71
72                         persp.getFastViewManager().addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, ref, true);
73                         wp.activate(ref.getPart(true));
74                         
75                         return;
76                     }
77                     
78                     IViewReference ref = wp.findViewReference(desc.getId());
79                     
80                     if (ref == null) {
81                         IViewPart part = page.showView(desc.getId(), null, IWorkbenchPage.VIEW_CREATE);
82                         ref = (IViewReference)wp.getReference(part);
83                     }
84                     
85                     if (!wp.isFastView(ref) && persp != null) {
86                         persp.getFastViewManager().addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, ref, true);
87                     }
88                     wp.activate(ref.getPart(true));
89                 } else {
90                     page.showView(desc.getId());
91                 }
92             } catch (PartInitException e) {
93                 ErrorDialog.openError(window.getShell(), WorkbenchMessages.ShowView_errorTitle,
94                         e.getMessage(), e.getStatus());
95             }
96         }
97     }
98
99     /*
100      * (non-Javadoc)
101      *
102      * @see org.eclipse.ui.activities.support.IPluginContribution#getLocalId()
103      */

104     public String JavaDoc getLocalId() {
105         return desc.getId();
106     }
107
108     /*
109      * (non-Javadoc)
110      *
111      * @see org.eclipse.ui.activities.support.IPluginContribution#getPluginId()
112      */

113     public String JavaDoc getPluginId() {
114         return desc instanceof IPluginContribution ? ((IPluginContribution) desc)
115                 .getPluginId()
116                 : null;
117     }
118 }
119
Popular Tags