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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
/* *************************************************************************
IT Mill Toolkit
Development of Browser User Interfaces Made Easy
Copyright (C) 2000-2006 IT Mill Ltd
*************************************************************************
This product is distributed under commercial license that can be found
from the product package on license.pdf. Use of this product might
require purchasing a commercial license from IT Mill Ltd. For guidelines
on usage, see licensing-guidelines.html
*************************************************************************
For more information, contact:
IT Mill Ltd phone: +358 2 4802 7180
Ruukinkatu 2-4 fax: +358 2 4802 7181
20540, Turku email: info@itmill.com
Finland company www: www.itmill.com
Primary source for information and releases: www.itmill.com
********************************************************************** */
package com.itmill.toolkit.demo.features;
import java.util.Iterator;
import java.util.StringTokenizer;
import com.itmill.toolkit.data.*;
import com.itmill.toolkit.ui.*;
import com.itmill.toolkit.ui.Button.ClickEvent;
import com.itmill.toolkit.ui.Button.ClickListener;
public class FeatureBrowser extends CustomComponent implements
Property.ValueChangeListener, ClickListener {
private Tree features;
private Feature currentFeature = null;
private OrderedLayout layout;
private Button propertiesSelect;
private OrderedLayout right;
private PropertyPanel properties;
private boolean initialized = false;
private Select themeSelector = new Select();
public void attach() {
if (initialized)
return;
initialized = true;
// Configure tree
features = new Tree();
features.addContainerProperty("name", String.class, "");
features.addContainerProperty("feature", Feature.class, null);
features.setItemCaptionPropertyId("name");
features.addListener(this);
features.setImmediate(true);
features.setStyle("menu");
// Configure component layout
layout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
layout.setStyle("featurebrowser-mainlayout");
setCompositionRoot(layout);
OrderedLayout left = new OrderedLayout(
OrderedLayout.ORIENTATION_VERTICAL);
left.addComponent(features);
layout.addComponent(left);
// Theme selector
left.addComponent(themeSelector);
themeSelector.addItem("demo");
themeSelector.addItem("corporate");
themeSelector.addItem("base");
themeSelector.addListener(this);
themeSelector.select("demo");
themeSelector.setImmediate(true);
// Restart button
Button close = new Button("restart", getApplication(), "close");
close.setStyle("link");
left.addComponent(close);
// Test component
registerFeature("/Welcome", new IntroWelcome());
registerFeature("/UI Components", new IntroComponents());
registerFeature("/UI Components/Basic", new IntroBasic());
registerFeature("/UI Components/Basic/Text Field",
new FeatureTextField());
registerFeature("/UI Components/Basic/Date Field",
new FeatureDateField());
registerFeature("/UI Components/Basic/Button", new FeatureButton());
registerFeature("/UI Components/Basic/Form", new FeatureForm());
registerFeature("/UI Components/Basic/Label", new FeatureLabel());
registerFeature("/UI Components/Basic/Link", new FeatureLink());
registerFeature("/UI Components/Item Containers",
new IntroItemContainers());
registerFeature("/UI Components/Item Containers/Select",
new FeatureSelect());
registerFeature("/UI Components/Item Containers/Table",
new FeatureTable());
registerFeature("/UI Components/Item Containers/Tree",
new FeatureTree());
registerFeature("/UI Components/Layouts", new IntroLayouts());
registerFeature("/UI Components/Layouts/Ordered Layout",
new FeatureOrderedLayout());
registerFeature("/UI Components/Layouts/Grid Layout",
new FeatureGridLayout());
registerFeature("/UI Components/Layouts/Custom Layout",
new FeatureCustomLayout());
registerFeature("/UI Components/Layouts/Panel", new FeaturePanel());
registerFeature("/UI Components/Layouts/Tab Sheet",
new FeatureTabSheet());
registerFeature("/UI Components/Layouts/Window", new FeatureWindow());
// Disabled for now
// registerFeature("/UI Components/Layouts/Frame Window",
// new FeatureFrameWindow());
registerFeature("/UI Components/Data handling", new IntroDataHandling());
registerFeature("/UI Components/Data handling/Embedded Objects",
new FeatureEmbedded());
registerFeature("/UI Components/Data handling/Upload",
new FeatureUpload());
registerFeature("/Data Model", new IntroDataModel());
registerFeature("/Data Model/Properties", new FeatureProperties());
registerFeature("/Data Model/Items", new FeatureItems());
registerFeature("/Data Model/Containers", new FeatureContainers());
registerFeature("/Data Model/Validators", new FeatureValidators());
registerFeature("/Data Model/Buffering", new FeatureBuffering());
// registerFeature("/Terminal", new IntroTerminal());
registerFeature("/Terminal/Parameters and URI Handling",
new FeatureParameters());
// Pre-open all menus
for (Iterator i = features.getItemIds().iterator(); i.hasNext();)
features.expandItem(i.next());
// Add demo component and tabs
currentFeature = new IntroWelcome();
layout.addComponent(currentFeature);
// Add properties
right = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
layout.addComponent(right);
propertiesSelect = new Button("Show properties", this);
propertiesSelect.setSwitchMode(true);
right.addComponent(propertiesSelect);
properties = currentFeature.getPropertyPanel();
properties.setVisible(false);
right.addComponent(properties);
}
public void registerFeature(String path, Feature feature) {
StringTokenizer st = new StringTokenizer(path, "/");
String id = "";
String parentId = null;
while (st.hasMoreTokens()) {
String token = st.nextToken();
id += "/" + token;
if (!features.containsId(id)) {
features.addItem(id);
features.setChildrenAllowed(id, false);
}
features.getContainerProperty(id, "name").setValue(token);
if (parentId != null) {
features.setChildrenAllowed(parentId, true);
features.setParent(id, parentId);
}
if (!st.hasMoreTokens())
features.getContainerProperty(id, "feature").setValue(feature);
parentId = id;
}
}
public void valueChange(Property.ValueChangeEvent event) {
// FIXME: navigation statistics
try {
if ((event.getProperty().toString() == null)
&& ((AbstractComponent) event.getProperty()).getTag()
.equals("tree")) {
// ignore tree initialization
} else {
FeatureUtil.debug(getApplication().getUser().toString(),
"valueChange "
+ ((AbstractComponent) event.getProperty())
.getTag() + ", " + event.getProperty());
}
} catch (Exception e) {
// ignored, should never happen
}
// Change feature
if (event.getProperty() == features) {
Object id = features.getValue();
if (id != null) {
if (features.areChildrenAllowed(id))
features.expandItem(id);
Property p = features.getContainerProperty(id, "feature");
Feature feature = p != null ? ((Feature) p.getValue()) : null;
if (feature != null) {
layout.replaceComponent(currentFeature, feature);
currentFeature = feature;
properties = feature.getPropertyPanel();
if (properties != null) {
Iterator i = right.getComponentIterator();
i.next();
PropertyPanel oldProps = (PropertyPanel) i.next();
if (oldProps != null)
right.replaceComponent(oldProps, properties);
else
right.addComponent(properties);
properties.setVisible(((Boolean) propertiesSelect
.getValue()).booleanValue());
}
getWindow()
.setCaption(
"IT Mill Toolkit Features / "
+ features.getContainerProperty(id,
"name"));
}
}
} else if (event.getProperty() == themeSelector) {
getApplication().setTheme(themeSelector.toString());
}
}
public void buttonClick(ClickEvent event) {
// FIXME: navigation statistics
try {
FeatureUtil.debug(getApplication().getUser().toString(),
"buttonClick " + event.getButton().getTag() + ", "
+ event.getButton().getCaption() + ", "
+ event.getButton().getValue());
} catch (Exception e) {
// ignored, should never happen
}
if (properties != null)
properties.setVisible(((Boolean) propertiesSelect.getValue())
.booleanValue());
}
}
|