diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ThemePanel.java @ 9416:05405292a7ca

Navigationtheme panel now shows themes of dWt and WQ charts grayed out, if the current station is outside the valid range of the theme.
author gernotbelger
date Thu, 16 Aug 2018 16:28:03 +0200
parents 5e38e2924c07
children cff7636035ce
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ThemePanel.java	Thu Aug 16 16:27:53 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ThemePanel.java	Thu Aug 16 16:28:03 2018 +0200
@@ -8,22 +8,8 @@
 
 package org.dive4elements.river.client.client.ui;
 
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-
-import com.smartgwt.client.util.BooleanCallback;
-import com.smartgwt.client.util.SC;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.grid.ListGrid;
-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 java.util.ArrayList;
+import java.util.List;
 
 import org.dive4elements.river.client.client.Config;
 import org.dive4elements.river.client.client.FLYSConstants;
@@ -47,8 +33,21 @@
 import org.dive4elements.river.client.shared.model.Theme;
 import org.dive4elements.river.client.shared.model.ThemeList;
 
-import java.util.ArrayList;
-import java.util.List;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.util.BooleanCallback;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.grid.ListGrid;
+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;
 
 /**
  * ThemePanel on the left in CollectionView.
@@ -57,67 +56,62 @@
  *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public abstract class ThemePanel
-extends               Canvas
-implements            OnMoveHandler,
-                      EditCompleteHandler,
-                      HasOutputParameterChangeHandlers,
-                      HasRedrawRequestHandlers
-{
-    protected CollectionAttributeServiceAsync updater =
-        GWT.create(CollectionAttributeService.class);
+public abstract class ThemePanel extends Canvas implements OnMoveHandler, EditCompleteHandler, HasOutputParameterChangeHandlers, HasRedrawRequestHandlers {
+
+    private final CollectionAttributeServiceAsync updater = GWT.create(CollectionAttributeService.class);
 
     /** The service used to get collection item attributes. */
-    protected CollectionItemAttributeServiceAsync itemAttributeService =
-        GWT.create(CollectionItemAttributeService.class);
+    private final CollectionItemAttributeServiceAsync itemAttributeService = GWT.create(CollectionItemAttributeService.class);
 
     /** i18ner. */
-    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+    protected final FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
     /** List of OutParameterChangedHandler. */
-    protected List<OutputParameterChangeHandler> outHandlers;
+    private final List<OutputParameterChangeHandler> outHandlers;
 
     /** List of ChartShallRedrawHandler. */
-    protected List<RedrawRequestHandler> redrawRequestHandlers;
-
-    protected OutputMode mode;
+    protected final List<RedrawRequestHandler> redrawRequestHandlers;
 
-    protected ThemeNavigationPanel navigation;
-    protected ListGrid list;
+    protected final OutputMode mode;
 
-    /** The collection view*/
+    protected final ThemeNavigationPanel navigation;
+
+    protected final ListGrid list;
+
+    /** The collection view */
     protected CollectionView view;
 
+    private final IThemeRecordHandler recordHandler;
+
     /**
      * Setup Grid, navigation bar.
-     * @param collection Collection for which to show themes.
+     *
+     * @param collection
+     *            Collection for which to show themes.
      */
