1 11 package org.eclipse.pde.internal.ui.view; 12 13 import org.eclipse.jface.viewers.StructuredViewer; 14 import org.eclipse.jface.viewers.Viewer; 15 import org.eclipse.pde.core.plugin.IPluginModelBase; 16 import org.eclipse.pde.internal.core.IPluginModelListener; 17 import org.eclipse.pde.internal.core.ModelEntry; 18 import org.eclipse.pde.internal.core.PDECore; 19 import org.eclipse.pde.internal.core.PluginModelDelta; 20 import org.eclipse.pde.internal.core.PluginModelManager; 21 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 22 23 public class DependenciesViewPageContentProvider extends DefaultContentProvider 24 implements IPluginModelListener { 25 private PluginModelManager fPluginManager; 26 27 private DependenciesView fView; 28 29 private StructuredViewer fViewer; 30 31 34 public DependenciesViewPageContentProvider(DependenciesView view) { 35 this.fView = view; 36 fPluginManager = PDECore.getDefault().getModelManager(); 37 fPluginManager.addPluginModelListener(this); 38 } 39 40 public void dispose() { 41 fPluginManager.removePluginModelListener(this); 42 } 43 44 private void handleRemoved(ModelEntry[] removed) { 45 for (int i = 0; i < removed.length; i++) { 46 ModelEntry entry = removed[i]; 47 IPluginModelBase model = entry.getActiveModel(); 48 if (model != null && model.equals(fViewer.getInput())) { 49 fViewer.setInput(null); 50 return; 51 } 52 } 53 fViewer.refresh(); 54 } 55 56 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 57 fView.updateTitle(newInput); 58 this.fViewer = (StructuredViewer) viewer; 59 } 60 61 public void modelsChanged(final PluginModelDelta delta) { 62 if (fViewer == null || fViewer.getControl().isDisposed()) 63 return; 64 65 fViewer.getControl().getDisplay().asyncExec(new Runnable () { 66 public void run() { 67 int kind = delta.getKind(); 68 if (fViewer.getControl().isDisposed()) 69 return; 70 if ((kind & PluginModelDelta.CHANGED) != 0 71 || (kind & PluginModelDelta.ADDED) != 0) { 72 fViewer.refresh(); 75 fView.updateTitle(fView.getInput()); 76 return; 77 } 78 if ((kind & PluginModelDelta.REMOVED) != 0) { 79 ModelEntry[] removed = delta.getRemovedEntries(); 80 handleRemoved(removed); 81 } 82 if ((kind & PluginModelDelta.ADDED) != 0) { 83 fViewer.refresh(); 84 } 85 } 86 }); 87 } 88 89 92 protected PluginModelManager getPluginManager() { 93 return fPluginManager; 94 } 95 } 96 | Popular Tags |