1 11 package org.eclipse.pde.internal.ui.views.dependencies; 12 13 import java.util.Arrays ; 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 import java.util.Set ; 19 20 import org.eclipse.jface.viewers.IStructuredContentProvider; 21 import org.eclipse.osgi.service.resolver.BundleDescription; 22 import org.eclipse.osgi.service.resolver.BundleSpecification; 23 import org.eclipse.osgi.service.resolver.ExportPackageDescription; 24 import org.eclipse.osgi.service.resolver.ImportPackageSpecification; 25 import org.eclipse.pde.core.plugin.IPluginModelBase; 26 import org.eclipse.pde.core.plugin.PluginRegistry; 27 import org.osgi.framework.Constants; 28 29 public class CalleesListContentProvider extends CalleesContentProvider 30 implements IStructuredContentProvider { 31 32 boolean fShowOptional; 33 34 public CalleesListContentProvider(DependenciesView view) { 35 super(view); 36 } 37 38 public void setShowOptional(boolean showOptional) { 39 fShowOptional = showOptional; 40 } 41 42 public boolean getShowOptional() { 43 return fShowOptional; 44 } 45 46 49 public Object [] getElements(Object inputElement) { 50 if (inputElement instanceof IPluginModelBase) { 51 Map elements = new HashMap (); 52 Set candidates = new HashSet (); 53 candidates.addAll(Arrays.asList(findCallees(((IPluginModelBase)inputElement)))); 54 55 while (!candidates.isEmpty()) { 56 Set newCandidates = new HashSet (); 57 for (Iterator it = candidates.iterator(); it.hasNext();) { 58 Object candidate = it.next(); 59 BundleDescription desc = null; 60 it.remove(); 61 if(candidate instanceof BundleSpecification){ 62 if (!fShowOptional && ((BundleSpecification)candidate).isOptional()) 63 continue; 64 desc = (BundleDescription)((BundleSpecification)candidate).getSupplier(); 65 if (desc == null) 67 elements.put(((BundleSpecification)candidate).getName(), candidate); 68 } else if (candidate instanceof BundleDescription) { 69 desc = (BundleDescription)candidate; 70 } else if (candidate instanceof ImportPackageSpecification) { 71 if (!fShowOptional && Constants.RESOLUTION_OPTIONAL.equals( 72 ((ImportPackageSpecification)candidate).getDirective(Constants.RESOLUTION_DIRECTIVE))) 73 continue; 74 desc = ((ExportPackageDescription)(((ImportPackageSpecification)candidate).getSupplier())).getExporter(); 75 } 76 if (desc == null) 77 continue; 78 IPluginModelBase callee = PluginRegistry.findModel(desc.getSymbolicName()); 79 if (!elements.containsKey(desc.getSymbolicName())) { 80 elements.put(desc.getSymbolicName(), candidate); 81 if (callee != null) { 82 newCandidates.addAll(Arrays 83 .asList(findCallees(desc))); 84 } 85 } 86 } 87 candidates = newCandidates; 88 89 } 90 return elements.values().toArray(); 91 } 92 return new Object [0]; 93 } 94 } 95 | Popular Tags |