changeset 73:39210a74db07

Moved parameterization specific code from CollectionView to ParameterList. flys-client/trunk@1576 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 28 Mar 2011 06:48:44 +0000
parents 9b726350ab07
children c5586446f3c0
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java
diffstat 3 files changed, 237 insertions(+), 211 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Sat Mar 26 18:07:41 2011 +0000
+++ b/flys-client/ChangeLog	Mon Mar 28 06:48:44 2011 +0000
@@ -1,3 +1,10 @@
+2011-03-28  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.java,
+	  src/main/java/de/intevation/flys/client/client/ui/ParameterList.java:
+	  Moved parameterization specific code from CollectionView to
+	  ParameterList.
+
 2011-03-26  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Sat Mar 26 18:07:41 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Mon Mar 28 06:48:44 2011 +0000
@@ -7,7 +7,6 @@
 import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
-import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Window;
 import com.smartgwt.client.widgets.layout.Layout;
 import com.smartgwt.client.widgets.layout.VLayout;
@@ -17,40 +16,21 @@
 import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.ArtifactDescription;
 import de.intevation.flys.client.shared.model.Collection;
-import de.intevation.flys.client.shared.model.Data;
-import de.intevation.flys.client.shared.model.DataItem;
-import de.intevation.flys.client.shared.model.DataList;
-import de.intevation.flys.client.shared.model.DefaultData;
-import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.shared.model.OutputMode;
-import de.intevation.flys.client.shared.model.River;
 import de.intevation.flys.client.shared.model.User;
 
 import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYS;
 import de.intevation.flys.client.client.FLYSMessages;
 import de.intevation.flys.client.client.event.HasCollectionChangeHandlers;
-import de.intevation.flys.client.client.event.HasParameterChangeHandler;
-import de.intevation.flys.client.client.event.HasStepForwardHandlers;
 import de.intevation.flys.client.client.event.CollectionChangeEvent;
 import de.intevation.flys.client.client.event.CollectionChangeHandler;
 import de.intevation.flys.client.client.event.ParameterChangeEvent;
 import de.intevation.flys.client.client.event.ParameterChangeHandler;
-import de.intevation.flys.client.client.event.StepBackEvent;
-import de.intevation.flys.client.client.event.StepBackHandler;
-import de.intevation.flys.client.client.event.StepForwardEvent;
-import de.intevation.flys.client.client.event.StepForwardHandler;
 import de.intevation.flys.client.client.services.AddArtifactService;
 import de.intevation.flys.client.client.services.AddArtifactServiceAsync;
-import de.intevation.flys.client.client.services.AdvanceService;
-import de.intevation.flys.client.client.services.AdvanceServiceAsync;
-import de.intevation.flys.client.client.services.ArtifactService;
-import de.intevation.flys.client.client.services.ArtifactServiceAsync;
-import de.intevation.flys.client.client.services.StepForwardService;
-import de.intevation.flys.client.client.services.StepForwardServiceAsync;
 import de.intevation.flys.client.client.services.CreateCollectionService;
 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync;
-import de.intevation.flys.client.client.ui.ModuleSelection;
 
 
 /**
@@ -59,22 +39,9 @@
 public class CollectionView
 extends      Window
 implements   CollectionChangeHandler, HasCollectionChangeHandlers,
-             HasParameterChangeHandler, ParameterChangeHandler,
-             StepForwardHandler, StepBackHandler
+             ParameterChangeHandler
 {
     /** The ArtifactService used to communicate with the Artifact server. */
-    protected ArtifactServiceAsync artifactService =
-        GWT.create(ArtifactService.class);
-
-    /** The StepForwardService used to put data into an existing artifact. */
-    protected StepForwardServiceAsync forwardService =
-        GWT.create(StepForwardService.class);
-
-    /** The StepForwardService used to put data into an existing artifact. */
-    protected AdvanceServiceAsync advanceService =
-        GWT.create(AdvanceService.class);
-
-    /** The ArtifactService used to communicate with the Artifact server. */
     protected CreateCollectionServiceAsync createCollectionService =
         GWT.create(CreateCollectionService.class);
 
@@ -83,7 +50,7 @@
         GWT.create(AddArtifactService.class);
 
     /** The message class that provides i18n strings.*/
-    FLYSMessages messages = GWT.create(FLYSMessages.class);
+    protected FLYSMessages messages = GWT.create(FLYSMessages.class);
 
     /** The FLYS instance used to call services.*/
     protected FLYS flys;
