1 11 12 package org.eclipse.ui.internal.quickaccess; 13 14 import java.util.HashMap ; 15 import java.util.List ; 16 import java.util.Map ; 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 34 public class PropertiesProvider extends QuickAccessProvider { 35 36 private Map idToElement; 37 38 public QuickAccessElement getElementForId(String id) { 39 getElements(); 40 return (PropertiesElement) idToElement.get(id); 41 } 42 43 public QuickAccessElement[] getElements() { 44 if (idToElement == null) { 45 idToElement = new HashMap (); 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 element = ((IStructuredSelection) selection) 54 .getFirstElement(); 55 PropertyPageContributorManager.getManager().contribute( 56 pageManager, element); 57 List 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 getId() { 75 return "org.eclipse.ui.properties"; } 77 78 public ImageDescriptor getImageDescriptor() { 79 return WorkbenchImages 80 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE); 81 } 82 83 public String getName() { 84 return QuickAccessMessages.QuickAccess_Properties; 85 } 86 } 87 | Popular Tags |