KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > view > CalleesListContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.view;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Hashtable 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.pde.core.plugin.IPlugin;
22 import org.eclipse.pde.core.plugin.IPluginBase;
23 import org.eclipse.pde.core.plugin.IPluginImport;
24 import org.eclipse.pde.core.plugin.IPluginModelBase;
25 import org.eclipse.pde.internal.core.PDECore;
26
27 public class CalleesListContentProvider extends CalleesContentProvider
28         implements IStructuredContentProvider {
29
30     public CalleesListContentProvider(DependenciesView view) {
31         super(view);
32     }
33
34     /**
35      * @see IStructuredContentProvider#getElements(Object)
36      */

37     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
38         // input either IPluginModelBase or ImportObject
39
if (inputElement instanceof IPluginModelBase) {
40             IPluginBase pluginBase = ((IPluginModelBase) inputElement)
41                     .getPluginBase();
42             Map JavaDoc elements = new Hashtable JavaDoc();
43             Set JavaDoc candidates = new HashSet JavaDoc();
44             candidates.addAll(Arrays.asList(findCallees(pluginBase)));
45
46             while (!candidates.isEmpty()) {
47                 Set JavaDoc newCandidates = new HashSet JavaDoc();
48                 for (Iterator JavaDoc it = candidates.iterator(); it.hasNext();) {
49                     Object JavaDoc candidate = it.next();
50                     String JavaDoc id;
51                     if(candidate instanceof IPluginImport){
52                         id = ((IPluginImport)candidate).getId();
53                     }else /*if (candidate instanceof IPluginBase)*/{
54                         id = ((IPluginBase)candidate).getId();
55                     }
56                     IPlugin callee = PDECore.getDefault()
57                             .findPlugin(id);
58                     it.remove();
59                     if (!elements.containsKey(id)) {
60                         elements.put(id, candidate);
61                         if (callee != null) {
62                             newCandidates.addAll(Arrays
63                                     .asList(findCallees(callee)));
64                         }
65                     }
66                 }
67                 candidates = newCandidates;
68
69             }
70             return elements.values().toArray();
71         }
72         return new Object JavaDoc[0];
73     }
74 }
75
Popular Tags