1 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 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 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 |