1 11 package org.eclipse.team.internal.ccvs.ui.mappings; 12 13 import org.eclipse.jface.viewers.Viewer; 14 import org.eclipse.team.internal.ccvs.core.mapping.CVSCheckedInChangeSet; 15 import org.eclipse.team.internal.core.subscribers.ActiveChangeSet; 16 import org.eclipse.team.internal.core.subscribers.ChangeSet; 17 import org.eclipse.team.internal.ui.mapping.ResourceModelSorter; 18 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 19 20 public class ChangeSetSorter extends ResourceModelSorter { 21 22 public final static int DATE = 1; 24 public final static int COMMENT = 2; 25 public final static int USER = 3; 26 private ISynchronizePageConfiguration configuration; 27 28 public ChangeSetSorter() { 29 super(); 30 } 31 32 35 public int compare(Viewer viewer, Object o1, Object o2) { 36 if (o1 instanceof ChangeSet && o2 instanceof ChangeSet) { 40 ChangeSet s1 = (ChangeSet) o1; 41 ChangeSet s2 = (ChangeSet) o2; 42 if (s1 instanceof ActiveChangeSet && s2 instanceof ActiveChangeSet) { 43 return compareNames(((ActiveChangeSet)s1).getTitle(), ((ActiveChangeSet)s2).getTitle()); 44 } 45 if (s1 instanceof CVSCheckedInChangeSet && s2 instanceof CVSCheckedInChangeSet) { 46 CVSCheckedInChangeSet r1 = (CVSCheckedInChangeSet)s1; 47 CVSCheckedInChangeSet r2 = (CVSCheckedInChangeSet)s2; 48 if (getCommentCriteria() == DATE) 49 return r1.getDate().compareTo(r2.getDate()); 50 else if (getCommentCriteria() == COMMENT) 51 return compareNames(r1.getComment(), r2.getComment()); 52 else if (getCommentCriteria() == USER) 53 return compareNames(r1.getAuthor(), r2.getAuthor()); 54 else 55 return 0; 56 } 57 if (s1 instanceof ActiveChangeSet) { 58 return -1; 59 } else if (s2 instanceof ActiveChangeSet) { 60 return 1; 61 } 62 if (s1 instanceof CVSCheckedInChangeSet) { 63 return -1; 64 } else if (s2 instanceof CVSCheckedInChangeSet) { 65 return 1; 66 } 67 } 68 return super.compare(viewer, o1, o2); 69 } 70 71 private int compareNames(String s1, String s2) { 72 return collator.compare(s1, s2); 73 } 74 75 public int getCommentCriteria() { 76 return ChangeSetActionProvider.getSortCriteria(configuration); 77 } 78 79 public void setConfiguration(ISynchronizePageConfiguration configuration) { 80 this.configuration = configuration; 81 } 82 } 83 | Popular Tags |