teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui.wq; ingo@580: ingo@580: import com.google.gwt.core.client.GWT; ingo@1498: import com.google.gwt.i18n.client.NumberFormat; ingo@580: ingo@580: import com.smartgwt.client.types.ListGridFieldType; ingo@580: import com.smartgwt.client.types.SelectionStyle; ingo@1498: import com.smartgwt.client.widgets.grid.CellFormatter; ingo@580: import com.smartgwt.client.widgets.grid.ListGrid; ingo@580: import com.smartgwt.client.widgets.grid.ListGridField; ingo@1498: import com.smartgwt.client.widgets.grid.ListGridRecord; ingo@580: teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; ingo@580: ingo@580: ingo@580: /** felix@6666: * Table showing Q and D main values, allowing for selection, if felix@6666: * showSelect is called. In that case, a CellClickHandler should felix@6666: * be registered. felix@6666: * felix@6666: * TODO becomes very similiar to WTable. Probably mergeable. felix@6666: * ingo@580: * @author Ingo Weinzierl ingo@580: */ ingo@580: public class QDTable extends ListGrid { ingo@580: ingo@580: /** The message class that provides i18n strings.*/ ingo@580: protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); ingo@580: ingo@580: raimund@1369: protected boolean lockClick; raimund@1369: ingo@580: public QDTable() { raimund@1399: String baseUrl = GWT.getHostPageBaseURL(); raimund@1399: ingo@580: setWidth100(); ingo@580: setHeight100(); ingo@580: setSelectionType(SelectionStyle.SINGLE); ingo@580: setSelectionType(SelectionStyle.SINGLE); ingo@580: setShowHeaderContextMenu(false); ingo@580: setShowRecordComponents(true); ingo@580: setShowRecordComponentsByCell(true); ingo@580: setEmptyMessage(MESSAGE.empty_table()); ingo@580: raimund@3543: ListGridField addMax = new ListGridField("max", MESSAGE.from()); raimund@912: addMax.setType(ListGridFieldType.ICON); raimund@912: addMax.setWidth(30); raimund@1399: addMax.setCellIcon(baseUrl + MESSAGE.markerRed()); raimund@912: raimund@3543: ListGridField addMin = new ListGridField("min", MESSAGE.to()); raimund@912: addMin.setType(ListGridFieldType.ICON); raimund@912: addMin.setWidth(30); raimund@1399: addMin.setCellIcon(baseUrl + MESSAGE.markerGreen()); raimund@912: raimund@3543: ListGridField select = new ListGridField("select", MESSAGE.selection()); raimund@3543: select.setType(ListGridFieldType.ICON); raimund@3543: select.setWidth(70); raimund@3543: select.setCellIcon(baseUrl + MESSAGE.markerGreen()); raimund@3543: raimund@904: ListGridField name = new ListGridField("name", MESSAGE.discharge()); ingo@580: name.setType(ListGridFieldType.TEXT); ingo@580: name.setWidth("*"); ingo@580: ingo@580: ListGridField type = new ListGridField("type", MESSAGE.type()); ingo@580: type.setType(ListGridFieldType.TEXT); teichmann@6371: type.setWidth("10%"); ingo@580: felix@7565: ListGridField startTime = new ListGridField("starttime", MESSAGE.starttime()); felix@7565: startTime.setType(ListGridFieldType.DATE); felix@7565: startTime.setWidth("60"); felix@7565: felix@7565: ListGridField stopTime = new ListGridField("stoptime", MESSAGE.stoptime()); felix@7565: stopTime.setType(ListGridFieldType.DATE); felix@7565: stopTime.setWidth("60"); felix@7565: ingo@1498: final NumberFormat nf = NumberFormat.getDecimalFormat(); ingo@1498: ingo@2460: ListGridField value = new ListGridField("value", MESSAGE.wq_value_q()); raimund@903: value.setType(ListGridFieldType.FLOAT); ingo@1498: value.setCellFormatter(new CellFormatter() { ingo@1498: @Override ingo@1498: public String format(Object v, ListGridRecord r, int row, int col) { ingo@1498: if (v == null) { ingo@1498: return null; ingo@1498: } ingo@1498: ingo@1498: try { ingo@1498: double value = Double.valueOf(v.toString()); ingo@1498: return nf.format(value); ingo@1498: } ingo@1498: catch (NumberFormatException nfe) { ingo@1498: return v.toString(); ingo@1498: } ingo@1498: } ingo@1498: }); teichmann@6371: value.setWidth("15%"); ingo@580: teichmann@6371: ListGridField official = new ListGridField("official", MESSAGE.official_regulation()); teichmann@6371: official.setType(ListGridFieldType.TEXT); teichmann@6371: official.setWidth("25%"); teichmann@6371: felix@7565: setFields(addMax, addMin, select, name, type, value, official, startTime, stopTime); ingo@580: } raimund@912: raimund@912: public void hideIconFields () { raimund@912: hideField("max"); raimund@912: hideField("min"); raimund@3543: hideField("select"); raimund@1369: lockClick = true; raimund@912: } raimund@912: raimund@912: raimund@912: public void showIconFields() { raimund@912: showField("max"); raimund@912: showField("min"); raimund@3543: hideField("select"); raimund@1369: lockClick = false; raimund@1369: } raimund@1369: raimund@3543: public void showSelect() { raimund@3543: showField("select"); raimund@3543: hideField("max"); raimund@3543: hideField("min"); raimund@3543: } raimund@3543: felix@6666: /** Whether or not can be clicked on. */ raimund@1369: public boolean isLocked() { raimund@1369: return lockClick; raimund@912: } felix@5774: felix@5774: /** felix@5774: * Search all records for one with attribute name equals to given name. felix@5774: * @return null if none found. felix@5774: * */ felix@5774: public Double findRecordValue(String name) { felix@5774: for (ListGridRecord record : getRecords()) { felix@5774: if (record.getAttribute("name").equals(name)) { felix@5774: return record.getAttributeAsDouble("value"); felix@5774: } felix@5774: } felix@5774: return null; felix@5774: } ingo@580: } ingo@580: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :