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.List;
14: import java.util.Map;
15:
16: import org.eclipse.jface.preference.IPreferenceNode;
17: import org.eclipse.jface.preference.PreferenceManager;
18: import org.eclipse.jface.resource.ImageDescriptor;
19: import org.eclipse.jface.viewers.ISelection;
20: import org.eclipse.jface.viewers.IStructuredSelection;
21: import org.eclipse.ui.IWorkbenchPage;
22: import org.eclipse.ui.PlatformUI;
23: import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
24: import org.eclipse.ui.internal.WorkbenchImages;
25: import org.eclipse.ui.internal.dialogs.PropertyPageContributorManager;
26: import org.eclipse.ui.internal.dialogs.PropertyPageManager;
27:
28: /**
29: * @since 3.3
30: *
31: */
32: public class PropertiesProvider extends QuickAccessProvider {
33:
34: private Map idToElement;
35:
36: public QuickAccessElement getElementForId(String id) {
37: getElements();
38: return (PropertiesElement) idToElement.get(id);
39: }
40:
41: public QuickAccessElement[] getElements() {
42: if (idToElement == null) {
43: idToElement = new HashMap();
44: IWorkbenchPage activePage = PlatformUI.getWorkbench()
45: .getActiveWorkbenchWindow().getActivePage();
46: if (activePage != null) {
47: PropertyPageManager pageManager = new PropertyPageManager();
48: ISelection selection = activePage.getSelection();
49: if (selection instanceof IStructuredSelection
50: && !selection.isEmpty()) {
51: Object element = ((IStructuredSelection) selection)
52: .getFirstElement();
53: PropertyPageContributorManager.getManager()
54: .contribute(pageManager, element);
55: List list = pageManager
56: .getElements(PreferenceManager.PRE_ORDER);
57: IPreferenceNode[] properties = (IPreferenceNode[]) list
58: .toArray(new IPreferenceNode[list.size()]);
59: for (int i = 0; i < properties.length; i++) {
60: PropertiesElement propertiesElement = new PropertiesElement(
61: element, properties[i], this );
62: idToElement.put(propertiesElement.getId(),
63: propertiesElement);
64: }
65: }
66: }
67: }
68: return (QuickAccessElement[]) idToElement.values().toArray(
69: new QuickAccessElement[idToElement.values().size()]);
70: }
71:
72: public String getId() {
73: return "org.eclipse.ui.properties"; //$NON-NLS-1$
74: }
75:
76: public ImageDescriptor getImageDescriptor() {
77: return WorkbenchImages
78: .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
79: }
80:
81: public String getName() {
82: return QuickAccessMessages.QuickAccess_Properties;
83: }
84: }
|