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.runtime.IProgressMonitor;
15: import org.eclipse.jface.action.Action;
16: import org.eclipse.jface.operation.IRunnableWithProgress;
17: import org.eclipse.jface.wizard.WizardDialog;
18: import org.eclipse.pde.core.IModel;
19: import org.eclipse.pde.internal.ui.PDEPlugin;
20: import org.eclipse.pde.internal.ui.PDEUIMessages;
21: import org.eclipse.ui.PlatformUI;
22:
23: public class SynchronizeVersionsAction extends Action {
24: private FeatureEditor activeEditor;
25:
26: public SynchronizeVersionsAction() {
27: setText(PDEUIMessages.Actions_synchronizeVersions_label);
28: }
29:
30: private void ensureContentSaved() {
31: if (activeEditor.isDirty()) {
32: try {
33: IRunnableWithProgress op = new IRunnableWithProgress() {
34: public void run(IProgressMonitor monitor) {
35: activeEditor.doSave(monitor);
36: }
37: };
38: PlatformUI.getWorkbench().getProgressService().runInUI(
39: PDEPlugin.getActiveWorkbenchWindow(), op,
40: PDEPlugin.getWorkspace().getRoot());
41: } catch (InvocationTargetException e) {
42: PDEPlugin.logException(e);
43: } catch (InterruptedException e) {
44: }
45: }
46: }
47:
48: public void run() {
49: ensureContentSaved();
50: SynchronizeVersionsWizard wizard = new SynchronizeVersionsWizard(
51: activeEditor);
52: WizardDialog dialog = new WizardDialog(PDEPlugin
53: .getActiveWorkbenchShell(), wizard);
54: dialog.open();
55: }
56:
57: public void setActiveEditor(FeatureEditor editor) {
58: this .activeEditor = editor;
59: IModel model = (IModel) editor.getAggregateModel();
60: setEnabled(model.isEditable());
61: }
62: }
|