01: package org.enhydra.shark.swingclient.workflowadmin;
02:
03: import java.awt.Component;
04:
05: import javax.swing.ImageIcon;
06: import javax.swing.JTree;
07: import javax.swing.tree.DefaultTreeCellRenderer;
08:
09: import org.enhydra.shark.swingclient.ResourceManager;
10:
11: /**
12: * Used to customize the display of package, process definition and instantiated
13: * processes nodes.
14: */
15: public class EngineTreeRenderer extends DefaultTreeCellRenderer {
16:
17: protected boolean hideProcesses;
18:
19: public EngineTreeRenderer(boolean hideProcesses) {
20: this .hideProcesses = hideProcesses;
21: }
22:
23: public Component getTreeCellRendererComponent(JTree tree,
24: Object value, boolean sel, boolean expanded, boolean leaf,
25: int row, boolean _hasFocus) {
26:
27: super .getTreeCellRendererComponent(tree, value, sel, expanded,
28: leaf, row, _hasFocus);
29:
30: int type = getUserObjectType(value);
31:
32: switch (type) {
33: case 0:
34: try {
35: javax.swing.Icon image = new ImageIcon(ResourceManager
36: .getResource("openedpackagesTreeImage"));
37: setIcon(image);
38: } catch (Throwable t) {
39: setIcon(null);
40: }
41: break;
42: case 1:
43: try {
44: javax.swing.Icon image = new ImageIcon(ResourceManager
45: .getResource("packageTreeImage"));
46: setIcon(image);
47: } catch (Throwable t) {
48: setIcon(null);
49: } finally {
50: setToolTipText(((EngineTreeNode) value).getName());
51: }
52: break;
53: case 2:
54: try {
55: javax.swing.Icon image = new ImageIcon(ResourceManager
56: .getResource("managerTreeImage"));
57: setIcon(image);
58: } catch (Throwable t) {
59: setIcon(null);
60: } finally {
61: setToolTipText(((EngineTreeNode) value).getName());
62: }
63: break;
64: case 3:
65: if (hideProcesses) {
66: return null;
67: }
68: try {
69: javax.swing.Icon image = new ImageIcon(ResourceManager
70: .getResource("processTreeImage"));
71: setIcon(image);
72: } catch (Throwable t) {
73: setIcon(null);
74: } finally {
75: setToolTipText(((EngineTreeNode) value).getName());
76: }
77: break;
78: }
79: return this ;
80: }
81:
82: protected int getUserObjectType(Object value) {
83: EngineTreeNode node = (EngineTreeNode) value;
84: if (node.getType() == EngineTreeNode.TYPE_PACKAGE) {
85: return 1;
86: } else if (node.getType() == EngineTreeNode.TYPE_PROCESSDEFINITION) {
87: return 2;
88: } else if (node.getType() == EngineTreeNode.TYPE_PROCESSINSTANCE) {
89: return 3;
90: } else {
91: return 0;
92: }
93: }
94:
95: }
|