diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java @ 858:9f07f67f60a5

Subclassed ChartThemePanel, trigger redraws of Chart when interaction with "Action" widgets in ThemePanel occured (but will still crash). flys-client/trunk@2651 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 06 Sep 2011 11:09:13 +0000
parents
children 65204f30877b
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/chart/CrossSectionChartThemePanel.java	Tue Sep 06 11:09:13 2011 +0000
@@ -0,0 +1,163 @@
+package de.intevation.flys.client.client.ui.chart;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.types.Alignment; 
+import com.smartgwt.client.widgets.Canvas;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.types.ListGridFieldType;
+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.layout.HLayout;
+import com.smartgwt.client.widgets.form.fields.SpinnerItem;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
+import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
+
+import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.shared.model.OutputMode;
+
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DefaultArtifact;
+import de.intevation.flys.client.shared.model.DefaultData;
+import de.intevation.flys.client.shared.model.DefaultDataItem;
+import de.intevation.flys.client.shared.model.FacetRecord;
+
+
+
+/**
+ * ThemePanel much like ChartThemePanel, but shows an "Actions" column,
+ * needed for interaction in the CrossSection Charts.
+ */
+public class CrossSectionChartThemePanel
+extends      ChartThemePanel {
+
+    /**
+     * Trivial constructor.
+     */
+    public CrossSectionChartThemePanel(
+            Collection collection,
+            OutputMode mode)
+    {
+        super(collection, mode);
+    }
+
+
+    /**
+     * Create and configure the Grid to display.
+     */
+    @Override
+    protected ListGrid createGrid() {
+        ListGrid list = new ListGrid() {
+            @Override
+            protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {
+
+                    String fieldName = this.getFieldName(colNum);
+
+                    if (fieldName.equals("actions")) {
+                        GWT.log("Gui: Put Actions");
+                        HLayout recordCanvas = new HLayout(3);
+                        recordCanvas.setHeight(22);
+                        recordCanvas.setAlign(Alignment.CENTER);
+                        // TODO decide on per case basis if to put an action
+                        // widget or not.
+                        // TODO Refactor in createSpinner(data, artifact)
+                        SpinnerItem spinnerItem = new SpinnerItem();
+                        spinnerItem.setShowTitle(false);
+                        spinnerItem.setTitle("Waterlevel-Spinner");
+                        spinnerItem.setWidth(50);
+                        // TODO actually get the value from artifact
+                        // TODO actually get the range from artifact (or river?)
+                        spinnerItem.setDefaultValue(0);
+                        spinnerItem.setMin(0);
+                        spinnerItem.setMax(1000);
+                        spinnerItem.setStep(5f);
+
+                        Config config = Config.getInstance();
+                        final String serverUrl = config.getServerUrl();
+                        final String locale    = config.getLocale();
+
+                        spinnerItem.addChangedHandler(new ChangedHandler() {
+                                @Override
+                                public void onChanged(ChangedEvent ce) {
+                                    FacetRecord facetRecord = (FacetRecord) record;
+                                    DefaultDataItem kmItem = new DefaultDataItem("cross_section.km",
+                                        "cross_section.km", ce.getValue().toString());
+                                    DefaultData km = new DefaultData("cross_section.km",
+                                        null, null, new DataItem[] {kmItem});
+                                    Data[] feedData = new Data[] {km};
+                                    feedService.feed(serverUrl,
+                                        locale,
+                                        new DefaultArtifact(facetRecord.getTheme().getArtifact(), "TODO:hash"),
+                                        feedData,
+                                        new AsyncCallback<Artifact>() {
+                                            public void onFailure(Throwable caught) {
+                                                GWT.log("Could not feed artifact " + caught.getMessage());
+                                                // TODO SC.warn 
+                                            }
+                                            public void onSuccess(Artifact artifact) {
+                                                GWT.log("Successfully fed");
+                                                //TODO and now?
+                                                // fireOutputParameterChanged();
+                                                // Also update content of spinnerbox
+                                                requestRedraw();
+                                            }
+                                        });
+                                }
+                            }
+                        );
+
+                        DynamicForm formWrap = new DynamicForm();
+                        formWrap.setFields(spinnerItem);
+                        formWrap.setTitlePrefix("");
+                        formWrap.setTitleSuffix("");
+                        recordCanvas.addMember(formWrap);
+                        return recordCanvas;
+                    }
+                    else {
+                        return null;
+                    }
+                }
+            };
+        list.setCanResizeFields(true);
+        list.setShowRecordComponents(true);
+        list.setShowRecordComponentsByCell(true);
+        list.setShowAllRecords(true);
+        return list;
+    }
+
+
+    /**
+     * Initializes the components (columns) of the theme grid.
+     */
+    @Override
+    protected void initGrid() {
+        list.setCanEdit(true);
+        list.setCanSort(false);
+        list.setShowRecordComponents(true);
+        list.setShowRecordComponentsByCell(true);
+        list.setShowHeader(true);
+        //list.setShowHeaderContextMenu(false);
+        list.setWidth100();
+        list.setHeight100();
+
+        list.addEditCompleteHandler(this);
+
+        ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20);
+        active.setType(ListGridFieldType.BOOLEAN);
+
+        ListGridField name = new ListGridField(
+            GRID_FIELD_NAME, MSG.chart_themepanel_header_themes());
+        name.setType(ListGridFieldType.TEXT);
+
+        ListGridField actions = new ListGridField(GRID_FIELD_ACTIONS,
+                GRID_FIELD_ACTIONS, 60);
+
+        list.setFields(active, name, actions);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org