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.core.resources.IProject;
07: import org.eclipse.jdt.core.IJavaElement;
08: import org.eclipse.jdt.core.IPackageFragment;
09: import org.eclipse.jface.viewers.ISelection;
10: import org.eclipse.swt.widgets.Menu;
11:
12: import org.terracotta.dso.ProjectNature;
13:
14: /**
15: * Popup action submenu that holds actions that are package fragment-related.
16: *
17: * @see org.eclipse.jdt.core.IType
18: * @see BaseMenuCreator
19: * @see AdaptableAction
20: * @see ExcludedTypeAction
21: * @see BootJarTypeAction
22: */
23:
24: public class PackageFragmentHandler extends BaseMenuCreator {
25: private IPackageFragment m_fragment;
26: private AdaptableAction m_adaptableAction;
27: private ExcludedTypeAction m_excludedAction;
28: private LockHandler m_lockHandler;
29:
30: public PackageFragmentHandler() {
31: super ();
32:
33: m_adaptableAction = new AdaptableAction();
34: m_excludedAction = new ExcludedTypeAction();
35: m_lockHandler = new LockHandler();
36: }
37:
38: protected IJavaElement getJavaElement(ISelection selection) {
39: IPackageFragment fragment = ActionUtil
40: .findSelectedPackageFragment(selection);
41:
42: m_fragment = null;
43:
44: if (fragment != null) {
45: IProject project = fragment.getJavaProject().getProject();
46:
47: try {
48: if (project.hasNature(ProjectNature.NATURE_ID)) {
49: m_fragment = fragment;
50: }
51: } catch (Exception e) {/**/
52: }
53: }
54:
55: return m_fragment;
56: }
57:
58: protected void fillMenu(Menu menu) {
59: if (m_fragment != null) {
60: m_adaptableAction.setJavaElement(m_fragment);
61: addMenuAction(menu, m_adaptableAction);
62:
63: m_excludedAction.setJavaElement(m_fragment);
64: addMenuAction(menu, m_excludedAction);
65:
66: m_lockHandler.setJavaElement(m_fragment);
67: m_lockHandler.fillMenu(menu);
68: }
69: }
70: }
|