1 11 package org.eclipse.pde.internal.ui.view; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.jface.action.Action; 19 import org.eclipse.jface.viewers.ISelection; 20 import org.eclipse.jface.viewers.ISelectionProvider; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.jface.viewers.StructuredSelection; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.internal.core.ModelEntry; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.ui.IViewPart; 27 import org.eclipse.ui.IWorkbenchPage; 28 import org.eclipse.ui.PartInitException; 29 import org.eclipse.ui.part.ISetSelectionTarget; 30 31 public class ShowInWorkspaceAction extends Action { 32 private String viewId; 33 private ISelectionProvider provider; 34 35 38 public ShowInWorkspaceAction(String viewId, ISelectionProvider provider) { 39 this.viewId = viewId; 40 this.provider = provider; 41 } 42 43 47 protected ShowInWorkspaceAction(String text) { 48 super(text); 49 } 50 51 public boolean isApplicable() { 52 IStructuredSelection selection = (IStructuredSelection) provider.getSelection(); 53 if (selection.isEmpty()) 54 return false; 55 for (Iterator iter = selection.iterator(); iter.hasNext();) { 56 Object obj = iter.next(); 57 if (!(obj instanceof ModelEntry)) 58 return false; 59 ModelEntry entry = (ModelEntry) obj; 60 IPluginModelBase model = entry.getActiveModel(); 61 if (model.getUnderlyingResource() == null) 62 return false; 63 } 64 return true; 65 } 66 67 public void run() { 68 List v = collectResources(); 69 IWorkbenchPage page = PDEPlugin.getActivePage(); 70 try { 71 IViewPart view = page.showView(viewId); 72 if (view instanceof ISetSelectionTarget) { 73 ISelection selection = new StructuredSelection(v); 74 ((ISetSelectionTarget) view).selectReveal(selection); 75 } 76 } catch (PartInitException e) { 77 PDEPlugin.logException(e); 78 } 79 } 80 81 private List collectResources() { 82 ArrayList list = new ArrayList (); 83 IStructuredSelection selection = (IStructuredSelection)provider.getSelection(); 84 if (selection.isEmpty()) 85 return list; 86 for (Iterator iter = selection.iterator(); iter.hasNext();) { 87 Object obj = iter.next(); 88 if (obj instanceof ModelEntry) { 89 ModelEntry entry = (ModelEntry) obj; 90 IPluginModelBase model = entry.getActiveModel(); 91 IResource resource = model.getUnderlyingResource(); 92 if (resource != null) 93 list.add(resource); 94 } 95 96 } 97 return list; 98 } 99 } 100 | Popular Tags |