Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 20cee79b88a0864fbc30c0177b0e0e3c53a5246f (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved.   This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* 
* Contributors:
*   IBM - Initial API and implementation
*   Jens Lukowski/Innoopract - initial renaming/restructuring
* 
*/
package org.eclipse.wst.sse.core.text;



import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.wst.encoding.EncodingMemento;
import org.eclipse.wst.sse.core.document.IEncodedDocument;
import org.eclipse.wst.sse.core.events.IModelAboutToBeChangedListener;
import org.eclipse.wst.sse.core.events.IStructuredDocumentListener;
import org.eclipse.wst.sse.core.events.NewModelEvent;
import org.eclipse.wst.sse.core.events.StructuredDocumentEvent;
import org.eclipse.wst.sse.core.parser.RegionParser;



/**
 * A IStructuredDocument is a collection of StructuredDocumentRegions. Its called "flat" because its contents
 * by design do not contain much structural information beyond containment.
 * 
 */
public interface IStructuredDocument extends IEncodedDocument, IAdaptable {

	void addModelAboutToBeChangedListener(IModelAboutToBeChangedListener listener);

	/**
	 * The StructuredDocumentListners and ModelChagnedListeners are very similar. 
	 * They both receive identical events. The difference is the timing.
	 * The "pure" StructuredDocumentListners are notified after the structuredDocument has
	 * been changed, but before other, related models may have been changed
	 * such as the Structural Model. The Structural model is in fact itself a
	 * "pure" StructuredDocumentListner. The ModelChangedListeners can rest assured
	 * that all models and data have been updated from the change by the tiem
	 * they are notified. This is especially important for the text widget, for example,
	 * which may rely on both structuredDocument and structural model information. 
	 */
	void addModelChangedListener(IStructuredDocumentListener listener);

	/**
	 * The StructuredDocumentListners and ModelChagnedListeners are very similar. 
	 * They both receive identical events. The difference is the timing.
	 * The "pure" StructuredDocumentListners are notified after the structuredDocument has
	 * been changed, but before other, related models may have been changed
	 * such as the Structural Model. The Structural model is in fact itself a
	 * "pure" StructuredDocumentListner. The ModelChangedListeners can rest assured
	 * that all models and data have been updated from the change by the tiem
	 * they are notified. This is especially important for the text widget, for example,
	 * which may rely on both structuredDocument and structural model information. 
	 */
	void addModelChangingListener(IStructuredDocumentListener listener);

	org.eclipse.wst.sse.core.text.IStructuredDocumentRegion getFirstStructuredDocumentRegion();

	org.eclipse.wst.sse.core.text.IStructuredDocumentRegion getLastStructuredDocumentRegion();

	/**
	 * This can be considered the preferred delimiter.
	 */
	public String getLineDelimiter();

	public void setLineDelimiter(String delimiter);

	int getLineOfOffset(int offset); // throws SourceEditingException;

	IStructuredDocumentRegion getRegionAtCharacterOffset(int offset);

	IStructuredDocumentRegionList getRegionList();

	String getText();

	void removeModelAboutToBeChangedListener(IModelAboutToBeChangedListener listener);

	void removeModelChangedListener(IStructuredDocumentListener listener);

	void removeModelChangingListener(IStructuredDocumentListener listener);

	/**
	 * One of the APIs to manipulate the IStructuredDocument.
	 *
	 * replaceText replaces the text from oldStart to oldEnd with the new text
	 * found in the requestedChange string. If oldStart and oldEnd are equal,
	 * it is an insertion request. If requestedChange is null (or empty) it
	 * is a delete request. Otherwise it is a replace request.
	 */
	StructuredDocumentEvent replaceText(Object source, int oldStart, int replacementLength, String requestedChange);

	/**
	 * One of the APIs to manipulate the IStructuredDocument in terms of Text.
	 *
	 * The setText method replaces all text in the model.
	 */
	NewModelEvent setText(Object requester, String allText);

	/**
	 * The parser is now required on constructor, so there are occasions
	 * it needs to be retrieved, such as to be initialized by EmbeddedContentType
	 */
	RegionParser getParser();

	/**
	 * newInstance is similar to clone, except it contains
	 * no data. One important thing to duplicate is the parser, 
	 * with the parser correctly "cloned", including its tokeninzer, 
	 * block tags, etc. 
	 * 
	 * NOTE: even after obtaining a 'newInstance' the client may have to 
	 * do some initialization, for example, it may need to add its own 
	 * model listeners. Or, as another example, if the IStructuredDocument has a parser
	 * of type StructuredDocumentRegionParser, then the client may need to add its own
	 * StructuredDocumentRegionHandler to that parser, if it is in fact needed.
	 */
	IStructuredDocument newInstance();

	/**
	 * This method is to remember info about the encoding
	 * When the resource was last loaded or saved. Note: 
	 * it is not kept "current", that is, can not be 
	 * depended on blindly to reflect what encoding to use.
	 * For that, must go through the normal rules expressed in 
	 * Loaders and Dumpers.
	 */

	EncodingMemento getEncodingMemento();

	/**
	 * This method is to remember info about the encoding
	 * When the resource was last loaded or saved. Note: 
	 * it is not kept "current", that is, can not be 
	 * depended on blindly to reflect what encoding to use.
	 * For that, must go through the normal rules expressed in 
	 * Loaders and Dumpers.
	 */
	void setEncodingMemento(EncodingMemento encodingMemento);


	/**
	 * Note: this method was made public, and part of the 
	 * interface, for easier testing. Clients normally never
	 * manipulate the reparser directly (nor should they need
	 * to).
	 */
	IStructuredTextReParser getReParser();

	/**
	 * returns true if any portion of startOffset to length is readonly
	 * @param startOffset
	 * @param length
	 * @return
	 */
	boolean containsReadOnly(int startOffset, int length);

	/**
	 * causes that portion of the document from startOffset to length to 
	 * be marked as readonly. Note that if this range overlaps with some 
	 * other region with is readonly, the regions are effectivly combined.
	 * @param startOffset
	 * @param length
	 */
	void makeReadOnly(int startOffset, int length);

	/**
	 * this API ensures that any portion of the document within startOff
	 * to length is not readonly (that is, that its editable). Note that if 
	 * the range overlaps with other readonly regions, those other readonly 
	 * regions will be adjusted. 
	 * @param startOffset
	 * @param length
	 */
	void clearReadOnly(int startOffset, int length);

	/**
	 * 
	 */
	void fireNewDocument(Object requester);
}

Back to the top