KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > SynchronizeModelElementSorter


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.synchronize;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.jface.viewers.Viewer;
15 import org.eclipse.team.internal.ui.Utils;
16 import org.eclipse.ui.views.navigator.ResourceSorter;
17
18 /**
19  * This class sorts <code>SyncInfoModelElement</code> instances.
20  * It is not thread safe so it should not be reused between views.
21  */

22 public class SynchronizeModelElementSorter extends ResourceSorter {
23             
24     public SynchronizeModelElementSorter() {
25         super(ResourceSorter.NAME);
26     }
27
28     /* (non-Javadoc)
29      * Method declared on ViewerSorter.
30      */

31     public int compare(Viewer viewer, Object JavaDoc o1, Object JavaDoc o2) {
32         IResource resource1 = getResource(o1);
33         IResource resource2 = getResource(o2);
34         int result;
35         if (resource1 != null && resource2 != null) {
36             result = super.compare(viewer, resource1, resource2);
37         } else {
38             result = super.compare(viewer, o1, o2);
39         }
40         return result;
41     }
42
43     protected IResource getResource(Object JavaDoc obj) {
44         IResource[] resources = Utils.getResources(new Object JavaDoc[] {obj});
45         return resources.length == 1 ? resources[0] : null;
46     }
47 }
48
Popular Tags