1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import org.eclipse.jface.viewers.Viewer; 14 import org.eclipse.jface.viewers.ViewerSorter; 15 import org.eclipse.team.internal.core.subscribers.*; 16 import org.eclipse.team.ui.synchronize.ISynchronizeModelElement; 17 18 23 public class ChangeSetModelSorter extends ViewerSorter { 24 25 private int commentCriteria; 26 private ChangeSetModelProvider provider; 27 28 public final static int DATE = 1; 30 public final static int COMMENT = 2; 31 public final static int USER = 3; 32 33 public ChangeSetModelSorter(ChangeSetModelProvider provider, int commentCriteria) { 34 this.provider = provider; 35 this.commentCriteria = commentCriteria; 36 } 37 38 protected int classComparison(Object element) { 39 if (element instanceof ChangeSetDiffNode) { 40 ChangeSet set = ((ChangeSetDiffNode)element).getSet(); 41 if (set instanceof ActiveChangeSet) { 42 return 0; 43 } 44 return 1; 45 } 46 return 2; 47 } 48 49 protected int compareClass(Object element1, Object element2) { 50 return classComparison(element1) - classComparison(element2); 51 } 52 53 protected int compareNames(String s1, String s2) { 54 return collator.compare(s1, s2); 55 } 56 57 60 public int compare(Viewer viewer, Object o1, Object o2) { 61 if (o1 instanceof ChangeSetDiffNode && o2 instanceof ChangeSetDiffNode) { 65 ChangeSet s1 = ((ChangeSetDiffNode) o1).getSet(); 66 ChangeSet s2 = ((ChangeSetDiffNode) o2).getSet(); 67 if (s1 instanceof ActiveChangeSet && s2 instanceof ActiveChangeSet) { 68 return compareNames(((ActiveChangeSet)s1).getTitle(), ((ActiveChangeSet)s2).getTitle()); 69 } 70 if (s1 instanceof CheckedInChangeSet && s2 instanceof CheckedInChangeSet) { 71 CheckedInChangeSet r1 = (CheckedInChangeSet)s1; 72 CheckedInChangeSet r2 = (CheckedInChangeSet)s2; 73 if (commentCriteria == DATE) 74 return r1.getDate().compareTo(r2.getDate()); 75 else if (commentCriteria == COMMENT) 76 return compareNames(r1.getComment(), r2.getComment()); 77 else if (commentCriteria == USER) 78 return compareNames(r1.getAuthor(), r2.getAuthor()); 79 else 80 return 0; 81 } 82 if (s1 instanceof ActiveChangeSet) { 83 return -1; 84 } else if (s2 instanceof ActiveChangeSet) { 85 return 1; 86 } 87 if (s1 instanceof CheckedInChangeSet) { 88 return -1; 89 } else if (s2 instanceof CheckedInChangeSet) { 90 return 1; 91 } 92 } 93 94 if (o1 instanceof ISynchronizeModelElement && o2 instanceof ISynchronizeModelElement) { 95 ViewerSorter embeddedSorter = provider.getEmbeddedSorter(); 96 if (embeddedSorter != null) { 97 return embeddedSorter.compare(viewer, o1, o2); 98 } else { 99 compareNames(((ISynchronizeModelElement)o1).getName(), ((ISynchronizeModelElement)o2).getName()); 100 } 101 } else if (o1 instanceof ISynchronizeModelElement) 102 return 1; 103 else if (o2 instanceof ISynchronizeModelElement) 104 return -1; 105 106 return 0; 107 } 108 109 public int getCommentCriteria() { 110 return commentCriteria; 111 } 112 } 113 | Popular Tags |