KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Cagatay Kavukcuoglu <cagatayk@acm.org>
11  * - Fix for bug 10025 - Resizing views should not use height ratios
12  *******************************************************************************/

13 package org.eclipse.ui.internal;
14
15 import org.eclipse.jface.action.IMenuManager;
16 import org.eclipse.ui.internal.presentations.PresentablePart;
17 import org.eclipse.ui.internal.presentations.PresentationFactoryUtil;
18 import org.eclipse.ui.internal.presentations.SystemMenuDetach;
19 import org.eclipse.ui.internal.presentations.SystemMenuFastView;
20 import org.eclipse.ui.internal.presentations.SystemMenuSize;
21 import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem;
22 import org.eclipse.ui.presentations.AbstractPresentationFactory;
23 import org.eclipse.ui.presentations.IPresentablePart;
24 import org.eclipse.ui.presentations.IStackPresentationSite;
25 import org.eclipse.ui.presentations.StackPresentation;
26
27 /**
28  * Manages a set of ViewPanes that are docked into the workbench window. The container for a ViewStack
29  * is always a PartSashContainer (or null), and its children are always either PartPlaceholders or ViewPanes.
30  * This contains the real behavior and state for stacks of views, although the widgets for the tabs are contributed
31  * using a StackPresentation.
32  *
33  * TODO: eliminate ViewStack and EditorStack. PartStack should be general enough to handle editors
34  * and views without any specialization for editors and views. The differences should be in the
35  * presentation and in the PartPanes themselves.
36  *
37  * TODO: eliminate PartPlaceholder. Placeholders should not be children of the ViewStack.
38  *
39  */

40 public class ViewStack extends PartStack {
41
42     private boolean allowStateChanges;
43
44     private WorkbenchPage page;
45
46     private SystemMenuSize sizeItem = new SystemMenuSize(null);
47
48     private SystemMenuFastView fastViewAction;
49
50     private SystemMenuDetach detachViewAction;
51     
52     public void addSystemActions(IMenuManager menuManager) {
53         appendToGroupIfPossible(menuManager,
54                 "misc", new UpdatingActionContributionItem(fastViewAction)); //$NON-NLS-1$
55
appendToGroupIfPossible(menuManager,
56                 "misc", new UpdatingActionContributionItem(detachViewAction)); //$NON-NLS-1$
57
sizeItem = new SystemMenuSize(getSelection());
58         appendToGroupIfPossible(menuManager, "size", sizeItem); //$NON-NLS-1$
59
}
60
61     public ViewStack(WorkbenchPage page) {
62         this(page, true);
63     }
64
65     public ViewStack(WorkbenchPage page, boolean allowsStateChanges) {
66         this(page, allowsStateChanges, PresentationFactoryUtil.ROLE_VIEW, null);
67     }
68
69     public ViewStack(WorkbenchPage page, boolean allowsStateChanges,
70             int appearance, AbstractPresentationFactory factory) {
71         super(appearance, factory);
72
73         this.page = page;
74         setID(this.toString());
75         // Each folder has a unique ID so relative positioning is unambiguous.
76

77         this.allowStateChanges = allowsStateChanges;
78         fastViewAction = new SystemMenuFastView(getPresentationSite());
79         detachViewAction = new SystemMenuDetach(getPresentationSite());
80     }
81
82     protected WorkbenchPage getPage() {
83         return page;
84     }
85
86     protected boolean canMoveFolder() {
87         Perspective perspective = page.getActivePerspective();
88
89         if (perspective == null) {
90             // Shouldn't happen -- can't have a ViewStack without a
91
// perspective
92
return false;
93         }
94
95         return !perspective.isFixedLayout();
96     }
97
98     protected void updateActions(PresentablePart current) {
99         ViewPane pane = null;
100         
101         if (current != null && current.getPane() instanceof ViewPane) {
102             pane = (ViewPane) current.getPane();
103         }
104
105         fastViewAction.setPane(current);
106         detachViewAction.setPane(pane);
107         sizeItem.setPane(pane);
108     }
109
110     /**
111      * Sets the minimized state for this stack. The part may call this method to
112      * minimize or restore itself. The minimized state only affects the view
113      * when unzoomed.
114      *
115      * This implementation is specific to the 3.3 presentation's
116      * min/max story; otherwise it just forwards the call.
117      */

118     public void setMinimized(boolean minimized) {
119         // 'Smart' minimize; move the stack to the trim
120
Perspective persp = getPage().getActivePerspective();
121         if (Perspective.useNewMinMax(persp)) {
122             FastViewManager fvm = persp.getFastViewManager();
123             if (minimized) {
124                 fvm.moveToTrim(this, false);
125             } else {
126                 // First, if we're maximized then revert
127
if (persp.getPresentation().getMaximizedStack() != null) {
128                     PartStack maxStack = persp.getPresentation().getMaximizedStack();
129                     if (maxStack != null) {
130                         maxStack.setState(IStackPresentationSite.STATE_RESTORED);
131                     }
132                 }
133                 
134                 fvm.restoreToPresentation(getID());
135             }
136         }
137         
138         super.setMinimized(minimized);
139     }
140
141     /* (non-Javadoc)
142      * @see org.eclipse.ui.internal.PartStack#isMoveable(org.eclipse.ui.presentations.IPresentablePart)
143      */

144     protected boolean isMoveable(IPresentablePart part) {
145         ViewPane pane = (ViewPane) getPaneFor(part);
146         Perspective perspective = page.getActivePerspective();
147         if (perspective == null) {
148             // Shouldn't happen -- can't have a ViewStack without a
149
// perspective
150
return true;
151         }
152         return perspective.isMoveable(pane.getViewReference());
153     }
154
155     /* (non-Javadoc)
156      * @see org.eclipse.ui.internal.PartStack#supportsState(int)
157      */

158     protected boolean supportsState(int newState) {
159         if (page.isFixedLayout()) {
160             return false;
161         }
162         return allowStateChanges;
163     }
164
165     /* (non-Javadoc)
166      * @see org.eclipse.ui.internal.PartStack#derefPart(org.eclipse.ui.internal.LayoutPart)
167      */

168     protected void derefPart(LayoutPart toDeref) {
169         page.getActivePerspective().getPresentation().derefPart(toDeref);
170     }
171
172     /* (non-Javadoc)
173      * @see org.eclipse.ui.internal.PartStack#allowsDrop(org.eclipse.ui.internal.PartPane)
174      */

175     protected boolean allowsDrop(PartPane part) {
176         return part instanceof ViewPane;
177     }
178
179     /**
180      * Get the presentation for testing purposes. This is for testing
181      * purposes <b>ONLY</b>.
182      *
183      * @return the presentation in use for this view stack
184      * @since 3.2
185      */

186     public StackPresentation getTestPresentation() {
187         return getPresentation();
188     }
189 }
190
Popular Tags