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 (-206 / +26 lines)
Lines 10-117 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;
17
import org.eclipse.pde.internal.runtime.registry.model.impl.generic.*;
19
import org.osgi.framework.*;
18
import org.eclipse.pde.internal.runtime.registry.model.impl.local.ExtensionPointAdapter;
20
19
21
public class RegistryBrowserContentProvider implements ITreeContentProvider {
20
public class RegistryBrowserContentProvider implements ITreeContentProvider {
22
	private Hashtable fExtensionPointMap = new Hashtable();
23
	public boolean isInExtensionSet;
21
	public boolean isInExtensionSet;
24
22
25
	static class BundleFolder implements IBundleFolder {
26
		private int id;
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
	}
114
115
	public void dispose() { // nothing to dispose
23
	public void dispose() { // nothing to dispose
116
	}
24
	}
117
25
Lines 123-147 Link Here
123
		if (element == null)
31
		if (element == null)
124
			return null;
32
			return null;
125
33
126
		if (element instanceof ExtensionAdapter)
34
		if (element instanceof IExtensionAdapter)
127
			return ((ExtensionAdapter) element).getChildren();
35
			return ((IExtensionAdapter) element).getConfigurationElements();
128
36
129
		isInExtensionSet = false;
37
		isInExtensionSet = false;
130
		if (element instanceof ExtensionPointAdapter)
38
		if (element instanceof ExtensionPointAdapter)
131
			return ((ExtensionPointAdapter) element).getChildren();
39
			return ((ExtensionPointAdapter) element).getExtensions();
132
40
133
		if (element instanceof ConfigurationElementAdapter)
41
		if (element instanceof IElement)
134
			return ((ConfigurationElementAdapter) element).getChildren();
42
			return ((IElement) element).getElements();
135
43
136
		if (element instanceof PluginAdapter) {
44
		if (element instanceof IBundle) {
137
			PluginAdapter bundle = (PluginAdapter) element;
45
			IBundle bundle = (IBundle) element;
138
46
139
			Object[] folders = bundle.getChildren();
47
			Object[] folders = new Object[7];
48
			folders[0] = new ConfigurationAttribute(IAttribute.F_LOCATION, bundle.getLocation());
49
			folders[1] = new BundleFolder(bundle, IBundleFolder.F_IMPORTS);
50
			folders[2] = new BundleFolder(bundle, IBundleFolder.F_LIBRARIES);
51
			folders[3] = new BundleFolder(bundle, IBundleFolder.F_EXTENSION_POINTS);
52
			folders[4] = new BundleFolder(bundle, IBundleFolder.F_EXTENSIONS);
53
			folders[5] = new BundleFolder(bundle, IBundleFolder.F_REGISTERED_SERVICES);
54
			folders[6] = new BundleFolder(bundle, IBundleFolder.F_SERVICES_IN_USE);
140
55
141
			// filter out empty folders
56
			// filter out empty folders
142
			ArrayList folderList = new ArrayList();
57
			ArrayList folderList = new ArrayList();
143
			for (int i = 0; i < folders.length; i++) {
58
			for (int i = 1; i < folders.length; i++) {
144
				if (folders[i] != null && ((IBundleFolder) folders[i]).getChildren() != null || ((IBundleFolder) folders[i]).getFolderId() == IBundleFolder.F_LOCATION)
59
				if (((IBundleFolder) folders[i]).getChildren() != null)
145
					folderList.add(folders[i]);
60
					folderList.add(folders[i]);
146
			}
61
			}
147
			folders = folderList.toArray(new Object[folderList.size()]);
62
			folders = folderList.toArray(new Object[folderList.size()]);
Lines 157-249 Link Here
157
			isInExtensionSet = folder.getFolderId() == IBundleFolder.F_EXTENSIONS;
72
			isInExtensionSet = folder.getFolderId() == IBundleFolder.F_EXTENSIONS;
158
			return ((IBundleFolder) element).getChildren();
73
			return ((IBundleFolder) element).getChildren();
159
		}
74
		}
160
		if (element instanceof IConfigurationElement) {
75
		if (element instanceof IElement) {
161
			return ((IConfigurationElement) element).getChildren();
76
			return ((IElement) element).getElements();
162
		}
77
		}
163
		if (element instanceof Object[]) {
78
		if (element instanceof Object[]) {
164
			return (Object[]) element;
79
			return (Object[]) element;
165
		}
80
		}
166
		if (element instanceof IExtensionPoint) {
81
		if (element instanceof IExtensionPointAdapter) {
167
			IExtensionPoint extensionPoint = (IExtensionPoint) element;
82
			IExtensionPointAdapter extensionPoint = (IExtensionPointAdapter) element;
168
			String id = extensionPoint.getUniqueIdentifier();
83
			String id = extensionPoint.getUniqueIdentifier();
169
84
			return extensionPoint.getExtensions();
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
179
					fExtensionPointMap.put(id, children);
180
				}
181
			}
182
183
			return children;
184
		}
85
		}
185
		return null;
86
		return null;
186
	}
87
	}
187
88
188
	protected static Object[] getFolderChildren(Bundle bundle, int id) {
189
		Object[] array = null;
190
		String bundleId = bundle.getSymbolicName();
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
		}
216
		return result;
217
	}
218
219
	protected static Object[] getServices(Bundle bundle, int type) {
220
		Set result = new HashSet();
221
222
		try {
223
			ServiceReference[] references = PDERuntimePlugin.getDefault().getBundleContext().getAllServiceReferences(null, null);
224
225
			for (int i = 0; i < references.length; i++) {
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
238
		} catch (InvalidSyntaxException e) { // nothing
239
		}
240
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) {
89
	public Object getParent(Object element) {
248
		return null;
90
		return null;
249
	}
91
	}
Lines 256-281 Link Here
256
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // do nothing
98
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // do nothing
257
	}
99
	}
258
100
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
}
101
}
(-)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 (-98 / +56 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.*;
26
import org.eclipse.pde.internal.runtime.registry.model.impl.generic.PluginObjectAdapter;
27
import org.eclipse.pde.internal.runtime.registry.model.impl.local.RegistryBrowserListener;
24
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.custom.BusyIndicator;
29
import org.eclipse.swt.custom.BusyIndicator;
26
import org.eclipse.swt.dnd.*;
30
import org.eclipse.swt.dnd.*;
Lines 33-39 Link Here
33
import org.eclipse.ui.dialogs.PatternFilter;
37
import org.eclipse.ui.dialogs.PatternFilter;
34
import org.eclipse.ui.part.DrillDownAdapter;
38
import org.eclipse.ui.part.DrillDownAdapter;
35
import org.eclipse.ui.part.ViewPart;
39
import org.eclipse.ui.part.ViewPart;
36
import org.osgi.framework.*;
40
import org.osgi.framework.Bundle;
41
import org.osgi.framework.BundleException;
37
import org.osgi.service.packageadmin.PackageAdmin;
42
import org.osgi.service.packageadmin.PackageAdmin;
38
43
39
public class RegistryBrowser extends ViewPart {
44
public class RegistryBrowser extends ViewPart {
Lines 49-54 Link Here
49
	private IMemento fMemento;
54
	private IMemento fMemento;
50
	private int fTotalItems = 0;
55
	private int fTotalItems = 0;
51
56
57
	private IRegistryModel model;
58
52
	// menus and action items
59
	// menus and action items
53
	private Action fRefreshAction;
60
	private Action fRefreshAction;
54
	private Action fShowPluginsAction;
61
	private Action fShowPluginsAction;
Lines 70-99 Link Here
70
	private DrillDownAdapter fDrillDownAdapter;
77
	private DrillDownAdapter fDrillDownAdapter;
71
	private ViewerFilter fActiveFilter = new ViewerFilter() {
78
	private ViewerFilter fActiveFilter = new ViewerFilter() {
72
		public boolean select(Viewer viewer, Object parentElement, Object element) {
79
		public boolean select(Viewer viewer, Object parentElement, Object element) {
73
			if (element instanceof PluginObjectAdapter)
80
			if (element instanceof IExtensionPointAdapter)
74
				element = ((PluginObjectAdapter) element).getObject();
81
				element = Platform.getBundle(((IExtensionPointAdapter) element).getNamespaceIdentifier());
75
			if (element instanceof IExtensionPoint)
82
			else if (element instanceof IExtensionAdapter)
76
				element = Platform.getBundle(((IExtensionPoint) element).getNamespaceIdentifier());
83
				element = Platform.getBundle(((IExtensionAdapter) element).getNamespaceIdentifier());
77
			else if (element instanceof IExtension)
84
			if (element instanceof IBundle)
78
				element = Platform.getBundle(((IExtension) element).getNamespaceIdentifier());
85
				return ((IBundle) element).getState() == Bundle.ACTIVE;
79
			if (element instanceof Bundle)
80
				return ((Bundle) element).getState() == Bundle.ACTIVE;
81
			return true;
86
			return true;
82
		}
87
		}
83
	};
88
	};
84
89
85
	private ViewerFilter fDisabledFilter = new ViewerFilter() {
90
	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) {
91
		public boolean select(Viewer viewer, Object parentElement, Object element) {
90
			if (element instanceof PluginObjectAdapter)
92
			if (element instanceof IBundle) {
91
				element = ((PluginObjectAdapter) element).getObject();
93
				return !((IBundle) element).isEnabled();
92
93
			if (element instanceof Bundle) {
94
				Bundle bundle = (Bundle) element;
95
				BundleDescription description = state.getBundle(bundle.getBundleId());
96
				return ((state.getDisabledInfos(description)).length > 0);
97
			}
94
			}
98
			return false;
95
			return false;
99
		}
96
		}
Lines 133-138 Link Here
133
		}
130
		}
134
	}
131
	}
135
132
133
	public RegistryBrowser() {
134
		try {
135
			model = RegistryModelFactory.getRegistryModel(new URI("local"));
136
		} catch (URISyntaxException e) {
137
			PDERuntimePlugin.log(e);
138
		}
139
	}
