KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > util > PluginAdapter


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

11 package org.eclipse.pde.internal.ui.util;
12 import java.util.HashSet JavaDoc;
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, IAdaptable[] elements) {
29         HashSet JavaDoc set = new HashSet JavaDoc();
30         for (int i = 0; i < elements.length; i++) {
31             IResource res = (IResource)elements[i].getAdapter(IResource.class);
32             if (res == null)
33                 continue;
34             IProject proj = res.getProject();
35             IPluginModelBase base = PluginRegistry.findModel(proj);
36             // if project is a plug-in project
37
if (base == null)
38                 continue;
39             BundleDescription desc = base.getBundleDescription();
40             String JavaDoc id = (desc != null) ? desc.getSymbolicName() : base.getPluginBase().getId();
41             set.add(new PersistablePluginObject(id));
42         }
43         return (IAdaptable[]) set.toArray(new IAdaptable[set.size()]);
44     }
45
46     /* (non-Javadoc)
47      * @see org.eclipse.ui.IWorkingSetElementAdapter#dispose()
48      */

49     public void dispose() {
50     }
51
52 }
53
Popular Tags