changeset 9523:d421c2bf0195

Allow to edit colors in vegetation zones
author gernotbelger
date Mon, 01 Oct 2018 17:08:50 +0200
parents 23d97d60b889
children 9dc6427059b2
files artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZoneServerClientXChange.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculationResult.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java gwt-client/src/main/java/org/dive4elements/river/client/shared/model/VegetationZoneServerClientXChange.java
diffstat 5 files changed, 61 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZoneServerClientXChange.java	Mon Oct 01 16:37:12 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZoneServerClientXChange.java	Mon Oct 01 17:08:50 2018 +0200
@@ -26,13 +26,17 @@
 public class VegetationZoneServerClientXChange implements Comparable<VegetationZoneServerClientXChange> {
 
     // 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<VegetationZoneServerClientXChange> parse(final String zonesRaw) {
@@ -50,14 +54,16 @@
         }
         for (final String[] zone : results) {
 
-            final VegetationZoneServerClientXChange helper = new VegetationZoneServerClientXChange(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2]), zone[3]);
+            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) {
+    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?
     }
 
@@ -81,10 +87,12 @@
 
     public String getHexColor() {
         try {
-            final int test = Integer.decode(this.hexColor);
+            // REMARK: only return valid colors
+            Integer.decode(this.hexColor);
             return this.hexColor;
         }
         catch (final NumberFormatException e) {
+            e.printStackTrace();
             return "#ffffff";
         }
     }
@@ -162,7 +170,7 @@
         treeList.addAll(list);
         int lowerCompare = lower;
         for (final VegetationZoneServerClientXChange zone : treeList) {
-            if (zone.getLowerFromTo() > (lowerCompare + 1)) { // nicht inklusiv
+            if (zone.getLowerFromTo() > (lowerCompare)) { // nicht inklusiv
                 return true;
             }
             lowerCompare = zone.getUpperFromTo();
@@ -179,12 +187,11 @@
 
         final int upper = getUpperFromTo();
         final int lower = getLowerFromTo();
-        final int otherSchwerpunkt = (otherLower + otherUpper) / 2;
-        if ((otherUpper <= upper && otherUpper >= lower)) {
+        if ((otherUpper <= upper && otherUpper > lower)) {
             return true;
-        } else if (otherLower >= lower && otherLower <= upper) {
+        } else if (otherLower >= lower && otherLower < upper) {
             return true;
-        } else if (otherSchwerpunkt >= (lower) && otherSchwerpunkt <= (upper)) {
+        } else if (otherLower == lower && otherUpper == upper) {
             return true;
         }
         return false;
@@ -197,5 +204,4 @@
     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
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculationResult.java	Mon Oct 01 16:37:12 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCalculationResult.java	Mon Oct 01 17:08:50 2018 +0200
@@ -25,6 +25,7 @@
  * @author Domenico Nardi Tironi
  */
 final class VegetationZonesCalculationResult extends AbstractCalculationExportableResult {
+
     private static final long serialVersionUID = 1L;
 
     private static final String JASPER_FILE = "/jasper/templates/uinfo.vegetationzones.jrxml";
@@ -41,8 +42,7 @@
         header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegname));
         header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegdauervon));
         header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegdauerbis));
-        if (VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE)
-            header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegzone_color));
+        header.add(exportContextCSV.formatCsvHeader(UInfoResultType.vegzone_color));
         exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
     }
 
@@ -85,9 +85,8 @@
         lines.add(context.formatRowValue(row, UInfoResultType.vegname));
         lines.add(context.formatRowValue(row, UInfoResultType.vegdauervon));
         lines.add(context.formatRowValue(row, UInfoResultType.vegdauerbis));
-        if (VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE)
-            lines.add(context.formatRowValue(row, UInfoResultType.vegzone_color));
+        lines.add(context.formatRowValue(row, UInfoResultType.vegzone_color));
+
         return lines.toArray(new String[lines.size()]);
     }
-
 }
\ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java	Mon Oct 01 16:37:12 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java	Mon Oct 01 17:08:50 2018 +0200
@@ -172,7 +172,6 @@
         toField.setCanEdit(true);// neue Anforderung - doch nicht?
 
         final ListGridField colorField = new ListGridField("color", this.MSG.uinfo_vegetation_zone_color());
-        colorField.setHidden(VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE ? false : true);
         final ColorItem item = new ColorItem();
         colorField.setEditorProperties(item);
 
