1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.mindcrimeilab.xsanalyzer.ui.renderer;
19
20 import java.awt.Component;
21
22 import javax.swing.Icon;
23 import javax.swing.JLabel;
24 import javax.swing.JTree;
25 import javax.swing.tree.DefaultTreeCellRenderer;
26 import javax.swing.tree.TreeCellRenderer;
27
28 import org.apache.xerces.xs.XSModelGroupDefinition;
29 import org.springframework.richclient.application.Application;
30 import org.springframework.richclient.image.IconSource;
31
32
33
34
35
36
37
38 public class GroupCellRenderer implements TreeCellRenderer {
39
40 private final static Icon icon = ((IconSource) Application.services().getService(IconSource.class)).getIcon("modelGroup.icon");
41
42 private final TreeCellRenderer delegateTreeCellRenderer = new DefaultTreeCellRenderer();
43
44
45
46
47
48
49
50 @Override
51 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
52
53 JLabel cell = (JLabel) delegateTreeCellRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
54
55 if (value instanceof XSModelGroupDefinition) {
56 XSModelGroupDefinition xsgroup = (XSModelGroupDefinition) value;
57 StringBuilder sb = new StringBuilder();
58 sb.append(xsgroup.getName());
59 sb.append(", <");
60 sb.append(xsgroup.getNamespace());
61 sb.append(">");
62 cell.setText(sb.toString());
63 cell.setIcon(GroupCellRenderer.icon);
64 }
65
66 return cell;
67 }
68 }