Skip to main content
summaryrefslogtreecommitdiffstats
blob: fa2a2f0c9a6a8a3f209b2b3c1c4944b7b10cc17e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.ui.synchronize.presentation;

import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.ui.views.navigator.ResourceSorter;

/**
 * This class sorts <code>SyncInfoDiffNode</code> instances.
 * It is not thread safe so it should not be reused between views.
 */
public class SyncInfoDiffNodeSorter extends ResourceSorter {
			
	public SyncInfoDiffNodeSorter() {
		super(ResourceSorter.NAME);
	}

	/* (non-Javadoc)
	 * Method declared on ViewerSorter.
	 */
	public int compare(Viewer viewer, Object o1, Object o2) {
		IResource resource1 = getResource(o1);
		IResource resource2 = getResource(o2);
		int result;
		if (resource1 != null && resource2 != null) {
			result = super.compare(viewer, resource1, resource2);
		} else {
			result = super.compare(viewer, o1, o2);
		}
		return result;
	}

	protected IResource getResource(Object obj) {
		IResource[] resources = Utils.getResources(new Object[] {obj});
		return resources.length == 1 ? resources[0] : null;
	}
}

Back to the top