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: * Cagatay Kavukcuoglu <cagatayk@acm.org>
011: * - Fix for bug 10025 - Resizing views should not use height ratios
012: *******************************************************************************/package org.eclipse.ui.internal;
013:
014: import org.eclipse.jface.action.IMenuManager;
015: import org.eclipse.ui.internal.presentations.PresentablePart;
016: import org.eclipse.ui.internal.presentations.PresentationFactoryUtil;
017: import org.eclipse.ui.internal.presentations.SystemMenuDetach;
018: import org.eclipse.ui.internal.presentations.SystemMenuFastView;
019: import org.eclipse.ui.internal.presentations.SystemMenuSize;
020: import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem;
021: import org.eclipse.ui.presentations.AbstractPresentationFactory;
022: import org.eclipse.ui.presentations.IPresentablePart;
023: import org.eclipse.ui.presentations.IStackPresentationSite;
024: import org.eclipse.ui.presentations.StackPresentation;
025:
026: /**
027: * Manages a set of ViewPanes that are docked into the workbench window. The container for a ViewStack
028: * is always a PartSashContainer (or null), and its children are always either PartPlaceholders or ViewPanes.
029: * This contains the real behavior and state for stacks of views, although the widgets for the tabs are contributed
030: * using a StackPresentation.
031: *
032: * TODO: eliminate ViewStack and EditorStack. PartStack should be general enough to handle editors
033: * and views without any specialization for editors and views. The differences should be in the
034: * presentation and in the PartPanes themselves.
035: *
036: * TODO: eliminate PartPlaceholder. Placeholders should not be children of the ViewStack.
037: *
038: */
039: public class ViewStack extends PartStack {
040:
041: private boolean allowStateChanges;
042:
043: private WorkbenchPage page;
044:
045: private SystemMenuSize sizeItem = new SystemMenuSize(null);
046:
047: private SystemMenuFastView fastViewAction;
048:
049: private SystemMenuDetach detachViewAction;
050:
051: public void addSystemActions(IMenuManager menuManager) {
052: appendToGroupIfPossible(
053: menuManager,
054: "misc", new UpdatingActionContributionItem(fastViewAction)); //$NON-NLS-1$
055: appendToGroupIfPossible(
056: menuManager,
057: "misc", new UpdatingActionContributionItem(detachViewAction)); //$NON-NLS-1$
058: sizeItem = new SystemMenuSize(getSelection());
059: appendToGroupIfPossible(menuManager, "size", sizeItem); //$NON-NLS-1$
060: }
061:
062: public ViewStack(WorkbenchPage page) {
063: this (page, true);
064: }
065:
066: public ViewStack(WorkbenchPage page, boolean allowsStateChanges) {
067: this (page, allowsStateChanges,
068: PresentationFactoryUtil.ROLE_VIEW, null);
069: }
070:
071: public ViewStack(WorkbenchPage page, boolean allowsStateChanges,
072: int appearance, AbstractPresentationFactory factory) {
073: super (appearance, factory);
074:
075: this .page = page;
076: setID(this .toString());
077: // Each folder has a unique ID so relative positioning is unambiguous.
078:
079: this .allowStateChanges = allowsStateChanges;
080: fastViewAction = new SystemMenuFastView(getPresentationSite());
081: detachViewAction = new SystemMenuDetach(getPresentationSite());
082: }
083:
084: protected WorkbenchPage getPage() {
085: return page;
086: }
087:
088: protected boolean canMoveFolder() {
089: Perspective perspective = page.getActivePerspective();
090:
091: if (perspective == null) {
092: // Shouldn't happen -- can't have a ViewStack without a
093: // perspective
094: return false;
095: }
096:
097: // We need to search if one of the presentations is not moveable
098: // if that's the case the whole folder should not be moveable
099: IStackPresentationSite presenationSite;
100:
101: if ((presenationSite = getPresentationSite()) != null) {
102: IPresentablePart[] parts = presenationSite.getPartList();
103: for (int i = 0; i < parts.length; i++) {
104: if (!presenationSite.isPartMoveable(parts[i])) {
105: return false;
106: }
107: }
108: }
109:
110: return !perspective.isFixedLayout();
111: }
112:
113: protected void updateActions(PresentablePart current) {
114: ViewPane pane = null;
115:
116: if (current != null && current.getPane() instanceof ViewPane) {
117: pane = (ViewPane) current.getPane();
118: }
119:
120: fastViewAction.setPane(current);
121: detachViewAction.setPane(pane);
122: sizeItem.setPane(pane);
123: }
124:
125: /**
126: * Sets the minimized state for this stack. The part may call this method to
127: * minimize or restore itself. The minimized state only affects the view
128: * when unzoomed.
129: *
130: * This implementation is specific to the 3.3 presentation's
131: * min/max story; otherwise it just forwards the call.
132: */
133: public void setMinimized(boolean minimized) {
134: // 'Smart' minimize; move the stack to the trim
135: Perspective persp = getPage().getActivePerspective();
136: if (Perspective.useNewMinMax(persp)) {
137: FastViewManager fvm = persp.getFastViewManager();
138: if (minimized) {
139: fvm.moveToTrim(this , false);
140: } else {
141: // First, if we're maximized then revert
142: if (persp.getPresentation().getMaximizedStack() != null) {
143: PartStack maxStack = persp.getPresentation()
144: .getMaximizedStack();
145: if (maxStack != null) {
146: maxStack
147: .setState(IStackPresentationSite.STATE_RESTORED);
148: }
149: }
150:
151: fvm.restoreToPresentation(getID());
152: }
153: }
154:
155: super .setMinimized(minimized);
156: }
157:
158: /* (non-Javadoc)
159: * @see org.eclipse.ui.internal.PartStack#isMoveable(org.eclipse.ui.presentations.IPresentablePart)
160: */
161: protected boolean isMoveable(IPresentablePart part) {
162: ViewPane pane = (ViewPane) getPaneFor(part);
163: Perspective perspective = page.getActivePerspective();
164: if (perspective == null) {
165: // Shouldn't happen -- can't have a ViewStack without a
166: // perspective
167: return true;
168: }
169: return perspective.isMoveable(pane.getViewReference());
170: }
171:
172: /* (non-Javadoc)
173: * @see org.eclipse.ui.internal.PartStack#supportsState(int)
174: */
175: protected boolean supportsState(int newState) {
176: if (page.isFixedLayout()) {
177: return false;
178: }
179: return allowStateChanges;
180: }
181:
182: /* (non-Javadoc)
183: * @see org.eclipse.ui.internal.PartStack#derefPart(org.eclipse.ui.internal.LayoutPart)
184: */
185: protected void derefPart(LayoutPart toDeref) {
186: page.getActivePerspective().getPresentation()
187: .derefPart(toDeref);
188: }
189:
190: /* (non-Javadoc)
191: * @see org.eclipse.ui.internal.PartStack#allowsDrop(org.eclipse.ui.internal.PartPane)
192: */
193: protected boolean allowsDrop(PartPane part) {
194: return part instanceof ViewPane;
195: }
196:
197: /**
198: * Get the presentation for testing purposes. This is for testing
199: * purposes <b>ONLY</b>.
200: *
201: * @return the presentation in use for this view stack
202: * @since 3.2
203: */
204: public StackPresentation getTestPresentation() {
205: return getPresentation();
206: }
207: }
|