ref #8785: add remove filter button and title containing the selected taxa
authorKatja Luther <k.luther@bgbm.org>
Thu, 18 Jun 2020 14:22:20 +0000 (16:22 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 18 Jun 2020 14:22:20 +0000 (16:22 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenSelectionDialog.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/AddDescriptionHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/l10n/Messages.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/l10n/messages.properties
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/l10n/messages_de.properties

index c3ab92c688fc49ac88f3d6233fccc8dd020e0e6e..5e82c6a360804993d26a98c1e1f13c387f9a9b60 100644 (file)
@@ -10,6 +10,7 @@ package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -66,13 +67,16 @@ public class SpecimenSelectionDialog extends Dialog {
     private Collection<SpecimenNodeWrapper> selectedSpecimens = new ArrayList<>();
     private CharacterMatrix matrix;
     private Text txtTextFilter;
-    private List<String> treeIndex;
+    private List<String> treeIndexList;
+    private List<String> taxonTitleList;
+    private Label l_title;
 
 
-    public SpecimenSelectionDialog(Shell parentShell, CharacterMatrix matrix, List<String> treeIndex) {
+    public SpecimenSelectionDialog(Shell parentShell, CharacterMatrix matrix, List<String> treeIndex, List<String> taxonTitleList) {
         super(parentShell);
         this.matrix = matrix;
-        this.treeIndex = treeIndex;
+        this.treeIndexList = treeIndex;
+        this.taxonTitleList = taxonTitleList;
     }
 
     @Override
@@ -81,7 +85,15 @@ public class SpecimenSelectionDialog extends Dialog {
         GridLayout gl_composite = new GridLayout();
         gl_composite.numColumns = 2;
         composite.setLayout(gl_composite);
-
+        l_title = new Label(composite, SWT.NULL);
+        if (taxonTitleList != null && !taxonTitleList.isEmpty()){
+            Iterator<String> iterator = taxonTitleList.iterator();
+            String titleString=iterator.next();
+            while(iterator.hasNext() ){
+                titleString += ", "+ iterator.next();
+            }
+            l_title.setText("Taxon Filter: " + titleString);
+        }
         Composite composite_1 = new Composite(composite, SWT.NONE);
         composite_1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
         composite_1.setLayout(new GridLayout(5, false));
@@ -124,19 +136,21 @@ public class SpecimenSelectionDialog extends Dialog {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 loadSpecimens();
-                refreshInput(matrix.getSpecimenCache());
+                refreshInput();
             }
         });
 
-        Button btnRemoveTaxonFilterButton = new Button(composite_1, SWT.NONE);
-        btnRemoveTaxonFilterButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
-        btnRemoveTaxonFilterButton.setToolTipText(Messages.SpecimenSelectionDialog_REMOVE_FILTER);
-        btnRemoveTaxonFilterButton.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
-        btnRemoveTaxonFilterButton.addSelectionListener(new SelectionAdapter() {
+        Button btnRemoveFilterButton = new Button(composite_1, SWT.NONE);
+        btnRemoveFilterButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+        btnRemoveFilterButton.setToolTipText(Messages.SpecimenSelectionDialog_REMOVE_FILTER);
+        btnRemoveFilterButton.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
+        btnRemoveFilterButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 txtTextFilter.setText("");
-                refreshInput(matrix.getSpecimenCache());
+                treeIndexList = null;
+                l_title.setText("");
+                refreshInput();
             }
         });
 
@@ -207,10 +221,10 @@ public class SpecimenSelectionDialog extends Dialog {
         if(matrix.getSpecimenCache()==null){
             loadSpecimens();
         }
-        if(treeIndex !=null){
-            filterByTaxonNode(treeIndex, null);
+        if(treeIndexList !=null){
+            filterByTaxonNode( null);
         }else{
-            refreshInput(matrix.getSpecimenCache());
+            refreshInput();
         }
 
         columnSpecimen.getColumn().pack();
@@ -218,8 +232,8 @@ public class SpecimenSelectionDialog extends Dialog {
         return composite;
     }
 
-    private void refreshInput(Object input){
-        list.setInput(input);
+    private void refreshInput(){
+        applyFilter();
     }
 
     private void applyFilter(){
@@ -227,7 +241,7 @@ public class SpecimenSelectionDialog extends Dialog {
         Collection<SpecimenNodeWrapper> specimenCache = matrix.getSpecimenCache();
         String text = txtTextFilter.getText();
 
-        //filter for treeIndex is missing
+        //filter for treeIndexList is missing
         if(CdmUtils.isBlank(text)){
             result = new ArrayList<>(specimenCache);
         }
@@ -242,7 +256,7 @@ public class SpecimenSelectionDialog extends Dialog {
                         .collect(Collectors.toList()));
             }
         }
-        filterByTaxonNode(treeIndex, result);
+        filterByTaxonNode(result);
 
     }
 
@@ -335,20 +349,24 @@ public class SpecimenSelectionDialog extends Dialog {
         }
     }
 
-    private void filterByTaxonNode(List<String> treeIndexList, Collection<SpecimenNodeWrapper> specimenCache){
+    private void filterByTaxonNode( Collection<SpecimenNodeWrapper> specimenCache){
         Collection<SpecimenNodeWrapper> result = new ArrayList<>();
         if (specimenCache == null){
             specimenCache = matrix.getSpecimenCache();
         }
-        for (String treeIndex: treeIndexList){
-            if (StringUtils.isNotBlank(treeIndex)){
-                result.addAll(specimenCache.stream()
-                            .filter(wrapper->wrapper.getTaxonNode().getTreeIndex().startsWith(treeIndex))
-                            .collect(Collectors.toList()));
+        if (treeIndexList != null){
+            for (String treeIndex: this.treeIndexList){
+                if (StringUtils.isNotBlank(treeIndex)){
+                    result.addAll(specimenCache.stream()
+                                .filter(wrapper->wrapper.getTaxonNode().getTreeIndex().startsWith(treeIndex))
+                                .collect(Collectors.toList()));
+                }
             }
+        }else{
+            result.addAll(specimenCache);
         }
 
 
-        refreshInput(result);
+        list.setInput(result);
     }
 }
index 1ab3a7c5fa063f5bd30a64148a526985684ed1f8..189612e403896ced4ba6cdd32a1430159ff109b8 100755 (executable)
@@ -48,8 +48,10 @@ public class AddDescriptionHandler {
         CharacterMatrix matrix = matrixPart.getMatrix();
         IStructuredSelection selection = matrixPart.getSelection();
         List<String> treeIndexList = null;
+        List<String> taxonTitleList = null;
         if(selection.size()>0){
             treeIndexList = new ArrayList<>();
+            taxonTitleList = new ArrayList<>();
             Iterator iterator = selection.iterator();
             while (iterator.hasNext()){
                 Object element = iterator.next();
@@ -57,12 +59,13 @@ public class AddDescriptionHandler {
                     TaxonNodeDto taxonRow = (TaxonNodeDto) element;
                     String treeIndex = taxonRow.getTreeIndex();
                     treeIndexList.add(treeIndex);
+                    taxonTitleList.add(taxonRow.getNameCache());
                 }
             }
 
         }
 
-        SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(matrix.getShell(), matrix, treeIndexList);
+        SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(matrix.getShell(), matrix, treeIndexList, taxonTitleList);
         if(dialog.open()==Window.OK){
             Collection<SpecimenNodeWrapper> wrappers = dialog.getSpecimen();
             if(wrappers.stream().anyMatch(wrapper->wrapper.getTaxonDescriptionUuid()==null)
index ed8b348a6209bcdcd8f050c0d2ce79dcf5ab6013..61e2cceb9d03833da14a90fdc461a13b244fc8cf 100644 (file)
@@ -271,6 +271,7 @@ public class Messages extends NLS {
     public static String SetSecundumHandler_configureSettings;
     public static String SetSecundumHandler_confirm;
     public static String SpecimenSelectionDialog_REFRESH;
+    public static String SpecimenSelectionDialog_REMOVE_FILTER;
     public static String SpecimenSelectionDialog_SELECT_SPECIMENS;
     public static String SwapSynonymAndAcceptedHandler_COULD_NOT_OPEN;
     public static String SwapSynonymAndAcceptedOperation_NOT_IMPLEMENTED;
index 9f7189970df9bbc850c556e517f15f04ef9cd326..356c2c0d4476a5f6e9ddd8ec1f571143f24877f9 100644 (file)
@@ -137,6 +137,7 @@ MultiPageTaxonEditor_UNSAVED_DATA_MESSAGE=This editor can not be refreshed becau
 SimpleSelectionProvider_SETTING_SELECTION=Setting Selection
 SpecimenSelectionDialog_REFRESH=Refresh
 SpecimenSelectionDialog_SELECT_SPECIMENS=Select specimens
+SpecimenSelectionDialog_REMOVE_FILTER=Remove filter
 TaxonEditorInput_INCORRECT_STATE=Incorrect state
 TaxonEditorInput_NEW_TAXON=New taxon
 TaxonEditorInput_NO_ACCEPTED_TAXON_PRESENT=Trying to open accepted taxon for a synonym or misapplication but misapplication but the accepted taxon is not present in any classification and can\u2019t be opened in name editor.
index 6d16cf78b00de85e72593233700330ff4aeb3664..39fb5f8ecf35f041b35f51f24fea164350bf5107 100644 (file)
@@ -136,6 +136,7 @@ MultiPageTaxonEditor_UNSAVED_DATA_MESSAGE=Der Editor kann nicht aktualisiert wer
 SimpleSelectionProvider_SETTING_SELECTION=Auswahl setzen
 SpecimenSelectionDialog_REFRESH=Aktualisieren
 SpecimenSelectionDialog_SELECT_SPECIMENS=Specimens auswählen
+SpecimenSelectionDialog_REMOVE_FILTER=Filter entfernen
 TaxonEditorInput_INCORRECT_STATE=Ungültiger Zustand
 TaxonEditorInput_NEW_TAXON=Neues Taxon
 TaxonEditorInput_NO_ACCEPTED_TAXON_PRESENT=Öffnen eines akzeptierten Taxons für ein Synonym oder eine Misapplikation, das akzeptierte Taxon ist aber in keiner Klassifikation enthalten, daher kann es nicht im Namens-Editor geöffnet werden. Benutzen Sie den Bulk-Editor.