changeset 1533:7fcec57c2f2c

Add cross sections loaded from datacage to the master artifacts list. flys-client/trunk@3743 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 20 Jan 2012 15:47:14 +0000
parents 916c94b32be2
children 98123d34529b
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java
diffstat 2 files changed, 96 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Jan 20 09:54:15 2012 +0000
+++ b/flys-client/ChangeLog	Fri Jan 20 15:47:14 2012 +0000
@@ -1,3 +1,10 @@
+2012-01-20  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Add cross sections loaded from datacage to the master artifacts list.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java:
+	  Overrides updateGrid() to update the list of master artifacts, too.
+
 2012-01-20  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Fix flys/issue458 (typo).
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Fri Jan 20 09:54:15 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Fri Jan 20 15:47:14 2012 +0000
@@ -86,6 +86,11 @@
     /** Whether or not to move through all cross sections synchronously. */
     protected boolean synchronNavigation;
 
+    /** Data for master artifact combobox.*/
+    protected LinkedHashMap<String, String> masters;
+
+    /** Combobox for master artifacts.*/
+    protected SelectItem masterCb;
 
     /**
      * Trivial constructor.
@@ -183,27 +188,26 @@
         layout = super.createLayout();
 
         // Create "set master" combobox.
-        SelectItem cbItem = new SelectItem();
+        masterCb = new SelectItem();
 
-        cbItem.setTitle(MSG.chart_themepanel_set_master());
-        cbItem.setType("comboBox");
-        final LinkedHashMap<String, String> valueMap =
-            getThemeList().toMapArtifactUUIDDescription("cross_section");
-        cbItem.setValueMap(valueMap);
+        masterCb.setTitle(MSG.chart_themepanel_set_master());
+        masterCb.setType("comboBox");
+        masters = getThemeList().toMapArtifactUUIDDescription("cross_section");
+        masterCb.setValueMap(masters);
 
         final DynamicForm form = new DynamicForm();
         form.setWidth(200);
-        form.setFields(cbItem);
+        form.setFields(masterCb);
         layout.addMember(form);
 
         Config config       = Config.getInstance();
         final String locale = config.getLocale();
         findCurrentCSMaster();
-        cbItem.setValue(getCurrentCSMaster());
+        masterCb.setValue(getCurrentCSMaster());
 
         // Add Change Handler to first unset the old master and then set the
         // new master.
-        cbItem.addChangeHandler(new ChangeHandler() {
+        masterCb.addChangeHandler(new ChangeHandler() {
             public void onChange(ChangeEvent event) {  
                 String selectedItem   = (String) event.getValue();
                 final String artifact = selectedItem;
@@ -609,5 +613,81 @@
 
         return contextMenu;
     }
+
+
+    /**
+     * This method is used to clear the current theme grid and add new updated
+     * data.
+     */
+    @Override
+    protected void updateGrid() {
+        GWT.log("CrossSectionChartThemePanel.updateGrid");
+
+        ListGridRecord[] selected = list.getSelectedRecords();
+
+        clearGrid();
+
+        ThemeList themeList = getThemeList();
+
+        if (themeList == null) {
+            GWT.log("ERROR: No theme list.");
+            return;
+        }
+
+        int count = themeList.getThemeCount();
+
+        for (int i = 1; i <= count; i++) {
+            Theme theme = themeList.getThemeAt(i);
+
+            if(theme.getFacet().equals("empty.facet")) {
+                theme.setVisible(0);
+            }
+
+            if (theme == null || theme.getVisible() == 0) {
+                continue;
+            }
+
+            if (theme.getFacet().equals("cross_section")) {
+                addToReferences(theme);
+            }
+
+            FacetRecord newRecord = createRecord(theme);
+            addFacetRecord(newRecord);
+
+            String newArtifact = theme.getArtifact();
+            String newFacet    = theme.getFacet();
+            int    newIndex    = theme.getIndex();
+
+            for (ListGridRecord r: selected) {
+                FacetRecord sel = (FacetRecord) r;
+                Theme oldTheme  = sel.getTheme();
+
+                if (oldTheme.getArtifact().equals(newArtifact)
+                    && oldTheme.getFacet().equals(newFacet)
+                    && oldTheme.getIndex() == newIndex) {
+                    list.selectRecord(newRecord);
+                }
+            }
+        }
+
+        fireOutputParameterChanged();
+
+    }
+
+
+    /**
+     * Adds a cross section theme to the master artifacts combobox and finds
+     * a new master if necessary.
+     *
+     * @param theme The cross section theme.
+     */
+    protected void addToReferences(Theme theme) {
+        masters.put(theme.getArtifact(), theme.getDescription());
+        masterCb.setValueMap(masters);
+        findCurrentCSMaster();
+        if (masterCb.getSelectedRecord() == null) {
+            masterCb.setValue(getCurrentCSMaster());
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org