Project

General

Profile

Revision 71ef005a

ID71ef005ae9cb2ba3c293dc6f151e0a44c4ab1900
Parent 835c1454
Child 46d40a62

Added by Patrick Plitzner over 2 years ago

ref #7095 Add text filter to specimen selection dialog

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java
13 13
import java.util.List;
14 14
import java.util.UUID;
15 15
import java.util.stream.Collectors;
16
import java.util.stream.Stream;
16 17

  
17 18
import org.eclipse.jface.dialogs.Dialog;
18 19
import org.eclipse.jface.layout.GridDataFactory;
......
38 39
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
39 40
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
40 41
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
42
import eu.etaxonomy.cdm.common.CdmUtils;
41 43
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
42 44
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
43 45
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
81 83

  
82 84
        txtTextFilter = new Text(composite_1, SWT.BORDER);
83 85
        txtTextFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
86
        txtTextFilter.addModifyListener(e->applyFilter());
84 87

  
85 88
        comboTaxon = new TaxonNodeCombo(composite_1, SWT.NONE);
86 89
        comboTaxon.setInput(matrix.getWorkingSet().getTaxonSubtreeFilter());
87
        comboTaxon.addSelectionChangedListener(e->
88
        list.setInput(
89
                matrix.getSpecimenCache()
90
                .stream()
91
                .filter(wrapper->wrapper.getTaxonNode().equals(comboTaxon.getSelection()))
92
                .collect(Collectors.toList()))
93
        );
90
        comboTaxon.addSelectionChangedListener(e->applyFilter());
94 91

  
95 92
        Button btnRefreshButton = new Button(composite_1, SWT.NONE);
96 93
        btnRefreshButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
......
106 103
        //table
107 104
        list = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
108 105
        Table table = list.getTable();
109
        table.setLayoutData(GridDataFactory.fillDefaults().create());
106
        GridData gd_table = GridDataFactory.fillDefaults().create();
107
        gd_table.grabExcessHorizontalSpace = true;
108
        gd_table.grabExcessVerticalSpace = true;
109
        table.setLayoutData(gd_table);
110 110
        //table columns
111 111
        TableViewerColumn columnTaxon = new TableViewerColumn(list, SWT.NONE);
112 112
        columnTaxon.getColumn().setText("Taxon");
......
131 131
        return composite;
132 132
    }
133 133

  
134
    private void applyFilter(){
135
        Stream<SpecimenWrapper> filteredWrappers =matrix.getSpecimenCache().stream();
136
        if(comboTaxon.getSelection()!=null){
137
            filteredWrappers =
138
                    filteredWrappers
139
                    .filter(wrapper->wrapper.getTaxonNode().equals(comboTaxon.getSelection()));
140
        }
141
        if(!CdmUtils.isBlank(txtTextFilter.getText())){
142
            filteredWrappers =
143
                    filteredWrappers
144
                    .filter(wrapper->wrapper.getLabel().toLowerCase().contains(txtTextFilter.getText().toLowerCase()));
145
        }
146
        list.setInput(filteredWrappers.collect(Collectors.toList()));
147
    }
148

  
134 149
    private void loadSpecimens(){
135 150
        List<SpecimenWrapper> specimenCache = new ArrayList<>();
136 151
        //set filter parameters

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)