KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > views > dependencies > CalleesListContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.views.dependencies;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Set JavaDoc;
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     /**
47      * @see IStructuredContentProvider#getElements(Object)
48      */

49     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
50         if (inputElement instanceof IPluginModelBase) {
51             Map JavaDoc elements = new HashMap JavaDoc();
52             Set JavaDoc candidates = new HashSet JavaDoc();
53             candidates.addAll(Arrays.asList(findCallees(((IPluginModelBase)inputElement))));
54             
55             while (!candidates.isEmpty()) {
56                 Set JavaDoc newCandidates = new HashSet JavaDoc();
57                 for (Iterator JavaDoc it = candidates.iterator(); it.hasNext();) {
58                     Object JavaDoc 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                         // include unresolved require-bundles
66
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 JavaDoc[0];
93     }
94 }
95
Popular Tags