changeset 5503:b660090b417d

Create a new sq relation project on measurement station record click. * Added new methods to artifact service. * Added new client-side artifact. * Updated UI to have a new row in 'Messstellen-Info'.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 28 Mar 2013 15:21:15 +0100
parents 566eea137330
children 57dda5111474
files flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeDischargeCurvePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/StaticDataPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationRecord.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java flys-client/src/main/java/de/intevation/flys/client/shared/model/StaticSQRelationArtifact.java
diffstat 12 files changed, 269 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Thu Mar 28 15:21:15 2013 +0100
@@ -514,6 +514,60 @@
             });
     }
 
+    public void newSQRelation(String river, int measurementStation) {
+        Config config = Config.getInstance();
+
+        final String locale = config.getLocale();
+        final String riv = river;
+        final int mStation = measurementStation;
+        final FLYS   flys = this;
+
+        User user = getCurrentUser();
+
+        if (user == null) {
+            SC.warn(MSG.error_not_logged_in());
+            return;
+        }
+
+        collectionService.create(locale, user.identifier(),
+            new AsyncCallback<Collection>() {
+                @Override
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not create new collection.");
+                    SC.warn(getExceptionString(MSG, caught));
+                }
+
+                @Override
+                public void onSuccess(Collection collection) {
+                    GWT.log("Successfully created a new collection.");
+                    final Collection col = collection;
+                    artifactService.createSQRelationArtifact(
+                        col, locale, riv, mStation,
+                        new AsyncCallback<Artifact>() {
+                            @Override
+                            public void onFailure(Throwable caught) {
+                                GWT.log("Could not create the new artifact.");
+                                SC.warn(getExceptionString(MSG, caught));
+                            }
+
+                            @Override
+                            public void onSuccess(Artifact artifact) {
+                                GWT.log("Successfully created a new artifact.");
+                                CollectionView view = new CollectionView(flys,
+                                    col, artifact);
+                                workspace.addView(col.identifier(), view);
+
+                                view.addCollectionChangeHandler(getProjectList());
+                                view.addCloseClickHandler(
+                                    new CloseCollectionViewHandler(
+                                        FLYS.this, col.identifier()));
+                                projectList.updateUserCollections();
+                            }
+                    });
+                }
+            });
+    }
+
     @Override
     public void onCollectionChange(CollectionChangeEvent event) {
         Collection oldC = event.getOldValue();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java	Thu Mar 28 15:21:15 2013 +0100
@@ -46,5 +46,19 @@
             String river,
             Long   gaugeref
     ) throws ServerException;
+
+    /**
+     * Create a new SQRelationArtifact
+     *
+     * @param collection the collection to add the artifact to
+     * @param river      the river
+     * @param measurementStation the measurement station id
+     */
+    public Artifact createSQRelationArtifact(
+            Collection collection,
+            String locale,
+            String river,
+            int measurementStation
+    ) throws ServerException;
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java	Thu Mar 28 15:21:15 2013 +0100
@@ -28,5 +28,13 @@
         Long   gaugeref,
         AsyncCallback<Artifact> callback
     );
