comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/MultiPeriodPanel.java @ 4131:360e22afb98b

Cosmetics, warnings and minor TODOs.
author Christian Lins <christian.lins@intevation.de>
date Mon, 15 Oct 2012 00:04:35 +0200
parents 0de61fc9d281
children
comparison
equal deleted inserted replaced
4130:df8ac7ff6b1a 4131:360e22afb98b
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2
3 import java.util.List;
4 import java.util.ArrayList;
5 import java.util.Date;
6 2
7 import com.google.gwt.core.client.GWT; 3 import com.google.gwt.core.client.GWT;
8 import com.google.gwt.i18n.client.DateTimeFormat; 4 import com.google.gwt.i18n.client.DateTimeFormat;
9 5
10 import com.smartgwt.client.data.Record; 6 import com.smartgwt.client.types.ListGridFieldType;
11 7 import com.smartgwt.client.widgets.Button;
12 import com.smartgwt.client.widgets.Canvas; 8 import com.smartgwt.client.widgets.Canvas;
13 import com.smartgwt.client.widgets.Label; 9 import com.smartgwt.client.widgets.Label;
14 import com.smartgwt.client.widgets.Button;
15 import com.smartgwt.client.widgets.events.ClickEvent; 10 import com.smartgwt.client.widgets.events.ClickEvent;
16 import com.smartgwt.client.widgets.events.ClickHandler; 11 import com.smartgwt.client.widgets.events.ClickHandler;
17
18 import com.smartgwt.client.widgets.grid.ListGrid; 12 import com.smartgwt.client.widgets.grid.ListGrid;
19 import com.smartgwt.client.widgets.grid.ListGridField; 13 import com.smartgwt.client.widgets.grid.ListGridField;
20 import com.smartgwt.client.widgets.grid.ListGridRecord; 14 import com.smartgwt.client.widgets.grid.ListGridRecord;
21 15 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
16 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
22 import com.smartgwt.client.widgets.layout.HLayout; 17 import com.smartgwt.client.widgets.layout.HLayout;
23 import com.smartgwt.client.widgets.layout.VLayout; 18 import com.smartgwt.client.widgets.layout.VLayout;
24
25 import com.smartgwt.client.types.ListGridFieldType;
26
27 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
28 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
29 19
30 import de.intevation.flys.client.shared.model.Data; 20 import de.intevation.flys.client.shared.model.Data;
31 import de.intevation.flys.client.shared.model.DataItem; 21 import de.intevation.flys.client.shared.model.DataItem;
32 import de.intevation.flys.client.shared.model.DataList; 22 import de.intevation.flys.client.shared.model.DataList;
33 import de.intevation.flys.client.shared.model.DefaultData; 23 import de.intevation.flys.client.shared.model.DefaultData;
34 import de.intevation.flys.client.shared.model.DefaultDataItem; 24 import de.intevation.flys.client.shared.model.DefaultDataItem;
25
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.List;
35 29
36 /** 30 /**
37 * This UIProvider creates a panel for location or distance input. 31 * This UIProvider creates a panel for location or distance input.
38 * 32 *
39 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 33 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
40 */ 34 */
41 public class MultiPeriodPanel 35 public class MultiPeriodPanel
42 extends PeriodPanel 36 extends PeriodPanel
43 { 37 {
44 38
39 private static final long serialVersionUID = 1811025931934462457L;
40
45 protected ListGrid elements; 41 protected ListGrid elements;
46 42
47 protected String values; 43 protected String values;
48 44
49 public MultiPeriodPanel() { 45 public MultiPeriodPanel() {
52 48
53 public MultiPeriodPanel(String startName, String endName) { 49 public MultiPeriodPanel(String startName, String endName) {
54 super(startName, endName); 50 super(startName, endName);
55 } 51 }
56 52
53 @Override
57 public Canvas createWidget(DataList data) { 54 public Canvas createWidget(DataList data) {
58 HLayout input = new HLayout(); 55 HLayout input = new HLayout();
59 VLayout root = new VLayout(); 56 VLayout root = new VLayout();
60 VLayout grid = new VLayout(); 57 VLayout grid = new VLayout();
61 VLayout layout = (VLayout) super.createWidget(data); 58 VLayout layout = (VLayout) super.createWidget(data);
62 Button add = new Button(MSG.add_date()); 59 Button add = new Button(MSG.add_date());
63 elements = new ListGrid(); 60 elements = new ListGrid();
64 61
65 add.addClickHandler(new ClickHandler() { 62 add.addClickHandler(new ClickHandler() {
63 @Override
66 public void onClick(ClickEvent ce) { 64 public void onClick(ClickEvent ce) {
67 Date f = inputPanel.getFromDate(); 65 Date f = inputPanel.getFromDate();
68 Date t = inputPanel.getToDate(); 66 Date t = inputPanel.getToDate();
69 if (f == null || t == null) { 67 if (f == null || t == null) {
70 return; 68 return;
99 setCanFreeze(false); 97 setCanFreeze(false);
100 setWidth(25); 98 setWidth(25);
101 }}; 99 }};
102 100
103 elements.addRecordClickHandler(new RecordClickHandler() { 101 elements.addRecordClickHandler(new RecordClickHandler() {
102 @Override
104 public void onRecordClick(final RecordClickEvent event) { 103 public void onRecordClick(final RecordClickEvent event) {
105 // Just handle remove-clicks 104 // Just handle remove-clicks
106 if(!event.getField().getName().equals(removeField.getName())) { 105 if(!event.getField().getName().equals(removeField.getName())) {
107 return; 106 return;
108 } 107 }
119 root.addMember(input); 118 root.addMember(input);
120 119
121 return root; 120 return root;
122 } 121 }
123 122
123 @SuppressWarnings("deprecation")
124 @Override 124 @Override
125 public Canvas createOld(DataList dataList) { 125 public Canvas createOld(DataList dataList) {
126 GWT.log("old............................"); 126 GWT.log("old............................");
127 HLayout layout = new HLayout(); 127 HLayout layout = new HLayout();
128 layout.setWidth("400px"); 128 layout.setWidth("400px");
164 /** 164 /**
165 * This method returns the selected data. 165 * This method returns the selected data.
166 * 166 *
167 * @return the selected/inserted data. 167 * @return the selected/inserted data.
168 */ 168 */
169 @Override
169 public Data[] getData() { 170 public Data[] getData() {
170 List<Data> data = new ArrayList<Data>(); 171 List<Data> data = new ArrayList<Data>();
171 172
172 boolean valid = saveDateValues(); 173 boolean valid = saveDateValues();
173 if(valid) { 174 if(valid) {
180 } 181 }
181 return data.toArray(new Data[data.size()]); 182 return data.toArray(new Data[data.size()]);
182 } 183 }
183 184
184 185
186 @Override
185 protected boolean saveDateValues() { 187 protected boolean saveDateValues() {
186 ListGridRecord[] lgr = elements.getRecords(); 188 ListGridRecord[] lgr = elements.getRecords();
187 if (lgr.length == 0) { 189 if (lgr.length == 0) {
188 return false; 190 return false;
189 } 191 }
208 public DateRangeRecord (Date from, Date to) { 210 public DateRangeRecord (Date from, Date to) {
209 setFrom(from); 211 setFrom(from);
210 setTo(to); 212 setTo(to);
211 } 213 }
212 214
215 @SuppressWarnings("deprecation")
213 public void setFrom(Date from) { 216 public void setFrom(Date from) {
214 this.from = from; 217 this.from = from;
215 setAttribute( 218 setAttribute(
216 FROM_FIELD, 219 FROM_FIELD,
217 DateTimeFormat.getMediumDateFormat().format(from)); 220 DateTimeFormat.getMediumDateFormat().format(from));
218 } 221 }
219 222
220 223
224 @SuppressWarnings("deprecation")
221 public void setTo(Date to) { 225 public void setTo(Date to) {
222 this.to = to; 226 this.to = to;
223 setAttribute( 227 setAttribute(
224 TO_FIELD, 228 TO_FIELD,
225 DateTimeFormat.getMediumDateFormat().format(to)); 229 DateTimeFormat.getMediumDateFormat().format(to));

http://dive4elements.wald.intevation.org