# HG changeset patch # User Ingo Weinzierl # Date 1350905485 -7200 # Node ID 1cdbd8a0c994c885a80cdaacda7f759dee7df02f # Parent e10d60d4f35b98e2b248d4bf740110643791f0c0 Added two new tables ClickableQDTable and ClickableWTable and made Ws and Qs clickable in historical discharge calculation. The new tables define listener interfaces (clicked lower or upper icon) to listen to user clicks. In addition to this, there is an enum ClickMode with NONE, SINGLE and RANGE options, which allows to specifiy, which icons are displayed in the tables. NONE means no icon for user clicks, SINGLE has 1 icon, RANGE 2 icons for lower and upper. diff -r e10d60d4f35b -r 1cdbd8a0c994 flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java Mon Oct 22 10:35:49 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java Mon Oct 22 13:31:25 2012 +0200 @@ -7,7 +7,6 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.rpc.AsyncCallback; - import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.DynamicForm; @@ -18,9 +17,19 @@ import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; import com.smartgwt.client.widgets.tab.TabSet; -import com.smartgwt.client.widgets.tab.Tab; +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.GaugeInfoService; +import de.intevation.flys.client.client.services.GaugeInfoServiceAsync; +import de.intevation.flys.client.client.services.WQInfoService; +import de.intevation.flys.client.client.services.WQInfoServiceAsync; +import de.intevation.flys.client.client.ui.wq.ClickableQDTable; +import de.intevation.flys.client.client.ui.wq.ClickableWTable; +import de.intevation.flys.client.client.ui.wq.ClickableWTable.ClickMode; +import de.intevation.flys.client.client.ui.wq.QDTable; import de.intevation.flys.client.shared.model.ArtifactDescription; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; @@ -30,17 +39,8 @@ import de.intevation.flys.client.shared.model.DoubleArrayData; import de.intevation.flys.client.shared.model.Gauge; import de.intevation.flys.client.shared.model.IntegerOptionsData; -import de.intevation.flys.client.shared.model.WQInfoRecord; import de.intevation.flys.client.shared.model.WQInfoObject; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.GaugeInfoService; -import de.intevation.flys.client.client.services.GaugeInfoServiceAsync; -import de.intevation.flys.client.client.services.WQInfoService; -import de.intevation.flys.client.client.services.WQInfoServiceAsync; -import de.intevation.flys.client.client.ui.wq.WTable; -import de.intevation.flys.client.client.ui.wq.QDTable; +import de.intevation.flys.client.shared.model.WQInfoRecord; /** @@ -75,8 +75,8 @@ protected DoubleArrayPanel panelW; protected DoubleArrayPanel panelQ; - protected WTable wTable; - protected QDTable qTable; + protected ClickableWTable wTable; + protected ClickableQDTable qTable; @Override @@ -170,8 +170,30 @@ protected void initializeTables() { - wTable = new WTable(); - qTable = new QDTable(); + wTable = new ClickableWTable(new ClickableWTable.WClickedListener() { + @Override + public void clickedUpper(double value) { + // nothing to do here + } + + @Override + public void clickedLower(double value) { + panelW.addValue(value); + } + }, ClickMode.SINGLE); + + qTable = new ClickableQDTable(new ClickableQDTable.QClickedListener() { + + @Override + public void clickedUpper(double value) { + // nothing to do here + } + + @Override + public void clickedLower(double value) { + panelQ.addValue(value); + } + }, ClickableQDTable.ClickMode.SINGLE); fetchWQData(); } diff -r e10d60d4f35b -r 1cdbd8a0c994 flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/ClickableQDTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/ClickableQDTable.java Mon Oct 22 13:31:25 2012 +0200 @@ -0,0 +1,171 @@ +package de.intevation.flys.client.client.ui.wq; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; + +import de.intevation.flys.client.client.FLYSConstants; + + +/** + * @author Ingo Weinzierl + */ +public class ClickableQDTable extends ListGrid { + + public static enum ClickMode { + NONE, SINGLE, RANGE + } + + public static interface QClickedListener { + + void clickedLower(double value); + + void clickedUpper(double value); + } + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + private QClickedListener qClickedListener; + private ClickMode clickMode; + + protected boolean lockClick; + + public ClickableQDTable() { + this.clickMode = ClickMode.NONE; + init(); + } + + public ClickableQDTable(QClickedListener qClickedListener, + ClickMode clickMode) { + this.qClickedListener = qClickedListener; + this.clickMode = clickMode; + init(); + } + + private void init() { + setWidth100(); + setHeight100(); + setSelectionType(SelectionStyle.SINGLE); + setSelectionType(SelectionStyle.SINGLE); + setShowHeaderContextMenu(false); + setShowRecordComponents(true); + setShowRecordComponentsByCell(true); + setEmptyMessage(MESSAGE.empty_table()); + + ListGridField name = new ListGridField("name", MESSAGE.discharge()); + name.setType(ListGridFieldType.TEXT); + name.setWidth("*"); + + ListGridField type = new ListGridField("type", MESSAGE.type()); + type.setType(ListGridFieldType.TEXT); + type.setWidth("20%"); + + final NumberFormat nf = NumberFormat.getDecimalFormat(); + + ListGridField value = new ListGridField("value", MESSAGE.wq_value_q()); + value.setType(ListGridFieldType.FLOAT); + value.setCellFormatter(new CellFormatter() { + + @Override + public String format(Object v, ListGridRecord r, int row, int col) { + if (v == null) { + return null; + } + + try { + double value = Double.valueOf(v.toString()); + return nf.format(value); + } + catch (NumberFormatException nfe) { + return v.toString(); + } + } + }); + value.setWidth("20%"); + + switch (clickMode) { + case NONE: + setFields(name, type, value); + break; + case SINGLE: + initSingleClickMode(name, type, value); + break; + case RANGE: + initRangeClickMode(name, type, value); + break; + } + } + + private void initSingleClickMode(ListGridField name, ListGridField type, + ListGridField value) { + ListGridField select = new ListGridField("select", MESSAGE.selection()); + select.setType(ListGridFieldType.ICON); + select.setWidth(70); + select.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); + + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 0) { + ListGridRecord r = event.getRecord(); + fireLowerClickEvent(r.getAttributeAsDouble("value")); + } + } + }); + + setFields(select, name, type, value); + } + + private void initRangeClickMode(ListGridField name, ListGridField type, + ListGridField value) { + ListGridField addMin = new ListGridField("min", MESSAGE.to()); + addMin.setType(ListGridFieldType.ICON); + addMin.setWidth(30); + addMin.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); + + ListGridField addMax = new ListGridField("max", MESSAGE.from()); + addMax.setType(ListGridFieldType.ICON); + addMax.setWidth(30); + addMax.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerRed()); + + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 0) { + ListGridRecord r = event.getRecord(); + fireLowerClickEvent(r.getAttributeAsDouble("value")); + } + + if (event.getColNum() == 1) { + ListGridRecord r = event.getRecord(); + fireUpperClickEvent(r.getAttributeAsDouble("value")); + } + } + }); + + setFields(addMin, addMax, name, type, value); + } + + private void fireLowerClickEvent(double value) { + if (qClickedListener != null) { + qClickedListener.clickedLower(value); + } + } + + private void fireUpperClickEvent(double value) { + if (qClickedListener != null) { + qClickedListener.clickedUpper(value); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r e10d60d4f35b -r 1cdbd8a0c994 flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/ClickableWTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/ClickableWTable.java Mon Oct 22 13:31:25 2012 +0200 @@ -0,0 +1,172 @@ +package de.intevation.flys.client.client.ui.wq; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; + +import de.intevation.flys.client.client.FLYSConstants; + + +public class ClickableWTable extends ListGrid { + + public static enum ClickMode { + NONE, SINGLE, RANGE + } + + public static interface WClickedListener { + + void clickedLower(double value); + + void clickedUpper(double value); + } + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + private WClickedListener wClickedListener; + private ClickMode clickMode; + + public ClickableWTable() { + this.clickMode = ClickMode.NONE; + init(); + } + + public ClickableWTable(WClickedListener lowerListener, + ClickMode selectionMode) { + this.wClickedListener = lowerListener; + this.clickMode = selectionMode; + init(); + } + + private void init() { + setWidth100(); + setHeight100(); + setSelectionType(SelectionStyle.NONE); + setSelectionType(SelectionStyle.NONE); + setShowHeaderContextMenu(false); + setShowRecordComponents(true); + setShowRecordComponentsByCell(true); + setEmptyMessage(MESSAGE.empty_table()); + + ListGridField name = new ListGridField("name", MESSAGE.name()); + name.setType(ListGridFieldType.TEXT); + name.setWidth("*"); + + ListGridField type = new ListGridField("type", MESSAGE.type()); + type.setType(ListGridFieldType.TEXT); + type.setWidth("50"); + + final NumberFormat nf = NumberFormat.getDecimalFormat(); + + ListGridField value = new ListGridField("value", MESSAGE.wq_value_w()); + value.setType(ListGridFieldType.FLOAT); + value.setCellFormatter(new CellFormatter() { + + @Override + public String format(Object v, ListGridRecord r, int row, int col) { + if (v == null) { + return null; + } + + try { + double value = Double.valueOf(v.toString()); + return nf.format(value); + } + catch (NumberFormatException nfe) { + return v.toString(); + } + } + }); + + switch (clickMode) { + case NONE: + setFields(name, type, value); + break; + case SINGLE: + initSingleClickMode(name, type, value); + break; + case RANGE: + initRangeClickMode(name, type, value); + break; + } + } + + private void initSingleClickMode(ListGridField name, ListGridField type, + ListGridField value) { + ListGridField lower = new ListGridField("selection", + MESSAGE.selection()); + lower.setType(ListGridFieldType.ICON); + lower.setWidth("65"); + lower.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 0) { + Record r = event.getRecord(); + double val = r.getAttributeAsDouble("value"); + fireLowerClickEvent(val); + } + } + }); + + setFields(lower, name, type, value); + } + + private void initRangeClickMode(ListGridField name, ListGridField type, + ListGridField value) { + ListGridField lower = new ListGridField("lower", MESSAGE.lower()); + lower.setType(ListGridFieldType.ICON); + lower.setWidth("50"); + lower.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerRed()); + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 0) { + Record r = event.getRecord(); + double val = r.getAttributeAsDouble("value"); + fireLowerClickEvent(val); + } + } + }); + + ListGridField upper = new ListGridField("upper", MESSAGE.upper()); + upper.setType(ListGridFieldType.ICON); + upper.setWidth("50"); + upper.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 1) { + Record r = event.getRecord(); + double val = r.getAttributeAsDouble("value"); + fireUpperClickEvent(val); + } + } + }); + + setFields(lower, upper, name, type, value); + } + + private void fireLowerClickEvent(double value) { + if (wClickedListener != null) { + wClickedListener.clickedLower(value); + } + } + + private void fireUpperClickEvent(double value) { + if (wClickedListener != null) { + wClickedListener.clickedUpper(value); + } + } +}