KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > quickaccess > QuickAccessProvider


1 /*******************************************************************************
2  * Copyright (c) 2006, 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
12 package org.eclipse.ui.internal.quickaccess;
13
14 import java.util.Arrays JavaDoc;
15 import java.util.Comparator JavaDoc;
16
17 import org.eclipse.jface.resource.ImageDescriptor;
18
19 /**
20  * @since 3.3
21  *
22  */

23 public abstract class QuickAccessProvider {
24
25     private QuickAccessElement[] sortedElements;
26
27     /**
28      * Returns the unique ID of this provider.
29      *
30      * @return the unique ID
31      */

32     public abstract String JavaDoc getId();
33
34     /**
35      * Returns the name of this provider to be displayed to the user.
36      *
37      * @return the name
38      */

39     public abstract String JavaDoc getName();
40
41     /**
42      * Returns the image descriptor for this provider.
43      *
44      * @return the image descriptor, or null if not defined
45      */

46     public abstract ImageDescriptor getImageDescriptor();
47
48     /**
49      * Returns the elements provided by this provider.
50      *
51      * @return this provider's elements
52      */

53     public abstract QuickAccessElement[] getElements();
54
55     public QuickAccessElement[] getElementsSorted() {
56         if (sortedElements == null) {
57             sortedElements = getElements();
58             Arrays.sort(sortedElements, new Comparator JavaDoc() {
59                 public int compare(Object JavaDoc o1, Object JavaDoc o2) {
60                     QuickAccessElement e1 = (QuickAccessElement) o1;
61                     QuickAccessElement e2 = (QuickAccessElement) o2;
62                     return e1.getLabel().compareTo(e2.getLabel());
63                 }
64             });
65         }
66         return sortedElements;
67     }
68     
69     /**
70      * Returns the element for the given ID if available, or null if no matching
71      * element is available.
72      *
73      * @param id
74      * the ID of an element
75      * @return the element with the given ID, or null if not found.
76      */

77     public abstract QuickAccessElement getElementForId(String JavaDoc id);
78 }
79
Popular Tags