KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.ui.IPerspectiveDescriptor;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
21 import org.eclipse.ui.internal.WorkbenchImages;
22
23 /**
24  * @since 3.3
25  *
26  */

27 public class PerspectiveProvider extends QuickAccessProvider {
28
29     private QuickAccessElement[] cachedElements;
30     private Map JavaDoc idToElement = new HashMap JavaDoc();
31
32     public String JavaDoc getId() {
33         return "org.eclipse.ui.perspectives"; //$NON-NLS-1$
34
}
35
36     public QuickAccessElement getElementForId(String JavaDoc id) {
37         getElements();
38         return (PerspectiveElement) idToElement.get(id);
39     }
40
41     public QuickAccessElement[] getElements() {
42         if (cachedElements == null) {
43             IPerspectiveDescriptor[] perspectives = PlatformUI.getWorkbench()
44                     .getPerspectiveRegistry().getPerspectives();
45             cachedElements = new QuickAccessElement[perspectives.length];
46             for (int i = 0; i < perspectives.length; i++) {
47                 PerspectiveElement perspectiveElement = new PerspectiveElement(
48                         perspectives[i], this);
49                 cachedElements[i] = perspectiveElement;
50                 idToElement.put(perspectiveElement.getId(), 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 JavaDoc getName() {
62         return QuickAccessMessages.QuickAccess_Perspectives;
63     }
64 }
65
Popular Tags