Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 70f2bc2d32a3f217089d34b5e4b683a5e47d76f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     
 *******************************************************************************/
package org.eclipse.wst.sse.core.internal.undo;



import org.eclipse.emf.common.command.AbstractCommand;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.wst.sse.core.internal.Logger;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;


public class StructuredTextCommandImpl extends AbstractCommand implements StructuredTextCommand {

	protected IDocument fDocument = null; // needed for updating the text
	protected String fTextDeleted = null;
	protected int fTextEnd = -1;
	protected String fTextInserted = null;
	protected int fTextStart = -1;

	/**
	 * We have no-arg constructor non-public to force document to be specfied.
	 *  
	 */
	protected StructuredTextCommandImpl() {
		super();
	}

	public StructuredTextCommandImpl(IDocument document) {
		this();
		fDocument = document; // needed for updating the text
	}

	public void execute() {
	}

	/**
	 * getTextDeleted method comment.
	 */
	public java.lang.String getTextDeleted() {
		return fTextDeleted;
	}

	/**
	 * textEnd is the same as (textStart + textInserted.length())
	 */
	public int getTextEnd() {
		return fTextEnd;
	}

	/**
	 * getTextInserted method comment.
	 */
	public java.lang.String getTextInserted() {
		return fTextInserted;
	}

	/**
	 * getTextStart method comment.
	 */
	public int getTextStart() {
		return fTextStart;
	}

	protected boolean prepare() {
		return true;
	}

	public void redo() {
		if (fDocument instanceof IStructuredDocument) {
			// note: one of the few places we programatically ignore read-only
			// settings
			((IStructuredDocument) fDocument).replaceText(this, fTextStart, fTextDeleted.length(), fTextInserted, true);
		} else {
			try {
				fDocument.replace(fTextStart, fTextDeleted.length(), fTextInserted);
			} catch (BadLocationException e) {
				// assumed impossible, for now
				Logger.logException(e);
			}
		}
	}

	/**
	 * setTextDeleted method comment.
	 */
	public void setTextDeleted(java.lang.String textDeleted) {
		fTextDeleted = textDeleted;
	}

	/**
	 * setTextEnd method comment.
	 */
	public void setTextEnd(int textEnd) {
		fTextEnd = textEnd;
	}

	/**
	 * setTextInserted method comment.
	 */
	public void setTextInserted(java.lang.String textInserted) {
		fTextInserted = textInserted;
	}

	/**
	 * setTextStart method comment.
	 */
	public void setTextStart(int textStart) {
		fTextStart = textStart;
	}

	public void undo() {
		if (fDocument instanceof IStructuredDocument) {
			// note: one of the few places we programatically ignore read-only
			// settings
			((IStructuredDocument) fDocument).replaceText(this, fTextStart, fTextInserted.length(), fTextDeleted, true);
		} else {
			try {
				fDocument.replace(fTextStart, fTextInserted.length(), fTextDeleted);
			} catch (BadLocationException e) {
				// assumed impossible, for now
				Logger.logException(e);
			}
		}
	}
}

Back to the top