diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapThemePanel.java @ 9483:992c188b7330

wms uinfo.inundation
author gernotbelger
date Thu, 13 Sep 2018 18:22:05 +0200
parents 05405292a7ca
children
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapThemePanel.java	Wed Sep 12 12:50:28 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapThemePanel.java	Thu Sep 13 18:22:05 2018 +0200
@@ -8,8 +8,16 @@
 
 package org.dive4elements.river.client.client.ui.map;
 
+import org.dive4elements.river.client.client.FLYSConstants;
+import org.dive4elements.river.client.client.ui.CollectionView;
+import org.dive4elements.river.client.client.ui.NoopThemeRecordHandler;
+import org.dive4elements.river.client.client.ui.ThemePanel;
+import org.dive4elements.river.client.shared.model.AttributedTheme;
+import org.dive4elements.river.client.shared.model.FacetRecord;
+import org.dive4elements.river.client.shared.model.OutputMode;
+import org.dive4elements.river.client.shared.model.Theme;
+
 import com.google.gwt.core.client.GWT;
-
 import com.smartgwt.client.types.ListGridFieldType;
 import com.smartgwt.client.util.BooleanCallback;
 import com.smartgwt.client.util.SC;
@@ -23,16 +31,6 @@
 import com.smartgwt.client.widgets.menu.events.ClickHandler;
 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
 
-import org.dive4elements.river.client.client.FLYSConstants;
-import org.dive4elements.river.client.client.ui.CollectionView;
-import org.dive4elements.river.client.client.ui.NoopThemeRecordHandler;
-import org.dive4elements.river.client.client.ui.ThemePanel;
-import org.dive4elements.river.client.shared.model.AttributedTheme;
-import org.dive4elements.river.client.shared.model.FacetRecord;
-import org.dive4elements.river.client.shared.model.OutputMode;
-import org.dive4elements.river.client.shared.model.Theme;
-
-
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
@@ -40,12 +38,10 @@
 
     public static final int CELL_HEIGHT = 25;
 
-
     public interface ActivateCallback {
         void activate(Theme theme, boolean activate);
     }
 
-
     public interface ThemeMovedCallback {
         void onThemeMoved(Theme theme, int oldIdx, int newIdx);
     }
@@ -54,39 +50,27 @@
         void onLayerZoom(Theme theme, String extent);
     }
 
-
-
-    private FLYSConstants MSG = GWT.create(FLYSConstants.class);
+    private final FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
-
-    protected ActivateCallback   activateCallback;
+    protected ActivateCallback activateCallback;
     protected ThemeMovedCallback themeMovedCallback;
-    protected LayerZoomCallback  layerZoomCallback;
+    protected LayerZoomCallback layerZoomCallback;
 
     protected ListGridRecord[] oldRecords;
 
-
     public static final String GRID_FIELD_ACTIVE = "active";
-    public static final String GRID_FIELD_NAME   = "name";
-
+    public static final String GRID_FIELD_NAME = "name";
 
     protected MapOutputTab mapOut;
 
