use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.
the class FileBufferCreation method test7_location.
/*
* Tests the creation of a file buffer for a non-existing file.
*/
@Test
public void test7_location() throws Exception {
IPath path = FileBuffersTestPlugin.getDefault().getStateLocation();
path = path.append("NonExistingFile");
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(path, LocationKind.LOCATION, null);
ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.LOCATION);
Assert.assertNotNull(buffer);
IDocument document = buffer.getDocument();
Assert.assertNotNull(document);
Assert.assertTrue("".equals(document.get()));
assertSame(buffer, manager.getTextFileBuffer(document));
manager.disconnect(path, LocationKind.LOCATION, null);
assertNull(manager.getTextFileBuffer(path, LocationKind.LOCATION));
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.
the class FileBufferCreation method test7.
/*
* Tests the creation of a file buffer for a non-existing file.
*/
@Test
public void test7() throws Exception {
IPath path = FileBuffersTestPlugin.getDefault().getStateLocation();
path = path.append("NonExistingFile");
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(path, LocationKind.NORMALIZE, null);
ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.NORMALIZE);
Assert.assertNotNull(buffer);
IDocument document = buffer.getDocument();
Assert.assertNotNull(document);
Assert.assertTrue("".equals(document.get()));
assertSame(buffer, manager.getTextFileBuffer(document));
manager.disconnect(path, LocationKind.NORMALIZE, null);
assertNull(manager.getTextFileBuffer(path, LocationKind.NORMALIZE));
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.
the class TextFileDocumentProvider method createFileInfo.
/**
* Creates and returns the file info object
* for the given element.
* <p>
* Subclasses which extend {@link org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo}
* will probably have to extend this method as well.
* </p>
*
* @param element the element
* @return a file info object of type <code>FileInfo</code>
* or <code>null</code> if none can be created
* @throws CoreException if the file info object could not successfully be created
*/
protected FileInfo createFileInfo(Object element) throws CoreException {
if (!(element instanceof IAdaptable))
return null;
IAdaptable adaptable = (IAdaptable) element;
IFile file = null;
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer fileBuffer = null;
LocationKind locationKind = null;
file = adaptable.getAdapter(IFile.class);
if (file != null) {
IPath location = file.getFullPath();
locationKind = LocationKind.IFILE;
manager.connect(location, locationKind, getProgressMonitor());
fileBuffer = manager.getTextFileBuffer(location, locationKind);
} else {
ILocationProvider provider = adaptable.getAdapter(ILocationProvider.class);
if (provider instanceof ILocationProviderExtension) {
URI uri = ((ILocationProviderExtension) provider).getURI(element);
if (ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri).length == 0) {
IFileStore fileStore = EFS.getStore(uri);
manager.connectFileStore(fileStore, getProgressMonitor());
fileBuffer = manager.getFileStoreTextFileBuffer(fileStore);
}
}
if (fileBuffer == null && provider != null) {
IPath location = provider.getPath(element);
if (location == null)
return null;
locationKind = LocationKind.NORMALIZE;
manager.connect(location, locationKind, getProgressMonitor());
fileBuffer = manager.getTextFileBuffer(location, locationKind);
file = FileBuffers.getWorkspaceFileAtLocation(location);
}
}
if (fileBuffer != null) {
fileBuffer.requestSynchronizationContext();
FileInfo info = createEmptyFileInfo();
info.fTextFileBuffer = fileBuffer;
info.fTextFileBufferLocationKind = locationKind;
info.fCachedReadOnlyState = isSystemFileReadOnly(info);
if (file != null)
info.fModel = createAnnotationModel(file);
if (info.fModel == null)
info.fModel = info.fTextFileBuffer.getAnnotationModel();
setUpSynchronization(info);
return info;
}
return null;
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.
the class TextSearchVisitor method evaluateTextEditor.
private void evaluateTextEditor(Map<IFile, IDocument> result, IEditorPart ep) {
IEditorInput input = ep.getEditorInput();
if (input instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) input).getFile();
if (!result.containsKey(file)) {
// take the first editor found
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (textFileBuffer != null) {
// file buffer has precedence
result.put(file, textFileBuffer.getDocument());
} else {
// use document provider
IDocument document = ((ITextEditor) ep).getDocumentProvider().getDocument(input);
if (document != null) {
result.put(file, document);
}
}
}
}
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.
the class GenericFileBufferOperationRunner method releaseFileBuffers.
private void releaseFileBuffers(IPath[] locations, IProgressMonitor progressMonitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(progressMonitor, FileBuffersMessages.FileBufferOperationRunner_task_disconnecting, locations.length);
final ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
for (IPath location : locations) {
fileBufferManager.disconnect(location, LocationKind.NORMALIZE, subMonitor.split(1));
}
}
Aggregations