KickJava   Java API By Example, From Geeks To Geeks.

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


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.ContributionItem;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.widgets.Menu;
16 import org.eclipse.swt.widgets.MenuItem;
17 import org.eclipse.ui.IViewReference;
18 import org.eclipse.ui.IWorkbenchPartReference;
19 import org.eclipse.ui.internal.FastViewBar;
20 import org.eclipse.ui.internal.IChangeListener;
21 import org.eclipse.ui.internal.IntModel;
22 import org.eclipse.ui.internal.PartPane;
23 import org.eclipse.ui.internal.RadioMenu;
24 import org.eclipse.ui.internal.ViewStackTrimToolBar;
25 import org.eclipse.ui.internal.WorkbenchMessages;
26 import org.eclipse.ui.internal.WorkbenchWindow;
27
28 /**
29  * @since 3.0
30  */

31 public class SystemMenuFastViewOrientation extends ContributionItem {
32
33     private PartPane viewPane;
34
35     private IntModel currentOrientation = new IntModel(SWT.VERTICAL);
36
37     private ViewStackTrimToolBar minimizedStack = null;
38     
39     public SystemMenuFastViewOrientation(PartPane newViewPane) {
40         this(newViewPane, null);
41     }
42
43     /**
44      * @param pane
45      * @param vstt
46      */

47     public SystemMenuFastViewOrientation(PartPane newViewPane,
48             final ViewStackTrimToolBar vstt) {
49         this.viewPane = newViewPane;
50         this.minimizedStack = vstt;
51         
52         currentOrientation.addChangeListener(new IChangeListener() {
53             public void update(boolean changed) {
54                 if (changed) {
55                     WorkbenchWindow workbenchWindow = (WorkbenchWindow) viewPane
56                             .getPage().getWorkbenchWindow();
57                     
58                     if (vstt == null) {
59                         FastViewBar bar = workbenchWindow.getFastViewBar();
60                         if (bar != null && viewPane != null) {
61                             IWorkbenchPartReference ref = viewPane.getPartReference();
62                             
63                             if (ref instanceof IViewReference) {
64                                 bar.setOrientation((IViewReference)ref,
65                                         currentOrientation.get());
66                             }
67                         }
68                     }
69                     else {
70                         vstt.setOrientation(currentOrientation.get(), workbenchWindow);
71                     }
72                 }
73             }
74         });
75     }
76
77     public void dispose() {
78         viewPane = null;
79     }
80
81     public void fill(Menu menu, int index) {
82         WorkbenchWindow workbenchWindow = (WorkbenchWindow) viewPane.getPage()
83                 .getWorkbenchWindow();
84
85         IWorkbenchPartReference ref = viewPane.getPartReference();
86         if (!(ref instanceof IViewReference))
87             return;
88         
89         if (minimizedStack == null) {
90             FastViewBar bar = workbenchWindow.getFastViewBar();
91             if (bar != null && viewPane != null) {
92                 currentOrientation.set(bar.getOrientation((IViewReference)ref));
93             }
94         }
95         else {
96             currentOrientation.set(minimizedStack.getPaneOrientation());
97         }
98         
99         MenuItem orientationItem = new MenuItem(menu, SWT.CASCADE, index);
100         {
101             orientationItem.setText(WorkbenchMessages.FastViewBar_view_orientation);
102
103             Menu orientationSwtMenu = new Menu(orientationItem);
104             RadioMenu orientationMenu = new RadioMenu(orientationSwtMenu,
105                     currentOrientation);
106             orientationMenu
107                     .addMenuItem(
108                             WorkbenchMessages.FastViewBar_horizontal, new Integer JavaDoc(SWT.HORIZONTAL));
109             orientationMenu
110                     .addMenuItem(
111                             WorkbenchMessages.FastViewBar_vertical, new Integer JavaDoc(SWT.VERTICAL));
112
113             orientationItem.setMenu(orientationSwtMenu);
114         }
115     }
116
117     public boolean isDynamic() {
118         return true;
119     }
120 }
121
Popular Tags