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.HashMap;
13: import java.util.Map;
14:
15: import org.eclipse.jface.resource.ImageDescriptor;
16: import org.eclipse.ui.IPerspectiveDescriptor;
17: import org.eclipse.ui.PlatformUI;
18: import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
19: import org.eclipse.ui.internal.WorkbenchImages;
20:
21: /**
22: * @since 3.3
23: *
24: */
25: public class PerspectiveProvider extends QuickAccessProvider {
26:
27: private QuickAccessElement[] cachedElements;
28: private Map idToElement = new HashMap();
29:
30: public String getId() {
31: return "org.eclipse.ui.perspectives"; //$NON-NLS-1$
32: }
33:
34: public QuickAccessElement getElementForId(String id) {
35: getElements();
36: return (PerspectiveElement) idToElement.get(id);
37: }
38:
39: public QuickAccessElement[] getElements() {
40: if (cachedElements == null) {
41: IPerspectiveDescriptor[] perspectives = PlatformUI
42: .getWorkbench().getPerspectiveRegistry()
43: .getPerspectives();
44: cachedElements = new QuickAccessElement[perspectives.length];
45: for (int i = 0; i < perspectives.length; i++) {
46: PerspectiveElement perspectiveElement = new PerspectiveElement(
47: perspectives[i], this );
48: cachedElements[i] = perspectiveElement;
49: idToElement.put(perspectiveElement.getId(),
50: perspectiveElement);
51: }
52: }
53: return cachedElements;
54: }
55:
56: public ImageDescriptor getImageDescriptor() {
57: return WorkbenchImages
58: .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_DEF_PERSPECTIVE);
59: }
60:
61: public String getName() {
62: return QuickAccessMessages.QuickAccess_Perspectives;
63: }
64: }
|