-    public ThemePanel(
-        OutputMode mode,
-        CollectionView view
-    ) {
-        this.mode       = mode;
-        this.list       = createGrid();
-        this.view       = view;
-        list.addRowContextClickHandler(new RowContextClickHandler() {
+    public ThemePanel(final OutputMode mode, final CollectionView view, final IThemeRecordHandler recordHandler) {
+        this.mode = mode;
+        this.recordHandler = recordHandler;
+        this.list = createGrid();
+        this.view = view;
+
+        this.list.addRowContextClickHandler(new RowContextClickHandler() {
             @Override
-            public void onRowContextClick(RowContextClickEvent event) {
-                ListGridRecord[] records = list.getSelectedRecords();
+            public void onRowContextClick(final RowContextClickEvent event) {
+                final ListGridRecord[] records = ThemePanel.this.list.getSelectedRecords();
 
                 Menu menu = null;
 
                 if (records == null || records.length == 0) {
                     return;
-                }
-                else if (records.length == 1) {
+                } else if (records.length == 1) {
                     menu = getSingleContextMenu(records);
-                }
-                else if (records.length > 1) {
+                } else if (records.length > 1) {
                     menu = getMultiContextMenu(records);
                 }
 
                 if (menu != null) {
-                    list.setContextMenu(menu);
+                    ThemePanel.this.list.setContextMenu(menu);
                     menu.showContextMenu();
 
                     event.cancel();
@@ -127,104 +121,98 @@
 
         this.redrawRequestHandlers = new ArrayList<RedrawRequestHandler>();
         this.outHandlers = new ArrayList<OutputParameterChangeHandler>();
-        this.navigation  = new ThemeNavigationPanel();
+        this.navigation = new ThemeNavigationPanel();
         this.navigation.addOnMoveHandler(this);
 
         this.setShowResizeBar(true);
     }
 
-
     public abstract void activateTheme(Theme theme, boolean active);
 
-
     /**
      * Replace the current collection with a new one. <b>NOTE: this operation
      * triggers updateGrid() which modifies the themes in the grid.</b>
      *
-     * @param collection The new collection object.
+     * @param collection
+     *            The new collection object.
      */
-    protected void setCollection(Collection collection) {
+    protected void setCollection(final Collection collection) {
         // Set collection of view, but do not trigger event shooting.
         this.view.setCollection(collection, true);
 
         updateGrid();
     }
 
-
     /** Get Collection. */
     public Collection getCollection() {
-        return view.getCollection();
+        return this.view.getCollection();
     }
 
-
     /**
      * Returns the ThemeList of the current collection and output mode.
      *
      * @return the current ThemeList.
      */
     public ThemeList getThemeList() {
-        return getCollection().getThemeList(mode.getName());
+        return getCollection().getThemeList(this.mode.getName());
     }
 
     public ListGridRecord[] getSelectedRecords() {
-        return list.getSelectedRecords();
+        return this.list.getSelectedRecords();
     }
 
     /**
      * Registers a new OutputParameterChangeHandler.
      *
-     * @param h The new handler.
+     * @param h
+     *            The new handler.
      */
     @Override
-    public void addOutputParameterChangeHandler(OutputParameterChangeHandler h){
+    public void addOutputParameterChangeHandler(final OutputParameterChangeHandler h) {
         if (h != null) {
-            outHandlers.add(h);
+            this.outHandlers.add(h);
         }
     }
 
-
     /**
      * Registers a RedrawRequestHandler.
      *
-     * @param h The new handler.
+     * @param h
+     *            The new handler.
      */
     @Override
-    public void addRedrawRequestHandler(RedrawRequestHandler h){
+    public void addRedrawRequestHandler(final RedrawRequestHandler h) {
         if (h != null) {
-            redrawRequestHandlers.add(h);
+            this.redrawRequestHandlers.add(h);
         }
     }
 
-
     /**
      * Request a redraw of e.g. a Chart.
      */
     final public void requestRedraw() {
-        for (RedrawRequestHandler handler: redrawRequestHandlers) {
+        for (final RedrawRequestHandler handler : this.redrawRequestHandlers) {
             handler.onRedrawRequest(new RedrawRequestEvent(Type.DEFAULT));
         }
     }
 
-
     /**
      * Called when the attribution of an output changed. It informs the
      * registered handlers about the changes.
      */
     protected void fireOutputParameterChanged() {
-        OutputParameterChangeEvent evt = new OutputParameterChangeEvent();
+        final OutputParameterChangeEvent evt = new OutputParameterChangeEvent();
 
-        for (OutputParameterChangeHandler handler: outHandlers) {
+        for (final OutputParameterChangeHandler handler : this.outHandlers) {
             handler.onOutputParameterChanged(evt);
         }
     }
 
-
     /** Registers the CollectionView associated to this ThemePanel. */
-    public void setCollectionView(CollectionView view) {
+    public void setCollectionView(final CollectionView view) {
         this.view = view;
     }
 
-
     /**
      * This method is used to clear the current theme grid and add new updated
      * data.
@@ -232,21 +220,21 @@
     protected void updateGrid() {
         GWT.log("ThemePanel.updateGrid");
 
-        ListGridRecord[] selected = list.getSelectedRecords();
+        final ListGridRecord[] selected = this.list.getSelectedRecords();
 
         clearGrid();
 
-        ThemeList themeList = getThemeList();
+        final ThemeList themeList = getThemeList();
 
         if (themeList == null) {
             GWT.log("ERROR: No theme list.");
             return;
         }
 
-        int count = themeList.getThemeCount();
+        final int count = themeList.getThemeCount();
 
         for (int i = 1; i <= count; i++) {
-            Theme theme = themeList.getThemeAt(i);
+            final Theme theme = themeList.getThemeAt(i);
 
             if (theme == null) {
                 continue;
@@ -260,41 +248,38 @@
                 continue;
             }
 
-            FacetRecord newRecord = createRecord(theme);
+            final FacetRecord newRecord = createRecord(theme);
             addFacetRecord(newRecord);
 
-            String newArtifact = theme.getArtifact();
-            String newFacet    = theme.getFacet();
-            int    newIndex    = theme.getIndex();
+            final String newArtifact = theme.getArtifact();
+            final String newFacet = theme.getFacet();
+            final int newIndex = theme.getIndex();
 
-            for (ListGridRecord r: selected) {
-                FacetRecord sel = (FacetRecord) r;
-                Theme oldTheme  = sel.getTheme();
+            for (final ListGridRecord r : selected) {
+                final FacetRecord sel = (FacetRecord) r;
+                final Theme oldTheme = sel.getTheme();
 
-                if (oldTheme.getArtifact().equals(newArtifact)
-                    && oldTheme.getFacet().equals(newFacet)
-                    && oldTheme.getIndex() == newIndex) {
-                    list.selectRecord(newRecord);
+                if (oldTheme.getArtifact().equals(newArtifact) && oldTheme.getFacet().equals(newFacet) && oldTheme.getIndex() == newIndex) {
+                    this.list.selectRecord(newRecord);
                 }
             }
         }
 
+        updateThemes();
+
         fireOutputParameterChanged();
     }
 
-
     /** Adds given Record to the list (table). */
-    protected void addFacetRecord(FacetRecord rec) {
-        list.addData(rec);
+    protected void addFacetRecord(final FacetRecord rec) {
+        this.list.addData(rec);
     }
 
-
     /** Create a FacetRecord that wraps given theme. */
-    protected FacetRecord createRecord(Theme theme) {
+    protected final FacetRecord createRecord(final Theme theme) {
         return new FacetRecord(theme);
     }
 
-
     /**
      * This method triggers the CollectionAttributeService. Based on the current
      * collectin settings, the attribute of the collection is modified or not.
@@ -303,25 +288,24 @@
      */
     public void updateCollection() {
         final Config config = Config.getInstance();
-        final String loc    = config.getLocale();
+        final String loc = config.getLocale();
 
         GWT.log("ThemePanel.updateCollection via RPC now");
 
         // Don't forget to enable the panel after the request has finished!
         disable();
 
-        updater.update(getCollection(), loc, new AsyncCallback<Collection>() {
+        this.updater.update(getCollection(), loc, new AsyncCallback<Collection>() {
             @Override
-            public void onFailure(Throwable caught) {
+            public void onFailure(final Throwable caught) {
                 GWT.log("Could not update collection attributes.");
-                SC.warn(MSG.getString(caught.getMessage()));
+                SC.warn(ThemePanel.this.MSG.getString(caught.getMessage()));
 
                 enable();
             }
 
-
             @Override
-            public void onSuccess(Collection collection) {
+            public void onSuccess(final Collection collection) {
                 setCollection(collection);
 
                 enable();
@@ -329,51 +313,43 @@
         });
     }
 
-
     /**
      * Create and configure the Grid to display.
      */
     protected ListGrid createGrid() {
-        ListGrid grid = createNewGrid();
+        final ListGrid grid = new ListGrid();
         grid.setLeaveScrollbarGap(false);
 
         return grid;
     }
 
-
-    protected ListGrid createNewGrid() {
-        return new ListGrid();
-    }
-
-
     /**
      * A method that removes all records from theme grid.
      */
     protected void clearGrid() {
-        ListGridRecord[] records = list.getRecords();
+        final ListGridRecord[] records = this.list.getRecords();
 
         if (records == null || records.length == 0) {
             return;
         }
 
-        for (ListGridRecord record: records) {
-            list.removeData(record);
+        for (final ListGridRecord record : records) {
+            this.list.removeData(record);
         }
     }
 
     /** Return 'separator'- menu-item. */
     protected MenuItem createSeparator() {
-        MenuItem separator = new MenuItem();
+        final MenuItem separator = new MenuItem();
         separator.setIsSeparator(true);
         return separator;
     }
 
-
     /**
      * Get the context menu for a (right mouse button)click on a single item.
      */
     protected Menu getSingleContextMenu(final ListGridRecord[] records) {
-        Menu menu = new Menu();
+        final Menu menu = new Menu();
 
         menu.addItem(createActivateItem(records));
         menu.addItem(createDeactivateItem(records));
@@ -384,9 +360,8 @@
         return menu;
     }
 
-
     protected Menu getMultiContextMenu(final ListGridRecord[] records) {
-        Menu menu = new Menu();
+        final Menu menu = new Menu();
 
         menu.addItem(createActivateItem(records));
         menu.addItem(createDeactivateItem(records));
@@ -395,16 +370,15 @@
         return menu;
     }
 
-
     /** The properties menu item (opens style editor on click). */
     protected MenuItem createPropertiesItem(final ListGridRecord[] records) {
-        MenuItem properties = new MenuItem(MSG.properties());
+        final MenuItem properties = new MenuItem(this.MSG.properties());
 
         properties.addClickHandler(new ClickHandler() {
             @Override
-            public void onClick(MenuItemClickEvent evt) {
+            public void onClick(final MenuItemClickEvent evt) {
                 GWT.log("clicked properties");
-                for (ListGridRecord record: records) {
+                for (final ListGridRecord record : records) {
                     openStyleEditor((FacetRecord) record);
                 }
             }
@@ -413,15 +387,14 @@
         return properties;
     }
 
-
     protected MenuItem createActivateItem(final ListGridRecord[] records) {
-        MenuItem activate = new MenuItem(MSG.activateTheme());
+        final MenuItem activate = new MenuItem(this.MSG.activateTheme());
 
         activate.addClickHandler(new ClickHandler() {
             @Override
-            public void onClick(MenuItemClickEvent evt) {
-                for (ListGridRecord record: records) {
-                    FacetRecord facet = (FacetRecord) record;
+            public void onClick(final MenuItemClickEvent evt) {
+                for (final ListGridRecord record : records) {
+                    final FacetRecord facet = (FacetRecord) record;
                     activateTheme(facet.getTheme(), true);
                 }
 
@@ -432,15 +405,14 @@
         return activate;
     }
 
-
     protected MenuItem createDeactivateItem(final ListGridRecord[] records) {
-        MenuItem deactivate = new MenuItem(MSG.deactivateTheme());
+        final MenuItem deactivate = new MenuItem(this.MSG.deactivateTheme());
 
         deactivate.addClickHandler(new ClickHandler() {
             @Override
-            public void onClick(MenuItemClickEvent evt) {
-                for (ListGridRecord record: records) {
-                    FacetRecord facet = (FacetRecord) record;
+            public void onClick(final MenuItemClickEvent evt) {
+                for (final ListGridRecord record : records) {
+                    final FacetRecord facet = (FacetRecord) record;
                     activateTheme(facet.getTheme(), false);
                 }
 
@@ -451,29 +423,27 @@
         return deactivate;
     }
 
-
     /** Remove given themes (not asking for confirmation). */
     protected void removeThemes(final ListGridRecord[] records) {
-        for (ListGridRecord record: records) {
-            FacetRecord facet = (FacetRecord) record;
-            Theme theme = facet.getTheme();
+        for (final ListGridRecord record : records) {
+            final FacetRecord facet = (FacetRecord) record;
+            final Theme theme = facet.getTheme();
             theme.setVisible(0);
             theme.setActive(0);
             updateCollection();
         }
     }
 
-
     /** Create menu item for removing theme(s). Will ask for confirmation. */
     protected MenuItem createRemoveItem(final ListGridRecord[] records) {
-        MenuItem remove = new MenuItem(MSG.removeTheme());
+        final MenuItem remove = new MenuItem(this.MSG.removeTheme());
 
         remove.addClickHandler(new ClickHandler() {
             @Override
-            public void onClick(MenuItemClickEvent evt) {
-                SC.ask(MSG.askThemeRemove(), new BooleanCallback() {
+            public void onClick(final MenuItemClickEvent evt) {
+                SC.ask(ThemePanel.this.MSG.askThemeRemove(), new BooleanCallback() {
                     @Override
-                    public void execute(Boolean value) {
+                    public void execute(final Boolean value) {
                         if (value) {
                             removeThemes(records);
                         }
@@ -485,20 +455,20 @@
         return remove;
     }
 
-
     /**
      * This method is called after a cell in the theme grid has been modified.
      *
-     * @param event The event that stores information about the modified record.
+     * @param event
+     *            The event that stores information about the modified record.
      */
     @Override
-    public void onEditComplete(EditCompleteEvent event) {
+    public void onEditComplete(final EditCompleteEvent event) {
         GWT.log("Edited record.");
 
-        int         row = event.getRowNum();
-        FacetRecord rec = (FacetRecord) list.getRecord(row);
+        final int row = event.getRowNum();
+        final FacetRecord rec = (FacetRecord) this.list.getRecord(row);
 
-        Theme theme = rec.getTheme();
+        final Theme theme = rec.getTheme();
 
         theme.setDescription(rec.getName());
         activateTheme(theme, rec.getActive());
@@ -506,27 +476,28 @@
         updateCollection();
     }
 
-
     /**
      * This method should be defined in subclasses that wants to listen to this
      * event.
      *
-     * @param theme The theme that is moved.
-     * @param oldIdx The index of the theme before it was moved.
-     * @param newIdx The index of the theme after it was moved.
+     * @param theme
+     *            The theme that is moved.
+     * @param oldIdx
+     *            The index of the theme before it was moved.
+     * @param newIdx
+     *            The index of the theme after it was moved.
      */
-    protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) {
+    protected void fireThemeMoved(final Theme theme, final int oldIdx, final int newIdx) {
         // Do nothing
     }
 
-
     @Override
-    public void onMove(OnMoveEvent event) {
-        int type = event.getType();
+    public void onMove(final OnMoveEvent event) {
+        final int type = event.getType();
 
         GWT.log("ThemePanel.onMove: " + type);
 
-        ListGridRecord[] records = list.getSelectedRecords();
+        final ListGridRecord[] records = this.list.getSelectedRecords();
 
         if (records == null || records.length == 0) {
             GWT.log("ThemePanel.onMove: No records selected.");
@@ -534,28 +505,36 @@
         }
 
         switch (type) {
-            case 0: moveRecordsTop(records); break;
-            case 1: moveRecordsUp(records); break;
-            case 2: moveRecordsDown(records); break;
-            case 3: moveRecordsBottom(records); break;
+        case 0:
+            moveRecordsTop(records);
+            break;
+        case 1:
+            moveRecordsUp(records);
+            break;
+        case 2:
+            moveRecordsDown(records);
+            break;
+        case 3:
+            moveRecordsBottom(records);
+            break;
         }
 
         updateCollection();
     }
 
-
     /**
      * Moves the selected grid records (themes) to the top of the grid.
      *
-     * @param records The selected themes in the list. Null not permitted.
+     * @param records
+     *            The selected themes in the list. Null not permitted.
      */
-    protected void moveRecordsTop(ListGridRecord[] records) {
-        ThemeList themeList = getThemeList();
+    protected void moveRecordsTop(final ListGridRecord[] records) {
+        final ThemeList themeList = getThemeList();
 
         int idx = 1;
 
-        for (ListGridRecord record: records) {
-            Theme theme = ((FacetRecord) record).getTheme();
+        for (final ListGridRecord record : records) {
+            final Theme theme = ((FacetRecord) record).getTheme();
             fireThemeMoved(theme, theme.getPosition(), idx);
             themeList.setThemePosition(theme, idx++);
         }
@@ -563,49 +542,24 @@
         updateGrid();
     }
 
-
     /**
      * Moves the selected grid records (themes) one step up.
      *
-     * @param records The selected themes in the list. Null not permitted.
+     * @param records
+     *            The selected themes in the list. Null not permitted.
      */
-    protected void moveRecordsUp(ListGridRecord[] records) {
-        ThemeList themeList = getThemeList();
-
-        int[] newPos = new int[records.length];
+    protected void moveRecordsUp(final ListGridRecord[] records) {
+        final ThemeList themeList = getThemeList();
 
-        for (int i = 0; i < records.length ; i++) {
-            Theme theme = ((FacetRecord) records[i]).getTheme();
-            newPos[i]   = theme.getPosition() - 1;
-        }
+        final int[] newPos = new int[records.length];
 
-        for (int i = 0; i < records.length ; i++) {
-            Theme theme = ((FacetRecord) records[i]).getTheme();
-            fireThemeMoved(theme, theme.getPosition(), newPos[i]);
-            themeList.setThemePosition(theme, newPos[i]);
+        for (int i = 0; i < records.length; i++) {
+            final Theme theme = ((FacetRecord) records[i]).getTheme();
+            newPos[i] = theme.getPosition() - 1;
         }
 
-        updateGrid();
-    }
-
-
-    /**
-     * Moves the selected grid records (themes) one step down.
-     *
-     * @param records The selected themes in the list. Null not permitted.
-     */
-    protected void moveRecordsDown(ListGridRecord[] records) {
-        ThemeList themeList = getThemeList();
-
-        int[] newPos = new int[records.length];
-
-        for (int i = records.length-1; i >= 0; i--) {
-            Theme theme = ((FacetRecord) records[i]).getTheme();
-            newPos[i] = theme.getPosition()+1;
-        }
-
-        for (int i = records.length-1; i >= 0; i--) {
-            Theme theme = ((FacetRecord) records[i]).getTheme();
+        for (int i = 0; i < records.length; i++) {
+            final Theme theme = ((FacetRecord) records[i]).getTheme();
             fireThemeMoved(theme, theme.getPosition(), newPos[i]);
             themeList.setThemePosition(theme, newPos[i]);
         }
@@ -613,19 +567,44 @@
         updateGrid();
     }
 
+    /**
+     * Moves the selected grid records (themes) one step down.
+     *
+     * @param records
+     *            The selected themes in the list. Null not permitted.
+     */
+    protected void moveRecordsDown(final ListGridRecord[] records) {
+        final ThemeList themeList = getThemeList();
+
+        final int[] newPos = new int[records.length];
+
+        for (int i = records.length - 1; i >= 0; i--) {
+            final Theme theme = ((FacetRecord) records[i]).getTheme();
+            newPos[i] = theme.getPosition() + 1;
+        }
+
+        for (int i = records.length - 1; i >= 0; i--) {
+            final Theme theme = ((FacetRecord) records[i]).getTheme();
+            fireThemeMoved(theme, theme.getPosition(), newPos[i]);
+            themeList.setThemePosition(theme, newPos[i]);
+        }
+
+        updateGrid();
+    }
 
     /**
      * Moves the selected grid records (themes) to the bottom of the grid.
      *
-     * @param records The selected themes in the list. Null not permitted.
+     * @param records
+     *            The selected themes in the list. Null not permitted.
      */
-    protected void moveRecordsBottom(ListGridRecord[] records) {
-        ThemeList themeList = getThemeList();
+    protected void moveRecordsBottom(final ListGridRecord[] records) {
+        final ThemeList themeList = getThemeList();
 
         int idx = themeList.getThemeCount();
 
-        for (int i = records.length-1; i >= 0; i--) {
-            Theme theme = ((FacetRecord) records[i]).getTheme();
+        for (int i = records.length - 1; i >= 0; i--) {
+            final Theme theme = ((FacetRecord) records[i]).getTheme();
             fireThemeMoved(theme, theme.getPosition(), idx);
             themeList.setThemePosition(theme, idx--);
         }
@@ -633,48 +612,47 @@
         updateGrid();
     }
 
-
     protected void openStyleEditor(final FacetRecord record) {
-        Config config = Config.getInstance();
-        String locale = config.getLocale();
-
-        String artifact = record.getTheme().getArtifact();
+        final Config config = Config.getInstance();
+        final String locale = config.getLocale();
 
-        itemAttributeService.getCollectionItemAttribute(
-            this.getCollection(),
-            artifact,
-            locale,
-            new AsyncCallback<CollectionItemAttribute>() {
-                @Override
-                public void onFailure (Throwable caught) {
-                    SC.warn(MSG.getString(caught.getMessage()));
-                }
-                @Override
-                public void onSuccess(CollectionItemAttribute cia) {
-                    GWT.log("Successfully loaded collectionitem attributes.");
-                    showStyleEditor(cia, record);
-                }
-            });
+        final String artifact = record.getTheme().getArtifact();
+
+        this.itemAttributeService.getCollectionItemAttribute(this.getCollection(), artifact, locale, new AsyncCallback<CollectionItemAttribute>() {
+            @Override
+            public void onFailure(final Throwable caught) {
+                SC.warn(ThemePanel.this.MSG.getString(caught.getMessage()));
+            }
+
+            @Override
+            public void onSuccess(final CollectionItemAttribute cia) {
+                GWT.log("Successfully loaded collectionitem attributes.");
+                showStyleEditor(cia, record);
+            }
+        });
     }
 
-
-    protected void showStyleEditor(
-        CollectionItemAttribute cia,
-        FacetRecord record)
-    {
-        StyleEditorWindow win = new StyleEditorWindow(
-            getCollection(),
-            cia,
-            record);
+    protected void showStyleEditor(final CollectionItemAttribute cia, final FacetRecord record) {
+        final StyleEditorWindow win = new StyleEditorWindow(getCollection(), cia, record);
         win.setThemePanel(this);
         win.centerInPage();
         win.show();
     }
 
-
     /** Get OutputMode of this Panel. */
     public OutputMode getMode() {
         return this.mode;
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+
+    public void updateThemes() {
+
+        final ListGridRecord[] records = this.list.getRecords();
+        for (final ListGridRecord record : records) {
+            final FacetRecord facetRecord = (FacetRecord) record;
+
+            this.recordHandler.handle(facetRecord);
+        }
+
+        this.list.markForRedraw();
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org