@@ -188,7 +187,7 @@
         if (editable) {
             final ListGridField removeField = PanelHelper.createRemoveField(this.elements, GWT.getHostPageBaseURL() + this.MSG.removeFeature());
             this.elements.addRecordClickHandler(new RecordClickHandler() { // adding another custom record-Remove-Handler which is not included in the
-                                                                           // Panelhelper TODO: MERGE WITH SupraRegionalPanel!!
+                // Panelhelper TODO: MERGE WITH SupraRegionalPanel!!
                 @Override
                 public void onRecordClick(final RecordClickEvent event) {
                     if (event.getField().getName().equals(removeField.getName())) {
@@ -341,9 +340,9 @@
         final Integer from = row.getMin_day_overflow();
         final Integer to = row.getMax_day_overflow();
         final String colorStr = row.getHexColor();
-        if (vegzone == null || from == null || to == null) {
+
+        if (vegzone == null)
             return null;
-        }
 
         final ListGridRecord r = new ListGridRecord();
         r.setAttribute("vegzone", vegzone);
@@ -377,7 +376,7 @@
 
             return null;
         }
-        catch (final NumberFormatException e) {
+        catch (@SuppressWarnings("unused") final NumberFormatException e) {
             return this.MSG.error_invalid_integer();
         }
     }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java	Mon Oct 01 16:37:12 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java	Mon Oct 01 17:08:50 2018 +0200
@@ -10,7 +10,6 @@
 
 import org.dive4elements.river.client.client.ui.PanelHelper;
 import org.dive4elements.river.client.shared.model.DataList;
-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,43 +58,13 @@
         final DynamicForm form1 = new DynamicForm();
 
         form1.setNumCols(4); // für Layout untereinander muss 2 eingestellt werden
-        if (VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE)
-            form1.setFields(this.vegzone, this.start, this.end, colorPicker);
-        else
-            form1.setFields(this.vegzone, this.start, this.end);
+        form1.setFields(this.vegzone, this.start, this.end, colorPicker);
 
         add.addClickHandler(new ClickHandler() {
             @Override
             public void onClick(final ClickEvent ce) {
-                final String v1 = VegetationzonesTableEditPanel.this.start.getValueAsString();
-                final String v2 = VegetationzonesTableEditPanel.this.end.getValueAsString();
-                final String v3 = VegetationzonesTableEditPanel.this.vegzone.getValueAsString();
-                
-                // REMARK: can't use 'ternary operator' here, becuae gwt (or java 6?) doesnt like it.
-                final String v4;
-                if (VegetationZoneServerClientXChange.HAS_COLORS_EDITABLE)
-                    v4 = colorPicker.getValueAsString();
-                else
-                    v4 = "#ffffff";
-                
-                final String message = validate(v1, v2, v3, v4);
-                if (message != null) {
-                    SC.warn(message);
-                    return;
-                }
 
-                final ListGridRecord r = new ListGridRecord();
-                r.setAttribute("vegzone", v3);
-                r.setAttribute("from", v1);
-                r.setAttribute("to", v2);
-                r.setAttribute("color", v4);
-                elements.addData(r);
-                updateValidationMsgLabel();
-                final String sortField = elements.getSortField();
-                if (sortField != null) {
-                    elements.toggleSort(sortField);
-                    elements.toggleSort(sortField); // HACK. has to be. otherwise normalizer won't be called :-(
-                }
+                handleAddClicked(elements, colorPicker);
             }
         });
 
@@ -105,9 +74,34 @@
         root.addMember(add);
     }
 
+    protected void handleAddClicked(final ListGrid elements, final ColorItem colorPicker) {
+        final String v1 = VegetationzonesTableEditPanel.this.start.getValueAsString();
+        final String v2 = VegetationzonesTableEditPanel.this.end.getValueAsString();
+        final String v3 = VegetationzonesTableEditPanel.this.vegzone.getValueAsString();
+        final String v4 = colorPicker.getValueAsString();
+
+        final String message = validate(v1, v2, v3, v4);
+        if (message != null) {
+            SC.warn(message);
+            return;
+        }
+
+        final ListGridRecord r = new ListGridRecord();
+        r.setAttribute("vegzone", v3);
+        r.setAttribute("from", v1);
+        r.setAttribute("to", v2);
+        r.setAttribute("color", v4);
+        elements.addData(r);
+        updateValidationMsgLabel();
+        final String sortField = elements.getSortField();
+        if (sortField != null) {
+            elements.toggleSort(sortField);
+            elements.toggleSort(sortField); // HACK. has to be. otherwise normalizer won't be called :-(
+        }
+    }
+
     @Override
     protected Canvas createHelper(final DataList data) {
         return null;
     }
-
 }
\ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/VegetationZoneServerClientXChange.java	Mon Oct 01 16:37:12 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/VegetationZoneServerClientXChange.java	Mon Oct 01 17:08:50 2018 +0200
@@ -7,7 +7,6 @@
  * 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;
@@ -21,13 +20,17 @@
 public class VegetationZoneServerClientXChange implements Comparable<VegetationZoneServerClientXChange> {
 
     // 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<VegetationZoneServerClientXChange> parse(final String zonesRaw) {
@@ -78,10 +81,12 @@
 
     public String getHexColor() {
         try {
-            final int test = Integer.decode(this.hexColor);
+            // REMARK: only return valid colors
+            Integer.decode(this.hexColor);
             return this.hexColor;
         }
         catch (final NumberFormatException e) {
+            e.printStackTrace();
             return "#ffffff";
         }
     }
@@ -90,22 +95,6 @@
         return this.min_day_overflow;
     }
 
-    public static final List<VegetationZoneServerClientXChange> getStandardList() {
-
-        final List<VegetationZoneServerClientXChange> list = new ArrayList<VegetationZoneServerClientXChange>();
-        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<VegetationZoneServerClientXChange> list) {
 
         java.util.Collections.sort(list);
@@ -178,7 +167,6 @@
 
         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) {
@@ -196,5 +184,4 @@
     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

http://dive4elements.wald.intevation.org