+
+    public void createSQRelationArtifact(
+        Collection collection,
+        String locale,
+        String river,
+        int measurementStation,
+        AsyncCallback<Artifact> callback
+    );
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeDischargeCurvePanel.java	Thu Mar 28 15:17:52 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-package de.intevation.flys.client.client.ui;
-
-import com.google.gwt.core.client.GWT;
-
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.Label;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.layout.HLayout;
-import com.smartgwt.client.widgets.layout.VLayout;
-
-import de.intevation.flys.client.client.FLYSConstants;
-import de.intevation.flys.client.shared.model.Data;
-import de.intevation.flys.client.shared.model.DataItem;
-import de.intevation.flys.client.shared.model.DataList;
-
-
-/**
- * This UIProvider displays the old DataItems of GaugeDischargeCurveArtifact
- *
- * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
- */
-public class GaugeDischargeCurvePanel
-extends      AbstractUIProvider
-{
-    private static final long serialVersionUID = 7411866539525588336L;
-
-    /** The message class that provides i18n strings.*/
-    protected FLYSConstants messages = GWT.create(FLYSConstants.class);
-
-    /** The combobox.*/
-    protected DynamicForm form;
-
-    @Override
-    public Canvas create(DataList data) {
-        VLayout layout   = new VLayout();
-        return layout;
-    }
-
-    @Override
-    public Canvas createOld(DataList dataList) {
-        VLayout vLayout = new VLayout();
-        vLayout.setWidth("400px");
-
-        int size = dataList.size();
-        for (int i = 0; i < size; i++) {
-            Data data        = dataList.get(i);
-            DataItem[] items = data.getItems();
-
-            for (DataItem item: items) {
-                HLayout hLayout = new HLayout();
-
-                hLayout.addMember(new Label(item.getLabel()));
-                hLayout.addMember(new Label(item.getStringValue()));
-
-                vLayout.addMember(hLayout);
-                vLayout.setWidth("130px");
-            }
-        }
-
-        return vLayout;
-    }
-
-    @Override
-    protected Data[] getData() {
-        return null;
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/StaticDataPanel.java	Thu Mar 28 15:21:15 2013 +0100
@@ -0,0 +1,68 @@
+package de.intevation.flys.client.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DataList;
+
+
+/**
+ * This UIProvider displays the old DataItems of GaugeDischargeCurveArtifact
+ *
+ * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
+ */
+public class StaticDataPanel
+extends      AbstractUIProvider
+{
+    private static final long serialVersionUID = 7411866539525588336L;
+
+    /** The message class that provides i18n strings.*/
+    protected FLYSConstants messages = GWT.create(FLYSConstants.class);
+
+    /** The combobox.*/
+    protected DynamicForm form;
+
+    @Override
+    public Canvas create(DataList data) {
+        VLayout layout   = new VLayout();
+        return layout;
+    }
+
+    @Override
+    public Canvas createOld(DataList dataList) {
+        VLayout vLayout = new VLayout();
+        vLayout.setWidth("400px");
+
+        int size = dataList.size();
+        for (int i = 0; i < size; i++) {
+            Data data        = dataList.get(i);
+            DataItem[] items = data.getItems();
+
+            for (DataItem item: items) {
+                HLayout hLayout = new HLayout();
+
+                hLayout.addMember(new Label(item.getLabel()));
+                hLayout.addMember(new Label(item.getStringValue()));
+
+                vLayout.addMember(hLayout);
+                vLayout.setWidth("130px");
+            }
+        }
+
+        return vLayout;
+    }
+
+    @Override
+    protected Data[] getData() {
+        return null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Thu Mar 28 15:21:15 2013 +0100
@@ -162,7 +162,7 @@
             return new RadioPanel();
         }
         else if (uiProvider.equals("gauge_discharge_curve")) {
-            return new GaugeDischargeCurvePanel();
+            return new StaticDataPanel();
         }
         else if (uiProvider.equals("minfo.sedimentload_distance_select")) {
             return new SedLoadDistancePanel();
@@ -182,6 +182,9 @@
         else if (uiProvider.equals("user_rgd_panel")) {
             return new UserRGDProvider();
         }
+        else if (uiProvider.equals("static_sqrelation")) {
+            return new StaticDataPanel();
+        }
         else {
             //GWT.log("Picked default provider.");
             return new SelectProvider();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java	Thu Mar 28 15:21:15 2013 +0100
@@ -7,6 +7,8 @@
 import com.smartgwt.client.widgets.WidgetCanvas;
 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 de.intevation.flys.client.client.FLYS;
 import de.intevation.flys.client.shared.model.MeasurementStation;
@@ -18,7 +20,9 @@
 /**
  * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
  */
-public class MeasurementStationListGrid extends InfoListGrid {
+public class MeasurementStationListGrid
+extends InfoListGrid
+implements RecordClickHandler {
 
     public MeasurementStationListGrid(FLYS flys) {
         super(flys);
@@ -28,7 +32,9 @@
         ListGridField stfield = new ListGridField("station", "Station [km]");
         ListGridField lfield = new ListGridField("link", "Link");
         lfield.setType(ListGridFieldType.LINK);
-        this.setFields(nfield, sfield, efield, stfield, lfield);
+        ListGridField cfield = new ListGridField("curvelink", "SQ");
+        cfield.addRecordClickHandler(this);
+        this.setFields(nfield, sfield, efield, stfield, lfield, cfield);
     }
 
     /**
@@ -88,4 +94,12 @@
         MeasurementStationRecord station = (MeasurementStationRecord)record;
         return new WidgetCanvas(new MeasurementStationInfoPanel(station));
     }
+
+    @Override
+    public void onRecordClick(RecordClickEvent event) {
+        MeasurementStationRecord station =
+            (MeasurementStationRecord)event.getRecord();
+        flys.newSQRelation(station.getRiverName(), station.getID());
+    }
+
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationRecord.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationRecord.java	Thu Mar 28 15:21:15 2013 +0100
@@ -27,6 +27,7 @@
             MSG.measurement_station_url();
         this.setLink(link);
         this.setLinkText(MSG.measurement_station_info_link());
+        this.setCurveLink(MSG.static_sqrelation());
         this.setID(number);
         this.setName(station.getName());
         if (station.isKmUp()) {
@@ -172,4 +173,13 @@
     public void setLink(String link) {
         this.setAttribute("link", link);
     }
+
+    public void setCurveLink(String link) {
+        this.setAttribute("curvelink", link);
+    }
+
+    public String getCurveLink() {
+        return this.getAttribute("curvelink");
+    }
+
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java	Thu Mar 28 15:21:15 2013 +0100
@@ -39,7 +39,7 @@
      * Name of the factory to generate a GaugeDischargeCurveArtifact
      */
     private static final String GAUGE_DISCHARGE_CURVE_ARTIFACT = "gaugedischargecurve";
-
+    private static final String SQ_RELATION_ARTIFACT = "staticsqrelation";
 
     private ArtifactHelper() {
     }
@@ -162,5 +162,35 @@
 
         return cf;
     }
+
+
+    public static Artifact createSQRelationArtifact(
+        String serverUrl,
+        String locale,
+        String river,
+        int measurementStation)
+    throws ServerException
+    {
+        Document create = ClientProtocolUtils.newCreateDocument(
+                SQ_RELATION_ARTIFACT);
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            create,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = create.getDocumentElement();
+
+        Element eriver = ec.create("river");
+        ec.addAttr(eriver, "name", river);
+
+        Element estation = ec.create("measurement_station");
+        ec.addAttr(estation, "number", String.valueOf(measurementStation));
+
+        root.appendChild(eriver);
+        root.appendChild(estation);
+
+        return sendCreate(serverUrl, locale, create);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java	Thu Mar 28 15:21:15 2013 +0100
@@ -78,5 +78,28 @@
         return artifact;
     }
 
+    @Override
+    public Artifact createSQRelationArtifact(
+        Collection collection,
+        String locale,
+        String river,
+        int measurementStation)
+    throws ServerException
+    {
+        logger.info("ArtifactServiceImpl.createSQRelationArtifact");
+        String url  = getServletContext().getInitParameter("server-url");
+
+        Artifact artifact = ArtifactHelper.createSQRelationArtifact(url,
+                locale, river, measurementStation);
+        if (artifact == null) {
+            return null;
+        }
+        logger.info("SQRelationArtifact created successfully");
+
+        CollectionHelper.addArtifact(collection, artifact, url, locale);
+
+        return artifact;
+    }
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java	Thu Mar 28 15:17:52 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java	Thu Mar 28 15:21:15 2013 +0100
@@ -24,6 +24,7 @@
 import de.intevation.flys.client.shared.model.GaugeDischargeCurveArtifact;
 import de.intevation.flys.client.shared.model.MapArtifact;
 import de.intevation.flys.client.shared.model.MINFOArtifact;
+import de.intevation.flys.client.shared.model.StaticSQRelationArtifact;
 import de.intevation.flys.client.shared.model.WINFOArtifact;
 
 
@@ -149,6 +150,10 @@
             logger.debug("+++++ NEW GAUGEDISCHARGECURVE ARTIFACT.");
             return new GaugeDischargeCurveArtifact(uuid, hash, background, msg);
         }
+        else if (name.length() > 0 && name.equals("staticsqrelation")) {
+            logger.debug("+++++ STATICSQRELATION ARTIFACT.");
+            return new StaticSQRelationArtifact(uuid, hash, background, msg);
+        }
 
         return new DefaultArtifact(uuid, hash, background, msg);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/StaticSQRelationArtifact.java	Thu Mar 28 15:21:15 2013 +0100
@@ -0,0 +1,36 @@
+package de.intevation.flys.client.shared.model;
+
+import java.util.List;
+
+
+public class StaticSQRelationArtifact
+extends DefaultArtifact
+{
+
+    /** The name of this artifact */
+    public static final String NAME = "static_sqrelation";
+
+
+
+    public StaticSQRelationArtifact() {
+    }
+
+    public StaticSQRelationArtifact(String uuid, String hash) {
+        super(uuid, hash);
+    }
+
+
+    public StaticSQRelationArtifact(
+        String                   uuid,
+        String                   hash,
+        boolean                  inBackground,
+        List<CalculationMessage> messages
+    ) {
+        super(uuid, hash, inBackground, messages);
+    }
+
+
+    public String getName() {
+        return NAME;
+    }
+}

http://dive4elements.wald.intevation.org