Mercurial > dive4elements > river
changeset 9064:28c50f5efceb
work on uinfo-vegetation-zones table
line wrap: on
line diff
--- a/artifacts/doc/conf/artifacts/uinfo.xml Tue May 08 15:21:23 2018 +0200 +++ b/artifacts/doc/conf/artifacts/uinfo.xml Wed May 09 16:31:12 2018 +0200 @@ -19,6 +19,11 @@ <data name="ld_from" type="Double" /> <data name="ld_to" type="Double" /> </state> + <state id="state.uinfo.distance" description="state.uinfo.distance" state="org.dive4elements.river.artifacts.states.DistanceSelect" helpText="help.state.uinfo.distance_only"> + <data name="ld_from" type="Double" /> + <data name="ld_to" type="Double" /> + <data name="ld_step" type="Double" /> + </state> @@ -184,16 +189,16 @@ <transition transition="org.dive4elements.river.artifacts.transitions.ValueCompareTransition"> <from state="state.uinfo.inundation.scenario" /> <to state="state.uinfo.inundation.vegetation" /> - <condition data="calculation_mode" value="uinfo_inundation_duration" operator="equal" /> + <condition data="calculation_mode" value="uinfo_inundation_duration" operator="equal" /> </transition> <transition transition="org.dive4elements.river.artifacts.transitions.ValueCompareTransition"> <from state="state.uinfo.inundation.vegetation" /> <to state="state.uinfo.inundation_duration" /> - <condition data="calculation_mode" value="uinfo_inundation_duration" operator="equal" /> + <condition data="calculation_mode" value="uinfo_inundation_duration" operator="equal" /> </transition> - + <state id="state.uinfo.inundation_duration" description="state.uinfo.inundation_duration" state="org.dive4elements.river.artifacts.uinfo.inundationduration.InundationDurationState" helpText="help.state.uinfo.inundation_duration"> <outputmodes> @@ -214,7 +219,6 @@ </outputmodes> </state> - </states> @@ -234,33 +238,87 @@ - <!-- Calculation Mode: Vegetation Zones --> - <transition transition="org.dive4elements.river.artifacts.transitions.ValueCompareTransition"> - <from state="state.uinfo.calculation_mode" /> - <to state="state.uinfo.vegetation_zones" /> - <condition data="calculation_mode" value="uinfo_vegetation_zones" operator="equal" /> - - </transition> - - <state id="state.uinfo.vegetation_zones" description="state.uinfo.vegetation_zones" state="org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZonesState" helpText="help.state.uinfo.vegetation_zones"> - <outputmodes> - <!-- FIXME: i01n name in FLYSConstants --> - <outputmode name="uinfo_vegetation_zones_export" description="output.uinfo_vegetation_zones_export" mime-type="text/plain" type="export"> - <facets> - <facet name="csv" description="facet.uinfo_vegetation_zones_export.csv" /> - <facet name="pdf" description="facet.uinfo_vegetation_zones_export.pdf" /> - </facets> - </outputmode> - - <!-- FIXME: i01n name in FLYSConstants --> - <outputmode name="uinfo_vegetation_zones_report" description="output.uinfo_vegetation_zones_report" mime-type="text/xml" type="report"> - <facets> - <facet name="report" description="facet.uinfo_vegetation_zones_report" /> - </facets> - </outputmode> - </outputmodes> - </state> + <!-- Calculation Mode: Vegetation Zones --> + + <transition transition="org.dive4elements.river.artifacts.transitions.ValueCompareTransition"> + <from state="state.uinfo.calculation_mode" /> + <to state="state.uinfo.distance" /> + <condition data="calculation_mode" value="uinfo_vegetation_zones" operator="equal" /> + </transition> + + + <transition transition="org.dive4elements.river.artifacts.transitions.ValueCompareTransition"> + <from state="state.uinfo.distance" /> + <to state="state.uinfo.vegetation_zones.table" /> + <condition data="calculation_mode" value="uinfo_vegetation_zones" operator="equal" /> + </transition> + + + + <state id="state.uinfo.vegetation_zones.table" description="state.uinfo.vegetation_zones.table" state="org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZonesTableState" helpText="help.state.uinfo.vegetation_zones"> + <data name="epochs" type="String" /> + </state> + + + <transition transition="org.dive4elements.river.artifacts.transitions.ValueCompareTransition"> + <from state="state.uinfo.vegetation_zones.table" /> + <to state="state.uinfo.vegetation_zones" /> + <condition data="calculation_mode" value="uinfo_vegetation_zones" operator="equal" /> + </transition> + + + <state id="state.uinfo.vegetation_zones" description="state.uinfo.vegetation_zones" state="org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZonesState" helpText="help.state.uinfo.vegetation_zones"> + <outputmodes> + + <!-- FIXME: i01n name in FLYSConstants --> + <outputmode name="uinfo_vegetation_zones_export" description="output.uinfo_vegetation_zones_export" mime-type="text/plain" type="export"> + <facets> + <facet name="csv" description="facet.uinfo_vegetation_zones_export.csv" /> + <facet name="pdf" description="facet.uinfo_vegetation_zones_export.pdf" /> + </facets> + </outputmode> + + <!-- FIXME: i01n name in FLYSConstants --> + <outputmode name="uinfo_vegetation_zones_report" description="output.uinfo_vegetation_zones_report" mime-type="text/xml" type="report"> + <facets> + <facet name="report" description="facet.uinfo_vegetation_zones_report" /> + </facets> + </outputmode> + </outputmodes> + </state> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + </states> </artifact> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableState.java Wed May 09 16:31:12 2018 +0200 @@ -0,0 +1,25 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.artifacts.uinfo.vegetationzones; + +import org.dive4elements.river.artifacts.states.DefaultState; + +/** + * @author Domenico Nardi Tironi + */ +public class VegetationZonesTableState extends DefaultState { + + private static final long serialVersionUID = 1L; + + @Override + protected String getUIProvider() { + return "uinfo.vegetationzones.table"; + } +} \ No newline at end of file
--- a/artifacts/src/main/resources/messages.properties Tue May 08 15:21:23 2018 +0200 +++ b/artifacts/src/main/resources/messages.properties Wed May 09 16:31:12 2018 +0200 @@ -75,6 +75,8 @@ state.minfo.t_per_a = t/a state.minfo.m3_per_a = m\u00b3/a +state.uinfo.vegetation_zones.table = Einteilung der Vegetationszonen und \u00dcberflutungsdauern (\u00dcFD) + state.uinfo.year_epoch = Year/Epoch state.uinfo.load.year= Year state.uinfo.load.epoch=Epoch @@ -1040,6 +1042,7 @@ scenarioType.option3 = Historische Betrachtung help.state.uinfo.scenario_type=${help.url}/OnlineHilfe/UINFO#help.state.uinfo.scenario_type +state.uinfo.distance = Berechnungsstrecke w\u00e4hlen [km] state.uinfo.distance_only_part = Teilabschnitt help.state.uinfo.distance_only_part = ${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only_part
--- a/artifacts/src/main/resources/messages_de.properties Tue May 08 15:21:23 2018 +0200 +++ b/artifacts/src/main/resources/messages_de.properties Wed May 09 16:31:12 2018 +0200 @@ -75,6 +75,8 @@ state.minfo.t_per_a = t/a state.minfo.m3_per_a = m\u00b3/a +state.uinfo.vegetation_zones.table = Einteilung der Vegetationszonen und \u00dcberflutungsdauern (\u00dcFD) + state.uinfo.year_epoch = Jahr/Epoche state.uinfo.load.year= Jahr state.uinfo.load.epoch=Epoche @@ -1040,6 +1042,7 @@ scenarioType.option1 = Historische Betrachtung help.state.uinfo.scenario_type=${help.url}/OnlineHilfe/UINFO#help.state.uinfo.scenario_type +state.uinfo.distance = Berechnungsstrecke w\u00e4hlen [km] state.uinfo.distance_only_part = Teilabschnitt help.state.uinfo.distance_only_part = ${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only_part
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java Tue May 08 15:21:23 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java Wed May 09 16:31:12 2018 +0200 @@ -1508,4 +1508,13 @@ String uinfo_vegetation_zones_export(); String uinfo_inundation_duration_export(); + + String uinfo_vegetation_zone_label(); + + String uinfo_vegetation_zones_label(); + + String uinfo_vegetation_zones_from(); + + String uinfo_vegetation_zones_to(); + } \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties Tue May 08 15:21:23 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties Wed May 09 16:31:12 2018 +0200 @@ -806,4 +806,9 @@ uinfo = U-INFO uinfo_inundation_duration_export = \u00dcberflutungsdauern Export uinfo_salix_line_export = Salix-Linie Export -uinfo_vegetation_zones_export = Vegetationszonen Export \ No newline at end of file +uinfo_vegetation_zones_export = Vegetationszonen Export + +uinfo_vegetation_zone_label = Vegetationszone +uinfo_vegetation_zones_label = Vegetationszonen +uinfo_vegetation_zones_from = \u00dcfd von [d/a] +uinfo_vegetation_zones_to = \u00dcfd bis [d/a] \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties Tue May 08 15:21:23 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties Wed May 09 16:31:12 2018 +0200 @@ -806,4 +806,9 @@ uinfo = U-INFO uinfo_inundation_duration_export = \u00dcberflutungsdauern Export uinfo_salix_line_export = Salix-Linie Export -uinfo_vegetation_zones_export = Vegetationszonen Export \ No newline at end of file +uinfo_vegetation_zones_export = Vegetationszonen Export + +uinfo_vegetation_zone_label = Vegetationszone +uinfo_vegetation_zones_label = Vegetationszonen +uinfo_vegetation_zones_from = \u00dcfd von [d/a] +uinfo_vegetation_zones_to = \u00dcfd bis [d/a] \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistanceOnlyPanel.java Tue May 08 15:21:23 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistanceOnlyPanel.java Wed May 09 16:31:12 2018 +0200 @@ -8,40 +8,35 @@ package org.dive4elements.river.client.client.ui; +import java.util.List; + import org.dive4elements.river.client.shared.model.Data; import org.dive4elements.river.client.shared.model.DataItem; import org.dive4elements.river.client.shared.model.DataList; -import java.util.List; - - public class DistanceOnlyPanel extends DistancePanel { private static final long serialVersionUID = -5794138573892656947L; - public DistanceOnlyPanel() { this("right"); } - - public DistanceOnlyPanel(String labelOrientation) { - distancePanel = new DoubleRangeOnlyPanel( - labelFrom(), labelTo(), 0d, 0d, 250, this, labelOrientation); + public DistanceOnlyPanel(final String labelOrientation) { + this.distancePanel = new DoubleRangeOnlyPanel(labelFrom(), labelTo(), 0d, 0d, 250, this, labelOrientation); } - @Override - protected String getOldSelectionString(DataList dataList) { - List<Data> items = dataList.getAll(); + protected String getOldSelectionString(final DataList dataList) { + final List<Data> items = dataList.getAll(); - Data dFrom = getData(items, getLowerField()); - Data dTo = getData(items, getUpperField()); + final Data dFrom = getData(items, getLowerField()); + final Data dTo = getData(items, getUpperField()); - DataItem[] from = dFrom.getItems(); - DataItem[] to = dTo.getItems(); + final DataItem[] from = dFrom.getItems(); + final DataItem[] to = dTo.getItems(); - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append(from[0].getLabel()); sb.append(" " + getUnitFrom() + " - "); sb.append(to[0].getLabel()); @@ -50,16 +45,14 @@ return sb.toString(); } - @Override - protected void initDefaultStep(DataList data) { + protected void initDefaultStep(final DataList data) { // do nothing } - @Override public Data[] getData() { - Data[] data = new Data[2]; + final Data[] data = new Data[2]; data[0] = getDataFrom(); data[1] = getDataTo(); @@ -67,16 +60,13 @@ return data; } - @Override protected String labelFrom() { return getUnitFrom() + " - "; } - @Override protected String labelTo() { return getUnitTo(); } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +} \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java Tue May 08 15:21:23 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java Wed May 09 16:31:12 2018 +0200 @@ -8,9 +8,27 @@ package org.dive4elements.river.client.client.ui; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +import org.dive4elements.river.client.client.Config; +import org.dive4elements.river.client.client.FLYSConstants; +import org.dive4elements.river.client.client.event.FilterHandler; +import org.dive4elements.river.client.client.event.RangeFilterEvent; +import org.dive4elements.river.client.client.event.StringFilterEvent; +import org.dive4elements.river.client.client.ui.range.DistanceInfoDataSource; +import org.dive4elements.river.client.client.ui.range.LocationsTable; +import org.dive4elements.river.client.client.ui.range.RangeTable; +import org.dive4elements.river.client.shared.model.ArtifactDescription; +import org.dive4elements.river.client.shared.model.Data; +import org.dive4elements.river.client.shared.model.DataItem; +import org.dive4elements.river.client.shared.model.DataList; +import org.dive4elements.river.client.shared.model.DefaultData; +import org.dive4elements.river.client.shared.model.DefaultDataItem; + import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.NumberFormat; - import com.smartgwt.client.data.AdvancedCriteria; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.Criterion; @@ -37,30 +55,8 @@ import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; -import org.dive4elements.river.client.client.Config; -import org.dive4elements.river.client.client.FLYSConstants; -import org.dive4elements.river.client.client.event.FilterHandler; -import org.dive4elements.river.client.client.event.RangeFilterEvent; -import org.dive4elements.river.client.client.event.StringFilterEvent; -import org.dive4elements.river.client.client.ui.range.DistanceInfoDataSource; -import org.dive4elements.river.client.client.ui.range.LocationsTable; -import org.dive4elements.river.client.client.ui.range.RangeTable; -import org.dive4elements.river.client.shared.model.ArtifactDescription; -import org.dive4elements.river.client.shared.model.Data; -import org.dive4elements.river.client.shared.model.DataItem; -import org.dive4elements.river.client.shared.model.DataList; -import org.dive4elements.river.client.shared.model.DefaultData; -import org.dive4elements.river.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - - /** Panel to allow input of distance for calculation range. */ -public class DistancePanel - extends AbstractUIProvider implements BlurHandler, FilterHandler -{ +public class DistancePanel extends AbstractUIProvider implements BlurHandler, FilterHandler { private static final long serialVersionUID = -883142387908664588L; @@ -68,12 +64,11 @@ public static final String FIELD_LOWER = "ld_from"; public static final String FIELD_UPPER = "ld_to"; - public static final String FIELD_STEP = "ld_step"; - + public static final String FIELD_STEP = "ld_step"; protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - protected RangeTable distancesTable; + protected RangeTable distancesTable; protected LocationsTable locationsTable; protected DoubleRangePanel distancePanel; @@ -93,28 +88,24 @@ this("right"); } - - public DistancePanel(String labelOrientation) { - distancePanel = new DoubleRangePanel( - labelFrom(), labelTo(), labelStep(), - 0d, 0d, 0d, 250, this, labelOrientation); + public DistancePanel(final String labelOrientation) { + this.distancePanel = new DoubleRangePanel(labelFrom(), labelTo(), labelStep(), 0d, 0d, 0d, 250, this, labelOrientation); } - @Override - public Canvas create(DataList data) { - VLayout layout = new VLayout(); + public Canvas create(final DataList data) { + final VLayout layout = new VLayout(); layout.setMembersMargin(10); - Label label = new Label(getLabel()); + final Label label = new Label(getLabel()); - Canvas submit = getNextButton(); + final Canvas submit = getNextButton(); label.setHeight(25); - distancePanel.setHeight(50); + this.distancePanel.setHeight(50); layout.addMember(label); - layout.addMember(distancePanel); + layout.addMember(this.distancePanel); layout.addMember(submit); initMinMaxValues(data); @@ -124,16 +115,15 @@ return layout; } - @Override - public Canvas createOld(DataList dataList) { - String s = getOldSelectionString(dataList); - String l = dataList.getLabel(); + public Canvas createOld(final DataList dataList) { + final String s = getOldSelectionString(dataList); + final String l = dataList.getLabel(); - Label label = new Label(l); - Label selected = new Label(s); + final Label label = new Label(l); + final Label selected = new Label(s); - HLayout layout = new HLayout(); + final HLayout layout = new HLayout(); layout.setWidth(400); label.setWidth(200); @@ -146,19 +136,18 @@ return layout; } - - protected String getOldSelectionString(DataList dataList) { - List<Data> items = dataList.getAll(); + protected String getOldSelectionString(final DataList dataList) { + final List<Data> items = dataList.getAll(); - Data dFrom = getData(items, getLowerField()); - Data dTo = getData(items, getUpperField()); - Data dStep = getData(items, getStepField()); + final Data dFrom = getData(items, getLowerField()); + final Data dTo = getData(items, getUpperField()); + final Data dStep = getData(items, getStepField()); - DataItem[] from = dFrom.getItems(); - DataItem[] to = dTo.getItems(); - DataItem[] step = dStep.getItems(); + final DataItem[] from = dFrom.getItems(); + final DataItem[] to = dTo.getItems(); + final DataItem[] step = dStep.getItems(); - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append(from[0].getLabel()); sb.append(" " + getUnitFrom() + " - "); sb.append(to[0].getLabel()); @@ -169,78 +158,64 @@ return sb.toString(); } - protected String getLabel() { - return MSG.distance_state(); + return this.MSG.distance_state(); } - protected String labelFrom() { return getLabelFrom() + " [" + getUnitFrom() + "]"; } - protected String getLabelFrom() { - return MSG.dpLabelFrom(); + return this.MSG.dpLabelFrom(); } - protected String getUnitFrom() { - return MSG.dpUnitFrom(); + return this.MSG.dpUnitFrom(); } - protected String labelTo() { return getLabelTo() + " [" + getUnitTo() + "]"; } - protected String getLabelTo() { - return MSG.dpLabelTo(); + return this.MSG.dpLabelTo(); } - protected String getUnitTo() { - return MSG.dpUnitTo(); + return this.MSG.dpUnitTo(); } - protected String labelStep() { return getLabelStep() + " [" + getUnitStep() + "]"; } - protected String getLabelStep() { - return MSG.dpLabelStep(); + return this.MSG.dpLabelStep(); } - protected String getUnitStep() { - return MSG.dpUnitStep(); + return this.MSG.dpUnitStep(); } - protected String getLowerField() { return FIELD_LOWER; } - protected String getUpperField() { return FIELD_UPPER; } - protected String getStepField() { return FIELD_STEP; } - @Override public List<String> validate() { - List<String> errors = new ArrayList<String>(); + final List<String> errors = new ArrayList<String>(); - if (!distancePanel.validateForm()) { - errors.add(MSG.wrongFormat()); + if (!this.distancePanel.validateForm()) { + errors.add(this.MSG.wrongFormat()); return errors; } @@ -251,413 +226,366 @@ return errors; } - - protected void validateFrom(List<String> errors) { - double from = distancePanel.getFrom(); + protected void validateFrom(final List<String> errors) { + final double from = this.distancePanel.getFrom(); - if (from < min || from > max) { - NumberFormat nf = NumberFormat.getDecimalFormat(); + if (from < this.min || from > this.max) { + final NumberFormat nf = NumberFormat.getDecimalFormat(); - String tmp = MSG.error_validate_lower_range(); - tmp = tmp.replace("$1", nf.format(from)); - tmp = tmp.replace("$2", nf.format(min)); + String tmp = this.MSG.error_validate_lower_range(); + tmp = tmp.replace("$1", nf.format(from)); + tmp = tmp.replace("$2", nf.format(this.min)); - distancePanel.setFrom(min); + this.distancePanel.setFrom(this.min); errors.add(tmp); } } - - protected void validateTo(List<String> errors) { - double to = distancePanel.getTo(); + protected void validateTo(final List<String> errors) { + final double to = this.distancePanel.getTo(); - if (to < min || to > max) { - NumberFormat nf = NumberFormat.getDecimalFormat(); + if (to < this.min || to > this.max) { + final NumberFormat nf = NumberFormat.getDecimalFormat(); - String tmp = MSG.error_validate_upper_range(); - tmp = tmp.replace("$1", nf.format(to)); - tmp = tmp.replace("$2", nf.format(max)); + String tmp = this.MSG.error_validate_upper_range(); + tmp = tmp.replace("$1", nf.format(to)); + tmp = tmp.replace("$2", nf.format(this.max)); - distancePanel.setTo(max); + this.distancePanel.setTo(this.max); errors.add(tmp); } } - @Override public Data[] getData() { - Data[] data = new Data[4]; + final Data[] data = new Data[4]; data[0] = getDataFrom(); data[1] = getDataTo(); data[2] = getDataStep(); - DataItem item = new DefaultDataItem("ld_mode","ld_mode", "distance"); - data[3] = new DefaultData( - "ld_mode", null, null, new DataItem[] { item }); + final DataItem item = new DefaultDataItem("ld_mode", "ld_mode", "distance"); + data[3] = new DefaultData("ld_mode", null, null, new DataItem[] { item }); return data; } - protected Data getDataFrom() { - String value = String.valueOf(distancePanel.getFrom()); - String field = getLowerField(); + final String value = String.valueOf(this.distancePanel.getFrom()); + final String field = getLowerField(); - DataItem item = new DefaultDataItem(field, field, value); - return new DefaultData( - field, null, null, new DataItem[] { item }); + final DataItem item = new DefaultDataItem(field, field, value); + return new DefaultData(field, null, null, new DataItem[] { item }); } - protected Data getDataTo() { - String value = String.valueOf(distancePanel.getTo()); - String field = getUpperField(); + final String value = String.valueOf(this.distancePanel.getTo()); + final String field = getUpperField(); - DataItem item = new DefaultDataItem(field, field, value); - return new DefaultData( - field, null, null, new DataItem[] { item }); + final DataItem item = new DefaultDataItem(field, field, value); + return new DefaultData(field, null, null, new DataItem[] { item }); } - protected Data getDataStep() { - String value = String.valueOf(distancePanel.getStep()); - String field = getStepField(); + final String value = String.valueOf(this.distancePanel.getStep()); + final String field = getStepField(); - DataItem item = new DefaultDataItem(field, field, value); - return new DefaultData( - field, null, null, new DataItem[] { item }); - } - - - @Override - public void onBlur(BlurEvent event) { - distancePanel.validateForm(); + final DataItem item = new DefaultDataItem(field, field, value); + return new DefaultData(field, null, null, new DataItem[] { item }); } + @Override + public void onBlur(final BlurEvent event) { + this.distancePanel.validateForm(); + } - protected void initMinMaxValues(DataList data) { - Data f = getData(data.getAll(), getLowerField()); - Data t = getData(data.getAll(), getUpperField()); + protected void initMinMaxValues(final DataList data) { + final Data f = getData(data.getAll(), getLowerField()); + final Data t = getData(data.getAll(), getUpperField()); - DataItem[] fItems = f.getItems(); - DataItem[] tItems = t.getItems(); + final DataItem[] fItems = f.getItems(); + final DataItem[] tItems = t.getItems(); try { - min = Double.valueOf(fItems[0].getStringValue()); - max = Double.valueOf(tItems[0].getStringValue()); + this.min = Double.valueOf(fItems[0].getStringValue()); + this.max = Double.valueOf(tItems[0].getStringValue()); } - catch (NumberFormatException nfe) { - min = -Double.MAX_VALUE; - max = Double.MAX_VALUE; + catch (final NumberFormatException nfe) { + this.min = -Double.MAX_VALUE; + this.max = Double.MAX_VALUE; } } - - protected void initDefaultValues(DataList data) { + protected void initDefaultValues(final DataList data) { initDefaultFrom(data); initDefaultTo(data); initDefaultStep(data); } - - protected void initDefaultFrom(DataList data) { - Data f = getData(data.getAll(), getLowerField()); + protected void initDefaultFrom(final DataList data) { + final Data f = getData(data.getAll(), getLowerField()); double from = getDefaultFrom(); try { from = getDefaultValue(f); } - catch (NumberFormatException nfe) { + catch (final NumberFormatException nfe) { // do nothing } - distancePanel.setFrom(from); + this.distancePanel.setFrom(from); } - protected double getDefaultFrom() { - return min; + return this.min; } - - protected void initDefaultTo(DataList data) { - Data t = getData(data.getAll(), getUpperField()); + protected void initDefaultTo(final DataList data) { + final Data t = getData(data.getAll(), getUpperField()); double to = getDefaultTo(); try { to = getDefaultValue(t); } - catch (NumberFormatException nfe) { + catch (final NumberFormatException nfe) { // do nothing } - distancePanel.setTo(to); + this.distancePanel.setTo(to); } - protected double getDefaultTo() { - return max; + return this.max; } - - protected void initDefaultStep(DataList data) { - Data s = getData(data.getAll(), getStepField()); + protected void initDefaultStep(final DataList data) { + final Data s = getData(data.getAll(), getStepField()); double step = getDefaultStep(); try { step = getDefaultValue(s); } - catch (NumberFormatException nfe) { + catch (final NumberFormatException nfe) { // do nothing } - distancePanel.setStep(step); + this.distancePanel.setStep(step); } - protected double getDefaultStep() { return DEFAULT_STEP_WIDTH; } - /** Gets the double from default in data, null if none. */ - protected double getDefaultValue(Data data) - throws NumberFormatException - { - DataItem def = data.getDefault(); - String defValue = def != null ? def.getStringValue() : null; + protected double getDefaultValue(final Data data) throws NumberFormatException { + final DataItem def = data.getDefault(); + final String defValue = def != null ? def.getStringValue() : null; return Double.valueOf(defValue); } - protected void initHelperPanel() { - distancesTable = new RangeTable(); - locationsTable = new LocationsTable(); - - Config config = Config.getInstance(); - String url = config.getServerUrl(); - String river = getRiverName(); + this.distancesTable = new RangeTable(); + this.locationsTable = new LocationsTable(); - distancesTable.setAutoFetchData(true); - locationsTable.setAutoFetchData(true); - distancesTable.setDataSource(new DistanceInfoDataSource( - url, river, "distances")); - locationsTable.setDataSource(new DistanceInfoDataSource( - url, river, "locations")); + final Config config = Config.getInstance(); + final String url = config.getServerUrl(); + final String river = getRiverName(); - distancesTable.addRecordClickHandler(new RecordClickHandler() { + this.distancesTable.setAutoFetchData(true); + this.locationsTable.setAutoFetchData(true); + this.distancesTable.setDataSource(new DistanceInfoDataSource(url, river, "distances")); + this.locationsTable.setDataSource(new DistanceInfoDataSource(url, river, "locations")); + + this.distancesTable.addRecordClickHandler(new RecordClickHandler() { @Override - public void onRecordClick(RecordClickEvent e) { - Record r = e.getRecord(); + public void onRecordClick(final RecordClickEvent e) { + final Record r = e.getRecord(); - String from = r.getAttribute("from"); - String to = r.getAttribute("to"); + final String from = r.getAttribute("from"); + final String to = r.getAttribute("to"); try { - distancePanel.setFrom(Double.valueOf(from)); - distancePanel.setTo(Double.valueOf(to)); - } - catch (NumberFormatException nfe) { - SC.warn(MSG.wrongFormat()); + DistancePanel.this.distancePanel.setFrom(Double.valueOf(from)); + DistancePanel.this.distancePanel.setTo(Double.valueOf(to)); } - } - }); - - locationsTable.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(RecordClickEvent e) { - Record r = e.getRecord(); - int field = e.getFieldNum(); - - try { - String value = r.getAttribute("from"); - - switch (field) { - case 0: - distancePanel.setFrom(Double.valueOf(value)); - break; - case 1: - distancePanel.setTo(Double.valueOf(value)); - break; - } - } - catch (NumberFormatException nfe) { - SC.warn(MSG.wrongFormat()); + catch (final NumberFormatException nfe) { + SC.warn(DistancePanel.this.MSG.wrongFormat()); } } }); - tabs = new TabSet(); - tabs.setWidth100(); - tabs.setHeight100(); - - Tab locations = new Tab(MSG.locations()); - Tab distances = new Tab(MSG.distance()); - - locations.setPane(locationsTable); - distances.setPane(distancesTable); - - tabs.addTab(locations, 0); - tabs.addTab(distances, 1); - - filterResultCount = new StaticTextItem(MSG.resultCount()); - filterResultCount.setTitleAlign(Alignment.LEFT); - filterResultCount.setTitleStyle("color: #000"); + this.locationsTable.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(final RecordClickEvent e) { + final Record r = e.getRecord(); + final int field = e.getFieldNum(); - filterDescription = new TableFilter(); - filterDescription.setHeight("30px"); - filterDescription.addFilterHandler(this); - - filterRange = new RangeTableFilter(); - filterRange.setHeight("30px"); - filterRange.addFilterHandler(this); - filterRange.setVisible(false); + try { + final String value = r.getAttribute("from"); - SelectItem filterCriteria = new SelectItem(); - filterCriteria.setShowTitle(false); - filterCriteria.setWidth(100); - filterCriteria.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent e) { - if(e.getValue().toString().equals("range")) { - filterRange.setVisible(true); - filterDescription.setVisible(false); - filterDescription.clear(); + switch (field) { + case 0: + DistancePanel.this.distancePanel.setFrom(Double.valueOf(value)); + break; + case 1: + DistancePanel.this.distancePanel.setTo(Double.valueOf(value)); + break; + } } - else { - filterRange.setVisible(false); - filterRange.clear(); - filterDescription.setVisible(true); + catch (final NumberFormatException nfe) { + SC.warn(DistancePanel.this.MSG.wrongFormat()); } } }); - LinkedHashMap<String, String> filterMap = - new LinkedHashMap<String, String>(); - filterMap.put("description", MSG.description()); - filterMap.put("range", MSG.range()); - filterCriteria.setValueMap(filterMap); - filterCriteria.setValue("description"); - - DynamicForm form = new DynamicForm(); - form.setFields(filterCriteria); - - DynamicForm form2 = new DynamicForm(); - form2.setFields(filterResultCount); + this.tabs = new TabSet(); + this.tabs.setWidth100(); + this.tabs.setHeight100(); - HLayout filterLayout = new HLayout(); - filterLayout.addMember(form); - filterLayout.addMember(filterDescription); - filterLayout.addMember(filterRange); - filterLayout.setHeight(30); - tabs.addTabSelectedHandler(new TabSelectedHandler() { + final Tab locations = new Tab(this.MSG.locations()); + final Tab distances = new Tab(this.MSG.distance()); + + locations.setPane(this.locationsTable); + distances.setPane(this.distancesTable); + + this.tabs.addTab(locations, 0); + this.tabs.addTab(distances, 1); + + this.filterResultCount = new StaticTextItem(this.MSG.resultCount()); + this.filterResultCount.setTitleAlign(Alignment.LEFT); + this.filterResultCount.setTitleStyle("color: #000"); + + this.filterDescription = new TableFilter(); + this.filterDescription.setHeight("30px"); + this.filterDescription.addFilterHandler(this); + + this.filterRange = new RangeTableFilter(); + this.filterRange.setHeight("30px"); + this.filterRange.addFilterHandler(this); + this.filterRange.setVisible(false); + + final SelectItem filterCriteria = new SelectItem(); + filterCriteria.setShowTitle(false); + filterCriteria.setWidth(100); + filterCriteria.addChangedHandler(new ChangedHandler() { @Override - public void onTabSelected(TabSelectedEvent evt) { - filterDescription.clear(); - filterRange.clear(); - filterResultCount.setValue(""); - - Canvas c = evt.getTabPane(); - if(c instanceof ListGrid) { - currentFiltered = (ListGrid)c; + public void onChanged(final ChangedEvent e) { + if (e.getValue().toString().equals("range")) { + DistancePanel.this.filterRange.setVisible(true); + DistancePanel.this.filterDescription.setVisible(false); + DistancePanel.this.filterDescription.clear(); + } else { + DistancePanel.this.filterRange.setVisible(false); + DistancePanel.this.filterRange.clear(); + DistancePanel.this.filterDescription.setVisible(true); } } }); - helperContainer.addMember(tabs); - helperContainer.addMember(filterLayout); - helperContainer.addMember(form2); + final LinkedHashMap<String, String> filterMap = new LinkedHashMap<String, String>(); + filterMap.put("description", this.MSG.description()); + filterMap.put("range", this.MSG.range()); + filterCriteria.setValueMap(filterMap); + filterCriteria.setValue("description"); + + final DynamicForm form = new DynamicForm(); + form.setFields(filterCriteria); + + final DynamicForm form2 = new DynamicForm(); + form2.setFields(this.filterResultCount); + + final HLayout filterLayout = new HLayout(); + filterLayout.addMember(form); + filterLayout.addMember(this.filterDescription); + filterLayout.addMember(this.filterRange); + filterLayout.setHeight(30); + this.tabs.addTabSelectedHandler(new TabSelectedHandler() { + @Override + public void onTabSelected(final TabSelectedEvent evt) { + DistancePanel.this.filterDescription.clear(); + DistancePanel.this.filterRange.clear(); + DistancePanel.this.filterResultCount.setValue(""); + + final Canvas c = evt.getTabPane(); + if (c instanceof ListGrid) { + DistancePanel.this.currentFiltered = (ListGrid) c; + } + } + }); + + this.helperContainer.addMember(this.tabs); + this.helperContainer.addMember(filterLayout); + this.helperContainer.addMember(form2); } - @Override - public void onFilterCriteriaChanged(StringFilterEvent event) { - String search = event.getFilter(); + public void onFilterCriteriaChanged(final StringFilterEvent event) { + final String search = event.getFilter(); if (search != null && search.length() > 0) { - Criteria c = new Criteria("description", search); - locationsTable.filterData(c); - distancesTable.filterData(c); - filterResultCount.setValue(currentFiltered.getRecords().length); - } - else { - locationsTable.clearCriteria(); - distancesTable.clearCriteria(); - filterResultCount.setValue(""); + final Criteria c = new Criteria("description", search); + this.locationsTable.filterData(c); + this.distancesTable.filterData(c); + this.filterResultCount.setValue(this.currentFiltered.getRecords().length); + } else { + this.locationsTable.clearCriteria(); + this.distancesTable.clearCriteria(); + this.filterResultCount.setValue(""); } } - @Override - public void onFilterCriteriaChanged(RangeFilterEvent event) { - Float from = event.getFrom() - 0.001f; - Float to = event.getTo() + 0.001f; + public void onFilterCriteriaChanged(final RangeFilterEvent event) { + final Float from = event.getFrom() - 0.001f; + final Float to = event.getTo() + 0.001f; Criterion combinedFilter = null; Criterion locationFilter = null; if (from.equals(Float.NaN) && to.equals(Float.NaN)) { - locationsTable.clearCriteria(); - distancesTable.clearCriteria(); - filterResultCount.setValue(""); + this.locationsTable.clearCriteria(); + this.distancesTable.clearCriteria(); + this.filterResultCount.setValue(""); return; } if (from.equals(Float.NaN)) { - combinedFilter = - new Criterion("to", OperatorId.LESS_OR_EQUAL, to); + combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); - locationFilter = - new Criterion("from", OperatorId.LESS_OR_EQUAL, to); + locationFilter = new Criterion("from", OperatorId.LESS_OR_EQUAL, to); - locationsTable.filterData(locationFilter); - distancesTable.filterData(combinedFilter); - filterResultCount.setValue(currentFiltered.getRecords().length); + this.locationsTable.filterData(locationFilter); + this.distancesTable.filterData(combinedFilter); + this.filterResultCount.setValue(this.currentFiltered.getRecords().length); return; } if (to.equals(Float.NaN)) { - combinedFilter = - new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); - } - else { - AdvancedCriteria c1 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), - new Criterion("from", OperatorId.LESS_OR_EQUAL, to) - }); + combinedFilter = new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); + } else { + final AdvancedCriteria c1 = new AdvancedCriteria(OperatorId.AND, + new Criterion[] { new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), new Criterion("from", OperatorId.LESS_OR_EQUAL, to) }); - AdvancedCriteria c2 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), - new Criterion("to", OperatorId.LESS_OR_EQUAL, to) - }); + final AdvancedCriteria c2 = new AdvancedCriteria(OperatorId.AND, + new Criterion[] { new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), new Criterion("to", OperatorId.LESS_OR_EQUAL, to) }); - AdvancedCriteria c3 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("from", OperatorId.LESS_OR_EQUAL, to), - new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) - }); + final AdvancedCriteria c3 = new AdvancedCriteria(OperatorId.AND, + new Criterion[] { new Criterion("from", OperatorId.LESS_OR_EQUAL, to), new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) }); - combinedFilter = - new AdvancedCriteria(OperatorId.OR, new Criterion[] { - c1, c2, c3 - }); + combinedFilter = new AdvancedCriteria(OperatorId.OR, new Criterion[] { c1, c2, c3 }); } - locationsTable.filterData(combinedFilter); - distancesTable.filterData(combinedFilter); - filterResultCount.setValue(currentFiltered.getRecords().length); + this.locationsTable.filterData(combinedFilter); + this.distancesTable.filterData(combinedFilter); + this.filterResultCount.setValue(this.currentFiltered.getRecords().length); } - protected String getRiverName() { - ArtifactDescription adescr = artifact.getArtifactDescription(); + final ArtifactDescription adescr = this.artifact.getArtifactDescription(); return adescr.getRiver(); } }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java Tue May 08 15:21:23 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java Wed May 09 16:31:12 2018 +0200 @@ -8,10 +8,17 @@ package org.dive4elements.river.client.client.ui; +import java.util.List; + +import org.dive4elements.river.client.client.Config; +import org.dive4elements.river.client.client.FLYSConstants; +import org.dive4elements.river.client.client.services.CSVExportService; +import org.dive4elements.river.client.client.services.CSVExportServiceAsync; +import org.dive4elements.river.client.shared.model.DataList; + 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.types.ListGridFieldType; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; @@ -20,26 +27,16 @@ import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.VLayout; -import org.dive4elements.river.client.client.Config; -import org.dive4elements.river.client.client.FLYSConstants; -import org.dive4elements.river.client.client.services.CSVExportService; -import org.dive4elements.river.client.client.services.CSVExportServiceAsync; -import org.dive4elements.river.client.shared.model.DataList; - -import java.util.List; - /** * This UIProvider creates a widget that displays calculated data in a table. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class TableDataPanel -{ +public class TableDataPanel { /** The message class that provides i18n strings. */ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - protected CSVExportServiceAsync exportService = - GWT.create(CSVExportService.class); + protected CSVExportServiceAsync exportService = GWT.create(CSVExportService.class); /** A container that will contain the location or the distance panel. */ protected VLayout container; @@ -53,106 +50,100 @@ /** The table. */ protected ListGrid dataTable; - /** * Creates a new TableDataPanel instance. */ public TableDataPanel() { - container = new VLayout(); - dataTable = new ListGrid(); - name = ""; + this.container = new VLayout(); + this.dataTable = new ListGrid(); + this.name = ""; } - /** * This method creates a widget that contains a table. * * @return a panel. */ public Canvas create() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - dataTable.setEmptyMessage(MESSAGES.empty_table()); - dataTable.setShowHeaderContextMenu(false); - dataTable.setCanDragSelectText(true); + final Config config = Config.getInstance(); + final String locale = config.getLocale(); + this.dataTable.setEmptyMessage(this.MESSAGES.empty_table()); + this.dataTable.setShowHeaderContextMenu(false); + this.dataTable.setCanDragSelectText(true); - exportService.getCSV(locale, uuid, name, - new AsyncCallback<List<String[]>>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not receive csv."); - SC.warn(caught.getMessage()); - } + this.exportService.getCSV(locale, this.uuid, this.name, new AsyncCallback<List<String[]>>() { + @Override + public void onFailure(final Throwable caught) { + GWT.log("Could not receive csv."); + SC.warn(caught.getMessage()); + } - @Override - public void onSuccess(List<String[]> l) { - GWT.log("Recieved csv with " + l.size() + " lines."); - setData(l); - } + @Override + public void onSuccess(final List<String[]> l) { + GWT.log("Recieved csv with " + l.size() + " lines."); + setData(l); } - ); + }); - container.addMember(dataTable); + this.container.addMember(this.dataTable); - return container; + return this.container; } - - public void setName(String name) { - this.name = name; + public void setName(final String name) { + this.name = name; } - public void setUuid(String uuid) { - this.uuid = uuid; + public void setUuid(final String uuid) { + this.uuid = uuid; } - - public Canvas createOld(DataList dataList) { + public Canvas createOld(final DataList dataList) { return null; } - - protected Canvas createWidget(DataList data) { + protected Canvas createWidget(final DataList data) { return null; } - /** * This method sets the data to a dynamic table. * - * @param list List of String[] containing the data. + * @param list + * List of String[] containing the data. */ - public void setData(List<String[]> list) { + public void setData(final List<String[]> list) { if (list == null || list.size() < 2) { - dataTable.setEmptyMessage(MESSAGES.error_no_calc_result()); - dataTable.redraw(); + this.dataTable.setEmptyMessage(this.MESSAGES.error_no_calc_result()); + this.dataTable.redraw(); return; } - Config config = Config.getInstance(); - String locale = config.getLocale(); + final Config config = Config.getInstance(); + final String locale = config.getLocale(); NumberFormat nf; if (locale.equals("de")) { nf = NumberFormat.getFormat("#,##"); - } - else { + } else { nf = NumberFormat.getFormat("#.##"); } - String[] header = list.get(0); - String[] displayField = new String[header.length]; + final String[] header = list.get(0); + final String[] displayField = new String[header.length]; - ListGridField[] fields = new ListGridField[header.length]; + final ListGridField[] fields = new ListGridField[header.length]; - for(int i = 0; i < header.length; i++) { - ListGridField f = new ListGridField(String.valueOf(i)); + for (int i = 0; i < header.length; i++) { + final ListGridField f = new ListGridField(String.valueOf(i)); fields[i] = f; f.setTitle(header[i]); try { - /* Try to determine the type with the first - * non empty element. */ + /* + * Try to determine the type with the first + * non empty element. + */ for (int j = 1; j < list.size(); j++) { if (!list.get(j)[i].isEmpty()) { nf.parse(list.get(j)[i]); @@ -161,7 +152,7 @@ } } } - catch (NumberFormatException nfe) { + catch (final NumberFormatException nfe) { f.setType(ListGridFieldType.TEXT); } @@ -175,28 +166,27 @@ f.setSortByDisplayField(false); } - dataTable.setFields(fields); + this.dataTable.setFields(fields); - for(int i = 1; i < list.size(); i++) { - String[] sItem = list.get(i); - ListGridRecord r = new ListGridRecord(); - for(int j = 0; j < sItem.length; j++) { + for (int i = 1; i < list.size(); i++) { + final String[] sItem = list.get(i); + final ListGridRecord r = new ListGridRecord(); + for (int j = 0; j < sItem.length; j++) { // See above, display 'as is' from server, but keep value // in machine-usable way (float), to allow numeric sorting. r.setAttribute(displayField[j], sItem[j]); if (fields[j].getType() == ListGridFieldType.TEXT) { r.setAttribute(String.valueOf(j), sItem[j]); - } - else { + } else { try { r.setAttribute(String.valueOf(j), nf.parse(sItem[j])); } - catch (NumberFormatException nfe) { + catch (final NumberFormatException nfe) { r.setAttribute(String.valueOf(j), sItem[j]); } } } - dataTable.addData(r); + this.dataTable.addData(r); } } }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Tue May 08 15:21:23 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Wed May 09 16:31:12 2018 +0200 @@ -29,6 +29,7 @@ import org.dive4elements.river.client.client.ui.uinfo.InundationDurLoadEpochPanel; import org.dive4elements.river.client.client.ui.uinfo.LoadSingleEpochPanel; import org.dive4elements.river.client.client.ui.uinfo.LoadSingleYearPanel; +import org.dive4elements.river.client.client.ui.uinfo.VegetationzonesTable; import org.dive4elements.river.client.shared.model.User; /** @@ -77,6 +78,8 @@ return new LinkSelection(); } else if (uiProvider.equals("continue")) { return new ContinuePanel(); + } else if (uiProvider.equals("uinfo.vegetationzones.table")) { + return new VegetationzonesTable(); } else if (uiProvider.equals("wsp_datacage_panel")) { return new WspDatacagePanel(user); } else if (uiProvider.equals("dgm_datacage_panel")) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTable.java Wed May 09 16:31:12 2018 +0200 @@ -0,0 +1,288 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.client.client.ui.uinfo; + +import java.util.ArrayList; +import java.util.List; + +import org.dive4elements.river.client.client.ui.AbstractUIProvider; +import org.dive4elements.river.client.shared.model.Data; +import org.dive4elements.river.client.shared.model.DataItem; +import org.dive4elements.river.client.shared.model.DataList; +import org.dive4elements.river.client.shared.model.DefaultData; +import org.dive4elements.river.client.shared.model.DefaultDataItem; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; +import com.smartgwt.client.widgets.form.validator.IsStringValidator; +import com.smartgwt.client.widgets.form.validator.Validator; +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.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +public class VegetationzonesTable extends AbstractUIProvider { + private static final long serialVersionUID = 1L; + + protected ListGrid elements; + private TextItem vegzone; + private TextItem start; + private TextItem end; + private ListGrid table; + + private TextItem createItem(final String identifier, final String title, final int width, final Validator... validator) { + final TextItem item = new TextItem(identifier, title); + item.setWidth(width); + item.setWrapTitle(false); + item.setValidators(validator);// eigentlich überflüssig, oder? + return item; + } + + public Canvas createWidget(final DataList data) { + + final VLayout root = new VLayout(); + final HLayout input = new HLayout(); + final VLayout tableLayout = new VLayout(); + final HLayout fields = new HLayout(); + final HLayout fields2 = new HLayout(); + final VLayout spacer = new VLayout(); + spacer.setHeight(10); + + final Button add = new Button(this.MSG.add_date()); // TODO: make key more generic or change to more specific + this.elements = new ListGrid(); + + final Label title = new Label(data.get(0).getDescription()); + title.setHeight("35px"); // orig:25 + + this.vegzone = createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), 200, new IsStringValidator()); + this.start = createItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), 40, new IsIntegerValidator()); + this.end = createItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), 40, new IsIntegerValidator()); + + final DynamicForm form1 = new DynamicForm(); + final DynamicForm form2 = new DynamicForm(); + form2.setNumCols(5); + form1.setNumCols(7); + form1.setFields(this.vegzone); + form2.setFields(this.start, this.end); + + add.addClickHandler(new ClickHandler() { + @Override + public void onClick(final ClickEvent ce) { + final String v1 = VegetationzonesTable.this.start.getValueAsString(); + final String v2 = VegetationzonesTable.this.end.getValueAsString(); + final String v3 = VegetationzonesTable.this.vegzone.getValueAsString(); + if (v1 == null || v2 == null || v3 == null) { + return; + } + + final ListGridRecord r = new ListGridRecord(); + r.setAttribute("vegzone", v3); + r.setAttribute("from", v1); + r.setAttribute("to", v2); + VegetationzonesTable.this.elements.addData(r); + } + }); + + final Label sel = new Label(this.MSG.select()); + sel.setHeight(25); + this.elements.setWidth(450); // 185 + this.elements.setHeight(500); // 120 + this.elements.setShowHeaderContextMenu(false); + this.elements.setCanReorderFields(false); + this.elements.setCanSort(false); + this.elements.setCanEdit(false); + final ListGridField vegzone = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label()); + final ListGridField from = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); + final ListGridField to = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to()); + vegzone.setWidth(285); + from.setWidth(70); + to.setWidth(70); + + final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") { + { + setType(ListGridFieldType.ICON); + setIcon(GWT.getHostPageBaseURL() + VegetationzonesTable.this.MSG.removeFeature()); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + } + }; + + this.elements.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if (!event.getField().getName().equals(removeField.getName())) { + return; + } + event.getViewer().removeData(event.getRecord()); + } + }); + + this.elements.setFields(vegzone, from, to, removeField); + + fields.addMember(form1); + fields2.addMember(form2); + // fields2.addMember(add); + + tableLayout.addMember(this.elements); + root.addMember(title); + root.addMember(input); + root.addMember(tableLayout); + root.addMember(spacer); + root.addMember(fields); + root.addMember(fields2); + root.addMember(spacer); + root.addMember(add); + root.addMember(spacer); + root.addMember(spacer); + + return root; + } + + @Override + public Canvas createOld(final DataList dataList) { + final HLayout layout = new HLayout(); + layout.setWidth("400px"); + final VLayout vLayout = new VLayout(); + vLayout.setWidth(130); + final Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + label.setHeight(25); + + final List<Data> items = dataList.getAll(); + final Data str = getData(items, "vegzones"); + final DataItem[] strItems = str.getItems(); + + final String[] entries = strItems[0].getLabel().split(";"); + for (final String entry : entries) { + final String[] vals = entry.split(","); + final Label dateLabel = new Label(vals[0] + " - " + vals[1]); + dateLabel.setHeight(20); + vLayout.addMember(dateLabel); + } + final Canvas back = getBackButton(dataList.getState()); + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + @Override + public Canvas create(final DataList data) { + final VLayout layout = new VLayout(); + final Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + final Canvas submit = getNextButton(); + final Canvas widget = createWidget(data); + + layout.addMember(widget); + layout.addMember(submit); // TODO: SUBMIT + + // fetchSedimentLoadData(); //TODO: feed from database... + + return layout; + } + + private Canvas createHelper() { + this.table = new ListGrid(); + this.table.setShowHeaderContextMenu(false); + this.table.setWidth100(); + this.table.setShowRecordComponents(true); + this.table.setShowRecordComponentsByCell(true); + this.table.setHeight100(); + this.table.setEmptyMessage(this.MSG.empty_table()); + this.table.setCanReorderFields(false); + + /* Input support pins */ + // final String baseUrl = GWT.getHostPageBaseURL(); + // final ListGridField pinFrom = new ListGridField("fromIcon", this.MSG.uinfo_vegetation_zones_from()); + // pinFrom.setWidth(300); + // pinFrom.setType(ListGridFieldType.ICON); + // pinFrom.setCellIcon(baseUrl + this.MSG.markerGreen()); + // + // final ListGridField pinTo = new ListGridField("toIcon", this.MSG.uinfo_vegetation_zones_to()); + // pinTo.setType(ListGridFieldType.ICON); + // pinTo.setWidth(300); + // pinTo.setCellIcon(baseUrl + this.MSG.markerRed()); + // + // pinFrom.addRecordClickHandler(new RecordClickHandler() { + // @Override + // public void onRecordClick(final RecordClickEvent e) { + // final Record r = e.getRecord(); + // VegetationzonesTable.this.vegzone.setValue(r.getAttribute("date")); // date?? + // } + // }); + // + // pinFrom.addRecordClickHandler(new RecordClickHandler() { + // @Override + // public void onRecordClick(final RecordClickEvent e) { + // final Record r = e.getRecord(); + // VegetationzonesTable.this.start.setValue(r.getAttribute("date")); + // } + // }); + // + // pinTo.addRecordClickHandler(new RecordClickHandler() { + // @Override + // public void onRecordClick(final RecordClickEvent e) { + // final Record r = e.getRecord(); + // VegetationzonesTable.this.end.setValue(r.getAttribute("date")); + // } + // }); + // + // final ListGridField date = new ListGridField("date", this.MSG.year()); + // date.setType(ListGridFieldType.TEXT); + // date.setWidth(100); + // + // final ListGridField descr = new ListGridField("description", this.MSG.description()); + // descr.setType(ListGridFieldType.TEXT); + // descr.setWidth("*"); + // + // this.table.setFields(pinFrom, pinTo, date, descr); + return this.table; + } + + @Override + protected Data[] getData() { + final List<Data> data = new ArrayList<Data>(); + + final ListGridRecord[] lgr = this.elements.getRecords(); + if (lgr.length == 0) { + return new Data[0]; + } + String d = ""; + for (final ListGridRecord element : lgr) { + final Record r = element; + d += r.getAttribute("vegzone") + "," + r.getAttribute("from") + "," + r.getAttribute("to"); + d += ";"; + } + + final DataItem item = new DefaultDataItem("vegzones", null, d); // DATA-key + data.add(new DefaultData("vegzones", null, null, new DataItem[] { item })); + return data.toArray(new Data[data.size()]); + } + +}