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
|
/* *************************************************************************
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.tests.featurebrowser;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import com.itmill.toolkit.terminal.DownloadStream;
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.terminal.ParameterHandler;
import com.itmill.toolkit.terminal.URIHandler;
import com.itmill.toolkit.ui.Component;
import com.itmill.toolkit.ui.Form;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Link;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Panel;
import com.itmill.toolkit.ui.Select;
import com.itmill.toolkit.ui.Table;
public class FeatureParameters extends Feature implements URIHandler,
ParameterHandler {
private Label context = new Label();
private Label relative = new Label();
private Table params = new Table();
public FeatureParameters() {
super();
params.addContainerProperty("Values", String.class, "");
}
protected Component getDemoComponent() {
OrderedLayout l = new OrderedLayout();
Label info = new Label("To test this feature, try to "
+ "add some get parameters to URL. For example if you have "
+ "the feature browser installed in your local host, try url: ");
info.setCaption("Usage info");
l.addComponent(info);
try {
URL u1 = new URL(getApplication().getURL(),
"test/uri?test=1&test=2");
URL u2 = new URL(getApplication().getURL(),
"foo/bar?mary=john&count=3");
l.addComponent(new Link(u1.toString(), new ExternalResource(u1)));
l.addComponent(new Label("Or this: "));
l.addComponent(new Link(u2.toString(), new ExternalResource(u2)));
} catch (Exception e) {
System.out.println("Couldn't get hostname for this machine: "
+ e.toString());
e.printStackTrace();
}
// URI
Panel p1 = new Panel("URI Handler");
context.setCaption("Last URI handler context");
p1.addComponent(context);
relative.setCaption("Last relative URI");
p1.addComponent(relative);
l.addComponent(p1);
// Parameters
Panel p2 = new Panel("Parameter Handler");
params.setCaption("Last parameters");
params.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID);
params.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
p2.addComponent(params);
l.addComponent(p2);
// Properties
propertyPanel = new PropertyPanel(p1);
Form ap = propertyPanel.createBeanPropertySet(new String[] { "width",
"height" });
Select themes = (Select) propertyPanel.getField("style");
themes.addItem("light").getItemProperty(
themes.getItemCaptionPropertyId()).setValue("light");
themes.addItem("strong").getItemProperty(
themes.getItemCaptionPropertyId()).setValue("strong");
propertyPanel.addProperties("Panel Properties", ap);
setJavadocURL("ui/Panel.html");
return l;
}
protected String getDescriptionXHTML() {
return "This is a demonstration of how URL parameters can be recieved and handled."
+ "Parameters and URL:s can be received trough the windows by registering "
+ "URIHandler and ParameterHandler classes window.";
}
protected String getImage() {
return "parameters.jpg";
}
protected String getTitle() {
return "Parameters";
}
/**
* Add URI and parametes handlers to window.
*
* @see com.itmill.toolkit.ui.Component#attach()
*/
public void attach() {
super.attach();
getWindow().addURIHandler(this);
getWindow().addParameterHandler(this);
}
/**
* Remove all handlers from window
*
* @see com.itmill.toolkit.ui.Component#detach()
*/
public void detach() {
super.detach();
getWindow().removeURIHandler(this);
getWindow().removeParameterHandler(this);
}
/**
* Update URI
*
* @see com.itmill.toolkit.terminal.URIHandler#handleURI(URL, String)
*/
public DownloadStream handleURI(URL context, String relativeUri) {
this.context.setValue(context.toString());
relative.setValue(relativeUri);
return null;
}
/**
* Update parameters table
*
* @see com.itmill.toolkit.terminal.ParameterHandler#handleParameters(Map)
*/
public void handleParameters(Map parameters) {
params.removeAllItems();
for (Iterator i = parameters.keySet().iterator(); i.hasNext();) {
String name = (String) i.next();
String[] values = (String[]) parameters.get(name);
String v = "";
for (int j = 0; j < values.length; j++) {
if (v.length() > 0) {
v += ", ";
}
v += "'" + values[j] + "'";
}
params.addItem(new Object[] { v }, name);
}
}
}
|