Project

General

Profile

Revision 64aa3373

ID64aa337311a9b9055ea76f0d4e620889c7edc8ca
Parent 23b1c77b
Child 7e55a0c5

Added by Patrick Plitzner over 5 years ago

Sort root entities in specimen editor #5797

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateContentProvider.java
2 2

  
3 3
import java.util.ArrayList;
4 4
import java.util.Collection;
5
import java.util.Comparator;
5 6
import java.util.LinkedHashSet;
6 7
import java.util.List;
7 8
import java.util.Set;
9
import java.util.TreeSet;
8 10

  
9 11
import org.eclipse.jface.viewers.ITreeContentProvider;
10 12
import org.eclipse.jface.viewers.TreeNode;
......
20 22

  
21 23
public class DerivateContentProvider implements ITreeContentProvider {
22 24

  
23
    List<TreeNode> rootNodes;
25
    private TreeSet<TreeNode> rootNodes;
24 26

  
25 27
	@Override
26 28
	public void dispose() {
......
45 47

  
46 48
	@Override
47 49
	public Object[] getElements(Object inputElement) {
48
	    rootNodes = new ArrayList<TreeNode>();
50
	    rootNodes = new TreeSet<TreeNode>(new TreeNodeComparator());
49 51
	    if(inputElement instanceof Collection){
50 52
	        for (Object o: (Collection)inputElement) {
51 53
	            if(o instanceof SpecimenOrObservationBase){
......
141 143
	    }
142 144
	    return derivates;
143 145
	}
146
	
147
	private class TreeNodeComparator implements Comparator<TreeNode>{
148

  
149
		@Override
150
		public int compare(TreeNode o1, TreeNode o2) {
151
			if(o1!=null && o2==null){
152
				return -1;
153
			}
154
			else if(o1==null && o2!=null){
155
				return 1;
156
			}
157
			else if(o1!=null && o2!=null){
158
				SpecimenOrObservationBase<?> specimenOrObservation1 = (SpecimenOrObservationBase<?>) o1.getValue();
159
				SpecimenOrObservationBase<?> specimenOrObservation2 = (SpecimenOrObservationBase<?>) o2.getValue();
160
				return specimenOrObservation1.getTitleCache().compareTo(specimenOrObservation2.getTitleCache());
161
			}
162
			return 0;
163
		}
164
		
165
	}
144 166

  
145 167
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)