@@ -94,9 +61,6 @@
     /** The list of ValueChangeHandlers.*/
     protected List<CollectionChangeHandler> handlers;
 
-    /** The list of ParameterizationChangeHandler.*/
-    protected List<ParameterChangeHandler> parameterHandlers;
-
     /** The collection to be displayed.*/
     protected Collection collection;
 
@@ -127,14 +91,14 @@
 
         this.tabs              = new TabSet();
         this.parameterTab      = new Tab(messages.winfo());
-        this.parameterList     = new ParameterList(this);
+        this.parameterList     = new ParameterList(flys, this);
         this.handlers          = new ArrayList<CollectionChangeHandler>();
-        this.parameterHandlers = new ArrayList<ParameterChangeHandler>();
         this.layout            = new VLayout();
 
         addCollectionChangeHandler(this);
-        addParameterChangeHandler(this);
-        addParameterChangeHandler(parameterList);
+
+        parameterList.addParameterChangeHandler(this);
+        parameterList.addParameterChangeHandler(parameterList);
 
         init();
     }
@@ -160,10 +124,8 @@
         layout.addMember(tabs);
         tabs.addTab(parameterTab);
 
-        if (isNew()) {
-            tabs.setTabTitle(0, messages.new_calculation());
-            tabs.updateTab(0, renderNew());
-        }
+        tabs.setTabTitle(0, messages.new_calculation());
+        tabs.updateTab(0, parameterList);
     }
 
 
@@ -194,6 +156,7 @@
 
                             public void onFailure(Throwable caught) {
                                 GWT.log("An error occured while adding artifact.");
+                                GWT.log(caught.getMessage());
                             }
 
                             public void onSuccess(Collection newCollection) {
@@ -225,17 +188,6 @@
     }
 
 
-    /**
-     * This method registers a new ParameterChangeHandler.
-     *
-     * @param handler The new ParameterChangeHandler.
-     */
-    public void addParameterChangeHandler(ParameterChangeHandler handler) {
-        if (handler != null) {
-            parameterHandlers.add(handler);
-        }
-    }
-
 
     /**
      * This method calls the <code>onValueChange()</code> method of all
@@ -251,17 +203,6 @@
 
 
     /**
-     * This method calls the <code>onParameterChange()</code> method of all
-     * registered ParameterChangeHandler.
-     */
-    protected void fireParameterChangeEvent(Artifact old, Artifact newArt) {
-        for (ParameterChangeHandler handler: parameterHandlers) {
-            handler.onParameterChange(new ParameterChangeEvent(old, newArt));
-        }
-    }
-
-
-    /**
      * This method returns true, if the Collection is new and no plugins has
      * been chosen.
      *
@@ -273,78 +214,6 @@
 
 
     /**
-     * This method creates a Canvas displaying the plugins of FLYS combined with
-     * a widget to select a river.
-     *
-     * @return a Canvas that displays the supported plugins and rivers of FLYS.
-     */
-    protected Canvas renderNew() {
-        River[] rivers   = flys.getRivers();
-        DataItem[] items = new DataItem[rivers.length];
-
-        int i = 0;
-        for (River river: rivers) {
-            String name = river.getName();
-            items[i++]  = new DefaultDataItem(name, null, name);
-        }
-
-        Data data = new DefaultData(
-            "river",
-            messages.river_selection(),
-            null,
-            items);
-
-        ModuleSelection widget         = new ModuleSelection();
-        HasStepForwardHandlers handler = (HasStepForwardHandlers) widget;
-
-        handler.addStepForwardHandler(new StepForwardHandler() {
-            public void onStepForward(StepForwardEvent event) {
-                Data[] data = event.getData();
-
-                DataItem[] moduleItems = data[0].getItems();
-                DataItem[] riversItems = data[1].getItems();
-
-                String module = moduleItems[0].getStringValue();
-                String river  = riversItems[0].getStringValue();
-
-                final String serverUrl = Config.getInstance().getServerUrl();
-                final Data[] feedData  = new Data[] { data[1] };
-                artifactService.create(
-                    serverUrl, module.toLowerCase(),
-                    new AsyncCallback<Artifact>() {
-                        public void onFailure(Throwable caught) {
-                            GWT.log("Could not create the new artifact.");
-                            GWT.log(caught.getMessage());
-                        }
-
-                        public void onSuccess(Artifact artifact) {
-                            GWT.log("Successfully created a new artifact.");
-
-                            forwardService.go(serverUrl, artifact, feedData,
-                            new AsyncCallback<Artifact>() {
-                                public void onFailure(Throwable caught) {
-                                    GWT.log("Could not feed the artifact.");
-                                    GWT.log(caught.getMessage());
-                                }
-
-                                public void onSuccess(Artifact artifact) {
-                                    GWT.log("Successfully feed the artifact.");
-                                    setArtifact(artifact);
-                                }
-                            });
-                        }
-                });
-            }
-        });
-
-        DataList list = new DataList();
-        list.add(data);
-
-        return widget.create(list);
-    }
-
-
-    /**
      * Returns the artifact that is used for the parameterization.
      *
      * @return the artifact that is used for the parameterization.
@@ -360,10 +229,7 @@
      * @param artifact The new artifact.
      */
     protected void setArtifact(Artifact artifact) {
-        Artifact tmp  = this.artifact;
         this.artifact = artifact;
-
-        fireParameterChangeEvent(tmp, this.artifact);
     }
 
 
