Project

General

Profile

« Previous | Next » 

Revision 9f8cd368

Added by Patrick Plitzner over 3 years ago

ref #7806 Sort result list

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/webimport/termimport/GfBioTerminologyImportPresenter.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.Iterator;
16
import java.util.List;
14 17
import java.util.stream.Collectors;
15 18

  
16 19
import org.eclipse.jface.util.LocalSelectionTransfer;
......
35 38
import eu.etaxonomy.taxeditor.model.ColorResources;
36 39
import eu.etaxonomy.taxeditor.model.MessagingUtils;
37 40
import eu.etaxonomy.taxeditor.preference.Resources;
38
import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.ParserUtil;
39 41
import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.TermParser;
40 42
import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestSearch;
41 43
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
......
184 186
        }
185 187
    }
186 188

  
187
    private void loadTermDetails(){
188
        OntologyTermWrapper selectedWrapper = getSelectedTerm((IStructuredSelection) composite.getTreeTermHierarchy().getSelection());
189
        if(selectedWrapper!=null){
190
            ParserUtil.loadDetails(selectedWrapper);
191
            updateDetails(new StructuredSelection(selectedWrapper));
192
        }
193
    }
194

  
195 189
    private void search(){
196 190
        //clear result count
197 191
        composite.getLblResultCount().setText("");
......
205 199
            MessagingUtils.informationDialog(NO_CONNECTION_TITLE, NO_CONNECTION_MESSAGE);
206 200
            return;
207 201
        }
208
        Collection<OntologyTermWrapper> wrapperList = new ArrayList<>();
202
        List<OntologyTermWrapper> wrapperList = new ArrayList<>();
209 203
        wrapperList = TermParser.parse(response);
210 204
        if(wrapperList.isEmpty()){
211 205
            MessagingUtils.informationDialog(Messages.GfBioTerminologyImportPresenter_NO_RESULTS_TITLE, Messages.GfBioTerminologyImportPresenter_NO_RESULTS_MESSAGE);
212 206
        }
207
        //sort list
208
        Collections.sort(wrapperList, new Comparator<OntologyTermWrapper>() {
209
            @Override
210
            public int compare(OntologyTermWrapper o1, OntologyTermWrapper o2) {
211
                String label1 = o1.getLabel();
212
                String label2 = o2.getLabel();
213
                //1. search string at the beginning
214
                if(label1.startsWith(searchString)){
215
                    if(!label2.startsWith(searchString)){
216
                        return -1;
217
                    }
218
                    else{
219
                        return label1.compareTo(label2);
220
                    }
221
                }
222
                else if(label2.startsWith(searchString)){
223
                    return 1;
224
                }
225
                //2. label that contains search string
226
                if(label1.contains(searchString)){
227
                    if(!label2.contains(searchString)){
228
                        return -1;
229
                    }
230
                }
231
                else if(label2.contains(searchString)){
232
                    return 1;
233
                }
234
                return label1.compareTo(label2);
235
            }
236
        });
213 237
        composite.getTreeTermHierarchy().setInput(wrapperList);
214 238

  
215 239
        composite.getLblResultCount().setText(Integer.toString(wrapperList.size()));
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/webimport/termimport/parser/TermParser.java
9 9
package eu.etaxonomy.taxeditor.view.webimport.termimport.parser;
10 10

  
11 11
import java.util.ArrayList;
12
import java.util.Collection;
13 12
import java.util.List;
14 13

  
15 14
import org.json.JSONArray;
......
38 37
        return null;
39 38
    }
40 39

  
41
    public static Collection<OntologyTermWrapper> parse(String response){
40
    public static List<OntologyTermWrapper> parse(String response){
42 41
        List<OntologyTermWrapper> wrapperList = new ArrayList<>();
43 42
        try {
44 43
            JSONObject jsonResponse = new JSONObject(response);

Also available in: Unified diff