1 11 package org.eclipse.ui.internal; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IConfigurationElement; 18 import org.eclipse.core.runtime.IExtension; 19 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; 20 import org.eclipse.jface.action.IMenuManager; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.jface.viewers.ISelectionProvider; 23 import org.eclipse.jface.viewers.IStructuredSelection; 24 import org.eclipse.ui.IWorkbenchPart; 25 26 30 public class ObjectActionContributorManager extends ObjectContributorManager { 31 private static ObjectActionContributorManager sharedInstance; 32 33 36 public ObjectActionContributorManager() { 37 super(); 38 loadContributors(); 39 } 40 41 50 public boolean contributeObjectActions(IWorkbenchPart part, 51 IMenuManager popupMenu, ISelectionProvider selProv) { 52 ISelection selection = selProv.getSelection(); 54 if (selection == null) { 55 return false; 56 } 57 58 List elements = null; 63 if (selection instanceof IStructuredSelection) { 64 elements = ((IStructuredSelection) selection).toList(); 65 } else { 66 elements = new ArrayList (1); 67 elements.add(selection); 68 } 69 70 List contributors = getContributors(elements); 71 72 if (contributors.isEmpty()) { 73 return false; 74 } 75 76 boolean actualContributions = false; 79 ArrayList overrides = new ArrayList (4); 80 for (Iterator it = contributors.iterator(); it.hasNext();) { 81 IObjectActionContributor contributor = (IObjectActionContributor) it.next(); 82 if (!isApplicableTo(elements, contributor)) { 83 it.remove(); 84 continue; 85 } 86 if (contributor.contributeObjectMenus(popupMenu, selProv)) { 87 actualContributions = true; 88 } 89 contributor.contributeObjectActionIdOverrides(overrides); 90 } 91 92 for (Iterator it = contributors.iterator(); it.hasNext();) { 95 IObjectActionContributor contributor = (IObjectActionContributor) it.next(); 96 if (contributor.contributeObjectActions(part, popupMenu, selProv, 97 overrides)) { 98 actualContributions = true; 99 } 100 } 101 return actualContributions; 102 } 103 104 108 public static ObjectActionContributorManager getManager() { 109 if (sharedInstance == null) { 110 sharedInstance = new ObjectActionContributorManager(); 111 } 112 return sharedInstance; 113 } 114 115 118 private void loadContributors() { 119 ObjectActionContributorReader reader = new ObjectActionContributorReader(); 120 reader.readPopupContributors(this); 121 } 122 123 126 public void addExtension(IExtensionTracker tracker, IExtension addedExtension) { 127 IConfigurationElement[] addedElements = addedExtension.getConfigurationElements(); 128 for (int i = 0; i < addedElements.length; i++) { 129 ObjectActionContributorReader reader = new ObjectActionContributorReader(); 130 reader.setManager(this); 131 reader.readElement(addedElements[i]); 132 } 133 } 134 } 135 | Popular Tags |