ref #7095 Sync state selection in combo and PersistenceDialog
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 11 Jan 2018 07:14:50 +0000 (08:14 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 11 Jan 2018 07:14:50 +0000 (08:14 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java

index 6e46011347e8ca314e7326a472fa8e62ebf6e6ef..6f0819ad26beaa1a69df95ab9a51cbb67a52050d 100644 (file)
@@ -76,6 +76,7 @@ import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenc
 import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler;
 import org.eclipse.nebula.widgets.nattable.persistence.command.IStateChangedListener;
 import org.eclipse.nebula.widgets.nattable.persistence.command.StateChangeEvent;
+import org.eclipse.nebula.widgets.nattable.persistence.gui.PersistenceDialog;
 import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
 import org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer;
 import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
@@ -86,7 +87,6 @@ import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
 import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
 import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
 import org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration;
-import org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration;
 import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
 import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
 import org.eclipse.swt.SWT;
@@ -365,12 +365,13 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
         //add default configuration because autoconfigure is set to false in constructor
         natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
 
+        //FIXME: this is for DEBUG ONLY
+//        natTable.addConfiguration(new DebugMenuConfiguration(natTable));
+
         // override the default sort configuration and change the mouse bindings
         // to sort on a single click
         natTable.addConfiguration(new SingleClickSortConfiguration());
 
-        //FIXME: this is for DEBUG ONLY
-        natTable.addConfiguration(new DebugMenuConfiguration(natTable));
 
         // add the header menu configuration for adding the column header menu
         // with hide/show actions
@@ -478,11 +479,10 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
         gridLayer.registerCommandHandler(handler);
         // create a combobox for showing the available view states
         Combo comboStates = new Combo(toolbarComposite, SWT.DROP_DOWN);
-        comboStates.setItems(PersistenceHelper
-                .getAvailableStates(natTableState)
-                .toArray(new String[] {}));
-        comboStates.addSelectionListener(new SelectionAdapter() {
+        Collection<String> availableStates = PersistenceHelper.getAvailableStates(natTableState);
+        comboStates.setItems(availableStates.toArray(new String[] {}));
 
+        comboStates.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 int index = comboStates.getSelectionIndex();
@@ -490,18 +490,18 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
                     String selected = comboStates.getItem(index);
                     // load the state
                     natTable.loadState(selected, natTableState);
+                    natTableState.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, selected);
                 }
             }
         });
 
         // add listener to update the combo on view state management changes
         handler.addStateChangeListener(new IStateChangedListener() {
-
             @Override
             public void handleStateChange(StateChangeEvent event) {
-                comboStates.setItems(PersistenceHelper
-                        .getAvailableStates(natTableState)
+                comboStates.setItems(PersistenceHelper.getAvailableStates(natTableState)
                         .toArray(new String[] {}));
+                selectStateItem(comboStates, event.getViewConfigName());
             }
         });
 
@@ -512,6 +512,7 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
             @Override
             public void widgetSelected(SelectionEvent e) {
                 natTable.doCommand(new DisplayPersistenceDialogCommand(natTable));
+                selectStateItem(comboStates, natTableState.get(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY).toString());
             }
         });
 
@@ -560,6 +561,16 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
         parent.layout();
     }
 
+    private void selectStateItem(Combo comboStates, String stateName){
+        String[] items = comboStates.getItems();
+        for(int i=0;i<items.length;i++){
+            if(items[i].equals(stateName)){
+                comboStates.select(i);
+                break;
+            }
+        }
+    }
+
     private SpecimenDescription getDescriptionForWorkingSet(SpecimenOrObservationBase specimen){
         Set<SpecimenDescription> descriptions = specimen.getDescriptions();
         if(descriptions!=null){