-
-    public MapThemePanel(
-        CollectionView     view,
-        OutputMode         mode,
-        MapOutputTab       mapOut,
-        ActivateCallback   activateCallback,
-        ThemeMovedCallback themeMovedCallback,
-        LayerZoomCallback  layerZoomCallback
-    ) {
+    public MapThemePanel(final CollectionView view, final OutputMode mode, final MapOutputTab mapOut, final ActivateCallback activateCallback,
+            final ThemeMovedCallback themeMovedCallback, final LayerZoomCallback layerZoomCallback) {
         super(mode, view, new NoopThemeRecordHandler());
 
-        this.mapOut             = mapOut;
-        this.activateCallback   = activateCallback;
+        this.mapOut = mapOut;
+        this.activateCallback = activateCallback;
         this.themeMovedCallback = themeMovedCallback;
-        this.layerZoomCallback  = layerZoomCallback;
+        this.layerZoomCallback = layerZoomCallback;
 
         initGrid();
         initLayout();
@@ -94,74 +78,69 @@
         updateGrid();
     }
 
-
     protected void initLayout() {
         setWidth100();
         setHeight100();
 
-        VLayout layout = new VLayout();
+        final VLayout layout = new VLayout();
         layout.setWidth100();
         layout.setHeight100();
 
-        layout.addMember(list);
-        layout.addMember(navigation);
+        layout.addMember(this.list);
+        layout.addMember(this.navigation);
 
         addChild(layout);
     }
 
-
     protected void initGrid() {
-        list.setCanEdit(true);
-        list.setCanSort(false);
-        list.setShowRecordComponents(false);
-        list.setShowRecordComponentsByCell(true);
-        list.setShowHeader(true);
-        list.setShowHeaderContextMenu(false);
-        list.setCanReorderFields(false);
-        list.setWidth100();
-        list.setHeight100();
+        this.list.setCanEdit(true);
+        this.list.setCanSort(false);
+        this.list.setShowRecordComponents(false);
+        this.list.setShowRecordComponentsByCell(true);
+        this.list.setShowHeader(true);
+        this.list.setShowHeaderContextMenu(false);
+        this.list.setCanReorderFields(false);
+        this.list.setWidth100();
+        this.list.setHeight100();
 
-        list.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() {
+        this.list.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() {
             @Override
-            public void onHeaderDoubleClick(HeaderDoubleClickEvent event) {
+            public void onHeaderDoubleClick(final HeaderDoubleClickEvent event) {
                 // cancel the event.
                 return;
             }
         });
 
-        list.setCellHeight(CELL_HEIGHT);
-        list.setShowRecordComponents(true);
-        list.setShowRecordComponentsByCell(true);
-        list.setShowAllRecords(true);
+        this.list.setCellHeight(CELL_HEIGHT);
+        this.list.setShowRecordComponents(true);
+        this.list.setShowRecordComponentsByCell(true);
+        this.list.setShowAllRecords(true);
 
-        list.addEditCompleteHandler(this);
+        this.list.addEditCompleteHandler(this);
 
-        ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20);
+        final ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20);
         active.setType(ListGridFieldType.BOOLEAN);
         active.setCanDragResize(false);
 
-        ListGridField name = new ListGridField(
-            GRID_FIELD_NAME, MSG.chart_themepanel_header_themes());
+        final ListGridField name = new ListGridField(GRID_FIELD_NAME, this.MSG.chart_themepanel_header_themes());
         name.setType(ListGridFieldType.TEXT);
 
-        list.setFields(active, name);
+        this.list.setFields(active, name);
     }
 
-
     @Override
     protected void clearGrid() {
-        oldRecords = list.getRecords();
+        this.oldRecords = this.list.getRecords();
         super.clearGrid();
     }
 
-
     @Override
