diff flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java @ 1309:a95e82d6bcc1

Refactored the code to create a context menu and a style editor so that it is also available for maps. flys-client/trunk@2943 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 12 Oct 2011 08:53:17 +0000
parents 84c50f1d939b
children c4c957a9c092
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java	Wed Oct 12 07:41:04 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java	Wed Oct 12 08:53:17 2011 +0000
@@ -12,8 +12,15 @@
 import com.smartgwt.client.widgets.grid.ListGridRecord;
 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
+import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
+import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
+import com.smartgwt.client.widgets.menu.Menu;
+import com.smartgwt.client.widgets.menu.MenuItem;
+import com.smartgwt.client.widgets.menu.events.ClickHandler;
+import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
 
 import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.shared.model.CollectionItemAttribute;
 import de.intevation.flys.client.shared.model.FacetRecord;
 import de.intevation.flys.client.shared.model.OutputMode;
 import de.intevation.flys.client.shared.model.Theme;
@@ -32,6 +39,8 @@
 import de.intevation.flys.client.client.event.RedrawRequestEvent.Type;
 import de.intevation.flys.client.client.services.CollectionAttributeService;
 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync;
+import de.intevation.flys.client.client.services.CollectionItemAttributeService;
+import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync;
 
 
 public abstract class ThemePanel
@@ -44,6 +53,10 @@
     protected CollectionAttributeServiceAsync updater =
         GWT.create(CollectionAttributeService.class);
 
+    /** The service used to get collection item attributes. */
+    protected CollectionItemAttributeServiceAsync itemAttributeService =
+        GWT.create(CollectionItemAttributeService.class);
+
     private FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
     /** List of OutParameterChangedHandler. */
@@ -57,6 +70,9 @@
     protected ThemeNavigationPanel navigation;
     protected ListGrid list;
 
+    /** The collection view*/
+    protected CollectionView view;
+
 
     /**
      * Setup Grid, navigation bar.
@@ -147,6 +163,11 @@
     }
 
 
+    public void setCollectionView(CollectionView view) {
+        this.view = view;
+    }
+
+
     /**
      * This method is used to clear the current theme grid and add new updated
      * data.
@@ -217,7 +238,33 @@
      * Create and configure the Grid to display.
      */
     protected ListGrid createGrid() {
-        return new ListGrid();
+        ListGrid grid =  new ListGrid();
+        grid.addRowContextClickHandler(new RowContextClickHandler() {
+            public void onRowContextClick(RowContextClickEvent event) {
+                ListGridRecord[] records = list.getSelection();
+
+                Menu menu = null;
+
+                if (records == null || records.length == 0) {
+                    return;
+                }
+                else if (records.length == 1) {
+                    menu = getSingleContextMenu(records);
+                }
+                else if (records.length > 1) {
+                    menu = getMultiContextMenu(records);
+                }
+
+                if (menu != null) {
+                    list.setContextMenu(menu);
+                    menu.showContextMenu();
+
+                    event.cancel();
+                }
+            }
+        });
+
+        return grid;
     }
 
 
@@ -237,6 +284,98 @@
     }
 
 
+    protected Menu getSingleContextMenu(final ListGridRecord[] records) {
+        Menu menu = new Menu();
+
+        menu.addItem(createActivateItem(records));
+        menu.addItem(createDeactivateItem(records));
+        menu.addItem(createRemoveItem(records));
+        menu.addItem(createPropertiesItem(records));
+
+        return menu;
+    }
+
+
+    protected Menu getMultiContextMenu(final ListGridRecord[] records) {
+        Menu menu = new Menu();
+
+        menu.addItem(createActivateItem(records));
+        menu.addItem(createDeactivateItem(records));
+        menu.addItem(createRemoveItem(records));
+
+        return menu;
+    }
+
+
+    protected MenuItem createPropertiesItem(final ListGridRecord[] records) {
+        MenuItem properties = new MenuItem(MSG.properties());
+
+        properties.addClickHandler(new ClickHandler() {
+            public void onClick(MenuItemClickEvent evt) {
+                GWT.log("clicked properties");
+                for (ListGridRecord record: records) {
+                    openStyleEditor((FacetRecord) record);
+                }
+            }
+        });
+
+        return properties;
+    }
+
+
+    protected MenuItem createActivateItem(final ListGridRecord[] records) {
+        MenuItem activate = new MenuItem(MSG.activateTheme());
+
+        activate.addClickHandler(new ClickHandler() {
+            public void onClick(MenuItemClickEvent evt) {
+                for (ListGridRecord record: records) {
+                    FacetRecord facet = (FacetRecord) record;
+                    activateTheme(facet.getTheme(), true);
+                }
+
+                updateCollection();
+            }
+        });
+
+        return activate;
+    }
+
+
+    protected MenuItem createDeactivateItem(final ListGridRecord[] records) {
+        MenuItem deactivate = new MenuItem(MSG.deactivateTheme());
+
+        deactivate.addClickHandler(new ClickHandler() {
+            public void onClick(MenuItemClickEvent evt) {
+                for (ListGridRecord record: records) {
+                    FacetRecord facet = (FacetRecord) record;
+                    activateTheme(facet.getTheme(), false);
+                }
+
+                updateCollection();
+            }
+        });
+
+        return deactivate;
+    }
+
+
+    protected MenuItem createRemoveItem(final ListGridRecord[] records) {
+        MenuItem remove = new MenuItem(MSG.removeTheme());
+
+        remove.addClickHandler(new ClickHandler() {
+            public void onClick(MenuItemClickEvent evt) {
+                SC.warn("Currently not implemented");
+
+                for (ListGridRecord record: records) {
+                    FacetRecord facet = (FacetRecord) record;
+                }
+            }
+        });
+
+        return remove;
+    }
+
+
     /**
      * This method is called after a cell in the theme grid has been modified.
      *
@@ -380,5 +519,34 @@
 
         updateGrid();
     }
+
+
+    protected void openStyleEditor(final FacetRecord record) {
+        Config config = Config.getInstance();
+        String url    = config.getServerUrl();
+        String locale = config.getLocale();
+
+        String artifact = record.getTheme().getArtifact();
+
+        itemAttributeService.getCollectionItemAttribute(
+            this.collection,
+            artifact,
+            url,
+            locale,
+            new AsyncCallback<CollectionItemAttribute>() {
+                public void onFailure (Throwable caught) {
+                    GWT.log("Could not get Collection item attributes.");
+                }
+                public void onSuccess(CollectionItemAttribute cia) {
+                    GWT.log("Successfully loaded collectionitem attributes.");
+                    StyleEditorWindow win = new StyleEditorWindow(
+                        collection,
+                        cia,
+                        record);
+                    win.setCollectionView(view);
+                    win.show();
+                }
+            });
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org