Project

General

Profile

« Previous | Next » 

Revision eac96113

Added by Patrick Plitzner over 4 years ago

Disable taxon filter + enable text filter on taxon names

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenSelectionDialog.java
10 10

  
11 11
import java.util.ArrayList;
12 12
import java.util.Collection;
13
import java.util.Collections;
14
import java.util.Comparator;
13 15
import java.util.List;
14 16
import java.util.stream.Collectors;
15 17

  
......
45 47
import eu.etaxonomy.taxeditor.model.ImageResources;
46 48
import eu.etaxonomy.taxeditor.preference.Resources;
47 49
import eu.etaxonomy.taxeditor.store.CdmStore;
48
import eu.etaxonomy.taxeditor.ui.combo.taxon.TaxonNodeCombo;
49 50

  
50 51
/**
51 52
 * Dialog to choose specimens for the character matrix.<br>
......
64 65
    private CharacterMatrix matrix;
65 66
    private Text txtTextFilter;
66 67

  
67
    private TaxonNodeCombo comboTaxon;
68
//    private TaxonNodeCombo comboTaxon;
68 69

  
69 70
    protected SpecimenSelectionDialog(Shell parentShell, CharacterMatrix matrix) {
70 71
        super(parentShell);
......
79 80

  
80 81
        Composite composite_1 = new Composite(composite, SWT.NONE);
81 82
        composite_1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
82
        composite_1.setLayout(new GridLayout(4, false));
83
        composite_1.setLayout(new GridLayout(2, false));
83 84

  
84 85
        Label lblNewLabel = new Label(composite_1, SWT.NONE);
85
        lblNewLabel.setText("Taxon");
86
        lblNewLabel.setText("Refresh");
86 87

  
87
        comboTaxon = new TaxonNodeCombo(composite_1, SWT.NONE);
88
        comboTaxon.setInput(matrix.getDescriptiveDataSet().getTaxonSubtreeFilter());
89
        comboTaxon.addSelectionChangedListener(e->applyFilter());
88
        // FIXME temporary disabled taxon filter because of performance issues
89
//        comboTaxon = new TaxonNodeCombo(composite_1, SWT.NONE);
90
//        comboTaxon.setInput(matrix.getDescriptiveDataSet().getTaxonSubtreeFilter());
91
//        comboTaxon.addSelectionChangedListener(e->applyFilter());
90 92

  
91 93
        txtTextFilter = new Text(composite_1, SWT.BORDER);
92 94
        txtTextFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
......
162 164
    }
163 165

  
164 166
    private void applyFilter(){
165
        Collection<SpecimenNodeWrapper> specimenCache = matrix.getSpecimenCache();
166 167
        List<SpecimenNodeWrapper> result = new ArrayList<>();
167
        if(comboTaxon.getSelection()!=null){
168
            result.addAll(specimenCache.stream()
169
                    .filter(wrapper->wrapper.getTaxonNode().equals(comboTaxon.getSelection()))
170
                    .collect(Collectors.toList()));
168
        Collection<SpecimenNodeWrapper> specimenCache = matrix.getSpecimenCache();
169
        if(CdmUtils.isBlank(txtTextFilter.getText())){
170
            result = new ArrayList<>(specimenCache);
171 171
        }
172
        if(!txtTextFilter.getForeground().equals(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND))
173
                &&!CdmUtils.isBlank(txtTextFilter.getText())){
174
            result.addAll(specimenCache.stream()
175
                    .filter(wrapper->wrapper.getUuidAndTitleCache().getTitleCache().toLowerCase().contains(txtTextFilter.getText().toLowerCase()))
176
                    .collect(Collectors.toList()));
172
        else{
173
            //        if(comboTaxon.getSelection()!=null){
174
            //            result.addAll(specimenCache.stream()
175
            //                    .filter(wrapper->wrapper.getTaxonNode().equals(comboTaxon.getSelection()))
176
            //                    .collect(Collectors.toList()));
177
            //        }
178
            if(!txtTextFilter.getForeground().equals(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND))
179
                    &&!CdmUtils.isBlank(txtTextFilter.getText())){
180
                result.addAll(specimenCache.stream()
181
                        .filter(wrapper->wrapper.getUuidAndTitleCache().getTitleCache().toLowerCase().contains(txtTextFilter.getText().toLowerCase()))
182
                        .collect(Collectors.toList()));
183
                result.addAll(specimenCache.stream()
184
                        .filter(wrapper->wrapper.getTaxonNode().getTaxon().getTitleCache().toLowerCase().contains(txtTextFilter.getText().toLowerCase()))
185
                        .collect(Collectors.toList()));
186
            }
177 187
        }
178 188
        list.setInput(result);
179 189
    }
180 190

  
181 191
    private void loadSpecimens(){
182
        Collection<SpecimenNodeWrapper> specimenCache = CdmStore.getService(IDescriptiveDataSetService.class).loadSpecimens(matrix.getDescriptiveDataSet());
183
        matrix.setSpecimenCache(specimenCache);
192
        ArrayList<SpecimenNodeWrapper> specimenList = new ArrayList<>(CdmStore.getService(IDescriptiveDataSetService.class).loadSpecimens(matrix.getDescriptiveDataSet()));
193
        Collections.sort(specimenList, new Comparator<SpecimenNodeWrapper>() {
194

  
195
            @Override
196
            public int compare(SpecimenNodeWrapper o1, SpecimenNodeWrapper o2) {
197
                if(o1 == null){
198
                    if(o2 == null){
199
                        return 0;
200
                    }
201
                    return -1;
202
                }
203
                if(o2==null){
204
                    return 1;
205
                }
206
                try{
207
                    return o1.getTaxonNode().getTaxon().getTitleCache().compareTo(o2.getTaxonNode().getTaxon().getTitleCache());
208
                }
209
                catch(NullPointerException e){
210
                    return 0;
211
                }
212
            }
213
        });
214
        matrix.setSpecimenCache(specimenList);
184 215
    }
185 216

  
186 217
    @Override

Also available in: Unified diff