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.jdt.core.IJavaElement;
07: import org.eclipse.jdt.core.IJavaProject;
08: import org.eclipse.jdt.core.IPackageFragment;
09: import org.eclipse.jdt.core.IType;
10: import org.terracotta.dso.ConfigurationHelper;
11: import org.terracotta.dso.TcPlugin;
12:
13: /**
14: * Mark the currently selected IType as instrumented.
15: */
16:
17: public class AdaptableAction extends BaseAction {
18: public AdaptableAction() {
19: super ("Instrumented", AS_CHECK_BOX);
20: }
21:
22: /**
23: * The IJavaElement must be one of IType, IPackageFragment, or IJavaProject.
24: */
25: public void setJavaElement(IJavaElement element) {
26: if (!(element instanceof IType
27: || element instanceof IPackageFragment || element instanceof IJavaProject)) {
28: throw new IllegalArgumentException(
29: "Java element must be IType, IPackageFragment, or IJavaProject");
30: }
31:
32: super .setJavaElement(element);
33:
34: if (element instanceof IType) {
35: IType type = (IType) element;
36: boolean isBootClass = TcPlugin.getDefault().isBootClass(
37: type);
38:
39: setEnabled(!isBootClass);
40: setChecked(isBootClass
41: || getConfigHelper().isAdaptable(type));
42: } else {
43: setChecked(getConfigHelper().isAdaptable(element));
44: }
45: }
46:
47: public void performAction() {
48: ConfigurationHelper helper = getConfigHelper();
49:
50: if (isChecked()) {
51: helper.ensureAdaptable(m_element);
52: } else {
53: helper.ensureNotAdaptable(m_element);
54: }
55:
56: inspectCompilationUnit();
57: }
58: }
|