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