use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.releng by eclipse.
the class PomVersionMarkerResolution method run.
@Override
public void run(IMarker marker) {
try {
correctedVersion = (String) marker.getAttribute(IPomVersionConstants.POM_CORRECT_VERSION);
} catch (CoreException e1) {
RelEngPlugin.log(e1);
}
if (correctedVersion == null || correctedVersion.trim().length() == 0) {
return;
}
int charstart = marker.getAttribute(IMarker.CHAR_START, -1);
int charend = marker.getAttribute(IMarker.CHAR_END, -1);
if (charstart < 0 || charend < 0) {
return;
}
IResource resource = marker.getResource();
if (resource.exists() && resource.getType() == IResource.FILE) {
IFile file = (IFile) resource;
if (!file.isReadOnly()) {
NullProgressMonitor monitor = new NullProgressMonitor();
ITextFileBufferManager fbm = FileBuffers.getTextFileBufferManager();
IPath location = file.getFullPath();
ITextFileBuffer buff = null;
try {
fbm.connect(location, LocationKind.IFILE, monitor);
buff = fbm.getTextFileBuffer(location, LocationKind.IFILE);
if (buff != null) {
IDocument doc = buff.getDocument();
try {
if (charstart > -1 && charend > -1) {
doc.replace(charstart, charend - charstart, correctedVersion);
buff.commit(monitor, true);
}
} catch (BadLocationException ble) {
RelEngPlugin.log(ble);
}
}
} catch (CoreException e) {
RelEngPlugin.log(e);
} finally {
try {
if (buff != null)
fbm.disconnect(location, LocationKind.IFILE, monitor);
} catch (CoreException e) {
RelEngPlugin.log(e);
}
}
}
}
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.
the class TestStructuredTextEditor method testSingleNonUIThreadUpdatesToEditorDocument.
public void testSingleNonUIThreadUpdatesToEditorDocument() throws Exception {
IFile file = getOrCreateFile(PROJECT_NAME + "/" + "testBackgroundChanges.xml");
ITextFileBufferManager textFileBufferManager = FileBuffers.getTextFileBufferManager();
textFileBufferManager.connect(file.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
final IDocument document = textFileBuffer.getDocument();
document.replace(0, 0, "<?xml encoding=\"UTF-8\" version=\"1.0\"?>\n");
textFileBuffer.commit(new NullProgressMonitor(), true);
String testText = document.get() + "<c/><b/><a/>";
final int end = document.getLength();
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart openedEditor = IDE.openEditor(activePage, file);
final boolean[] state = new boolean[] { false };
Job changer = new Job("text changer") {
protected IStatus run(IProgressMonitor monitor) {
try {
document.replace(end, 0, "<a/>");
document.replace(end, 0, "<b/>");
document.replace(end, 0, "<c/>");
} catch (Exception e) {
return new Status(IStatus.ERROR, SSEUIPlugin.ID, e.getMessage());
} finally {
state[0] = true;
}
return Status.OK_STATUS;
}
};
changer.setUser(true);
changer.setSystem(false);
changer.schedule();
while (!state[0]) {
openedEditor.getSite().getShell().getDisplay().readAndDispatch();
}
String finalText = document.get();
textFileBuffer.commit(new NullProgressMonitor(), true);
textFileBufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
activePage.closeEditor(openedEditor, false);
assertEquals("Non-UI changes did not apply", testText, finalText);
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.
the class ReconcileStepForValidator method getURI.
private String getURI() {
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
if (model != null && !(IModelManager.UNMANAGED_MODEL.equals(model.getBaseLocation()))) {
return model.getBaseLocation();
}
ITextFileBufferManager textFileBufferManager = FileBuffers.getTextFileBufferManager();
if (textFileBufferManager != null) {
ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(getDocument());
if (textFileBuffer != null && textFileBuffer.getLocation() != null) {
return textFileBuffer.getLocation().toString();
}
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
return null;
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse-integration-commons by spring-projects.
the class DocumentFetcher method getClosedDocument.
private IDocument getClosedDocument(IFile file) {
// No in the manager yet. Try to create a temporary buffer then remove it again.
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
// Must use workspace location, not fs location for API below.
IPath location = file.getFullPath();
ITextFileBuffer buffer = null;
try {
bufferManager.connect(location, LocationKind.IFILE, new NullProgressMonitor());
buffer = bufferManager.getTextFileBuffer(location, LocationKind.IFILE);
if (buffer != null) {
return buffer.getDocument();
}
} catch (Throwable e) {
QuickSearchActivator.log(e);
} finally {
try {
bufferManager.disconnect(location, LocationKind.IFILE, new NullProgressMonitor());
} catch (CoreException e) {
}
}
return null;
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse-integration-commons by spring-projects.
the class DocumentFetcher method getOpenDocument.
private IDocument getOpenDocument(IFile file) {
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (textFileBuffer != null) {
return textFileBuffer.getDocument();
}
return null;
}
Aggregations