[PATCH] tab titles from server

Wald Commits scm-commit at wald.intevation.org
Fri Jun 22 11:03:28 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1529658179 -7200
# Node ID f1be005f0c46340d222745433b21c4cd953b2c49
# Parent  9b2e46090099ef304bb8c45d4541ca5b84685eea
tab titles from server

diff -r 9b2e46090099 -r f1be005f0c46 artifacts/src/main/java/org/dive4elements/river/artifacts/common/ExportContextCSV.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/common/ExportContextCSV.java	Thu Jun 21 14:32:11 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/ExportContextCSV.java	Fri Jun 22 11:02:59 2018 +0200
@@ -11,6 +11,8 @@
 
 import java.text.DateFormat;
 import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 import java.util.Locale;
 
@@ -231,4 +233,11 @@
         return type.getPdfHeader(this.context.getMeta());
 
     }
+
+    public void writeTitleForTabs(final String tabTitleMsg, final int colSize) {
+
+        final Collection<String> title = new ArrayList<>(colSize);
+        title.add(msg("export_csv_title") + msg(tabTitleMsg));
+        writeCSVLine(title.toArray(new String[colSize]));
+    }
 }
\ No newline at end of file
diff -r 9b2e46090099 -r f1be005f0c46 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcDetailResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcDetailResult.java	Thu Jun 21 14:32:11 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcDetailResult.java	Fri Jun 22 11:02:59 2018 +0200
@@ -36,17 +36,19 @@
 
     @Override
     protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final CollisionCalculationResults results) {
-        // TODO Auto-generated method stub
-        // final WstInfo wst = result.getWst();
-        // exportContext.writeCSVWaterlevelMetadata(writer, wst);
-        // if hasMetadata...
+
         exportContextCSV.writeBlankLine();
     }
 
     @Override
     public void writeCSVHeader(final ExportContextCSV exportContextCSV, final CollisionCalculationResults results, final RiverInfo river) {
 
-        final Collection<String> header = new ArrayList<>(6);
+        final int colSize = 6;
+        exportContextCSV.writeTitleForTabs("sinfo.export.csv.title.collision.detail", 6); // Voraussetzung für Tabs ist, dass der Titel vor den Headern
+                                                                                          // geschrieben wird.
+        // Das ist etwas doof.
+
+        final Collection<String> header = new ArrayList<>(colSize);
 
         header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station));
         header.add(exportContextCSV.formatCsvHeader(GeneralResultType.date));
@@ -55,7 +57,7 @@
         header.add(exportContextCSV.formatCsvHeader(SInfoResultType.discharge));
         header.add(exportContextCSV.formatCsvHeader(SInfoResultType.dischargeZone));
 
-        exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
+        exportContextCSV.writeCSVLine(header.toArray(new String[colSize]));
     }
 
     @Override
diff -r 9b2e46090099 -r f1be005f0c46 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java	Thu Jun 21 14:32:11 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java	Fri Jun 22 11:02:59 2018 +0200
@@ -40,18 +40,23 @@
         // TODO Auto-generated method stub
         // final WstInfo wst = result.getWst();
         // exportContext.writeCSVWaterlevelMetadata(writer, wst);
+
     }
 
     @Override
     public void writeCSVHeader(final ExportContextCSV exportContextCSV, final CollisionCalculationResults results, final RiverInfo river) {
+        final int colSize = 3;
+        exportContextCSV.writeTitleForTabs("sinfo.export.csv.title.collison.overview", 3); // Voraussetzung für Tabs ist, dass der Titel vor den Headern
+                                                                                           // geschrieben wird.
+        // Das ist etwas doof.
 
-        final Collection<String> header = new ArrayList<>(3);
+        final Collection<String> header = new ArrayList<>(colSize);
 
         header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station));
         header.add(exportContextCSV.formatCsvHeader(SInfoResultType.years));
         header.add(exportContextCSV.formatCsvHeader(SInfoResultType.collisionCount));
 
