KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > PluginExportAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.plugin;
12 import java.lang.reflect.InvocationTargetException JavaDoc;
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     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 JavaDoc e) {
51                 PDEPlugin.logException(e);
52             } catch (InterruptedException JavaDoc 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         //wd.getShell().setSize(450, 600);
74
int result = wd.open();
75         notifyResult(result == Window.OK);
76     }
77 }
78
Popular Tags