10 |
ddelon |
1 |
/*
|
|
|
2 |
* Copyright 2006 Google Inc.
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
5 |
* use this file except in compliance with the License. You may obtain a copy of
|
|
|
6 |
* the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
12 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
13 |
* License for the specific language governing permissions and limitations under
|
|
|
14 |
* the License.
|
|
|
15 |
*/
|
|
|
16 |
package org.tela_botanica.client;
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
import com.google.gwt.json.client.JSONArray;
|
|
|
20 |
import com.google.gwt.json.client.JSONParser;
|
|
|
21 |
import com.google.gwt.json.client.JSONString;
|
|
|
22 |
import com.google.gwt.json.client.JSONValue;
|
|
|
23 |
import com.google.gwt.user.client.HTTPRequest;
|
|
|
24 |
import com.google.gwt.user.client.ResponseTextHandler;
|
|
|
25 |
import com.google.gwt.user.client.ui.Composite;
|
|
|
26 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
27 |
import com.google.gwt.user.client.ui.Grid;
|
|
|
28 |
import com.google.gwt.user.client.ui.SourcesTableEvents;
|
|
|
29 |
import com.google.gwt.user.client.ui.TableListener;
|
|
|
30 |
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* A tree displaying a set of email folders.
|
|
|
34 |
*/
|
|
|
35 |
public class LocationList extends Composite {
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
private static final int VISIBLE_LOCATION_COUNT = 15;
|
|
|
39 |
private static final String VALUE_UNKNOWN = "Inconnues";
|
|
|
40 |
|
|
|
41 |
private Grid header = new Grid(1, 1);
|
|
|
42 |
|
|
|
43 |
private Grid selector = new Grid(1, 1);
|
|
|
44 |
|
|
|
45 |
private FlexTable table = new FlexTable();
|
|
|
46 |
|
|
|
47 |
private VerticalPanel outer = new VerticalPanel();
|
|
|
48 |
private VerticalPanel inner = new VerticalPanel();
|
|
|
49 |
|
|
|
50 |
private int startIndex = 0;
|
|
|
51 |
|
|
|
52 |
private String user;
|
|
|
53 |
|
|
|
54 |
private String serviceBaseUrl = null;
|
|
|
55 |
|
|
|
56 |
private String location = "all";
|
|
|
57 |
|
|
|
58 |
// Tous selectionné
|
|
|
59 |
private int selectedRow = -1;
|
|
|
60 |
|
|
|
61 |
private Mediator mediator = null;
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
public LocationList(Mediator med) {
|
|
|
65 |
|
|
|
66 |
mediator=med;
|
|
|
67 |
|
|
|
68 |
mediator.registerLocationList(this);
|
|
|
69 |
|
|
|
70 |
user=mediator.getUser();
|
|
|
71 |
serviceBaseUrl = mediator.getServiceBaseUrl();
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
// Mise en forme du header
|
|
|
75 |
|
|
|
76 |
header.setCellSpacing(0);
|
|
|
77 |
header.setCellPadding(2);
|
|
|
78 |
header.setWidth("100%");
|
|
|
79 |
|
|
|
80 |
header.setStyleName("location-ListHeader");
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
header.setHTML(0, 0, "Localités "); // yeah !
|
|
|
84 |
|
|
|
85 |
header.getCellFormatter().setWidth(0, 0, "100%");
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
// Mise en forme du selecteur
|
|
|
89 |
|
|
|
90 |
selector.setCellSpacing(0);
|
|
|
91 |
selector.setCellPadding(0);
|
|
|
92 |
selector.setWidth("100%");
|
|
|
93 |
|
|
|
94 |
selector.setHTML(0, 0, "Toutes");
|
|
|
95 |
|
|
|
96 |
selector.getCellFormatter().setWidth(0, 0, "100%");
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
// Hook up events.
|
|
|
100 |
selector.addTableListener(new TableListener () {
|
|
|
101 |
|
|
|
102 |
public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
|
|
|
103 |
styleRow(selectedRow, false);
|
|
|
104 |
selector.getRowFormatter().addStyleName(0, "location-SelectedRow");
|
|
|
105 |
mediator.onLocationSelected("all");
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
});
|
|
|
109 |
|
|
|
110 |
selector.setStyleName("location-ListElement");
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
// Mise en forme de la table.
|
|
|
114 |
|
|
|
115 |
table.setCellSpacing(0);
|
|
|
116 |
table.setBorderWidth(0);
|
|
|
117 |
table.setCellPadding(2);
|
|
|
118 |
table.setWidth("100%");
|
|
|
119 |
|
|
|
120 |
table.setStyleName("location-ListElement");
|
|
|
121 |
|
|
|
122 |
// Mise en forme barre navigation
|
|
|
123 |
|
|
|
124 |
outer.add(header);
|
|
|
125 |
inner.add(selector);
|
|
|
126 |
inner.add(table);
|
|
|
127 |
inner.setStyleName("location-List");
|
|
|
128 |
inner.setWidth("100%");
|
|
|
129 |
outer.setWidth("100%");
|
|
|
130 |
outer.add(inner);
|
|
|
131 |
|
|
|
132 |
// Hook up events.
|
|
|
133 |
table.addTableListener(new TableListener () {
|
|
|
134 |
|
|
|
135 |
public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
|
|
|
136 |
|
|
|
137 |
selectRow(row);
|
|
|
138 |
String loc=table.getText(row,cell);
|
|
|
139 |
if (loc.compareTo(VALUE_UNKNOWN)!=0) {
|
|
|
140 |
mediator.onLocationSelected(table.getText(row,cell));
|
|
|
141 |
}
|
|
|
142 |
else {
|
|
|
143 |
mediator.onLocationSelected("000null");
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
});
|
|
|
149 |
|
|
|
150 |
styleRow(selectedRow, false);
|
|
|
151 |
selector.getRowFormatter().addStyleName(0, "location-SelectedRow");
|
|
|
152 |
mediator.onLocationSelected("all");
|
|
|
153 |
|
|
|
154 |
update();
|
|
|
155 |
|
|
|
156 |
initWidget(outer);
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
private void selectRow(int row) {
|
|
|
164 |
|
|
|
165 |
styleRow(selectedRow, false);
|
|
|
166 |
styleRow(row, true);
|
|
|
167 |
|
|
|
168 |
selectedRow = row;
|
|
|
169 |
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
private void styleRow(int row, boolean selected) {
|
|
|
174 |
if (row != -1) {
|
|
|
175 |
selector.getRowFormatter().removeStyleName(0, "location-SelectedRow");
|
|
|
176 |
if (selected)
|
|
|
177 |
table.getRowFormatter().addStyleName(row, "location-SelectedRow");
|
|
|
178 |
else
|
|
|
179 |
if (row < table.getRowCount()) {
|
|
|
180 |
table.getRowFormatter().removeStyleName(row, "location-SelectedRow");
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
/**
|
|
|
187 |
*
|
|
|
188 |
* Mise a jour de l'affichage, à partir des données d'inventaire deja
|
|
|
189 |
* saisies. La valeur de this.startIndex permet de determiner quelles
|
|
|
190 |
* données seront affichées
|
|
|
191 |
*
|
|
|
192 |
*/
|
|
|
193 |
|
|
|
194 |
public void update() {
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
// TODO : ne pas recreer la table a chaque fois ... : parcouris le retour, le comparer au present
|
|
|
198 |
// et inserer ou supprimer s'il le faut.
|
|
|
199 |
|
|
|
200 |
// TODO : ou alors prevoir un update pour les ajouts (forcemment à la fin) et un update pour les suppressions ...
|
|
|
201 |
// Sauf qu'il y a les chgts de pages ... : oui, la un fait un update normal ...
|
|
|
202 |
|
|
|
203 |
// TODO : despaghettiser
|
|
|
204 |
|
|
|
205 |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user + "/"
|
|
|
206 |
+ startIndex + "/" + VISIBLE_LOCATION_COUNT,
|
|
|
207 |
|
|
|
208 |
new ResponseTextHandler() {
|
|
|
209 |
|
|
|
210 |
public void onCompletion(String str) {
|
|
|
211 |
|
|
|
212 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
213 |
JSONArray jsonArray;
|
|
|
214 |
JSONArray jsonArrayNested;
|
|
|
215 |
|
|
|
216 |
for (int i = table.getRowCount() - 1; i >= 0; i--) {
|
|
|
217 |
table.removeRow(i);
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
if (location.compareTo("all")==0) {
|
|
|
221 |
styleRow(selectedRow, false);
|
|
|
222 |
selector.getRowFormatter().addStyleName(0, "location-SelectedRow");
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
227 |
int arraySize = jsonArray.size();
|
|
|
228 |
for (int i = 0; i < arraySize; ++i) {
|
|
|
229 |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
|
|
|
230 |
int row = table.insertRow(table.getRowCount());
|
|
|
231 |
// Lieu
|
|
|
232 |
|
|
|
233 |
String loc=((JSONString)jsonArrayNested.get(0)).stringValue();
|
|
|
234 |
|
|
|
235 |
if (loc.compareTo("000null")!=0) {
|
|
|
236 |
table.setText(row, 0,loc);
|
|
|
237 |
}
|
|
|
238 |
else {
|
|
|
239 |
table.setText(row, 0,VALUE_UNKNOWN);
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
if (loc.compareTo(location)==0) {
|
|
|
243 |
styleRow(row, true);
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
table.getFlexCellFormatter().setWidth(row, 0, "100%");
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
}
|
|
|
253 |
});
|
|
|
254 |
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
public void setLocation(String location) {
|
|
|
258 |
this.location = location;
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
}
|