-        exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
+        exportContextCSV.writeCSVLine(header.toArray(new String[colSize]));
     }
 
     @Override
diff -r 9b2e46090099 -r f1be005f0c46 artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties	Thu Jun 21 14:32:11 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties	Fri Jun 22 11:02:59 2018 +0200
@@ -392,6 +392,7 @@
 chart.beddifference.yaxis.label.heights = Absolute Height [m]
 chart.subtitle.radius = Width of sample window for moving average
 
+export_csv_title = Title: 
 export.csv.header.km = km
 export.csv.header.year = year
 
@@ -1107,6 +1108,8 @@
 sinfo.export.csv.header.infrastructure.height = Infrastrukturh\u00f6he
 infrastructure.height.title = Geod. H\u00f6he 
 
+sinfo.export.csv.title.collision.detail = Detail View
+sinfo.export.csv.title.collison.overview = Overview
 sinfo.export.csv.header.collision.count = Anzahl der Grundber\u00fchrungen
 collision.count.title = Grundber\u00fchrungen {0}
 chart.collision_count.section.yaxis.label = H\u00e4ufigkeit
diff -r 9b2e46090099 -r f1be005f0c46 artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties	Thu Jun 21 14:32:11 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties	Fri Jun 22 11:02:59 2018 +0200
@@ -392,6 +392,7 @@
 chart.beddifference.yaxis.label.heights = Absolute H\u00f6he [{0}]
 chart.subtitle.radius = Fensterbreite f\u00fcr gleitenden Mittelwert
 
+export_csv_title = Titel: 
 export.csv.header.km = km
 export.csv.header.year = Jahr
 
@@ -1107,6 +1108,8 @@
 sinfo.export.csv.header.infrastructure.height = Infrastrukturh\u00f6he
 infrastructure.height.title = Geod. H\u00f6he 
 
+sinfo.export.csv.title.collision.detail = Detailansicht
+sinfo.export.csv.title.collison.overview = \u00dcbersicht
 sinfo.export.csv.header.collision.count = Anzahl der Grundber\u00fchrungen
 collision.count.title = Grundber\u00fchrungen {0}
 chart.collision_count.section.yaxis.label = H\u00e4ufigkeit
diff -r 9b2e46090099 -r f1be005f0c46 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Thu Jun 21 14:32:11 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Fri Jun 22 11:02:59 2018 +0200
@@ -1540,4 +1540,6 @@
     String sinfo_floodduration_export();
 
     String sinfo_floodduration_report();
+
+    String export_csv_title();
 }
\ No newline at end of file
diff -r 9b2e46090099 -r f1be005f0c46 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Thu Jun 21 14:32:11 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Fri Jun 22 11:02:59 2018 +0200
@@ -827,4 +827,5 @@
 
 bundu = Betrieb und Unterhaltung 
 
-chart_settings_export_metadata = Show Meta-Data
\ No newline at end of file
+chart_settings_export_metadata = Show Meta-Data
+export_csv_title = Title: 
\ No newline at end of file
diff -r 9b2e46090099 -r f1be005f0c46 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Thu Jun 21 14:32:11 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Fri Jun 22 11:02:59 2018 +0200
@@ -827,4 +827,5 @@
 
 bundu = Betrieb und Unterhaltung
 
-chart_settings_export_metadata = Metadaten anzeigen
\ No newline at end of file
+chart_settings_export_metadata = Metadaten anzeigen
+export_csv_title = Titel: 
\ No newline at end of file
diff -r 9b2e46090099 -r f1be005f0c46 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java	Thu Jun 21 14:32:11 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java	Fri Jun 22 11:02:59 2018 +0200
@@ -8,8 +8,9 @@
 
 package org.dive4elements.river.client.client.ui;
 
-import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 
 import org.dive4elements.river.client.client.Config;
 import org.dive4elements.river.client.client.FLYSConstants;
