Search in sources :

Example 66 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.

the class FileBuffersForWorkspaceFiles method modifyUnderlyingFile.

@Override
protected boolean modifyUnderlyingFile() throws Exception {
    IFileStore fileStore = FileBuffers.getFileStoreAtLocation(getPath());
    assertTrue(fileStore.fetchInfo().exists());
    OutputStream out = fileStore.openOutputStream(EFS.NONE, null);
    try {
        out.write("Changed content of workspace file".getBytes());
        out.flush();
    } catch (IOException x) {
        fail();
    } finally {
        out.close();
    }
    IFileInfo fileInfo = fileStore.fetchInfo();
    fileInfo.setLastModified(1000);
    fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
    IFile iFile = FileBuffers.getWorkspaceFileAtLocation(getPath());
    assertTrue(iFile.exists() && iFile.getFullPath().equals(getPath()));
    iFile.refreshLocal(IResource.DEPTH_INFINITE, null);
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException)

Example 67 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test1_IFileStore.

/*
	 * Tests the creation of file buffer for an existing file.
	 */
@Test
public void test1_IFileStore() throws Exception {
    IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
    IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
    IPath path = file.getFullPath();
    assertNotNull(path);
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.getLocation());
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connectFileStore(fileStore, null);
    ITextFileBuffer buffer = manager.getFileStoreTextFileBuffer(fileStore);
    assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertEquals(CONTENT1, document.get());
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnectFileStore(fileStore, null);
    assertNull(manager.getFileStoreTextFileBuffer(fileStore));
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) IDocument(org.eclipse.jface.text.IDocument) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 68 with IFileStore

use of org.eclipse.core.filesystem.IFileStore 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 69 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.

the class TextFileDocumentProvider method createFileStoreFromDocument.

/**
 * Creates the given file store with the given document content.
 *
 * @param monitor the progress monitor
 * @param uri the location where the file store should be created
 * @param document the document to be written to the file store
 * @throws CoreException if the creation of the file store fails
 * @since 3.3
 */
private void createFileStoreFromDocument(IProgressMonitor monitor, URI uri, IDocument document) throws CoreException {
    try {
        monitor.beginTask(TextEditorMessages.TextFileDocumentProvider_beginTask_saving, 2000);
        IFileStore fileStore = EFS.getStore(uri);
        FileBuffers.getTextFileBufferManager().connectFileStore(fileStore, monitor);
        ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getFileStoreTextFileBuffer(fileStore);
        buffer.getDocument().set(document.get());
        buffer.commit(monitor, true);
        FileBuffers.getTextFileBufferManager().disconnectFileStore(fileStore, monitor);
    } finally {
        monitor.done();
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 70 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.

the class FileStoreFileBuffersForExternalFiles method setReadOnly.

@Override
protected void setReadOnly(boolean state) throws Exception {
    IFileStore fileStore = FileBuffers.getFileStoreAtLocation(getPath());
    assertNotNull(fileStore);
    fileStore.fetchInfo().setAttribute(EFS.ATTRIBUTE_READ_ONLY, state);
}
Also used : IFileStore(org.eclipse.core.filesystem.IFileStore)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)105 CoreException (org.eclipse.core.runtime.CoreException)49 IPath (org.eclipse.core.runtime.IPath)29 IOException (java.io.IOException)26 IFileInfo (org.eclipse.core.filesystem.IFileInfo)25 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 URI (java.net.URI)16 InputStream (java.io.InputStream)14 Path (org.eclipse.core.runtime.Path)14 IFile (org.eclipse.core.resources.IFile)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)12 InputStreamReader (java.io.InputStreamReader)11 PartInitException (org.eclipse.ui.PartInitException)11 BufferedReader (java.io.BufferedReader)10 URISyntaxException (java.net.URISyntaxException)10 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 Test (org.junit.Test)10 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)9 IStatus (org.eclipse.core.runtime.IStatus)9