KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > quickdiff > RevertLineAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ui.internal.texteditor.quickdiff;
12
13
14 import org.eclipse.jface.text.BadLocationException;
15 import org.eclipse.jface.text.source.ILineDiffInfo;
16 import org.eclipse.jface.text.source.ILineDiffer;
17
18 import org.eclipse.ui.texteditor.ITextEditor;
19
20 /**
21  * Action that will revert a line in the currently displayed document to the state in the
22  * reference document.
23  *
24  * @since 3.0
25  */

26 public class RevertLineAction extends QuickDiffRestoreAction {
27
28     /** The line to be restored. Set in <code>update()</code>. */
29     private int fLine;
30
31     /**
32      * Creates a new instance.
33      *
34      * @param editor the editor this action belongs to
35      * @param isRulerAction <code>true</code> if this is a ruler action
36      */

37     public RevertLineAction(ITextEditor editor, boolean isRulerAction) {
38         super("RevertLineAction.", editor, isRulerAction); //$NON-NLS-1$
39
}
40
41     /*
42      * @see org.eclipse.ui.internal.texteditor.quickdiff.QuickDiffRestoreAction#computeEnablement()
43      */

44     public boolean computeEnablement() {
45         if (!super.computeEnablement())
46             return false;
47
48         fLine= getLastLine();
49         if (fLine == -1)
50             return false;
51         ILineDiffer differ= getDiffer();
52         if (differ == null)
53             return false;
54         ILineDiffInfo info= differ.getLineInfo(fLine);
55         if (info == null || info.getChangeType() == ILineDiffInfo.UNCHANGED)
56             return false;
57
58         if (info.getChangeType() == ILineDiffInfo.ADDED)
59             setText(QuickDiffMessages.RevertLineAction_delete_label);
60         else
61             setText(QuickDiffMessages.RevertLineAction_label);
62         return true;
63     }
64
65     /*
66      * @see org.eclipse.ui.internal.editors.quickdiff.QuickDiffRestoreAction#runCompoundChange()
67      */

68     public void runCompoundChange() {
69         if (!isEnabled())
70             return;
71         ILineDiffer differ= getDiffer();
72         if (differ != null) {
73             try {
74                 differ.revertLine(fLine);
75             } catch (BadLocationException e) {
76                 setStatus(e.getMessage());
77             }
78         }
79     }
80 }
81
Popular Tags