KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.jface.preference.IPreferenceNode;
19 import org.eclipse.jface.preference.PreferenceManager;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.ui.IWorkbenchPage;
24 import org.eclipse.ui.PlatformUI;
25 import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
26 import org.eclipse.ui.internal.WorkbenchImages;
27 import org.eclipse.ui.internal.dialogs.PropertyPageContributorManager;
28 import org.eclipse.ui.internal.dialogs.PropertyPageManager;
29
30 /**
31  * @since 3.3
32  *
33  */

34 public class PropertiesProvider extends QuickAccessProvider {
35
36     private Map JavaDoc idToElement;
37
38     public QuickAccessElement getElementForId(String JavaDoc id) {
39         getElements();
40         return (PropertiesElement) idToElement.get(id);
41     }
42
43     public QuickAccessElement[] getElements() {
44         if (idToElement == null) {
45             idToElement = new HashMap JavaDoc();
46             IWorkbenchPage activePage = PlatformUI.getWorkbench()
47                     .getActiveWorkbenchWindow().getActivePage();
48             if (activePage != null) {
49                 PropertyPageManager pageManager = new PropertyPageManager();
50                 ISelection selection = activePage.getSelection();
51                 if (selection instanceof IStructuredSelection
52                         && !selection.isEmpty()) {
53                     Object JavaDoc element = ((IStructuredSelection) selection)
54                             .getFirstElement();
55                     PropertyPageContributorManager.getManager().contribute(
56                             pageManager, element);
57                     List JavaDoc list = pageManager
58                             .getElements(PreferenceManager.PRE_ORDER);
59                     IPreferenceNode[] properties = (IPreferenceNode[]) list
60                             .toArray(new IPreferenceNode[list.size()]);
61                     for (int i = 0; i < properties.length; i++) {
62                         PropertiesElement propertiesElement = new PropertiesElement(
63                                 element, properties[i], this);
64                         idToElement.put(propertiesElement.getId(),
65                                 propertiesElement);
66                     }
67                 }
68             }
69         }
70         return (QuickAccessElement[]) idToElement.values().toArray(
71                 new QuickAccessElement[idToElement.values().size()]);
72     }
73
74     public String JavaDoc getId() {
75         return "org.eclipse.ui.properties"; //$NON-NLS-1$
76
}
77
78     public ImageDescriptor getImageDescriptor() {
79         return WorkbenchImages
80                 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
81     }
82
83     public String JavaDoc getName() {
84         return QuickAccessMessages.QuickAccess_Properties;
85     }
86 }
87
Popular Tags