Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/QDTable.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/client/ui/wq/QDTable.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.client.ui.wq; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.google.gwt.i18n.client.NumberFormat; | |
5 | |
6 import com.smartgwt.client.types.ListGridFieldType; | |
7 import com.smartgwt.client.types.SelectionStyle; | |
8 import com.smartgwt.client.widgets.grid.CellFormatter; | |
9 import com.smartgwt.client.widgets.grid.ListGrid; | |
10 import com.smartgwt.client.widgets.grid.ListGridField; | |
11 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
12 | |
13 import org.dive4elements.river.client.client.FLYSConstants; | |
14 | |
15 | |
16 /** | |
17 * Table showing Q and D main values, allowing for selection. | |
18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
19 */ | |
20 public class QDTable extends ListGrid { | |
21 | |
22 /** The message class that provides i18n strings.*/ | |
23 protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); | |
24 | |
25 | |
26 protected boolean lockClick; | |
27 | |
28 public QDTable() { | |
29 String baseUrl = GWT.getHostPageBaseURL(); | |
30 | |
31 setWidth100(); | |
32 setHeight100(); | |
33 setSelectionType(SelectionStyle.SINGLE); | |
34 setSelectionType(SelectionStyle.SINGLE); | |
35 setShowHeaderContextMenu(false); | |
36 setShowRecordComponents(true); | |
37 setShowRecordComponentsByCell(true); | |
38 setEmptyMessage(MESSAGE.empty_table()); | |
39 | |
40 ListGridField addMax = new ListGridField("max", MESSAGE.from()); | |
41 addMax.setType(ListGridFieldType.ICON); | |
42 addMax.setWidth(30); | |
43 addMax.setCellIcon(baseUrl + MESSAGE.markerRed()); | |
44 | |
45 ListGridField addMin = new ListGridField("min", MESSAGE.to()); | |
46 addMin.setType(ListGridFieldType.ICON); | |
47 addMin.setWidth(30); | |
48 addMin.setCellIcon(baseUrl + MESSAGE.markerGreen()); | |
49 | |
50 ListGridField select = new ListGridField("select", MESSAGE.selection()); | |
51 select.setType(ListGridFieldType.ICON); | |
52 select.setWidth(70); | |
53 select.setCellIcon(baseUrl + MESSAGE.markerGreen()); | |
54 | |
55 ListGridField name = new ListGridField("name", MESSAGE.discharge()); | |
56 name.setType(ListGridFieldType.TEXT); | |
57 name.setWidth("*"); | |
58 | |
59 ListGridField type = new ListGridField("type", MESSAGE.type()); | |
60 type.setType(ListGridFieldType.TEXT); | |
61 type.setWidth("20%"); | |
62 | |
63 final NumberFormat nf = NumberFormat.getDecimalFormat(); | |
64 | |
65 ListGridField value = new ListGridField("value", MESSAGE.wq_value_q()); | |
66 value.setType(ListGridFieldType.FLOAT); | |
67 value.setCellFormatter(new CellFormatter() { | |
68 @Override | |
69 public String format(Object v, ListGridRecord r, int row, int col) { | |
70 if (v == null) { | |
71 return null; | |
72 } | |
73 | |
74 try { | |
75 double value = Double.valueOf(v.toString()); | |
76 return nf.format(value); | |
77 } | |
78 catch (NumberFormatException nfe) { | |
79 return v.toString(); | |
80 } | |
81 } | |
82 }); | |
83 value.setWidth("20%"); | |
84 | |
85 setFields(addMax, addMin, select, name, type, value); | |
86 } | |
87 | |
88 public void hideIconFields () { | |
89 hideField("max"); | |
90 hideField("min"); | |
91 hideField("select"); | |
92 lockClick = true; | |
93 } | |
94 | |
95 | |
96 public void showIconFields() { | |
97 showField("max"); | |
98 showField("min"); | |
99 hideField("select"); | |
100 lockClick = false; | |
101 } | |
102 | |
103 public void showSelect() { | |
104 showField("select"); | |
105 hideField("max"); | |
106 hideField("min"); | |
107 } | |
108 | |
109 public boolean isLocked() { | |
110 return lockClick; | |
111 } | |
112 | |
113 /** | |
114 * Search all records for one with attribute name equals to given name. | |
115 * @return null if none found. | |
116 * */ | |
117 public Double findRecordValue(String name) { | |
118 for (ListGridRecord record : getRecords()) { | |
119 if (record.getAttribute("name").equals(name)) { | |
120 return record.getAttributeAsDouble("value"); | |
121 } | |
122 } | |
123 return null; | |
124 } | |
125 } | |
126 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |