KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > SystemMenuFastView


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 package org.eclipse.ui.internal.presentations;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.ui.IViewReference;
15 import org.eclipse.ui.IWorkbenchPartReference;
16 import org.eclipse.ui.internal.FastViewBar;
17 import org.eclipse.ui.internal.FastViewManager;
18 import org.eclipse.ui.internal.Perspective;
19 import org.eclipse.ui.internal.ViewPane;
20 import org.eclipse.ui.internal.WorkbenchMessages;
21 import org.eclipse.ui.internal.WorkbenchWindow;
22 import org.eclipse.ui.presentations.IStackPresentationSite;
23
24 public class SystemMenuFastView extends Action implements ISelfUpdatingAction {
25
26     private PresentablePart viewPane;
27
28     private IStackPresentationSite site;
29
30     private boolean realFV = true;
31     
32     public SystemMenuFastView(IStackPresentationSite site) {
33         this.site = site;
34         setText(WorkbenchMessages.ViewPane_fastView);
35         update();
36     }
37
38     public void setPane(PresentablePart newPane) {
39         viewPane = newPane;
40         update();
41     }
42     
43     public void update() {
44         IViewReference viewRef = getReference();
45         if (viewRef == null) {
46             setEnabled(false);
47             return;
48         }
49         
50         // Are we showing a 'real' fast view or a minimized view ?
51
Perspective persp = viewPane.getPane().getPage().getActivePerspective();
52         FastViewManager fvm = persp.getFastViewManager();
53         
54         String JavaDoc trimId = null;
55         if (fvm != null)
56             trimId = fvm.getIdForRef(viewRef);
57         realFV = trimId == null || FastViewBar.FASTVIEWBAR_ID.equals(trimId);
58
59         // it's 'restore' if we're not using a real fast view
60
if (realFV) {
61             setText(WorkbenchMessages.ViewPane_fastView);
62         }
63         else {
64             setText(WorkbenchMessages.StandardSystemToolbar_Restore);
65             setChecked(false);
66         }
67         
68         if (!site.isPartMoveable(viewPane)) {
69             setEnabled(false);
70         } else {
71             setEnabled(true);
72             
73             if (realFV)
74                 setChecked(persp.isFastView(viewRef));
75         }
76     }
77
78     private IViewReference getReference() {
79         IViewReference viewRef = null;
80         
81         if (viewPane != null) {
82             IWorkbenchPartReference ref = viewPane.getPane().getPartReference();
83             
84             if (ref instanceof IViewReference) {
85                 viewRef = (IViewReference) ref;
86             }
87         }
88         return viewRef;
89     }
90
91     public boolean shouldBeVisible() {
92         if (viewPane == null || viewPane.getPane().getPage() == null) {
93             return false;
94         }
95
96         WorkbenchWindow workbenchWindow = (WorkbenchWindow) viewPane.getPane().getPage()
97                 .getWorkbenchWindow();
98
99         return workbenchWindow.getShowFastViewBars() && viewPane != null
100                 && site.isPartMoveable(viewPane);
101     }
102
103     public void dispose() {
104         viewPane = null;
105     }
106
107     public void run() {
108         if (realFV) {
109             if (viewPane.getPane() instanceof ViewPane) {
110                 ViewPane pane = (ViewPane) viewPane.getPane();
111                 
112                 if (!isChecked()) {
113                     pane.doMakeFast();
114                 } else {
115                     pane.doRemoveFast();
116                 }
117             }
118         }
119         else {
120             // We're a minimized stack...restore it
121
IViewReference viewRef = getReference();
122             
123             Perspective persp = viewPane.getPane().getPage().getActivePerspective();
124             FastViewManager fvm = persp.getFastViewManager();
125             String JavaDoc trimId = fvm.getIdForRef(viewRef);
126             fvm.restoreToPresentation(trimId);
127         }
128     }
129 }
130
Popular Tags