KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > jres > JREsEnvironmentComparator


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.jdt.internal.debug.ui.jres;
12
13 import org.eclipse.jdt.launching.IVMInstall;
14 import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
15 import org.eclipse.jface.viewers.Viewer;
16 import org.eclipse.jface.viewers.ViewerComparator;
17
18 /**
19  * Sorts execution environments.
20  *
21  * @since 3.3
22  */

23 public class JREsEnvironmentComparator extends ViewerComparator {
24     
25     IExecutionEnvironment fEnvironment;
26
27     /* (non-Javadoc)
28      * @see org.eclipse.jface.viewers.ViewerSorter#category(java.lang.Object)
29      */

30     public int category(Object JavaDoc element) {
31         if (fEnvironment == null) {
32             return super.category(element);
33         } else {
34             if (fEnvironment.isStrictlyCompatible((IVMInstall) element)) {
35                 return 0;
36             } else {
37                 return 1;
38             }
39         }
40     }
41
42     /* (non-Javadoc)
43      * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
44      */

45     public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
46         fEnvironment = (IExecutionEnvironment) viewer.getInput();
47         int result = super.compare(viewer, e1, e2);
48         fEnvironment = null;
49         return result;
50     }
51
52 }
53
Popular Tags