01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.quickaccess;
11:
12: import java.util.Arrays;
13: import java.util.Comparator;
14:
15: import org.eclipse.jface.resource.ImageDescriptor;
16:
17: /**
18: * @since 3.3
19: *
20: */
21: public abstract class QuickAccessProvider {
22:
23: private QuickAccessElement[] sortedElements;
24:
25: /**
26: * Returns the unique ID of this provider.
27: *
28: * @return the unique ID
29: */
30: public abstract String getId();
31:
32: /**
33: * Returns the name of this provider to be displayed to the user.
34: *
35: * @return the name
36: */
37: public abstract String getName();
38:
39: /**
40: * Returns the image descriptor for this provider.
41: *
42: * @return the image descriptor, or null if not defined
43: */
44: public abstract ImageDescriptor getImageDescriptor();
45:
46: /**
47: * Returns the elements provided by this provider.
48: *
49: * @return this provider's elements
50: */
51: public abstract QuickAccessElement[] getElements();
52:
53: public QuickAccessElement[] getElementsSorted() {
54: if (sortedElements == null) {
55: sortedElements = getElements();
56: Arrays.sort(sortedElements, new Comparator() {
57: public int compare(Object o1, Object o2) {
58: QuickAccessElement e1 = (QuickAccessElement) o1;
59: QuickAccessElement e2 = (QuickAccessElement) o2;
60: return e1.getLabel().compareTo(e2.getLabel());
61: }
62: });
63: }
64: return sortedElements;
65: }
66:
67: /**
68: * Returns the element for the given ID if available, or null if no matching
69: * element is available.
70: *
71: * @param id
72: * the ID of an element
73: * @return the element with the given ID, or null if not found.
74: */
75: public abstract QuickAccessElement getElementForId(String id);
76: }
|