@@ -134,20 +135,21 @@
         } else {
             nf = NumberFormat.getFormat("#.##");
         }
-        final List<List<String[]>> tabData = getTabData(list);
+        final Map<String, List<String[]>> tabData = getTabData(list);
         if (tabData.size() == 1) {
-            createTable(this.dataTable, tabData.get(0), nf, 0);
+            createTable(this.dataTable, tabData.get(tabData.keySet().iterator().next()), nf, 0);
 
         } else if (tabData.size() > 1) {
 
-            for (int i = 0; i < tabData.size(); i++) {
-                final List<String[]> items = tabData.get(i);
+            final int index = 0;
+            for (final String key : tabData.keySet()) {
+                final List<String[]> items = tabData.get(key);
 
                 final ListGrid table = new ListGrid();
 
-                createTable(table, items, nf, i);
+                createTable(table, items, nf, index);
                 final Tab tab = new Tab();
-                tab.setTitle("Ergebnis: " + i); // TODO: get Title from Server
+                tab.setTitle(key);
                 tab.setPane(table);
                 this.tabSet.addTab(tab);
             }
@@ -197,7 +199,6 @@
             f.setDisplayField(displayField[i]);
             f.setValueField(String.valueOf(i));
             f.setSortByDisplayField(false);
-
         }
         dataTableTab.setFields(fields);
 
@@ -228,25 +229,51 @@
         }
     }
 
-    private List<List<String[]>> getTabData(final List<String[]> raw) {
-        final List<List<String[]>> tabs = new ArrayList<List<String[]>>();
-        String[] compare = raw.get(0);
-        int lastIndex = 0;
+    private Map<String, List<String[]>> getTabData(final List<String[]> raw) {
+        // Condition: tableTitle must be first
+        final Map<String, List<String[]>> tabs = new TreeMap<String, List<String[]>>(); // auto-sort
 
-        for (int i = 0; i < raw.size(); i++) {
-            final String[] row = raw.get(i);
-            if (compare.length != row.length) {
-                tabs.add(raw.subList(lastIndex, i));
-                lastIndex = i;
+        if (raw.get(0)[0].startsWith(this.MESSAGES.export_csv_title())) {
+            // Bedingung für Tabs
+            int lastIndex = 0;
+            String lastTableTitle = "";
+
+            for (int i = 0; i < raw.size(); i++) {
+
+                final String[] row = raw.get(i);
+                if (row[0].startsWith(this.MESSAGES.export_csv_title())) {
+
+                    if (i > 0) {
+                        tabs.put(makeKeyTitle(lastTableTitle, tabs.size()), raw.subList((lastIndex + 1), (i))); // toIndex exclusive (without
+                                                                                                                // tabTitle-Line of the next tab, which is
+                                                                                                                // stored in the current row (raw.get(i));
+                                                                                                                // fromIndex
+                                                                                                                // inclusive ->
+                                                                                                                // without tabTitle from the past tab ->
+                                                                                                                // lastindex+1
+                    }
+                    lastTableTitle = row[0].replace(this.MESSAGES.export_csv_title(), "");
+                    lastIndex = i;
+                }
+
+                if (i == (raw.size() - 1)) {
+                    tabs.put(makeKeyTitle(lastTableTitle, tabs.size()), raw.subList((lastIndex + 1), i + 1));
+                    // last result-tab:
+                    // toIndex exclusive -> last i + 1
+                    // fromIndex inclusive: lastInde +1 -> no title-line included
+                }
+
             }
-
-            if (i == (raw.size() - 1)) {
-                tabs.add(raw.subList(lastIndex, i + 1)); // toIndex exclusive, fromIndex inclusive
-            }
-            compare = row;
+        } else {
+            // plainOld Table, no TABS
+            tabs.put("", raw);
         }
 
         return tabs;
     }
+
+    private String makeKeyTitle(final String title, final int index) {
+        return new StringBuilder().append("(").append((index + 1)).append(") ").append(title).toString();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4Elements-commits mailing list