KickJava   Java API By Example, From Geeks To Geeks.

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


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

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