use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.
the class FileBufferCreation method test1.
/*
* Tests the creation of file buffer for an existing file.
*/
@Test
public void test1() throws Exception {
IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
IPath path = file.getFullPath();
assertNotNull(path);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(path, LocationKind.NORMALIZE, null);
ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.NORMALIZE);
assertNotNull(buffer);
IDocument document = buffer.getDocument();
assertNotNull(document);
assertEquals(CONTENT1, 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 FileBufferCreation method test3_1.
/*
* Tests the creation of a file buffer for a linked file.
*/
@Test
public void test3_1() throws Exception {
IPath path = createLinkedFile("file", "testResources/LinkedFileTarget");
assertNotNull(path);
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(CONTENT2.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 FileBufferCreation method test4_IFILE.
/*
* Tests that two different files linked to the same target file result
* in two different, independent file buffers.
*/
@Test
public void test4_IFILE() throws Exception {
IPath path1 = createLinkedFile("file1", "testResources/LinkedFileTarget");
assertNotNull(path1);
IPath path2 = createLinkedFile("file2", "testResources/LinkedFileTarget");
assertNotNull(path2);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(path1, LocationKind.IFILE, null);
ITextFileBuffer buffer1 = manager.getTextFileBuffer(path1, LocationKind.IFILE);
assertNotNull(buffer1);
manager.connect(path2, LocationKind.IFILE, null);
ITextFileBuffer buffer2 = manager.getTextFileBuffer(path2, LocationKind.IFILE);
assertNotNull(buffer2);
IDocument document1 = buffer1.getDocument();
assertNotNull(document1);
assertSame(buffer1, manager.getTextFileBuffer(document1));
IDocument document2 = buffer2.getDocument();
assertNotNull(document2);
assertSame(buffer2, manager.getTextFileBuffer(document2));
assertEquals(document1.get(), document2.get());
assertEquals(CONTENT2, document1.get());
try {
document1.replace(0, document1.getLength(), CONTENT1);
} catch (BadLocationException x) {
Assert.assertFalse(false);
}
assertFalse(document1.get().equals(document2.get()));
manager.disconnect(path1, LocationKind.IFILE, null);
assertNull(manager.getTextFileBuffer(path1, LocationKind.IFILE));
assertNotNull(manager.getTextFileBuffer(path2, LocationKind.IFILE));
manager.disconnect(path2, LocationKind.IFILE, null);
assertNull(manager.getTextFileBuffer(path2, LocationKind.IFILE));
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.
the class FileBufferCreation method test1_IFILE.
/*
* Tests the creation of file buffer for an existing file.
*/
@Test
public void test1_IFILE() throws Exception {
IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
IPath path = file.getFullPath();
assertNotNull(path);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(path, LocationKind.IFILE, null);
ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
assertNotNull(buffer);
IDocument document = buffer.getDocument();
assertNotNull(document);
assertEquals(CONTENT1, document.get());
assertSame(buffer, manager.getTextFileBuffer(document));
manager.disconnect(path, LocationKind.IFILE, null);
assertNull(manager.getTextFileBuffer(path, LocationKind.IFILE));
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.
the class TextFileDocumentProvider method createFileFromDocument.
/**
* Creates the given file with the given document content.
*
* @param monitor the progress monitor
* @param file the file to be created
* @param document the document to be written to the file
* @throws CoreException if the creation of the file fails
*/
protected void createFileFromDocument(IProgressMonitor monitor, IFile file, IDocument document) throws CoreException {
try {
monitor.beginTask(TextEditorMessages.TextFileDocumentProvider_beginTask_saving, 2000);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(file.getFullPath(), LocationKind.IFILE, monitor);
ITextFileBuffer buffer = ITextFileBufferManager.DEFAULT.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
buffer.getDocument().set(document.get());
buffer.commit(monitor, true);
manager.disconnect(file.getFullPath(), LocationKind.IFILE, monitor);
} finally {
monitor.done();
}
}
Aggregations