001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.views.plugins;
011:
012: import java.io.File;
013:
014: import org.eclipse.core.resources.IStorage;
015: import org.eclipse.jdt.core.ICompilationUnit;
016: import org.eclipse.jdt.core.IJarEntryResource;
017: import org.eclipse.jdt.core.IPackageFragment;
018: import org.eclipse.jdt.core.IPackageFragmentRoot;
019: import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
020: import org.eclipse.jface.viewers.IStructuredContentProvider;
021: import org.eclipse.jface.viewers.ITreeContentProvider;
022: import org.eclipse.jface.viewers.Viewer;
023: import org.eclipse.pde.core.plugin.IPluginModelBase;
024: import org.eclipse.pde.internal.core.FileAdapter;
025: import org.eclipse.pde.internal.core.ModelFileAdapter;
026: import org.eclipse.pde.internal.core.PDECore;
027: import org.eclipse.pde.internal.core.PluginModelManager;
028: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
029:
030: public class PluginsContentProvider extends DefaultContentProvider
031: implements ITreeContentProvider, IStructuredContentProvider {
032:
033: private PluginsView fView;
034: private StandardJavaElementContentProvider fJavaProvider;
035:
036: /**
037: * Constructor for PluginsContentProvider.
038: */
039: public PluginsContentProvider(PluginsView view) {
040: fView = view;
041: fJavaProvider = new StandardJavaElementContentProvider();
042: }
043:
044: public void inputChanged(Viewer viewer, Object oldInput,
045: Object newInput) {
046: if (newInput == null)
047: return;
048: fView.updateTitle(newInput);
049: }
050:
051: /*
052: * (non-Javadoc)
053: * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
054: */
055: public Object[] getChildren(Object parentElement) {
056: if (parentElement instanceof PluginModelManager) {
057: return ((PluginModelManager) parentElement).getAllModels();
058: }
059: if (parentElement instanceof IPluginModelBase) {
060: IPluginModelBase model = (IPluginModelBase) parentElement;
061: if (model != null) {
062: File file = new File(model.getInstallLocation());
063: if (!file.isFile()) {
064: FileAdapter adapter = new ModelFileAdapter(model,
065: file, PDECore.getDefault()
066: .getSearchablePluginsManager());
067: return adapter.getChildren();
068: }
069: }
070: }
071:
072: if (parentElement instanceof FileAdapter) {
073: return ((FileAdapter) parentElement).getChildren();
074: }
075:
076: if (parentElement instanceof IPackageFragmentRoot
077: || parentElement instanceof IPackageFragment
078: || parentElement instanceof ICompilationUnit
079: || parentElement instanceof IStorage)
080: return fJavaProvider.getChildren(parentElement);
081:
082: return new Object[0];
083: }
084:
085: /*
086: * (non-Javadoc)
087: * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
088: */
089: public Object getParent(Object element) {
090: if (element instanceof PluginModelManager) {
091: return null;
092: }
093: if (element instanceof IPluginModelBase) {
094: return PDECore.getDefault().getModelManager();
095: }
096: if (element instanceof ModelFileAdapter) {
097: return ((ModelFileAdapter) element).getModel();
098: }
099: if (element instanceof FileAdapter) {
100: return ((FileAdapter) element).getParent();
101: }
102: if (element instanceof IJarEntryResource) {
103: return ((IJarEntryResource) element).getParent();
104: }
105: return null;
106: }
107:
108: /*
109: * (non-Javadoc)
110: * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
111: */
112: public boolean hasChildren(Object element) {
113: if (element instanceof PluginModelManager) {
114: return !((PluginModelManager) element).isEmpty();
115: }
116: if (element instanceof IPluginModelBase) {
117: IPluginModelBase model = (IPluginModelBase) element;
118: return model.getUnderlyingResource() == null
119: && !new File(model.getInstallLocation()).isFile();
120: }
121: if (element instanceof FileAdapter) {
122: FileAdapter fileAdapter = (FileAdapter) element;
123: return fileAdapter.hasChildren();
124: }
125: if (element instanceof IPackageFragmentRoot
126: || element instanceof IPackageFragment
127: || element instanceof ICompilationUnit
128: || element instanceof IStorage)
129: return fJavaProvider.hasChildren(element);
130: return false;
131: }
132:
133: /**
134: * @see IStructuredContentProvider#getElements(Object)
135: */
136: public Object[] getElements(Object inputElement) {
137: return getChildren(inputElement);
138: }
139:
140: }
|