KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > view > DependenciesViewPageContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /**
32      * Constructor.
33      */

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 JavaDoc oldInput, Object JavaDoc 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 JavaDoc() {
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                     // Don't know exactly what change -
73
// the safest way out is to refresh
74
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     /**
90      * @return Returns the fPluginManager.
91      */

92     protected PluginModelManager getPluginManager() {
93         return fPluginManager;
94     }
95 }
96
Popular Tags