KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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;
12
13 import org.eclipse.jface.action.ContributionItem;
14 import org.eclipse.jface.action.IContributionItem;
15 import org.eclipse.jface.action.ToolBarManager;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.events.SelectionListener;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.widgets.ToolBar;
21 import org.eclipse.swt.widgets.ToolItem;
22 import org.eclipse.ui.IPageLayout;
23 import org.eclipse.ui.IViewReference;
24 import org.eclipse.ui.internal.layout.TrimToolBarBase;
25
26 public class EditorAreaTrimToolBar extends TrimToolBarBase {
27     private LayoutPart editorArea;
28     private boolean restoreOnUnzoom = false;
29     
30     // The orientation of the fast view pane when showing a view
31
private int paneOrientation;
32
33     public EditorAreaTrimToolBar(WorkbenchWindow wbw, LayoutPart editorArea) {
34         super(IPageLayout.ID_EDITOR_AREA, SWT.TOP, wbw);
35         
36         this.editorArea = editorArea;
37         dock(SWT.TOP);
38     }
39     
40     /**
41      * Put the stack back into the presentation
42      */

43     protected void restoreToPresentation() {
44         EditorSashContainer esc = (EditorSashContainer)editorArea;
45         EditorStack curStack = esc.getUpperRightEditorStack(esc.getChildren());
46         curStack.setMinimized(false);
47     }
48
49     public void initToolBarManager(final ToolBarManager mgr) {
50         // Set up the ToolBar with a restore button
51
IContributionItem restoreContrib = new ContributionItem() {
52             public void fill(ToolBar parent, int index) {
53                 ToolItem restoreItem = new ToolItem(mgr.getControl(), SWT.PUSH, index);
54                 Image tbImage = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_ETOOL_RESTORE_TRIMPART);
55                 restoreItem.setImage(tbImage);
56                 String JavaDoc menuTip = WorkbenchMessages.StandardSystemToolbar_Restore;
57                 restoreItem.setToolTipText(menuTip);
58                 restoreItem.addSelectionListener(new SelectionListener() {
59                     public void widgetDefaultSelected(SelectionEvent e) {
60                         restoreToPresentation();
61                     }
62                     public void widgetSelected(SelectionEvent e) {
63                         restoreToPresentation();
64                     }
65                 });
66             }
67         };
68         mgr.add(restoreContrib);
69
70         // Set up the ToolBar with a button represing the Editor Area
71
IContributionItem eaContrib = new ContributionItem() {
72             public void fill(ToolBar parent, int index) {
73                 ToolItem editorAreaItem = new ToolItem(mgr.getControl(), SWT.PUSH, index);
74                 Image tbImage = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_ETOOL_EDITOR_TRIMPART);
75                 editorAreaItem.setImage(tbImage);
76                 String JavaDoc menuTip = WorkbenchMessages.EditorArea_Tooltip;
77                 editorAreaItem.setToolTipText(menuTip);
78                 editorAreaItem.addSelectionListener(new SelectionListener() {
79                     public void widgetDefaultSelected(SelectionEvent e) {
80                         restoreToPresentation();
81                     }
82                     public void widgetSelected(SelectionEvent e) {
83                         restoreToPresentation();
84                     }
85                 });
86             }
87         };
88         mgr.add(eaContrib);
89     }
90
91     /* (non-Javadoc)
92      * @see org.eclipse.ui.internal.layout.TrimToolBarBase#hookControl(org.eclipse.swt.widgets.ToolBar)
93      */

94     public void hookControl(ToolBarManager mgr) {
95         // Hook a drop Listener to the control
96
// NOTE: the drop target is self-managing...it
97
// both hooks the new target and removes it on dispose
98
new FastViewDnDHandler(id, mgr, wbw);
99     }
100     
101     /**
102      * Sets whether or not the stack gets restored on an unzoom
103      * operation.
104      *
105      * @param restoreOnUnzoom
106      */

107     public void setRestoreOnUnzoom(boolean restoreOnUnzoom) {
108         this.restoreOnUnzoom = restoreOnUnzoom;
109     }
110     
111     public boolean restoreOnUnzoom() {
112         return restoreOnUnzoom;
113     }
114
115     /**
116      * @param ref
117      * @param selected
118      */

119     public void setIconSelection(IViewReference ref, boolean selected) {
120         ToolItem item = ShowFastViewContribution.getItem(tbMgr.getControl(), ref);
121         if (item != null)
122             item.setSelection(selected);
123     }
124
125     /**
126      * @return Returns the paneOrientation.
127      */

128     public int getPaneOrientation() {
129         return paneOrientation;
130     }
131 }
132
Popular Tags