KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.jface.viewers.ITreeContentProvider;
14 import org.eclipse.osgi.service.resolver.BundleDescription;
15 import org.eclipse.osgi.service.resolver.BundleSpecification;
16 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
17 import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
18 import org.eclipse.pde.core.plugin.IPluginBase;
19 import org.eclipse.pde.core.plugin.IPluginModelBase;
20
21 public class CalleesTreeContentProvider extends CalleesContentProvider
22         implements ITreeContentProvider {
23
24     /**
25      * Constructor.
26      */

27     public CalleesTreeContentProvider(DependenciesView view) {
28         super(view);
29     }
30
31     public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
32         if (parentElement instanceof IPluginBase) {
33             parentElement = ((IPluginBase)parentElement).getModel();
34         }
35         if (parentElement instanceof IPluginModelBase) {
36             return findCallees(((IPluginModelBase)parentElement));
37         }
38         if (parentElement instanceof BundleSpecification) {
39             parentElement = ((BundleSpecification)parentElement).getSupplier();
40         }
41         if (parentElement instanceof ImportPackageSpecification) {
42             parentElement = ((ExportPackageDescription)(((ImportPackageSpecification)parentElement).getSupplier())).getExporter();
43         }
44         if (parentElement instanceof BundleDescription) {
45             return findCallees((BundleDescription)parentElement);
46         }
47         return new Object JavaDoc[0];
48     }
49
50     /**
51      * @see IStructuredContentProvider#getElements(Object)
52      * @return Object[] of IPluginBase
53      */

54     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
55         if (inputElement instanceof IPluginModelBase) {
56             // need to use PluginBase. If we use BundleDescription, whenever the Manifest is update the tree refreshes and collapses
57
// If we use IPluginModelBase, it confuses the Tree since we return the same object as our input
58
return new Object JavaDoc[] { ((IPluginModelBase) inputElement).getPluginBase() };
59         }
60         return new Object JavaDoc[0];
61     }
62
63     /**
64      * @see ITreeContentProvider#getParent(Object)
65      */

66     public Object JavaDoc getParent(Object JavaDoc element) {
67         return null;
68     }
69
70     /**
71      * @see ITreeContentProvider#hasChildren(Object)
72      */

73     public boolean hasChildren(Object JavaDoc element) {
74         return getChildren(element).length > 0;
75     }
76
77 }
78
Popular Tags