1 11 package org.eclipse.pde.internal.ui.views.plugins; 12 13 import java.io.File ; 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 40 public PluginsContentProvider(PluginsView view) { 41 fView = view; 42 fJavaProvider = new StandardJavaElementContentProvider(); 43 } 44 45 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 46 if (newInput == null) return; 47 fView.updateTitle(newInput); 48 } 49 50 54 public Object [] getChildren(Object 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 file = new File (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 [0]; 84 } 85 86 90 public Object getParent(Object 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 113 public boolean hasChildren(Object 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 (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 137 public Object [] getElements(Object inputElement) { 138 return getChildren(inputElement); 139 } 140 141 } 142 | Popular Tags |