KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > util > StandardViewSystemMenu


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.util;
12
13 import org.eclipse.jface.action.GroupMarker;
14 import org.eclipse.jface.action.MenuManager;
15 import org.eclipse.jface.action.Separator;
16 import org.eclipse.swt.graphics.Point;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.Menu;
19 import org.eclipse.ui.internal.WorkbenchMessages;
20 import org.eclipse.ui.internal.presentations.SystemMenuClose;
21 import org.eclipse.ui.internal.presentations.SystemMenuMaximize;
22 import org.eclipse.ui.internal.presentations.SystemMenuMinimize;
23 import org.eclipse.ui.internal.presentations.SystemMenuMove;
24 import org.eclipse.ui.internal.presentations.SystemMenuRestore;
25 import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem;
26 import org.eclipse.ui.presentations.IPresentablePart;
27 import org.eclipse.ui.presentations.IStackPresentationSite;
28
29 /**
30  * Implements the system context menu that is used by the default presentation. Not
31  * intended to be subclassed by clients.
32  *
33  * @since 3.1
34  */

35 public class StandardViewSystemMenu implements ISystemMenu {
36
37     /* package */ MenuManager menuManager = new MenuManager();
38     private SystemMenuRestore restore;
39     private SystemMenuMove move;
40     private SystemMenuMinimize minimize;
41     private SystemMenuMaximize maximize;
42     private SystemMenuClose close;
43     
44     /**
45      * Create the standard view menu
46      *
47      * @param site the site to associate the view with
48      */

49     public StandardViewSystemMenu(IStackPresentationSite site) {
50         restore = new SystemMenuRestore(site);
51         move = new SystemMenuMove(site, getMoveMenuText(), false);
52         minimize = new SystemMenuMinimize(site);
53         maximize = new SystemMenuMaximize(site);
54         close = new SystemMenuClose(site);
55         
56         { // Initialize system menu
57
menuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
58
menuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
59
menuManager.add(new UpdatingActionContributionItem(restore));
60
61             menuManager.add(move);
62             menuManager.add(new GroupMarker("size")); //$NON-NLS-1$
63
menuManager.add(new GroupMarker("state")); //$NON-NLS-1$
64
menuManager.add(new UpdatingActionContributionItem(minimize));
65
66             menuManager.add(new UpdatingActionContributionItem(maximize));
67             menuManager.add(new Separator("close")); //$NON-NLS-1$
68
menuManager.add(close);
69
70             site.addSystemActions(menuManager);
71         } // End of system menu initialization
72

73     }
74
75     String JavaDoc getMoveMenuText() {
76         return WorkbenchMessages.ViewPane_moveView;
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.ui.internal.presentations.util.ISystemMenu#show(org.eclipse.swt.graphics.Point, org.eclipse.ui.presentations.IPresentablePart)
81      */

82     public void show(Control parent, Point displayCoordinates, IPresentablePart currentSelection) {
83         restore.update();
84         move.setTarget(currentSelection);
85         move.update();
86         minimize.update();
87         maximize.update();
88         close.setTarget(currentSelection);
89         
90         Menu aMenu = menuManager.createContextMenu(parent);
91         menuManager.update(true);
92         aMenu.setLocation(displayCoordinates.x, displayCoordinates.y);
93         aMenu.setVisible(true);
94     }
95     
96     /**
97      * Dispose resources associated with this menu
98      */

99     public void dispose() {
100         menuManager.dispose();
101         menuManager.removeAll();
102     }
103
104 }
105
Popular Tags