Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 243441 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/runtime/registry/ConfigurationAttributeAdapter.java (-23 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.runtime.registry;
12
13
public class ConfigurationAttributeAdapter extends ParentAdapter {
14
15
	public ConfigurationAttributeAdapter(Object object) {
16
		super(object);
17
	}
18
19
	protected Object[] createChildren() {
20
		return null;
21
	}
22
23
}
(-)src/org/eclipse/pde/internal/runtime/registry/PluginAdapter.java (-39 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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.runtime.registry;
12
13
import org.eclipse.pde.internal.runtime.registry.RegistryBrowserContentProvider.BundleFolder;
14
import org.osgi.framework.Bundle;
15
16
/**
17
 * Adapter for bundle objects.
18
 *
19
 */
20
public class PluginAdapter extends ParentAdapter {
21
22
	public PluginAdapter(Bundle object) {
23
		super(object);
24
	}
25
26
	protected Object[] createChildren() {
27
		Bundle bundle = (Bundle) getObject();
28
29
		Object[] array = new Object[7];
30
		array[0] = new BundleFolder(bundle, IBundleFolder.F_LOCATION);
31
		array[1] = new BundleFolder(bundle, IBundleFolder.F_IMPORTS);
32
		array[2] = new BundleFolder(bundle, IBundleFolder.F_LIBRARIES);
33
		array[3] = new BundleFolder(bundle, IBundleFolder.F_EXTENSION_POINTS);
34
		array[4] = new BundleFolder(bundle, IBundleFolder.F_EXTENSIONS);
35
		array[5] = new BundleFolder(bundle, IBundleFolder.F_REGISTERED_SERVICES);
36
		array[6] = new BundleFolder(bundle, IBundleFolder.F_SERVICES_IN_USE);
37
		return array;
38
	}
39
}
(-)src/org/eclipse/pde/internal/runtime/registry/IConfigurationAttribute.java (-15 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.runtime.registry;
12
13
public interface IConfigurationAttribute {
14
	public String getLabel();
15
}
(-)src/org/eclipse/pde/internal/runtime/registry/RegistryBrowserContentProvider.java (-210 / +45 lines)
Lines 10-115 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.runtime.registry;
11
package org.eclipse.pde.internal.runtime.registry;
12
12
13
import java.util.*;
13
import java.util.ArrayList;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.jface.viewers.ITreeContentProvider;
14
import org.eclipse.jface.viewers.ITreeContentProvider;
16
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.osgi.util.ManifestElement;
16
import org.eclipse.pde.internal.runtime.registry.model.*;
18
import org.eclipse.pde.internal.runtime.PDERuntimePlugin;
19
import org.osgi.framework.*;
20
17
21
public class RegistryBrowserContentProvider implements ITreeContentProvider {
18
public class RegistryBrowserContentProvider implements ITreeContentProvider {
22
	private Hashtable fExtensionPointMap = new Hashtable();
23
	public boolean isInExtensionSet;
19
	public boolean isInExtensionSet;
20
	private RegistryBrowser fRegistryBrowser;
24
21
25
	static class BundleFolder implements IBundleFolder {
22
	public RegistryBrowserContentProvider(RegistryBrowser registryBrowser) {
26
		private int id;
23
		fRegistryBrowser = registryBrowser;
27
		private Bundle bundle;
28
		private Object[] children;
29
30
		public BundleFolder(Bundle pd, int id) {
31
			this.bundle = pd;
32
			this.id = id;
33
		}
34
35
		public Bundle getBundle() {
36
			return bundle;
37
		}
38
39
		public Object[] getChildren() {
40
			if (children == null) {
41
				children = getFolderChildren(bundle, id);
42
			}
43
			return children;
44
		}
45
46
		/**
47
		 * Resets folder's previously cached knowledge about it's children. 
48
		 */
49
		public void refresh() {
50
			children = null;
51
		}
52
53
		public int getFolderId() {
54
			return id;
55
		}
56
57
		public Object getAdapter(Class key) {
58
			return null;
59
		}
60
	}
61
62
	static class BundlePrerequisite implements IBundlePrerequisite {
63
		private ManifestElement underlyingElement;
64
65
		public BundlePrerequisite(ManifestElement element) {
66
			underlyingElement = element;
67
		}
68
69
		public ManifestElement getPrerequisite() {
70
			return underlyingElement;
71
		}
72
73
		public boolean isExported() {
74
			String visibility = underlyingElement.getDirective(Constants.VISIBILITY_DIRECTIVE);
75
			return Constants.VISIBILITY_REEXPORT.equals(visibility);
76
		}
77
78
		public String getLabel() {
79
			String version = underlyingElement.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
80
			String value = underlyingElement.getValue();
81
			if (version == null)
82
				return value;
83
			if (Character.isDigit(version.charAt(0)))
84
				version = '(' + version + ')';
85
			return value + ' ' + version;
86
		}
87
	}
88
89
	static class BundleLibrary implements IBundleLibrary {
90
		private ManifestElement underlyingElement;
91
92
		public BundleLibrary(ManifestElement element) {
93
			underlyingElement = element;
94
		}
95
96
		public String getLibrary() {
97
			return underlyingElement.getValue();
98
		}
99
	}
100
101
	/**
102
	 * Creates contents adapter for given folder id.
103
	 * @param object Folder contents to be wrapped in adapter
104
	 * @param id Type of folder
105
	 * @return Adapter 
106
	 */
107
	static protected PluginObjectAdapter createAdapter(Object object, int id) {
108
		if (id == IBundleFolder.F_EXTENSIONS)
109
			return new ExtensionAdapter(object);
110
		if (id == IBundleFolder.F_EXTENSION_POINTS)
111
			return new ExtensionPointAdapter(object);
112
		return new PluginObjectAdapter(object);
113
	}
24
	}
114
25
115
	public void dispose() { // nothing to dispose
26
	public void dispose() { // nothing to dispose
Lines 123-250 Link Here
123
		if (element == null)
34
		if (element == null)
124
			return null;
35
			return null;
125
36
126
		if (element instanceof ExtensionAdapter)
37
		if (element instanceof Extension)
127
			return ((ExtensionAdapter) element).getChildren();
38
			return ((Extension) element).getConfigurationElements();
128
39
129
		isInExtensionSet = false;
40
		isInExtensionSet = false;
130
		if (element instanceof ExtensionPointAdapter)
41
		if (element instanceof ExtensionPoint)
131
			return ((ExtensionPointAdapter) element).getChildren();
42
			return ((ExtensionPoint) element).getExtensions().toArray();
132
43
133
		if (element instanceof ConfigurationElementAdapter)
44
		if (element instanceof ConfigurationElement)
134
			return ((ConfigurationElementAdapter) element).getChildren();
45
			return ((ConfigurationElement) element).getElements();
135
46
136
		if (element instanceof PluginAdapter) {
47
		if (element instanceof Bundle) {
137
			PluginAdapter bundle = (PluginAdapter) element;
48
			Bundle bundle = (Bundle) element;
138
49
139
			Object[] folders = bundle.getChildren();
50
			Folder[] folders = new Folder[6];
51
			folders[0] = new Folder(Folder.F_IMPORTS, bundle);
52
			folders[1] = new Folder(Folder.F_LIBRARIES, bundle);
53
			folders[2] = new Folder(Folder.F_EXTENSION_POINTS, bundle);
54
			folders[3] = new Folder(Folder.F_EXTENSIONS, bundle);
55
			folders[4] = new Folder(Folder.F_REGISTERED_SERVICES, bundle);
56
			folders[5] = new Folder(Folder.F_SERVICES_IN_USE, bundle);
140
57
141
			// filter out empty folders
58
			// filter out empty folders
142
			ArrayList folderList = new ArrayList();
59
			ArrayList folderList = new ArrayList();
60
			folderList.add(new Attribute(bundle.getModel(), Attribute.F_LOCATION, bundle.getLocation()));
61
143
			for (int i = 0; i < folders.length; i++) {
62
			for (int i = 0; i < folders.length; i++) {
144
				if (folders[i] != null && ((IBundleFolder) folders[i]).getChildren() != null || ((IBundleFolder) folders[i]).getFolderId() == IBundleFolder.F_LOCATION)
63
				if ((folders[i].getChildren() != null) && (folders[i].getChildren().length > 0))
145
					folderList.add(folders[i]);
64
					folderList.add(folders[i]);
146
			}
65
			}
147
			folders = folderList.toArray(new Object[folderList.size()]);
66
			return folderList.toArray();
148
149
			return folders;
150
		}
67
		}
151
68
152
		if (element instanceof PluginObjectAdapter)
69
		if (element instanceof Folder) {
153
			element = ((PluginObjectAdapter) element).getObject();
70
			Folder folder = (Folder) element;
154
71
			isInExtensionSet = folder.getId() == Folder.F_EXTENSIONS;
155
		if (element instanceof IBundleFolder) {
72
			Object[] objs = ((Folder) element).getChildren();
156
			IBundleFolder folder = (IBundleFolder) element;
73
			return objs;
157
			isInExtensionSet = folder.getFolderId() == IBundleFolder.F_EXTENSIONS;
74
		}
158
			return ((IBundleFolder) element).getChildren();
75
		if (element instanceof ConfigurationElement) {
76
			return ((ConfigurationElement) element).getElements();
159
		}
77
		}
160
		if (element instanceof IConfigurationElement) {
78
161
			return ((IConfigurationElement) element).getChildren();
79
		if (element instanceof ExtensionPoint) {
80
			ExtensionPoint extensionPoint = (ExtensionPoint) element;
81
			Object[] objs = extensionPoint.getExtensions().toArray();
82
			return objs;
162
		}
83
		}
84
163
		if (element instanceof Object[]) {
85
		if (element instanceof Object[]) {
164
			return (Object[]) element;
86
			return (Object[]) element;
165
		}
87
		}
166
		if (element instanceof IExtensionPoint) {
167
			IExtensionPoint extensionPoint = (IExtensionPoint) element;
168
			String id = extensionPoint.getUniqueIdentifier();
169
170
			Object[] children = (Object[]) fExtensionPointMap.get(id);
171
			if (children == null) {
172
				Object[] array = extensionPoint.getExtensions();
173
				if (array != null && array.length > 0) {
174
					children = new Object[array.length];
175
					for (int i = 0; i < array.length; i++) {
176
						children[i] = createAdapter(array[i], IBundleFolder.F_EXTENSIONS);
177
					}
178
88
179
					fExtensionPointMap.put(id, children);
180
				}
181
			}
182
183
			return children;
184
		}
185
		return null;
89
		return null;
186
	}
90
	}
187
91
188
	protected static Object[] getFolderChildren(Bundle bundle, int id) {
92
	public Object getParent(Object element) {
189
		Object[] array = null;
93
		if (!(element instanceof ModelObject)) {
190
		String bundleId = bundle.getSymbolicName();
94
			return null;
191
		switch (id) {
192
			case IBundleFolder.F_EXTENSIONS :
193
				array = Platform.getExtensionRegistry().getExtensions(bundleId);
194
				break;
195
			case IBundleFolder.F_EXTENSION_POINTS :
196
				array = Platform.getExtensionRegistry().getExtensionPoints(bundleId);
197
				break;
198
			case IBundleFolder.F_IMPORTS :
199
				array = getManifestHeaderArray(bundle, Constants.REQUIRE_BUNDLE);
200
				break;
201
			case IBundleFolder.F_LIBRARIES :
202
				array = getManifestHeaderArray(bundle, Constants.BUNDLE_CLASSPATH);
203
				break;
204
			case IBundleFolder.F_REGISTERED_SERVICES :
205
				return getServices(bundle, IBundleFolder.F_REGISTERED_SERVICES);
206
			case IBundleFolder.F_SERVICES_IN_USE :
207
				return getServices(bundle, IBundleFolder.F_SERVICES_IN_USE);
208
		}
209
		Object[] result = null;
210
		if (array != null && array.length > 0) {
211
			result = new Object[array.length];
212
			for (int i = 0; i < array.length; i++) {
213
				result[i] = createAdapter(array[i], id);
214
			}
215
		}
95
		}
216
		return result;
217
	}
218
219
	protected static Object[] getServices(Bundle bundle, int type) {
220
		Set result = new HashSet();
221
96
222
		try {
97
		ModelObject object = (ModelObject) element;
223
			ServiceReference[] references = PDERuntimePlugin.getDefault().getBundleContext().getAllServiceReferences(null, null);
224
98
225
			for (int i = 0; i < references.length; i++) {
99
		boolean extOnly = fRegistryBrowser.showExtensionsOnly();
226
				ServiceReference ref = references[i];
227
228
				if ((type == IBundleFolder.F_REGISTERED_SERVICES) && (bundle.equals(ref.getBundle()))) {
229
					result.add(new ServiceReferenceAdapter(ref));
230
				}
231
232
				Bundle[] usingBundles = ref.getUsingBundles();
233
				if ((type == IBundleFolder.F_SERVICES_IN_USE) && (usingBundles != null && Arrays.asList(usingBundles).contains(bundle))) {
234
					result.add(new ServiceReferenceAdapter(ref));
235
				}
236
			}
237
100
238
		} catch (InvalidSyntaxException e) { // nothing
101
		if (element instanceof Folder) {
102
			return ((Folder) element).getParent();
239
		}
103
		}
240
104
241
		if (result.size() == 0)
242
			return null;
243
244
		return result.toArray(new ServiceReferenceAdapter[result.size()]);
245
	}
246
247
	public Object getParent(Object element) {
248
		return null;
105
		return null;
249
	}
106
	}
250
107
Lines 256-281 Link Here
256
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // do nothing
113
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // do nothing
257
	}
114
	}
258
115
259
	static private Object[] getManifestHeaderArray(Bundle bundle, String headerKey) {
260
		String libraries = (String) bundle.getHeaders().get(headerKey);
261
		try {
262
			ManifestElement[] elements = ManifestElement.parseHeader(headerKey, libraries);
263
			if (elements == null)
264
				return null;
265
			if (headerKey.equals(Constants.BUNDLE_CLASSPATH)) {
266
				IBundleLibrary[] array = new IBundleLibrary[elements.length];
267
				for (int i = 0; i < elements.length; i++)
268
					array[i] = new BundleLibrary(elements[i]);
269
				return array;
270
			} else if (headerKey.equals(Constants.REQUIRE_BUNDLE)) {
271
				IBundlePrerequisite[] array = new IBundlePrerequisite[elements.length];
272
				for (int i = 0; i < elements.length; i++)
273
					array[i] = new BundlePrerequisite(elements[i]);
274
				return array;
275
			}
276
		} catch (BundleException e) { // do nothing
277
		}
278
		return null;
279
	}
280
281
}
116
}
(-)src/org/eclipse/pde/internal/runtime/registry/IBundlePrerequisite.java (-21 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.runtime.registry;
12
13
import org.eclipse.osgi.util.ManifestElement;
14
15
public interface IBundlePrerequisite {
16
	public ManifestElement getPrerequisite();
17
18
	public boolean isExported();
19
20
	public String getLabel();
21
}
(-)src/org/eclipse/pde/internal/runtime/registry/ParentAdapter.java (-27 lines)
Removed Link Here
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.runtime.registry;
12
13
public abstract class ParentAdapter extends PluginObjectAdapter {
14
	Object[] fChildren;
15
16
	public ParentAdapter(Object object) {
17
		super(object);
18
	}
19
20
	protected abstract Object[] createChildren();
21
22
	public Object[] getChildren() {
23
		if (fChildren == null)
24
			fChildren = createChildren();
25
		return fChildren;
26
	}
27
}
(-)src/org/eclipse/pde/internal/runtime/registry/RegistryBrowser.java (-114 / +74 lines)
Lines 11-16 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.runtime.registry;
12
package org.eclipse.pde.internal.runtime.registry;
13
13
14
import java.net.URI;
15
import java.net.URISyntaxException;
14
import java.util.*;
16
import java.util.*;
15
import java.util.List;
17
import java.util.List;
16
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
Lines 18-26 Link Here
18
import org.eclipse.jface.dialogs.Dialog;
20
import org.eclipse.jface.dialogs.Dialog;
19
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.viewers.*;
22
import org.eclipse.jface.viewers.*;
21
import org.eclipse.osgi.service.resolver.*;
22
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.pde.internal.runtime.*;
24
import org.eclipse.pde.internal.runtime.*;
25
import org.eclipse.pde.internal.runtime.registry.model.*;
24
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.custom.BusyIndicator;
27
import org.eclipse.swt.custom.BusyIndicator;
26
import org.eclipse.swt.dnd.*;
28
import org.eclipse.swt.dnd.*;
Lines 33-40 Link Here
33
import org.eclipse.ui.dialogs.PatternFilter;
35
import org.eclipse.ui.dialogs.PatternFilter;
34
import org.eclipse.ui.part.DrillDownAdapter;
36
import org.eclipse.ui.part.DrillDownAdapter;
35
import org.eclipse.ui.part.ViewPart;
37
import org.eclipse.ui.part.ViewPart;
36
import org.osgi.framework.*;
38
import org.osgi.framework.BundleException;
37
import org.osgi.service.packageadmin.PackageAdmin;
38
39
39
public class RegistryBrowser extends ViewPart {
40
public class RegistryBrowser extends ViewPart {
40
41
Lines 43-54 Link Here
43
	public static final String SHOW_EXTENSIONS_ONLY = "RegistryView.showExtensions.label"; //$NON-NLS-1$ 
44
	public static final String SHOW_EXTENSIONS_ONLY = "RegistryView.showExtensions.label"; //$NON-NLS-1$ 
44
	public static final String SHOW_DISABLED_MODE = "RegistryView.showDisabledMode.label"; //$NON-NLS-1$
45
	public static final String SHOW_DISABLED_MODE = "RegistryView.showDisabledMode.label"; //$NON-NLS-1$
45
46
46
	private RegistryBrowserListener fListener;
47
	private FilteredTree fFilteredTree;
47
	private FilteredTree fFilteredTree;
48
	private TreeViewer fTreeViewer;
48
	private TreeViewer fTreeViewer;
49
	private IMemento fMemento;
49
	private IMemento fMemento;
50
	private int fTotalItems = 0;
50
	private int fTotalItems = 0;
51
51
52
	private RegistryModel model;
53
	private ModelChangeListener listener;
54
55
	private RegistryBrowserContentProvider fContentProvider;
56
52
	// menus and action items
57
	// menus and action items
53
	private Action fRefreshAction;
58
	private Action fRefreshAction;
54
	private Action fShowPluginsAction;
59
	private Action fShowPluginsAction;
Lines 70-81 Link Here
70
	private DrillDownAdapter fDrillDownAdapter;
75
	private DrillDownAdapter fDrillDownAdapter;
71
	private ViewerFilter fActiveFilter = new ViewerFilter() {
76
	private ViewerFilter fActiveFilter = new ViewerFilter() {
72
		public boolean select(Viewer viewer, Object parentElement, Object element) {
77
		public boolean select(Viewer viewer, Object parentElement, Object element) {
73
			if (element instanceof PluginObjectAdapter)
78
			if (element instanceof ExtensionPoint)
74
				element = ((PluginObjectAdapter) element).getObject();
79
				element = Platform.getBundle(((ExtensionPoint) element).getNamespaceIdentifier());
75
			if (element instanceof IExtensionPoint)
80
			else if (element instanceof Extension)
76
				element = Platform.getBundle(((IExtensionPoint) element).getNamespaceIdentifier());
81
				element = Platform.getBundle(((Extension) element).getNamespaceIdentifier());
77
			else if (element instanceof IExtension)
78
				element = Platform.getBundle(((IExtension) element).getNamespaceIdentifier());
79
			if (element instanceof Bundle)
82
			if (element instanceof Bundle)
80
				return ((Bundle) element).getState() == Bundle.ACTIVE;
83
				return ((Bundle) element).getState() == Bundle.ACTIVE;
81
			return true;
84
			return true;
Lines 83-99 Link Here
83
	};
86
	};
84
87
85
	private ViewerFilter fDisabledFilter = new ViewerFilter() {
88
	private ViewerFilter fDisabledFilter = new ViewerFilter() {
86
		PlatformAdmin plaformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
87
		State state = plaformAdmin.getState(false);
88
89
		public boolean select(Viewer viewer, Object parentElement, Object element) {
89
		public boolean select(Viewer viewer, Object parentElement, Object element) {
90
			if (element instanceof PluginObjectAdapter)
91
				element = ((PluginObjectAdapter) element).getObject();
92
93
			if (element instanceof Bundle) {
90
			if (element instanceof Bundle) {
94
				Bundle bundle = (Bundle) element;
91
				return !((Bundle) element).isEnabled();
95
				BundleDescription description = state.getBundle(bundle.getBundleId());
96
				return ((state.getDisabledInfos(description)).length > 0);
97
			}
92
			}
98
			return false;
93
			return false;
99
		}
94
		}
Lines 133-138 Link Here
133
		}
128
		}
134
	}
129
	}
135
130
131
	public RegistryBrowser() {
132
		try {
133
			model = RegistryModelFactory.getRegistryModel(new URI("local"));
134
		} catch (URISyntaxException e) {
135
			PDERuntimePlugin.log(e);
136
		}
137
		model.connect();
138
139
		listener = new RegistryBrowserModelChangeListener(this);
140
		model.addModelChangeListener(listener);
141
	}
142
136
	public void init(IViewSite site, IMemento memento) throws PartInitException {
143
	public void init(IViewSite site, IMemento memento) throws PartInitException {
137
		super.init(site, memento);
144
		super.init(site, memento);
138
		if (memento == null)
145
		if (memento == null)
Lines 140-147 Link Here
140
		else
147
		else
141
			this.fMemento = memento;
148
			this.fMemento = memento;
142
		initializeMemento();
149
		initializeMemento();
143
144
		fListener = new RegistryBrowserListener(this);
145
	}
150
	}
146
151
147
	private void initializeMemento() {
152
	private void initializeMemento() {
Lines 159-170 Link Here
159
	}
164
	}
160
165
161
	public void dispose() {
166
	public void dispose() {
162
		if (fListener != null) {
167
		model.disconnect();
163
			Platform.getExtensionRegistry().removeRegistryChangeListener(fListener);
168
		model.removeModelChangeListener(listener);
164
			PDERuntimePlugin.getDefault().getBundleContext().removeBundleListener(fListener);
169
		if (fClipboard != null) {
165
			PDERuntimePlugin.getDefault().getBundleContext().removeServiceListener(fListener);
170
			fClipboard.dispose();
166
		}
171
		}
167
		fClipboard.dispose();
168
		super.dispose();
172
		super.dispose();
169
	}
173
	}
170
174
Lines 179-188 Link Here
179
		createTreeViewer(composite);
183
		createTreeViewer(composite);
180
		fClipboard = new Clipboard(fTreeViewer.getTree().getDisplay());
184
		fClipboard = new Clipboard(fTreeViewer.getTree().getDisplay());
181
		fillToolBar();
185
		fillToolBar();
182
183
		PDERuntimePlugin.getDefault().getBundleContext().addBundleListener(fListener);
184
		Platform.getExtensionRegistry().addRegistryChangeListener(fListener);
185
		PDERuntimePlugin.getDefault().getBundleContext().addServiceListener(fListener);
186
	}
186
	}
187
187
188
	private void createTreeViewer(Composite parent) {
188
	private void createTreeViewer(Composite parent) {
Lines 198-214 Link Here
198
		GridData gd = new GridData(GridData.FILL_BOTH);
198
		GridData gd = new GridData(GridData.FILL_BOTH);
199
		fFilteredTree.setLayoutData(gd);
199
		fFilteredTree.setLayoutData(gd);
200
		fTreeViewer = fFilteredTree.getViewer();
200
		fTreeViewer = fFilteredTree.getViewer();
201
		fTreeViewer.setContentProvider(new RegistryBrowserContentProvider());
201
		fContentProvider = new RegistryBrowserContentProvider(this);
202
		fTreeViewer.setContentProvider(fContentProvider);
202
		fTreeViewer.setLabelProvider(new RegistryBrowserLabelProvider(fTreeViewer));
203
		fTreeViewer.setLabelProvider(new RegistryBrowserLabelProvider(fTreeViewer));
203
		fTreeViewer.setUseHashlookup(true);
204
		fTreeViewer.setUseHashlookup(true);
204
		fTreeViewer.setComparator(new ViewerComparator() {
205
		fTreeViewer.setComparator(new ViewerComparator() {
205
			public int compare(Viewer viewer, Object e1, Object e2) {
206
			public int compare(Viewer viewer, Object e1, Object e2) {
206
				if (e1 instanceof PluginObjectAdapter)
207
				if (e1 instanceof Folder && e2 instanceof Folder)
207
					e1 = ((PluginObjectAdapter) e1).getObject();
208
					return ((Folder) e1).getId() - ((Folder) e2).getId();
208
				if (e2 instanceof PluginObjectAdapter)
209
					e2 = ((PluginObjectAdapter) e2).getObject();
210
				if (e1 instanceof IBundleFolder && e2 instanceof IBundleFolder)
211
					return ((IBundleFolder) e1).getFolderId() - ((IBundleFolder) e2).getFolderId();
212
				if (e1 instanceof Bundle && e2 instanceof Bundle) {
209
				if (e1 instanceof Bundle && e2 instanceof Bundle) {
213
					e1 = ((Bundle) e1).getSymbolicName();
210
					e1 = ((Bundle) e1).getSymbolicName();
214
					e2 = ((Bundle) e2).getSymbolicName();
211
					e2 = ((Bundle) e2).getSymbolicName();
Lines 240-254 Link Here
240
		tree.setMenu(menu);
237
		tree.setMenu(menu);
241
	}
238
	}
242
239
243
	private PluginObjectAdapter[] getBundles() {
244
		Bundle[] bundles = PDERuntimePlugin.getDefault().getBundleContext().getBundles();
245
		ArrayList list = new ArrayList();
246
		for (int i = 0; i < bundles.length; i++)
247
			if (bundles[i].getHeaders().get(Constants.FRAGMENT_HOST) == null)
248
				list.add(new PluginAdapter(bundles[i]));
249
		return (PluginObjectAdapter[]) list.toArray(new PluginObjectAdapter[list.size()]);
250
	}
251
252
	private void fillToolBar() {
240
	private void fillToolBar() {
253
		fDrillDownAdapter = new RegistryDrillDownAdapter(fTreeViewer);
241
		fDrillDownAdapter = new RegistryDrillDownAdapter(fTreeViewer);
254
		IActionBars bars = getViewSite().getActionBars();
242
		IActionBars bars = getViewSite().getActionBars();
Lines 424-484 Link Here
424
		fEnableAction = new Action(PDERuntimeMessages.RegistryView_enableAction_label) {
412
		fEnableAction = new Action(PDERuntimeMessages.RegistryView_enableAction_label) {
425
			public void run() {
413
			public void run() {
426
				List bundles = getSelectedBundles();
414
				List bundles = getSelectedBundles();
427
				State state = PDERuntimePlugin.getDefault().getState();
428
				for (Iterator it = bundles.iterator(); it.hasNext();) {
415
				for (Iterator it = bundles.iterator(); it.hasNext();) {
429
					Bundle bundle = (Bundle) it.next();
416
					Bundle bundle = (Bundle) it.next();
430
					BundleDescription desc = state.getBundle(bundle.getBundleId());
417
					bundle.setEnabled(true);
431
					DisabledInfo[] infos = state.getDisabledInfos(desc);
432
					for (int i = 0; i < infos.length; i++) {
433
						PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
434
						platformAdmin.removeDisabledInfo(infos[i]);
435
					}
436
				}
418
				}
437
				PackageAdmin packageAdmin = PDERuntimePlugin.getDefault().getPackageAdmin();
438
				packageAdmin.refreshPackages((Bundle[]) bundles.toArray(new Bundle[bundles.size()]));
439
			}
419
			}
440
		};
420
		};
441
421
442
		fDisableAction = new Action(PDERuntimeMessages.RegistryView_disableAction_label) {
422
		fDisableAction = new Action(PDERuntimeMessages.RegistryView_disableAction_label) {
443
			public void run() {
423
			public void run() {
444
				List bundles = getSelectedBundles();
424
				List bundles = getSelectedBundles();
445
				State state = PDERuntimePlugin.getDefault().getState();
446
				for (Iterator it = bundles.iterator(); it.hasNext();) {
425
				for (Iterator it = bundles.iterator(); it.hasNext();) {
447
					Bundle bundle = (Bundle) it.next();
426
					Bundle bundle = (Bundle) it.next();
448
					BundleDescription desc = state.getBundle(bundle.getBundleId());
427
					bundle.setEnabled(false);
449
					DisabledInfo info = new DisabledInfo("org.eclipse.pde.ui", "Disabled via PDE", desc); //$NON-NLS-1$ //$NON-NLS-2$
450
					PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
451
					platformAdmin.addDisabledInfo(info);
452
				}
428
				}
453
				PackageAdmin packageAdmin = PDERuntimePlugin.getDefault().getPackageAdmin();
454
				packageAdmin.refreshPackages((Bundle[]) bundles.toArray(new Bundle[bundles.size()]));
455
			}
429
			}
456
		};
430
		};
457
431
458
		fDiagnoseAction = new Action(PDERuntimeMessages.RegistryView_diagnoseAction_label) {
432
		fDiagnoseAction = new Action(PDERuntimeMessages.RegistryView_diagnoseAction_label) {
459
			public void run() {
433
			public void run() {
460
				List bundles = getSelectedBundles();
434
				List bundles = getSelectedBundles();
461
				State state = PDERuntimePlugin.getDefault().getState();
462
				for (Iterator it = bundles.iterator(); it.hasNext();) {
435
				for (Iterator it = bundles.iterator(); it.hasNext();) {
463
					Bundle bundle = (Bundle) it.next();
436
					Bundle bundle = (Bundle) it.next();
464
					BundleDescription desc = state.getBundle(bundle.getBundleId());
437
					MultiStatus problems = bundle.diagnose();
465
					PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
466
					VersionConstraint[] unsatisfied = platformAdmin.getStateHelper().getUnsatisfiedConstraints(desc);
467
					ResolverError[] resolverErrors = platformAdmin.getState(false).getResolverErrors(desc);
468
					MultiStatus problems = new MultiStatus(PDERuntimePlugin.ID, IStatus.INFO, PDERuntimeMessages.RegistryView_found_problems, null);
469
					for (int i = 0; i < resolverErrors.length; i++) {
470
						if ((resolverErrors[i].getType() & (ResolverError.MISSING_FRAGMENT_HOST | ResolverError.MISSING_GENERIC_CAPABILITY | ResolverError.MISSING_IMPORT_PACKAGE | ResolverError.MISSING_REQUIRE_BUNDLE)) != 0)
471
							continue;
472
						IStatus status = new Status(IStatus.WARNING, PDERuntimePlugin.ID, resolverErrors[i].toString());
473
						problems.add(status);
474
					}
475
438
476
					for (int i = 0; i < unsatisfied.length; i++) {
477
						IStatus status = new Status(IStatus.WARNING, PDERuntimePlugin.ID, MessageHelper.getResolutionFailureMessage(unsatisfied[i]));
478
						problems.add(status);
479
					}
480
					Dialog dialog;
439
					Dialog dialog;
481
					if (unsatisfied.length != 0 || resolverErrors.length != 0) {
440
					if (problems.getChildren().length > 0) {
482
						dialog = new DiagnosticsDialog(getSite().getShell(), PDERuntimeMessages.RegistryView_diag_dialog_title, null, problems, IStatus.WARNING);
441
						dialog = new DiagnosticsDialog(getSite().getShell(), PDERuntimeMessages.RegistryView_diag_dialog_title, null, problems, IStatus.WARNING);
483
						dialog.open();
442
						dialog.open();
484
					} else {
443
					} else {
Lines 499-515 Link Here
499
		fCollapseAllAction.setToolTipText(PDERuntimeMessages.RegistryView_collapseAll_tooltip);
458
		fCollapseAllAction.setToolTipText(PDERuntimeMessages.RegistryView_collapseAll_tooltip);
500
	}
459
	}
501
460
461
	public boolean showExtensionsOnly() {
462
		return fShowExtensionsOnlyAction.isChecked();
463
	}
464
502
	protected void updateItems(boolean resetInput) {
465
	protected void updateItems(boolean resetInput) {
503
		Object[] input = null;
466
		Object[] input = null;
504
		boolean extOnly = fShowExtensionsOnlyAction.isChecked();
467
		if (showExtensionsOnly())
505
		if (extOnly)
468
			input = model.getExtensionPoints();
506
			input = Platform.getExtensionRegistry().getExtensionPoints();
507
		else
469
		else
508
			input = getBundles();
470
			input = model.getBundles();
509
		fListener.fExtOnly = extOnly;
510
		fTotalItems = input.length;
471
		fTotalItems = input.length;
511
		if (resetInput)
472
		if (resetInput)
512
			fTreeViewer.setInput(new PluginObjectAdapter(input));
473
			fTreeViewer.setInput(input);
513
		updateTitle();
474
		updateTitle();
514
	}
475
	}
515
476
Lines 531-552 Link Here
531
		return NLS.bind(PDERuntimeMessages.RegistryView_titleSummary, (new String[] {Integer.toString(tree.getItemCount()), Integer.toString(fTotalItems), type}));
492
		return NLS.bind(PDERuntimeMessages.RegistryView_titleSummary, (new String[] {Integer.toString(tree.getItemCount()), Integer.toString(fTotalItems), type}));
532
	}
493
	}
533
494
534
	// TODO hackish, should rewrite
535
	private boolean isBundleSelected() {
495
	private boolean isBundleSelected() {
536
		IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
496
		IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
537
		if (selection != null) {
497
		if (selection != null) {
538
			Object[] elements = selection.toArray();
498
			Object[] elements = selection.toArray();
539
			for (int i = 0; i < elements.length; i++) {
499
			for (int i = 0; i < elements.length; i++) {
540
				if (elements[i] instanceof PluginObjectAdapter) {
500
				if (!(elements[i] instanceof Bundle)) {
541
					PluginObjectAdapter adapter = (PluginObjectAdapter) elements[i];
542
					Object object = adapter.getObject();
543
					if (!(object instanceof Bundle))
544
						return false;
545
				} else {
546
					return false;
501
					return false;
547
				}
502
				}
548
			}
503
			}
549
		}
504
		}
505
550
		return true;
506
		return true;
551
	}
507
	}
552
508
Lines 556-572 Link Here
556
		if (selection != null) {
512
		if (selection != null) {
557
			Object[] elements = selection.toArray();
513
			Object[] elements = selection.toArray();
558
			for (int i = 0; i < elements.length; i++) {
514
			for (int i = 0; i < elements.length; i++) {
559
				if (elements[i] instanceof PluginObjectAdapter) {
515
				if (elements[i] instanceof Bundle) {
560
					PluginObjectAdapter adapter = (PluginObjectAdapter) elements[i];
516
					bundles.add(elements[i]);
561
					Object object = adapter.getObject();
562
					if (object instanceof Bundle)
563
						bundles.add(object);
564
				}
517
				}
565
			}
518
			}
566
		}
519
		}
567
		return bundles;
520
		return bundles;
568
	}
521
	}
569
522
523
	/**
524
	 * @return true if none is stopped, false if at least one is stopped
525
	 */
570
	private boolean selectedBundlesStarted() {
526
	private boolean selectedBundlesStarted() {
571
		List bundles = getSelectedBundles();
527
		List bundles = getSelectedBundles();
572
		for (Iterator it = bundles.iterator(); it.hasNext();) {
528
		for (Iterator it = bundles.iterator(); it.hasNext();) {
Lines 577-582 Link Here
577
		return true;
533
		return true;
578
	}
534
	}
579
535
536
	/**
537
	 * @return true if none is active, false if at least one is active
538
	 */
580
	private boolean selectedBundlesStopped() {
539
	private boolean selectedBundlesStopped() {
581
		List bundles = getSelectedBundles();
540
		List bundles = getSelectedBundles();
582
		for (Iterator it = bundles.iterator(); it.hasNext();) {
541
		for (Iterator it = bundles.iterator(); it.hasNext();) {
Lines 587-620 Link Here
587
		return true;
546
		return true;
588
	}
547
	}
589
548
549
	/**
550
	 * @return true if none is enabled, false if at least one is enabled
551
	 */
590
	private boolean selectedBundlesDisabled() {
552
	private boolean selectedBundlesDisabled() {
591
		List bundles = getSelectedBundles();
553
		List bundles = getSelectedBundles();
592
		for (Iterator it = bundles.iterator(); it.hasNext();) {
554
		for (Iterator it = bundles.iterator(); it.hasNext();) {
593
			Bundle bundle = (Bundle) it.next();
555
			Bundle bundle = (Bundle) it.next();
594
			State state = PDERuntimePlugin.getDefault().getState();
556
			if (bundle.isEnabled())
595
			BundleDescription desc = state.getBundle(bundle.getBundleId());
596
			DisabledInfo[] infos = state.getDisabledInfos(desc);
597
			if (infos.length == 0)
598
				return false;
557
				return false;
599
		}
558
		}
600
		return true;
559
		return true;
601
	}
560
	}
602
561
562
	/**
563
	 * @return true if none is disabled, false if at least one is disabled
564
	 */
603
	private boolean selectedBundlesEnabled() {
565
	private boolean selectedBundlesEnabled() {
604
		List bundles = getSelectedBundles();
566
		List bundles = getSelectedBundles();
605
		for (Iterator it = bundles.iterator(); it.hasNext();) {
567
		for (Iterator it = bundles.iterator(); it.hasNext();) {
606
			Bundle bundle = (Bundle) it.next();
568
			Bundle bundle = (Bundle) it.next();
607
			State state = PDERuntimePlugin.getDefault().getState();
569
			if (!bundle.isEnabled())
608
			BundleDescription desc = state.getBundle(bundle.getBundleId());
609
			DisabledInfo[] infos = state.getDisabledInfos(desc);
610
			if (infos.length > 0)
611
				return false;
570
				return false;
612
		}
571
		}
613
		return true;
572
		return true;
614
	}
573
	}
615
574
616
	protected void add(Object object) {
575
	public void add(Object object) {
617
		add(fTreeViewer.getInput(), object);
576
		Object parent = fContentProvider.getParent(object);
577
		if (parent == null) {
578
			add(fTreeViewer.getInput(), object);
579
		} else {
580
			refresh(parent);
581
		}
618
	}
582
	}
619
583
620
	protected void add(Object parent, Object object) {
584
	protected void add(Object parent, Object object) {
Lines 625-631 Link Here
625
		updateTitle();
589
		updateTitle();
626
	}
590
	}
627
591
628
	protected void remove(Object object) {
592
	public void remove(Object object) {
629
		if (fDrillDownAdapter.canGoHome())
593
		if (fDrillDownAdapter.canGoHome())
630
			return;
594
			return;
631
		fTotalItems -= 1;
595
		fTotalItems -= 1;
Lines 633-647 Link Here
633
		updateTitle();
597
		updateTitle();
634
	}
598
	}
635
599
636
	protected void update(Object object) {
600
	public void update(Object object) {
637
		fTreeViewer.update(object, null);
601
		fTreeViewer.update(object, null);
638
	}
602
	}
639
603
640
	protected void refresh(Object object) {
604
	public void refresh(Object object) {
641
		fTreeViewer.refresh(object);
605
		fTreeViewer.refresh(object);
642
	}
606
	}
643
644
	protected TreeItem[] getTreeItems() {
645
		return fTreeViewer.getTree().getItems();
646
	}
647
}
607
}
(-)src/org/eclipse/pde/internal/runtime/registry/ExtensionAdapter.java (-33 lines)
Removed Link Here
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.runtime.registry;
12
13
import org.eclipse.core.runtime.IConfigurationElement;
14
import org.eclipse.core.runtime.IExtension;
15
16
public class ExtensionAdapter extends ParentAdapter {
17
18
	public ExtensionAdapter(Object object) {
19
		super(object);
20
	}
21
22
	protected Object[] createChildren() {
23
		IExtension extension = (IExtension) getObject();
24
25
		IConfigurationElement[] elements = extension.getConfigurationElements();
26
		Object[] result = new ConfigurationElementAdapter[elements.length];
27
		for (int i = 0; i < elements.length; i++) {
28
			IConfigurationElement config = elements[i];
29
			result[i] = new ConfigurationElementAdapter(config);
30
		}
31
		return result;
32
	}
33
}
(-)src/org/eclipse/pde/internal/runtime/registry/ExtensionPointAdapter.java (-33 lines)
Removed Link Here
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.runtime.registry;
12
13
import org.eclipse.core.runtime.IExtension;
14
import org.eclipse.core.runtime.IExtensionPoint;
15
16
public class ExtensionPointAdapter extends ParentAdapter {
17
18
	public ExtensionPointAdapter(Object object) {
19
		super(object);
20
	}
21
22
	protected Object[] createChildren() {
23
		IExtensionPoint extensionPoint = (IExtensionPoint) getObject();
24
25
		IExtension[] extensions = extensionPoint.getExtensions();
26
		Object[] result = new Object[extensions.length];
27
		for (int i = 0; i < extensions.length; i++) {
28
			IExtension extension = extensions[i];
29
			result[i] = new ExtensionAdapter(extension);
30
		}
31
		return result;
32
	}
33
}
(-)src/org/eclipse/pde/internal/runtime/registry/ServiceReferenceAdapter.java (-35 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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.runtime.registry;
12
13
import org.osgi.framework.ServiceReference;
14
15
public class ServiceReferenceAdapter extends ParentAdapter {
16
17
	public ServiceReferenceAdapter(ServiceReference object) {
18
		super(object);
19
	}
20
21
	protected Object[] createChildren() {
22
		// TODO pluggable support for different services
23
		return null;
24
	}
25
26
	public boolean equals(Object obj) {
27
		// imitate ServiceReference behavior, that multiple ServiceReference instances are equal
28
		return (obj instanceof ServiceReferenceAdapter) ? getObject().equals(((ServiceReferenceAdapter) obj).getObject()) : false;
29
	}
30
31
	public int hashCode() {
32
		// imitate ServiceReference behavior, that multiple ServiceReference instances return the same hashCode
33
		return getObject().hashCode();
34
	}
35
}
(-)src/org/eclipse/pde/internal/runtime/registry/PluginObjectAdapter.java (-25 lines)
Removed Link Here
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.runtime.registry;
12
13
import org.eclipse.core.runtime.PlatformObject;
14
15
public class PluginObjectAdapter extends PlatformObject {
16
	private Object fObject;
17
18
	public PluginObjectAdapter(Object object) {
19
		this.fObject = object;
20
	}
21
22
	public Object getObject() {
23
		return fObject;
24
	}
25
}
(-)src/org/eclipse/pde/internal/runtime/registry/ConfigurationElementAdapter.java (-51 lines)
Removed Link Here
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.runtime.registry;
12
13
import org.eclipse.core.runtime.IConfigurationElement;
14
15
public class ConfigurationElementAdapter extends ParentAdapter {
16
17
	class ConfigurationAttribute implements IConfigurationAttribute {
18
		private String fLabel;
19
20
		public ConfigurationAttribute(String name, String value) {
21
			fLabel = name + " = " + value; //$NON-NLS-1$
22
		}
23
24
		public String getLabel() {
25
			return fLabel;
26
		}
27
	}
28
29
	public ConfigurationElementAdapter(Object object) {
30
		super(object);
31
	}
32
33
	protected Object[] createChildren() {
34
		IConfigurationElement config = (IConfigurationElement) getObject();
35
		String[] atts = config.getAttributeNames();
36
		IConfigurationAttribute[] catts = new IConfigurationAttribute[atts.length];
37
		for (int i = 0; i < atts.length; i++)
38
			catts[i] = new ConfigurationAttribute(atts[i], config.getAttribute(atts[i]));
39
		IConfigurationElement[] children = config.getChildren();
40
		Object[] result = new Object[children.length + catts.length];
41
		for (int i = 0; i < children.length; i++) {
42
			IConfigurationElement child = children[i];
43
			result[i] = new ConfigurationElementAdapter(child);
44
		}
45
		for (int i = 0; i < catts.length; i++) {
46
			IConfigurationAttribute child = catts[i];
47
			result[children.length + i] = new ConfigurationAttributeAdapter(child);
48
		}
49
		return result;
50
	}
51
}
(-)src/org/eclipse/pde/internal/runtime/registry/RegistryBrowserListener.java (-376 lines)
Removed Link Here
1
/******************************************************************************
2
 * Copyright (c) 2008 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.runtime.registry;
12
13
import org.eclipse.core.runtime.*;
14
import org.eclipse.pde.internal.runtime.registry.RegistryBrowserContentProvider.BundleFolder;
15
import org.eclipse.swt.widgets.Tree;
16
import org.eclipse.swt.widgets.TreeItem;
17
import org.osgi.framework.*;
18
19
public class RegistryBrowserListener implements IRegistryChangeListener, BundleListener, ServiceListener {
20
21
	protected RegistryBrowser fBrowser;
22
	protected boolean fExtOnly;
23
24
	protected RegistryBrowserListener(RegistryBrowser browser) {
25
		fBrowser = browser;
26
	}
27
28
	public void registryChanged(final IRegistryChangeEvent event) {
29
		final Tree tree = fBrowser.getUndisposedTree();
30
		if (tree == null)
31
			return;
32
33
		tree.getDisplay().asyncExec(new Runnable() {
34
			public void run() {
35
				IExtensionDelta[] deltas = event.getExtensionDeltas();
36
				for (int i = 0; i < deltas.length; i++) {
37
					if (fExtOnly)
38
						handleExtOnlyEvent(deltas[i]);
39
					else
40
						handleEvent(deltas[i]);
41
				}
42
			}
43
		});
44
	}
45
46
	public void bundleChanged(final BundleEvent event) {
47
		final Tree tree = fBrowser.getUndisposedTree();
48
		if (tree == null)
49
			return;
50
51
		tree.getDisplay().asyncExec(new Runnable() {
52
			public void run() {
53
				if (fExtOnly)
54
					handleExtOnlyEvent(event.getType(), event.getBundle());
55
				else
56
					handleEvent(event.getType(), event.getBundle());
57
			}
58
		});
59
	}
60
61
	void handleEvent(IExtensionDelta delta) {
62
		handleDelta(delta, false);
63
	}
64
65
	void handleExtOnlyEvent(IExtensionDelta delta) {
66
		handleDelta(delta, true);
67
	}
68
69
	private void handleDelta(IExtensionDelta delta, boolean extOnly) {
70
		IExtension ext = delta.getExtension();
71
		IExtensionPoint extPoint = delta.getExtensionPoint();
72
		// TODO fix this method (and addToTree/removeFromTree)
73
		// bug 130655
74
		if (delta.getKind() == IExtensionDelta.ADDED) {
75
			addExtensionObjectToTree(ext, extOnly);
76
			addExtensionObjectToTree(extPoint, extOnly);
77
		} else if (delta.getKind() == IExtensionDelta.REMOVED) {
78
			removeFromTree(ext);
79
			removeFromTree(extPoint);
80
		}
81
	}
82
83
	//	private void addToTree(Object object) {
84
	//		String namespace = getNamespaceIdentifier(object);
85
	//		if (namespace == null)
86
	//			return;
87
	//		TreeItem[] items = fTreeViewer.getTree().getItems();
88
	//		for (int i = 0; i < items.length; i++) {
89
	//			Object data = items[i].getData();
90
	//			Object adapted = null;
91
	//			if (data instanceof PluginObjectAdapter)
92
	//				adapted = ((PluginObjectAdapter)data).getObject();
93
	//			if (adapted instanceof Bundle && ((Bundle)adapted).getSymbolicName().equals(namespace)) {
94
	//				addBundleToTree(items[i], data, object);
95
	//			}
96
	//		}
97
	//	}
98
99
	private void addExtensionObjectToTree(Object child, boolean extOnly) {
100
		Object parent = null;
101
		if (!extOnly)
102
			parent = getAdoptingBundleParent(child);
103
		else if (child instanceof IExtensionPoint) {
104
			// add to root
105
			fBrowser.add(child);
106
			return;
107
		} else if (child instanceof IExtension) {
108
			// search all extensionPoints and return the correct one
109
			String extPoint = ((IExtension) child).getExtensionPointUniqueIdentifier();
110
			TreeItem[] items = fBrowser.getTreeItems();
111
			for (int i = 0; i < items.length; i++) {
112
				Object data = items[i].getData();
113
				if (data instanceof PluginObjectAdapter)
114
					data = ((PluginObjectAdapter) data).getObject();
115
				if (data instanceof IExtensionPoint && ((IExtensionPoint) data).getUniqueIdentifier().equals(extPoint)) {
116
					parent = items[i].getData();
117
					break;
118
				}
119
			}
120
		}
121
		if (parent != null)
122
			fBrowser.add(parent, child);
123
	}
124
125
	private Object getAdoptingBundleParent(Object child) {
126
		TreeItem bundleItem = findBundleItem(getNamespaceIdentifier(child));
127
		if (bundleItem != null) {
128
			// TODO fix this
129
			// remove this if (true) clause and return the proper parent
130
			if (true) {
131
				fBrowser.refresh(bundleItem.getData());
132
				fBrowser.updateItems(false);
133
				return null;
134
			}
135
			TreeItem[] folders = bundleItem.getItems();
136
			for (int j = 0; j < folders.length; j++) {
137
				// make sure to check extensionsOnlyMode()
138
				// and add to root/proper extension if true
139
				IBundleFolder folder = (IBundleFolder) folders[j].getData();
140
				if (correctFolder(folder, child))
141
					return folder;
142
			}
143
			// folder not found - 1st extension - refresh bundle item
144
			// to rebuild folders
145
			fBrowser.refresh(bundleItem.getData());
146
		}
147
		return null;
148
	}
149
150
	private TreeItem findBundleItem(String namespace) {
151
		if (namespace == null)
152
			return null;
153
		TreeItem[] items = fBrowser.getTreeItems();
154
		for (int i = 0; i < items.length; i++) {
155
			Object data = items[i].getData();
156
			if (data instanceof PluginObjectAdapter)
157
				data = ((PluginObjectAdapter) data).getObject();
158
			if (data instanceof Bundle && ((Bundle) data).getSymbolicName().equals(namespace))
159
				return items[i];
160
		}
161
		return null;
162
	}
163
164
	//	private void addBundleToTree(TreeItem item, Object data, Object object) {
165
	//		// TODO fix this method
166
	//		if (true) {
167
	//			fTreeViewer.refresh(data);
168
	//			updateItems(false);
169
	//			return;
170
	//		}
171
	//		TreeItem[] folders = item.getItems();
172
	//		for (int j = 0; j < folders.length; j++) {
173
	//			// make sure to check extensionsOnlyMode()
174
	//			// and add to root/proper extension if true
175
	//			IBundleFolder folder = (IBundleFolder)folders[j].getData();
176
	//			if (correctFolder(folder, object)) {
177
	//				fTreeViewer.add(folder, object);
178
	//				return;
179
	//			}
180
	//		}
181
	//		// folder not found - 1st extension - refresh bundle item
182
	//		fTreeViewer.refresh(data);
183
	//	}
184
185
	private String getNamespaceIdentifier(Object object) {
186
		if (object instanceof IExtensionPoint)
187
			return ((IExtensionPoint) object).getNamespaceIdentifier();
188
		if (object instanceof IExtension)
189
			return ((IExtension) object).getContributor().getName();
190
		return null;
191
	}
192
193
	private boolean correctFolder(IBundleFolder folder, Object child) {
194
		if (folder == null)
195
			return false;
196
		if (child instanceof IExtensionPoint)
197
			return folder.getFolderId() == IBundleFolder.F_EXTENSION_POINTS;
198
		if (child instanceof IExtension)
199
			return folder.getFolderId() == IBundleFolder.F_EXTENSIONS;
200
		return false;
201
	}
202
203
	private void removeFromTree(Object object) {
204
		String namespace = getNamespaceIdentifier(object);
205
		if (namespace == null)
206
			return;
207
		TreeItem[] bundles = fBrowser.getTreeItems();
208
		for (int i = 0; i < bundles.length; i++) {
209
			Object data = bundles[i].getData();
210
			Object adapted = null;
211
			if (data instanceof PluginObjectAdapter)
212
				adapted = ((PluginObjectAdapter) data).getObject();
213
			if (adapted instanceof Bundle && ((Bundle) adapted).getSymbolicName().equals(namespace)) {
214
				TreeItem[] folders = bundles[i].getItems();
215
				// TODO fix this method
216
				if (true) {
217
					fBrowser.refresh(data);
218
					fBrowser.updateItems(false);
219
					return;
220
				}
221
				for (int j = 0; j < folders.length; j++) {
222
					IBundleFolder folder = (IBundleFolder) folders[j].getData();
223
					if (correctFolder(folder, object)) {
224
						fBrowser.remove(object);
225
						return;
226
					}
227
				}
228
				// folder not found - 1st extension - refresh bundle item
229
				fBrowser.refresh(data);
230
			}
231
		}
232
	}
233
234
	protected Object findTreeBundleData(Object searchData) {
235
		final Tree tree = fBrowser.getUndisposedTree();
236
		if (tree == null)
237
			return null;
238
239
		Object data = null;
240
		TreeItem[] items = fBrowser.getTreeItems();
241
		if (items == null)
242
			return null;
243
		for (int i = 0; i < items.length; i++) {
244
			Object object = items[i].getData();
245
			data = object;
246
			if (object instanceof PluginObjectAdapter)
247
				object = ((PluginObjectAdapter) object).getObject();
248
			if (searchData.equals(object))
249
				return data;
250
		}
251
		return null;
252
	}
253
254
	void handleEvent(int changeType, Bundle bundle) {
255
		Object data = findTreeBundleData(bundle);
256
		switch (changeType) {
257
			case BundleEvent.INSTALLED :
258
				if (data == null)
259
					fBrowser.add(new PluginAdapter(bundle));
260
				break;
261
			case BundleEvent.UNINSTALLED :
262
				if (data != null)
263
					fBrowser.remove(data);
264
				break;
265
			case BundleEvent.STARTED :
266
			case BundleEvent.STOPPED :
267
			case BundleEvent.UPDATED :
268
			case BundleEvent.RESOLVED :
269
			case BundleEvent.STARTING :
270
			case BundleEvent.STOPPING :
271
			case BundleEvent.UNRESOLVED :
272
			case BundleEvent.LAZY_ACTIVATION :
273
				if (data != null)
274
					fBrowser.update(data);
275
				break;
276
		}
277
	}
278
279
	void handleExtOnlyEvent(int changeType, Bundle bundle) {
280
		switch (changeType) {
281
			case BundleEvent.INSTALLED :
282
			case BundleEvent.UNINSTALLED :
283
				// add/remove all extension points contributed by new bundle
284
				IExtensionPoint[] points = Platform.getExtensionRegistry().getExtensionPoints(bundle.getSymbolicName());
285
				for (int i = 0; i < points.length; i++) {
286
					Object pointData = findTreeBundleData(points[i]);
287
					if (pointData == null) {
288
						if (changeType == BundleEvent.INSTALLED)
289
							fBrowser.add(new ExtensionPointAdapter(points[i]));
290
						else
291
							// changeType == BundleEvent.UNINSTALLED
292
							fBrowser.remove(pointData);
293
					}
294
				}
295
				// add/remove all extensions contributed by new bundle
296
				IExtension[] extensions = Platform.getExtensionRegistry().getExtensions(bundle.getSymbolicName());
297
				for (int i = 0; i < extensions.length; i++) {
298
					String pointId = extensions[i].getExtensionPointUniqueIdentifier();
299
					if (changeType == BundleEvent.INSTALLED) {
300
						IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(pointId);
301
						Object pointData = findTreeBundleData(point);
302
						if (pointData != null)
303
							fBrowser.add(pointData, new ExtensionAdapter(extensions[i]));
304
					} else { // changeType == BundleEvent.UNINSTALLED
305
						Object extensionData = findTreeBundleData(extensions[i]);
306
						if (extensionData != null)
307
							fBrowser.remove(extensionData);
308
					}
309
				}
310
				break;
311
			case BundleEvent.STARTED :
312
			case BundleEvent.STOPPED :
313
			case BundleEvent.UPDATED :
314
			case BundleEvent.RESOLVED :
315
			case BundleEvent.STARTING :
316
			case BundleEvent.STOPPING :
317
			case BundleEvent.UNRESOLVED :
318
			case BundleEvent.LAZY_ACTIVATION :
319
				// nothing needs to be done for any other cases
320
				break;
321
		}
322
	}
323
324
	public void serviceChanged(final ServiceEvent event) {
325
		final Tree tree = fBrowser.getUndisposedTree();
326
		if (tree == null)
327
			return;
328
329
		tree.getDisplay().asyncExec(new Runnable() {
330
			public void run() {
331
				handleServiceChangedEvent(event);
332
			}
333
		});
334
335
	}
336
337
	protected void handleServiceChangedEvent(ServiceEvent event) {
338
		ServiceReference ref = event.getServiceReference();
339
		switch (event.getType()) {
340
			case ServiceEvent.REGISTERED :
341
			case ServiceEvent.UNREGISTERING :
342
				Bundle bundle = ref.getBundle();
343
				if (bundle == null)
344
					return;
345
				String name = bundle.getSymbolicName();
346
				if (name == null)
347
					return;
348
				TreeItem bundleItem = findBundleItem(name);
349
				if (bundleItem == null)
350
					return;
351
				PluginAdapter bundleAdapter = ((PluginAdapter) bundleItem.getData());
352
				Object[] folders = bundleAdapter.getChildren();
353
354
				for (int j = 0; j < folders.length; j++) {
355
					if (folders[j] instanceof IBundleFolder) {
356
						IBundleFolder folder = (IBundleFolder) folders[j];
357
358
						if (folder.getFolderId() == IBundleFolder.F_REGISTERED_SERVICES) {
359
							if ((event.getType() == ServiceEvent.REGISTERED) || (event.getType() == ServiceEvent.UNREGISTERING)) {
360
								((BundleFolder) folder).refresh(); // refresh model
361
								fBrowser.refresh(folder); // refresh view
362
363
								// refresh whole bundle in case there were folders added - they might have not existed if bundle had no service before
364
								fBrowser.refresh(bundleAdapter);
365
							}
366
						}
367
					}
368
				}
369
370
				break;
371
			case ServiceEvent.MODIFIED :
372
				break;
373
		}
374
	}
375
376
}
(-)src/org/eclipse/pde/internal/runtime/registry/RegistryBrowserLabelProvider.java (-89 / +54 lines)
Lines 10-28 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.runtime.registry;
11
package org.eclipse.pde.internal.runtime.registry;
12
12
13
import java.io.IOException;
14
import java.net.URL;
15
import java.util.Arrays;
13
import java.util.Arrays;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.jface.resource.ImageDescriptor;
14
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.jface.viewers.LabelProvider;
19
import org.eclipse.jface.viewers.TreeViewer;
16
import org.eclipse.jface.viewers.TreeViewer;
20
import org.eclipse.osgi.service.resolver.*;
21
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.osgi.util.NLS;
22
import org.eclipse.pde.internal.runtime.*;
18
import org.eclipse.pde.internal.runtime.*;
19
import org.eclipse.pde.internal.runtime.registry.model.*;
23
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.graphics.Image;
24
import org.osgi.framework.Bundle;
25
import org.osgi.framework.ServiceReference;
26
21
27
public class RegistryBrowserLabelProvider extends LabelProvider {
22
public class RegistryBrowserLabelProvider extends LabelProvider {
28
23
Lines 102-119 Link Here
102
	}
97
	}
103
98
104
	public Image getImage(Object element) {
99
	public Image getImage(Object element) {
105
		if (element instanceof PluginObjectAdapter)
106
			element = ((PluginObjectAdapter) element).getObject();
107
108
		if (element instanceof Bundle) {
100
		if (element instanceof Bundle) {
109
			Bundle bundle = (Bundle) element;
101
			Bundle bundle = (Bundle) element;
110
102
111
			// check if bundle is disabled
103
			if (!bundle.isEnabled())
112
			PlatformAdmin plaformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
113
			State state = plaformAdmin.getState(false);
114
115
			BundleDescription description = state.getBundle(bundle.getBundleId());
116
			if ((state.getDisabledInfos(description)).length > 0)
117
				return fDisabledImage;
104
				return fDisabledImage;
118
105
119
			switch (bundle.getState()) {
106
			switch (bundle.getState()) {
Lines 122-268 Link Here
122
				case Bundle.UNINSTALLED :
109
				case Bundle.UNINSTALLED :
123
					return fUnresolvedPluginImage;
110
					return fUnresolvedPluginImage;
124
				case Bundle.INSTALLED :
111
				case Bundle.INSTALLED :
125
					if ((state.getDisabledInfos(description)).length > 0)
112
					if (!bundle.isEnabled())
126
						return fUnresolvedPluginImage;
113
						return fUnresolvedPluginImage;
127
				default :
114
				default :
128
					return fPluginImage;
115
					return fPluginImage;
129
			}
116
			}
130
		}
117
		}
131
118
132
		if (element instanceof ServiceReference) {
119
		if (element instanceof ServiceRegistration) {
133
			return fServiceImage;
120
			return fServiceImage;
134
		}
121
		}
135
122
136
		if (element instanceof IBundleFolder) {
123
		if (element instanceof Folder) {
137
			int id = ((IBundleFolder) element).getFolderId();
124
			int id = ((Folder) element).getId();
138
			switch (id) {
125
			switch (id) {
139
				case IBundleFolder.F_EXTENSIONS :
126
				case Folder.F_EXTENSIONS :
140
					return fExtensionsImage;
127
					return fExtensionsImage;
141
				case IBundleFolder.F_EXTENSION_POINTS :
128
				case Folder.F_EXTENSION_POINTS :
142
					return fExtensionPointsImage;
129
					return fExtensionPointsImage;
143
				case IBundleFolder.F_IMPORTS :
130
				case Folder.F_IMPORTS :
144
					return fRequiresImage;
131
					return fRequiresImage;
145
				case IBundleFolder.F_LIBRARIES :
132
				case Folder.F_LIBRARIES :
146
					return fRuntimeImage;
133
					return fRuntimeImage;
147
				case IBundleFolder.F_LOCATION :
134
				case Folder.F_REGISTERED_SERVICES :
148
					return fLocationImage;
149
				case IBundleFolder.F_REGISTERED_SERVICES :
150
					return fExporterImage;
135
					return fExporterImage;
151
				case IBundleFolder.F_SERVICES_IN_USE :
136
				case Folder.F_SERVICES_IN_USE :
152
					return fImporterImage;
137
					return fImporterImage;
153
			}
138
			}
154
			return null;
139
			return null;
155
		}
140
		}
156
		if (element instanceof IExtension)
141
		if (element instanceof Extension)
157
			return fExtensionImage;
142
			return fExtensionImage;
158
143
159
		if (element instanceof IExtensionPoint)
144
		if (element instanceof ExtensionPoint)
160
			return fExtensionPointImage;
145
			return fExtensionPointImage;
161
146
162
		if (element instanceof IBundlePrerequisite)
147
		if (element instanceof BundlePrerequisite)
163
			return ((IBundlePrerequisite) element).isExported() ? fExpReqPluginImage : fReqPluginImage;
148
			return ((BundlePrerequisite) element).isExported() ? fExpReqPluginImage : fReqPluginImage;
164
149
165
		if (element instanceof IBundleLibrary)
150
		if (element instanceof BundleLibrary)
166
			return fLibraryImage;
151
			return fLibraryImage;
167
152
168
		if (element instanceof IConfigurationElement)
153
		if (element instanceof ConfigurationElement)
169
			return fGenericTagImage;
154
			return fGenericTagImage;
170
155
171
		if (element instanceof IConfigurationAttribute)
156
		if (element instanceof Attribute) {
157
			Attribute attr = (Attribute) element;
158
			if (Attribute.F_LOCATION.equals(attr.getName())) {
159
				return fLocationImage;
160
			}
172
			return fGenericAttrImage;
161
			return fGenericAttrImage;
162
		}
173
163
174
		return null;
164
		return null;
175
	}
165
	}
176
166
177
	public String getText(Object element) {
167
	public String getText(Object element) {
178
		if (element instanceof PluginObjectAdapter)
179
			element = ((PluginObjectAdapter) element).getObject();
180
		if (element instanceof Bundle) {
168
		if (element instanceof Bundle) {
181
			String id = ((Bundle) element).getSymbolicName();
169
			String id = ((Bundle) element).getSymbolicName();
182
			String version = (String) ((Bundle) element).getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
170
			String version = ((Bundle) element).getVersion();
183
			if (version == null)
171
			if (version == null)
184
				return id;
172
				return id;
185
			return id + " (" + version + ")"; //$NON-NLS-1$ //$NON-NLS-2$
173
			return id + " (" + version + ")"; //$NON-NLS-1$ //$NON-NLS-2$
186
		}
174
		}
187
		if (element instanceof ServiceReference) {
175
		if (element instanceof ServiceRegistration) {
188
			ServiceReference ref = (ServiceReference) element;
176
			ServiceRegistration ref = (ServiceRegistration) element;
189
			String[] classes = (String[]) ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
177
			String[] classes = ref.getClasses();
190
			Long id = (Long) ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
178
			Long id = ref.getId();
191
			String identifier = " (id=" + id.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
179
			String identifier = " (id=" + id.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
192
			return Arrays.asList(classes).toString().concat(identifier);
180
			return Arrays.asList(classes).toString().concat(identifier);
193
		}
181
		}
194
		if (element instanceof IBundleFolder) {
182
		if (element instanceof Folder) {
195
			switch (((IBundleFolder) element).getFolderId()) {
183
			switch (((Folder) element).getId()) {
196
				case IBundleFolder.F_IMPORTS :
184
				case Folder.F_IMPORTS :
197
					return PDERuntimeMessages.RegistryView_folders_imports;
185
					return PDERuntimeMessages.RegistryView_folders_imports;
198
				case IBundleFolder.F_LIBRARIES :
186
				case Folder.F_LIBRARIES :
199
					return PDERuntimeMessages.RegistryView_folders_libraries;
187
					return PDERuntimeMessages.RegistryView_folders_libraries;
200
				case IBundleFolder.F_EXTENSION_POINTS :
188
				case Folder.F_EXTENSION_POINTS :
201
					return PDERuntimeMessages.RegistryView_folders_extensionPoints;
189
					return PDERuntimeMessages.RegistryView_folders_extensionPoints;
202
				case IBundleFolder.F_EXTENSIONS :
190
				case Folder.F_EXTENSIONS :
203
					return PDERuntimeMessages.RegistryView_folders_extensions;
191
					return PDERuntimeMessages.RegistryView_folders_extensions;
204
				case IBundleFolder.F_REGISTERED_SERVICES :
192
				case Folder.F_REGISTERED_SERVICES :
205
					return PDERuntimeMessages.RegistryBrowserLabelProvider_registeredServices;
193
					return PDERuntimeMessages.RegistryBrowserLabelProvider_registeredServices;
206
				case IBundleFolder.F_SERVICES_IN_USE :
194
				case Folder.F_SERVICES_IN_USE :
207
					return PDERuntimeMessages.RegistryBrowserLabelProvider_usedServices;
195
					return PDERuntimeMessages.RegistryBrowserLabelProvider_usedServices;
208
				case IBundleFolder.F_LOCATION :
209
					Bundle bundle = ((IBundleFolder) element).getBundle();
210
					URL bundleEntry = bundle.getEntry("/"); //$NON-NLS-1$
211
					try {
212
						bundleEntry = FileLocator.resolve(bundleEntry);
213
					} catch (IOException e) { // do nothing
214
					}
215
					IPath path = new Path(bundleEntry.getFile());
216
					String pathString = path.removeTrailingSeparator().toOSString();
217
					if (pathString.startsWith("file:")) //$NON-NLS-1$
218
						pathString = pathString.substring(5);
219
					if (pathString.endsWith("!")) //$NON-NLS-1$
220
						pathString = pathString.substring(0, pathString.length() - 1);
221
					return pathString;
222
			}
196
			}
223
		}
197
		}
224
		if (element instanceof IExtension) {
198
		if (element instanceof Extension) {
225
			if (((RegistryBrowserContentProvider) fViewer.getContentProvider()).isInExtensionSet) {
199
			if (((RegistryBrowserContentProvider) fViewer.getContentProvider()).isInExtensionSet) {
226
				String name = ((IExtension) element).getLabel();
200
				String name = ((Extension) element).getLabel();
227
				String id = ((IExtension) element).getExtensionPointUniqueIdentifier();
201
				String id = ((Extension) element).getExtensionPointUniqueIdentifier();
228
				if (name != null && name.length() > 0)
202
				if (name != null && name.length() > 0)
229
					return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name);
203
					return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name);
230
				return id;
204
				return id;
231
			}
205
			}
232
206
233
			String contributor = ((IExtension) element).getNamespaceIdentifier();
207
			String contributor = ((Extension) element).getNamespaceIdentifier();
234
			return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_contributedBy, contributor);
208
			return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_contributedBy, contributor);
235
209
236
		}
210
		}
237
		if (element instanceof IExtensionPoint) {
211
		if (element instanceof ExtensionPoint) {
238
			String id = ((IExtensionPoint) element).getUniqueIdentifier();
212
			String id = ((ExtensionPoint) element).getUniqueIdentifier();
239
			String name = ((IExtensionPoint) element).getLabel();
213
			String name = ((ExtensionPoint) element).getLabel();
240
			if (name != null && name.length() > 0)
214
			if (name != null && name.length() > 0)
241
				return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name);
215
				return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name);
242
			return id;
216
			return id;
243
		}
217
		}
244
		if (element instanceof IBundlePrerequisite)
218
		if (element instanceof BundlePrerequisite)
245
			return ((IBundlePrerequisite) element).getLabel();
219
			return ((BundlePrerequisite) element).getName();
246
220
247
		if (element instanceof IBundleLibrary)
221
		if (element instanceof BundleLibrary)
248
			return ((IBundleLibrary) element).getLibrary();
222
			return ((BundleLibrary) element).getLibrary();
249
223
250
		if (element instanceof IConfigurationElement) {
224
		if (element instanceof ConfigurationElement) {
251
			String label = ((IConfigurationElement) element).getAttribute("label"); //$NON-NLS-1$
225
			return ((ConfigurationElement) element).getName();
252
			if (label == null)
226
		}
253
				label = ((IConfigurationElement) element).getName();
227
		if (element instanceof Attribute) {
254
228
			Attribute attribute = (Attribute) element;
255
			if (label == null)
229
			return attribute.getName() + " = " + attribute.getValue(); //$NON-NLS-1$
256
				label = ((IConfigurationElement) element).getAttribute("name"); //$NON-NLS-1$
257
258
			if (label == null && ((IConfigurationElement) element).getAttribute("id") != null) { //$NON-NLS-1$
259
				String[] labelSplit = ((IConfigurationElement) element).getAttribute("id").split("\\."); //$NON-NLS-1$ //$NON-NLS-2$
260
				label = labelSplit.length == 0 ? null : labelSplit[labelSplit.length - 1];
261
			}
262
			return label;
263
		}
230
		}
264
		if (element instanceof IConfigurationAttribute)
265
			return ((IConfigurationAttribute) element).getLabel();
266
231
267
		return super.getText(element);
232
		return super.getText(element);
268
	}
233
	}
(-)src/org/eclipse/pde/internal/runtime/registry/IBundleFolder.java (-32 lines)
Removed Link Here
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.runtime.registry;
12
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.osgi.framework.Bundle;
15
16
public interface IBundleFolder extends IAdaptable {
17
	public static final int F_LOCATION = 0;
18
	public static final int F_EXTENSIONS = 1;
19
	public static final int F_EXTENSION_POINTS = 2;
20
	public static final int F_IMPORTS = 3;
21
	public static final int F_LIBRARIES = 4;
22
	public static final int F_REGISTERED_SERVICES = 5;
23
	public static final int F_SERVICES_IN_USE = 6;
24
25
	public Object[] getChildren();
26
27
	public void refresh();
28
29
	int getFolderId();
30
31
	public Bundle getBundle();
32
}
(-)src/org/eclipse/pde/internal/runtime/registry/IBundleLibrary.java (-15 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.runtime.registry;
12
13
public interface IBundleLibrary {
14
	public String getLibrary();
15
}
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 17-22 Link Here
17
Eclipse-LazyStart: true
17
Eclipse-LazyStart: true
18
Export-Package: org.eclipse.pde.internal.runtime;x-internal:=true,
18
Export-Package: org.eclipse.pde.internal.runtime;x-internal:=true,
19
 org.eclipse.pde.internal.runtime.registry;x-internal:=true,
19
 org.eclipse.pde.internal.runtime.registry;x-internal:=true,
20
 org.eclipse.pde.internal.runtime.registry.model;x-internal:=true,
20
 org.eclipse.pde.internal.runtime.spy;x-internal:=true,
21
 org.eclipse.pde.internal.runtime.spy;x-internal:=true,
21
 org.eclipse.pde.internal.runtime.spy.dialogs;x-internal:=true,
22
 org.eclipse.pde.internal.runtime.spy.dialogs;x-internal:=true,
22
 org.eclipse.pde.internal.runtime.spy.handlers;x-internal:=true,
23
 org.eclipse.pde.internal.runtime.spy.handlers;x-internal:=true,
(-)src/org/eclipse/pde/internal/runtime/PDERuntimePlugin.java (-5 / +4 lines)
Lines 32-37 Link Here
32
	private ServiceTracker packageAdminTracker;
32
	private ServiceTracker packageAdminTracker;
33
	private ServiceTracker platformAdminTracker;
33
	private ServiceTracker platformAdminTracker;
34
34
35
	public PDERuntimePlugin() {
36
		inst = this;
37
	}
38
35
	private static boolean isBundleAvailable(String bundleID) {
39
	private static boolean isBundleAvailable(String bundleID) {
36
		Bundle bundle = Platform.getBundle(bundleID);
40
		Bundle bundle = Platform.getBundle(bundleID);
37
		return bundle != null && (bundle.getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.RESOLVED)) != 0;
41
		return bundle != null && (bundle.getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.RESOLVED)) != 0;
Lines 86-95 Link Here
86
		return getDefault().getBundle().getSymbolicName();
90
		return getDefault().getBundle().getSymbolicName();
87
	}
91
	}
88
92
89
	public PDERuntimePlugin() {
90
		inst = this;
91
	}
92
93
	private IWorkbenchPage internalGetActivePage() {
93
	private IWorkbenchPage internalGetActivePage() {
94
		return getWorkbench().getActiveWorkbenchWindow().getActivePage();
94
		return getWorkbench().getActiveWorkbenchWindow().getActivePage();
95
	}
95
	}
Lines 142-148 Link Here
142
			platformAdminTracker.close();
142
			platformAdminTracker.close();
143
			platformAdminTracker = null;
143
			platformAdminTracker = null;
144
		}
144
		}
145
		inst = null;
146
	}
145
	}
147
146
148
}
147
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/LocalRegistryBackend.java (+423 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import java.io.IOException;
4
import java.net.URL;
5
import java.util.*;
6
import org.eclipse.core.runtime.*;
7
import org.eclipse.osgi.service.resolver.*;
8
import org.eclipse.osgi.util.ManifestElement;
9
import org.eclipse.pde.internal.runtime.*;
10
import org.osgi.framework.*;
11
import org.osgi.service.packageadmin.PackageAdmin;
12
13
public class LocalRegistryBackend implements IRegistryEventListener, BundleListener, ServiceListener, RegistryBackend {
14
15
	private BackendChangeListener listener;
16
	private RegistryModel model;
17
18
	public void setRegistryModel(RegistryModel model) {
19
		this.model = model;
20
	}
21
22
	public void setRegistryListener(BackendChangeListener listener) {
23
		this.listener = listener;
24
	}
25
26
	/* (non-Javadoc)
27
	 * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#connect()
28
	 */
29
	public void connect() {
30
		PDERuntimePlugin.getDefault().getBundleContext().addBundleListener(this);
31
		Platform.getExtensionRegistry().addListener(this);
32
		PDERuntimePlugin.getDefault().getBundleContext().addServiceListener(this);
33
	}
34
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#disconnect()
37
	 */
38
	public void disconnect() {
39
		Platform.getExtensionRegistry().removeListener(this);
40
		PDERuntimePlugin.getDefault().getBundleContext().removeBundleListener(this);
41
		PDERuntimePlugin.getDefault().getBundleContext().removeServiceListener(this);
42
	}
43
44
	protected static boolean isRegisteredService(org.osgi.framework.Bundle bundle, ServiceReference ref) {
45
		return bundle.equals(ref.getBundle());
46
	}
47
48
	protected static boolean isServiceInUse(org.osgi.framework.Bundle bundle, ServiceReference ref) {
49
		org.osgi.framework.Bundle[] usingBundles = ref.getUsingBundles();
50
		return (usingBundles != null && Arrays.asList(usingBundles).contains(bundle));
51
	}
52
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#start(org.osgi.framework.Bundle)
55
	 */
56
	public void start(Bundle bundle) throws BundleException {
57
		PDERuntimePlugin.getDefault().getBundleContext().getBundle(bundle.getId().longValue()).start();
58
	}
59
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#stop(org.osgi.framework.Bundle)
62
	 */
63
	public void stop(Bundle bundle) throws BundleException {
64
		PDERuntimePlugin.getDefault().getBundleContext().getBundle(bundle.getId().longValue()).stop();
65
	}
66
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#diagnose(org.osgi.framework.Bundle)
69
	 */
70
	public MultiStatus diagnose(Bundle bundle) {
71
		PlatformAdmin plaformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
72
		State state = plaformAdmin.getState(false);
73
74
		BundleDescription desc = state.getBundle(bundle.getId().longValue());
75
76
		PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
77
		VersionConstraint[] unsatisfied = platformAdmin.getStateHelper().getUnsatisfiedConstraints(desc);
78
		ResolverError[] resolverErrors = platformAdmin.getState(false).getResolverErrors(desc);
79
80
		MultiStatus problems = new MultiStatus(PDERuntimePlugin.ID, IStatus.INFO, PDERuntimeMessages.RegistryView_found_problems, null);
81
		for (int i = 0; i < resolverErrors.length; i++) {
82
			if ((resolverErrors[i].getType() & (ResolverError.MISSING_FRAGMENT_HOST | ResolverError.MISSING_GENERIC_CAPABILITY | ResolverError.MISSING_IMPORT_PACKAGE | ResolverError.MISSING_REQUIRE_BUNDLE)) != 0)
83
				continue;
84
			IStatus status = new Status(IStatus.WARNING, PDERuntimePlugin.ID, resolverErrors[i].toString());
85
			problems.add(status);
86
		}
87
88
		for (int i = 0; i < unsatisfied.length; i++) {
89
			IStatus status = new Status(IStatus.WARNING, PDERuntimePlugin.ID, MessageHelper.getResolutionFailureMessage(unsatisfied[i]));
90
			problems.add(status);
91
		}
92
93
		return problems;
94
	}
95
96
	public Map initializeBundles() {
97
		org.osgi.framework.Bundle[] newBundles = PDERuntimePlugin.getDefault().getBundleContext().getBundles();
98
		Map tmp = new HashMap(newBundles.length);
99
		for (int i = 0; i < newBundles.length; i++) {
100
			if (newBundles[i].getHeaders().get(Constants.FRAGMENT_HOST) == null) {
101
				Bundle ba = createBundleAdapter(newBundles[i]);
102
				tmp.put(ba.getId(), ba);
103
			}
104
		}
105
		return tmp;
106
	}
107
108
	public Map initializeExtensionPoints() {
109
		IExtensionPoint[] extPoints = Platform.getExtensionRegistry().getExtensionPoints();
110
		Map tmp = new HashMap(extPoints.length);
111
		for (int i = 0; i < extPoints.length; i++) {
112
			ExtensionPoint epa = createExtensionPointAdapter(extPoints[i]);
113
			tmp.put(epa.getUniqueIdentifier(), epa);
114
		}
115
		return tmp;
116
	}
117
118
	public Map initializeServices() {
119
		Map result = new HashMap();
120
121
		ServiceReference[] references = null;
122
		try {
123
			references = PDERuntimePlugin.getDefault().getBundleContext().getAllServiceReferences(null, null);
124
		} catch (InvalidSyntaxException e) { // nothing
125
		}
126
127
		if (references == null) {
128
			return null;
129
		}
130
131
		for (int i = 0; i < references.length; i++) {
132
			ServiceRegistration service = createServiceReferenceAdapter(references[i]);
133
			result.put(service.getId(), service);
134
		}
135
136
		return result;
137
	}
138
139
	private Bundle createBundleAdapter(org.osgi.framework.Bundle bundle) {
140
		String symbolicName = bundle.getSymbolicName();
141
		String version = (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
142
		int state = bundle.getState();
143
		Long id = new Long(bundle.getBundleId());
144
		String location = createLocation(bundle);
145
		BundlePrerequisite[] imports = (BundlePrerequisite[]) getManifestHeaderArray(bundle, Constants.REQUIRE_BUNDLE);
146
		BundleLibrary[] libraries = (BundleLibrary[]) getManifestHeaderArray(bundle, Constants.BUNDLE_CLASSPATH);
147
		boolean isEnabled = getIsEnabled(bundle);
148
149
		return new Bundle(model, symbolicName, version, state, id, location, imports, libraries, isEnabled);
150
	}
151
152
	private Extension createExtensionAdapter(IExtension extension) {
153
		String namespaceIdentifier = extension.getNamespaceIdentifier();
154
		String label = extension.getLabel();
155
		String extensionPointUniqueIdentifier = extension.getExtensionPointUniqueIdentifier();
156
		Long contributor = getBundleId(extension.getContributor().getName());
157
158
		IConfigurationElement[] elements = extension.getConfigurationElements();
159
		ConfigurationElement[] configurationElements = new ConfigurationElement[elements.length];
160
		for (int i = 0; i < elements.length; i++) {
161
			configurationElements[i] = createConfigurationElement(elements[i]);
162
		}
163
		return new Extension(model, namespaceIdentifier, label, extensionPointUniqueIdentifier, configurationElements, contributor);
164
	}
165
166
	private ConfigurationElement createConfigurationElement(IConfigurationElement config) {
167
		Attribute[] attributes = createConfigurationElementAttributes(config);
168
		String name = createName(config);
169
		return new ConfigurationElement(model, name, attributes);
170
	}
171
172
	private static Long getBundleId(String name) {
173
		BundleDescription descr = PDERuntimePlugin.getDefault().getPlatformAdmin().getState().getBundle(name, null);
174
		return new Long(descr.getBundleId());
175
	}
176
177
	private ExtensionPoint createExtensionPointAdapter(IExtensionPoint extensionPoint) {
178
		String label = extensionPoint.getLabel();
179
		String uniqueIdentifier = extensionPoint.getUniqueIdentifier();
180
		String namespaceIdentifier = extensionPoint.getNamespaceIdentifier();
181
		Long contributor = getBundleId(extensionPoint.getContributor().getName());
182
		Extension[] extensions = createExtensionAdapters(extensionPoint.getExtensions());
183
		ExtensionPoint adapter = new ExtensionPoint(model, label, uniqueIdentifier, namespaceIdentifier, contributor);
184
		adapter.getExtensions().addAll(Arrays.asList(extensions));
185
		return adapter;
186
	}
187
188
	private ServiceRegistration createServiceReferenceAdapter(ServiceReference ref) {
189
		Long id = (Long) ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
190
		String bundle = ref.getBundle().getSymbolicName();
191
		org.osgi.framework.Bundle[] usingBundles = ref.getUsingBundles();
192
		Long[] usingBundlesIds = null;
193
		if (usingBundles != null) {
194
			usingBundlesIds = new Long[usingBundles.length];
195
			for (int i = 0; i < usingBundles.length; i++) {
196
				usingBundlesIds[i] = new Long(usingBundles[i].getBundleId());
197
			}
198
		}
199
		String[] classes = (String[]) ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
200
		return new ServiceRegistration(model, id, bundle, usingBundlesIds, classes);
201
	}
202
203
	private static boolean getIsEnabled(org.osgi.framework.Bundle bundle) {
204
		PlatformAdmin plaformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
205
		State state = plaformAdmin.getState(false);
206
207
		BundleDescription description = state.getBundle(bundle.getBundleId());
208
		return (state.getDisabledInfos(description)).length == 0;
209
	}
210
211
	private static String createLocation(org.osgi.framework.Bundle bundle) {
212
		URL bundleEntry = bundle.getEntry("/"); //$NON-NLS-1$
213
		try {
214
			bundleEntry = FileLocator.resolve(bundleEntry);
215
		} catch (IOException e) { // do nothing
216
		}
217
		IPath path = new Path(bundleEntry.getFile());
218
		String pathString = path.removeTrailingSeparator().toOSString();
219
		if (pathString.startsWith("file:")) //$NON-NLS-1$
220
			pathString = pathString.substring(5);
221
		if (pathString.endsWith("!")) //$NON-NLS-1$
222
			pathString = pathString.substring(0, pathString.length() - 1);
223
		return pathString;
224
	}
225
226
	private Object[] getManifestHeaderArray(org.osgi.framework.Bundle bundle, String headerKey) {
227
		String libraries = (String) bundle.getHeaders().get(headerKey);
228
		try {
229
			ManifestElement[] elements = ManifestElement.parseHeader(headerKey, libraries);
230
			if (elements == null)
231
				return null;
232
			if (headerKey.equals(Constants.BUNDLE_CLASSPATH)) {
233
				BundleLibrary[] array = new BundleLibrary[elements.length];
234
				for (int i = 0; i < elements.length; i++)
235
					array[i] = new BundleLibrary(model, elements[i].getValue());
236
				return array;
237
			} else if (headerKey.equals(Constants.REQUIRE_BUNDLE)) {
238
				BundlePrerequisite[] array = new BundlePrerequisite[elements.length];
239
				for (int i = 0; i < elements.length; i++) {
240
					ManifestElement element = elements[i];
241
					String name = element.getValue();
242
					String version = element.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
243
244
					String visibility = element.getDirective(Constants.VISIBILITY_DIRECTIVE);
245
					boolean isExported = Constants.VISIBILITY_REEXPORT.equals(visibility);
246
					array[i] = new BundlePrerequisite(model, name, version, isExported);
247
				}
248
				return array;
249
			}
250
		} catch (BundleException e) { // do nothing
251
		}
252
		return null;
253
	}
254
255
	private Attribute[] createConfigurationElementAttributes(IConfigurationElement config) {
256
		String[] atts = config.getAttributeNames();
257
258
		Attribute[] catts = new Attribute[atts.length];
259
		for (int i = 0; i < atts.length; i++)
260
			catts[i] = new Attribute(model, atts[i], config.getAttribute(atts[i]));
261
262
		IConfigurationElement[] children = config.getChildren();
263
		Attribute[] result = new Attribute[children.length + catts.length];
264
		for (int i = 0; i < children.length; i++) {
265
			IConfigurationElement child = children[i];
266
			result[i] = createConfigurationElement(child);
267
		}
268
		for (int i = 0; i < catts.length; i++) {
269
			result[children.length + i] = catts[i];
270
		}
271
		return result;
272
	}
273
274
	private static String createName(IConfigurationElement config) {
275
		String label = config.getAttribute("label"); //$NON-NLS-1$
276
		if (label == null)
277
			label = config.getName();
278
279
		if (label == null)
280
			label = config.getAttribute("name"); //$NON-NLS-1$
281
282
		if (label == null && config.getAttribute("id") != null) { //$NON-NLS-1$
283
			String[] labelSplit = config.getAttribute("id").split("\\."); //$NON-NLS-1$ //$NON-NLS-2$
284
			label = labelSplit.length == 0 ? null : labelSplit[labelSplit.length - 1];
285
		}
286
287
		return label;
288
	}
289
290
	private Extension[] createExtensionAdapters(IExtension[] extensions) {
291
		Extension[] extensionAdapters = new Extension[extensions.length];
292
		for (int i = 0; i < extensions.length; i++) {
293
			extensionAdapters[i] = createExtensionAdapter(extensions[i]);
294
		}
295
		return extensionAdapters;
296
	}
297
298
	public void bundleChanged(BundleEvent event) {
299
		org.osgi.framework.Bundle bundle = event.getBundle();
300
		Bundle adapter = createBundleAdapter(bundle);
301
302
		switch (event.getType()) {
303
			case BundleEvent.INSTALLED :
304
				listener.addBundle(adapter);
305
				break;
306
			case BundleEvent.UNINSTALLED :
307
				listener.removeBundle(adapter);
308
				break;
309
			case BundleEvent.UPDATED :
310
				listener.updateBundle(adapter, ModelChangeDelta.UPDATED);
311
				break;
312
			case BundleEvent.RESOLVED :
313
				listener.updateBundle(adapter, ModelChangeDelta.RESOLVED);
314
				break;
315
			case BundleEvent.UNRESOLVED :
316
				listener.updateBundle(adapter, ModelChangeDelta.UNRESOLVED);
317
				break;
318
			case BundleEvent.STARTING :
319
				listener.updateBundle(adapter, ModelChangeDelta.STARTING);
320
				break;
321
			case BundleEvent.STARTED :
322
				listener.updateBundle(adapter, ModelChangeDelta.STARTED);
323
				break;
324
			case BundleEvent.STOPPING :
325
				listener.updateBundle(adapter, ModelChangeDelta.STOPPING);
326
				break;
327
			case BundleEvent.STOPPED :
328
				listener.updateBundle(adapter, ModelChangeDelta.STOPPED);
329
				break;
330
			default :
331
				listener.updateBundle(adapter, ModelChangeDelta.UPDATED);
332
		}
333
	}
334
335
	public void serviceChanged(ServiceEvent event) {
336
		ServiceReference ref = event.getServiceReference();
337
		ServiceRegistration adapter = createServiceReferenceAdapter(ref);
338
339
		switch (event.getType()) {
340
			case ServiceEvent.REGISTERED :
341
				listener.addService(adapter);
342
				break;
343
			case ServiceEvent.UNREGISTERING :
344
				listener.removeService(adapter);
345
				break;
346
			case ServiceEvent.MODIFIED :
347
			default :
348
				listener.updateService(adapter);
349
				break;
350
		}
351
	}
352
353
	private ExtensionPoint[] createExtensionPointAdapters(IExtensionPoint[] extensionPoints) {
354
		ExtensionPoint[] result = new ExtensionPoint[extensionPoints.length];
355
		for (int i = 0; i < extensionPoints.length; i++) {
356
			result[i] = createExtensionPointAdapter(extensionPoints[i]);
357
		}
358
		return result;
359
	}
360
361
	public void added(IExtension[] extensions) {
362
		listener.addExtensions(createExtensionAdapters(extensions));
363
	}
364
365
	public void removed(IExtension[] extensions) {
366
		listener.removeExtensions(createExtensionAdapters(extensions));
367
	}
368
369
	public void added(IExtensionPoint[] extensionPoints) {
370
		listener.addExtensionPoints(createExtensionPointAdapters(extensionPoints));
371
	}
372
373
	public void removed(IExtensionPoint[] extensionPoints) {
374
		listener.removeExtensionPoints(createExtensionPointAdapters(extensionPoints));
375
	}
376
377
	public void setEnabled(Bundle bundle, boolean enabled) {
378
		State state = PDERuntimePlugin.getDefault().getState();
379
		long bundleId = bundle.getId().longValue();
380
		BundleDescription desc = state.getBundle(bundleId);
381
382
		if (enabled) {
383
			DisabledInfo[] infos = state.getDisabledInfos(desc);
384
			for (int i = 0; i < infos.length; i++) {
385
				PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
386
				platformAdmin.removeDisabledInfo(infos[i]);
387
			}
388
		} else {
389
			DisabledInfo info = new DisabledInfo("org.eclipse.pde.ui", "Disabled via PDE", desc); //$NON-NLS-1$ //$NON-NLS-2$
390
			PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
391
			platformAdmin.addDisabledInfo(info);
392
		}
393
394
		org.osgi.framework.Bundle b = PDERuntimePlugin.getDefault().getBundleContext().getBundle(bundleId);
395
		PackageAdmin packageAdmin = PDERuntimePlugin.getDefault().getPackageAdmin();
396
		packageAdmin.refreshPackages(new org.osgi.framework.Bundle[] {b});
397
	}
398
399
	/* (non-Javadoc)
400
	 * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#setEnabled(org.osgi.framework.Bundle, boolean)
401
	 */
402
	public void setEnabled(org.osgi.framework.Bundle bundle, boolean enabled) {
403
		PlatformAdmin plaformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
404
		State state = plaformAdmin.getState(false);
405
406
		BundleDescription desc = state.getBundle(bundle.getBundleId());
407
408
		if (enabled) {
409
			DisabledInfo[] infos = state.getDisabledInfos(desc);
410
			for (int i = 0; i < infos.length; i++) {
411
				PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
412
				platformAdmin.removeDisabledInfo(infos[i]);
413
			}
414
		} else {
415
			DisabledInfo info = new DisabledInfo("org.eclipse.pde.ui", "Disabled via PDE", desc); //$NON-NLS-1$ //$NON-NLS-2$
416
			PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
417
			platformAdmin.addDisabledInfo(info);
418
		}
419
420
		PackageAdmin packageAdmin = PDERuntimePlugin.getDefault().getPackageAdmin();
421
		packageAdmin.refreshPackages(new org.osgi.framework.Bundle[] {bundle});
422
	}
423
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/Extension.java (+66 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public class Extension extends ModelObject {
4
5
	private String namespaceIdentifier;
6
	private String label;
7
	private String extensionPointUniqueIdentifier;
8
	private ConfigurationElement[] configurationElements;
9
	private Long contributor;
10
11
	public Extension(RegistryModel model, String namespaceIdentifier, String label, String extensionPointUniqueIdentifier, ConfigurationElement[] cfg, Long contributor) {
12
		super(model);
13
		this.namespaceIdentifier = namespaceIdentifier;
14
		this.label = label;
15
		this.extensionPointUniqueIdentifier = extensionPointUniqueIdentifier;
16
		this.configurationElements = cfg;
17
		this.contributor = contributor;
18
	}
19
20
	public ConfigurationElement[] getConfigurationElements() {
21
		return configurationElements;
22
	}
23
24
	public String getExtensionPointUniqueIdentifier() {
25
		return extensionPointUniqueIdentifier;
26
	}
27
28
	public String getLabel() {
29
		return label;
30
	}
31
32
	public String getNamespaceIdentifier() {
33
		return namespaceIdentifier;
34
	}
35
36
	public Long getContributorId() {
37
		return contributor;
38
	}
39
40
	public boolean equals(Object obj) {
41
		if (obj instanceof Extension) {
42
			Extension ext = (Extension) obj;
43
			return namespaceIdentifier.endsWith(ext.namespaceIdentifier) && label.equals(ext.label) && extensionPointUniqueIdentifier.equals(ext.extensionPointUniqueIdentifier) && contributor.equals(ext.contributor);
44
		}
45
46
		return false;
47
	}
48
49
	public int hashCode() {
50
		final int prime = 31;
51
		int result = 1;
52
		result = prime * result + ((contributor == null) ? 0 : contributor.hashCode());
53
		result = prime * result + ((extensionPointUniqueIdentifier == null) ? 0 : extensionPointUniqueIdentifier.hashCode());
54
		result = prime * result + ((label == null) ? 0 : label.hashCode());
55
		result = prime * result + ((namespaceIdentifier == null) ? 0 : namespaceIdentifier.hashCode());
56
		return result;
57
	}
58
59
	public ExtensionPoint getExtensionPoint() {
60
		return getModel().getExtensionPoint(extensionPointUniqueIdentifier);
61
	}
62
63
	public Bundle getContributor() {
64
		return getModel().getBundle(contributor);
65
	}
66
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/ExtensionPoint.java (+53 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
6
public class ExtensionPoint extends ModelObject {
7
8
	private String label;
9
	private String uniqueIdentifier;
10
	private String namespaceIdentifier;
11
	private Long contributor;
12
	private List extensions = new ArrayList();
13
14
	public ExtensionPoint(RegistryModel model, String label, String uniqueIdentifier, String namespaceIdentifier, Long contributor) {
15
		super(model);
16
		this.label = label;
17
		this.uniqueIdentifier = uniqueIdentifier;
18
		this.namespaceIdentifier = namespaceIdentifier;
19
		this.contributor = contributor;
20
	}
21
22
	public List getExtensions() {
23
		return extensions;
24
	}
25
26
	public String getLabel() {
27
		return label;
28
	}
29
30
	public String getUniqueIdentifier() {
31
		return uniqueIdentifier;
32
	}
33
34
	public String getNamespaceIdentifier() {
35
		return namespaceIdentifier;
36
	}
37
38
	public Long getContributorId() {
39
		return contributor;
40
	}
41
42
	public Bundle getContributor() {
43
		return getModel().getBundle(contributor);
44
	}
45
46
	public boolean equals(Object obj) {
47
		return (obj instanceof ExtensionPoint) && (uniqueIdentifier.equals(((ExtensionPoint) obj).uniqueIdentifier));
48
	}
49
50
	public int hashCode() {
51
		return uniqueIdentifier.hashCode();
52
	}
53
}
(-)src/org/eclipse/pde/internal/runtime/registry/RegistryBrowserModelChangeListener.java (+88 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry;
2
3
import org.eclipse.pde.internal.runtime.registry.model.*;
4
5
public class RegistryBrowserModelChangeListener implements ModelChangeListener {
6
7
	private RegistryBrowser fRegistryBrowser;
8
9
	public RegistryBrowserModelChangeListener(RegistryBrowser registryBrowser) {
10
		fRegistryBrowser = registryBrowser;
11
	}
12
13
	public void modelChanged(final ModelChangeDelta[] delta) {
14
		fRegistryBrowser.getSite().getWorkbenchWindow().getWorkbench().getDisplay().asyncExec(new Runnable() {
15
			public void run() {
16
				update(delta);
17
			}
18
		});
19
	}
20
21
	private boolean topLevelElement(Object object) {
22
		return fRegistryBrowser.showExtensionsOnly() ? object instanceof ExtensionPoint : object instanceof Bundle;
23
	}
24
25
	private Object getTopLevelElement(Object object) {
26
		if (!fRegistryBrowser.showExtensionsOnly()) { // show bundles
27
			if (object instanceof Bundle) {
28
				return object;
29
			} else if (object instanceof ExtensionPoint) {
30
				ExtensionPoint ext = (ExtensionPoint) object;
31
				return ext.getContributor();
32
			} else if (object instanceof Extension) {
33
				Extension ext = (Extension) object;
34
				return ext.getContributor();
35
			} else if (object instanceof ServiceRegistration) {
36
				ServiceRegistration reg = (ServiceRegistration) object;
37
				//return reg.getBundle(); // TODO FIXME
38
			}
39
		} else { // show only extensions
40
			if (object instanceof ExtensionPoint) {
41
				return object;
42
			} else if (object instanceof Extension) {
43
				Extension ext = (Extension) object;
44
				return ext.getExtensionPoint();
45
			}
46
		}
47
48
		return null;
49
	}
50
51
	protected void update(ModelChangeDelta[] deltas) {
52
		for (int i = 0; i < deltas.length; i++) {
53
			ModelObject object = deltas[i].getModelObject();
54
55
			switch (deltas[i].getFlag()) {
56
				case ModelChangeDelta.ADDED :
57
					if (topLevelElement(object)) {
58
						fRegistryBrowser.add(object);
59
					} else {
60
						Object topLevelElement = getTopLevelElement(object);
61
						fRegistryBrowser.refresh(topLevelElement);
62
					}
63
					break;
64
				case ModelChangeDelta.REMOVED :
65
					if (topLevelElement(object)) {
66
						fRegistryBrowser.remove(object);
67
					} else {
68
						Object topLevelElement = getTopLevelElement(object);
69
						fRegistryBrowser.refresh(topLevelElement);
70
					}
71
					break;
72
				case ModelChangeDelta.STARTED :
73
				case ModelChangeDelta.STOPPED :
74
				case ModelChangeDelta.RESOLVED :
75
				case ModelChangeDelta.UNRESOLVED :
76
				case ModelChangeDelta.UPDATED :
77
					if (topLevelElement(object)) {
78
						fRegistryBrowser.refresh(object);
79
					} else {
80
						Object topLevelElement = getTopLevelElement(object);
81
						fRegistryBrowser.refresh(topLevelElement);
82
					}
83
					break;
84
			}
85
		}
86
	}
87
88
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/Folder.java (+68 lines)
Added Link Here
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.runtime.registry.model;
12
13
public class Folder {
14
15
	public static final int F_EXTENSIONS = 1;
16
	public static final int F_EXTENSION_POINTS = 2;
17
	public static final int F_IMPORTS = 3;
18
	public static final int F_LIBRARIES = 4;
19
	public static final int F_REGISTERED_SERVICES = 5;
20
	public static final int F_SERVICES_IN_USE = 6;
21
22
	private int id;
23
	private Bundle parent;
24
25
	public Folder(int id, Bundle parent) {
26
		this.id = id;
27
		this.parent = parent;
28
	}
29
30
	public int getId() {
31
		return id;
32
	}
33
34
	public ModelObject getParent() {
35
		return parent;
36
	}
37
38
	public ModelObject[] getChildren() {
39
		switch (id) {
40
			case F_EXTENSION_POINTS :
41
				return parent.getExtensionPoints();
42
			case F_EXTENSIONS :
43
				return parent.getExtensions();
44
			case F_IMPORTS :
45
				return parent.getImports();
46
			case F_LIBRARIES :
47
				return parent.getLibraries();
48
			case F_REGISTERED_SERVICES :
49
				return parent.getRegisteredServices();
50
			case F_SERVICES_IN_USE :
51
				return parent.getServicesInUse();
52
		}
53
54
		return null;
55
	}
56
57
	public int hashCode() {
58
		final int prime = 31;
59
		int result = 1;
60
		result = prime * result + id;
61
		result = prime * result + ((parent == null) ? 0 : parent.hashCode());
62
		return result;
63
	}
64
65
	public boolean equals(Object obj) {
66
		return ((obj instanceof Folder) && (((Folder) obj).id == id) && (((Folder) obj).parent.equals(parent)));
67
	}
68
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/BundlePrerequisite.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.runtime.registry.model;
12
13
public class BundlePrerequisite extends ModelObject {
14
15
	private boolean isExported;
16
	private String name;
17
	private String version;
18
19
	public BundlePrerequisite(RegistryModel model, String name, String version, boolean isExported) {
20
		super(model);
21
		this.name = name;
22
		this.version = version;
23
		this.isExported = isExported;
24
	}
25
26
	public boolean isExported() {
27
		return isExported;
28
	}
29
30
	public String getName() {
31
		if (version != null) {
32
			if (Character.isDigit(version.charAt(0)))
33
				version = '(' + version + ')';
34
			return name + ' ' + version;
35
		}
36
37
		return name;
38
	}
39
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/ModelChangeDelta.java (+34 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
/**
4
 * 
5
 * Delta model objects are of type IBundle, IService, IExtension, IExtensionPoint
6
 */
7
public class ModelChangeDelta {
8
9
	public static final int ADDED = 0;
10
	public static final int UPDATED = 1;
11
	public static final int REMOVED = 2;
12
	public static final int STARTING = 3;
13
	public static final int STARTED = 4;
14
	public static final int STOPPING = 5;
15
	public static final int STOPPED = 6;
16
	public static final int RESOLVED = 7;
17
	public static final int UNRESOLVED = 8;
18
19
	private ModelObject fObject;
20
	private int fFlag;
21
22
	public ModelChangeDelta(ModelObject object, int flag) {
23
		fObject = object;
24
		fFlag = flag;
25
	}
26
27
	public ModelObject getModelObject() {
28
		return fObject;
29
	}
30
31
	public int getFlag() {
32
		return fFlag;
33
	}
34
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/ModelObject.java (+14 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public abstract class ModelObject {
4
5
	private RegistryModel model;
6
7
	public ModelObject(RegistryModel model) {
8
		this.model = model;
9
	}
10
11
	public RegistryModel getModel() {
12
		return model;
13
	}
14
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/BackendChangeListener.java (+29 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
/**
4
 * Notifies on any changes coming from backend. Usually RegistryModel is only interested in receiving
5
 * news about that.
6
 *
7
 */
8
public interface BackendChangeListener {
9
10
	void addBundle(Bundle adapter);
11
12
	void removeBundle(Bundle adapter);
13
14
	void updateBundle(Bundle adapter, int updated);
15
16
	void addService(ServiceRegistration adapter);
17
18
	void removeService(ServiceRegistration adapter);
19
20
	void updateService(ServiceRegistration adapter);
21
22
	void addExtensions(Extension[] createExtensionAdapters);
23
24
	void removeExtensions(Extension[] createExtensionAdapters);
25
26
	void addExtensionPoints(ExtensionPoint[] createExtensionPointAdapters);
27
28
	void removeExtensionPoints(ExtensionPoint[] createExtensionPointAdapters);
29
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/RegistryBackend.java (+43 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import java.util.Map;
4
import org.eclipse.core.runtime.MultiStatus;
5
import org.osgi.framework.BundleException;
6
7
public interface RegistryBackend {
8
9
	public void connect();
10
11
	public void disconnect();
12
13
	public void setEnabled(Bundle bundle, boolean enabled);
14
15
	public void start(Bundle bundle) throws BundleException;
16
17
	public void stop(Bundle bundle) throws BundleException;
18
19
	public MultiStatus diagnose(Bundle bundle);
20
21
	public Map initializeBundles();
22
23
	public Map initializeExtensionPoints();
24
25
	public void setRegistryListener(BackendChangeListener listener);
26
27
	public void setRegistryModel(RegistryModel listener);
28
29
	public Map initializeServices();
30
31
}
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
/**
4
 * Event provides a list of objects that have changed.
5
 * Possible objects on the list are IBundle, IService, IExtension, IExtensionPoint.
6
 * This is temporary solution and is subject to future changes.
7
 * 
8
 */
9
public interface ModelChangeListener {
10
11
	void modelChanged(ModelChangeDelta[] deltas);
12
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/Attribute.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.runtime.registry.model;
12
13
public class Attribute extends ModelObject {
14
	public static final String F_LOCATION = "Location";
15
16
	private String name;
17
	private String value;
18
19
	public Attribute(RegistryModel model, String name, String value) {
20
		super(model);
21
		this.name = name;
22
		this.value = value;
23
	}
24
25
	public String getValue() {
26
		return value;
27
	}
28
29
	public String getName() {
30
		return name;
31
	}
32
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/ConfigurationElement.java (+15 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public class ConfigurationElement extends Attribute {
4
5
	private Attribute[] elements;
6
7
	public ConfigurationElement(RegistryModel model, String name, Attribute[] attributes) {
8
		super(model, name, null);
9
		elements = attributes;
10
	}
11
12
	public Attribute[] getElements() {
13
		return elements;
14
	}
15
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/ServiceRegistration.java (+41 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public class ServiceRegistration extends ModelObject {
4
5
	private Long id;
6
	private String bundle;
7
	private Long[] usingBundles;
8
	private String[] classes;
9
10
	public ServiceRegistration(RegistryModel model, Long id, String bundle, Long[] usingBundles, String[] classes) {
11
		super(model);
12
		this.id = id;
13
		this.bundle = bundle;
14
		this.usingBundles = usingBundles;
15
		this.classes = classes;
16
	}
17
18
	public Long getId() {
19
		return id;
20
	}
21
22
	public String[] getClasses() {
23
		return classes;
24
	}
25
26
	public String getBundle() {
27
		return bundle;
28
	}
29
30
	public Long[] getUsingBundles() {
31
		return usingBundles;
32
	}
33
34
	public boolean equals(Object obj) {
35
		return (obj instanceof ServiceRegistration) && (id.equals(((ServiceRegistration) obj).id));
36
	}
37
38
	public int hashCode() {
39
		return id.intValue();
40
	}
41
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/RegistryModelFactory.java (+22 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import java.net.URI;
4
5
/**
6
 * Produces RegistryModels for URLs. Valid URLs:
7
 * local
8
 * target
9
 * remote://host:port
10
 *
11
 */
12
public class RegistryModelFactory {
13
14
	/**
15
	 * 
16
	 * @param codename
17
	 * @return never returns null
18
	 */
19
	public static RegistryModel getRegistryModel(URI codename) {
20
		return new RegistryModel(new LocalRegistryBackend());
21
	}
22
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/BundleLibrary.java (+25 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.runtime.registry.model;
12
13
public class BundleLibrary extends ModelObject {
14
15
	private String library;
16
17
	public BundleLibrary(RegistryModel model, String library) {
18
		super(model);
19
		this.library = library;
20
	}
21
22
	public String getLibrary() {
23
		return library;
24
	}
25
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/RegistryModel.java (+194 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import java.util.*;
4
5
/**
6
 * Model entry point for Eclipse runtime. Provides information about runtime bundles, services and extension points.
7
 *
8
 */
9
public class RegistryModel {
10
11
	private BackendChangeListener backendListener = new BackendChangeListener() {
12
		public void addBundle(Bundle adapter) {
13
			ModelChangeDelta delta = new ModelChangeDelta(adapter, ModelChangeDelta.ADDED);
14
15
			bundles.put(adapter.getId(), adapter);
16
17
			fireModelChangeEvent(new ModelChangeDelta[] {delta});
18
		}
19
20
		public void removeBundle(Bundle adapter) {
21
			ModelChangeDelta delta = new ModelChangeDelta(adapter, ModelChangeDelta.REMOVED);
22
23
			bundles.remove(adapter.getId());
24
25
			fireModelChangeEvent(new ModelChangeDelta[] {delta});
26
		}
27
28
		public void updateBundle(Bundle adapter, int updated) {
29
			ModelChangeDelta delta = new ModelChangeDelta(adapter, updated);
30
31
			bundles.put(adapter.getId(), adapter); // replace old with new one
32
33
			fireModelChangeEvent(new ModelChangeDelta[] {delta});
34
		}
35
36
		public void addService(ServiceRegistration adapter) {
37
			services.put(adapter.getId(), adapter);
38
39
			ModelChangeDelta delta = new ModelChangeDelta(adapter, ModelChangeDelta.ADDED);
40
41
			fireModelChangeEvent(new ModelChangeDelta[] {delta});
42
		}
43
44
		public void removeService(ServiceRegistration adapter) {
45
			services.remove(adapter.getId());
46
47
			ModelChangeDelta delta = new ModelChangeDelta(adapter, ModelChangeDelta.REMOVED);
48
49
			fireModelChangeEvent(new ModelChangeDelta[] {delta});
50
		}
51
52
		public void updateService(ServiceRegistration adapter) {
53
			services.put(adapter.getId(), adapter);
54
55
			ModelChangeDelta delta = new ModelChangeDelta(adapter, ModelChangeDelta.UPDATED);
56
57
			fireModelChangeEvent(new ModelChangeDelta[] {delta});
58
		}
59
60
		public void addExtensions(Extension[] extensionAdapters) {
61
			for (int i = 0; i < extensionAdapters.length; i++) {
62
				String id = extensionAdapters[i].getExtensionPointUniqueIdentifier();
63
				ExtensionPoint extPoint = (ExtensionPoint) extensionPoints.get(id);
64
				extPoint.getExtensions().add(extensionAdapters[i]);
65
			}
66
67
			ModelChangeDelta[] delta = new ModelChangeDelta[extensionAdapters.length];
68
			for (int i = 0; i < delta.length; i++) {
69
				delta[i] = new ModelChangeDelta(extensionAdapters[i], ModelChangeDelta.ADDED);
70
			}
71
			fireModelChangeEvent(delta);
72
		}
73
74
		public void removeExtensions(Extension[] extensionAdapters) {
75
			for (int i = 0; i < extensionAdapters.length; i++) {
76
				String id = extensionAdapters[i].getExtensionPointUniqueIdentifier();
77
				ExtensionPoint extPoint = (ExtensionPoint) extensionPoints.get(id);
78
				extPoint.getExtensions().remove(extensionAdapters[i]);
79
			}
80
81
			ModelChangeDelta[] delta = new ModelChangeDelta[extensionAdapters.length];
82
			for (int i = 0; i < delta.length; i++) {
83
				delta[i] = new ModelChangeDelta(extensionAdapters[i], ModelChangeDelta.REMOVED);
84
			}
85
			fireModelChangeEvent(delta);
86
		}
87
88
		public void addExtensionPoints(ExtensionPoint[] extensionPointAdapters) {
89
			for (int i = 0; i < extensionPointAdapters.length; i++) {
90
				extensionPoints.put(extensionPointAdapters[i].getUniqueIdentifier(), extensionPointAdapters[i]);
91
			}
92
93
			ModelChangeDelta[] delta = new ModelChangeDelta[extensionPointAdapters.length];
94
			for (int i = 0; i < delta.length; i++) {
95
				delta[i] = new ModelChangeDelta(extensionPointAdapters[i], ModelChangeDelta.ADDED);
96
			}
97
			fireModelChangeEvent(delta);
98
		}
99
100
		public void removeExtensionPoints(ExtensionPoint[] extensionPointAdapters) {
101
			for (int i = 0; i < extensionPointAdapters.length; i++) {
102
				extensionPoints.remove(extensionPointAdapters[i].getUniqueIdentifier());
103
			}
104
105
			ModelChangeDelta[] delta = new ModelChangeDelta[extensionPointAdapters.length];
106
			for (int i = 0; i < delta.length; i++) {
107
				delta[i] = new ModelChangeDelta(extensionPointAdapters[i], ModelChangeDelta.REMOVED);
108
			}
109
			fireModelChangeEvent(delta);
110
		}
111
	};
112
113
	private List listeners = new ArrayList();
114
	private Map bundles;
115
	private Map services;
116
	private Map extensionPoints;
117
	protected RegistryBackend backend;
118
119
	public RegistryModel(RegistryBackend backend) {
120
		this.backend = backend;
121
		backend.setRegistryListener(backendListener);
122
		backend.setRegistryModel(this);
123
	}
124
125
	public void connect() {
126
		backend.connect();
127
	}
128
129
	public void disconnect() {
130
		backend.disconnect();
131
	}
132
133
	public Bundle[] getBundles() {
134
		if (bundles == null) {
135
			bundles = backend.initializeBundles();
136
		}
137
138
		return (Bundle[]) bundles.values().toArray(new Bundle[bundles.values().size()]);
139
	}
140
141
	public ExtensionPoint[] getExtensionPoints() {
142
		if (extensionPoints == null) {
143
			extensionPoints = backend.initializeExtensionPoints();
144
		}
145
146
		return (ExtensionPoint[]) extensionPoints.values().toArray(new ExtensionPoint[extensionPoints.values().size()]);
147
	}
148
149
	public ServiceRegistration[] getServices() {
150
		if (services == null) {
151
			services = backend.initializeServices();
152
		}
153
154
		return (ServiceRegistration[]) services.values().toArray(new ServiceRegistration[services.values().size()]);
155
	}
156
157
	public void addModelChangeListener(ModelChangeListener listener) {
158
		listeners.add(listener);
159
	}
160
161
	public void removeModelChangeListener(ModelChangeListener listener) {
162
		listeners.remove(listener);
163
	}
164
165
	/**
166
	 * For received domain types: Bundle, IExtension, IExtensionPoint, ServiceReference,
167
	 * generates delta with model types: IBundle, IExtensionAdapter, IExtensionPointAdapter, IService
168
	 *  
169
	 * @param objects
170
	 */
171
	protected void fireModelChangeEvent(ModelChangeDelta[] delta) {
172
		for (Iterator i = listeners.iterator(); i.hasNext();) {
173
			ModelChangeListener listener = (ModelChangeListener) i.next();
174
			listener.modelChanged(delta);
175
		}
176
	}
177
178
	public Bundle getBundle(Long id) {
179
		return (Bundle) bundles.get(id);
180
	}
181
182
	public ExtensionPoint getExtensionPoint(String extensionPointUniqueIdentifier) {
183
		return (ExtensionPoint) extensionPoints.get(extensionPointUniqueIdentifier);
184
	}
185
186
	/*	void setEnabled(Bundle bundle, boolean enabled);
187
188
		void start(Bundle bundle) throws BundleException; // XXX Create custom Exception
189
190
		void stop(Bundle bundle) throws BundleException;
191
192
		MultiStatus diagnose(Bundle bundle);*/
193
194
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/Bundle.java (+142 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import java.util.*;
4
import org.eclipse.core.runtime.MultiStatus;
5
import org.osgi.framework.BundleException;
6
7
public class Bundle extends ModelObject {
8
9
	public static final int ACTIVE = org.osgi.framework.Bundle.ACTIVE;
10
	public static final int UNINSTALLED = org.osgi.framework.Bundle.UNINSTALLED;
11
	public static final int INSTALLED = org.osgi.framework.Bundle.INSTALLED;
12
13
	private String symbolicName;
14
	private String location;
15
	private boolean isEnabled;
16
	private BundlePrerequisite[] imports;
17
	private String version;
18
	private int state;
19
	private Long id;
20
	private BundleLibrary[] libraries;
21
22
	public Bundle(RegistryModel model, String symbolicName, String version, int state, Long id, String location, BundlePrerequisite[] prereq, BundleLibrary[] libs, boolean isEnabled) {
23
		super(model);
24
		this.symbolicName = symbolicName;
25
		this.version = version;
26
		this.state = state;
27
		this.id = id;
28
		this.location = location;
29
		this.imports = prereq;
30
		this.libraries = libs;
31
		this.isEnabled = isEnabled;
32
	}
33
34
	public String getSymbolicName() {
35
		return symbolicName;
36
	}
37
38
	public boolean isEnabled() {
39
		return isEnabled;
40
	}
41
42
	public BundlePrerequisite[] getImports() {
43
		return imports;
44
	}
45
46
	public BundleLibrary[] getLibraries() {
47
		return libraries;
48
	}
49
50
	public String getLocation() {
51
		return location;
52
	}
53
54
	public String getVersion() {
55
		return version;
56
	}
57
58
	public int getState() {
59
		return state;
60
	}
61
62
	public Long getId() {
63
		return id;
64
	}
65
66
	public void start() throws BundleException {
67
		getModel().backend.start(this);
68
	}
69
70
	public void stop() throws BundleException {
71
		getModel().backend.stop(this);
72
	}
73
74
	public void setEnabled(boolean enabled) {
75
		getModel().backend.setEnabled(this, enabled);
76
	}
77
78
	public MultiStatus diagnose() {
79
		return getModel().backend.diagnose(this);
80
	}
81
82
	public ExtensionPoint[] getExtensionPoints() {
83
		ExtensionPoint[] extPoints = getModel().getExtensionPoints();
84
		List result = new ArrayList();
85
86
		for (int i = 0; i < extPoints.length; i++) {
87
			if (id.equals(extPoints[i].getContributorId()))
88
				result.add(extPoints[i]);
89
		}
90
		return (ExtensionPoint[]) result.toArray(new ExtensionPoint[result.size()]);
91
	}
92
93
	public Extension[] getExtensions() {
94
		ExtensionPoint[] extPoints = getModel().getExtensionPoints();
95
		List result = new ArrayList();
96
97
		for (int i = 0; i < extPoints.length; i++) {
98
			for (Iterator it = extPoints[i].getExtensions().iterator(); it.hasNext();) {
99
				Extension a = (Extension) it.next();
100
				if (id.equals(a.getContributorId()))
101
					result.add(a);
102
			}
103
104
		}
105
		return (Extension[]) result.toArray(new Extension[result.size()]);
106
	}
107
108
	public ServiceRegistration[] getRegisteredServices() {
109
		ServiceRegistration[] services = getModel().getServices();
110
		List result = new ArrayList();
111
112
		for (int i = 0; i < services.length; i++) {
113
			if (symbolicName.equals(services[i].getBundle()))
114
				result.add(services[i]);
115
		}
116
		return (ServiceRegistration[]) result.toArray(new ServiceRegistration[result.size()]);
117
	}
118
119
	public ServiceRegistration[] getServicesInUse() {
120
		ServiceRegistration[] services = getModel().getServices();
121
		List result = new ArrayList();
122
123
		for (int i = 0; i < services.length; i++) {
124
			Long[] usingBundles = services[i].getUsingBundles();
125
			if (usingBundles != null) {
126
				for (int j = usingBundles.length; j < usingBundles.length; j++)
127
					if (id.equals(usingBundles[j]))
128
						result.add(services[i]);
129
			}
130
		}
131
		return (ServiceRegistration[]) result.toArray(new ServiceRegistration[result.size()]);
132
	}
133
134
	public boolean equals(Object obj) {
135
		return (obj instanceof Bundle) && (id.equals(((Bundle) obj).id));
136
	}
137
138
	public int hashCode() {
139
		return id.intValue();
140
	}
141
142
}

Return to bug 243441