diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java @ 854:67c678903280

Refactored to allow specialized controls within the ChartThemePanel, stubby first steps towards such a control (bound to FeedService). flys-client/trunk@2641 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 02 Sep 2011 13:20:06 +0000
parents f43d06d6a4a2
children 9f07f67f60a5
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Fri Sep 02 13:14:43 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Fri Sep 02 13:20:06 2011 +0000
@@ -2,10 +2,22 @@
 
 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.VLayout;
+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.Theme;
 import de.intevation.flys.client.shared.model.OutputMode;
@@ -13,6 +25,9 @@
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.ui.ThemePanel;
 
+import de.intevation.flys.client.client.services.FeedService;
+import de.intevation.flys.client.client.services.FeedServiceAsync;
+
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
@@ -23,9 +38,12 @@
     private FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
 
-    public static final String GRID_FIELD_ACTIVE = "active";
-    public static final String GRID_FIELD_NAME   = "name";
+    public static final String GRID_FIELD_ACTIVE  = "active";
+    public static final String GRID_FIELD_NAME    = "name";
+    public static final String GRID_FIELD_ACTIONS = "actions";
 
+    FeedServiceAsync feedService = GWT.create(
+        de.intevation.flys.client.client.services.FeedService.class);
 
     public ChartThemePanel(Collection collection, OutputMode mode) {
         super(collection, mode);
@@ -38,6 +56,75 @@
 
 
     /**
+     * Create and configure the Grid to display.
+     */
+    protected ListGrid createGrid() {
+        ListGrid list = new ListGrid() {
+            @Override
+            protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {
+                    GWT.log("createRecordComponent! " + this.getFieldName(colNum));
+
+                    String fieldName = this.getFieldName(colNum);
+
+                    if (fieldName.equals("actions")) {
+                        GWT.log("GG UU II: Put actopms");
+                        HLayout recordCanvas = new HLayout(3);
+                        recordCanvas.setHeight(22);
+                        recordCanvas.setAlign(Alignment.CENTER);
+                        // Grid Cell Widgets example
+                        SpinnerItem spinnerItem = new SpinnerItem();
+                        spinnerItem.setShowTitle(false);
+                        spinnerItem.setTitle("Waterlevel-Spinner");
+                        spinnerItem.setWidth(50);
+                        spinnerItem.setDefaultValue(5);
+                        spinnerItem.setMin(130);
+                        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) {
+                                    // artifact instead of null
+                                    // data[] instead of null
+                                    feedService.feed(serverUrl, locale, null, null,
+                                        new AsyncCallback<Artifact>() {
+                                            public void onFailure(Throwable caught) {
+                                                GWT.log("Could not feed artifact");
+                                                // TODO SC.warn 
+                                            }
+                                            public void onSuccess(Artifact artifact) {
+                                                GWT.log("Successfully fed");
+                                                //TODO and now?
+                                            }
+                                        });
+                                }
+                            }
+                        );
+
+                        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 layout of this panel.
      */
     protected void initLayout() {
@@ -61,7 +148,7 @@
     protected void initGrid() {
         list.setCanEdit(true);
         list.setCanSort(false);
-        list.setShowRecordComponents(false);
+        //list.setShowRecordComponents(false);
         list.setShowRecordComponentsByCell(true);
         list.setShowHeader(true);
         list.setShowHeaderContextMenu(false);
@@ -77,7 +164,12 @@
             GRID_FIELD_NAME, MSG.chart_themepanel_header_themes());
         name.setType(ListGridFieldType.TEXT);
 
-        list.setFields(active, name);
+        // TODO Visibility of this Field (~"column") shall depend on
+        // availability of facets allowing for actions.
+        ListGridField actions = new ListGridField(GRID_FIELD_ACTIONS,
+                GRID_FIELD_ACTIONS, 60);
+
+        list.setFields(active, name, actions);
     }
 
 

http://dive4elements.wald.intevation.org