KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > actions > LockHandler


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.actions;
5
6 import org.eclipse.jdt.core.IJavaElement;
7 import org.eclipse.jface.viewers.ISelection;
8 import org.eclipse.swt.widgets.Menu;
9 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.findSelectedJavaElement(selection);
32   }
33   
34   protected void fillMenu(Menu menu) {
35     if(m_element == null) {
36       return;
37     }
38
39     int elementType = m_element.getElementType();
40     if(elementType != IJavaElement.METHOD &&
41        elementType != IJavaElement.TYPE &&
42        elementType != IJavaElement.PACKAGE_FRAGMENT &&
43        elementType != IJavaElement.COMPILATION_UNIT) {
44       return;
45     }
46     
47     try {
48       ConfigurationHelper config = getConfigHelper();
49
50       if(config != null) {
51         m_namedLockAction.setJavaElement(m_element);
52         addMenuAction(menu, m_namedLockAction);
53           
54         m_autolockAction.setJavaElement(m_element);
55         addMenuAction(menu, m_autolockAction);
56       }
57     } catch(Exception JavaDoc e) {
58       e.printStackTrace();
59     }
60   }
61 }
62
Popular Tags