01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.plugin;
11:
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: /**
30: *
31: */
32: public class PluginExportAction extends Action {
33: private PDEFormEditor fEditor;
34:
35: public PluginExportAction(PDEFormEditor editor) {
36: fEditor = editor;
37: }
38:
39: public PluginExportAction() {
40: }
41:
42: private void ensureContentSaved() {
43: if (fEditor.isDirty()) {
44: try {
45: IRunnableWithProgress op = new IRunnableWithProgress() {
46: public void run(IProgressMonitor monitor) {
47: fEditor.doSave(monitor);
48: }
49: };
50: PlatformUI.getWorkbench().getProgressService().runInUI(
51: PDEPlugin.getActiveWorkbenchWindow(), op,
52: PDEPlugin.getWorkspace().getRoot());
53: } catch (InvocationTargetException e) {
54: PDEPlugin.logException(e);
55: } catch (InterruptedException e) {
56: }
57: }
58: }
59:
60: public void run() {
61: if (fEditor != null)
62: ensureContentSaved();
63: PluginExportWizard wizard = new PluginExportWizard();
64: IStructuredSelection selection;
65: IResource resource = null;
66: if (fEditor != null)
67: resource = ((IModel) fEditor.getAggregateModel())
68: .getUnderlyingResource();
69: if (resource != null)
70: selection = new StructuredSelection(resource);
71: else
72: selection = new StructuredSelection();
73: wizard.init(PlatformUI.getWorkbench(), selection);
74: WizardDialog wd = new ResizableWizardDialog(PDEPlugin
75: .getActiveWorkbenchShell(), wizard);
76: wd.create();
77: //wd.getShell().setSize(450, 600);
78: int result = wd.open();
79: notifyResult(result == Window.OK);
80: }
81: }
|