use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.
the class FileBufferDocumentTester method doTestCreate.
private void doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws CoreException, IOException {
IFile file = (IFile) fTestProject.findMember(filePath);
System.out.println(fTestProject.getLocation().toOSString());
assertNotNull("Test Case in error. Could not find file " + filePath, file);
IPath locationPath = file.getLocation();
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
bufferManager.connect(locationPath, null);
ITextFileBuffer buffer = bufferManager.getTextFileBuffer(locationPath);
IDocument document = buffer.getDocument();
assertNotNull(document);
assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
IDocumentPartitioner setupPartitioner = null;
if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
} else {
setupPartitioner = document.getDocumentPartitioner();
}
assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
bufferManager.disconnect(locationPath, null);
// doTestCreateWithFacade(file, expectedDocumentClass, expectedPartioner);
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.
the class FormatActionDelegate method format.
protected void format(final IProgressMonitor monitor, IResource resource) {
if (resource instanceof IFile) {
final IFile file = (IFile) resource;
// format of the file when it can
try {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer buffer = null;
try {
if (manager != null) {
manager.connect(file.getFullPath(), LocationKind.IFILE, monitor);
buffer = manager.getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
}
if (buffer != null && buffer.isShared()) {
Display display = getDisplay();
display.syncExec(new Runnable() {
public void run() {
format(monitor, file);
}
});
} else
format(monitor, file);
} finally {
if (manager != null)
manager.disconnect(file.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
}
} catch (CoreException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
} finally {
if (monitor != null)
monitor.done();
}
} else if (resource instanceof IContainer) {
IContainer container = (IContainer) resource;
try {
IResource[] members = container.members();
monitor.beginTask("", members.length);
for (int i = 0; i < members.length; i++) {
if (monitor != null && !monitor.isCanceled())
format(new SubProgressMonitor(monitor, 1), members[i]);
}
monitor.done();
} catch (CoreException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { resource.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
}
}
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.
the class JavascriptValidationStrategy method getContentType.
private String getContentType() {
IDocument doc = getDocument();
if (doc == null)
return null;
ITextFileBufferManager textFileBufferManager = FileBuffers.getTextFileBufferManager();
if (textFileBufferManager != null) {
ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(doc);
if (textFileBuffer != null && textFileBuffer.getLocation() != null) {
try {
IContentType ct = textFileBuffer.getContentType();
if (ct != null)
return ct.getId();
} catch (CoreException e) {
// Ignore;
}
}
}
return null;
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.
the class FileBufferDocumentTester method doTestCreate.
private void doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws CoreException, IOException {
IFile file = (IFile) fTestProject.findMember(filePath);
assertNotNull("Test Case in error. Could not find file " + filePath, file);
IPath fullPath = file.getFullPath();
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
bufferManager.connect(fullPath, LocationKind.IFILE, null);
ITextFileBuffer buffer = bufferManager.getTextFileBuffer(fullPath);
IDocument document = buffer.getDocument();
assertNotNull(document);
assertTrue("wrong class of document: " + (document != null ? document.getClass() : null), expectedDocumentClass.isInstance(document));
assertTrue("document does not implement IDocumentExtension3", document instanceof IDocumentExtension3);
IDocumentPartitioner actualPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
assertTrue("wrong partitioner in document: " + actualPartitioner, expectedPartioner.isInstance(actualPartitioner));
bufferManager.disconnect(fullPath, LocationKind.IFILE, null);
// doTestCreateWithFacade(file, expectedDocumentClass, expectedPartioner);
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.
the class TransitionTests method testSoftRevert.
public void testSoftRevert() throws CoreException, IOException {
// $NON-NLS-1$
String filePath = "testfiles/xml/EmptyFile.xml";
IFile file = (IFile) fTestProject.findMember(filePath);
// $NON-NLS-1$
assertNotNull("Test Case in error. Could not find file " + filePath, file);
IPath locationPath = file.getLocation();
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
bufferManager.connect(locationPath, null);
ITextFileBuffer buffer = bufferManager.getTextFileBuffer(locationPath);
IDocument document = buffer.getDocument();
assertNotNull(document);
// $NON-NLS-1$
assertTrue("wrong class of document", document instanceof BasicStructuredDocument);
// $NON-NLS-1$
assertTrue("wrong partitioner in document.", ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING) instanceof StructuredTextPartitionerForXML);
IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document);
try {
try {
// $NON-NLS-1$
document.replace(0, 0, "__");
// $NON-NLS-1$
document.replace(2, 0, "<a");
// $NON-NLS-1$
document.replace(4, 0, ">");
// $NON-NLS-1$
document.replace(5, 0, " ");
} catch (BadLocationException e) {
assertNull(e);
}
// $NON-NLS-1$
document.set("");
} finally {
model.releaseFromEdit();
bufferManager.disconnect(locationPath, null);
}
}
Aggregations