Search in sources :

Example 61 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test7_location.

/*
	 * Tests the creation of a file buffer for a non-existing file.
	 */
@Test
public void test7_location() throws Exception {
    IPath path = FileBuffersTestPlugin.getDefault().getStateLocation();
    path = path.append("NonExistingFile");
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path, LocationKind.LOCATION, null);
    ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.LOCATION);
    Assert.assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    Assert.assertNotNull(document);
    Assert.assertTrue("".equals(document.get()));
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.LOCATION, null);
    assertNull(manager.getTextFileBuffer(path, LocationKind.LOCATION));
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 62 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test7.

/*
	 * Tests the creation of a file buffer for a non-existing file.
	 */
@Test
public void test7() throws Exception {
    IPath path = FileBuffersTestPlugin.getDefault().getStateLocation();
    path = path.append("NonExistingFile");
    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("".equals(document.get()));
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.NORMALIZE, null);
    assertNull(manager.getTextFileBuffer(path, LocationKind.NORMALIZE));
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 63 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class TextFileDocumentProvider method createFileInfo.

/**
 * Creates and returns the file info object
 * for the given element.
 * <p>
 * Subclasses which extend {@link org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo}
 * will probably have to extend this method as well.
 * </p>
 *
 * @param element the element
 * @return a file info object of type <code>FileInfo</code>
 * 			 or <code>null</code> if none can be created
 * @throws CoreException if the file info object could not successfully be created
 */
protected FileInfo createFileInfo(Object element) throws CoreException {
    if (!(element instanceof IAdaptable))
        return null;
    IAdaptable adaptable = (IAdaptable) element;
    IFile file = null;
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    ITextFileBuffer fileBuffer = null;
    LocationKind locationKind = null;
    file = adaptable.getAdapter(IFile.class);
    if (file != null) {
        IPath location = file.getFullPath();
        locationKind = LocationKind.IFILE;
        manager.connect(location, locationKind, getProgressMonitor());
        fileBuffer = manager.getTextFileBuffer(location, locationKind);
    } else {
        ILocationProvider provider = adaptable.getAdapter(ILocationProvider.class);
        if (provider instanceof ILocationProviderExtension) {
            URI uri = ((ILocationProviderExtension) provider).getURI(element);
            if (ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri).length == 0) {
                IFileStore fileStore = EFS.getStore(uri);
                manager.connectFileStore(fileStore, getProgressMonitor());
                fileBuffer = manager.getFileStoreTextFileBuffer(fileStore);
            }
        }
        if (fileBuffer == null && provider != null) {
            IPath location = provider.getPath(element);
            if (location == null)
                return null;
            locationKind = LocationKind.NORMALIZE;
            manager.connect(location, locationKind, getProgressMonitor());
            fileBuffer = manager.getTextFileBuffer(location, locationKind);
            file = FileBuffers.getWorkspaceFileAtLocation(location);
        }
    }
    if (fileBuffer != null) {
        fileBuffer.requestSynchronizationContext();
        FileInfo info = createEmptyFileInfo();
        info.fTextFileBuffer = fileBuffer;
        info.fTextFileBufferLocationKind = locationKind;
        info.fCachedReadOnlyState = isSystemFileReadOnly(info);
        if (file != null)
            info.fModel = createAnnotationModel(file);
        if (info.fModel == null)
            info.fModel = info.fTextFileBuffer.getAnnotationModel();
        setUpSynchronization(info);
        return info;
    }
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) LocationKind(org.eclipse.core.filebuffers.LocationKind) IPath(org.eclipse.core.runtime.IPath) IFileInfo(org.eclipse.core.filesystem.IFileInfo) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) URI(java.net.URI)

Example 64 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class TextSearchVisitor method evaluateTextEditor.

private void evaluateTextEditor(Map<IFile, IDocument> result, IEditorPart ep) {
    IEditorInput input = ep.getEditorInput();
    if (input instanceof IFileEditorInput) {
        IFile file = ((IFileEditorInput) input).getFile();
        if (!result.containsKey(file)) {
            // take the first editor found
            ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
            ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
            if (textFileBuffer != null) {
                // file buffer has precedence
                result.put(file, textFileBuffer.getDocument());
            } else {
                // use document provider
                IDocument document = ((ITextEditor) ep).getDocumentProvider().getDocument(input);
                if (document != null) {
                    result.put(file, document);
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 65 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class GenericFileBufferOperationRunner method releaseFileBuffers.

private void releaseFileBuffers(IPath[] locations, IProgressMonitor progressMonitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(progressMonitor, FileBuffersMessages.FileBufferOperationRunner_task_disconnecting, locations.length);
    final ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
    for (IPath location : locations) {
        fileBufferManager.disconnect(location, LocationKind.NORMALIZE, subMonitor.split(1));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) SubMonitor(org.eclipse.core.runtime.SubMonitor)

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