diff flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 74:c5586446f3c0

Available output modes are displayed in the tab bar of the collection view. flys-client/trunk@1577 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 28 Mar 2011 07:09:34 +0000
parents 39210a74db07
children 571843833129
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Mon Mar 28 06:48:44 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Mon Mar 28 07:09:34 2011 +0000
@@ -1,7 +1,10 @@
 package de.intevation.flys.client.client.ui;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.DateTimeFormat;
@@ -73,7 +76,7 @@
     protected Tab parameterTab;
 
     /** The output tab.*/
-    protected Tab outputTab;
+    protected Map<String, OutputTab> outputTabs;
 
     /** The layout.*/
     protected Layout layout;
@@ -91,6 +94,7 @@
 
         this.tabs              = new TabSet();
         this.parameterTab      = new Tab(messages.winfo());
+        this.outputTabs        = new HashMap<String, OutputTab>();
         this.parameterList     = new ParameterList(flys, this);
         this.handlers          = new ArrayList<CollectionChangeHandler>();
         this.layout            = new VLayout();
@@ -240,6 +244,7 @@
      * @param event The ParameterChangeEvent.
      */
     public void onParameterChange(ParameterChangeEvent event) {
+        GWT.log("Parameter have changed.");
         Artifact art             = event.getNewValue();
         ArtifactDescription desc = art.getArtifactDescription();
         OutputMode[] outs        = desc.getOutputModes();
@@ -251,12 +256,23 @@
             createNewCollection(user.identifier());
         }
         else {
+            clearOutputTabs();
             updateView();
         }
     }
 
 
     /**
+     * Returns the collection of displayed by this view.
+     *
+     * @return the collection of this view.
+     */
+    protected Collection getCollection() {
+        return collection;
+    }
+
+
+    /**
      * Set the current collection.
      *
      * @param collection The new collection.
@@ -270,18 +286,68 @@
 
 
     public void onCollectionChange(CollectionChangeEvent event) {
+        Collection newCol = event.getNewValue();
+
+        Map<String, OutputMode> outs = newCol.getOutputModes();
+
+        Set<String> keys = outs.keySet();
+        for (String outname: keys) {
+            addOutputTab(outname, outs.get(outname));
+        }
+
         updateView();
     }
 
 
     /**
+     * Adds a new tab for the OutputMode <i>out</i>.
+     *
+     * @param name The name and title of the output.
+     */
+    protected void addOutputTab(String name, OutputMode out) {
+        GWT.log("Add new output tab for '" + name + "'");
+        OutputTab tab = new OutputTab(name, getCollection(), out);
+        outputTabs.put(name, tab);
+    }
+
+
+    /**
+     * Removes all output mode tabs from tab bar.
+     */
+    protected void clearOutputTabs() {
+        GWT.log("Clear OutputTabs.");
+
+        int num = tabs.getNumTabs();
+
+        for (int i = num-1; i >= 1; i--) {
+            tabs.removeTab(i);
+        }
+
+        outputTabs.clear();
+    }
+
+
+    /**
      * Update the view (refresh the list of old and current data).
      */
     protected void updateView() {
         GWT.log("CollectionView.updateView()");
+        updateOutputTabs();
+    }
 
-        tabs.setTabTitle(0, messages.winfo());
-        tabs.updateTab(0, parameterList);
+
+    /**
+     * This method is used to update the tabs to show specific output modes.
+     */
+    protected void updateOutputTabs() {
+        GWT.log("Update output tabs.");
+        if (outputTabs != null) {
+            Set<String> keys = outputTabs.keySet();
+
+            for (String key: keys) {
+                tabs.addTab(outputTabs.get(key));
+            }
+        }
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org