01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 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.ui.internal.texteditor.quickdiff;
11:
12: import org.eclipse.jface.text.BadLocationException;
13: import org.eclipse.jface.text.source.ILineDiffInfo;
14: import org.eclipse.jface.text.source.ILineDiffer;
15:
16: import org.eclipse.ui.texteditor.ITextEditor;
17:
18: /**
19: * Action that will revert a line in the currently displayed document to the state in the
20: * reference document.
21: *
22: * @since 3.0
23: */
24: public class RevertLineAction extends QuickDiffRestoreAction {
25:
26: /** The line to be restored. Set in <code>update()</code>. */
27: private int fLine;
28:
29: /**
30: * Creates a new instance.
31: *
32: * @param editor the editor this action belongs to
33: * @param isRulerAction <code>true</code> if this is a ruler action
34: */
35: public RevertLineAction(ITextEditor editor, boolean isRulerAction) {
36: super ("RevertLineAction.", editor, isRulerAction); //$NON-NLS-1$
37: }
38:
39: /*
40: * @see org.eclipse.ui.internal.texteditor.quickdiff.QuickDiffRestoreAction#computeEnablement()
41: */
42: public boolean computeEnablement() {
43: if (!super .computeEnablement())
44: return false;
45:
46: fLine = getLastLine();
47: if (fLine == -1)
48: return false;
49: ILineDiffer differ = getDiffer();
50: if (differ == null)
51: return false;
52: ILineDiffInfo info = differ.getLineInfo(fLine);
53: if (info == null
54: || info.getChangeType() == ILineDiffInfo.UNCHANGED)
55: return false;
56:
57: if (info.getChangeType() == ILineDiffInfo.ADDED)
58: setText(QuickDiffMessages.RevertLineAction_delete_label);
59: else
60: setText(QuickDiffMessages.RevertLineAction_label);
61: return true;
62: }
63:
64: /*
65: * @see org.eclipse.ui.internal.editors.quickdiff.QuickDiffRestoreAction#runCompoundChange()
66: */
67: public void runCompoundChange() {
68: if (!isEnabled())
69: return;
70: ILineDiffer differ = getDiffer();
71: if (differ != null) {
72: try {
73: differ.revertLine(fLine);
74: } catch (BadLocationException e) {
75: setStatus(e.getMessage());
76: }
77: }
78: }
79: }
|