Search in sources :

Example 1 with ITextFileBufferManager

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;
}
Also used : ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with ITextFileBufferManager

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);
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent)

Example 3 with ITextFileBufferManager

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];
}
Also used : ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) UndoEdit(org.eclipse.text.edits.UndoEdit) BadLocationException(org.eclipse.jface.text.BadLocationException) Lock(org.eclipse.ltk.internal.core.refactoring.Lock)

Example 4 with ITextFileBufferManager

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];
    }
}
Also used : ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) BadLocationException(org.eclipse.jface.text.BadLocationException) Lock(org.eclipse.ltk.internal.core.refactoring.Lock)

Example 5 with ITextFileBufferManager

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)87 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)66 IDocument (org.eclipse.jface.text.IDocument)54 IPath (org.eclipse.core.runtime.IPath)52 CoreException (org.eclipse.core.runtime.CoreException)36 BadLocationException (org.eclipse.jface.text.BadLocationException)26 IFile (org.eclipse.core.resources.IFile)22 Test (org.junit.Test)17 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 IOException (java.io.IOException)10 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)10 IResource (org.eclipse.core.resources.IResource)8 Path (org.eclipse.core.runtime.Path)8 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 TextEdit (org.eclipse.text.edits.TextEdit)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)6 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)6 UndoEdit (org.eclipse.text.edits.UndoEdit)6 FileNotFoundException (java.io.FileNotFoundException)5 MalformedURLException (java.net.MalformedURLException)5