1 11 package org.eclipse.pde.internal.ui.views.dependencies; 12 13 import org.eclipse.jface.viewers.StructuredViewer; 14 import org.eclipse.jface.viewers.Viewer; 15 import org.eclipse.osgi.service.resolver.BundleDescription; 16 import org.eclipse.pde.core.plugin.IPluginModelBase; 17 import org.eclipse.pde.core.plugin.ModelEntry; 18 import org.eclipse.pde.internal.core.IPluginModelListener; 19 import org.eclipse.pde.internal.core.PDECore; 20 import org.eclipse.pde.internal.core.PluginModelDelta; 21 import org.eclipse.pde.internal.core.PluginModelManager; 22 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 23 24 public class DependenciesViewPageContentProvider extends DefaultContentProvider 25 implements IPluginModelListener { 26 private PluginModelManager fPluginManager; 27 28 private DependenciesView fView; 29 30 private StructuredViewer fViewer; 31 32 35 public DependenciesViewPageContentProvider(DependenciesView view) { 36 this.fView = view; 37 fPluginManager = PDECore.getDefault().getModelManager(); 38 attachModelListener(); 39 } 40 41 public void attachModelListener() { 42 fPluginManager.addPluginModelListener(this); 43 } 44 45 public void removeModelListener() { 46 fPluginManager.removePluginModelListener(this); 47 } 48 49 public void dispose() { 50 removeModelListener(); 51 } 52 53 private void handleModifiedModels(ModelEntry[] modified) { 54 Object input = fViewer.getInput(); 55 if (input instanceof IPluginModelBase) { 56 BundleDescription desc = ((IPluginModelBase)input).getBundleDescription(); 57 String inputID = (desc != null) ? desc.getSymbolicName() : ((IPluginModelBase)input).getPluginBase().getId(); 58 59 for (int i = 0; i < modified.length; i++) { 60 ModelEntry entry = modified[i]; 61 if (entry.getId().equals(inputID)) { 62 if (modelExists(entry, (IPluginModelBase)input)) 64 fView.updateTitle(input); 65 else 66 fView.openTo(null); 68 return; 69 } 70 } 71 } 72 } 73 74 private boolean modelExists(ModelEntry entry, IPluginModelBase input) { 75 IPluginModelBase[][] entries = new IPluginModelBase[][] {entry.getExternalModels(), entry.getWorkspaceModels()}; 76 for (int i = 0; i < 2; i++) { 77 for (int j = 0; j < entries[i].length; j++) { 78 if (entries[i][j].equals(input)) 79 return true; 80 } 81 } 82 return false; 83 } 84 85 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 86 fView.updateTitle(newInput); 87 this.fViewer = (StructuredViewer) viewer; 88 } 89 90 public void modelsChanged(final PluginModelDelta delta) { 91 if (fViewer == null || fViewer.getControl().isDisposed()) 92 return; 93 94 fViewer.getControl().getDisplay().asyncExec(new Runnable () { 95 public void run() { 96 int kind = delta.getKind(); 97 if (fViewer.getControl().isDisposed()) 98 return; 99 try { 100 if ((kind & PluginModelDelta.REMOVED) != 0) { 101 handleModifiedModels(delta.getRemovedEntries()); 103 } 104 if ((kind & PluginModelDelta.CHANGED) != 0) { 105 handleModifiedModels(delta.getChangedEntries()); 108 } 109 if ((kind & PluginModelDelta.ADDED) != 0) { 110 handleModifiedModels(delta.getAddedEntries()); 113 } 114 } finally { 115 fViewer.refresh(); 117 } 118 } 119 }); 120 } 121 122 125 protected PluginModelManager getPluginManager() { 126 return fPluginManager; 127 } 128 } 129 | Popular Tags |