01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.util;
11:
12: import java.util.HashSet;
13:
14: import org.eclipse.core.resources.IProject;
15: import org.eclipse.core.resources.IResource;
16: import org.eclipse.core.runtime.IAdaptable;
17: import org.eclipse.osgi.service.resolver.BundleDescription;
18: import org.eclipse.pde.core.plugin.IPluginModelBase;
19: import org.eclipse.pde.core.plugin.PluginRegistry;
20: import org.eclipse.ui.IWorkingSet;
21: import org.eclipse.ui.IWorkingSetElementAdapter;
22:
23: public class PluginAdapter implements IWorkingSetElementAdapter {
24:
25: /* (non-Javadoc)
26: * @see org.eclipse.ui.IWorkingSetElementAdapter#adaptElements(org.eclipse.ui.IWorkingSet, org.eclipse.core.runtime.IAdaptable[])
27: */
28: public IAdaptable[] adaptElements(IWorkingSet ws,
29: IAdaptable[] elements) {
30: HashSet set = new HashSet();
31: for (int i = 0; i < elements.length; i++) {
32: IResource res = (IResource) elements[i]
33: .getAdapter(IResource.class);
34: if (res == null)
35: continue;
36: IProject proj = res.getProject();
37: IPluginModelBase base = PluginRegistry.findModel(proj);
38: // if project is a plug-in project
39: if (base == null)
40: continue;
41: BundleDescription desc = base.getBundleDescription();
42: String id = (desc != null) ? desc.getSymbolicName() : base
43: .getPluginBase().getId();
44: set.add(new PersistablePluginObject(id));
45: }
46: return (IAdaptable[]) set.toArray(new IAdaptable[set.size()]);
47: }
48:
49: /* (non-Javadoc)
50: * @see org.eclipse.ui.IWorkingSetElementAdapter#dispose()
51: */
52: public void dispose() {
53: }
54:
55: }
|