1 11 12 package org.eclipse.ui.internal.quickaccess; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 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 27 public class PerspectiveProvider extends QuickAccessProvider { 28 29 private QuickAccessElement[] cachedElements; 30 private Map idToElement = new HashMap (); 31 32 public String getId() { 33 return "org.eclipse.ui.perspectives"; } 35 36 public QuickAccessElement getElementForId(String 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 getName() { 62 return QuickAccessMessages.QuickAccess_Perspectives; 63 } 64 } 65 | Popular Tags |