001: /*******************************************************************************
002: * Copyright (c) 2004, 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.presentations.util;
011:
012: import org.eclipse.jface.action.GroupMarker;
013: import org.eclipse.jface.action.MenuManager;
014: import org.eclipse.jface.action.Separator;
015: import org.eclipse.swt.graphics.Point;
016: import org.eclipse.swt.widgets.Control;
017: import org.eclipse.swt.widgets.Menu;
018: import org.eclipse.ui.internal.WorkbenchMessages;
019: import org.eclipse.ui.internal.presentations.SystemMenuClose;
020: import org.eclipse.ui.internal.presentations.SystemMenuMaximize;
021: import org.eclipse.ui.internal.presentations.SystemMenuMinimize;
022: import org.eclipse.ui.internal.presentations.SystemMenuMove;
023: import org.eclipse.ui.internal.presentations.SystemMenuRestore;
024: import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem;
025: import org.eclipse.ui.presentations.IPresentablePart;
026: import org.eclipse.ui.presentations.IStackPresentationSite;
027:
028: /**
029: * Implements the system context menu that is used by the default presentation. Not
030: * intended to be subclassed by clients.
031: *
032: * @since 3.1
033: */
034: public class StandardViewSystemMenu implements ISystemMenu {
035:
036: /* package */MenuManager menuManager = new MenuManager();
037: private SystemMenuRestore restore;
038: private SystemMenuMove move;
039: private SystemMenuMinimize minimize;
040: private SystemMenuMaximize maximize;
041: private SystemMenuClose close;
042:
043: /**
044: * Create the standard view menu
045: *
046: * @param site the site to associate the view with
047: */
048: public StandardViewSystemMenu(IStackPresentationSite site) {
049: restore = new SystemMenuRestore(site);
050: move = new SystemMenuMove(site, getMoveMenuText(), false);
051: minimize = new SystemMenuMinimize(site);
052: maximize = new SystemMenuMaximize(site);
053: close = new SystemMenuClose(site);
054:
055: { // Initialize system menu
056: menuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
057: menuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
058: menuManager
059: .add(new UpdatingActionContributionItem(restore));
060:
061: menuManager.add(move);
062: menuManager.add(new GroupMarker("size")); //$NON-NLS-1$
063: menuManager.add(new GroupMarker("state")); //$NON-NLS-1$
064: menuManager
065: .add(new UpdatingActionContributionItem(minimize));
066:
067: menuManager
068: .add(new UpdatingActionContributionItem(maximize));
069: menuManager.add(new Separator("close")); //$NON-NLS-1$
070: menuManager.add(close);
071:
072: site.addSystemActions(menuManager);
073: } // End of system menu initialization
074:
075: }
076:
077: String getMoveMenuText() {
078: return WorkbenchMessages.ViewPane_moveView;
079: }
080:
081: /* (non-Javadoc)
082: * @see org.eclipse.ui.internal.presentations.util.ISystemMenu#show(org.eclipse.swt.graphics.Point, org.eclipse.ui.presentations.IPresentablePart)
083: */
084: public void show(Control parent, Point displayCoordinates,
085: IPresentablePart currentSelection) {
086: restore.update();
087: move.setTarget(currentSelection);
088: move.update();
089: minimize.update();
090: maximize.update();
091: close.setTarget(currentSelection);
092:
093: Menu aMenu = menuManager.createContextMenu(parent);
094: menuManager.update(true);
095: aMenu.setLocation(displayCoordinates.x, displayCoordinates.y);
096: aMenu.setVisible(true);
097: }
098:
099: /**
100: * Dispose resources associated with this menu
101: */
102: public void dispose() {
103: menuManager.dispose();
104: menuManager.removeAll();
105: }
106:
107: }
|