KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > views > plugins > PluginsContentProvider


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.plugins;
12
13 import java.io.File JavaDoc;
14
15 import org.eclipse.core.resources.IStorage;
16 import org.eclipse.jdt.core.ICompilationUnit;
17 import org.eclipse.jdt.core.IJarEntryResource;
18 import org.eclipse.jdt.core.IPackageFragment;
19 import org.eclipse.jdt.core.IPackageFragmentRoot;
20 import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
21 import org.eclipse.jface.viewers.IStructuredContentProvider;
22 import org.eclipse.jface.viewers.ITreeContentProvider;
23 import org.eclipse.jface.viewers.Viewer;
24 import org.eclipse.pde.core.plugin.IPluginModelBase;
25 import org.eclipse.pde.internal.core.FileAdapter;
26 import org.eclipse.pde.internal.core.ModelFileAdapter;
27 import org.eclipse.pde.internal.core.PDECore;
28 import org.eclipse.pde.internal.core.PluginModelManager;
29 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
30
31 public class PluginsContentProvider extends DefaultContentProvider
32                 implements ITreeContentProvider, IStructuredContentProvider {
33     
34     private PluginsView fView;
35     private StandardJavaElementContentProvider fJavaProvider;
36
37     /**
38      * Constructor for PluginsContentProvider.
39      */

40     public PluginsContentProvider(PluginsView view) {
41         fView = view;
42         fJavaProvider = new StandardJavaElementContentProvider();
43     }
44
45     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
46         if (newInput == null) return;
47         fView.updateTitle(newInput);
48     }
49
50     /*
51      * (non-Javadoc)
52      * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
53      */

54     public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
55         if (parentElement instanceof PluginModelManager) {
56             return ((PluginModelManager) parentElement).getAllModels();
57         }
58         if (parentElement instanceof IPluginModelBase) {
59             IPluginModelBase model = (IPluginModelBase)parentElement;
60             if (model != null) {
61                 File JavaDoc file = new File JavaDoc(model.getInstallLocation());
62                 if (!file.isFile()) {
63                     FileAdapter adapter =
64                         new ModelFileAdapter(
65                             model,
66                             file,
67                             PDECore.getDefault().getSearchablePluginsManager());
68                     return adapter.getChildren();
69                 }
70             }
71         }
72             
73         if (parentElement instanceof FileAdapter) {
74             return ((FileAdapter) parentElement).getChildren();
75         }
76         
77         if (parentElement instanceof IPackageFragmentRoot ||
78             parentElement instanceof IPackageFragment ||
79             parentElement instanceof ICompilationUnit ||
80             parentElement instanceof IStorage)
81             return fJavaProvider.getChildren(parentElement);
82         
83         return new Object JavaDoc[0];
84     }
85
86     /*
87      * (non-Javadoc)
88      * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
89      */

90     public Object JavaDoc getParent(Object JavaDoc element) {
91         if (element instanceof PluginModelManager) {
92             return null;
93         }
94         if (element instanceof IPluginModelBase) {
95             return PDECore.getDefault().getModelManager();
96         }
97         if (element instanceof ModelFileAdapter) {
98             return ((ModelFileAdapter) element).getModel();
99         }
100         if (element instanceof FileAdapter) {
101             return ((FileAdapter) element).getParent();
102         }
103         if (element instanceof IJarEntryResource) {
104             return ((IJarEntryResource) element).getParent();
105         }
106         return null;
107     }
108
109     /*
110      * (non-Javadoc)
111      * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
112      */

113     public boolean hasChildren(Object JavaDoc element) {
114         if (element instanceof PluginModelManager) {
115             return !((PluginModelManager) element).isEmpty();
116         }
117         if (element instanceof IPluginModelBase) {
118             IPluginModelBase model = (IPluginModelBase)element;
119             return model.getUnderlyingResource() == null
120                     && !new File JavaDoc(model.getInstallLocation()).isFile();
121         }
122         if (element instanceof FileAdapter) {
123             FileAdapter fileAdapter = (FileAdapter) element;
124             return fileAdapter.hasChildren();
125         }
126         if (element instanceof IPackageFragmentRoot ||
127             element instanceof IPackageFragment ||
128             element instanceof ICompilationUnit ||
129             element instanceof IStorage)
130             return fJavaProvider.hasChildren(element);
131         return false;
132     }
133
134     /**
135      * @see IStructuredContentProvider#getElements(Object)
136      */

137     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
138         return getChildren(inputElement);
139     }
140
141 }
142
Popular Tags