140
136
	public void init(IViewSite site, IMemento memento) throws PartInitException {
141
	public void init(IViewSite site, IMemento memento) throws PartInitException {
137
		super.init(site, memento);
142
		super.init(site, memento);
138
		if (memento == null)
143
		if (memento == null)
Lines 203-217 Link Here
203
		fTreeViewer.setUseHashlookup(true);
208
		fTreeViewer.setUseHashlookup(true);
204
		fTreeViewer.setComparator(new ViewerComparator() {
209
		fTreeViewer.setComparator(new ViewerComparator() {
205
			public int compare(Viewer viewer, Object e1, Object e2) {
210
			public int compare(Viewer viewer, Object e1, Object e2) {
206
				if (e1 instanceof PluginObjectAdapter)
207
					e1 = ((PluginObjectAdapter) e1).getObject();
208
				if (e2 instanceof PluginObjectAdapter)
209
					e2 = ((PluginObjectAdapter) e2).getObject();
210
				if (e1 instanceof IBundleFolder && e2 instanceof IBundleFolder)
211
				if (e1 instanceof IBundleFolder && e2 instanceof IBundleFolder)
211
					return ((IBundleFolder) e1).getFolderId() - ((IBundleFolder) e2).getFolderId();
212
					return ((IBundleFolder) e1).getFolderId() - ((IBundleFolder) e2).getFolderId();
212
				if (e1 instanceof Bundle && e2 instanceof Bundle) {
213
				if (e1 instanceof IBundle && e2 instanceof IBundle) {
213
					e1 = ((Bundle) e1).getSymbolicName();
214
					e1 = ((IBundle) e1).getSymbolicName();
214
					e2 = ((Bundle) e2).getSymbolicName();
215
					e2 = ((IBundle) e2).getSymbolicName();
215
				}
216
				}
216
				return super.compare(viewer, e1, e2);
217
				return super.compare(viewer, e1, e2);
217
			}
218
			}
Lines 240-254 Link Here
240
		tree.setMenu(menu);
241
		tree.setMenu(menu);
241
	}
242
	}
242
243
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() {
244
	private void fillToolBar() {
253
		fDrillDownAdapter = new RegistryDrillDownAdapter(fTreeViewer);
245
		fDrillDownAdapter = new RegistryDrillDownAdapter(fTreeViewer);
254
		IActionBars bars = getViewSite().getActionBars();
246
		IActionBars bars = getViewSite().getActionBars();
Lines 398-404 Link Here
398
				try {
390
				try {
399
					List bundles = getSelectedBundles();
391
					List bundles = getSelectedBundles();
400
					for (Iterator it = bundles.iterator(); it.hasNext();) {
392
					for (Iterator it = bundles.iterator(); it.hasNext();) {
401
						Bundle bundle = (Bundle) it.next();
393
						IBundle bundle = (IBundle) it.next();
402
						bundle.start();
394
						bundle.start();
403
					}
395
					}
404
				} catch (BundleException e) {
396
				} catch (BundleException e) {
Lines 412-418 Link Here
412
				try {
404
				try {
413
					List bundles = getSelectedBundles();
405
					List bundles = getSelectedBundles();
414
					for (Iterator it = bundles.iterator(); it.hasNext();) {
406
					for (Iterator it = bundles.iterator(); it.hasNext();) {
415
						Bundle bundle = (Bundle) it.next();
407
						IBundle bundle = (IBundle) it.next();
416
						bundle.stop();
408
						bundle.stop();
417
					}
409
					}
418
				} catch (BundleException e) {
410
				} catch (BundleException e) {
Lines 424-438 Link Here
424
		fEnableAction = new Action(PDERuntimeMessages.RegistryView_enableAction_label) {
416
		fEnableAction = new Action(PDERuntimeMessages.RegistryView_enableAction_label) {
425
			public void run() {
417
			public void run() {
426
				List bundles = getSelectedBundles();
418
				List bundles = getSelectedBundles();
427
				State state = PDERuntimePlugin.getDefault().getState();
428
				for (Iterator it = bundles.iterator(); it.hasNext();) {
419
				for (Iterator it = bundles.iterator(); it.hasNext();) {
429
					Bundle bundle = (Bundle) it.next();
420
					IBundle bundle = (IBundle) it.next();
430
					BundleDescription desc = state.getBundle(bundle.getBundleId());
421
					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
				}
422
				}
437
				PackageAdmin packageAdmin = PDERuntimePlugin.getDefault().getPackageAdmin();
423
				PackageAdmin packageAdmin = PDERuntimePlugin.getDefault().getPackageAdmin();
438
				packageAdmin.refreshPackages((Bundle[]) bundles.toArray(new Bundle[bundles.size()]));
424
				packageAdmin.refreshPackages((Bundle[]) bundles.toArray(new Bundle[bundles.size()]));
Lines 442-454 Link Here
442
		fDisableAction = new Action(PDERuntimeMessages.RegistryView_disableAction_label) {
428
		fDisableAction = new Action(PDERuntimeMessages.RegistryView_disableAction_label) {
443
			public void run() {
429
			public void run() {
444
				List bundles = getSelectedBundles();
430
				List bundles = getSelectedBundles();
445
				State state = PDERuntimePlugin.getDefault().getState();
446
				for (Iterator it = bundles.iterator(); it.hasNext();) {
431
				for (Iterator it = bundles.iterator(); it.hasNext();) {
447
					Bundle bundle = (Bundle) it.next();
432
					IBundle bundle = (IBundle) it.next();
448
					BundleDescription desc = state.getBundle(bundle.getBundleId());
433
					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
				}
434
				}
453
				PackageAdmin packageAdmin = PDERuntimePlugin.getDefault().getPackageAdmin();
435
				PackageAdmin packageAdmin = PDERuntimePlugin.getDefault().getPackageAdmin();
454
				packageAdmin.refreshPackages((Bundle[]) bundles.toArray(new Bundle[bundles.size()]));
436
				packageAdmin.refreshPackages((Bundle[]) bundles.toArray(new Bundle[bundles.size()]));
Lines 458-484 Link Here
458
		fDiagnoseAction = new Action(PDERuntimeMessages.RegistryView_diagnoseAction_label) {
440
		fDiagnoseAction = new Action(PDERuntimeMessages.RegistryView_diagnoseAction_label) {
459
			public void run() {
441
			public void run() {
460
				List bundles = getSelectedBundles();
442
				List bundles = getSelectedBundles();
461
				State state = PDERuntimePlugin.getDefault().getState();
462
				for (Iterator it = bundles.iterator(); it.hasNext();) {
443
				for (Iterator it = bundles.iterator(); it.hasNext();) {
463
					Bundle bundle = (Bundle) it.next();
444
					IBundle bundle = (IBundle) it.next();
464
					BundleDescription desc = state.getBundle(bundle.getBundleId());
445
					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
446
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;
447
					Dialog dialog;
481
					if (unsatisfied.length != 0 || resolverErrors.length != 0) {
448
					if (problems.getChildren().length > 0) {
482
						dialog = new DiagnosticsDialog(getSite().getShell(), PDERuntimeMessages.RegistryView_diag_dialog_title, null, problems, IStatus.WARNING);
449
						dialog = new DiagnosticsDialog(getSite().getShell(), PDERuntimeMessages.RegistryView_diag_dialog_title, null, problems, IStatus.WARNING);
483
						dialog.open();
450
						dialog.open();
484
					} else {
451
					} else {
Lines 499-511 Link Here
499
		fCollapseAllAction.setToolTipText(PDERuntimeMessages.RegistryView_collapseAll_tooltip);
466
		fCollapseAllAction.setToolTipText(PDERuntimeMessages.RegistryView_collapseAll_tooltip);
500
	}
467
	}
501
468
502
	protected void updateItems(boolean resetInput) {
469
	public/* was protected */void updateItems(boolean resetInput) {
503
		Object[] input = null;
470
		Object[] input = null;
504
		boolean extOnly = fShowExtensionsOnlyAction.isChecked();
471
		boolean extOnly = fShowExtensionsOnlyAction.isChecked();
505
		if (extOnly)
472
		if (extOnly)
506
			input = Platform.getExtensionRegistry().getExtensionPoints();
473
			input = model.getExtensionPoints();
507
		else
474
		else
508
			input = getBundles();
475
			input = model.getBundles();
509
		fListener.fExtOnly = extOnly;
476
		fListener.fExtOnly = extOnly;
510
		fTotalItems = input.length;
477
		fTotalItems = input.length;
511
		if (resetInput)
478
		if (resetInput)
Lines 517-523 Link Here
517
		setContentDescription(getTitleSummary());
484
		setContentDescription(getTitleSummary());
518
	}
485
	}
519
486
520
	protected Tree getUndisposedTree() {
487
	public/* was protected */Tree getUndisposedTree() {
521
		if (fTreeViewer == null || fTreeViewer.getTree() == null || fTreeViewer.getTree().isDisposed())
488
		if (fTreeViewer == null || fTreeViewer.getTree() == null || fTreeViewer.getTree().isDisposed())
522
			return null;
489
			return null;
523
		return fTreeViewer.getTree();
490
		return fTreeViewer.getTree();
Lines 556-566 Link Here
556
		if (selection != null) {
523
		if (selection != null) {
557
			Object[] elements = selection.toArray();
524
			Object[] elements = selection.toArray();
558
			for (int i = 0; i < elements.length; i++) {
525
			for (int i = 0; i < elements.length; i++) {
559
				if (elements[i] instanceof PluginObjectAdapter) {
526
				if (elements[i] instanceof IBundle) {
560
					PluginObjectAdapter adapter = (PluginObjectAdapter) elements[i];
527
					bundles.add(elements[i]);
561
					Object object = adapter.getObject();
562
					if (object instanceof Bundle)
563
						bundles.add(object);
564
				}
528
				}
565
			}
529
			}
566
		}
530
		}
Lines 570-576 Link Here
570
	private boolean selectedBundlesStarted() {
534
	private boolean selectedBundlesStarted() {
571
		List bundles = getSelectedBundles();
535
		List bundles = getSelectedBundles();
572
		for (Iterator it = bundles.iterator(); it.hasNext();) {
536
		for (Iterator it = bundles.iterator(); it.hasNext();) {
573
			Bundle bundle = (Bundle) it.next();
537
			IBundle bundle = (IBundle) it.next();
574
			if (bundle.getState() != Bundle.ACTIVE)
538
			if (bundle.getState() != Bundle.ACTIVE)
575
				return false;
539
				return false;
576
		}
540
		}
Lines 580-586 Link Here
580
	private boolean selectedBundlesStopped() {
544
	private boolean selectedBundlesStopped() {
581
		List bundles = getSelectedBundles();
545
		List bundles = getSelectedBundles();
582
		for (Iterator it = bundles.iterator(); it.hasNext();) {
546
		for (Iterator it = bundles.iterator(); it.hasNext();) {
583
			Bundle bundle = (Bundle) it.next();
547
			IBundle bundle = (IBundle) it.next();
584
			if (bundle.getState() == Bundle.ACTIVE)
548
			if (bundle.getState() == Bundle.ACTIVE)
585
				return false;
549
				return false;
586
		}
550
		}
Lines 590-600 Link Here
590
	private boolean selectedBundlesDisabled() {
554
	private boolean selectedBundlesDisabled() {
591
		List bundles = getSelectedBundles();
555
		List bundles = getSelectedBundles();
592
		for (Iterator it = bundles.iterator(); it.hasNext();) {
556
		for (Iterator it = bundles.iterator(); it.hasNext();) {
593
			Bundle bundle = (Bundle) it.next();
557
			IBundle bundle = (IBundle) it.next();
594
			State state = PDERuntimePlugin.getDefault().getState();
558
			if (!bundle.isEnabled())
595
			BundleDescription desc = state.getBundle(bundle.getBundleId());
596
			DisabledInfo[] infos = state.getDisabledInfos(desc);
597
			if (infos.length == 0)
598
				return false;
559
				return false;
599
		}
560
		}
600
		return true;
561
		return true;
Lines 603-623 Link Here
603
	private boolean selectedBundlesEnabled() {
564
	private boolean selectedBundlesEnabled() {
604
		List bundles = getSelectedBundles();
565
		List bundles = getSelectedBundles();
605
		for (Iterator it = bundles.iterator(); it.hasNext();) {
566
		for (Iterator it = bundles.iterator(); it.hasNext();) {
606
			Bundle bundle = (Bundle) it.next();
567
			IBundle bundle = (IBundle) it.next();
607
			State state = PDERuntimePlugin.getDefault().getState();
568
			if (bundle.isEnabled())
608
			BundleDescription desc = state.getBundle(bundle.getBundleId());
569
				return true;
609
			DisabledInfo[] infos = state.getDisabledInfos(desc);
610
			if (infos.length > 0)
611
				return false;
612
		}
570
		}
613
		return true;
571
		return true;
614
	}
572
	}
615
573
616
	protected void add(Object object) {
574
	public/* was protected */void add(Object object) {
617
		add(fTreeViewer.getInput(), object);
575
		add(fTreeViewer.getInput(), object);
618
	}
576
	}
619
577
620
	protected void add(Object parent, Object object) {
578
	public/* was protected */void add(Object parent, Object object) {
621
		if (fDrillDownAdapter.canGoHome())
579
		if (fDrillDownAdapter.canGoHome())
622
			return;
580
			return;
623
		fTotalItems += 1;
581
		fTotalItems += 1;
Lines 625-631 Link Here
625
		updateTitle();
583
		updateTitle();
626
	}
584
	}
627
585
628
	protected void remove(Object object) {
586
	public/* was protected */void remove(Object object) {
629
		if (fDrillDownAdapter.canGoHome())
587
		if (fDrillDownAdapter.canGoHome())
630
			return;
588
			return;
631
		fTotalItems -= 1;
589
		fTotalItems -= 1;
Lines 633-647 Link Here
633
		updateTitle();
591
		updateTitle();
634
	}
592
	}
635
593
636
	protected void update(Object object) {
594
	public/* was protected */void update(Object object) {
637
		fTreeViewer.update(object, null);
595
		fTreeViewer.update(object, null);
638
	}
596
	}
639
597
640
	protected void refresh(Object object) {
598
	public/* was protected */void refresh(Object object) {
641
		fTreeViewer.refresh(object);
599
		fTreeViewer.refresh(object);
642
	}
600
	}
643
601
644
	protected TreeItem[] getTreeItems() {
602
	public/* was protected */TreeItem[] getTreeItems() {
645
		return fTreeViewer.getTree().getItems();
603
		return fTreeViewer.getTree().getItems();
646
	}
604
	}
647
}
605
}
(-)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 (-388 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
			System.out.println("adding "); //$NON-NLS-1$
76
			if (ext != null)
77
				System.out.println("ext: " + ext.getUniqueIdentifier() + "/" + ext.getLabel() + " : " + ext.getExtensionPointUniqueIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
78
			if (extPoint != null)
79
				System.out.println("extPoint: " + extPoint.getUniqueIdentifier()); //$NON-NLS-1$
80
			addExtensionObjectToTree(ext, extOnly);
81
			addExtensionObjectToTree(extPoint, extOnly);
82
			//			addToTree(ext);
83
			//			addToTree(extPoint);
84
		} else if (delta.getKind() == IExtensionDelta.REMOVED) {
85
			System.out.println("removing "); //$NON-NLS-1$
86
			if (ext != null)
87
				System.out.println("ext: " + ext.getUniqueIdentifier() + " : " + ext.getExtensionPointUniqueIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
88
			if (extPoint != null)
89
				System.out.println("extPoint: " + extPoint.getUniqueIdentifier()); //$NON-NLS-1$
90
			removeFromTree(ext);
91
			removeFromTree(extPoint);
92
		}
93
	}
94
95
	//	private void addToTree(Object object) {
96
	//		String namespace = getNamespaceIdentifier(object);
97
	//		if (namespace == null)
98
	//			return;
99
	//		TreeItem[] items = fTreeViewer.getTree().getItems();
100
	//		for (int i = 0; i < items.length; i++) {
101
	//			Object data = items[i].getData();
102
	//			Object adapted = null;
103
	//			if (data instanceof PluginObjectAdapter)
104
	//				adapted = ((PluginObjectAdapter)data).getObject();
105
	//			if (adapted instanceof Bundle && ((Bundle)adapted).getSymbolicName().equals(namespace)) {
106
	//				addBundleToTree(items[i], data, object);
107
	//			}
108
	//		}
109
	//	}
110
111
	private void addExtensionObjectToTree(Object child, boolean extOnly) {
112
		Object parent = null;
113
		if (!extOnly)
114
			parent = getAdoptingBundleParent(child);
115
		else if (child instanceof IExtensionPoint) {
116
			// add to root
117
			fBrowser.add(child);
118
			return;
119
		} else if (child instanceof IExtension) {
120
			// search all extensionPoints and return the correct one
121
			String extPoint = ((IExtension) child).getExtensionPointUniqueIdentifier();
122
			TreeItem[] items = fBrowser.getTreeItems();
123
			for (int i = 0; i < items.length; i++) {
124
				Object data = items[i].getData();
125
				if (data instanceof PluginObjectAdapter)
126
					data = ((PluginObjectAdapter) data).getObject();
127
				if (data instanceof IExtensionPoint && ((IExtensionPoint) data).getUniqueIdentifier().equals(extPoint)) {
128
					parent = items[i].getData();
129
					break;
130
				}
131
			}
132
		}
133
		if (parent != null)
134
			fBrowser.add(parent, child);
135
	}
136
137
	private Object getAdoptingBundleParent(Object child) {
138
		TreeItem bundleItem = findBundleItem(getNamespaceIdentifier(child));
139
		if (bundleItem != null) {
140
			// TODO fix this
141
			// remove this if (true) clause and return the proper parent
142
			if (true) {
143
				fBrowser.refresh(bundleItem.getData());
144
				fBrowser.updateItems(false);
145
				return null;
146
			}
147
			TreeItem[] folders = bundleItem.getItems();
148
			for (int j = 0; j < folders.length; j++) {
149
				// make sure to check extensionsOnlyMode()
150
				// and add to root/proper extension if true
151
				IBundleFolder folder = (IBundleFolder) folders[j].getData();
152
				if (correctFolder(folder, child))
153
					return folder;
154
			}
155
			// folder not found - 1st extension - refresh bundle item
156
			// to rebuild folders
157
			fBrowser.refresh(bundleItem.getData());
158
		}
159
		return null;
160
	}
161
162
	private TreeItem findBundleItem(String namespace) {
163
		if (namespace == null)
164
			return null;
165
		TreeItem[] items = fBrowser.getTreeItems();
166
		for (int i = 0; i < items.length; i++) {
167
			Object data = items[i].getData();
168
			if (data instanceof PluginObjectAdapter)
169
				data = ((PluginObjectAdapter) data).getObject();
170
			if (data instanceof Bundle && ((Bundle) data).getSymbolicName().equals(namespace))
171
				return items[i];
172
		}
173
		return null;
174
	}
175
176
	//	private void addBundleToTree(TreeItem item, Object data, Object object) {
177
	//		// TODO fix this method
178
	//		if (true) {
179
	//			fTreeViewer.refresh(data);
180
	//			updateItems(false);
181
	//			return;
182
	//		}
183
	//		TreeItem[] folders = item.getItems();
184
	//		for (int j = 0; j < folders.length; j++) {
185
	//			// make sure to check extensionsOnlyMode()
186
	//			// and add to root/proper extension if true
187
	//			IBundleFolder folder = (IBundleFolder)folders[j].getData();
188
	//			if (correctFolder(folder, object)) {
189
	//				fTreeViewer.add(folder, object);
190
	//				return;
191
	//			}
192
	//		}
193
	//		// folder not found - 1st extension - refresh bundle item
194
	//		fTreeViewer.refresh(data);
195
	//	}
196
197
	private String getNamespaceIdentifier(Object object) {
198
		if (object instanceof IExtensionPoint)
199
			return ((IExtensionPoint) object).getNamespaceIdentifier();
200
		if (object instanceof IExtension)
201
			return ((IExtension) object).getContributor().getName();
202
		return null;
203
	}
204
205
	private boolean correctFolder(IBundleFolder folder, Object child) {
206
		if (folder == null)
207
			return false;
208
		if (child instanceof IExtensionPoint)
209
			return folder.getFolderId() == IBundleFolder.F_EXTENSION_POINTS;
210
		if (child instanceof IExtension)
211
			return folder.getFolderId() == IBundleFolder.F_EXTENSIONS;
212
		return false;
213
	}
214
215
	private void removeFromTree(Object object) {
216
		String namespace = getNamespaceIdentifier(object);
217
		if (namespace == null)
218
			return;
219
		TreeItem[] bundles = fBrowser.getTreeItems();
220
		for (int i = 0; i < bundles.length; i++) {
221
			Object data = bundles[i].getData();
222
			Object adapted = null;
223
			if (data instanceof PluginObjectAdapter)
224
				adapted = ((PluginObjectAdapter) data).getObject();
225
			if (adapted instanceof Bundle && ((Bundle) adapted).getSymbolicName().equals(namespace)) {
226
				TreeItem[] folders = bundles[i].getItems();
227
				// TODO fix this method
228
				if (true) {
229
					fBrowser.refresh(data);
230
					fBrowser.updateItems(false);
231
					return;
232
				}
233
				for (int j = 0; j < folders.length; j++) {
234
					IBundleFolder folder = (IBundleFolder) folders[j].getData();
235
					if (correctFolder(folder, object)) {
236
						fBrowser.remove(object);
237
						return;
238
					}
239
				}
240
				// folder not found - 1st extension - refresh bundle item
241
				fBrowser.refresh(data);
242
			}
243
		}
244
	}
245
246
	protected Object findTreeBundleData(Object searchData) {
247
		final Tree tree = fBrowser.getUndisposedTree();
248
		if (tree == null)
249
			return null;
250
251
		Object data = null;
252
		TreeItem[] items = fBrowser.getTreeItems();
253
		if (items == null)
254
			return null;
255
		for (int i = 0; i < items.length; i++) {
256
			Object object = items[i].getData();
257
			data = object;
258
			if (object instanceof PluginObjectAdapter)
259
				object = ((PluginObjectAdapter) object).getObject();
260
			if (searchData.equals(object))
261
				return data;
262
		}
263
		return null;
264
	}
265
266
	void handleEvent(int changeType, Bundle bundle) {
267
		Object data = findTreeBundleData(bundle);
268
		switch (changeType) {
269
			case BundleEvent.INSTALLED :
270
				if (data == null)
271
					fBrowser.add(new PluginAdapter(bundle));
272
				break;
273
			case BundleEvent.UNINSTALLED :
274
				if (data != null)
275
					fBrowser.remove(data);
276
				break;
277
			case BundleEvent.STARTED :
278
			case BundleEvent.STOPPED :
279
			case BundleEvent.UPDATED :
280
			case BundleEvent.RESOLVED :
281
			case BundleEvent.STARTING :
282
			case BundleEvent.STOPPING :
283
			case BundleEvent.UNRESOLVED :
284
			case BundleEvent.LAZY_ACTIVATION :
285
				if (data != null)
286
					fBrowser.update(data);
287
				break;
288
		}
289
	}
290
291
	void handleExtOnlyEvent(int changeType, Bundle bundle) {
292
		switch (changeType) {
293
			case BundleEvent.INSTALLED :
294
			case BundleEvent.UNINSTALLED :
295
				// add/remove all extension points contributed by new bundle
296
				IExtensionPoint[] points = Platform.getExtensionRegistry().getExtensionPoints(bundle.getSymbolicName());
297
				for (int i = 0; i < points.length; i++) {
298
					Object pointData = findTreeBundleData(points[i]);
299
					if (pointData == null) {
300
						if (changeType == BundleEvent.INSTALLED)
301
							fBrowser.add(new ExtensionPointAdapter(points[i]));
302
						else
303
							// changeType == BundleEvent.UNINSTALLED
304
							fBrowser.remove(pointData);
305
					}
306
				}
307
				// add/remove all extensions contributed by new bundle
308
				IExtension[] extensions = Platform.getExtensionRegistry().getExtensions(bundle.getSymbolicName());
309
				for (int i = 0; i < extensions.length; i++) {
310
					String pointId = extensions[i].getExtensionPointUniqueIdentifier();
311
					if (changeType == BundleEvent.INSTALLED) {
312
						IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(pointId);
313
						Object pointData = findTreeBundleData(point);
314
						if (pointData != null)
315
							fBrowser.add(pointData, new ExtensionAdapter(extensions[i]));
316
					} else { // changeType == BundleEvent.UNINSTALLED
317
						Object extensionData = findTreeBundleData(extensions[i]);
318
						if (extensionData != null)
319
							fBrowser.remove(extensionData);
320
					}
321
				}
322
				break;
323
			case BundleEvent.STARTED :
324
			case BundleEvent.STOPPED :
325
			case BundleEvent.UPDATED :
326
			case BundleEvent.RESOLVED :
327
			case BundleEvent.STARTING :
328
			case BundleEvent.STOPPING :
329
			case BundleEvent.UNRESOLVED :
330
			case BundleEvent.LAZY_ACTIVATION :
331
				// nothing needs to be done for any other cases
332
				break;
333
		}
334
	}
335
336
	public void serviceChanged(final ServiceEvent event) {
337
		final Tree tree = fBrowser.getUndisposedTree();
338
		if (tree == null)
339
			return;
340
341
		tree.getDisplay().asyncExec(new Runnable() {
342
			public void run() {
343
				handleServiceChangedEvent(event);
344
			}
345
		});
346
347
	}
348
349
	protected void handleServiceChangedEvent(ServiceEvent event) {
350
		ServiceReference ref = event.getServiceReference();
351
		switch (event.getType()) {
352
			case ServiceEvent.REGISTERED :
353
			case ServiceEvent.UNREGISTERING :
354
				Bundle bundle = ref.getBundle();
355
				if (bundle == null)
356
					return;
357
				String name = bundle.getSymbolicName();
358
				if (name == null)
359
					return;
360
				TreeItem bundleItem = findBundleItem(name);
361
				if (bundleItem == null)
362
					return;
363
				PluginAdapter bundleAdapter = ((PluginAdapter) bundleItem.getData());
364
				Object[] folders = bundleAdapter.getChildren();
365
366
				for (int j = 0; j < folders.length; j++) {
367
					if (folders[j] instanceof IBundleFolder) {
368
						IBundleFolder folder = (IBundleFolder) folders[j];
369
370
						if (folder.getFolderId() == IBundleFolder.F_REGISTERED_SERVICES) {
371
							if ((event.getType() == ServiceEvent.REGISTERED) || (event.getType() == ServiceEvent.UNREGISTERING)) {
372
								((BundleFolder) folder).refresh(); // refresh model
373
								fBrowser.refresh(folder); // refresh view
374
375
								// refresh whole bundle in case there were folders added - they might have not existed if bundle had no service before
376
								fBrowser.refresh(bundleAdapter);
377
							}
378
						}
379
					}
380
				}
381
382
				break;
383
			case ServiceEvent.MODIFIED :
384
				break;
385
		}
386
	}
387
388
}
(-)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/RegistryBrowserLabelProvider.java (-65 / +34 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.*;
14
import org.eclipse.core.runtime.IConfigurationElement;
17
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.viewers.LabelProvider;
16
import org.eclipse.jface.viewers.LabelProvider;
19
import org.eclipse.jface.viewers.TreeViewer;
17
import org.eclipse.jface.viewers.TreeViewer;
20
import org.eclipse.osgi.service.resolver.*;
21
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.osgi.util.NLS;
22
import org.eclipse.pde.internal.runtime.*;
19
import org.eclipse.pde.internal.runtime.*;
20
import org.eclipse.pde.internal.runtime.registry.model.*;
21
import org.eclipse.pde.internal.runtime.registry.model.impl.generic.PluginObjectAdapter;
23
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Image;
24
import org.osgi.framework.Bundle;
23
import org.osgi.framework.Bundle;
25
import org.osgi.framework.ServiceReference;
26
24
27
public class RegistryBrowserLabelProvider extends LabelProvider {
25
public class RegistryBrowserLabelProvider extends LabelProvider {
28
26
Lines 105-119 Link Here
105
		if (element instanceof PluginObjectAdapter)
103
		if (element instanceof PluginObjectAdapter)
106
			element = ((PluginObjectAdapter) element).getObject();
104
			element = ((PluginObjectAdapter) element).getObject();
107
105
108
		if (element instanceof Bundle) {
106
		if (element instanceof IBundle) {
109
			Bundle bundle = (Bundle) element;
107
			IBundle bundle = (IBundle) element;
110
108
111
			// check if bundle is disabled
109
			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;
110
				return fDisabledImage;
118
111
119
			switch (bundle.getState()) {
112
			switch (bundle.getState()) {
Lines 122-135 Link Here
122
				case Bundle.UNINSTALLED :
115
				case Bundle.UNINSTALLED :
123
					return fUnresolvedPluginImage;
116
					return fUnresolvedPluginImage;
124
				case Bundle.INSTALLED :
117
				case Bundle.INSTALLED :
125
					if ((state.getDisabledInfos(description)).length > 0)
118
					if (!bundle.isEnabled())
126
						return fUnresolvedPluginImage;
119
						return fUnresolvedPluginImage;
127
				default :
120
				default :
128
					return fPluginImage;
121
					return fPluginImage;
129
			}
122
			}
130
		}
123
		}
131
124
132
		if (element instanceof ServiceReference) {
125
		if (element instanceof IService) {
133
			return fServiceImage;
126
			return fServiceImage;
134
		}
127
		}
135
128
Lines 144-151 Link Here
144
					return fRequiresImage;
137
					return fRequiresImage;
145
				case IBundleFolder.F_LIBRARIES :
138
				case IBundleFolder.F_LIBRARIES :
146
					return fRuntimeImage;
139
					return fRuntimeImage;
147
				case IBundleFolder.F_LOCATION :
148
					return fLocationImage;
149
				case IBundleFolder.F_REGISTERED_SERVICES :
140
				case IBundleFolder.F_REGISTERED_SERVICES :
150
					return fExporterImage;
141
					return fExporterImage;
151
				case IBundleFolder.F_SERVICES_IN_USE :
142
				case IBundleFolder.F_SERVICES_IN_USE :
Lines 153-162 Link Here
153
			}
144
			}
154
			return null;
145
			return null;
155
		}
146
		}
156
		if (element instanceof IExtension)
147
		if (element instanceof IExtensionAdapter)
157
			return fExtensionImage;
148
			return fExtensionImage;
158
149
159
		if (element instanceof IExtensionPoint)
150
		if (element instanceof IExtensionPointAdapter)
160
			return fExtensionPointImage;
151
			return fExtensionPointImage;
161
152
162
		if (element instanceof IBundlePrerequisite)
153
		if (element instanceof IBundlePrerequisite)
Lines 168-193 Link Here
168
		if (element instanceof IConfigurationElement)
159
		if (element instanceof IConfigurationElement)
169
			return fGenericTagImage;
160
			return fGenericTagImage;
170
161
171
		if (element instanceof IConfigurationAttribute)
162
		if (element instanceof IAttribute) {
163
			IAttribute attr = (IAttribute) element;
164
			if (IAttribute.F_LOCATION.equals(attr.getName())) {
165
				return fLocationImage;
166
			}
172
			return fGenericAttrImage;
167
			return fGenericAttrImage;
168
		}
173
169
174
		return null;
170
		return null;
175
	}
171
	}
176
172
177
	public String getText(Object element) {
173
	public String getText(Object element) {
178
		if (element instanceof PluginObjectAdapter)
174
		if (element instanceof IBundle) {
179
			element = ((PluginObjectAdapter) element).getObject();
175
			String id = ((IBundle) element).getSymbolicName();
180
		if (element instanceof Bundle) {
176
			String version = ((IBundle) element).getVersion();
181
			String id = ((Bundle) element).getSymbolicName();
182
			String version = (String) ((Bundle) element).getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
183
			if (version == null)
177
			if (version == null)
184
				return id;
178
				return id;
185
			return id + " (" + version + ")"; //$NON-NLS-1$ //$NON-NLS-2$
179
			return id + " (" + version + ")"; //$NON-NLS-1$ //$NON-NLS-2$
186
		}
180
		}
187
		if (element instanceof ServiceReference) {
181
		if (element instanceof IService) {
188
			ServiceReference ref = (ServiceReference) element;
182
			IService ref = (IService) element;
189
			String[] classes = (String[]) ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
183
			String[] classes = ref.getClasses();
190
			Long id = (Long) ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
184
			Long id = ref.getId();
191
			String identifier = " (id=" + id.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
185
			String identifier = " (id=" + id.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
192
			return Arrays.asList(classes).toString().concat(identifier);
186
			return Arrays.asList(classes).toString().concat(identifier);
193
		}
187
		}
Lines 205-242 Link Here
205
					return PDERuntimeMessages.RegistryBrowserLabelProvider_registeredServices;
199
					return PDERuntimeMessages.RegistryBrowserLabelProvider_registeredServices;
206
				case IBundleFolder.F_SERVICES_IN_USE :
200
				case IBundleFolder.F_SERVICES_IN_USE :
207
					return PDERuntimeMessages.RegistryBrowserLabelProvider_usedServices;
201
					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
			}
202
			}
223
		}
203
		}
224
		if (element instanceof IExtension) {
204
		if (element instanceof IExtensionAdapter) {
225
			if (((RegistryBrowserContentProvider) fViewer.getContentProvider()).isInExtensionSet) {
205
			if (((RegistryBrowserContentProvider) fViewer.getContentProvider()).isInExtensionSet) {
226
				String name = ((IExtension) element).getLabel();
206
				String name = ((IExtensionAdapter) element).getLabel();
227
				String id = ((IExtension) element).getExtensionPointUniqueIdentifier();
207
				String id = ((IExtensionAdapter) element).getExtensionPointUniqueIdentifier();
228
				if (name != null && name.length() > 0)
208
				if (name != null && name.length() > 0)
229
					return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name);
209
					return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name);
230
				return id;
210
				return id;
231
			}
211
			}
232
212
233
			String contributor = ((IExtension) element).getNamespaceIdentifier();
213
			String contributor = ((IExtensionAdapter) element).getNamespaceIdentifier();
234
			return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_contributedBy, contributor);
214
			return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_contributedBy, contributor);
235
215
236
		}
216
		}
237
		if (element instanceof IExtensionPoint) {
217
		if (element instanceof IExtensionPointAdapter) {
238
			String id = ((IExtensionPoint) element).getUniqueIdentifier();
218
			String id = ((IExtensionPointAdapter) element).getUniqueIdentifier();
239
			String name = ((IExtensionPoint) element).getLabel();
219
			String name = ((IExtensionPointAdapter) element).getLabel();
240
			if (name != null && name.length() > 0)
220
			if (name != null && name.length() > 0)
241
				return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name);
221
				return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name);
242
			return id;
222
			return id;
Lines 247-268 Link Here
247
		if (element instanceof IBundleLibrary)
227
		if (element instanceof IBundleLibrary)
248
			return ((IBundleLibrary) element).getLibrary();
228
			return ((IBundleLibrary) element).getLibrary();
249
229
250
		if (element instanceof IConfigurationElement) {
230
		if (element instanceof IElement) {
251
			String label = ((IConfigurationElement) element).getAttribute("label"); //$NON-NLS-1$
231
			return ((IElement) element).getLabel();
252
			if (label == null)
253
				label = ((IConfigurationElement) element).getName();
254
255
			if (label == null)
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
		}
232
		}
264
		if (element instanceof IConfigurationAttribute)
233
		if (element instanceof IAttribute)
265
			return ((IConfigurationAttribute) element).getLabel();
234
			return ((IAttribute) element).getLabel();
266
235
267
		return super.getText(element);
236
		return super.getText(element);
268
	}
237
	}
(-)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 (+3 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,
21
 org.eclipse.pde.internal.runtime.registry.model.impl.generic;x-internal:=true,
22
 org.eclipse.pde.internal.runtime.registry.model.impl.local;x-internal:=true,
20
 org.eclipse.pde.internal.runtime.spy;x-internal:=true,
23
 org.eclipse.pde.internal.runtime.spy;x-internal:=true,
21
 org.eclipse.pde.internal.runtime.spy.dialogs;x-internal:=true,
24
 org.eclipse.pde.internal.runtime.spy.dialogs;x-internal:=true,
22
 org.eclipse.pde.internal.runtime.spy.handlers;x-internal:=true,
25
 org.eclipse.pde.internal.runtime.spy.handlers;x-internal:=true,
(-)src/org/eclipse/pde/internal/runtime/registry/model/IRegistryModel.java (+20 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import org.eclipse.core.runtime.IExtensionPoint;
4
5
public interface IRegistryModel {
6
7
	void connect();
8
9
	IBundle[] getBundles();
10
11
	IService[] getServices();
12
13
	IExtensionPoint[] getExtensionPoints();
14
15
	void addModelChangeListener(IModelChangeListener listener);
16
17
	void removeModelChangeListener(IModelChangeListener listener);
18
19
	void disconnect();
20
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IBundle.java (+38 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import org.eclipse.core.runtime.MultiStatus;
4
import org.osgi.framework.BundleException;
5
6
public interface IBundle extends IModelObject {
7
8
	String getSymbolicName();
9
10
	String getVersion();
11
12
	boolean isEnabled();
13
14
	void setEnabled(boolean enabled);
15
16
	public IExtensionAdapter[] getExtensions();
17
18
	public IExtensionPointAdapter[] getExtensionPoints();
19
20
	public IBundlePrerequisite[] getImports();
21
22
	public IBundleLibrary[] getLibraries();
23
24
	public Object[] getRegisteredServices();
25
26
	public Object[] getServicesInUse();
27
28
	public String getLocation();
29
30
	int getState();
31
32
	void start() throws BundleException; // XXX Create custom Exception
33
34
	void stop() throws BundleException;
35
36
	MultiStatus diagnose();
37
38
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IBundleFolder.java (+26 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 interface IBundleFolder extends IModelObject {
14
	public static final int F_EXTENSIONS = 1;
15
	public static final int F_EXTENSION_POINTS = 2;
16
	public static final int F_IMPORTS = 3;
17
	public static final int F_LIBRARIES = 4;
18
	public static final int F_REGISTERED_SERVICES = 5;
19
	public static final int F_SERVICES_IN_USE = 6;
20
21
	public Object[] getChildren();
22
23
	public void refresh();
24
25
	int getFolderId();
26
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IBundleLibrary.java (+15 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 interface IBundleLibrary extends IModelObject {
14
	public String getLibrary();
15
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/ServiceReferenceAdapter.java (+47 lines)
Added 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.model.impl.local;
12
13
import org.eclipse.pde.internal.runtime.registry.model.IModelObject;
14
import org.eclipse.pde.internal.runtime.registry.model.IService;
15
import org.osgi.framework.ServiceReference;
16
17
public class ServiceReferenceAdapter implements IService {
18
19
	private ServiceReference ref;
20
21
	public ServiceReferenceAdapter(ServiceReference object) {
22
		this.ref = object;
23
	}
24
25
	public boolean equals(Object obj) {
26
		// imitate ServiceReference behavior, that multiple ServiceReference instances are equal
27
		return (obj instanceof ServiceReferenceAdapter) ? ref.equals(((ServiceReferenceAdapter) obj).ref) : false;
28
	}
29
30
	public int hashCode() {
31
		// imitate ServiceReference behavior, that multiple ServiceReference instances return the same hashCode
32
		return ref.hashCode();
33
	}
34
35
	public IModelObject getParent() {
36
		// TODO Auto-generated method stub
37
		return null;
38
	}
39
40
	public String[] getClasses() {
41
		return (String[]) ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
42
	}
43
44
	public Long getId() {
45
		return (Long) ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
46
	}
47
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/ExtensionAdapter.java (+51 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.impl.local;
12
13
import org.eclipse.core.runtime.IConfigurationElement;
14
import org.eclipse.pde.internal.runtime.registry.model.*;
15
16
public class ExtensionAdapter implements IExtensionAdapter {
17
18
	org.eclipse.core.runtime.IExtension extension;
19
20
	public ExtensionAdapter(org.eclipse.core.runtime.IExtension extension) {
21
		this.extension = extension;
22
	}
23
24
	public IElement[] getConfigurationElements() {
25
26
		IConfigurationElement[] elements = extension.getConfigurationElements();
27
		IElement[] result = new IElement[elements.length];
28
		for (int i = 0; i < elements.length; i++) {
29
			IConfigurationElement config = elements[i];
30
			result[i] = new ConfigurationElementAdapter(config);
31
		}
32
		return result;
33
	}
34
35
	public IModelObject getParent() {
36
		// TODO Auto-generated method stub
37
		return null;
38
	}
39
40
	public String getExtensionPointUniqueIdentifier() {
41
		return extension.getExtensionPointUniqueIdentifier();
42
	}
43
44
	public String getLabel() {
45
		return extension.getLabel();
46
	}
47
48
	public String getNamespaceIdentifier() {
49
		return extension.getNamespaceIdentifier();
50
	}
51
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/RegistryBrowserListener.java (+393 lines)
Added 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.model.impl.local;
12
13
import org.eclipse.core.runtime.*;
14
import org.eclipse.pde.internal.runtime.registry.RegistryBrowser;
15
import org.eclipse.pde.internal.runtime.registry.model.IBundle;
16
import org.eclipse.pde.internal.runtime.registry.model.IBundleFolder;
17
import org.eclipse.pde.internal.runtime.registry.model.impl.generic.PluginObjectAdapter;
18
import org.eclipse.swt.widgets.Tree;
19
import org.eclipse.swt.widgets.TreeItem;
20
import org.osgi.framework.*;
21
22
public class RegistryBrowserListener implements IRegistryChangeListener, BundleListener, ServiceListener {
23
24
	protected RegistryBrowser fBrowser;
25
	public/* was protected */boolean fExtOnly;
26
27
	public/* was protected */RegistryBrowserListener(RegistryBrowser browser) {
28
		fBrowser = browser;
29
	}
30
31
	public void registryChanged(final IRegistryChangeEvent event) {
32
		final Tree tree = fBrowser.getUndisposedTree();
33
		if (tree == null)
34
			return;
35
36
		tree.getDisplay().asyncExec(new Runnable() {
37
			public void run() {
38
				IExtensionDelta[] deltas = event.getExtensionDeltas();
39
				for (int i = 0; i < deltas.length; i++) {
40
					if (fExtOnly)
41
						handleExtOnlyEvent(deltas[i]);
42
					else
43
						handleEvent(deltas[i]);
44
				}
45
			}
46
		});
47
	}
48
49
	public void bundleChanged(final BundleEvent event) {
50
		final Tree tree = fBrowser.getUndisposedTree();
51
		if (tree == null)
52
			return;
53
54
		tree.getDisplay().asyncExec(new Runnable() {
55
			public void run() {
56
				if (fExtOnly)
57
					handleExtOnlyEvent(event.getType(), event.getBundle());
58
				else
59
					handleEvent(event.getType(), event.getBundle());
60
			}
61
		});
62
	}
63
64
	void handleEvent(IExtensionDelta delta) {
65
		handleDelta(delta, false);
66
	}
67
68
	void handleExtOnlyEvent(IExtensionDelta delta) {
69
		handleDelta(delta, true);
70
	}
71
72
	private void handleDelta(IExtensionDelta delta, boolean extOnly) {
73
		IExtension ext = delta.getExtension();
74
		IExtensionPoint extPoint = delta.getExtensionPoint();
75
		// TODO fix this method (and addToTree/removeFromTree)
76
		// bug 130655
77
		if (delta.getKind() == IExtensionDelta.ADDED) {
78
			System.out.println("adding "); //$NON-NLS-1$
79
			if (ext != null)
80
				System.out.println("ext: " + ext.getUniqueIdentifier() + "/" + ext.getLabel() + " : " + ext.getExtensionPointUniqueIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
81
			if (extPoint != null)
82
				System.out.println("extPoint: " + extPoint.getUniqueIdentifier()); //$NON-NLS-1$
83
			addExtensionObjectToTree(ext, extOnly);
84
			addExtensionObjectToTree(extPoint, extOnly);
85
			//			addToTree(ext);
86
			//			addToTree(extPoint);
87
		} else if (delta.getKind() == IExtensionDelta.REMOVED) {
88
			System.out.println("removing "); //$NON-NLS-1$
89
			if (ext != null)
90
				System.out.println("ext: " + ext.getUniqueIdentifier() + " : " + ext.getExtensionPointUniqueIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
91
			if (extPoint != null)
92
				System.out.println("extPoint: " + extPoint.getUniqueIdentifier()); //$NON-NLS-1$
93
			removeFromTree(ext);
94
			removeFromTree(extPoint);
95
		}
96
	}
97
98
	//	private void addToTree(Object object) {
99
	//		String namespace = getNamespaceIdentifier(object);
100
	//		if (namespace == null)
101
	//			return;
102
	//		TreeItem[] items = fTreeViewer.getTree().getItems();
103
	//		for (int i = 0; i < items.length; i++) {
104
	//			Object data = items[i].getData();
105
	//			Object adapted = null;
106
	//			if (data instanceof PluginObjectAdapter)
107
	//				adapted = ((PluginObjectAdapter)data).getObject();
108
	//			if (adapted instanceof Bundle && ((Bundle)adapted).getSymbolicName().equals(namespace)) {
109
	//				addBundleToTree(items[i], data, object);
110
	//			}
111
	//		}
112
	//	}
113
114
	private void addExtensionObjectToTree(Object child, boolean extOnly) {
115
		Object parent = null;
116
		if (!extOnly)
117
			parent = getAdoptingBundleParent(child);
118
		else if (child instanceof IExtensionPoint) {
119
			// add to root
120
			fBrowser.add(child);
121
			return;
122
		} else if (child instanceof IExtension) {
123
			// search all extensionPoints and return the correct one
124
			String extPoint = ((IExtension) child).getExtensionPointUniqueIdentifier();
125
			TreeItem[] items = fBrowser.getTreeItems();
126
			for (int i = 0; i < items.length; i++) {
127
				Object data = items[i].getData();
128
				if (data instanceof PluginObjectAdapter)
129
					data = ((PluginObjectAdapter) data).getObject();
130
				if (data instanceof IExtensionPoint && ((IExtensionPoint) data).getUniqueIdentifier().equals(extPoint)) {
131
					parent = items[i].getData();
132
					break;
133
				}
134
			}
135
		}
136
		if (parent != null)
137
			fBrowser.add(parent, child);
138
	}
139
140
	private Object getAdoptingBundleParent(Object child) {
141
		TreeItem bundleItem = findBundleItem(getNamespaceIdentifier(child));
142
		if (bundleItem != null) {
143
			// TODO fix this
144
			// remove this if (true) clause and return the proper parent
145
			if (true) {
146
				fBrowser.refresh(bundleItem.getData());
147
				fBrowser.updateItems(false);
148
				return null;
149
			}
150
			TreeItem[] folders = bundleItem.getItems();
151
			for (int j = 0; j < folders.length; j++) {
152
				// make sure to check extensionsOnlyMode()
153
				// and add to root/proper extension if true
154
				IBundleFolder folder = (IBundleFolder) folders[j].getData();
155
				if (correctFolder(folder, child))
156
					return folder;
157
			}
158
			// folder not found - 1st extension - refresh bundle item
159
			// to rebuild folders
160
			fBrowser.refresh(bundleItem.getData());
161
		}
162
		return null;
163
	}
164
165
	private TreeItem findBundleItem(String namespace) {
166
		if (namespace == null)
167
			return null;
168
		TreeItem[] items = fBrowser.getTreeItems();
169
		for (int i = 0; i < items.length; i++) {
170
			Object data = items[i].getData();
171
			if (data instanceof PluginObjectAdapter)
172
				data = ((PluginObjectAdapter) data).getObject();
173
			if (data instanceof BundleAdapter && ((IBundle) data).getSymbolicName().equals(namespace))
174
				return items[i];
175
		}
176
		return null;
177
	}
178
179
	//	private void addBundleToTree(TreeItem item, Object data, Object object) {
180
	//		// TODO fix this method
181
	//		if (true) {
182
	//			fTreeViewer.refresh(data);
183
	//			updateItems(false);
184
	//			return;
185
	//		}
186
	//		TreeItem[] folders = item.getItems();
187
	//		for (int j = 0; j < folders.length; j++) {
188
	//			// make sure to check extensionsOnlyMode()
189
	//			// and add to root/proper extension if true
190
	//			IBundleFolder folder = (IBundleFolder)folders[j].getData();
191
	//			if (correctFolder(folder, object)) {
192
	//				fTreeViewer.add(folder, object);
193
	//				return;
194
	//			}
195
	//		}
196
	//		// folder not found - 1st extension - refresh bundle item
197
	//		fTreeViewer.refresh(data);
198
	//	}
199
200
	private String getNamespaceIdentifier(Object object) {
201
		if (object instanceof IExtensionPoint)
202
			return ((IExtensionPoint) object).getNamespaceIdentifier();
203
		if (object instanceof IExtension)
204
			return ((IExtension) object).getContributor().getName();
205
		return null;
206
	}
207
208
	private boolean correctFolder(IBundleFolder folder, Object child) {
209
		if (folder == null)
210
			return false;
211
		if (child instanceof IExtensionPoint)
212
			return folder.getFolderId() == IBundleFolder.F_EXTENSION_POINTS;
213
		if (child instanceof IExtension)
214
			return folder.getFolderId() == IBundleFolder.F_EXTENSIONS;
215
		return false;
216
	}
217
218
	private void removeFromTree(Object object) {
219
		String namespace = getNamespaceIdentifier(object);
220
		if (namespace == null)
221
			return;
222
		TreeItem[] bundles = fBrowser.getTreeItems();
223
		for (int i = 0; i < bundles.length; i++) {
224
			Object data = bundles[i].getData();
225
			Object adapted = null;
226
			if (data instanceof PluginObjectAdapter)
227
				adapted = ((PluginObjectAdapter) data).getObject();
228
			if (adapted instanceof BundleAdapter && ((IBundle) adapted).getSymbolicName().equals(namespace)) {
229
				TreeItem[] folders = bundles[i].getItems();
230
				// TODO fix this method
231
				if (true) {
232
					fBrowser.refresh(data);
233
					fBrowser.updateItems(false);
234
					return;
235
				}
236
				for (int j = 0; j < folders.length; j++) {
237
					IBundleFolder folder = (IBundleFolder) folders[j].getData();
238
					if (correctFolder(folder, object)) {
239
						fBrowser.remove(object);
240
						return;
241
					}
242
				}
243
				// folder not found - 1st extension - refresh bundle item
244
				fBrowser.refresh(data);
245
			}
246
		}
247
	}
248
249
	protected Object findTreeBundleData(Object searchData) {
250
		final Tree tree = fBrowser.getUndisposedTree();
251
		if (tree == null)
252
			return null;
253
254
		Object data = null;
255
		TreeItem[] items = fBrowser.getTreeItems();
256
		if (items == null)
257
			return null;
258
		for (int i = 0; i < items.length; i++) {
259
			Object object = items[i].getData();
260
			data = object;
261
			if (object instanceof PluginObjectAdapter)
262
				object = ((PluginObjectAdapter) object).getObject();
263
			if (searchData.equals(object))
264
				return data;
265
		}
266
		return null;
267
	}
268
269
	void handleEvent(int changeType, Bundle bundle) {
270
		Object data = findTreeBundleData(bundle);
271
		switch (changeType) {
272
			case BundleEvent.INSTALLED :
273
				if (data == null)
274
					fBrowser.add(new BundleAdapter(bundle));
275
				break;
276
			case BundleEvent.UNINSTALLED :
277
				if (data != null)
278
					fBrowser.remove(data);
279
				break;
280
			case BundleEvent.STARTED :
281
			case BundleEvent.STOPPED :
282
			case BundleEvent.UPDATED :
283
			case BundleEvent.RESOLVED :
284
			case BundleEvent.STARTING :
285
			case BundleEvent.STOPPING :
286
			case BundleEvent.UNRESOLVED :
287
			case BundleEvent.LAZY_ACTIVATION :
288
				if (data != null)
289
					fBrowser.update(data);
290
				break;
291
		}
292
	}
293
294
	void handleExtOnlyEvent(int changeType, Bundle bundle) {
295
		switch (changeType) {
296
			case BundleEvent.INSTALLED :
297
			case BundleEvent.UNINSTALLED :
298
				// add/remove all extension points contributed by new bundle
299
				IExtensionPoint[] points = Platform.getExtensionRegistry().getExtensionPoints(bundle.getSymbolicName());
300
				for (int i = 0; i < points.length; i++) {
301
					Object pointData = findTreeBundleData(points[i]);
302
					if (pointData == null) {
303
						if (changeType == BundleEvent.INSTALLED)
304
							fBrowser.add(new ExtensionPointAdapter(points[i]));
305
						else
306
							// changeType == BundleEvent.UNINSTALLED
307
							fBrowser.remove(pointData);
308
					}
309
				}
310
				// add/remove all extensions contributed by new bundle
311
				IExtension[] extensions = Platform.getExtensionRegistry().getExtensions(bundle.getSymbolicName());
312
				for (int i = 0; i < extensions.length; i++) {
313
					String pointId = extensions[i].getExtensionPointUniqueIdentifier();
314
					if (changeType == BundleEvent.INSTALLED) {
315
						IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(pointId);
316
						Object pointData = findTreeBundleData(point);
317
						if (pointData != null)
318
							fBrowser.add(pointData, new ExtensionAdapter(extensions[i]));
319
					} else { // changeType == BundleEvent.UNINSTALLED
320
						Object extensionData = findTreeBundleData(extensions[i]);
321
						if (extensionData != null)
322
							fBrowser.remove(extensionData);
323
					}
324
				}
325
				break;
326
			case BundleEvent.STARTED :
327
			case BundleEvent.STOPPED :
328
			case BundleEvent.UPDATED :
329
			case BundleEvent.RESOLVED :
330
			case BundleEvent.STARTING :
331
			case BundleEvent.STOPPING :
332
			case BundleEvent.UNRESOLVED :
333
			case BundleEvent.LAZY_ACTIVATION :
334
				// nothing needs to be done for any other cases
335
				break;
336
		}
337
	}
338
339
	public void serviceChanged(final ServiceEvent event) {
340
		final Tree tree = fBrowser.getUndisposedTree();
341
		if (tree == null)
342
			return;
343
344
		tree.getDisplay().asyncExec(new Runnable() {
345
			public void run() {
346
				handleServiceChangedEvent(event);
347
			}
348
		});
349
350
	}
351
352
	protected void handleServiceChangedEvent(ServiceEvent event) {
353
		ServiceReference ref = event.getServiceReference();
354
		switch (event.getType()) {
355
			case ServiceEvent.REGISTERED :
356
			case ServiceEvent.UNREGISTERING :
357
				Bundle bundle = ref.getBundle();
358
				if (bundle == null)
359
					return;
360
				String name = bundle.getSymbolicName();
361
				if (name == null)
362
					return;
363
				TreeItem bundleItem = findBundleItem(name);
364
				if (bundleItem == null)
365
					return;
366
				BundleAdapter bundleAdapter = ((BundleAdapter) bundleItem.getData());
367
				fBrowser.refresh(bundleAdapter);
368
369
				/*Object[] folders = bundleAdapter.getChildren(); // XXX uncomment this and split changes notification into model and impl specyfic
370
371
				for (int j = 0; j < folders.length; j++) {
372
					if (folders[j] instanceof IBundleFolder) {
373
						IBundleFolder folder = (IBundleFolder) folders[j];
374
375
						if (folder.getFolderId() == IBundleFolder.F_REGISTERED_SERVICES) {
376
							if ((event.getType() == ServiceEvent.REGISTERED) || (event.getType() == ServiceEvent.UNREGISTERING)) {
377
								((BundleFolder) folder).refresh(); // refresh model
378
								fBrowser.refresh(folder); // refresh view
379
380
								// refresh whole bundle in case there were folders added - they might have not existed if bundle had no service before
381
								fBrowser.refresh(bundleAdapter);
382
							}
383
						}
384
					}
385
				}*/
386
387
				break;
388
			case ServiceEvent.MODIFIED :
389
				break;
390
		}
391
	}
392
393
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IBundlePrerequisite.java (+21 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
import org.eclipse.osgi.util.ManifestElement;
14
15
public interface IBundlePrerequisite extends IModelObject {
16
	public ManifestElement getPrerequisite();
17
18
	public boolean isExported();
19
20
	public String getLabel();
21
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/ConfigurationElementAdapter.java (+75 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.impl.local;
12
13
import org.eclipse.core.runtime.IConfigurationElement;
14
import org.eclipse.pde.internal.runtime.registry.model.*;
15
import org.eclipse.pde.internal.runtime.registry.model.impl.generic.ConfigurationAttribute;
16
17
public class ConfigurationElementAdapter implements IElement {
18
19
	private IConfigurationElement config;
20
	private IAttribute[] elements;
21
22
	public ConfigurationElementAdapter(IConfigurationElement config) {
23
		this.config = config;
24
	}
25
26
	protected void createChildren() {
27
		String[] atts = config.getAttributeNames();
28
		IAttribute[] catts = new IAttribute[atts.length];
29
		for (int i = 0; i < atts.length; i++)
30
			catts[i] = new ConfigurationAttribute(atts[i], config.getAttribute(atts[i]));
31
		IConfigurationElement[] children = config.getChildren();
32
		IAttribute[] result = new IAttribute[children.length + catts.length];
33
		for (int i = 0; i < children.length; i++) {
34
			IConfigurationElement child = children[i];
35
			result[i] = new ConfigurationElementAdapter(child);
36
		}
37
		for (int i = 0; i < catts.length; i++) {
38
			result[children.length + i] = catts[i];
39
		}
40
		elements = result;
41
	}
42
43
	public IAttribute[] getElements() {
44
		if (elements == null) {
45
			createChildren();
46
		}
47
48
		return elements;
49
	}
50
51
	public IModelObject getParent() {
52
		// TODO Auto-generated method stub
53
		return null;
54
	}
55
56
	public String getLabel() {
57
		String label = config.getAttribute("label"); //$NON-NLS-1$
58
		if (label == null)
59
			label = config.getName();
60
61
		if (label == null)
62
			label = config.getAttribute("name"); //$NON-NLS-1$
63
64
		if (label == null && config.getAttribute("id") != null) { //$NON-NLS-1$
65
			String[] labelSplit = config.getAttribute("id").split("\\."); //$NON-NLS-1$ //$NON-NLS-2$
66
			label = labelSplit.length == 0 ? null : labelSplit[labelSplit.length - 1];
67
		}
68
		return label;
69
	}
70
71
	public String getName() {
72
		// TODO Auto-generated method stub
73
		return null;
74
	}
75
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IExtensionAdapter.java (+12 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public interface IExtensionAdapter extends IModelObject {
4
5
	IElement[] getConfigurationElements();
6
7
	String getLabel();
8
9
	String getExtensionPointUniqueIdentifier();
10
11
	String getNamespaceIdentifier();
12
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/LocalModel.java (+52 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model.impl.local;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import org.eclipse.core.runtime.IExtensionPoint;
6
import org.eclipse.core.runtime.Platform;
7
import org.eclipse.pde.internal.runtime.PDERuntimePlugin;
8
import org.eclipse.pde.internal.runtime.registry.model.*;
9
import org.osgi.framework.Bundle;
10
import org.osgi.framework.Constants;
11
12
public class LocalModel implements IRegistryModel {
13
14
	private List listeners = new ArrayList();
15
16
	public void connect() {
17
		// TODO Auto-generated method stub
18
19
	}
20
21
	public void disconnect() {
22
		// TODO Auto-generated method stub
23
24
	}
25
26
	public IBundle[] getBundles() {
27
		Bundle[] bundles = PDERuntimePlugin.getDefault().getBundleContext().getBundles();
28
		ArrayList list = new ArrayList();
29
		for (int i = 0; i < bundles.length; i++)
30
			if (bundles[i].getHeaders().get(Constants.FRAGMENT_HOST) == null)
31
				list.add(new BundleAdapter(bundles[i]));
32
		return (BundleAdapter[]) list.toArray(new BundleAdapter[list.size()]);
33
	}
34
35
	public IExtensionPoint[] getExtensionPoints() {
36
		return Platform.getExtensionRegistry().getExtensionPoints();
37
	}
38
39
	public IService[] getServices() {
40
		// TODO Auto-generated method stub
41
		return null;
42
	}
43
44
	public void addModelChangeListener(IModelChangeListener listener) {
45
		listeners.add(listener);
46
	}
47
48
	public void removeModelChangeListener(IModelChangeListener listener) {
49
		listeners.remove(listener);
50
	}
51
52
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IExtensionPointAdapter.java (+13 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public interface IExtensionPointAdapter extends IModelObject {
4
5
	String getUniqueIdentifier();
6
7
	IExtensionAdapter[] getExtensions();
8
9
	String getLabel();
10
11
	String getNamespaceIdentifier();
12
13
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/generic/BundleFolder.java (+62 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.pde.internal.runtime.registry.model.impl.generic;
5
6
import org.eclipse.pde.internal.runtime.registry.model.*;
7
8
public class BundleFolder implements IBundleFolder {
9
	private int id;
10
	private IModelObject parent;
11
	private Object[] children;
12
13
	public BundleFolder(IModelObject parent, int id) {
14
		this.parent = parent;
15
		this.id = id;
16
	}
17
18
	protected void createChildren() {
19
		switch (id) {
20
			case F_EXTENSION_POINTS :
21
				children = ((IBundle) parent).getExtensionPoints();
22
				return;
23
			case F_EXTENSIONS :
24
				children = ((IBundle) parent).getExtensions();
25
				return;
26
			case F_IMPORTS :
27
				children = ((IBundle) parent).getImports();
28
				return;
29
			case F_LIBRARIES :
30
				children = ((IBundle) parent).getLibraries();
31
				return;
32
			case F_REGISTERED_SERVICES :
33
				children = ((IBundle) parent).getRegisteredServices();
34
				return;
35
			case F_SERVICES_IN_USE :
36
				children = ((IBundle) parent).getServicesInUse();
37
				return;
38
		}
39
	}
40
41
	public Object[] getChildren() {
42
		if (children == null) {
43
			createChildren();
44
		}
45
		return children;
46
	}
47
48
	/**
49
	 * Resets folder's previously cached knowledge about it's children. 
50
	 */
51
	public void refresh() {
52
		children = null;
53
	}
54
55
	public int getFolderId() {
56
		return id;
57
	}
58
59
	public IModelObject getParent() {
60
		return parent;
61
	}
62
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IModelChangedEvent.java (+5 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public interface IModelChangedEvent {
4
5
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IModelChangeListener.java (+6 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public interface IModelChangeListener {
4
5
	void modelChange(IModelChangedEvent event);
6
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/generic/ConfigurationAttribute.java (+30 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.pde.internal.runtime.registry.model.impl.generic;
5
6
import org.eclipse.pde.internal.runtime.registry.model.IAttribute;
7
import org.eclipse.pde.internal.runtime.registry.model.IModelObject;
8
9
public class ConfigurationAttribute implements IAttribute {
10
	private String fLabel;
11
	private String name;
12
13
	public ConfigurationAttribute(String name, String value) {
14
		fLabel = name + " = " + value; //$NON-NLS-1$
15
		this.name = name;
16
	}
17
18
	public String getLabel() {
19
		return fLabel;
20
	}
21
22
	public IModelObject getParent() {
23
		// TODO Auto-generated method stub
24
		return null;
25
	}
26
27
	public String getName() {
28
		return name;
29
	}
30
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IModelObject.java (+6 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public interface IModelObject {
4
5
	IModelObject getParent();
6
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/BundleAdapter.java (+223 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model.impl.local;
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.eclipse.pde.internal.runtime.registry.model.*;
11
import org.osgi.framework.*;
12
13
public class BundleAdapter implements IBundle {
14
15
	private Bundle bundle;
16
17
	private IExtensionAdapter[] fExtensions;
18
19
	private IExtensionPointAdapter[] fExtensionPoints;
20
21
	public BundleAdapter(Bundle bundle) {
22
		this.bundle = bundle;
23
	}
24
25
	public String getSymbolicName() {
26
		return bundle.getSymbolicName();
27
	}
28
29
	public boolean isEnabled() {
30
		PlatformAdmin plaformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
31
		State state = plaformAdmin.getState(false);
32
33
		BundleDescription description = state.getBundle(bundle.getBundleId());
34
		return ((state.getDisabledInfos(description)).length == 0);
35
	}
36
37
	public void setEnabled(boolean enabled) {
38
		PlatformAdmin plaformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
39
		State state = plaformAdmin.getState(false);
40
41
		BundleDescription desc = state.getBundle(bundle.getBundleId());
42
43
		if (enabled) {
44
			DisabledInfo[] infos = state.getDisabledInfos(desc);
45
			for (int i = 0; i < infos.length; i++) {
46
				PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
47
				platformAdmin.removeDisabledInfo(infos[i]);
48
			}
49
		} else {
50
			DisabledInfo info = new DisabledInfo("org.eclipse.pde.ui", "Disabled via PDE", desc); //$NON-NLS-1$ //$NON-NLS-2$
51
			PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
52
			platformAdmin.addDisabledInfo(info);
53
		}
54
		// TODO Auto-generated method stub
55
56
	}
57
58
	public IModelObject getParent() {
59
		// TODO Auto-generated method stub
60
		return null;
61
	}
62
63
	public IExtensionAdapter[] getExtensions() {
64
		if (fExtensions == null) {
65
			IExtension[] extensions = Platform.getExtensionRegistry().getExtensions(getSymbolicName());
66
			IExtensionAdapter[] tmp = new IExtensionAdapter[extensions.length];
67
			for (int i = 0; i < extensions.length; i++) {
68
				tmp[i] = new ExtensionAdapter(extensions[i]);
69
			}
70
			fExtensions = tmp;
71
		}
72
		return fExtensions;
73
	}
74
75
	public IExtensionPointAdapter[] getExtensionPoints() {
76
		if (fExtensionPoints == null) {
77
			IExtensionPoint[] extensions = Platform.getExtensionRegistry().getExtensionPoints(getSymbolicName());
78
			IExtensionPointAdapter[] tmp = new IExtensionPointAdapter[extensions.length];
79
			for (int i = 0; i < extensions.length; i++) {
80
				tmp[i] = new ExtensionPointAdapter(extensions[i]);
81
			}
82
			fExtensionPoints = tmp;
83
		}
84
		return fExtensionPoints;
85
	}
86
87
	public IBundlePrerequisite[] getImports() {
88
		return (IBundlePrerequisite[]) getManifestHeaderArray(bundle, Constants.REQUIRE_BUNDLE);
89
	}
90
91
	public IBundleLibrary[] getLibraries() {
92
		return (IBundleLibrary[]) getManifestHeaderArray(bundle, Constants.BUNDLE_CLASSPATH);
93
	}
94
95
	public Object[] getRegisteredServices() {
96
		return getServices(bundle, IBundleFolder.F_REGISTERED_SERVICES);
97
	}
98
99
	public Object[] getServicesInUse() {
100
		return getServices(bundle, IBundleFolder.F_SERVICES_IN_USE);
101
	}
102
103
	public static Object[] getServices(Bundle bundle, int type) {
104
		Set result = new HashSet();
105
106
		try {
107
			ServiceReference[] references = PDERuntimePlugin.getDefault().getBundleContext().getAllServiceReferences(null, null);
108
109
			for (int i = 0; i < references.length; i++) {
110
				ServiceReference ref = references[i];
111
112
				if ((type == IBundleFolder.F_REGISTERED_SERVICES) && (bundle.equals(ref.getBundle()))) {
113
					result.add(new ServiceReferenceAdapter(ref));
114
				}
115
116
				Bundle[] usingBundles = ref.getUsingBundles();
117
				if ((type == IBundleFolder.F_SERVICES_IN_USE) && (usingBundles != null && Arrays.asList(usingBundles).contains(bundle))) {
118
					result.add(new ServiceReferenceAdapter(ref));
119
				}
120
			}
121
122
		} catch (InvalidSyntaxException e) { // nothing
123
		}
124
125
		if (result.size() == 0)
126
			return null;
127
128
		return result.toArray(new ServiceReferenceAdapter[result.size()]);
129
	}
130
131
	/*	public static Object[] getFolderChildren(int id) {
132
			Object[] array = null;
133
134
			Object[] result = null;
135
			if (array != null && array.length > 0) {
136
				result = new Object[array.length];
137
				for (int i = 0; i < array.length; i++) {
138
					result[i] = createAdapter(array[i], id);
139
				}
140
			}
141
			return result;
142
		}*/
143
144
	public static Object[] getManifestHeaderArray(Bundle bundle, String headerKey) {
145
		String libraries = (String) bundle.getHeaders().get(headerKey);
146
		try {
147
			ManifestElement[] elements = ManifestElement.parseHeader(headerKey, libraries);
148
			if (elements == null)
149
				return null;
150
			if (headerKey.equals(Constants.BUNDLE_CLASSPATH)) {
151
				IBundleLibrary[] array = new IBundleLibrary[elements.length];
152
				for (int i = 0; i < elements.length; i++)
153
					array[i] = new BundleLibrary(elements[i]);
154
				return array;
155
			} else if (headerKey.equals(Constants.REQUIRE_BUNDLE)) {
156
				IBundlePrerequisite[] array = new IBundlePrerequisite[elements.length];
157
				for (int i = 0; i < elements.length; i++)
158
					array[i] = new BundlePrerequisite(elements[i]);
159
				return array;
160
			}
161
		} catch (BundleException e) { // do nothing
162
		}
163
		return null;
164
	}
165
166
	public String getLocation() {
167
		URL bundleEntry = bundle.getEntry("/"); //$NON-NLS-1$
168
		try {
169
			bundleEntry = FileLocator.resolve(bundleEntry);
170
		} catch (IOException e) { // do nothing
171
		}
172
		IPath path = new Path(bundleEntry.getFile());
173
		String pathString = path.removeTrailingSeparator().toOSString();
174
		if (pathString.startsWith("file:")) //$NON-NLS-1$
175
			pathString = pathString.substring(5);
176
		if (pathString.endsWith("!")) //$NON-NLS-1$
177
			pathString = pathString.substring(0, pathString.length() - 1);
178
		return pathString;
179
	}
180
181
	public String getVersion() {
182
		return (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
183
	}
184
185
	public int getState() {
186
		return bundle.getState();
187
	}
188
189
	public void start() throws BundleException {
190
		bundle.start();
191
	}
192
193
	public void stop() throws BundleException {
194
		bundle.stop();
195
	}
196
197
	public MultiStatus diagnose() {
198
		PlatformAdmin plaformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
199
		State state = plaformAdmin.getState(false);
200
201
		BundleDescription desc = state.getBundle(bundle.getBundleId());
202
203
		PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin();
204
		VersionConstraint[] unsatisfied = platformAdmin.getStateHelper().getUnsatisfiedConstraints(desc);
205
		ResolverError[] resolverErrors = platformAdmin.getState(false).getResolverErrors(desc);
206
207
		MultiStatus problems = new MultiStatus(PDERuntimePlugin.ID, IStatus.INFO, PDERuntimeMessages.RegistryView_found_problems, null);
208
		for (int i = 0; i < resolverErrors.length; i++) {
209
			if ((resolverErrors[i].getType() & (ResolverError.MISSING_FRAGMENT_HOST | ResolverError.MISSING_GENERIC_CAPABILITY | ResolverError.MISSING_IMPORT_PACKAGE | ResolverError.MISSING_REQUIRE_BUNDLE)) != 0)
210
				continue;
211
			IStatus status = new Status(IStatus.WARNING, PDERuntimePlugin.ID, resolverErrors[i].toString());
212
			problems.add(status);
213
		}
214
215
		for (int i = 0; i < unsatisfied.length; i++) {
216
			IStatus status = new Status(IStatus.WARNING, PDERuntimePlugin.ID, MessageHelper.getResolutionFailureMessage(unsatisfied[i]));
217
			problems.add(status);
218
		}
219
220
		return problems;
221
	}
222
223
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/ExtensionPointAdapter.java (+60 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.impl.local;
12
13
import org.eclipse.core.runtime.IExtension;
14
import org.eclipse.core.runtime.IExtensionPoint;
15
import org.eclipse.pde.internal.runtime.registry.model.*;
16
17
public class ExtensionPointAdapter implements IExtensionPointAdapter {
18
19
	private IExtensionPoint extensionPoint;
20
21
	private IExtensionAdapter[] extensions;
22
23
	public ExtensionPointAdapter(IExtensionPoint extensionPoint) {
24
		this.extensionPoint = extensionPoint;
25
	}
26
27
	protected void createChildren() {
28
		IExtension[] exts = extensionPoint.getExtensions();
29
		IExtensionAdapter[] result = new IExtensionAdapter[exts.length];
30
		for (int i = 0; i < exts.length; i++) {
31
			result[i] = new ExtensionAdapter(exts[i]);
32
		}
33
		extensions = result;
34
	}
35
36
	public IExtensionAdapter[] getExtensions() {
37
		if (extensions == null) {
38
			createChildren();
39
		}
40
41
		return extensions;
42
	}
43
44
	public IModelObject getParent() {
45
		// TODO Auto-generated method stub
46
		return null;
47
	}
48
49
	public String getLabel() {
50
		return extensionPoint.getLabel();
51
	}
52
53
	public String getUniqueIdentifier() {
54
		return extensionPoint.getUniqueIdentifier();
55
	}
56
57
	public String getNamespaceIdentifier() {
58
		return extensionPoint.getNamespaceIdentifier();
59
	}
60
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IAttribute.java (+19 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 interface IAttribute extends IModelObject {
14
	String F_LOCATION = "Location";
15
16
	public String getLabel();
17
18
	String getName();
19
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/BundlePrerequisite.java (+41 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.pde.internal.runtime.registry.model.impl.local;
5
6
import org.eclipse.osgi.util.ManifestElement;
7
import org.eclipse.pde.internal.runtime.registry.model.IBundlePrerequisite;
8
import org.eclipse.pde.internal.runtime.registry.model.IModelObject;
9
import org.osgi.framework.Constants;
10
11
public class BundlePrerequisite implements IBundlePrerequisite {
12
	private ManifestElement underlyingElement;
13
14
	public BundlePrerequisite(ManifestElement element) {
15
		underlyingElement = element;
16
	}
17
18
	public ManifestElement getPrerequisite() {
19
		return underlyingElement;
20
	}
21
22
	public boolean isExported() {
23
		String visibility = underlyingElement.getDirective(Constants.VISIBILITY_DIRECTIVE);
24
		return Constants.VISIBILITY_REEXPORT.equals(visibility);
25
	}
26
27
	public String getLabel() {
28
		String version = underlyingElement.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
29
		String value = underlyingElement.getValue();
30
		if (version == null)
31
			return value;
32
		if (Character.isDigit(version.charAt(0)))
33
			version = '(' + version + ')';
34
		return value + ' ' + version;
35
	}
36
37
	public IModelObject getParent() {
38
		// TODO Auto-generated method stub
39
		return null;
40
	}
41
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/IElement.java (+7 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public interface IElement extends IAttribute {
4
5
	IAttribute[] getElements();
6
7
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/RegistryModelFactory.java (+23 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import java.net.URI;
4
import org.eclipse.pde.internal.runtime.registry.model.impl.local.LocalModel;
5
6
/**
7
 * Produces RegistryModels for URLs. Valid URLs:
8
 * local
9
 * target
10
 * remote://host:port
11
 *
12
 */
13
public class RegistryModelFactory {
14
15
	/**
16
	 * 
17
	 * @param codename
18
	 * @return never returns null
19
	 */
20
	public static IRegistryModel getRegistryModel(URI codename) {
21
		return new LocalModel();
22
	}
23
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/generic/PluginObjectAdapter.java (+25 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.impl.generic;
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/model/IService.java (+9 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
public interface IService extends IModelObject {
4
5
	String[] getClasses();
6
7
	Long getId();
8
9
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/impl/local/BundleLibrary.java (+25 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.pde.internal.runtime.registry.model.impl.local;
5
6
import org.eclipse.osgi.util.ManifestElement;
7
import org.eclipse.pde.internal.runtime.registry.model.IBundleLibrary;
8
import org.eclipse.pde.internal.runtime.registry.model.IModelObject;
9
10
public class BundleLibrary implements IBundleLibrary {
11
	private ManifestElement underlyingElement;
12
13
	public BundleLibrary(ManifestElement element) {
14
		underlyingElement = element;
15
	}
16
17
	public String getLibrary() {
18
		return underlyingElement.getValue();
19
	}
20
21
	public IModelObject getParent() {
22
		// TODO Auto-generated method stub
23
		return null;
24
	}
25
}

Return to bug 243441