diff flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java @ 4254:33b15ac17fd1

Only create and add GaugePanel when necessary The GaugePanel isn't created always and only show if WINFO and a river is selected now. It is only created on demand. Therefore all access to the GaugePanel is abstraced via methods that check if the GaugePanel is null before accessing it's methods.
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 25 Oct 2012 13:58:53 +0200
parents 207de712d79d
children cde9a6fe1844
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Thu Oct 25 13:52:58 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Thu Oct 25 13:58:53 2012 +0200
@@ -115,6 +115,8 @@
     protected GaugePanel gaugePanel;
     protected Canvas  reportPanel;
 
+    private SectionStack stack;
+
     public ParameterList(FLYS flys, CollectionView cView, String title) {
         super(title);
 
@@ -206,18 +208,11 @@
 
 
     protected SectionStack createSectionStack() {
-        final SectionStack stack = new SectionStack();
+        stack = new SectionStack();
         stack.setHeight100();
         stack.setCanResizeSections(true);
         stack.setVisibilityMode(VisibilityMode.MULTIPLE);
 
-        final SectionStackSection gaugeSection = new SectionStackSection();
-        gaugeSection.setExpanded(false);
-        gaugeSection.setTitle(MSG.gaugePanelTitle());
-        gaugePanel = new GaugePanel(flys, gaugeSection);
-        gaugePanel.setWidth100();
-        gaugePanel.setHeight100();
-
         // This canvas is used to render helper widgets.
         final SectionStackSection helperSection = new SectionStackSection();
         helperSection.setExpanded(false);
@@ -260,7 +255,7 @@
         tablePanel.setWidth100();
         tableSection.setItems(tablePanel);
 
-        stack.setSections(gaugeSection, helperSection, tableSection);
+        stack.setSections(helperSection, tableSection);
 
         return stack;
     }
@@ -758,13 +753,17 @@
         }
         if (art instanceof WINFOArtifact) {
             String river = desc.getRiver();
+
             if (river != null) {
                 renderGaugeInfo(desc.getRiver(), desc.getOldData());
             }
             else {
-                gaugePanel.hide();
+                hideGaugePanel();
             }
         }
+        else {
+            removeGaugePanel();
+        }
 
         addOldDatas(
             desc.getOldData(),
@@ -943,10 +942,51 @@
     }
 
 
+    private void createGaugePanel() {
+        GWT.log("ParameterList - createGaugePanel");
+        if (gaugePanel == null) {
+            gaugePanel = new GaugePanel(flys);
+            gaugePanel.setWidth100();
+            gaugePanel.setHeight100();
+        }
+    }
+
+    private void addGaugePanel() {
+        GWT.log("ParameterList - addGaugePanel");
+        createGaugePanel();
+        stack.addSection(gaugePanel.getSection(), 0);
+    }
+
+    private void showGaugePanel() {
+        GWT.log("ParameterList - showGaugePanel");
+
+        /* Don't add GaugePanel twice */
+        SectionStackSection exists = stack.getSection(GaugePanel.SECTION_ID);
+        if (exists == null) {
+            addGaugePanel();
+        }
+
+        gaugePanel.show();
+    }
+
+    private void hideGaugePanel() {
+        GWT.log("ParameterList - hideGaugePanel");
+
+        if (gaugePanel != null) {
+            gaugePanel.hide();
+        }
+    }
+
+    private void removeGaugePanel() {
+        GWT.log("ParameterList - removeGaugePanel");
+        stack.removeSection(GaugePanel.SECTION_ID);
+    }
+
+
     private void renderGaugeInfo(String river, DataList[] data) {
+        showGaugePanel();
         gaugePanel.setRiver(river);
         gaugePanel.setData(data);
-        gaugePanel.show();
     }
 
 }

http://dive4elements.wald.intevation.org