KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > views > dependencies > DependenciesViewComparator


1 /*******************************************************************************
2  * Copyright (c) 2007 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.pde.internal.ui.views.dependencies;
12
13 import org.eclipse.jface.viewers.Viewer;
14 import org.eclipse.jface.viewers.ViewerComparator;
15 import org.eclipse.osgi.service.resolver.BundleDescription;
16 import org.eclipse.osgi.service.resolver.BundleSpecification;
17 import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
18 import org.eclipse.pde.internal.ui.PDEPlugin;
19
20 public class DependenciesViewComparator extends ViewerComparator {
21     
22     private static DependenciesViewComparator fComparator = null;
23     
24     private DependenciesViewComparator() {
25         super();
26     }
27     
28     public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
29         return getId(e1).compareTo(getId(e2));
30     }
31     
32     private String JavaDoc getId(Object JavaDoc obj) {
33         BundleDescription desc = null;
34         if (obj instanceof ImportPackageSpecification) {
35             return ((ImportPackageSpecification)obj).getName();
36         } else if (obj instanceof BundleSpecification) {
37             desc = (BundleDescription)((BundleSpecification)obj).getSupplier();
38         } else if (obj instanceof BundleDescription)
39             desc = (BundleDescription)obj;
40         if (desc != null)
41             return PDEPlugin.getDefault().getLabelProvider().getObjectText(desc);
42         return ""; //$NON-NLS-1$
43
}
44     
45     public static DependenciesViewComparator getViewerComparator() {
46         if (fComparator == null)
47             fComparator = new DependenciesViewComparator();
48         return fComparator;
49     }
50
51 }
52
Popular Tags