001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.views.dependencies;
011:
012: import java.util.Arrays;
013: import java.util.HashMap;
014: import java.util.HashSet;
015: import java.util.Iterator;
016: import java.util.Map;
017: import java.util.Set;
018:
019: import org.eclipse.jface.viewers.IStructuredContentProvider;
020: import org.eclipse.osgi.service.resolver.BundleDescription;
021: import org.eclipse.osgi.service.resolver.BundleSpecification;
022: import org.eclipse.osgi.service.resolver.ExportPackageDescription;
023: import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
024: import org.eclipse.pde.core.plugin.IPluginModelBase;
025: import org.eclipse.pde.core.plugin.PluginRegistry;
026: import org.osgi.framework.Constants;
027:
028: public class CalleesListContentProvider extends CalleesContentProvider
029: implements IStructuredContentProvider {
030:
031: boolean fShowOptional;
032:
033: public CalleesListContentProvider(DependenciesView view) {
034: super (view);
035: }
036:
037: public void setShowOptional(boolean showOptional) {
038: fShowOptional = showOptional;
039: }
040:
041: public boolean getShowOptional() {
042: return fShowOptional;
043: }
044:
045: /**
046: * @see IStructuredContentProvider#getElements(Object)
047: */
048: public Object[] getElements(Object inputElement) {
049: if (inputElement instanceof IPluginModelBase) {
050: Map elements = new HashMap();
051: Set candidates = new HashSet();
052: candidates
053: .addAll(Arrays
054: .asList(findCallees(((IPluginModelBase) inputElement))));
055:
056: while (!candidates.isEmpty()) {
057: Set newCandidates = new HashSet();
058: for (Iterator it = candidates.iterator(); it.hasNext();) {
059: Object candidate = it.next();
060: BundleDescription desc = null;
061: it.remove();
062: if (candidate instanceof BundleSpecification) {
063: if (!fShowOptional
064: && ((BundleSpecification) candidate)
065: .isOptional())
066: continue;
067: desc = (BundleDescription) ((BundleSpecification) candidate)
068: .getSupplier();
069: // include unresolved require-bundles
070: if (desc == null)
071: elements.put(
072: ((BundleSpecification) candidate)
073: .getName(), candidate);
074: } else if (candidate instanceof BundleDescription) {
075: desc = (BundleDescription) candidate;
076: } else if (candidate instanceof ImportPackageSpecification) {
077: if (!fShowOptional
078: && Constants.RESOLUTION_OPTIONAL
079: .equals(((ImportPackageSpecification) candidate)
080: .getDirective(Constants.RESOLUTION_DIRECTIVE)))
081: continue;
082: desc = ((ExportPackageDescription) (((ImportPackageSpecification) candidate)
083: .getSupplier())).getExporter();
084: }
085: if (desc == null)
086: continue;
087: IPluginModelBase callee = PluginRegistry
088: .findModel(desc.getSymbolicName());
089: if (!elements.containsKey(desc.getSymbolicName())) {
090: elements.put(desc.getSymbolicName(), candidate);
091: if (callee != null) {
092: newCandidates.addAll(Arrays
093: .asList(findCallees(desc)));
094: }
095: }
096: }
097: candidates = newCandidates;
098:
099: }
100: return elements.values().toArray();
101: }
102: return new Object[0];
103: }
104: }
|