KickJava   Java API By Example, From Geeks To Geeks.

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


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.IEditorReference;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
22 import org.eclipse.ui.internal.WorkbenchImages;
23
24 /**
25  * @since 3.3
26  *
27  */

28 public class EditorProvider extends QuickAccessProvider {
29
30     private Map JavaDoc idToElement;
31
32     public QuickAccessElement getElementForId(String JavaDoc id) {
33         getElements();
34         return (EditorElement) idToElement.get(id);
35     }
36
37     public QuickAccessElement[] getElements() {
38         if (idToElement == null) {
39             idToElement = new HashMap JavaDoc();
40             IWorkbenchPage activePage = PlatformUI.getWorkbench()
41                     .getActiveWorkbenchWindow().getActivePage();
42             IEditorReference[] editors = activePage.getEditorReferences();
43             for (int i = 0; i < editors.length; i++) {
44                 EditorElement editorElement = new EditorElement(editors[i],
45                         this);
46                 idToElement.put(editorElement.getId(), editorElement);
47             }
48         }
49         return (QuickAccessElement[]) idToElement.values().toArray(
50                 new QuickAccessElement[idToElement.values().size()]);
51     }
52
53     public String JavaDoc getId() {
54         return "org.eclipse.ui.editors"; //$NON-NLS-1$
55
}
56
57     public ImageDescriptor getImageDescriptor() {
58         return WorkbenchImages
59                 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
60     }
61
62     public String JavaDoc getName() {
63         return QuickAccessMessages.QuickAccess_Editors;
64     }
65 }
66
Popular Tags