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.jface.viewers.ISelection;
08: import org.eclipse.swt.widgets.Menu;
09: import org.terracotta.dso.ConfigurationHelper;
10:
11: /**
12: * Popup action submenu that contains lock-related actions.
13: *
14: * @see BaseMenuCreator
15: * @see NameLockedAction
16: * @see AutolockAction
17: */
18:
19: public class LockHandler extends BaseMenuCreator {
20: private NameLockedAction m_namedLockAction;
21: private AutolockAction m_autolockAction;
22:
23: public LockHandler() {
24: super ();
25:
26: m_namedLockAction = new NameLockedAction();
27: m_autolockAction = new AutolockAction();
28: }
29:
30: protected IJavaElement getJavaElement(ISelection selection) {
31: return m_element = ActionUtil
32: .findSelectedJavaElement(selection);
33: }
34:
35: protected void fillMenu(Menu menu) {
36: if (m_element == null) {
37: return;
38: }
39:
40: int elementType = m_element.getElementType();
41: if (elementType != IJavaElement.METHOD
42: && elementType != IJavaElement.TYPE
43: && elementType != IJavaElement.PACKAGE_FRAGMENT
44: && elementType != IJavaElement.COMPILATION_UNIT) {
45: return;
46: }
47:
48: try {
49: ConfigurationHelper config = getConfigHelper();
50:
51: if (config != null) {
52: m_namedLockAction.setJavaElement(m_element);
53: addMenuAction(menu, m_namedLockAction);
54:
55: m_autolockAction.setJavaElement(m_element);
56: addMenuAction(menu, m_autolockAction);
57: }
58: } catch (Exception e) {
59: e.printStackTrace();
60: }
61: }
62: }
|