001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.admin.common;
006:
007: import org.dijon.PopupMenu;
008:
009: import com.tc.object.appevent.NonPortableObjectState;
010:
011: import java.awt.event.ActionEvent;
012:
013: import javax.swing.ImageIcon;
014: import javax.swing.JPopupMenu;
015:
016: public class NonPortableWalkNode extends XTreeNode {
017: private NonPortableObjectState objectState;
018:
019: private static final ImageIcon NOT_PORTABLE_ICON = new ImageIcon(
020: NonPortableWalkNode.class
021: .getResource("/com/tc/admin/icons/field_protected_obj.gif"));
022: private static final ImageIcon NEVER_PORTABLE_ICON = new ImageIcon(
023: NonPortableWalkNode.class
024: .getResource("/com/tc/admin/icons/field_private_obj.gif"));
025: private static final ImageIcon TRANSIENT_ICON = new ImageIcon(
026: NonPortableWalkNode.class
027: .getResource("/com/tc/admin/icons/field_public_obj.gif"));
028: private static final ImageIcon PORTABLE_ICON = new ImageIcon(
029: NonPortableWalkNode.class
030: .getResource("/com/tc/admin/icons/field_default_obj.gif"));
031: private static final ImageIcon PRE_INSTRUMENTED_ICON = new ImageIcon(
032: NonPortableWalkNode.class
033: .getResource("/com/tc/admin/icons/owned_ovr.gif"));
034:
035: public NonPortableWalkNode(Object userObject) {
036: super ();
037: setUserObject(userObject);
038: if (userObject instanceof NonPortableObjectState) {
039: setObjectState((NonPortableObjectState) userObject);
040: }
041: }
042:
043: void setObjectState(NonPortableObjectState objectState) {
044: if ((this .objectState = objectState) != null) {
045: ImageIcon icon = PORTABLE_ICON;
046:
047: if (isPreInstrumented()) {
048: icon = PRE_INSTRUMENTED_ICON;
049: } else if (isNeverPortable()) {
050: icon = NEVER_PORTABLE_ICON;
051: } else if (!isPortable()) {
052: icon = NOT_PORTABLE_ICON;
053: } else if (isTransient()) {
054: icon = TRANSIENT_ICON;
055: }
056:
057: setIcon(icon);
058: }
059: }
060:
061: public NonPortableObjectState getObjectState() {
062: return this .objectState;
063: }
064:
065: public String getLabel() {
066: return this .objectState != null ? this .objectState.getLabel()
067: : null;
068: }
069:
070: public String getFieldName() {
071: return this .objectState != null ? this .objectState
072: .getFieldName() : null;
073: }
074:
075: public String getTypeName() {
076: return this .objectState != null ? this .objectState
077: .getTypeName() : null;
078: }
079:
080: public boolean isPortable() {
081: return this .objectState != null ? this .objectState.isPortable()
082: : false;
083: }
084:
085: public boolean isTransient() {
086: return this .objectState != null ? this .objectState
087: .isTransient() : false;
088: }
089:
090: public boolean isNeverPortable() {
091: return this .objectState != null ? this .objectState
092: .isNeverPortable() : false;
093: }
094:
095: public boolean isPreInstrumented() {
096: return this .objectState != null ? this .objectState
097: .isPreInstrumented() : false;
098: }
099:
100: class MakeTransientAction extends XAbstractAction {
101: public MakeTransientAction() {
102: super ("Make transient");
103: }
104:
105: public void actionPerformed(ActionEvent e) {
106: // TODO
107: }
108: }
109:
110: class IncludeForInstrumentationAction extends XAbstractAction {
111: public IncludeForInstrumentationAction() {
112: super ("Include from instrumentation");
113: }
114:
115: public void actionPerformed(ActionEvent e) {
116: // TODO
117: }
118: }
119:
120: class ExcludeForInstrumentationAction extends XAbstractAction {
121: public ExcludeForInstrumentationAction() {
122: super ("Exclude from instrumentation");
123: }
124:
125: public void actionPerformed(ActionEvent e) {
126: // TODO
127: }
128: }
129:
130: class MakeBootClassAction extends XAbstractAction {
131: public MakeBootClassAction() {
132: super ("Add to BootJar");
133: }
134:
135: public void actionPerformed(ActionEvent e) {
136: // TODO
137: }
138: }
139:
140: public JPopupMenu getPopupMenu() {
141: JPopupMenu popupMenu = super .getPopupMenu();
142: if (popupMenu == null) {
143: popupMenu = new PopupMenu();
144: if (isNeverPortable()) {
145: popupMenu.add(new MakeTransientAction());
146: } else if (!isPortable()) {
147: popupMenu.add(new IncludeForInstrumentationAction());
148: popupMenu.add(new MakeBootClassAction());
149: if (getFieldName() != null) {
150: popupMenu.add(new MakeTransientAction());
151: }
152: } else {
153: popupMenu.add(new ExcludeForInstrumentationAction());
154: }
155: }
156: return popupMenu;
157: }
158: }
|