# HG changeset patch # User gernotbelger # Date 1534332120 -7200 # Node ID e2da9c8a7c577359a5301c1d1869dd586506cc3f # Parent e511eb935ccd45c6fc91393893cc4e5343226726 VegetationZone umbenennen diff -r e511eb935ccd -r e2da9c8a7c57 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java Tue Aug 14 14:04:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java Wed Aug 15 13:22:00 2018 +0200 @@ -18,7 +18,7 @@ import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.access.RiverAccess; -import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZone; +import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZoneServerClientXChange; import org.dive4elements.river.utils.RiverUtils; /** @@ -49,6 +49,6 @@ final RiverAccess access = new RiverAccess(artifact); - return VegetationZone.parseListToDataString(VegetationZone.getStandardList(access.getRiver(), this.context)); + return VegetationZoneServerClientXChange.parseListToDataString(VegetationZoneServerClientXChange.getStandardList(access.getRiver(), this.context)); } } \ No newline at end of file diff -r e511eb935ccd -r e2da9c8a7c57 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java Tue Aug 14 14:04:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -/** 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 java.util.ArrayList; -import java.util.List; -import java.util.TreeSet; - -import org.dive4elements.artifacts.CallContext; -import org.dive4elements.river.artifacts.resources.Resources; -import org.dive4elements.river.model.River; - -/** - * @author Domenico Nardi Tironi - * - */ -public class VegetationZone implements Comparable { - - // IMMER ABGLEICHEN MIT VegetationZone.class Server und Client - public static final boolean HAS_COLORS_EDITABLE = false; - - private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; - private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; - private final String zoneName; - private final int min_day_overflow; - private final int max_day_overflow; - private final String hexColor; - - public static List parse(final String zonesRaw) { - final List resultList = new ArrayList<>(); - - final List results = new ArrayList<>(); - if (zonesRaw.contains(TABLE_ROW_SEPARATOR)) { - final String[] rows = zonesRaw.split(TABLE_ROW_SEPARATOR); - for (final String row : rows) { - if (row.contains(TABLE_CELL_SEPARATOR)) { - final String[] result = row.split(TABLE_CELL_SEPARATOR); - results.add(result); - } - } - } - for (final String[] zone : results) { - - final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2]), zone[3]); - resultList.add(helper); - } - - return resultList; - } - - public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow, final String hexColor) { - return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow), hexColor); // Error-Handling? - } - - private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow, final String hexColor) { - this.zoneName = zone; - this.min_day_overflow = min_day_overflow; - this.max_day_overflow = max_day_overflow; - this.hexColor = hexColor; - } - - public int getMax_day_overflow() { - return this.max_day_overflow; - } - - public String getZoneName() { - if (this.zoneName == null || this.zoneName.equals("")) { - return "---"; - } - return this.zoneName; - } - - public String getHexColor() { - try { - final int test = Integer.decode(this.hexColor); - return this.hexColor; - } - catch (final NumberFormatException e) { - return "#ffffff"; - } - } - - public int getMin_day_overflow() { - return this.min_day_overflow; - } - - public static final List getStandardList(final River river, final CallContext context) { - - final List list = new ArrayList<>(); - for (final org.dive4elements.river.model.uinfo.VegetationZone vz : org.dive4elements.river.model.uinfo.VegetationZone.getValues(river)) { - final String zn = Resources.getMsg(context.getMeta(), "uinfo_vegetation_type_" + vz.getVegetationType().getId().toString()); - list.add(new VegetationZone(zn, vz.getMin_overflow_days(), vz.getMax_overflow_days(), vz.getColor())); - } - return list; - } - - public static final String parseListToDataString(final List list) { - - java.util.Collections.sort(list); - final StringBuilder builder = new StringBuilder(); - for (final VegetationZone zone : list) { - builder.append(zone.getZoneName()); - builder.append(TABLE_CELL_SEPARATOR); - builder.append(zone.getMin_day_overflow()); - builder.append(TABLE_CELL_SEPARATOR); - builder.append(zone.getMax_day_overflow()); - builder.append(TABLE_CELL_SEPARATOR); - builder.append(zone.getHexColor()); - builder.append(TABLE_ROW_SEPARATOR); - } - return builder.toString(); - - } - - @Override - public int compareTo(final VegetationZone o) { - final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow()); - if (basicCompare == 0) - return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? - - if (basicCompare == 0) { - return 1; // for treeSet - } - - return basicCompare; - } - - public static final boolean zonesAreOverlapping(final List list) { - for (final VegetationZone zone : list) { - for (final VegetationZone zoneOther : list) { - if (zone != zoneOther) { - final boolean overlaps = zone.overlaps(zoneOther); - if (overlaps) { - return overlaps; // cancel. only one zone has to overlap - } - } - } - } - - return false; - } - - public static final boolean hasGaps(final List list, final int lower, final int upper) { - - if ((upper - lower) == 0) - return true; - - final TreeSet treeList = new TreeSet<>(); - treeList.addAll(list); - int lowerCompare = lower; - for (final VegetationZone zone : treeList) { - if (zone.getLowerFromTo() > (lowerCompare + 1)) { // nicht inklusiv - return true; - } - lowerCompare = zone.getUpperFromTo(); - } - if ((lowerCompare) < upper) - return true; // am Ende nicht geschlossen - - return false; - } - - private boolean overlaps(final VegetationZone otherZone) { - final int otherLower = otherZone.getLowerFromTo(); - final int otherUpper = otherZone.getUpperFromTo(); - - final int upper = getUpperFromTo(); - final int lower = getLowerFromTo(); - final int otherSchwerpunkt = (otherLower + otherUpper) / 2; - if ((otherUpper <= upper && otherUpper >= lower)) { - return true; - } else if (otherLower >= lower && otherLower <= upper) { - return true; - } else if (otherSchwerpunkt >= (lower) && otherSchwerpunkt <= (upper)) { - return true; - } - return false; - } - - public Integer getLowerFromTo() { - return this.min_day_overflow < this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow; // Math. is forbidden :-( - } - - public Integer getUpperFromTo() { - return this.min_day_overflow > this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow;// Math. is forbidden :-( - } - -} diff -r e511eb935ccd -r e2da9c8a7c57 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZoneServerClientXChange.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZoneServerClientXChange.java Wed Aug 15 13:22:00 2018 +0200 @@ -0,0 +1,195 @@ +/** 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 java.util.ArrayList; +import java.util.List; +import java.util.TreeSet; + +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.river.artifacts.resources.Resources; +import org.dive4elements.river.model.River; + +/** + * @author Domenico Nardi Tironi + * + */ +public class VegetationZoneServerClientXChange implements Comparable { + + // IMMER ABGLEICHEN MIT VegetationZoneServerClientXChange.class Server und Client + public static final boolean HAS_COLORS_EDITABLE = false; + + private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; + private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; + private final String zoneName; + private final int min_day_overflow; + private final int max_day_overflow; + private final String hexColor; + + public static List parse(final String zonesRaw) { + final List resultList = new ArrayList<>(); + + final List results = new ArrayList<>(); + if (zonesRaw.contains(TABLE_ROW_SEPARATOR)) { + final String[] rows = zonesRaw.split(TABLE_ROW_SEPARATOR); + for (final String row : rows) { + if (row.contains(TABLE_CELL_SEPARATOR)) { + final String[] result = row.split(TABLE_CELL_SEPARATOR); + results.add(result); + } + } + } + for (final String[] zone : results) { + + final VegetationZoneServerClientXChange helper = new VegetationZoneServerClientXChange(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2]), zone[3]); + resultList.add(helper); + } + + return resultList; + } + + public static VegetationZoneServerClientXChange createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow, final String hexColor) { + return new VegetationZoneServerClientXChange(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow), hexColor); // Error-Handling? + } + + private VegetationZoneServerClientXChange(final String zone, final Integer min_day_overflow, final Integer max_day_overflow, final String hexColor) { + this.zoneName = zone; + this.min_day_overflow = min_day_overflow; + this.max_day_overflow = max_day_overflow; + this.hexColor = hexColor; + } + + public int getMax_day_overflow() { + return this.max_day_overflow; + } + + public String getZoneName() { + if (this.zoneName == null || this.zoneName.equals("")) { + return "---"; + } + return this.zoneName; + } + + public String getHexColor() { + try { + final int test = Integer.decode(this.hexColor); + return this.hexColor; + } + catch (final NumberFormatException e) { + return "#ffffff"; + } + } + + public int getMin_day_overflow() { + return this.min_day_overflow; + } + + public static final List getStandardList(final River river, final CallContext context) { + + final List list = new ArrayList<>(); + for (final org.dive4elements.river.model.uinfo.VegetationZone vz : org.dive4elements.river.model.uinfo.VegetationZone.getValues(river)) { + final String zn = Resources.getMsg(context.getMeta(), "uinfo_vegetation_type_" + vz.getVegetationType().getId().toString()); + list.add(new VegetationZoneServerClientXChange(zn, vz.getMin_overflow_days(), vz.getMax_overflow_days(), vz.getColor())); + } + return list; + } + + public static final String parseListToDataString(final List list) { + + java.util.Collections.sort(list); + final StringBuilder builder = new StringBuilder(); + for (final VegetationZoneServerClientXChange zone : list) { + builder.append(zone.getZoneName()); + builder.append(TABLE_CELL_SEPARATOR); + builder.append(zone.getMin_day_overflow()); + builder.append(TABLE_CELL_SEPARATOR); + builder.append(zone.getMax_day_overflow()); + builder.append(TABLE_CELL_SEPARATOR); + builder.append(zone.getHexColor()); + builder.append(TABLE_ROW_SEPARATOR); + } + return builder.toString(); + + } + + @Override + public int compareTo(final VegetationZoneServerClientXChange o) { + final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow()); + if (basicCompare == 0) + return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? + + if (basicCompare == 0) { + return 1; // for treeSet + } + + return basicCompare; + } + + public static final boolean zonesAreOverlapping(final List list) { + for (final VegetationZoneServerClientXChange zone : list) { + for (final VegetationZoneServerClientXChange zoneOther : list) { + if (zone != zoneOther) { + final boolean overlaps = zone.overlaps(zoneOther); + if (overlaps) { + return overlaps; // cancel. only one zone has to overlap + } + } + } + } + + return false; + } + + public static final boolean hasGaps(final List list, final int lower, final int upper) { + + if ((upper - lower) == 0) + return true; + + final TreeSet treeList = new TreeSet<>(); + treeList.addAll(list); + int lowerCompare = lower; + for (final VegetationZoneServerClientXChange zone : treeList) { + if (zone.getLowerFromTo() > (lowerCompare + 1)) { // nicht inklusiv + return true; + } + lowerCompare = zone.getUpperFromTo(); + } + if ((lowerCompare) < upper) + return true; // am Ende nicht geschlossen + + return false; + } + + private boolean overlaps(final VegetationZoneServerClientXChange otherZone) { + final int otherLower = otherZone.getLowerFromTo(); + final int otherUpper = otherZone.getUpperFromTo(); + + final int upper = getUpperFromTo(); + final int lower = getLowerFromTo(); + final int otherSchwerpunkt = (otherLower + otherUpper) / 2; + if ((otherUpper <= upper && otherUpper >= lower)) { + return true; + } else if (otherLower >= lower && otherLower <= upper) { + return true; + } else if (otherSchwerpunkt >= (lower) && otherSchwerpunkt <= (upper)) { + return true; + } + return false; + } + + public Integer getLowerFromTo() { + return this.min_day_overflow < this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow; // Math. is forbidden :-( + } + + public Integer getUpperFromTo() { + return this.min_day_overflow > this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow;// Math. is forbidden :-( + } + +} diff -r e511eb935ccd -r e2da9c8a7c57 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculation.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculation.java Tue Aug 14 14:04:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculation.java Wed Aug 15 13:22:00 2018 +0200 @@ -49,11 +49,11 @@ final RiverInfo riverInfo = new RiverInfo(river); final String zonesRaw = vAccess.getVegZones(); - final List helpers = VegetationZone.parse(zonesRaw); + final List helpers = VegetationZoneServerClientXChange.parse(zonesRaw); final VegetationZonesCalculationResults results = new VegetationZonesCalculationResults(calcModeLabel, user, riverInfo, calcRange); final Collection rows = new ArrayList<>(); - for (final VegetationZone zone : helpers) { + for (final VegetationZoneServerClientXChange zone : helpers) { final ResultRow row2 = ResultRow.create().// putValue(UInfoResultType.vegname, zone.getZoneName()).// putValue(UInfoResultType.vegdauervon, zone.getMin_day_overflow()).// diff -r e511eb935ccd -r e2da9c8a7c57 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculationResult.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculationResult.java Tue Aug 14 14:04:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculationResult.java Wed Aug 15 13:22:00 2018 +0200 @@ -41,7 +41,7 @@ header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegname)); header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegdauervon)); header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegdauerbis)); - if (VegetationZone.HAS_COLORS_EDITABLE) + if (VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE) header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegzone_color)); exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); } @@ -85,7 +85,7 @@ lines.add(context.formatRowValue(row, UInfoResultType.vegname)); lines.add(context.formatRowValue(row, UInfoResultType.vegdauervon)); lines.add(context.formatRowValue(row, UInfoResultType.vegdauerbis)); - if (VegetationZone.HAS_COLORS_EDITABLE) + if (VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE) lines.add(context.formatRowValue(row, UInfoResultType.vegzone_color)); return lines.toArray(new String[lines.size()]); } diff -r e511eb935ccd -r e2da9c8a7c57 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableEditState.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableEditState.java Tue Aug 14 14:04:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableEditState.java Wed Aug 15 13:22:00 2018 +0200 @@ -40,7 +40,7 @@ final Element value = ProtocolUtils.createArtNode(cr, "value", null, null); final D4EArtifact flys = (D4EArtifact) artifact; final River river = new RiverAccess(flys).getRiver(); - final String s = flys.getDataAsString(datakey) == null ? VegetationZone.parseListToDataString(VegetationZone.getStandardList(river, context)) + final String s = flys.getDataAsString(datakey) == null ? VegetationZoneServerClientXChange.parseListToDataString(VegetationZoneServerClientXChange.getStandardList(river, context)) : flys.getDataAsString(datakey); value.setTextContent(s); diff -r e511eb935ccd -r e2da9c8a7c57 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableState.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableState.java Tue Aug 14 14:04:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableState.java Wed Aug 15 13:22:00 2018 +0200 @@ -41,7 +41,7 @@ final Element value = ProtocolUtils.createArtNode(cr, "value", null, null); final D4EArtifact flys = (D4EArtifact) artifact; final River river = new RiverAccess(flys).getRiver(); - final String s = flys.getDataAsString(datakey) == null ? VegetationZone.parseListToDataString(VegetationZone.getStandardList(river, context)) + final String s = flys.getDataAsString(datakey) == null ? VegetationZoneServerClientXChange.parseListToDataString(VegetationZoneServerClientXChange.getStandardList(river, context)) : flys.getDataAsString(datakey); value.setTextContent(s); diff -r e511eb935ccd -r e2da9c8a7c57 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java Tue Aug 14 14:04:01 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java Wed Aug 15 13:22:00 2018 +0200 @@ -20,7 +20,7 @@ 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 org.dive4elements.river.client.shared.model.VegetationZone; +import org.dive4elements.river.client.shared.model.VegetationZoneServerClientXChange; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Label; @@ -172,7 +172,7 @@ toField.setCanEdit(true);// neue Anforderung - doch nicht? final ListGridField colorField = new ListGridField("color", this.MSG.uinfo_vegetation_zone_color()); - colorField.setHidden(VegetationZone.HAS_COLORS_EDITABLE ? false : true); + colorField.setHidden(VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE ? false : true); final ColorItem item = new ColorItem(); colorField.setEditorProperties(item); @@ -252,8 +252,8 @@ for (final ListGridRecord r : this.elements.getRecords()) { this.elements.removeData(r); } - final List rows = VegetationZone.parse(data); - for (final VegetationZone row : rows) { + final List rows = VegetationZoneServerClientXChange.parse(data); + for (final VegetationZoneServerClientXChange row : rows) { this.elements.addData(createEntry(row)); } } @@ -295,9 +295,9 @@ final Data str = getData(items, datakey); final DataItem[] strItems = str.getItems(); - final List entries = VegetationZone.parse(strItems[0].getLabel()); + final List entries = VegetationZoneServerClientXChange.parse(strItems[0].getLabel()); - for (final VegetationZone entry : entries) { + for (final VegetationZoneServerClientXChange entry : entries) { final Label dateLabel = new Label(entry.getZoneName() + " (" + entry.getMin_day_overflow() + "-" + entry.getMax_day_overflow() + ")"); dateLabel.setHeight("20px"); vLayout.addMember(dateLabel); @@ -319,23 +319,23 @@ return new Data[0]; // TODO: Klären, ob Vegetationszonen-Auswahl Pflicht ist, ob es ein Fallback geben soll usw. } - final DataItem item = new DefaultDataItem(datakey, null, VegetationZone.parseListToDataString(getZones(lgr))); // DATA-key + final DataItem item = new DefaultDataItem(datakey, null, VegetationZoneServerClientXChange.parseListToDataString(getZones(lgr))); // DATA-key data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); return data.toArray(new Data[data.size()]); } - protected final List getZones(final ListGridRecord[] lgr) { - final List zoneList = new ArrayList(); + protected final List getZones(final ListGridRecord[] lgr) { + final List zoneList = new ArrayList(); for (final ListGridRecord element : lgr) { final Record r = element; - final VegetationZone zone = VegetationZone.createFromTableEntry(r.getAttribute("vegzone"), r.getAttribute("from"), r.getAttribute("to"), + final VegetationZoneServerClientXChange zone = VegetationZoneServerClientXChange.createFromTableEntry(r.getAttribute("vegzone"), r.getAttribute("from"), r.getAttribute("to"), r.getAttribute("color")); zoneList.add(zone); } return zoneList; } - public final ListGridRecord createEntry(final VegetationZone row) { + public final ListGridRecord createEntry(final VegetationZoneServerClientXChange row) { final String vegzone = row.getZoneName(); final Integer from = row.getMin_day_overflow(); @@ -386,9 +386,9 @@ public final List validate() { final List errors = new ArrayList(); - if (VegetationZone.zonesAreOverlapping(this.getZones(this.elements.getRecords()))) + if (VegetationZoneServerClientXChange.zonesAreOverlapping(this.getZones(this.elements.getRecords()))) errors.add(this.MSG.uinfo_vegetation_zone_overlap()); - if (VegetationZone.hasGaps(this.getZones(this.elements.getRecords()), 0, 365)) + if (VegetationZoneServerClientXChange.hasGaps(this.getZones(this.elements.getRecords()), 0, 365)) errors.add(this.MSG.uinfo_vegetation_zone_has_gaps()); return errors; } diff -r e511eb935ccd -r e2da9c8a7c57 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java Tue Aug 14 14:04:01 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java Wed Aug 15 13:22:00 2018 +0200 @@ -10,7 +10,7 @@ import org.dive4elements.river.client.client.ui.PanelHelper; import org.dive4elements.river.client.shared.model.DataList; -import org.dive4elements.river.client.shared.model.VegetationZone; +import org.dive4elements.river.client.shared.model.VegetationZoneServerClientXChange; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -59,7 +59,7 @@ final DynamicForm form1 = new DynamicForm(); form1.setNumCols(4); // für Layout untereinander muss 2 eingestellt werden - if (VegetationZone.HAS_COLORS_EDITABLE) + if (VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE) form1.setFields(this.vegzone, this.start, this.end, colorPicker); else form1.setFields(this.vegzone, this.start, this.end); @@ -73,7 +73,7 @@ // REMARK: can't use 'ternary operator' here, becuae gwt (or java 6?) doesnt like it. final String v4; - if (VegetationZone.HAS_COLORS_EDITABLE) + if (VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE) v4 = colorPicker.getValueAsString(); else v4 = "#ffffff"; diff -r e511eb935ccd -r e2da9c8a7c57 gwt-client/src/main/java/org/dive4elements/river/client/shared/model/VegetationZone.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/VegetationZone.java Tue Aug 14 14:04:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -/** 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.client.shared.model; - -import java.util.ArrayList; -import java.util.List; -import java.util.TreeSet; - -/** - * @author Domenico Nardi Tironi - * - */ -public class VegetationZone implements Comparable { - - // IMMER ABGLEICHEN MIT VegetationZone.class IM SERVER - public static final boolean HAS_COLORS_EDITABLE = false; - - private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; - private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; - private final String zoneName; - private final int min_day_overflow; - private final int max_day_overflow; - private final String hexColor; - - public static List parse(final String zonesRaw) { - final List resultList = new ArrayList(); - - final List results = new ArrayList(); - if (zonesRaw.contains(TABLE_ROW_SEPARATOR)) { - final String[] rows = zonesRaw.split(TABLE_ROW_SEPARATOR); - for (final String row : rows) { - if (row.contains(TABLE_CELL_SEPARATOR)) { - final String[] result = row.split(TABLE_CELL_SEPARATOR); - results.add(result); - } - } - } - for (final String[] zone : results) { - - final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2]), zone[3]); - resultList.add(helper); - } - - return resultList; - } - - public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow, final String hexColor) { - return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow), hexColor); // Error-Handling? - } - - private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow, final String hexColor) { - this.zoneName = zone; - this.min_day_overflow = min_day_overflow; - this.max_day_overflow = max_day_overflow; - this.hexColor = hexColor; - } - - public int getMax_day_overflow() { - return this.max_day_overflow; - } - - public String getZoneName() { - if (this.zoneName == null || this.zoneName.equals("")) { - return "---"; - } - return this.zoneName; - } - - public String getHexColor() { - try { - final int test = Integer.decode(this.hexColor); - return this.hexColor; - } - catch (final NumberFormatException e) { - return "#ffffff"; - } - } - - public int getMin_day_overflow() { - return this.min_day_overflow; - } - - public static final List getStandardList() { - - final List list = new ArrayList(); - list.add(new VegetationZone("Zonaler Wald", 0, 5, "#336600")); - list.add(new VegetationZone("Hartholzaue, trocken", 6, 40, "#00cc00")); - list.add(new VegetationZone("Hartholzaue, feucht", 41, 80, "#66ff33")); - list.add(new VegetationZone("Silberweidenwald", 81, 140, "#008080")); - list.add(new VegetationZone("Weidengebüsch", 141, 200, "#33cccc")); - list.add(new VegetationZone("Uferröhricht", 201, 260, "#ffa8ff")); - list.add(new VegetationZone("Uferpioniere", 261, 320, "#ff0000")); - list.add(new VegetationZone("Vegetationslos", 321, 364, "#b2b2b2")); - list.add(new VegetationZone("Wasserfläche", 365, 365, "#0066ff")); - - return list; - } - - public static final String parseListToDataString(final List list) { - - java.util.Collections.sort(list); - final StringBuilder builder = new StringBuilder(); - for (final VegetationZone zone : list) { - builder.append(zone.getZoneName()); - builder.append(TABLE_CELL_SEPARATOR); - builder.append(zone.getMin_day_overflow()); - builder.append(TABLE_CELL_SEPARATOR); - builder.append(zone.getMax_day_overflow()); - builder.append(TABLE_CELL_SEPARATOR); - builder.append(zone.getHexColor()); - builder.append(TABLE_ROW_SEPARATOR); - } - return builder.toString(); - - } - - @Override - public int compareTo(final VegetationZone o) { - final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow()); - if (basicCompare == 0) - return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? - - if (basicCompare == 0) { - return 1; // for treeSet - } - - return basicCompare; - } - - public static final boolean zonesAreOverlapping(final List list) { - for (final VegetationZone zone : list) { - for (final VegetationZone zoneOther : list) { - if (zone != zoneOther) { - final boolean overlaps = zone.overlaps(zoneOther); - if (overlaps) { - return overlaps; // cancel. only one zone has to overlap - } - } - } - } - - return false; - } - - public static final boolean hasGaps(final List list, final int lower, final int upper) { - - if ((upper - lower) == 0) - return true; - - final TreeSet treeList = new TreeSet(); - treeList.addAll(list); - int lowerCompare = lower; - for (final VegetationZone zone : treeList) { - if (zone.getLowerFromTo() > (lowerCompare + 1)) { // nicht inklusiv - return true; - } - lowerCompare = zone.getUpperFromTo(); - } - if ((lowerCompare) < upper) - return true; // am Ende nicht geschlossen - - return false; - } - - private boolean overlaps(final VegetationZone otherZone) { - final int otherLower = otherZone.getLowerFromTo(); - final int otherUpper = otherZone.getUpperFromTo(); - - final int upper = getUpperFromTo(); - final int lower = getLowerFromTo(); - final int otherSchwerpunkt = (otherLower + otherUpper) / 2; - if ((otherUpper <= upper && otherUpper >= lower)) { - return true; - } else if (otherLower >= lower && otherLower <= upper) { - return true; - } else if (otherSchwerpunkt >= (lower) && otherSchwerpunkt <= (upper)) { - return true; - } - return false; - } - - public Integer getLowerFromTo() { - return this.min_day_overflow < this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow; // Math. is forbidden :-( - } - - public Integer getUpperFromTo() { - return this.min_day_overflow > this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow;// Math. is forbidden :-( - } - -} \ No newline at end of file diff -r e511eb935ccd -r e2da9c8a7c57 gwt-client/src/main/java/org/dive4elements/river/client/shared/model/VegetationZoneServerClientXChange.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/VegetationZoneServerClientXChange.java Wed Aug 15 13:22:00 2018 +0200 @@ -0,0 +1,198 @@ +/** 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.client.shared.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.TreeSet; + +/** + * @author Domenico Nardi Tironi + * + */ +public class VegetationZoneServerClientXChange implements Comparable { + + // IMMER ABGLEICHEN MIT VegetationZoneServerClientXChange.class IM SERVER + public static final boolean HAS_COLORS_EDITABLE = false; + + private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; + private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; + private final String zoneName; + private final int min_day_overflow; + private final int max_day_overflow; + private final String hexColor; + + public static List parse(final String zonesRaw) { + final List resultList = new ArrayList(); + + final List results = new ArrayList(); + if (zonesRaw.contains(TABLE_ROW_SEPARATOR)) { + final String[] rows = zonesRaw.split(TABLE_ROW_SEPARATOR); + for (final String row : rows) { + if (row.contains(TABLE_CELL_SEPARATOR)) { + final String[] result = row.split(TABLE_CELL_SEPARATOR); + results.add(result); + } + } + } + for (final String[] zone : results) { + + final VegetationZoneServerClientXChange helper = new VegetationZoneServerClientXChange(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2]), zone[3]); + resultList.add(helper); + } + + return resultList; + } + + public static VegetationZoneServerClientXChange createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow, final String hexColor) { + return new VegetationZoneServerClientXChange(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow), hexColor); // Error-Handling? + } + + private VegetationZoneServerClientXChange(final String zone, final Integer min_day_overflow, final Integer max_day_overflow, final String hexColor) { + this.zoneName = zone; + this.min_day_overflow = min_day_overflow; + this.max_day_overflow = max_day_overflow; + this.hexColor = hexColor; + } + + public int getMax_day_overflow() { + return this.max_day_overflow; + } + + public String getZoneName() { + if (this.zoneName == null || this.zoneName.equals("")) { + return "---"; + } + return this.zoneName; + } + + public String getHexColor() { + try { + final int test = Integer.decode(this.hexColor); + return this.hexColor; + } + catch (final NumberFormatException e) { + return "#ffffff"; + } + } + + public int getMin_day_overflow() { + return this.min_day_overflow; + } + + public static final List getStandardList() { + + final List list = new ArrayList(); + list.add(new VegetationZoneServerClientXChange("Zonaler Wald", 0, 5, "#336600")); + list.add(new VegetationZoneServerClientXChange("Hartholzaue, trocken", 6, 40, "#00cc00")); + list.add(new VegetationZoneServerClientXChange("Hartholzaue, feucht", 41, 80, "#66ff33")); + list.add(new VegetationZoneServerClientXChange("Silberweidenwald", 81, 140, "#008080")); + list.add(new VegetationZoneServerClientXChange("Weidengebüsch", 141, 200, "#33cccc")); + list.add(new VegetationZoneServerClientXChange("Uferröhricht", 201, 260, "#ffa8ff")); + list.add(new VegetationZoneServerClientXChange("Uferpioniere", 261, 320, "#ff0000")); + list.add(new VegetationZoneServerClientXChange("Vegetationslos", 321, 364, "#b2b2b2")); + list.add(new VegetationZoneServerClientXChange("Wasserfläche", 365, 365, "#0066ff")); + + return list; + } + + public static final String parseListToDataString(final List list) { + + java.util.Collections.sort(list); + final StringBuilder builder = new StringBuilder(); + for (final VegetationZoneServerClientXChange zone : list) { + builder.append(zone.getZoneName()); + builder.append(TABLE_CELL_SEPARATOR); + builder.append(zone.getMin_day_overflow()); + builder.append(TABLE_CELL_SEPARATOR); + builder.append(zone.getMax_day_overflow()); + builder.append(TABLE_CELL_SEPARATOR); + builder.append(zone.getHexColor()); + builder.append(TABLE_ROW_SEPARATOR); + } + return builder.toString(); + + } + + @Override + public int compareTo(final VegetationZoneServerClientXChange o) { + final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow()); + if (basicCompare == 0) + return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? + + if (basicCompare == 0) { + return 1; // for treeSet + } + + return basicCompare; + } + + public static final boolean zonesAreOverlapping(final List list) { + for (final VegetationZoneServerClientXChange zone : list) { + for (final VegetationZoneServerClientXChange zoneOther : list) { + if (zone != zoneOther) { + final boolean overlaps = zone.overlaps(zoneOther); + if (overlaps) { + return overlaps; // cancel. only one zone has to overlap + } + } + } + } + + return false; + } + + public static final boolean hasGaps(final List list, final int lower, final int upper) { + + if ((upper - lower) == 0) + return true; + + final TreeSet treeList = new TreeSet(); + treeList.addAll(list); + int lowerCompare = lower; + for (final VegetationZoneServerClientXChange zone : treeList) { + if (zone.getLowerFromTo() > (lowerCompare + 1)) { // nicht inklusiv + return true; + } + lowerCompare = zone.getUpperFromTo(); + } + if ((lowerCompare) < upper) + return true; // am Ende nicht geschlossen + + return false; + } + + private boolean overlaps(final VegetationZoneServerClientXChange otherZone) { + final int otherLower = otherZone.getLowerFromTo(); + final int otherUpper = otherZone.getUpperFromTo(); + + final int upper = getUpperFromTo(); + final int lower = getLowerFromTo(); + final int otherSchwerpunkt = (otherLower + otherUpper) / 2; + if ((otherUpper <= upper && otherUpper >= lower)) { + return true; + } else if (otherLower >= lower && otherLower <= upper) { + return true; + } else if (otherSchwerpunkt >= (lower) && otherSchwerpunkt <= (upper)) { + return true; + } + return false; + } + + public Integer getLowerFromTo() { + return this.min_day_overflow < this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow; // Math. is forbidden :-( + } + + public Integer getUpperFromTo() { + return this.min_day_overflow > this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow;// Math. is forbidden :-( + } + +} \ No newline at end of file