KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > LaunchConfigurationComparator


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.debug.internal.ui.launchConfigurations;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.Collections JavaDoc;
15 import java.util.Comparator JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.debug.core.DebugPlugin;
23 import org.eclipse.debug.core.ILaunchConfiguration;
24 import org.eclipse.debug.core.ILaunchConfigurationType;
25 import org.eclipse.ui.model.WorkbenchViewerComparator;
26
27 /**
28  * Groups configurations by type.
29  *
30  * @since 3.3
31  * CONTEXTLAUNCHING
32  */

33 public class LaunchConfigurationComparator extends WorkbenchViewerComparator {
34
35     /**
36      * the map of categories of <code>ILaunchConfigurationType</code>s to <code>Integer</code>s entries
37      */

38     private static Map JavaDoc fgCategories;
39     
40     /**
41      * @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
42      */

43     public int category(Object JavaDoc element) {
44         Map JavaDoc map = getCategories();
45         if (element instanceof ILaunchConfiguration) {
46             ILaunchConfiguration configuration = (ILaunchConfiguration) element;
47             try {
48                 Integer JavaDoc i = (Integer JavaDoc) map.get(configuration.getType());
49                 if (i != null) {
50                     return i.intValue();
51                 }
52             } catch (CoreException e) {
53             }
54         }
55         return map.size();
56     }
57     
58     /**
59      * Returns the map of categories
60      * @return the map of categories
61      */

62     private Map JavaDoc getCategories() {
63         if (fgCategories == null) {
64             fgCategories = new HashMap JavaDoc();
65             List JavaDoc types = Arrays.asList(DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes());
66             Collections.sort(types, new Comparator JavaDoc() {
67                 public int compare(Object JavaDoc o1, Object JavaDoc o2) {
68                     ILaunchConfigurationType t1 = (ILaunchConfigurationType) o1;
69                     ILaunchConfigurationType t2 = (ILaunchConfigurationType) o2;
70                     return t1.getName().compareTo(t2.getName());
71                 }
72             
73             });
74             Iterator JavaDoc iterator = types.iterator();
75             int i = 0;
76             while (iterator.hasNext()) {
77                 fgCategories.put(iterator.next(), new Integer JavaDoc(i));
78                 i++;
79             }
80         }
81         return fgCategories;
82     }
83 }
84
Popular Tags