Skip to main content
summaryrefslogtreecommitdiffstats
blob: a3c0345c3c75039202c87eb8ab01f7e7b9deee9d (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*******************************************************************************
 * Copyright (c) 2000, 2004 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 Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.filebuffers;


import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.jobs.ISchedulingRule;


/**
 * A file buffer represents a file that can be edited by more than one client.
 * Editing is session oriented. This means that editing is a sequence of
 * modification steps. The start of the sequence and the end of the sequence are
 * explicitly indicated. There are no time constraints connected with the
 * sequence of modification steps. A file buffer reifies editing sessions and
 * allows them to interleave.
 * <p>
 * It is not specified whether simultaneous editing sessions can be owned by
 * different threads.
 * </p>
 * <p>
 * Clients are not supposed to implement that interface. Instances of this type
 * are obtained from a {@link org.eclipse.core.filebuffers.IFileBufferManager}.
 * </p>
 * 
 * @since 3.0
 */
public interface IFileBuffer {
	
	/**
	 * Returns the location of this file buffer.
	 * <p>
	 * The location is either a full path of a workspace resource or an
	 * absolute path in the local file system.
	 * </p>
	 * 
	 * @return the location of this file buffer
	 */
	IPath getLocation();
	
	/**
	 * Returns whether this file buffer is shared by more than one client.
	 * 
	 * @return <code>true</code> if this file buffer is shared by more than one client
	 */
	boolean isShared();

	/**
	 * Returns whether this file buffer is synchronized with the file system. This is when
	 * the file buffer's underlying file is in synchronization with the file system and the file buffer
	 * has been initialized after the underlying files has been modified the last time.
	 * 
	 * @return <code>true</code> if the file buffer is synchronized with the file system
	 */
	boolean isSynchronized();
	
	/**
	 * Returns the modification stamp of the file underlying this file buffer.
	 * 
	 * @return the modification stamp of the file underlying this file buffer
	 */
	long getModificationStamp();
	
	/**
	 * Returns whether this file buffer is commitable. This is the case when the
	 * file buffer's state has been successfully validated.
	 * <p>
	 * Not yet for public use. API under construction.
	 * 
	 * @return <code>true</code> if the file buffer is commitable,
	 *         <code>false</code> otherwise
	 * @since 3.1
	 */
	boolean isCommitable();
	
	/**
	 * Computes the scheduling rule that is required for committing a changed buffer.
	 * <p>
	 * Not yet for public use. API under construction.
	 * 
	 * @return the commit scheduling rule or <code>null</code>
	 * @since 3.1
	 */
	ISchedulingRule computeCommitRule();
	
	/**
	 * Commits this file buffer by changing the contents of the underlying file to
	 * the contents of this file buffer. After that call, <code>isDirty</code> 
	 * returns <code>false</code> and <code>isSynchronized</code> returns
	 * <code>true</code>.
	 * 
	 * @param monitor the progress monitor
	 * @param overwrite indicates whether the underlying file should be overwritten if it is not synchronized with the file system
	 * @throws CoreException if writing or accessing the underlying file fails
	 */
	void commit(IProgressMonitor monitor, boolean overwrite) throws CoreException;
	
	/**
	 * Reverts the contents of this file buffer to the content of its underlying file. After 
	 * that call successfully returned, <code>isDirty</code> returns <code>false</code> and
	 * <code>isSynchronized</code> returns <code>true</code>.
	 * 
	 * @param monitor the progress monitor
	 * @throws CoreException  if reading or accessing the underlying file fails
	 */
	void revert(IProgressMonitor monitor) throws CoreException;
	
	/**
	 * Returns whether changes have been applied to this file buffer since initialization, or the most
	 * recent <code>revert</code> or <code>commit</code> call.
	 * 
	 * @return <code>true</code> if changes have been applied to this buffer
	 */
	boolean isDirty();
	
	/**
	 * Sets the dirty state of the file buffer to the given value. A direct
	 * subsequent call to <code>isDirty</code> returns the previously set 
	 * value.
	 * <p>
	 * Not yet for public use. API under construction.
	 * 
	 * @param isDirty <code>true</code> if the buffer should be marked dirty, <code>false</code> otherwise
	 * @since 3.1
	 */
	void setDirty(boolean isDirty);
		
	/**
	 * Computes the scheduling rule that is required for validating the state of the buffer.
	 * <p>
	 * Not yet for public use. API under construction.
	 * 
	 * @return the validate state scheduling rule or <code>null</code>
	 * @since 3.1
	 */
	ISchedulingRule computeValidateStateRule();
	
	/**
	 * Validates the state of this file buffer and tries to bring the buffer's
	 * underlying file into a state in which it can be modified. If state
	 * validation is not supported this operation does nothing.
	 * 
	 * @param monitor the progress monitor
	 * @param computationContext the context in which the validation is performed, e.g., a SWT shell
	 * @exception CoreException if the underlying file can not be accessed to it's state cannot be changed
	 */
	void validateState(IProgressMonitor monitor, Object computationContext) throws CoreException;
	
	/**
	 * Returns whether the state of this file buffer has been validated. If
	 * state validation is not supported this method always returns <code>true</code>.
	 * 
	 * @return <code>true</code> if the state has been validated, <code>false</code> otherwise
	 */
	boolean isStateValidated();
	
	/**
	 * Resets state validation. If state validation is supported, <code>isStateValidated</code>
	 * afterwards returns <code>false</code> until the state is revalidated.
	 */
	void resetStateValidation();
	
	/**
	 * Returns the status of this file buffer. This is the result of the last operation performed on this file buffer or
	 * internally initiated by this file buffer.
	 * 
	 * @return the status of this file buffer
	 */
	IStatus getStatus();
	
	/**
	 * The caller requests that the synchronization context is used to
	 * synchronize this file buffer with its underlying file.
	 * <p>
	 * Not yet for public use. API under construction.
	 * 
	 * @since 3.1
	 */
	void requestSynchronizationContext();

	/**
	 * The caller no longer requests the synchronization context for this file
	 * buffer.
	 * <p>
	 * Not yet for public use. API under construction.
	 * 
	 * @since 3.1
	 */
	void releaseSynchronizationContext();
	
	/**
	 * Returns whether a synchronization context has been requested for this
	 * file buffer and not yet released.
	 * <p>
	 * Not yet for public use. API under construction.
	 * 
	 * @return <code>true</code> if a synchronization context is requested,
	 *         <code>false</code> otherwise
	 * @since 3.1
	 */
	boolean isSynchronizationContextRequested();

	/**
	 * Returns the content type of this file buffer or <code>null</code>
	 * if none could be determined. If the file buffer is dirty, the
	 * returned content type is determined by the buffer's dirty state.
	 * <p>
	 * Not yet for public use. API under construction.
	 * </p>
	 * 
	 * @return the content type or <code>null</code>
	 * @throws CoreException if reading or accessing the underlying file
	 *                 fails
	 * @since 3.1
	 */
	IContentType getContentType() throws CoreException;
}

Back to the top