Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java @ 9107:41f4bc83aa7a
vegzones improved
author | gernotbelger |
---|---|
date | Tue, 29 May 2018 15:19:03 +0200 |
parents | 611a523fc42f |
children | f5b55b383ef9 |
comparison
equal
deleted
inserted
replaced
9106:ffd4e2b0381c | 9107:41f4bc83aa7a |
---|---|
18 import org.dive4elements.river.client.shared.model.DataItem; | 18 import org.dive4elements.river.client.shared.model.DataItem; |
19 import org.dive4elements.river.client.shared.model.DataList; | 19 import org.dive4elements.river.client.shared.model.DataList; |
20 import org.dive4elements.river.client.shared.model.DefaultData; | 20 import org.dive4elements.river.client.shared.model.DefaultData; |
21 import org.dive4elements.river.client.shared.model.DefaultDataItem; | 21 import org.dive4elements.river.client.shared.model.DefaultDataItem; |
22 | 22 |
23 import com.google.gwt.core.client.GWT; | |
23 import com.smartgwt.client.data.Record; | 24 import com.smartgwt.client.data.Record; |
24 import com.smartgwt.client.types.Alignment; | 25 import com.smartgwt.client.types.Alignment; |
26 import com.smartgwt.client.types.ListGridFieldType; | |
25 import com.smartgwt.client.widgets.Canvas; | 27 import com.smartgwt.client.widgets.Canvas; |
26 import com.smartgwt.client.widgets.Label; | 28 import com.smartgwt.client.widgets.Label; |
27 import com.smartgwt.client.widgets.form.fields.TextItem; | 29 import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator; |
28 import com.smartgwt.client.widgets.grid.ListGrid; | 30 import com.smartgwt.client.widgets.grid.ListGrid; |
29 import com.smartgwt.client.widgets.grid.ListGridField; | 31 import com.smartgwt.client.widgets.grid.ListGridField; |
30 import com.smartgwt.client.widgets.grid.ListGridRecord; | 32 import com.smartgwt.client.widgets.grid.ListGridRecord; |
33 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
34 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
31 import com.smartgwt.client.widgets.layout.HLayout; | 35 import com.smartgwt.client.widgets.layout.HLayout; |
36 import com.smartgwt.client.widgets.layout.Layout; | |
32 import com.smartgwt.client.widgets.layout.VLayout; | 37 import com.smartgwt.client.widgets.layout.VLayout; |
33 | 38 |
34 /** | 39 /** |
35 * @author Domenico Nardi Tironi | 40 * @author Domenico Nardi Tironi |
36 * | 41 * |
37 */ | 42 */ |
38 public abstract class AbstractVegZonesTablePanel extends AbstractUIProvider { | 43 public abstract class AbstractVegZonesTablePanel extends AbstractUIProvider { |
39 private static final long serialVersionUID = 1L; | 44 private static final long serialVersionUID = 1L; |
40 public static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; | 45 |
41 public static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; | 46 private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; |
42 | 47 |
43 protected static final String datakey = "vegzones"; | 48 private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; |
44 | 49 |
45 protected final ListGrid elements = new ListGrid(); | 50 private static final String datakey = "vegzones"; |
46 protected TextItem vegzone; | 51 |
47 protected TextItem start; | 52 private final ListGrid elements = new ListGrid(); |
48 protected TextItem end; | 53 |
49 private ListGrid table; | 54 // private final HLayout input = new HLayout(); |
50 | 55 |
51 protected ListGridField vegzoneField;// = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label()); | 56 protected final ListGrid createTable(final Layout root, final DataList data, final int width, final boolean editable) { |
52 protected ListGridField fromField;// = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); | |
53 protected ListGridField toField;// = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to()); | |
54 | |
55 final protected VLayout root = new VLayout(); | |
56 final protected HLayout input = new HLayout(); | |
57 final protected VLayout tableLayout = new VLayout(); | |
58 | |
59 protected final void createTable(final DataList data, final int width) { | |
60 data.add(VegetationzonesTablePanel.getDummyData()); // TODO: GET REAL DATA! | 57 data.add(VegetationzonesTablePanel.getDummyData()); // TODO: GET REAL DATA! |
61 | 58 |
62 final Label title = new Label(data.get(0).getDescription()); | 59 final Label title = new Label(data.get(0).getDescription()); |
63 title.setHeight("35px"); // orig:25 | 60 title.setHeight("35px"); // orig:25 |
64 | 61 |
65 this.elements.setWidth(width); // 185 | 62 this.elements.setWidth(width); // 185 |
66 this.elements.setHeight(300); // | 63 this.elements.setHeight(300); // |
67 this.elements.setShowHeaderContextMenu(false); | 64 this.elements.setShowHeaderContextMenu(false); |
68 this.elements.setCanReorderFields(false); | 65 this.elements.setCanReorderFields(false); |
69 this.elements.setCanSort(false); | 66 this.elements.setCanSort(false); |
70 this.elements.setCanEdit(false); | 67 this.elements.setCanEdit(editable); |
71 this.vegzoneField = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label()); | 68 |
72 this.fromField = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); | 69 final ListGridField vegzoneField = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label()); |
73 this.toField = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to()); | 70 vegzoneField.setType(ListGridFieldType.TEXT); |
74 this.vegzoneField.setWidth(245); | 71 vegzoneField.setWidth(245); |
75 this.fromField.setWidth(80); | 72 |
76 this.toField.setWidth(80); | 73 final ListGridField fromField = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); |
77 this.fromField.setAlign(Alignment.RIGHT); | 74 fromField.setType(ListGridFieldType.INTEGER); |
78 this.toField.setAlign(Alignment.RIGHT); | 75 final IntegerRangeValidator validator = new IntegerRangeValidator(); |
76 validator.setMin(0); | |
77 validator.setMax(365); | |
78 | |
79 fromField.setValidators(validator); | |
80 fromField.setWidth(80); | |
81 fromField.setAlign(Alignment.RIGHT); | |
82 | |
83 final ListGridField toField = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to()); | |
84 toField.setType(ListGridFieldType.INTEGER); | |
85 toField.setValidators(validator); | |
86 toField.setWidth(80); | |
87 toField.setAlign(Alignment.RIGHT); | |
88 | |
89 if (editable) { | |
90 final ListGridField removeField = createRemoveField(); | |
91 this.elements.setFields(vegzoneField, fromField, toField, removeField); | |
92 | |
93 } else { | |
94 this.elements.setFields(vegzoneField, fromField, toField); | |
95 } | |
79 | 96 |
80 addDataInit(data); | 97 addDataInit(data); |
81 | 98 |
82 this.root.addMember(title); | 99 root.addMember(title); |
83 this.tableLayout.addMember(this.elements); | 100 root.addMember(this.elements); |
84 this.root.addMember(this.input); | 101 root.addMember(PanelHelper.getSpacer(10)); |
85 this.root.addMember(this.tableLayout); | 102 |
86 this.root.addMember(PanelHelper.getSpacer(10)); | 103 return this.elements; |
87 | 104 } |
88 } | 105 |
89 | 106 private ListGridField createRemoveField() { |
90 protected final Canvas createHelper() { | 107 |
91 this.table = new ListGrid(); | 108 final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") { |
92 this.table.setShowHeaderContextMenu(false); | 109 { |
93 this.table.setWidth100(); | 110 setType(ListGridFieldType.ICON); |
94 this.table.setShowRecordComponents(true); | 111 setIcon(GWT.getHostPageBaseURL() + AbstractVegZonesTablePanel.this.MSG.removeFeature()); |
95 this.table.setShowRecordComponentsByCell(true); | 112 setCanEdit(false); |
96 this.table.setHeight100(); | 113 setCanFilter(false); |
97 this.table.setEmptyMessage(this.MSG.empty_table()); | 114 setCanSort(false); |
98 this.table.setCanReorderFields(false); | 115 setCanGroupBy(false); |
99 | 116 setCanFreeze(false); |
100 /* Input support pins */ | 117 setWidth(25); |
101 // final String baseUrl = GWT.getHostPageBaseURL(); | 118 } |
102 // final ListGridField pinFrom = new ListGridField("fromIcon", this.MSG.uinfo_vegetation_zones_from()); | 119 }; |
103 // pinFrom.setWidth(300); | 120 |
104 // pinFrom.setType(ListGridFieldType.ICON); | 121 this.elements.addRecordClickHandler(new RecordClickHandler() { |
105 // pinFrom.setCellIcon(baseUrl + this.MSG.markerGreen()); | 122 @Override |
106 // | 123 public void onRecordClick(final RecordClickEvent event) { |
107 // final ListGridField pinTo = new ListGridField("toIcon", this.MSG.uinfo_vegetation_zones_to()); | 124 // Just handle remove-clicks |
108 // pinTo.setType(ListGridFieldType.ICON); | 125 if (!event.getField().getName().equals(removeField.getName())) { |
109 // pinTo.setWidth(300); | 126 return; |
110 // pinTo.setCellIcon(baseUrl + this.MSG.markerRed()); | 127 } |
111 // | 128 event.getViewer().removeData(event.getRecord()); |
112 // pinFrom.addRecordClickHandler(new RecordClickHandler() { | 129 } |
113 // @Override | 130 }); |
114 // public void onRecordClick(final RecordClickEvent e) { | 131 |
115 // final Record r = e.getRecord(); | 132 return removeField; |
116 // VegetationzonesTableEditPanel.this.vegzone.setValue(r.getAttribute("date")); // date?? | 133 } |
117 // } | 134 |
118 // }); | 135 public abstract void createWidget(final Layout root, final DataList data); |
119 // | |
120 // pinFrom.addRecordClickHandler(new RecordClickHandler() { | |
121 // @Override | |
122 // public void onRecordClick(final RecordClickEvent e) { | |
123 // final Record r = e.getRecord(); | |
124 // VegetationzonesTableEditPanel.this.start.setValue(r.getAttribute("date")); | |
125 // } | |
126 // }); | |
127 // | |
128 // pinTo.addRecordClickHandler(new RecordClickHandler() { | |
129 // @Override | |
130 // public void onRecordClick(final RecordClickEvent e) { | |
131 // final Record r = e.getRecord(); | |
132 // VegetationzonesTableEditPanel.this.end.setValue(r.getAttribute("date")); | |
133 // } | |
134 // }); | |
135 // | |
136 // final ListGridField date = new ListGridField("date", this.MSG.year()); | |
137 // date.setType(ListGridFieldType.TEXT); | |
138 // date.setWidth(100); | |
139 // | |
140 // final ListGridField descr = new ListGridField("description", this.MSG.description()); | |
141 // descr.setType(ListGridFieldType.TEXT); | |
142 // descr.setWidth("*"); | |
143 // | |
144 // this.table.setFields(pinFrom, pinTo, date, descr); | |
145 return this.table; | |
146 } | |
147 | |
148 public abstract Canvas createWidget(final DataList data); | |
149 | 136 |
150 private final void addDataInit(final DataList data) { | 137 private final void addDataInit(final DataList data) { |
151 for (final Data dataItemContainer : data.getAll()) { | 138 for (final Data dataItemContainer : data.getAll()) { |
152 if (dataItemContainer.getItems() != null) { | 139 if (dataItemContainer.getItems() != null) { |
153 for (final DataItem dataItem : dataItemContainer.getItems()) { | 140 for (final DataItem dataItem : dataItemContainer.getItems()) { |
164 } | 151 } |
165 | 152 |
166 @Override | 153 @Override |
167 public final Canvas create(final DataList data) { | 154 public final Canvas create(final DataList data) { |
168 final VLayout layout = new VLayout(); | 155 final VLayout layout = new VLayout(); |
169 final Canvas helper = createHelper(); | 156 |
170 this.helperContainer.addMember(helper); | 157 // final Canvas helper = createHelper(); |
158 // this.helperContainer.addMember(helper); | |
171 | 159 |
172 final Canvas submit = getNextButton(); | 160 final Canvas submit = getNextButton(); |
173 final Canvas widget = createWidget(data); | 161 |
174 | 162 final VLayout root = new VLayout(); |
175 layout.addMember(widget); | 163 createWidget(root, data); |
176 layout.addMember(submit); // TODO: SUBMIT | 164 |
177 | 165 layout.addMember(root); |
178 // fetchSedimentLoadData(); //TODO: feed from database... | 166 layout.addMember(submit); |
179 | 167 |
180 return layout; | 168 return layout; |
181 } | 169 } |
182 | 170 |
183 @Override | 171 @Override |
192 | 180 |
193 final List<Data> items = dataList.getAll(); | 181 final List<Data> items = dataList.getAll(); |
194 final Data str = getData(items, datakey); | 182 final Data str = getData(items, datakey); |
195 final DataItem[] strItems = str.getItems(); | 183 final DataItem[] strItems = str.getItems(); |
196 | 184 |
197 final String[] entries = strItems[0].getLabel().split(VegetationzonesTablePanel.TABLE_ROW_SEPARATOR); | 185 final String[] entries = strItems[0].getLabel().split(AbstractVegZonesTablePanel.TABLE_ROW_SEPARATOR); |
198 for (final String entry : entries) { | 186 for (final String entry : entries) { |
199 final String[] vals = entry.split(VegetationzonesTablePanel.TABLE_CELL_SEPARATOR); | 187 final String[] vals = entry.split(AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR); |
200 final Label dateLabel = new Label(vals[0] + " (" + vals[1] + "-" + vals[2] + ")"); | 188 final Label dateLabel = new Label(vals[0] + " (" + vals[1] + "-" + vals[2] + ")"); |
201 dateLabel.setHeight(20); | 189 dateLabel.setHeight(20); |
202 vLayout.addMember(dateLabel); | 190 vLayout.addMember(dateLabel); |
203 } | 191 } |
204 final Canvas back = getBackButton(dataList.getState()); | 192 final Canvas back = getBackButton(dataList.getState()); |
237 return getDummyData();// new Data[0]; // return getDummyData(); | 225 return getDummyData();// new Data[0]; // return getDummyData(); |
238 } | 226 } |
239 String d = ""; | 227 String d = ""; |
240 for (final ListGridRecord element : lgr) { | 228 for (final ListGridRecord element : lgr) { |
241 final Record r = element; | 229 final Record r = element; |
242 d += r.getAttribute("vegzone") + VegetationzonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("from") | 230 d += r.getAttribute("vegzone") + AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("from") |
243 + VegetationzonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("to"); | 231 + AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("to"); |
244 d += VegetationzonesTablePanel.TABLE_ROW_SEPARATOR; | 232 d += AbstractVegZonesTablePanel.TABLE_ROW_SEPARATOR; |
245 } | 233 } |
246 | 234 |
247 final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key | 235 final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key |
248 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); | 236 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); |
249 return data.toArray(new Data[data.size()]); | 237 return data.toArray(new Data[data.size()]); |
272 } | 260 } |
273 | 261 |
274 } | 262 } |
275 return null; | 263 return null; |
276 } | 264 } |
277 | |
278 } | 265 } |