KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > EditorBuildFeatureAction


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.feature;
12 import java.lang.reflect.InvocationTargetException JavaDoc;
13
14 import org.eclipse.core.resources.IFile;
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.wizard.WizardDialog;
21 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
22 import org.eclipse.pde.internal.ui.PDEPlugin;
23 import org.eclipse.pde.internal.ui.PDEUIMessages;
24 import org.eclipse.pde.internal.ui.wizards.ResizableWizardDialog;
25 import org.eclipse.pde.internal.ui.wizards.exports.FeatureExportWizard;
26 import org.eclipse.ui.PlatformUI;
27 public class EditorBuildFeatureAction extends Action {
28     private FeatureEditor activeEditor;
29     private IFile featureFile;
30     public EditorBuildFeatureAction() {
31         setText(PDEUIMessages.FeatureEditor_BuildAction_label);
32     }
33     private void ensureContentSaved() {
34         if (activeEditor.isDirty()) {
35             try {
36                 IRunnableWithProgress op = new IRunnableWithProgress() {
37                     public void run(IProgressMonitor monitor) {
38                         activeEditor.doSave(monitor);
39                     }
40                 };
41                 PlatformUI.getWorkbench().getProgressService().runInUI(
42                         PDEPlugin.getActiveWorkbenchWindow(), op,
43                         PDEPlugin.getWorkspace().getRoot());
44
45             } catch (InvocationTargetException JavaDoc e) {
46                 PDEPlugin.logException(e);
47             } catch (InterruptedException JavaDoc e) {
48             }
49         }
50     }
51     public void run() {
52         ensureContentSaved();
53         FeatureExportWizard wizard = new FeatureExportWizard();
54         IStructuredSelection selection;
55         if (featureFile != null)
56             selection = new StructuredSelection(featureFile);
57         else
58             selection = new StructuredSelection();
59         wizard.init(PlatformUI.getWorkbench(), selection);
60         WizardDialog wd = new ResizableWizardDialog(PDEPlugin
61                 .getActiveWorkbenchShell(), wizard);
62         wd.create();
63         wd.open();
64     }
65     public void setActiveEditor(FeatureEditor editor) {
66         this.activeEditor = editor;
67         IFeatureModel model = (IFeatureModel) editor.getAggregateModel();
68         featureFile = (IFile) model.getUnderlyingResource();
69         setEnabled(model.isEditable());
70     }
71 }
72
Popular Tags