KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > mappings > ChangeSetSorter


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     // Comment sorting options
23
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     /* (non-Javadoc)
33      * Method declared on ViewerSorter.
34      */

35     public int compare(Viewer viewer, Object JavaDoc o1, Object JavaDoc o2) {
36         //have to deal with non-resources in navigator
37
//if one or both objects are not resources, returned a comparison
38
//based on class.
39
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 JavaDoc s1, String JavaDoc 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