KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.swt.SWT;
14 import org.eclipse.swt.widgets.Event;
15 import org.eclipse.ui.IWorkbenchPart;
16 import org.eclipse.ui.IWorkbenchWindow;
17 import org.eclipse.ui.actions.ActionFactory;
18 import org.eclipse.ui.actions.PartEventAction;
19
20 /**
21  * Show the menu on top of the icon in the
22  * view or editor label.
23  */

24 public class ShowPartPaneMenuAction extends PartEventAction implements
25         ActionFactory.IWorkbenchAction {
26
27     /**
28      * The workbench window; or <code>null</code> if this
29      * action has been <code>dispose</code>d.
30      */

31     private IWorkbenchWindow workbenchWindow;
32
33     private int accelerator;
34
35     /**
36      * Constructor for ShowPartPaneMenuAction.
37      *
38      * @param window the window
39      */

40     public ShowPartPaneMenuAction(IWorkbenchWindow window) {
41         super(""); //$NON-NLS-1$
42
if (window == null) {
43             throw new IllegalArgumentException JavaDoc();
44         }
45         this.workbenchWindow = window;
46         // @issue missing action id
47
initText();
48         workbenchWindow.getPartService().addPartListener(this);
49         workbenchWindow.getWorkbench().getHelpSystem().setHelp(this,
50                 IWorkbenchHelpContextIds.SHOW_PART_PANE_MENU_ACTION);
51         setActionDefinitionId("org.eclipse.ui.window.showSystemMenu"); //$NON-NLS-1$
52
}
53
54     /**
55      * Initialize the menu text and tooltip.
56      */

57     protected void initText() {
58         setText(WorkbenchMessages.ShowPartPaneMenuAction_text);
59         setToolTipText(WorkbenchMessages.ShowPartPaneMenuAction_toolTip);
60     }
61
62     /**
63      * Show the pane title menu.
64      */

65     protected void showMenu(PartPane pane) {
66         pane.showSystemMenu();
67     }
68
69     /**
70      * Updates the enabled state.
71      */

72     protected void updateState() {
73         setEnabled(getActivePart() != null);
74     }
75
76     /**
77      * See Action
78      */

79     public void runWithEvent(Event e) {
80         if (workbenchWindow == null) {
81             // action has been disposed
82
return;
83         }
84         accelerator = e.detail;
85         IWorkbenchPart part = getActivePart();
86         if (part != null) {
87             showMenu(((PartSite) part.getSite()).getPane());
88         }
89     }
90
91     /**
92      * See IPartListener
93      */

94     public void partOpened(IWorkbenchPart part) {
95         super.partOpened(part);
96         updateState();
97     }
98
99     /**
100      * See IPartListener
101      */

102     public void partClosed(IWorkbenchPart part) {
103         super.partClosed(part);
104         updateState();
105     }
106
107     /**
108      * See IPartListener
109      */

110     public void partActivated(IWorkbenchPart part) {
111         super.partActivated(part);
112         updateState();
113     }
114
115     /**
116      * See IPartListener
117      */

118     public void partDeactivated(IWorkbenchPart part) {
119         super.partDeactivated(part);
120         updateState();
121     }
122
123     public int getAccelerator() {
124         int accelerator = this.accelerator;
125         accelerator = accelerator & ~SWT.CTRL;
126         accelerator = accelerator & ~SWT.SHIFT;
127         accelerator = accelerator & ~SWT.ALT;
128         return accelerator;
129     }
130
131     /* (non-Javadoc)
132      * Method declared on ActionFactory.IWorkbenchAction.
133      */

134     public void dispose() {
135         if (workbenchWindow == null) {
136             // already disposed
137
return;
138         }
139         workbenchWindow.getPartService().removePartListener(this);
140         workbenchWindow = null;
141     }
142
143 }
144
145
Popular Tags