/
WiseTreeItem.java
188 lines (149 loc) · 5.16 KB
/
WiseTreeItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package org.jboss.wise.gwt.client.ui;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.DoubleBox;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.LabelBase;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.SimpleCheckBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.ValueBoxBase;
import com.google.gwt.user.client.ui.Widget;
import java.util.Iterator;
import org.jboss.wise.gwt.shared.tree.element.EnumerationTreeElement;
import org.jboss.wise.gwt.shared.tree.element.SimpleTreeElement;
import org.jboss.wise.gwt.shared.tree.element.TreeElement;
/**
* User: rsearls
* Date: 5/23/15
*/
public class WiseTreeItem extends TreeItem {
public static final String CSS_ENABLEBLK = "enableBlk";
public static final String CSS_DISABLEBLK = "disableBlk";
private TreeElement wTreeElement = null;
private SimpleCheckBox checkBox = null;
private FocusWidget inputBox = null;
private boolean validationError = false;
public WiseTreeItem () {
}
public WiseTreeItem (Widget widget) {
super(widget);
}
public TreeElement getWTreeElement() {
return wTreeElement;
}
public void setWTreeElement(TreeElement wTreeElement) {
this.wTreeElement = wTreeElement;
}
public void setValidationError(boolean flag) {
validationError = flag;
}
public boolean isValidationError() {
return validationError;
}
public SimpleCheckBox getCheckBox() {
return checkBox;
}
public TextBox getTextBox() {
if(inputBox instanceof TextBox){
return (TextBox)inputBox;
}
return null;
}
/**
*
* @param enable
*/
public void setEnableTreeItem(boolean enable) {
String styleName = (enable) ? CSS_ENABLEBLK : CSS_DISABLEBLK;
Widget widget = getWidget();
if (widget instanceof ComplexPanel) {
Iterator<Widget> itWidget = ((ComplexPanel) widget).iterator();
while (itWidget.hasNext()) {
Widget w = itWidget.next();
if (w instanceof FocusWidget){
((FocusWidget) w).setEnabled(enable);
((FocusWidget) w).setStyleName(styleName);
if (w instanceof SimpleCheckBox) {
wTreeElement.setNil(!enable);
}
} else if (w instanceof LabelBase) {
w.setStyleName(styleName);
}
}
}
}
/**
* Extract components for future ref
*/
public void postCreateProcess() {
Widget widget = getWidget();
if (widget instanceof ComplexPanel) {
Iterator<Widget> itWidget = ((ComplexPanel) widget).iterator();
while (itWidget.hasNext()) {
Widget w = itWidget.next();
if (w instanceof SimpleCheckBox) {
checkBox = (SimpleCheckBox)w;
} else if (w instanceof ValueBoxBase) {
inputBox = (FocusWidget)w;
} else if (w instanceof ListBox) {
inputBox = (FocusWidget)w;
}
}
}
}
public void postProcess() {
// special eval of items using LeafKeyUpHandler required
if (inputBox == null) {
int cnt = getChildCount();
for (int i = 0; i < cnt; i++) {
((WiseTreeItem) getChild(i)).postProcess();
}
} else {
if (inputBox instanceof TextBox) {
if (checkBox != null) {
wTreeElement.setNil(!checkBox.getValue());
}
if (!wTreeElement.isNil()) {
setWidgetValue(inputBox, wTreeElement);
int cnt = getChildCount();
for (int i = 0; i < cnt; i++) {
((WiseTreeItem) getChild(i)).postProcess();
}
}
// work around: setWidgetValue seems to override the initial setting, reset value
if (checkBox != null) {
wTreeElement.setNil(!checkBox.getValue());
}
} else {
setWidgetValue(inputBox, wTreeElement);
}
}
}
private void setWidgetValue(Widget widget, TreeElement pNode) {
if (pNode instanceof EnumerationTreeElement) {
ListBox lBox = (ListBox) widget;
EnumerationTreeElement eNode = (EnumerationTreeElement) pNode;
int index = lBox.getSelectedIndex();
eNode.setValue(lBox.getItemText(index));
} else {
if (widget instanceof TextBox) {
String s = ((TextBox) widget).getValue();
if (s != null) {
((SimpleTreeElement)pNode).setValue(s);
}
} else if (widget instanceof IntegerBox) {
Integer i = ((IntegerBox) widget).getValue();
if (i != null) {
((SimpleTreeElement)pNode).setValue(i.toString());
}
} else if (widget instanceof DoubleBox) {
Double d = ((DoubleBox) widget).getValue();
if (d != null) {
((SimpleTreeElement)pNode).setValue(d.toString());
}
}
}
}
}