KickJava   Java API By Example, From Geeks To Geeks.

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


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.ICompilationUnit;
7 import org.eclipse.jdt.core.IJavaElement;
8 import org.eclipse.jdt.core.IType;
9 import org.eclipse.jdt.core.JavaModelException;
10 import org.eclipse.jface.viewers.ISelection;
11 import org.eclipse.swt.widgets.Menu;
12
13 /**
14  * Popup action submenu that contains module-related actions.
15  *
16  * @see org.eclipse.jdt.core.ICompilationUnit
17  * @see BaseMenuCreator
18  * @see AdaptableAction
19  * @see ExcludedTypeAction
20  * @see BootJarTypeAction
21  */

22
23 public class ModuleHandler extends BaseMenuCreator {
24   private AdaptableAction m_adaptableAction;
25   private ExcludedTypeAction m_excludedAction;
26   private BootJarTypeAction m_bootJarAction;
27   
28   public ModuleHandler() {
29     super();
30     
31     m_adaptableAction = new AdaptableAction();
32     m_excludedAction = new ExcludedTypeAction();
33     m_bootJarAction = new BootJarTypeAction();
34   }
35   
36   private static boolean isKnownConcrete(IType type) {
37     try {
38       return !type.isInterface();
39     } catch(JavaModelException jme) {
40       return false;
41     }
42   }
43
44   protected IJavaElement getJavaElement(ISelection selection) {
45     ICompilationUnit module = ActionUtil.findSelectedCompilationUnit(selection);
46     String JavaDoc label = "Module";
47     
48     if(module != null) {
49       if(isKnownConcrete(module.findPrimaryType())) {
50         label = "Module " + module.getElementName();
51       }
52       else {
53         module = null;
54       }
55     }
56     
57     m_delegateAction.setText(label);
58     
59     return module;
60   }
61   
62   protected void fillMenu(Menu menu) {
63     if(m_element != null) {
64       IType type = ((ICompilationUnit)m_element).findPrimaryType();
65       
66       if(type != null) {
67         m_adaptableAction.setJavaElement(type);
68         addMenuAction(menu, m_adaptableAction);
69       
70         m_excludedAction.setJavaElement(type);
71         addMenuAction(menu, m_excludedAction);
72       
73         m_bootJarAction.setType(type);
74         addMenuAction(menu, m_bootJarAction);
75       }
76     }
77   }
78 }
79
Popular Tags