changeset 9611:8ed6c45136fa

#20 UI
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Wed, 09 Oct 2019 15:58:46 +0200
parents 020d4a595205
children f8308db94634
files artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodInfrastructure.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/FloodInfrastructurePanel.java
diffstat 3 files changed, 323 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodInfrastructure.java	Wed Oct 09 15:58:46 2019 +0200
@@ -0,0 +1,29 @@
+/* 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.artifacts.sinfo.flood_duration;
+
+import org.dive4elements.river.artifacts.states.DefaultState;
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class FloodInfrastructure extends DefaultState {
+
+    private static final long serialVersionUID = 1L;
+
+    protected final String getDatakey() {
+        return "flood_infrastructure";
+    }
+
+    @Override
+    protected String getUIProvider() {
+
+        return "flood_infrastructure_panel";
+    }
+}
\ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Wed Oct 09 15:47:38 2019 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Wed Oct 09 15:58:46 2019 +0200
@@ -31,6 +31,7 @@
 import org.dive4elements.river.client.client.ui.sinfo.CollisionLoadEpochPanel;
 import org.dive4elements.river.client.client.ui.sinfo.CollisionLoadYearPanel;
 import org.dive4elements.river.client.client.ui.sinfo.DiffPairTwinPanel;
+import org.dive4elements.river.client.client.ui.sinfo.FloodInfrastructurePanel;
 import org.dive4elements.river.client.client.ui.sinfo.FlowDepthMinMaxTwinPanel;
 import org.dive4elements.river.client.client.ui.sq.SQPeriodPanel;
 import org.dive4elements.river.client.client.ui.uinfo.InundationWMSInputPanel;
@@ -241,6 +242,8 @@
             return new StaticDataPanel();
         } else if (uiProvider.equals("uinfo.salix.supraregional.table")) {
             return new SupraRegionalTablePanel();
+        } else if (uiProvider.equals("flood_infrastructure_panel")) {
+            return new FloodInfrastructurePanel(user);
         } else if ("sinfo_flowdepth_development_twin_panel".equals(uiProvider))
             return new DiffPairTwinPanel(user, 1, getMSG().sinfo_flow_depth_development_twin_panel_max_count_msg(), true);// if switched here, also switch on
                                                                                                                           // server side
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/FloodInfrastructurePanel.java	Wed Oct 09 15:58:46 2019 +0200
@@ -0,0 +1,291 @@
+/** 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.client.ui.sinfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.dive4elements.river.client.client.ui.AbstractUIProvider;
+import org.dive4elements.river.client.client.ui.DatacageWidget;
+import org.dive4elements.river.client.client.ui.DatacageWidgetData;
+import org.dive4elements.river.client.client.ui.PanelHelper;
+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 org.dive4elements.river.client.shared.model.User;
+import org.dive4elements.river.client.shared.model.VegetationZoneServerClientXChange;
+
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.util.SC;
+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.ColorItem;
+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.CellSavedEvent;
+import com.smartgwt.client.widgets.grid.events.CellSavedHandler;
+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.Layout;
+import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.tree.TreeNode;
+
+/**
+ * @author Domenico Nardi Tironi
+ *
+ */
+public class FloodInfrastructurePanel extends AbstractUIProvider {
+    private static final long serialVersionUID = 1L;
+
+    private static final String datakey = "flood_infrastructure";
+    final protected List<ListGridRecord> records = new ArrayList<ListGridRecord>();
+    private ListGrid elements = new ListGrid();
+
+    private final User m_user;
+
+    public FloodInfrastructurePanel(final User user) {
+        this.m_user = user;
+    }
+
+    protected final ListGrid createTable(final Layout root, final DataList data, final String width, final boolean editable) {
+
+        final Label title = new Label(data.get(0).getDescription());
+        title.setHeight("35px");
+
+        this.elements.setWidth(width);
+        this.elements.setHeight(300);
+        this.elements.setShowHeaderContextMenu(false);
+        this.elements.setCanReorderFields(false);
+        this.elements.setCanSort(true);
+        this.elements.setSortField("to");
+        this.elements.setCanResizeFields(false);
+
+        this.elements.setCanEdit(editable);
+
+        final ListGridField internalNumber = new ListGridField("number", "number"); // valid only if no data is to be added
+        internalNumber.setCanSort(false);
+        internalNumber.setHidden(true);
+
+        final ListGridField infrstrField = new ListGridField("infrstr", "Infrastruktur BWaStr");// this.MSG.uinfo_vegetation_zones_label());
+        infrstrField.setType(ListGridFieldType.TEXT);
+        infrstrField.setWidth("*"); // 245
+        infrstrField.setCanSort(false);
+        infrstrField.setCanDragResize(true);
+        infrstrField.setCanEdit(true); // neue Anforderung - doch nicht? ???
+
+        final ListGridField fromField = new ListGridField("type", "Typ/Bezeichnung"); // VegZonePanelHelper.createIntTableField("from",
+        // this.MSG.uinfo_vegetation_zones_from(), true,
+        // getNormalizer(), getValidator()
+        // );
+        fromField.addCellSavedHandler(new CellSavedHandler() {
+            @Override
+            public void onCellSaved(final CellSavedEvent event) {
+                // updateValidationMsgLabel();
+            }
+        });
+
+        fromField.setCanEdit(false);
+
+        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!!
+            @Override
+            public void onRecordClick(final RecordClickEvent event) {
+                if (event.getField().getName().equals(removeField.getName())) {
+                    // updateValidationMsgLabel();
+                }
+            }
+        });
+        this.elements.setFields(infrstrField, fromField, removeField);
+
+        root.setWidth(width);
+        root.addMember(title);
+        root.addMember(this.elements);
+        root.addMember(PanelHelper.getSpacer(3));
+        root.addMember(PanelHelper.getSpacer(3));
+        return this.elements;
+
+    }
+
+    @Override
+    public final VLayout create(final DataList data) {
+        final VLayout layout = new VLayout();
+
+        final Canvas helper = createHelper(data);
+        if (helper != null)
+            this.helperContainer.addMember(helper);
+
+        final Canvas submit = getNextButton();
+
+        final VLayout root = new VLayout();
+        root.setWidth(450);
+        createWidget(root, data);
+
+        layout.addMember(root);
+        layout.addMember(submit);
+
+        // updateValidationMsgLabel();// init Text
+
+        return layout;
+    }
+
+    protected Canvas createHelper(final DataList dataList) {
+
+        final DatacageWidgetData data = new DatacageWidgetData(this.artifact, this.m_user, "uinfo.inundation_duration.vegZoneSelect", "load-system:true",
+                false);
+
+        final DatacageWidget datacage = new DatacageWidget(data);
+
+        final Button plusBtn = new Button("Hinzufügen"); // this.MSG.uinfo_inundation_duration_set_vegetation_zone()
+        plusBtn.addClickHandler(new ClickHandler() {
+            @Override
+            public void onClick(final ClickEvent event) {
+                handlePlusClicked(datacage);
+            }
+        });
+
+        final VLayout helperLayout = new VLayout();
+        helperLayout.addMember(datacage);
+        helperLayout.addMember(plusBtn);
+
+        return helperLayout;
+    }
+
+    private void handlePlusClicked(final DatacageWidget datacage) {
+        final List<TreeNode> selection = datacage.getPlainSelection();
+        if (selection == null || selection.isEmpty()) {
+            SC.say("VegetationzonesTablePanel.this.MSG.warning()");
+            return;
+        }
+
+        final TreeNode selectedNode = selection.get(0);
+
+        /*
+         * the encoded veg-zones is either in 'data' or 'ids'. We need both, because we have the cases of stadnard vegzones and
+         * user-defined vegzones.
+         */
+        final String dataAttribute = selectedNode.getAttribute("data");
+        final String idsAttribute = selectedNode.getAttribute("ids");
+        final String vegZoneData = (dataAttribute == null || dataAttribute.trim().length() == 0) ? idsAttribute : dataAttribute;
+
+        // for (final ListGridRecord r : this.elements.getRecords()) {
+        // this.elements.removeData(r);
+        // }
+        // final List<VegetationZoneServerClientXChange> rows = VegetationZoneServerClientXChange.parse(data);
+        // for (final VegetationZoneServerClientXChange row : rows) {
+        // this.elements.addData(createEntry(row));
+        // }
+
+    }
+
+    public final ListGridRecord createEntry(final VegetationZoneServerClientXChange row) {
+
+        final String vegzone = row.getZoneName();
+        final Integer from = row.getMin_day_overflow();
+        final Integer to = row.getMax_day_overflow();
+        final String colorStr = row.getHexColor();
+
+        if (vegzone == null)
+            return null;
+
+        final ListGridRecord r = new ListGridRecord();
+        r.setAttribute("vegzone", vegzone);
+        r.setAttribute("from", from);
+        r.setAttribute("to", to);
+        r.setAttribute("color", colorStr);
+        r.setAttribute("number", this.records.size());
+        this.records.add(r);
+        return r;
+
+    }
+
+    public void createWidget(final Layout root, final DataList data) {
+
+        this.elements = createTable(root, data, "420", true);
+
+        // this.vegzone = PanelHelper.createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), "*");
+        // this.vegzone.setColSpan(4);
+        // this.start = PanelHelper.createIntegerItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(),
+        // "*");
+        // this.end = PanelHelper.createIntegerItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), "*");
+        final VLayout fields = new VLayout();
+
+        final ColorItem colorPicker = new ColorItem();
+        colorPicker.setTitle(this.MSG.uinfo_vegetation_zone_color());
+
+        colorPicker.setShowTitle(true);
+        colorPicker.setShowValueIconOnly(false);
+        colorPicker.setShowPickerIcon(true);
+        colorPicker.setColSpan(2);
+        colorPicker.setWidth(110);
+
+        final Button add = new Button(this.MSG.add_date()); // TODO: make key more generic or change to more specific
+
+        final DynamicForm form1 = new DynamicForm();
+
+        form1.setNumCols(5); // für Layout untereinander muss 2 eingestellt werden
+        // form1.setFields(this.vegzone, this.start, this.end, colorPicker);
+
+        fields.addMember(form1);
+        root.addMember(fields);
+        root.addMember(PanelHelper.getSpacer(10));
+    }
+
+    @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("25px");
+
+        final List<Data> items = dataList.getAll();
+        final Data str = getData(items, datakey);
+        final DataItem[] strItems = str.getItems();
+
+        // for (final VegetationZoneServerClientXChange entry : entries) {
+        final Label dateLabel = new Label("zone  (   asfd  - asdf )");
+        dateLabel.setHeight("20px");
+        vLayout.addMember(dateLabel);
+
+        final Canvas back = getBackButton(dataList.getState());
+        layout.addMember(label);
+        layout.addMember(vLayout);
+        layout.addMember(back);
+
+        return layout;
+    }
+
+    @Override
+    protected final Data[] getData() {
+        final List<Data> data = new ArrayList<Data>();
+
+        final ListGridRecord[] lgr = this.elements.getRecords();
+        if (lgr.length == 0) {
+            // 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, "VegetationZoneServerClientXChange.parseListToDataString(getZones(lgr))"); // DATA-key
+        data.add(new DefaultData(datakey, null, null, new DataItem[] { item }));
+        return data.toArray(new Data[data.size()]);
+    }
+
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org