Project

General

Profile

Download (2.05 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 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.gef;
12

    
13
import org.eclipse.jface.action.IMenuListener;
14
import org.eclipse.jface.action.IMenuManager;
15
import org.eclipse.jface.action.MenuManager;
16

    
17
/**
18
 * Extends MenuManager to allow populating the menu directly from the manager
19
 * itself. Using this class is no different than using a standalone
20
 * <code>MenuManager</code>, and adding a menuAboutToShow listener.
21
 * 
22
 * @author hudsonr
23
 */
24
public abstract class ContextMenuProvider extends MenuManager implements
25
		IMenuListener {
26

    
27
	private EditPartViewer viewer;
28

    
29
	/**
30
	 * Constructs a context menu for the specified EditPartViewer.
31
	 * 
32
	 * @param viewer
33
	 *            the editpart viewer
34
	 */
35
	public ContextMenuProvider(EditPartViewer viewer) {
36
		setViewer(viewer);
37
		addMenuListener(this);
38
		setRemoveAllWhenShown(true);
39
	}
40

    
41
	/**
42
	 * Called when the menu is about to show. Subclasses must implement this
43
	 * method to populate the menu each time it is shown.
44
	 * 
45
	 * @param menu
46
	 *            this parameter is actually <code>this</code> object
47
	 */
48
	public abstract void buildContextMenu(IMenuManager menu);
49

    
50
	/**
51
	 * Returns the EditPartViewer
52
	 * 
53
	 * @return the viewer
54
	 */
55
	protected EditPartViewer getViewer() {
56
		return viewer;
57
	}
58

    
59
	/**
60
	 * @see IMenuListener#menuAboutToShow(IMenuManager)
61
	 */
62
	public void menuAboutToShow(IMenuManager menu) {
63
		buildContextMenu(menu);
64
	}
65

    
66
	/**
67
	 * Sets the editpart viewer. Called during construction.
68
	 * 
69
	 * @param viewer
70
	 *            the viewer
71
	 */
72
	protected void setViewer(EditPartViewer viewer) {
73
		this.viewer = viewer;
74
	}
75

    
76
}
(7-7/44)