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.IEditorReference;
17: import org.eclipse.ui.IWorkbenchPage;
18: import org.eclipse.ui.PlatformUI;
19: import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
20: import org.eclipse.ui.internal.WorkbenchImages;
21:
22: /**
23: * @since 3.3
24: *
25: */
26: public class EditorProvider extends QuickAccessProvider {
27:
28: private Map idToElement;
29:
30: public QuickAccessElement getElementForId(String id) {
31: getElements();
32: return (EditorElement) idToElement.get(id);
33: }
34:
35: public QuickAccessElement[] getElements() {
36: if (idToElement == null) {
37: idToElement = new HashMap();
38: IWorkbenchPage activePage = PlatformUI.getWorkbench()
39: .getActiveWorkbenchWindow().getActivePage();
40: IEditorReference[] editors = activePage
41: .getEditorReferences();
42: for (int i = 0; i < editors.length; i++) {
43: EditorElement editorElement = new EditorElement(
44: editors[i], this );
45: idToElement.put(editorElement.getId(), editorElement);
46: }
47: }
48: return (QuickAccessElement[]) idToElement.values().toArray(
49: new QuickAccessElement[idToElement.values().size()]);
50: }
51:
52: public String getId() {
53: return "org.eclipse.ui.editors"; //$NON-NLS-1$
54: }
55:
56: public ImageDescriptor getImageDescriptor() {
57: return WorkbenchImages
58: .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
59: }
60:
61: public String getName() {
62: return QuickAccessMessages.QuickAccess_Editors;
63: }
64: }
|