-    protected void addFacetRecord(FacetRecord rec) {
-        Theme newTheme = rec.getTheme();
-        boolean  isNew = true;
+    protected void addFacetRecord(final FacetRecord rec) {
+        final Theme newTheme = rec.getTheme();
+        boolean isNew = true;
 
-        for (ListGridRecord old: getOldRecords()) {
-            FacetRecord fr = (FacetRecord) old;
+        for (final ListGridRecord old : getOldRecords()) {
+            final FacetRecord fr = (FacetRecord) old;
 
             if (newTheme.equals(fr.getTheme())) {
                 isNew = false;
@@ -169,19 +148,17 @@
             }
         }
 
-        if (isNew && mapOut != null) {
-            mapOut.addLayer(mapOut.createWMSLayer(newTheme));
-        }
+        if (isNew && this.mapOut != null)
+            this.mapOut.addLayer(newTheme);
 
         super.addFacetRecord(rec);
     }
 
-
     @Override
     protected Menu getSingleContextMenu(final ListGridRecord[] records) {
-        Menu menu = super.getSingleContextMenu(records);
+        final Menu menu = super.getSingleContextMenu(records);
 
-        MenuItem layerZoom = createLayerZoomItem(records);
+        final MenuItem layerZoom = createLayerZoomItem(records);
         if (layerZoom != null) {
             menu.addItem(layerZoom);
         }
@@ -190,45 +167,42 @@
         return menu;
     }
 
-
     protected MenuItem createMapURLItem(final ListGridRecord[] records) {
-        final FacetRecord     fr = (FacetRecord) records[0];
-        final AttributedTheme at = (AttributedTheme) fr.getTheme();
+        final FacetRecord fr = (FacetRecord) records[0];
+        final Theme theme = fr.getTheme();
+        final AttributedTheme at = (AttributedTheme) theme;
 
-        MenuItem item = new MenuItem(MSG.wmsURLMenuItem());
+        final MenuItem item = new MenuItem(this.MSG.wmsURLMenuItem());
         item.addClickHandler(new ClickHandler() {
             @Override
-            public void onClick(MenuItemClickEvent evt) {
-                String url = getMapOutputTab().wmsUrls().get(
-                    at.getAttr("layers"));
-                SC.say(MSG.wmsURLBoxTitle(), url);
+            public void onClick(final MenuItemClickEvent evt) {
+                final String url = getMapOutputTab().getWMSUrl(theme);
+
+                SC.say(MapThemePanel.this.MSG.wmsURLBoxTitle(), url);
             }
         });
 
         return item;
     }
 
-
     @Override
     protected MenuItem createRemoveItem(final ListGridRecord[] records) {
-        MenuItem item = super.createRemoveItem(records);
+        final MenuItem item = super.createRemoveItem(records);
         item.addClickHandler(new ClickHandler() {
             @Override
-            public void onClick(MenuItemClickEvent evt) {
-                SC.ask(MSG.askThemeRemove(), new BooleanCallback() {
+            public void onClick(final MenuItemClickEvent evt) {
+                SC.ask(MapThemePanel.this.MSG.askThemeRemove(), new BooleanCallback() {
                     @Override
-                    public void execute(Boolean value) {
+                    public void execute(final Boolean value) {
                         if (value) {
-                            for (ListGridRecord record: records) {
-                                FacetRecord facet = (FacetRecord) record;
+                            for (final ListGridRecord record : records) {
+                                final FacetRecord facet = (FacetRecord) record;
 
-                                Theme theme = facet.getTheme();
+                                final Theme theme = facet.getTheme();
                                 theme.setVisible(0);
                                 theme.setActive(0);
 
-                                AttributedTheme at = (AttributedTheme) theme;
-                                getMapOutputTab().removeLayer(
-                                    at.getAttr("layers"));
+                                getMapOutputTab().removeLayer(theme);
                             }
 
                             updateCollection();
@@ -241,9 +215,8 @@
         return item;
     }
 
-
     protected MenuItem createLayerZoomItem(final ListGridRecord[] recs) {
-        final FacetRecord     fr = (FacetRecord) recs[0];
+        final FacetRecord fr = (FacetRecord) recs[0];
         final AttributedTheme at = (AttributedTheme) fr.getTheme();
 
         final String extent = at.getAttr("extent");
@@ -252,12 +225,12 @@
             return null;
         }
 
-        MenuItem zoom = new MenuItem(MSG.zoomToLayer());
+        final MenuItem zoom = new MenuItem(this.MSG.zoomToLayer());
         zoom.addClickHandler(new ClickHandler() {
             @Override
-            public void onClick(MenuItemClickEvent evt) {
-                if (layerZoomCallback != null) {
-                    layerZoomCallback.onLayerZoom(at, extent);
+            public void onClick(final MenuItemClickEvent evt) {
+                if (MapThemePanel.this.layerZoomCallback != null) {
+                    MapThemePanel.this.layerZoomCallback.onLayerZoom(at, extent);
                 }
             }
         });
@@ -267,39 +240,35 @@
 
     @Override
     public String getWidthAsString() {
-        if(!isVisible()) {
+        if (!isVisible()) {
             return "0";
-        }
-        else {
+        } else {
             return super.getWidthAsString();
         }
     }
 
     @Override
-    public void activateTheme(Theme theme, boolean active) {
-        if (activateCallback != null) {
-            activateCallback.activate(theme, active);
+    public void activateTheme(final Theme theme, final boolean active) {
+        if (this.activateCallback != null) {
+            this.activateCallback.activate(theme, active);
         }
 
         theme.setActive(active ? 1 : 0);
     }
 
-
     @Override
-    protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) {
-        if (themeMovedCallback != null) {
-            themeMovedCallback.onThemeMoved(theme, oldIdx, newIdx);
+    protected void fireThemeMoved(final Theme theme, final int oldIdx, final int newIdx) {
+        if (this.themeMovedCallback != null) {
+            this.themeMovedCallback.onThemeMoved(theme, oldIdx, newIdx);
         }
     }
 
-
     protected ListGridRecord[] getOldRecords() {
-        return oldRecords != null ? oldRecords : new ListGridRecord[0];
+        return this.oldRecords != null ? this.oldRecords : new ListGridRecord[0];
     }
 
-
     protected MapOutputTab getMapOutputTab() {
-        return mapOut;
+        return this.mapOut;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org