KickJava   Java API By Example, From Geeks To Geeks.

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


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

27 public class ViewProvider 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.views"; //$NON-NLS-1$
34
}
35
36     public QuickAccessElement getElementForId(String JavaDoc id) {
37         getElements();
38         return (ViewElement) idToElement.get(id);
39     }
40
41     public QuickAccessElement[] getElements() {
42         if (cachedElements == null) {
43             IViewDescriptor[] views = PlatformUI.getWorkbench()
44                     .getViewRegistry().getViews();
45             cachedElements = new QuickAccessElement[views.length];
46             for (int i = 0; i < views.length; i++) {
47                 ViewElement viewElement = new ViewElement(views[i], this);
48                 cachedElements[i] = viewElement;
49                 idToElement.put(viewElement.getId(), viewElement);
50             }
51         }
52         return cachedElements;
53     }
54
55     public ImageDescriptor getImageDescriptor() {
56         return WorkbenchImages
57                 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_VIEW_DEFAULTVIEW_MISC);
58     }
59
60     public String JavaDoc getName() {
61         return QuickAccessMessages.QuickAccess_Views;
62     }
63 }
64
Popular Tags