From 71ef005ae9cb2ba3c293dc6f151e0a44c4ab1900 Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Thu, 12 Apr 2018 08:40:18 +0200
Subject: [PATCH] ref #7095 Add text filter to specimen selection dialog
---
.../matrix/SpecimenSelectionDialog.java | 31 ++++++++++++++-----
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java
index 5a26884cd..4519564ab 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java
@@ -13,6 +13,7 @@ import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridDataFactory;
@@ -38,6 +39,7 @@ import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
+import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.taxon.Taxon;
@@ -81,16 +83,11 @@ public class SpecimenSelectionDialog extends Dialog {
txtTextFilter = new Text(composite_1, SWT.BORDER);
txtTextFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ txtTextFilter.addModifyListener(e->applyFilter());
comboTaxon = new TaxonNodeCombo(composite_1, SWT.NONE);
comboTaxon.setInput(matrix.getWorkingSet().getTaxonSubtreeFilter());
- comboTaxon.addSelectionChangedListener(e->
- list.setInput(
- matrix.getSpecimenCache()
- .stream()
- .filter(wrapper->wrapper.getTaxonNode().equals(comboTaxon.getSelection()))
- .collect(Collectors.toList()))
- );
+ comboTaxon.addSelectionChangedListener(e->applyFilter());
Button btnRefreshButton = new Button(composite_1, SWT.NONE);
btnRefreshButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
@@ -106,7 +103,10 @@ public class SpecimenSelectionDialog extends Dialog {
//table
list = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
Table table = list.getTable();
- table.setLayoutData(GridDataFactory.fillDefaults().create());
+ GridData gd_table = GridDataFactory.fillDefaults().create();
+ gd_table.grabExcessHorizontalSpace = true;
+ gd_table.grabExcessVerticalSpace = true;
+ table.setLayoutData(gd_table);
//table columns
TableViewerColumn columnTaxon = new TableViewerColumn(list, SWT.NONE);
columnTaxon.getColumn().setText("Taxon");
@@ -131,6 +131,21 @@ public class SpecimenSelectionDialog extends Dialog {
return composite;
}
+ private void applyFilter(){
+ Stream filteredWrappers =matrix.getSpecimenCache().stream();
+ if(comboTaxon.getSelection()!=null){
+ filteredWrappers =
+ filteredWrappers
+ .filter(wrapper->wrapper.getTaxonNode().equals(comboTaxon.getSelection()));
+ }
+ if(!CdmUtils.isBlank(txtTextFilter.getText())){
+ filteredWrappers =
+ filteredWrappers
+ .filter(wrapper->wrapper.getLabel().toLowerCase().contains(txtTextFilter.getText().toLowerCase()));
+ }
+ list.setInput(filteredWrappers.collect(Collectors.toList()));
+ }
+
private void loadSpecimens(){
List specimenCache = new ArrayList<>();
//set filter parameters
--
2.34.1