use of org.eclipse.core.filebuffers.ITextFileBufferManager in project che by eclipse.
the class TextSearchVisitor method getOpenDocument.
private IDocument getOpenDocument(IFile file, Map documentsInEditors) {
IDocument document = (IDocument) documentsInEditors.get(file);
if (document == null) {
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (textFileBuffer != null) {
document = textFileBuffer.getDocument();
}
}
return document;
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project che by eclipse.
the class ProjectListeners method handleEvent.
public void handleEvent(ProjectItemModifiedEvent event) {
final String eventPath = event.getPath();
if (!isJavaProject(event.getProject())) {
return;
}
try {
JavaModelManager.getJavaModelManager().deltaState.resourceChanged(new ResourceChangedEvent(workspace, event));
} catch (Throwable t) {
//catch all exceptions that may be happened
LOG.error("Can't update java model in " + eventPath, t);
}
if (event.getType() == ProjectItemModifiedEvent.EventType.UPDATED) {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer fileBuffer = manager.getTextFileBuffer(new Path(eventPath), LocationKind.IFILE);
if (fileBuffer != null) {
try {
fileBuffer.revert(new NullProgressMonitor());
} catch (CoreException e) {
LOG.error("Can't read file content: " + eventPath, e);
}
}
}
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project che by eclipse.
the class DocumentChange method performEdits.
/*
* @see org.eclipse.ltk.core.refactoring.TextChange#performEdits(org.eclipse.jface.text.IDocument)
* @since 3.6
*/
protected UndoEdit performEdits(final IDocument document) throws BadLocationException, MalformedTreeException {
ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer fileBuffer = fileBufferManager.getTextFileBuffer(document);
if (fileBuffer == null || !fileBuffer.isSynchronizationContextRequested()) {
return super.performEdits(document);
}
/** The lock for waiting for computation in the UI thread to complete. */
final Lock completionLock = new Lock();
final UndoEdit[] result = new UndoEdit[1];
final BadLocationException[] exception = new BadLocationException[1];
Runnable runnable = new Runnable() {
public void run() {
synchronized (completionLock) {
try {
result[0] = DocumentChange.super.performEdits(document);
} catch (BadLocationException e) {
exception[0] = e;
} finally {
completionLock.fDone = true;
completionLock.notifyAll();
}
}
}
};
synchronized (completionLock) {
fileBufferManager.execute(runnable);
while (!completionLock.fDone) {
try {
completionLock.wait(500);
} catch (InterruptedException x) {
}
}
}
if (exception[0] != null) {
throw exception[0];
}
return result[0];
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project che by eclipse.
the class MultiStateTextFileChange method performChanges.
/**
* Performs the changes on the specified document.
*
* @param document
* the document to perform the changes on
* @param undoList
* the undo list, or <code>null</code> to discard the undos
* @param preview
* <code>true</code> if the changes are performed for preview,
* <code>false</code> otherwise
* @throws BadLocationException
* if the edit tree could not be applied
*/
private void performChanges(final IDocument document, final LinkedList undoList, final boolean preview) throws BadLocationException {
if (!fBuffer.isSynchronizationContextRequested()) {
performChangesInSynchronizationContext(document, undoList, preview);
return;
}
ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
/** The lock for waiting for computation in the UI thread to complete. */
final Lock completionLock = new Lock();
final BadLocationException[] exception = new BadLocationException[1];
Runnable runnable = new Runnable() {
public void run() {
synchronized (completionLock) {
try {
performChangesInSynchronizationContext(document, undoList, preview);
} catch (BadLocationException e) {
exception[0] = e;
} finally {
completionLock.fDone = true;
completionLock.notifyAll();
}
}
}
};
synchronized (completionLock) {
fileBufferManager.execute(runnable);
while (!completionLock.fDone) {
try {
completionLock.wait(500);
} catch (InterruptedException x) {
}
}
}
if (exception[0] != null) {
throw exception[0];
}
}
use of org.eclipse.core.filebuffers.ITextFileBufferManager in project che by eclipse.
the class MultiStateTextFileChange method acquireDocument.
/**
* Acquires a document from the file buffer manager.
*
* @param monitor
* the progress monitor to use
* @return the document
* @throws CoreException if the document could not successfully be acquired
*/
private IDocument acquireDocument(final IProgressMonitor monitor) throws CoreException {
if (fCount > 0)
return fBuffer.getDocument();
final ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
final IPath path = fFile.getFullPath();
manager.connect(path, LocationKind.IFILE, monitor);
fCount++;
fBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
final IDocument document = fBuffer.getDocument();
fContentStamp = ContentStamps.get(fFile, document);
return document;
}
Aggregations