KickJava   Java API By Example, From Geeks To Geeks.

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


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.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     public SynchronizeVersionsAction() {
26         setText(PDEUIMessages.Actions_synchronizeVersions_label);
27     }
28     private void ensureContentSaved() {
29         if (activeEditor.isDirty()) {
30             try {
31                 IRunnableWithProgress op = new IRunnableWithProgress() {
32                     public void run(IProgressMonitor monitor) {
33                         activeEditor.doSave(monitor);
34                     }
35                 };
36                 PlatformUI.getWorkbench().getProgressService().runInUI(
37                         PDEPlugin.getActiveWorkbenchWindow(), op,
38                         PDEPlugin.getWorkspace().getRoot());
39             } catch (InvocationTargetException JavaDoc e) {
40                 PDEPlugin.logException(e);
41             } catch (InterruptedException JavaDoc e) {
42             }
43         }
44     }
45
46     public void run() {
47         ensureContentSaved();
48         SynchronizeVersionsWizard wizard = new SynchronizeVersionsWizard(
49                 activeEditor);
50         WizardDialog dialog = new WizardDialog(PDEPlugin
51                 .getActiveWorkbenchShell(), wizard);
52         dialog.open();
53     }
54     public void setActiveEditor(FeatureEditor editor) {
55         this.activeEditor = editor;
56         IModel model = (IModel) editor.getAggregateModel();
57         setEnabled(model.isEditable());
58     }
59 }
60
Popular Tags