KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > EngineTreeRenderer


1 package org.enhydra.shark.swingclient.workflowadmin;
2
3 import java.awt.*;
4
5 import javax.swing.*;
6 import javax.swing.tree.*;
7
8
9 import org.enhydra.shark.api.client.wfmodel.*;
10
11 import org.enhydra.shark.swingclient.*;
12
13 /**
14 * Used to customize the display of package, process definition and instantiated
15 * processes nodes.
16 */

17 public class EngineTreeRenderer extends DefaultTreeCellRenderer {
18
19    public Component getTreeCellRendererComponent(
20       JTree tree,
21       Object JavaDoc value,
22       boolean sel,
23       boolean expanded,
24       boolean leaf,
25       int row,
26       boolean hasFocus) {
27
28       super.getTreeCellRendererComponent(
29          tree, value, sel,
30          expanded, leaf, row,
31          hasFocus);
32
33       int type=getUserObjectType(value);
34
35       switch (type) {
36          case 0:
37             try {
38                javax.swing.Icon JavaDoc image = new ImageIcon(
39                   ResourceManager.getResource("openedpackagesTreeImage"));
40                setIcon(image);
41             } catch (Throwable JavaDoc t) {
42                setIcon(null);
43             }
44             break;
45          case 1:
46             try {
47                javax.swing.Icon JavaDoc image = new ImageIcon(
48                   ResourceManager.getResource("packageTreeImage"));
49                setIcon(image);
50             } catch (Throwable JavaDoc t) {
51                setIcon(null);
52             } finally {
53                org.enhydra.jawe.xml.elements.Package pkg=
54                   (org.enhydra.jawe.xml.elements.Package)
55                   ((DefaultMutableTreeNode)value).getUserObject();
56                String JavaDoc disp=ResourceManager.
57                   getLanguageDependentString("PackageKey")+"-"+pkg.toString();
58                setText(disp);
59                setToolTipText(disp);
60             }
61             break;
62          case 2:
63             try {
64                javax.swing.Icon JavaDoc image = new ImageIcon(
65                   ResourceManager.getResource("managerTreeImage"));
66                setIcon(image);
67             } catch (Throwable JavaDoc t) {
68                setIcon(null);
69             } finally {
70                WfProcessMgr mgr=(WfProcessMgr)((DefaultMutableTreeNode)value).getUserObject();
71                String JavaDoc name;
72                try {
73                   name=SharkAdmin.getAdminMiscUtilities().getProcessMgrProcDefName(mgr.name());
74                } catch (Exception JavaDoc ex) {
75                   name=ResourceManager.getLanguageDependentString("UnknownKey");
76                }
77                String JavaDoc disp=ResourceManager.
78                   getLanguageDependentString("ProcessDefinitionKey")+"-"+name;
79                setText(disp);
80                setToolTipText(disp);
81             }
82             break;
83          case 3:
84             try {
85                javax.swing.Icon JavaDoc image = new ImageIcon(
86                   ResourceManager.getResource("processTreeImage"));
87                setIcon(image);
88             } catch (Throwable JavaDoc t) {
89                setIcon(null);
90             } finally {
91                WfProcess pr=(WfProcess)((DefaultMutableTreeNode)value).getUserObject();
92                String JavaDoc name;
93                try {
94                   name=pr.key();
95                } catch (Exception JavaDoc ex) {
96                   name=ResourceManager.getLanguageDependentString("UnknownKey");
97                }
98                String JavaDoc disp=ResourceManager.
99                   getLanguageDependentString("InstantiatedProcessKey")+"-"+name;
100                setText(disp);
101                setToolTipText(disp);
102             }
103             break;
104       }
105       return this;
106    }
107
108    protected int getUserObjectType (Object JavaDoc value) {
109       DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
110       Object JavaDoc userObj = node.getUserObject();
111       if (userObj instanceof org.enhydra.jawe.xml.elements.Package) {
112          return 1;
113       } else if (userObj instanceof WfProcessMgr) {
114          return 2;
115       } else if (userObj instanceof WfProcess) {
116          return 3;
117       } else {
118          return 0;
119       }
120    }
121
122 }
123
Popular Tags