1 11 package org.eclipse.pde.internal.ui.view; 12 13 import org.eclipse.jface.viewers.*; 14 import org.eclipse.pde.core.plugin.*; 15 import org.eclipse.pde.internal.core.*; 16 import org.eclipse.pde.internal.core.plugin.ImportObject; 17 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 18 19 public class DependenciesContentProvider 20 extends DefaultContentProvider 21 implements ITreeContentProvider, IStructuredContentProvider, IPluginModelListener { 22 private PluginModelManager manager; 23 private TreeViewer viewer; 24 private DependenciesView view; 25 26 29 public DependenciesContentProvider(DependenciesView view, PluginModelManager manager) { 30 this.manager = manager; 31 manager.addPluginModelListener(this); 32 this.view = view; 33 } 34 35 public void dispose() { 36 manager.removePluginModelListener(this); 37 } 38 39 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 40 this.viewer = (TreeViewer) viewer; 41 if (newInput==null) return; 42 view.updateTitle(newInput); 43 } 44 45 48 public Object [] getChildren(Object parentElement) { 49 if (parentElement instanceof IPluginModelBase) { 50 return new Object [] {((IPluginModelBase)parentElement).getPluginBase()}; 51 } 52 if (parentElement instanceof IPluginBase) { 53 return createImportObjects((IPluginBase)parentElement); 54 } 55 if (parentElement instanceof ImportObject) { 56 ImportObject iobj = (ImportObject)parentElement; 57 IPlugin plugin = iobj.getPlugin(); 58 if (plugin==null) return new Object [0]; 59 return createImportObjects(plugin); 60 } 61 return new Object [0]; 62 } 63 64 private Object [] createImportObjects(IPluginBase plugin) { 65 IPluginImport [] imports = plugin.getImports(); 66 Object [] result = new Object [imports.length]; 67 for (int i=0; i<imports.length; i++) { 68 result[i] = new ImportObject(imports[i]); 69 } 70 return result; 71 } 72 73 76 public Object getParent(Object element) { 77 return null; 78 } 79 80 83 public boolean hasChildren(Object element) { 84 return getChildren(element).length>0; 85 } 86 87 90 public Object [] getElements(Object inputElement) { 91 return getChildren(inputElement); 92 } 93 94 public void modelsChanged(final PluginModelDelta delta) { 95 if (viewer == null || viewer.getTree().isDisposed()) 96 return; 97 98 viewer.getTree().getDisplay().asyncExec(new Runnable () { 99 public void run() { 100 int kind = delta.getKind(); 101 if (viewer.getTree().isDisposed()) 102 return; 103 if ((kind & PluginModelDelta.CHANGED) !=0 || 104 (kind & PluginModelDelta.ADDED) !=0) { 105 viewer.refresh(); 108 return; 109 } 110 if ((kind & PluginModelDelta.REMOVED) != 0) { 111 ModelEntry[] removed = delta.getRemovedEntries(); 112 handleRemoved(removed); 113 } 114 if ((kind & PluginModelDelta.ADDED) != 0) { 115 viewer.refresh(); 116 } 117 } 118 }); 119 } 120 private void handleRemoved(ModelEntry [] removed) { 121 for (int i=0; i<removed.length; i++) { 122 ModelEntry entry = removed[i]; 123 IPluginModelBase model = entry.getActiveModel(); 124 if (model!=null && model.equals(viewer.getInput())) { 125 viewer.setInput(null); 126 return; 127 } 128 } 129 viewer.refresh(); 130 } 131 } | Popular Tags |