1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.models;
17
18 import java.awt.Component;
19
20 import javax.swing.JTable;
21 import javax.swing.border.LineBorder;
22 import javax.swing.table.DefaultTableCellRenderer;
23
24 import org.xulux.api.core.PartRequest;
25 import org.xulux.api.gui.IWidget;
26 import org.xulux.api.rules.IRuleEngine;
27 import org.xulux.core.XuluxContext;
28 import org.xulux.gui.utils.ColorUtils;
29 import org.xulux.guilayer.swing.widgets.Table;
30
31
32
33
34
35
36
37
38 public class NyxTableCellRenderer extends DefaultTableCellRenderer {
39
40
41
42
43 protected IWidget widget;
44
45
46
47 protected Table parent;
48
49
50
51 protected PartRequest request;
52
53
54
55
56
57 public NyxTableCellRenderer(IWidget widget, Table parent) {
58 super();
59 this.widget = widget;
60 this.parent = parent;
61 request = new CellPartRequest(widget);
62 }
63
64
65
66
67
68 public Component getTableCellRendererComponent(
69 JTable table,
70 Object value,
71 boolean isSelected,
72 boolean hasFocus,
73 int row,
74 int column) {
75 request.setValue(value);
76 widget.setLazyProperty("cellvalue", value);
77 widget.setLazyProperty("rowValue", table.getModel().getValueAt(row, -1));
78 XuluxContext.getRuleEngine().fireFieldRequest(widget, request, IRuleEngine.PRE_REQUEST);
79
80 Object newValue = widget.getProperty("value");
81 if (newValue != null) {
82 value = newValue;
83
84 widget.setLazyProperty("value", null);
85 }
86 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
87 widget.setLazyProperty("cellvalue", null);
88 widget.setLazyProperty("rowvalue", null);
89
90
91 if (!isSelected) {
92 String bgColor = widget.getProperty("background-color-enabled");
93 if (bgColor != null) {
94
95 setOpaque(true);
96
97 setBackground(ColorUtils.getSwingColor(bgColor));
98 }
99 }
100 String border = widget.getProperty("border");
101 if (border != null) {
102 int thickness = 1;
103 try {
104 thickness = Integer.parseInt(widget.getProperty("border-thickness"));
105 } catch(NumberFormatException nfe) {
106 }
107 String borderColor = widget.getProperty("border-color");
108 setBorder(new LineBorder(ColorUtils.getSwingColor(borderColor),thickness));
109 }
110 String tooltipText = widget.getProperty("tooltip");
111 if (tooltipText != null) {
112 setToolTipText(tooltipText);
113 }
114 return this;
115 }
116
117
118
119
120
121 public void destroy() {
122 widget = null;
123 }
124
125 }