01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.views.dependencies;
11:
12: import org.eclipse.jface.viewers.ITreeContentProvider;
13: import org.eclipse.osgi.service.resolver.BundleDescription;
14: import org.eclipse.osgi.service.resolver.BundleSpecification;
15: import org.eclipse.osgi.service.resolver.ExportPackageDescription;
16: import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
17: import org.eclipse.pde.core.plugin.IPluginBase;
18: import org.eclipse.pde.core.plugin.IPluginModelBase;
19:
20: public class CalleesTreeContentProvider extends CalleesContentProvider
21: implements ITreeContentProvider {
22:
23: /**
24: * Constructor.
25: */
26: public CalleesTreeContentProvider(DependenciesView view) {
27: super (view);
28: }
29:
30: public Object[] getChildren(Object parentElement) {
31: if (parentElement instanceof IPluginBase) {
32: parentElement = ((IPluginBase) parentElement).getModel();
33: }
34: if (parentElement instanceof IPluginModelBase) {
35: return findCallees(((IPluginModelBase) parentElement));
36: }
37: if (parentElement instanceof BundleSpecification) {
38: parentElement = ((BundleSpecification) parentElement)
39: .getSupplier();
40: }
41: if (parentElement instanceof ImportPackageSpecification) {
42: parentElement = ((ExportPackageDescription) (((ImportPackageSpecification) parentElement)
43: .getSupplier())).getExporter();
44: }
45: if (parentElement instanceof BundleDescription) {
46: return findCallees((BundleDescription) parentElement);
47: }
48: return new Object[0];
49: }
50:
51: /**
52: * @see IStructuredContentProvider#getElements(Object)
53: * @return Object[] of IPluginBase
54: */
55: public Object[] getElements(Object inputElement) {
56: if (inputElement instanceof IPluginModelBase) {
57: // need to use PluginBase. If we use BundleDescription, whenever the Manifest is update the tree refreshes and collapses
58: // If we use IPluginModelBase, it confuses the Tree since we return the same object as our input
59: return new Object[] { ((IPluginModelBase) inputElement)
60: .getPluginBase() };
61: }
62: return new Object[0];
63: }
64:
65: /**
66: * @see ITreeContentProvider#getParent(Object)
67: */
68: public Object getParent(Object element) {
69: return null;
70: }
71:
72: /**
73: * @see ITreeContentProvider#hasChildren(Object)
74: */
75: public boolean hasChildren(Object element) {
76: return getChildren(element).length > 0;
77: }
78:
79: }
|