Mercurial > dive4elements > river
changeset 4199:02a2d4b5bd14
Merged.
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 22 Oct 2012 13:32:38 +0200 |
parents | 1cdbd8a0c994 (diff) 810db532803a (current diff) |
children | 1f212836998e |
files | |
diffstat | 3 files changed, 381 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java Mon Oct 22 11:48:01 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java Mon Oct 22 13:32:38 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(); }
--- /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:32:38 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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +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 :
--- /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:32:38 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); + } + } +}