KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > views > ContextHelpSorter


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.help.ui.internal.views;
12
13 import org.eclipse.help.IContext2;
14 import org.eclipse.help.IHelpResource;
15 import org.eclipse.jface.viewers.Viewer;
16 import org.eclipse.jface.viewers.ViewerComparator;
17
18 public class ContextHelpSorter extends ViewerComparator {
19     private IContext2 context;
20     
21     public ContextHelpSorter(IContext2 context) {
22         super(ReusableHelpPart.SHARED_COLLATOR);
23         this.context = context;
24     }
25     
26     public int category(Object JavaDoc element) {
27         if (element instanceof IHelpResource) {
28             IHelpResource r = (IHelpResource)element;
29             String JavaDoc c = context.getCategory(r);
30             if (c!=null) {
31                 return -5;
32             }
33         }
34         return super.category(element);
35     }
36
37     /* (non-Javadoc)
38      * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
39      */

40     public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
41         int cat1 = category(e1);
42         int cat2 = category(e2);
43
44         if (cat1 != cat2)
45             return cat1 - cat2;
46         IHelpResource r1 = (IHelpResource) e1;
47         IHelpResource r2 = (IHelpResource) e2;
48         String JavaDoc c1 = context.getCategory(r1);
49         String JavaDoc c2 = context.getCategory(r2);
50         if (c1!=null && c2!=null) {
51             int cat = super.compare(viewer, c1, c2);
52             if (cat!=0) return cat;
53         }
54         return 0;
55     }
56 }
57
Popular Tags