01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.actions;
05:
06: import org.eclipse.jdt.core.IJavaElement;
07: import org.eclipse.jdt.core.IMethod;
08: import org.eclipse.jface.viewers.ISelection;
09: import org.eclipse.swt.widgets.Menu;
10:
11: /**
12: * Popup action submenu that contains method-related actions.
13: *
14: * @see BaseMenuCreator
15: * @see AutolockAction
16: * @see NameLockedAction
17: * @see NameLockedAction
18: */
19:
20: public class MethodHandler extends BaseMenuCreator {
21: private AutolockAction m_autolockAction;
22: private NameLockedAction m_namedLockAction;
23: private DistributedMethodAction m_distributedAction;
24:
25: public MethodHandler() {
26: super ();
27:
28: m_autolockAction = new AutolockAction();
29: m_namedLockAction = new NameLockedAction();
30: m_distributedAction = new DistributedMethodAction();
31: }
32:
33: protected IJavaElement getJavaElement(ISelection selection) {
34: IJavaElement elem = null;
35: String label = "Methods";
36:
37: if ((elem = ActionUtil.findSelectedJavaElement(selection)) != null) {
38: if (elem.getElementType() == IJavaElement.METHOD) {
39: label = "Method " + elem.getElementName();
40: }
41: }
42:
43: m_delegateAction.setText(label);
44:
45: return elem;
46: }
47:
48: protected void fillMenu(Menu menu) {
49: if (m_element == null) {
50: return;
51: }
52:
53: int elementType = m_element.getElementType();
54: if (elementType != IJavaElement.METHOD
55: && elementType != IJavaElement.TYPE
56: && elementType != IJavaElement.PACKAGE_FRAGMENT
57: && elementType != IJavaElement.COMPILATION_UNIT) {
58: return;
59: }
60:
61: m_autolockAction.setJavaElement(m_element);
62: addMenuAction(menu, m_autolockAction);
63:
64: m_namedLockAction.setJavaElement(m_element);
65: addMenuAction(menu, m_namedLockAction);
66:
67: if (m_element.getElementType() == IJavaElement.METHOD) {
68: m_distributedAction.setMethod((IMethod) m_element);
69: addMenuAction(menu, m_distributedAction);
70: }
71: }
72: }
|