diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java @ 1382:78542ff1f562

Update map and theme panel when new layers are added via datacage or removed by context menu. flys-client/trunk@3155 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Nov 2011 14:51:16 +0000
parents b0fe35d4ce6b
children 6a7cfe9d87fe
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java	Tue Nov 01 16:07:39 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java	Thu Nov 03 14:51:16 2011 +0000
@@ -59,6 +59,8 @@
     protected ThemeMovedCallback themeMovedCallback;
     protected LayerZoomCallback  layerZoomCallback;
 
+    protected ListGridRecord[] oldRecords;
+
 
     public static final String GRID_FIELD_ACTIVE = "active";
     public static final String GRID_FIELD_STYLE  = "style";
@@ -70,22 +72,25 @@
 
     public MapThemePanel(
         Collection         collection,
+        MapOutputTab       mapOut,
         OutputMode         mode,
         ActivateCallback   activateCallback
     ) {
-        this(collection, mode, activateCallback, null, null);
+        this(collection, mode, mapOut, activateCallback, null, null);
     }
 
 
     public MapThemePanel(
         Collection         collection,
         OutputMode         mode,
+        MapOutputTab       mapOut,
         ActivateCallback   activateCallback,
         ThemeMovedCallback themeMovedCallback,
         LayerZoomCallback  layerZoomCallback
     ) {
         super(collection, mode);
 
+        this.mapOut             = mapOut;
         this.activateCallback   = activateCallback;
         this.themeMovedCallback = themeMovedCallback;
         this.layerZoomCallback  = layerZoomCallback;
@@ -184,6 +189,35 @@
 
 
     @Override
+    protected void clearGrid() {
+        oldRecords = list.getRecords();
+        super.clearGrid();
+    }
+
+
+    @Override
+    protected void addFacetRecord(FacetRecord rec) {
+        Theme newTheme = rec.getTheme();
+        boolean  isNew = true;
+
+        for (ListGridRecord old: getOldRecords()) {
+            FacetRecord fr = (FacetRecord) old;
+
+            if (newTheme.equals(fr.getTheme())) {
+                isNew = false;
+                break;
+            }
+        }
+
+        if (isNew && mapOut != null) {
+            mapOut.addLayer(mapOut.createWMSLayer(newTheme));
+        }
+
+        super.addFacetRecord(rec);
+    }
+
+
+    @Override
     protected Menu getSingleContextMenu(final ListGridRecord[] records) {
         Menu menu = super.getSingleContextMenu(records);
 
@@ -196,6 +230,30 @@
     }
 
 
+    @Override
+    protected MenuItem createRemoveItem(final ListGridRecord[] records) {
+        MenuItem item = super.createRemoveItem(records);
+        item.addClickHandler(new ClickHandler() {
+            @Override
+            public void onClick(MenuItemClickEvent evt) {
+                for (ListGridRecord record: records) {
+                    FacetRecord facet = (FacetRecord) record;
+
+                    Theme theme = facet.getTheme();
+                    theme.setVisible(0);
+                    theme.setActive(0);
+
+                    getMapOutputTab().removeLayer(theme.getDescription());
+                }
+
+                updateCollection();
+            }
+        });
+
+        return item;
+    }
+
+
     protected MenuItem createLayerZoomItem(final ListGridRecord[] recs) {
         final FacetRecord     fr = (FacetRecord) recs[0];
         final AttributedTheme at = (AttributedTheme) fr.getTheme();
@@ -236,5 +294,15 @@
             themeMovedCallback.onThemeMoved(theme, oldIdx, newIdx);
         }
     }
+
+
+    protected ListGridRecord[] getOldRecords() {
+        return oldRecords != null ? oldRecords : new ListGridRecord[0];
+    }
+
+
+    protected MapOutputTab getMapOutputTab() {
+        return mapOut;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org