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;
}
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));
}
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;
}
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();
}
}
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);
}
Aggregations