1 11 package org.eclipse.jdt.internal.ui.actions; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.action.IAction; 15 import org.eclipse.jface.viewers.ISelection; 16 import org.eclipse.jface.viewers.ISelectionChangedListener; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 import org.eclipse.jface.viewers.SelectionChangedEvent; 19 import org.eclipse.jface.wizard.WizardDialog; 20 21 import org.eclipse.ui.IImportWizard; 22 import org.eclipse.ui.IObjectActionDelegate; 23 import org.eclipse.ui.IWorkbenchPart; 24 import org.eclipse.ui.IWorkbenchWindow; 25 import org.eclipse.ui.PlatformUI; 26 27 import org.eclipse.jdt.core.IClasspathEntry; 28 import org.eclipse.jdt.core.IPackageFragmentRoot; 29 import org.eclipse.jdt.core.JavaModelException; 30 31 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 32 import org.eclipse.jdt.internal.ui.JavaPlugin; 33 import org.eclipse.jdt.internal.ui.jarimport.JarImportWizard; 34 35 40 public class JarImportWizardAction extends Action implements IObjectActionDelegate, ISelectionChangedListener { 41 42 43 public static final int SIZING_WIZARD_HEIGHT= 520; 44 45 46 public static final int SIZING_WIZARD_WIDTH= 470; 47 48 49 private IStructuredSelection fSelection= null; 50 51 52 private IWorkbenchPart fWorkbenchPart= null; 53 54 57 public void run() { 58 run(this); 59 } 60 61 64 public void run(final IAction action) { 65 if (fWorkbenchPart == null || fSelection == null) 66 return; 67 final IImportWizard wizard= new JarImportWizard(false); 68 final IWorkbenchWindow window= fWorkbenchPart.getSite().getWorkbenchWindow(); 69 wizard.init(window.getWorkbench(), fSelection); 70 final WizardDialog dialog= new WizardDialog(window.getShell(), wizard); 71 dialog.create(); 72 dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), SIZING_WIZARD_HEIGHT); 73 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IJavaHelpContextIds.JARIMPORT_WIZARD_PAGE); 74 dialog.open(); 75 } 76 77 80 public void selectionChanged(final IAction action, final ISelection selection) { 81 fSelection= null; 82 if (selection instanceof IStructuredSelection) { 83 final IStructuredSelection structured= (IStructuredSelection) selection; 84 if (structured.size() == 1) { 85 final Object element= structured.getFirstElement(); 86 if (element instanceof IPackageFragmentRoot) { 87 final IPackageFragmentRoot root= (IPackageFragmentRoot) element; 88 try { 89 final IClasspathEntry entry= root.getRawClasspathEntry(); 90 if (entry != null) { 91 if (JarImportWizard.isValidClassPathEntry(entry) && JarImportWizard.isValidJavaProject(root.getJavaProject())) 92 fSelection= structured; 93 } 94 } catch (JavaModelException exception) { 95 JavaPlugin.log(exception); 96 } 97 } 98 } 99 } 100 action.setEnabled(fSelection != null); 101 } 102 103 106 public void selectionChanged(final SelectionChangedEvent event) { 107 selectionChanged(this, event.getSelection()); 108 } 109 110 113 public void setActivePart(final IAction action, final IWorkbenchPart part) { 114 fWorkbenchPart= part; 115 } 116 } 117 | Popular Tags |