@@ -378,6 +244,8 @@
         ArtifactDescription desc = art.getArtifactDescription();
         OutputMode[] outs        = desc.getOutputModes();
 
+        setArtifact(art);
+
         if (outs != null) {
             User user = getFlys().getCurrentUser();
             createNewCollection(user.identifier());
@@ -407,57 +275,6 @@
 
 
     /**
-     * This method is used to call the ADVANCE service to go back to a previous
-     * state.
-     *
-     * @param e The StepBackEvent that holds the identifier of the target state.
-     */
-    public void onStepBack(StepBackEvent e) {
-        final String target    = e.getTarget();
-        final String serverUrl = Config.getInstance().getServerUrl();
-
-        advanceService.advance(serverUrl, artifact, target,
-            new AsyncCallback<Artifact>() {
-                public void onFailure(Throwable caught) {
-                    GWT.log("Could not go back to '" + target + "'");
-                    GWT.log(caught.getMessage());
-                }
-
-                public void onSuccess(Artifact artifact) {
-                    GWT.log("Successfully step back to '" + target + "'");
-                    setArtifact(artifact);
-                }
-            }
-        );
-    }
-
-
-    /**
-     * This method is called if the user clicks on the 'next' button to advance
-     * to the next state.
-     *
-     * @param event The StepForwardEvent.
-     */
-    public void onStepForward(StepForwardEvent event) {
-        GWT.log("CollectionView - onStepForward()");
-        String serverUrl = Config.getInstance().getServerUrl();
-
-        forwardService.go(serverUrl, artifact, event.getData(),
-            new AsyncCallback<Artifact>() {
-                public void onFailure(Throwable caught) {
-                    GWT.log("Could not feed the artifact.");
-                    GWT.log(caught.getMessage());
-                }
-
-                public void onSuccess(Artifact artifact) {
-                    GWT.log("Successfully feed the artifact.");
-                    setArtifact(artifact);
-                }
-        });
-    }
-
-
-    /**
      * Update the view (refresh the list of old and current data).
      */
     protected void updateView() {
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Sat Mar 26 18:07:41 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Mon Mar 28 06:48:44 2011 +0000
@@ -4,6 +4,7 @@
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.types.VerticalAlignment;
 import com.smartgwt.client.widgets.Canvas;
@@ -13,21 +14,61 @@
 import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.ArtifactDescription;
 import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.DataList;
+import de.intevation.flys.client.shared.model.DefaultData;
+import de.intevation.flys.client.shared.model.DefaultDataItem;
+import de.intevation.flys.client.shared.model.River;
+import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.client.FLYS;
+import de.intevation.flys.client.client.FLYSMessages;
+import de.intevation.flys.client.client.event.HasParameterChangeHandler;
 import de.intevation.flys.client.client.event.HasStepBackHandlers;
 import de.intevation.flys.client.client.event.HasStepForwardHandlers;
 import de.intevation.flys.client.client.event.ParameterChangeEvent;
 import de.intevation.flys.client.client.event.ParameterChangeHandler;
 import de.intevation.flys.client.client.event.StepBackEvent;
 import de.intevation.flys.client.client.event.StepBackHandler;
+import de.intevation.flys.client.client.event.StepForwardEvent;
+import de.intevation.flys.client.client.event.StepForwardHandler;
+import de.intevation.flys.client.client.services.AdvanceService;
+import de.intevation.flys.client.client.services.AdvanceServiceAsync;
+import de.intevation.flys.client.client.services.ArtifactService;
+import de.intevation.flys.client.client.services.ArtifactServiceAsync;
+import de.intevation.flys.client.client.services.StepForwardService;
+import de.intevation.flys.client.client.services.StepForwardServiceAsync;
 
 
 public class ParameterList
-extends      VLayout
-implements   StepBackHandler, ParameterChangeHandler
+extends      HLayout
+implements   StepBackHandler, StepForwardHandler, ParameterChangeHandler,
+             HasParameterChangeHandler
 {
+    /** The message class that provides i18n strings.*/
+    protected FLYSMessages MSG = GWT.create(FLYSMessages.class);
+
+    /** The ArtifactService used to communicate with the Artifact server. */
+    protected ArtifactServiceAsync artifactService =
+        GWT.create(ArtifactService.class);
+
+    /** The StepForwardService used to put data into an existing artifact. */
+    protected StepForwardServiceAsync forwardService =
+        GWT.create(StepForwardService.class);
+
+    /** The StepForwardService used to put data into an existing artifact. */
+    protected AdvanceServiceAsync advanceService =
+        GWT.create(AdvanceService.class);
+
+
+    /** The list of ParameterizationChangeHandler.*/
+    protected List<ParameterChangeHandler> parameterHandlers;
+
+    protected FLYS flys;
+
     protected CollectionView cView;
 
+    protected Artifact artifact;
+
     protected List<DataList> old;
     protected DataList   current;
 
@@ -36,28 +77,147 @@
     protected VLayout oldItems;
     protected VLayout currentItems;
 
-    public ParameterList(CollectionView cView) {
-        this.cView   = cView;
-        old          = new ArrayList<DataList>();
-        oldItems     = new VLayout();
-        currentItems = new VLayout();
+    public ParameterList(FLYS flys, CollectionView cView) {
+        this.cView = cView;
+        this.flys  = flys;
+
+        parameterHandlers = new ArrayList<ParameterChangeHandler>();
+        old               = new ArrayList<DataList>();
+        oldItems          = new VLayout();
+        currentItems      = new VLayout();
 
         init();
     }
 
 
     protected void init() {
-        setWidth(300);
+        setMembersMargin(20);
+
+        VLayout left = new VLayout();
 
         oldItems.setHeight(20);
         oldItems.setMembersMargin(10);
         currentItems.setHeight("*");
         currentItems.setAlign(VerticalAlignment.TOP);
 
-        setMembersMargin(20);
+        left.setMembersMargin(20);
+        left.setWidth(300);
 
-        addMember(oldItems);
-        addMember(currentItems);
+        left.addMember(oldItems);
+        left.addMember(currentItems);
+
+        // This canvas is used to render helper widgets
+        Canvas right = new Canvas();
+
+        addMember(left);
+        addMember(right);
+
+        Canvas moduleSelection = renderNew();
+        moduleSelection.setLayoutAlign(VerticalAlignment.TOP);
+        currentItems.addMember(moduleSelection);
+    }
+
+
+    protected void setArtifact(Artifact artifact) {
+        Artifact tmp  = this.artifact;
+        this.artifact = artifact;
+
+        fireParameterChangeEvent(tmp, this.artifact);
+    }
+
+
+    /**
+     * This method registers a new ParameterChangeHandler.
+     *
+     * @param handler The new ParameterChangeHandler.
+     */
+    public void addParameterChangeHandler(ParameterChangeHandler handler) {
+        if (handler != null) {
+            parameterHandlers.add(handler);
+        }
+    }
+
+
+    /**
+     * This method calls the <code>onParameterChange()</code> method of all
+     * registered ParameterChangeHandler.
+     */
+    protected void fireParameterChangeEvent(Artifact old, Artifact newArt) {
+        for (ParameterChangeHandler handler: parameterHandlers) {
+            handler.onParameterChange(new ParameterChangeEvent(old, newArt));
+        }
+    }
+
+
+    /**
+     * This method creates a Canvas displaying the plugins of FLYS combined with
+     * a widget to select a river.
+     *
+     * @return a Canvas that displays the supported plugins and rivers of FLYS.
+     */
+    protected Canvas renderNew() {
+        River[] rivers   = flys.getRivers();
+        DataItem[] items = new DataItem[rivers.length];
+
+        int i = 0;
+        for (River river: rivers) {
+            String name = river.getName();
+            items[i++]  = new DefaultDataItem(name, null, name);
+        }
+
+        Data data = new DefaultData(
+            "river",
+            MSG.river_selection(),
+            null,
+            items);
+
+        ModuleSelection widget         = new ModuleSelection();
+        HasStepForwardHandlers handler = (HasStepForwardHandlers) widget;
+
+        handler.addStepForwardHandler(new StepForwardHandler() {
+            public void onStepForward(StepForwardEvent event) {
+                Data[] data = event.getData();
+
+                DataItem[] moduleItems = data[0].getItems();
+                DataItem[] riversItems = data[1].getItems();
+
+                String module = moduleItems[0].getStringValue();
+                String river  = riversItems[0].getStringValue();
+
+                final String serverUrl = Config.getInstance().getServerUrl();
+                final Data[] feedData  = new Data[] { data[1] };
+                artifactService.create(
+                    serverUrl, module.toLowerCase(),
+                    new AsyncCallback<Artifact>() {
+                        public void onFailure(Throwable caught) {
+                            GWT.log("Could not create the new artifact.");
+                            GWT.log(caught.getMessage());
+                        }
+
+                        public void onSuccess(Artifact artifact) {
+                            GWT.log("Successfully created a new artifact.");
+
+                            forwardService.go(serverUrl, artifact, feedData,
+                            new AsyncCallback<Artifact>() {
+                                public void onFailure(Throwable caught) {
+                                    GWT.log("Could not feed the artifact.");
+                                    GWT.log(caught.getMessage());
+                                }
+
+                                public void onSuccess(Artifact artifact) {
+                                    GWT.log("Successfully feed the artifact.");
+                                    setArtifact(artifact);
+                                }
+                            });
+                        }
+                });
+            }
+        });
+
+        DataList list = new DataList();
+        list.add(data);
+
+        return widget.create(list);
     }
 
 
@@ -124,7 +284,6 @@
 
             String     provider   = dataList.getUIProvider();
             UIProvider uiprovider = UIProviderFactory.getProvider(provider);
-            ((HasStepBackHandlers) uiprovider).addStepBackHandler(cView);
             ((HasStepBackHandlers) uiprovider).addStepBackHandler(this);
 
             oldItems.addMember(uiprovider.createOld(dataList));
@@ -157,14 +316,57 @@
 
 
     /**
+     * This method is called if the user clicks on the 'next' button to advance
+     * to the next state.
+     *
+     * @param event The StepForwardEvent.
+     */
+    public void onStepForward(StepForwardEvent event) {
+        GWT.log("CollectionView - onStepForward()");
+        String serverUrl = Config.getInstance().getServerUrl();
+
+        forwardService.go(serverUrl, artifact, event.getData(),
+            new AsyncCallback<Artifact>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not feed the artifact.");
+                    GWT.log(caught.getMessage());
+                }
+
+                public void onSuccess(Artifact artifact) {
+                    GWT.log("Successfully feed the artifact.");
+                    setArtifact(artifact);
+                }
+        });
+    }
+
+
+    /**
      * This method is used to remove all old items from this list after the user
      * has clicked the step back button.
      *
-     * @param e The StepBackEvent.
+     * @param e The StepBackEvent that holds the identifier of the target state.
      */
     public void onStepBack(StepBackEvent e) {
-        old.clear();
-        oldItems.removeMembers(oldItems.getMembers());
+        final String target    = e.getTarget();
+        final String serverUrl = Config.getInstance().getServerUrl();
+
+        advanceService.advance(serverUrl, artifact, target,
+            new AsyncCallback<Artifact>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not go back to '" + target + "'");
+                    GWT.log(caught.getMessage());
+                }
+
+                public void onSuccess(Artifact artifact) {
+                    GWT.log("Successfully step back to '" + target + "'");
+
+                    old.clear();
+                    oldItems.removeMembers(oldItems.getMembers());
+
+                    setArtifact(artifact);
+                }
+            }
+        );
     }
 
 
@@ -186,8 +388,8 @@
             String uiProvider   = currentData.getUIProvider();
             UIProvider provider = UIProviderFactory.getProvider(uiProvider);
 
-            ((HasStepForwardHandlers) provider).addStepForwardHandler(cView);
-            ((HasStepBackHandlers) provider).addStepBackHandler(cView);
+            ((HasStepForwardHandlers) provider).addStepForwardHandler(this);
+            ((HasStepBackHandlers) provider).addStepBackHandler(this);
 
             setCurrentData(currentData, provider);
         }

http://dive4elements.wald.intevation.org