KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > history > BrowseRefactoringHistoryViewerSorter


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.ltk.internal.ui.refactoring.history;
12
13 import org.eclipse.jface.viewers.Viewer;
14 import org.eclipse.jface.viewers.ViewerComparator;
15
16 /**
17  * Viewer sorter for the browse refactoring history control.
18  *
19  * @since 3.2
20  */

21 public final class BrowseRefactoringHistoryViewerSorter extends ViewerComparator {
22
23     /**
24      * {@inheritDoc}
25      */

26     public int category(final Object JavaDoc element) {
27         if (element instanceof RefactoringHistoryProject)
28             return 0;
29         return 1;
30     }
31
32     /**
33      * {@inheritDoc}
34      */

35     public int compare(final Viewer viewer, final Object JavaDoc first, final Object JavaDoc second) {
36         if (first instanceof RefactoringHistoryProject && second instanceof RefactoringHistoryProject) {
37             final RefactoringHistoryProject predecessor= (RefactoringHistoryProject) first;
38             final RefactoringHistoryProject successor= (RefactoringHistoryProject) second;
39             return getComparator().compare(predecessor.getProject(), successor.getProject());
40         } else if (first instanceof RefactoringHistoryDate && second instanceof RefactoringHistoryDate) {
41             final RefactoringHistoryDate predecessor= (RefactoringHistoryDate) first;
42             final RefactoringHistoryDate successor= (RefactoringHistoryDate) second;
43             final int delta= predecessor.getKind() - successor.getKind();
44             if (delta != 0)
45                 return delta;
46             final long result= successor.getTimeStamp() - predecessor.getTimeStamp();
47             if (result < 0)
48                 return -1;
49             else if (result > 0)
50                 return 1;
51             return 0;
52         } else if (first instanceof RefactoringHistoryEntry && second instanceof RefactoringHistoryEntry) {
53             final RefactoringHistoryEntry predecessor= (RefactoringHistoryEntry) first;
54             final RefactoringHistoryEntry successor= (RefactoringHistoryEntry) second;
55             final long delta= successor.getDescriptor().getTimeStamp() - predecessor.getDescriptor().getTimeStamp();
56             if (delta < 0)
57                 return -1;
58             else if (delta > 0)
59                 return 1;
60             else
61                 return 0;
62         }
63         return super.compare(viewer, first, second);
64     }
65 }
Popular Tags