001: /*******************************************************************************
002: * Copyright (c) 2004, 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.presentations;
011:
012: import org.eclipse.jface.action.Action;
013: import org.eclipse.ui.IViewReference;
014: import org.eclipse.ui.IWorkbenchPartReference;
015: import org.eclipse.ui.internal.FastViewBar;
016: import org.eclipse.ui.internal.FastViewManager;
017: import org.eclipse.ui.internal.Perspective;
018: import org.eclipse.ui.internal.ViewPane;
019: import org.eclipse.ui.internal.WorkbenchMessages;
020: import org.eclipse.ui.internal.WorkbenchWindow;
021: import org.eclipse.ui.presentations.IStackPresentationSite;
022:
023: public class SystemMenuFastView extends Action implements
024: ISelfUpdatingAction {
025:
026: private PresentablePart viewPane;
027:
028: private IStackPresentationSite site;
029:
030: private boolean realFV = true;
031:
032: public SystemMenuFastView(IStackPresentationSite site) {
033: this .site = site;
034: setText(WorkbenchMessages.ViewPane_fastView);
035: update();
036: }
037:
038: public void setPane(PresentablePart newPane) {
039: viewPane = newPane;
040: update();
041: }
042:
043: public void update() {
044: IViewReference viewRef = getReference();
045: if (viewRef == null) {
046: setEnabled(false);
047: return;
048: }
049:
050: // Are we showing a 'real' fast view or a minimized view ?
051: Perspective persp = viewPane.getPane().getPage()
052: .getActivePerspective();
053: FastViewManager fvm = persp.getFastViewManager();
054:
055: String trimId = null;
056: if (fvm != null)
057: trimId = fvm.getIdForRef(viewRef);
058: realFV = trimId == null
059: || FastViewBar.FASTVIEWBAR_ID.equals(trimId);
060:
061: // it's 'restore' if we're not using a real fast view
062: if (realFV) {
063: setText(WorkbenchMessages.ViewPane_fastView);
064: } else {
065: setText(WorkbenchMessages.StandardSystemToolbar_Restore);
066: setChecked(false);
067: }
068:
069: if (!site.isPartMoveable(viewPane)) {
070: setEnabled(false);
071: } else {
072: setEnabled(true);
073:
074: if (realFV)
075: setChecked(persp.isFastView(viewRef));
076: }
077: }
078:
079: private IViewReference getReference() {
080: IViewReference viewRef = null;
081:
082: if (viewPane != null) {
083: IWorkbenchPartReference ref = viewPane.getPane()
084: .getPartReference();
085:
086: if (ref instanceof IViewReference) {
087: viewRef = (IViewReference) ref;
088: }
089: }
090: return viewRef;
091: }
092:
093: public boolean shouldBeVisible() {
094: if (viewPane == null || viewPane.getPane().getPage() == null) {
095: return false;
096: }
097:
098: WorkbenchWindow workbenchWindow = (WorkbenchWindow) viewPane
099: .getPane().getPage().getWorkbenchWindow();
100:
101: return workbenchWindow.getShowFastViewBars()
102: && viewPane != null && site.isPartMoveable(viewPane);
103: }
104:
105: public void dispose() {
106: viewPane = null;
107: }
108:
109: public void run() {
110: if (realFV) {
111: if (viewPane.getPane() instanceof ViewPane) {
112: ViewPane pane = (ViewPane) viewPane.getPane();
113:
114: if (!isChecked()) {
115: pane.doMakeFast();
116: } else {
117: pane.doRemoveFast();
118: }
119: }
120: } else {
121: // We're a minimized stack...restore it
122: IViewReference viewRef = getReference();
123:
124: Perspective persp = viewPane.getPane().getPage()
125: .getActivePerspective();
126: FastViewManager fvm = persp.getFastViewManager();
127: String trimId = fvm.getIdForRef(viewRef);
128: fvm.restoreToPresentation(trimId);
129: }
130: }
131: }
|