001: /*******************************************************************************
002: * Copyright (c) 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.ContributionItem;
013: import org.eclipse.jface.action.IContributionItem;
014: import org.eclipse.jface.action.ToolBarManager;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.events.SelectionEvent;
017: import org.eclipse.swt.events.SelectionListener;
018: import org.eclipse.swt.graphics.Image;
019: import org.eclipse.swt.widgets.ToolBar;
020: import org.eclipse.swt.widgets.ToolItem;
021: import org.eclipse.ui.IPageLayout;
022: import org.eclipse.ui.IViewReference;
023: import org.eclipse.ui.internal.layout.TrimToolBarBase;
024:
025: public class EditorAreaTrimToolBar extends TrimToolBarBase {
026: private LayoutPart editorArea;
027: private boolean restoreOnUnzoom = false;
028:
029: // The orientation of the fast view pane when showing a view
030: private int paneOrientation;
031:
032: public EditorAreaTrimToolBar(WorkbenchWindow wbw,
033: LayoutPart editorArea) {
034: super (IPageLayout.ID_EDITOR_AREA, SWT.TOP, wbw);
035:
036: this .editorArea = editorArea;
037: dock(SWT.TOP);
038: }
039:
040: /**
041: * Put the stack back into the presentation
042: */
043: protected void restoreToPresentation() {
044: EditorSashContainer esc = (EditorSashContainer) editorArea;
045: EditorStack curStack = esc.getUpperRightEditorStack(esc
046: .getChildren());
047: curStack.setMinimized(false);
048: }
049:
050: public void initToolBarManager(final ToolBarManager mgr) {
051: // Set up the ToolBar with a restore button
052: IContributionItem restoreContrib = new ContributionItem() {
053: public void fill(ToolBar parent, int index) {
054: ToolItem restoreItem = new ToolItem(mgr.getControl(),
055: SWT.PUSH, index);
056: Image tbImage = WorkbenchImages
057: .getImage(IWorkbenchGraphicConstants.IMG_ETOOL_RESTORE_TRIMPART);
058: restoreItem.setImage(tbImage);
059: String menuTip = WorkbenchMessages.StandardSystemToolbar_Restore;
060: restoreItem.setToolTipText(menuTip);
061: restoreItem
062: .addSelectionListener(new SelectionListener() {
063: public void widgetDefaultSelected(
064: SelectionEvent e) {
065: restoreToPresentation();
066: }
067:
068: public void widgetSelected(SelectionEvent e) {
069: restoreToPresentation();
070: }
071: });
072: }
073: };
074: mgr.add(restoreContrib);
075:
076: // Set up the ToolBar with a button represing the Editor Area
077: IContributionItem eaContrib = new ContributionItem() {
078: public void fill(ToolBar parent, int index) {
079: ToolItem editorAreaItem = new ToolItem(
080: mgr.getControl(), SWT.PUSH, index);
081: Image tbImage = WorkbenchImages
082: .getImage(IWorkbenchGraphicConstants.IMG_ETOOL_EDITOR_TRIMPART);
083: editorAreaItem.setImage(tbImage);
084: String menuTip = WorkbenchMessages.EditorArea_Tooltip;
085: editorAreaItem.setToolTipText(menuTip);
086: editorAreaItem
087: .addSelectionListener(new SelectionListener() {
088: public void widgetDefaultSelected(
089: SelectionEvent e) {
090: restoreToPresentation();
091: }
092:
093: public void widgetSelected(SelectionEvent e) {
094: restoreToPresentation();
095: }
096: });
097: }
098: };
099: mgr.add(eaContrib);
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.ui.internal.layout.TrimToolBarBase#hookControl(org.eclipse.swt.widgets.ToolBar)
104: */
105: public void hookControl(ToolBarManager mgr) {
106: // Hook a drop Listener to the control
107: // NOTE: the drop target is self-managing...it
108: // both hooks the new target and removes it on dispose
109: new FastViewDnDHandler(id, mgr, wbw);
110: }
111:
112: /**
113: * Sets whether or not the stack gets restored on an unzoom
114: * operation.
115: *
116: * @param restoreOnUnzoom
117: */
118: public void setRestoreOnUnzoom(boolean restoreOnUnzoom) {
119: this .restoreOnUnzoom = restoreOnUnzoom;
120: }
121:
122: public boolean restoreOnUnzoom() {
123: return restoreOnUnzoom;
124: }
125:
126: /**
127: * @param ref
128: * @param selected
129: */
130: public void setIconSelection(IViewReference ref, boolean selected) {
131: ToolItem item = ShowFastViewContribution.getItem(tbMgr
132: .getControl(), ref);
133: if (item != null)
134: item.setSelection(selected);
135: }
136:
137: /**
138: * @return Returns the paneOrientation.
139: */
140: public int getPaneOrientation() {
141: return paneOrientation;
142: }
143: }
|