Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/LinkSelection.java @ 282:e92f7ef455d6
Show rivers as links instead of a combobox.
flys-client/trunk@1911 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 12 May 2011 14:59:18 +0000 |
parents | |
children | be842e36ce1c |
comparison
equal
deleted
inserted
replaced
281:c271012a97a3 | 282:e92f7ef455d6 |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 | |
5 import com.smartgwt.client.types.VerticalAlignment; | |
6 import com.smartgwt.client.widgets.Canvas; | |
7 import com.smartgwt.client.widgets.Label; | |
8 import com.smartgwt.client.widgets.form.DynamicForm; | |
9 import com.smartgwt.client.widgets.form.fields.LinkItem; | |
10 import com.smartgwt.client.widgets.layout.HLayout; | |
11 import com.smartgwt.client.widgets.layout.VLayout; | |
12 import com.smartgwt.client.widgets.form.fields.events.ClickHandler; | |
13 import com.smartgwt.client.widgets.form.fields.events.ClickEvent; | |
14 | |
15 import de.intevation.flys.client.shared.model.Data; | |
16 import de.intevation.flys.client.shared.model.DataItem; | |
17 import de.intevation.flys.client.shared.model.DataList; | |
18 import de.intevation.flys.client.shared.model.DefaultData; | |
19 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
20 import de.intevation.flys.client.client.event.StepForwardEvent; | |
21 | |
22 import de.intevation.flys.client.client.FLYSConstants; | |
23 | |
24 | |
25 /** | |
26 * This UIProvider displays the DataItems of the Data object in a list of links. | |
27 * | |
28 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
29 */ | |
30 public class LinkSelection | |
31 extends MapSelection | |
32 { | |
33 /** The message class that provides i18n strings.*/ | |
34 protected FLYSConstants messages = GWT.create(FLYSConstants.class); | |
35 | |
36 /** The combobox.*/ | |
37 protected DynamicForm form; | |
38 | |
39 /** The selected river*/ | |
40 protected Data river; | |
41 | |
42 /** | |
43 * This method currently returns a | |
44 * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all | |
45 * data items in a list of links stored in <i>data</i>. | |
46 * | |
47 * @param data The {@link Data} object. | |
48 * | |
49 * @return a combobox. | |
50 */ | |
51 public Canvas create(DataList data) { | |
52 VLayout v = new VLayout(); | |
53 v.setMembersMargin(10); | |
54 v.setAlign(VerticalAlignment.TOP); | |
55 GWT.log("-------datastate: "+ data.getState()); | |
56 if (data.getState() == null) { | |
57 Canvas module = super.createWidget(data); | |
58 v.addMember(module); | |
59 } | |
60 Canvas content = createWidget(data); | |
61 v.addMember(content); | |
62 | |
63 return v; | |
64 } | |
65 | |
66 | |
67 public Canvas createOld(DataList dataList) { | |
68 HLayout layout = new HLayout(); | |
69 VLayout vLayout = new VLayout(); | |
70 layout.setWidth("400px"); | |
71 | |
72 Label label = new Label(dataList.getLabel()); | |
73 label.setWidth("200px"); | |
74 | |
75 int size = dataList.size(); | |
76 for (int i = 0; i < size; i++) { | |
77 Data data = dataList.get(i); | |
78 DataItem[] items = data.getItems(); | |
79 | |
80 for (DataItem item: items) { | |
81 HLayout hLayout = new HLayout(); | |
82 | |
83 hLayout.addMember(label); | |
84 hLayout.addMember(new Label(item.getLabel())); | |
85 | |
86 vLayout.addMember(hLayout); | |
87 vLayout.setWidth("130px"); | |
88 } | |
89 } | |
90 | |
91 Canvas back = getBackButton(dataList.getState()); | |
92 | |
93 layout.addMember(label); | |
94 layout.addMember(vLayout); | |
95 layout.addMember(back); | |
96 | |
97 return layout; | |
98 } | |
99 | |
100 | |
101 /** | |
102 * This method creates the content of the widget. | |
103 * | |
104 * @param data The {@link Data} object. | |
105 * | |
106 * @return a list of links | |
107 */ | |
108 protected Canvas createWidget(DataList data) { | |
109 GWT.log("LinkSelection - create()"); | |
110 | |
111 VLayout layout = new VLayout(); | |
112 layout.setAlign(VerticalAlignment.TOP); | |
113 layout.setHeight(25); | |
114 | |
115 | |
116 form = new DynamicForm(); | |
117 VLayout formLayout = new VLayout(); | |
118 | |
119 formLayout.setLayoutLeftMargin(60); | |
120 int size = data.size(); | |
121 | |
122 for (int i = 0; i < size; i++) { | |
123 Data d = data.get(i); | |
124 | |
125 Label label = new Label(d.getDescription()); | |
126 label.setValign(VerticalAlignment.TOP); | |
127 label.setHeight(20); | |
128 | |
129 for (DataItem item: d.getItems()) { | |
130 LinkItem link = new LinkItem("river"); | |
131 link.setLinkTitle(item.getLabel()); | |
132 link.setTarget(item.getStringValue()); | |
133 link.setShowTitle(false); | |
134 DynamicForm f = new DynamicForm(); | |
135 f.setItems(link); | |
136 formLayout.addMember(f); | |
137 link.addClickHandler(new ClickHandler() { | |
138 public void onClick(ClickEvent event) { | |
139 DataItem item = new DefaultDataItem( | |
140 ((LinkItem)event.getItem()).getLinkTitle(), | |
141 null, | |
142 ((LinkItem)event.getItem()).getLinkTitle()); | |
143 | |
144 river = new DefaultData( | |
145 "river", | |
146 null, | |
147 null, | |
148 new DataItem [] {item}); | |
149 fireStepForwardEvent (new StepForwardEvent (getData())); | |
150 } | |
151 }); | |
152 | |
153 } | |
154 label.setWidth(50); | |
155 | |
156 layout.addMember(label); | |
157 layout.addMember(formLayout); | |
158 } | |
159 layout.setAlign(VerticalAlignment.TOP); | |
160 | |
161 return layout; | |
162 } | |
163 | |
164 | |
165 protected Data[] getData() { | |
166 Data[] module = super.getData(); | |
167 if (module != null) { | |
168 return new Data[] {module[0], river}; | |
169 } | |
170 else { | |
171 return new Data[] {river}; | |
172 } | |
173 } | |
174 } | |
175 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |