1 11 package org.eclipse.pde.internal.ui.editor.plugin; 12 import java.lang.reflect.InvocationTargetException ; 13 14 import org.eclipse.core.resources.IResource; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.jface.action.Action; 17 import org.eclipse.jface.operation.IRunnableWithProgress; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.jface.viewers.StructuredSelection; 20 import org.eclipse.jface.window.Window; 21 import org.eclipse.jface.wizard.WizardDialog; 22 import org.eclipse.pde.core.IModel; 23 import org.eclipse.pde.internal.ui.PDEPlugin; 24 import org.eclipse.pde.internal.ui.editor.PDEFormEditor; 25 import org.eclipse.pde.internal.ui.wizards.ResizableWizardDialog; 26 import org.eclipse.pde.internal.ui.wizards.exports.PluginExportWizard; 27 import org.eclipse.ui.PlatformUI; 28 29 32 public class PluginExportAction extends Action { 33 private PDEFormEditor fEditor; 34 public PluginExportAction(PDEFormEditor editor) { 35 fEditor = editor; 36 } 37 public PluginExportAction() { 38 } 39 private void ensureContentSaved() { 40 if (fEditor.isDirty()) { 41 try { 42 IRunnableWithProgress op = new IRunnableWithProgress() { 43 public void run(IProgressMonitor monitor) { 44 fEditor.doSave(monitor); 45 } 46 }; 47 PlatformUI.getWorkbench().getProgressService().runInUI( 48 PDEPlugin.getActiveWorkbenchWindow(), op, 49 PDEPlugin.getWorkspace().getRoot()); 50 } catch (InvocationTargetException e) { 51 PDEPlugin.logException(e); 52 } catch (InterruptedException e) { 53 } 54 } 55 } 56 public void run() { 57 if (fEditor != null) 58 ensureContentSaved(); 59 PluginExportWizard wizard = new PluginExportWizard(); 60 IStructuredSelection selection; 61 IResource resource = null; 62 if (fEditor != null) 63 resource = ((IModel) fEditor.getAggregateModel()) 64 .getUnderlyingResource(); 65 if (resource != null) 66 selection = new StructuredSelection(resource); 67 else 68 selection = new StructuredSelection(); 69 wizard.init(PlatformUI.getWorkbench(), selection); 70 WizardDialog wd = new ResizableWizardDialog(PDEPlugin 71 .getActiveWorkbenchShell(), wizard); 72 wd.create(); 73 int result = wd.open(); 75 notifyResult(result == Window.OK); 76 } 77 } 78 | Popular Tags |