Debian Codegraph @

plugins/org.eclipse.emf.edit.ui/src/org/eclipse/emf/edit/ui/action/RevertAction.java

raw
1 /*
2 * Copyright (c) Eclipse contributors and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 */
8 package org.eclipse.emf.edit.ui.action;
9
10
11 import org.eclipse.emf.edit.ui.EMFEditUIPlugin;
12 import org.eclipse.emf.edit.ui.util.IRevertablePart;
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.ui.IWorkbenchPart;
15
16
17 /**
18 * An action for {@link IRevertablePart#doRevert() reverting} a workbench part to its saved state.
19 *
20 * @since 2.14
21 */
22 public final class RevertAction extends Action
23 {
24 /**
25 * The current associated revertable part.
26 * @see #setActiveWorkbenchPart(IWorkbenchPart)
27 */
28 private IRevertablePart revertablePart;
29
30 public RevertAction()
31 {
32 super(EMFEditUIPlugin.INSTANCE.getString("_UI_Revert_menu_item"));
33 }
34
35 @Override
36 public void run()
37 {
38 if (revertablePart != null)
39 {
40 revertablePart.doRevert();
41 }
42 }
43
44 /**
45 * Sets the current active workbench part.
46 * @param workbenchPart the current active workbench part.
47 * @see EditingDomainActionBarContributor#activate()
48 * @see EditingDomainActionBarContributor#deactivate()
49 */
50 public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart)
51 {
52 if (workbenchPart instanceof IRevertablePart)
53 {
54 this.revertablePart = (IRevertablePart)workbenchPart;
55 setEnabled(revertablePart.isDirty());
56 }
57 else
58 {
59 this.revertablePart = null;
60 setEnabled(false);
61 }
62 }
63
64 /**
65 * Updates the action.
66 *
67 * @see EditingDomainActionBarContributor#update()
68 */
69 public void update()
70 {
71 setEnabled(revertablePart != null && revertablePart.isDirty());
72 }
73 }