KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashSet JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.jface.viewers.IStructuredContentProvider;
18 import org.eclipse.osgi.service.resolver.BundleDescription;
19 import org.eclipse.pde.core.plugin.IPluginModelBase;
20
21 public class CallersListContentProvider extends CallersContentProvider
22         implements IStructuredContentProvider {
23
24     public CallersListContentProvider(DependenciesView view) {
25         super(view);
26     }
27
28     /**
29      * @see IStructuredContentProvider#getElements(Object)
30      */

31     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
32         // input IPluginModelBase
33
BundleDescription desc = null;
34         if (inputElement instanceof IPluginModelBase) {
35             desc = ((IPluginModelBase) inputElement)
36                     .getBundleDescription();
37         } else if (inputElement instanceof BundleDescription) {
38             desc = (BundleDescription)inputElement;
39         }
40         if (desc != null) {
41             Set JavaDoc callers = new HashSet JavaDoc();
42             Set JavaDoc candidates = new HashSet JavaDoc();
43             candidates.addAll(findReferences(desc));
44             while (!candidates.isEmpty()) {
45                 Set JavaDoc newCandidates = new HashSet JavaDoc();
46                 for (Iterator JavaDoc it = candidates.iterator(); it.hasNext();) {
47                     Object JavaDoc o = it.next();
48                     it.remove();
49                     BundleDescription caller = (BundleDescription) o;
50                     if (!callers.contains(caller)) {
51                         callers.add(caller);
52                         newCandidates.addAll(findReferences(caller));
53                     }
54                 }
55                 candidates = newCandidates;
56
57             }
58
59             return callers.toArray();
60         }
61         return new Object JavaDoc[0];
62     }
63 }
64
Popular Tags