001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal;
011:
012: import org.eclipse.jface.action.Action;
013: import org.eclipse.jface.dialogs.ErrorDialog;
014: import org.eclipse.ui.IPluginContribution;
015: import org.eclipse.ui.IViewPart;
016: import org.eclipse.ui.IViewReference;
017: import org.eclipse.ui.IWorkbenchPage;
018: import org.eclipse.ui.IWorkbenchWindow;
019: import org.eclipse.ui.PartInitException;
020: import org.eclipse.ui.internal.registry.ViewDescriptor;
021: import org.eclipse.ui.views.IViewDescriptor;
022:
023: /**
024: * Show a View.
025: */
026: public class ShowViewAction extends Action implements
027: IPluginContribution {
028: private IWorkbenchWindow window;
029:
030: private IViewDescriptor desc;
031: private boolean makeFast = false;
032:
033: /**
034: * ShowViewAction constructor comment.
035: */
036: protected ShowViewAction(IWorkbenchWindow window,
037: IViewDescriptor desc, boolean makeFast) {
038: super (""); //$NON-NLS-1$
039:
040: // TODO: is this wart still needed?
041: String accel = desc instanceof ViewDescriptor ? ((ViewDescriptor) desc)
042: .getAccelerator()
043: : null;
044: String label = desc.getLabel();
045: setText(accel == null ? label : label + "@" + accel); //$NON-NLS-1$
046: setImageDescriptor(desc.getImageDescriptor());
047: setToolTipText(label);
048: window.getWorkbench().getHelpSystem().setHelp(this ,
049: IWorkbenchHelpContextIds.SHOW_VIEW_ACTION);
050: this .window = window;
051: this .desc = desc;
052: this .makeFast = makeFast;
053: }
054:
055: /**
056: * Implementation of method defined on <code>IAction</code>.
057: */
058: public void run() {
059: IWorkbenchPage page = window.getActivePage();
060: if (page != null) {
061: try {
062: if (makeFast) {
063: WorkbenchPage wp = (WorkbenchPage) page;
064: Perspective persp = wp.getActivePerspective();
065:
066: // If we're making a fast view then use the new mechanism directly
067: boolean useNewMinMax = Perspective
068: .useNewMinMax(persp);
069: if (useNewMinMax) {
070: IViewReference ref = persp.getViewReference(
071: desc.getId(), null);
072: if (ref == null)
073: return;
074:
075: persp.getFastViewManager().addViewReference(
076: FastViewBar.FASTVIEWBAR_ID, -1, ref,
077: true);
078: wp.activate(ref.getPart(true));
079:
080: return;
081: }
082:
083: IViewReference ref = wp.findViewReference(desc
084: .getId());
085:
086: if (ref == null) {
087: IViewPart part = page.showView(desc.getId(),
088: null, IWorkbenchPage.VIEW_CREATE);
089: ref = (IViewReference) wp.getReference(part);
090: }
091:
092: if (!wp.isFastView(ref) && persp != null) {
093: persp.getFastViewManager().addViewReference(
094: FastViewBar.FASTVIEWBAR_ID, -1, ref,
095: true);
096: }
097: wp.activate(ref.getPart(true));
098: } else {
099: page.showView(desc.getId());
100: }
101: } catch (PartInitException e) {
102: ErrorDialog.openError(window.getShell(),
103: WorkbenchMessages.ShowView_errorTitle, e
104: .getMessage(), e.getStatus());
105: }
106: }
107: }
108:
109: /*
110: * (non-Javadoc)
111: *
112: * @see org.eclipse.ui.activities.support.IPluginContribution#getLocalId()
113: */
114: public String getLocalId() {
115: return desc.getId();
116: }
117:
118: /*
119: * (non-Javadoc)
120: *
121: * @see org.eclipse.ui.activities.support.IPluginContribution#getPluginId()
122: */
123: public String getPluginId() {
124: return desc instanceof IPluginContribution ? ((IPluginContribution) desc)
125: .getPluginId()
126: : null;
127: }
128: }
|