9063
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 |
|
9 package org.dive4elements.river.client.client.ui.sinfo; |
|
10 |
9079
|
11 import org.dive4elements.river.client.client.ui.AbstractEpochPanel; |
9063
|
12 import org.dive4elements.river.client.shared.model.DataList; |
|
13 |
|
14 import com.google.gwt.core.client.GWT; |
|
15 import com.smartgwt.client.types.ListGridFieldType; |
|
16 import com.smartgwt.client.widgets.Button; |
|
17 import com.smartgwt.client.widgets.Canvas; |
|
18 import com.smartgwt.client.widgets.Label; |
|
19 import com.smartgwt.client.widgets.events.ClickEvent; |
|
20 import com.smartgwt.client.widgets.events.ClickHandler; |
|
21 import com.smartgwt.client.widgets.form.DynamicForm; |
|
22 import com.smartgwt.client.widgets.form.fields.TextItem; |
|
23 import com.smartgwt.client.widgets.grid.ListGrid; |
|
24 import com.smartgwt.client.widgets.grid.ListGridField; |
|
25 import com.smartgwt.client.widgets.grid.ListGridRecord; |
|
26 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; |
|
27 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; |
|
28 import com.smartgwt.client.widgets.layout.HLayout; |
|
29 import com.smartgwt.client.widgets.layout.VLayout; |
|
30 |
9079
|
31 public class CollisionLoadEpochPanel extends AbstractEpochPanel { |
9063
|
32 |
9079
|
33 private static final long serialVersionUID = 1L; |
9063
|
34 |
9079
|
35 @Override |
|
36 protected String getDatakey() { |
9078
|
37 return "epochs"; |
|
38 } |
|
39 |
9079
|
40 public CollisionLoadEpochPanel() { |
|
41 super(Type.multi); |
|
42 } |
9063
|
43 |
9079
|
44 @Override |
|
45 protected Canvas createWidget(final DataList data) { |
9063
|
46 final HLayout input = new HLayout(); |
|
47 final VLayout root = new VLayout(); |
|
48 final VLayout grid = new VLayout(); |
|
49 final VLayout intFields = new VLayout(); |
|
50 final Button add = new Button(this.MSG.add_date()); |
9079
|
51 final ListGrid elements = createListGrid(); |
|
52 elements.setWidth(185); |
|
53 elements.setHeight(120); |
9063
|
54 |
|
55 final Label title = new Label(data.get(0).getDescription()); |
|
56 title.setHeight("25px"); |
|
57 |
|
58 final DynamicForm form = new DynamicForm(); |
|
59 form.setNumCols(4); |
9079
|
60 final TextItem start = createStartInputItem(this.MSG.from()); |
|
61 final TextItem end = createEndInputItem(this.MSG.to()); |
|
62 |
|
63 form.setFields(start, end); |
9063
|
64 add.addClickHandler(new ClickHandler() { |
|
65 @Override |
|
66 public void onClick(final ClickEvent ce) { |
9079
|
67 final String v1 = start.getValueAsString(); |
|
68 final String v2 = end.getValueAsString(); |
9063
|
69 if (v1 == null || v2 == null) { |
|
70 return; |
|
71 } |
|
72 if (!isValidEpoch(v1, v2)) { |
|
73 return; |
|
74 } |
|
75 final ListGridRecord r = new ListGridRecord(); |
|
76 r.setAttribute("from", v1); |
|
77 r.setAttribute("to", v2); |
9079
|
78 elements.addData(r); |
9063
|
79 } |
|
80 }); |
|
81 |
|
82 final Label sel = new Label(this.MSG.select()); |
|
83 sel.setHeight(25); |
9079
|
84 |
9063
|
85 final ListGridField from = new ListGridField("from", this.MSG.from()); |
|
86 final ListGridField to = new ListGridField("to", this.MSG.to()); |
|
87 from.setWidth(70); |
|
88 to.setWidth(70); |
|
89 |
|
90 final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") { |
|
91 { |
|
92 setType(ListGridFieldType.ICON); |
|
93 setIcon(GWT.getHostPageBaseURL() + CollisionLoadEpochPanel.this.MSG.removeFeature()); |
|
94 setCanEdit(false); |
|
95 setCanFilter(false); |
|
96 setCanSort(false); |
|
97 setCanGroupBy(false); |
|
98 setCanFreeze(false); |
|
99 setWidth(25); |
|
100 } |
|
101 }; |
|
102 |
9079
|
103 elements.addRecordClickHandler(new RecordClickHandler() { |
9063
|
104 @Override |
|
105 public void onRecordClick(final RecordClickEvent event) { |
|
106 // Just handle remove-clicks |
|
107 if (!event.getField().getName().equals(removeField.getName())) { |
|
108 return; |
|
109 } |
|
110 event.getViewer().removeData(event.getRecord()); |
|
111 } |
|
112 }); |
|
113 |
9079
|
114 elements.setFields(from, to, removeField); |
9063
|
115 |
|
116 intFields.addMember(form); |
|
117 intFields.addMember(add); |
|
118 grid.addMember(sel); |
9079
|
119 grid.addMember(elements); |
9063
|
120 input.addMember(intFields); |
|
121 input.addMember(grid); |
|
122 root.addMember(title); |
|
123 root.addMember(input); |
|
124 |
|
125 return root; |
|
126 } |
|
127 |
|
128 } |