1 11 package org.eclipse.jdt.internal.ui.jarpackager; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.resources.IFile; 16 17 import org.eclipse.swt.widgets.Shell; 18 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.jface.viewers.StructuredSelection; 23 24 import org.eclipse.ui.IObjectActionDelegate; 25 import org.eclipse.ui.IWorkbench; 26 import org.eclipse.ui.IWorkbenchPart; 27 import org.eclipse.ui.IWorkbenchPartSite; 28 import org.eclipse.ui.PlatformUI; 29 30 import org.eclipse.jdt.internal.ui.JavaPlugin; 31 32 36 abstract class JarPackageActionDelegate implements IObjectActionDelegate { 37 38 private IStructuredSelection fSelection; 39 private Shell fShell; 40 41 44 protected Shell getShell() { 45 if (fShell != null) 46 return fShell; 47 return JavaPlugin.getActiveWorkbenchShell(); 48 } 49 50 53 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 54 IWorkbenchPartSite site= targetPart.getSite(); 55 fShell= site != null ? site.getShell() : null; 56 } 57 58 61 public void selectionChanged(IAction action, ISelection selection) { 62 if (selection instanceof IStructuredSelection) 63 fSelection= (IStructuredSelection)selection; 64 else 65 fSelection= StructuredSelection.EMPTY; 66 } 67 68 73 protected IFile getDescriptionFile(IStructuredSelection selection) { 74 return (IFile)selection.getFirstElement(); 75 } 76 77 82 protected IFile[] getDescriptionFiles(IStructuredSelection selection) { 83 IFile[] files= new IFile[selection.size()]; 84 Iterator iter= selection.iterator(); 85 int i= 0; 86 while (iter.hasNext()) 87 files[i++]= (IFile)iter.next(); 88 return files; 89 } 90 91 protected IWorkbench getWorkbench() { 92 return PlatformUI.getWorkbench(); 93 } 94 95 protected IStructuredSelection getSelection() { 96 return fSelection; 97 } 98 } 99 | Popular Tags |