diff flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java @ 2505:87ac5c532523

First part of the UI for fixing analysis parameter. flys-client/trunk@4350 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 07 May 2012 13:22:43 +0000
parents
children 8f528f5ae137
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java	Mon May 07 13:22:43 2012 +0000
@@ -0,0 +1,149 @@
+package de.intevation.flys.client.client.ui.fixation;
+
+import java.util.HashMap;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import com.smartgwt.client.util.SC;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.HTMLPane;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.ui.AbstractUIProvider;
+
+import de.intevation.flys.client.client.Config;
+
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataList;
+import de.intevation.flys.client.shared.model.FixingsOverviewInfo;
+
+import de.intevation.flys.client.client.services.FixingsOverviewService;
+import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync;
+
+
+/**
+ * This UIProvider creates helper panel for fixation analysis without input
+ * elements.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public abstract class FixationPanel
+extends      AbstractUIProvider
+{
+    protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>();
+
+    /** The message class that provides i18n strings. */
+    protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
+
+    protected FixingsOverviewServiceAsync overviewService =
+        GWT.create(FixingsOverviewService.class);
+
+    protected String   htmlOverview;
+    protected FixingsOverviewInfo fixInfo;
+
+    public FixationPanel() {
+        htmlOverview = "";
+    }
+
+    protected String getArtifactUuid() {
+        return this.artifact.getUuid();
+    }
+
+    protected void init() {
+
+    }
+
+    public Data[] getData() {
+        return null;
+    }
+
+    public Canvas create(DataList list) {
+        VLayout layout = new VLayout();
+
+        Canvas helper = createHelper();
+        this.helperContainer.addMember(helper);
+
+        Canvas submit = getNextButton();
+        Canvas widget = createWidget(list);
+
+        layout.addMember(widget);
+        layout.addMember(submit);
+        return layout;
+    }
+
+    public Canvas createOld(DataList list) {
+        return new DynamicForm();
+    }
+
+    protected Canvas createHelper() {
+        Config config    = Config.getInstance();
+        String locale    = config.getLocale ();
+
+        final HTMLPane helper = new HTMLPane();
+
+        String river = artifact.getArtifactDescription().getRiver();
+
+        createCallback();
+/*
+Filter example.
+{"fixings": { "river": { "name": "Elbe"}, "range": {"from": 1, "to": 200}, "filter": {"and": { "column": {"cid": 1}, "column": {"cid": 2} } }}
+*/
+        String callBack = "fixationCallback(this.checked, this.name)";
+
+        overviewService.generateOverview(
+            locale,
+            artifact.getUuid(),
+            "{\"fixings\": {\"river\": {\"name\": \"" + river + "\"}}}",
+            renderCheckboxes(),
+            callBack,
+            new AsyncCallback<FixingsOverviewInfo>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not receive overview.");
+                    SC.warn(caught.getMessage());
+                }
+                public void onSuccess(FixingsOverviewInfo info) {
+                    GWT.log("Successfully loaded overview.");
+                    fixInfo = info;
+                    htmlOverview = info.getHTML();
+                    GWT.log("html: " + info.getHTML());
+                    helper.setContents(htmlOverview);
+
+                }
+            });
+
+        this.helperContainer.addMember(helper);
+
+        return helper;
+    }
+
+    private native void createCallback() /*-{
+        $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;);
+    }-*/;
+
+    private static void helperCallback(boolean checked, String name) {
+        String[] parts = name.split(":");
+        String uuid = parts[0];
+        String cid = parts[1];
+        FixationPanel p = FixationPanel.getInstance(uuid);
+        if (p != null) {
+            p.setValues(cid, checked);
+        }
+    }
+
+    private static FixationPanel getInstance(String uuid) {
+        for (int i = 0; i < instances.size(); i++) {
+            if (instances.get(uuid) != null) {
+                return instances.get(uuid);
+            }
+        }
+        return null;
+    }
+
+    public abstract Canvas createWidget(DataList data);
+    public abstract void setValues(String cid, boolean checked);
+    public abstract boolean renderCheckboxes();
+}

http://dive4elements.wald.intevation.org