Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.core.filebuffers/src/org/eclipse/core/internal')
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java36
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java130
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DefaultDocumentFactory.java32
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ExtensionsRegistry.java557
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.java82
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.properties29
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersPlugin.java96
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaFileBuffer.java217
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java436
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java426
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java523
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java315
12 files changed, 0 insertions, 2879 deletions
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
deleted file mode 100644
index f0721e2475f..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.core.filebuffers.IFileBuffer;
-
-/**
- * @since 3.0
- */
-public abstract class AbstractFileBuffer implements IFileBuffer {
-
-
- public abstract void create(IPath location, IProgressMonitor monitor) throws CoreException;
-
- public abstract void connect();
-
- public abstract void disconnect() throws CoreException;
-
- public abstract boolean isDisposed();
-
- public abstract void requestSynchronizationContext();
-
- public abstract void releaseSynchronizationContext();
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java
deleted file mode 100644
index ec5f82f8323..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-
-public class ContainerGenerator {
-
- private IPath fContainerFullPath;
- private IContainer fContainer;
- private IWorkspace fWorkspace;
-
- public ContainerGenerator(IWorkspace workspace, IPath containerPath) {
- fWorkspace= workspace;
- fContainerFullPath = containerPath;
- }
-
- private IFolder createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException {
- folderHandle.create(false, true, monitor);
- if (monitor.isCanceled())
- throw new OperationCanceledException();
- return folderHandle;
- }
-
- private IFolder createFolderHandle(IContainer container, String folderName) {
- return container.getFolder(new Path(folderName));
- }
-
- private IProject createProject(IProject projectHandle, IProgressMonitor monitor) throws CoreException {
- try {
- monitor.beginTask("",2000);//$NON-NLS-1$
-
- projectHandle.create(new SubProgressMonitor(monitor, 1000));
- if (monitor.isCanceled())
- throw new OperationCanceledException();
-
- projectHandle.open(new SubProgressMonitor(monitor, 1000));
- if (monitor.isCanceled())
- throw new OperationCanceledException();
-
- } finally {
- monitor.done();
- }
-
- return projectHandle;
- }
-
- private IProject createProjectHandle(IWorkspaceRoot root, String projectName) {
- return root.getProject(projectName);
- }
-
- public IContainer generateContainer(IProgressMonitor monitor) throws CoreException {
- IWorkspaceRunnable runnable= new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- monitor.beginTask(FileBuffersMessages.getString("ContainerGenerator.task.creatingContainer"), 1000 * fContainerFullPath.segmentCount()); //$NON-NLS-1$
- if (fContainer != null)
- return;
-
- // Does the container exist already?
- IWorkspaceRoot root= fWorkspace.getRoot();
- IResource found= root.findMember(fContainerFullPath);
- if (found instanceof IContainer) {
- fContainer= (IContainer) found;
- return;
- } else if (found != null) {
- // fContainerFullPath specifies a file as directory
- throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getFormattedString("ContainerGenerator.destinationMustBeAContainer", fContainerFullPath), null)); //$NON-NLS-1$
- }
-
- // Create the container for the given path
- fContainer= root;
- for (int i = 0; i < fContainerFullPath.segmentCount(); i++) {
- String currentSegment = fContainerFullPath.segment(i);
- IResource resource = fContainer.findMember(currentSegment);
- if (resource != null) {
- if (resource instanceof IContainer) {
- fContainer= (IContainer) resource;
- monitor.worked(1000);
- } else {
- // fContainerFullPath specifies a file as directory
- throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getFormattedString("ContainerGenerator.destinationMustBeAContainer", resource.getFullPath()), null)); //$NON-NLS-1$
- }
- }
- else {
- if (i == 0) {
- IProject projectHandle= createProjectHandle(root, currentSegment);
- fContainer= createProject(projectHandle, new SubProgressMonitor(monitor,1000));
- }
- else {
- IFolder folderHandle= createFolderHandle(fContainer, currentSegment);
- fContainer= createFolder(folderHandle, new SubProgressMonitor(monitor,1000));
- }
- }
- }
- }
- };
-
- // Get scheduling rule
- IWorkspaceRoot root= fWorkspace.getRoot();
- IPath existingParentPath= fContainerFullPath;
- while (!root.exists(existingParentPath))
- existingParentPath= existingParentPath.removeLastSegments(1);
-
- IResource schedulingRule= root.findMember(existingParentPath);
- fWorkspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
- return fContainer;
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DefaultDocumentFactory.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DefaultDocumentFactory.java
deleted file mode 100644
index 61ab7ca3b67..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DefaultDocumentFactory.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import org.eclipse.core.filebuffers.IDocumentFactory;
-
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-
-/**
- * The default document factory.
- */
-public class DefaultDocumentFactory implements IDocumentFactory {
-
- public DefaultDocumentFactory() {
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IDocumentFactory#createDocument()
- */
- public IDocument createDocument() {
- return new Document();
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ExtensionsRegistry.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ExtensionsRegistry.java
deleted file mode 100644
index f1926c6932e..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ExtensionsRegistry.java
+++ /dev/null
@@ -1,557 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.content.IContentDescription;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.core.runtime.content.IContentTypeManager;
-
-import org.eclipse.core.filebuffers.FileBuffers;
-import org.eclipse.core.filebuffers.IAnnotationModelFactory;
-import org.eclipse.core.filebuffers.IDocumentFactory;
-import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
-
-import org.eclipse.jface.text.Assert;
-
-
-/**
- * This registry manages sharable document factories. Document factories are specified
- * in <code>plugin.xml</code> per file name extension.
- */
-public class ExtensionsRegistry {
-
- /**
- * Adapts IContentType with the ability to check
- * equality. This allows to use them in a collection.
- */
- private static class ContentTypeAdapter {
-
- /** The adapted content type. */
- private IContentType fContentType;
-
- /**
- * Creates a new content type adapter for the
- * given content type.
- *
- * @param contentType the content type to be adapted
- */
- public ContentTypeAdapter(IContentType contentType) {
- Assert.isNotNull(contentType);
- fContentType= contentType;
- }
-
- /**
- * Return the adapted content type.
- *
- * @return the content type
- */
- public IContentType getContentType() {
- return fContentType;
- }
-
- /**
- * Return the Id of the adapted content type.
- *
- * @return the Id
- */
- public String getId() {
- return fContentType.getId();
- }
-
- /*
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- return obj instanceof ContentTypeAdapter && fContentType.getId().equals(((ContentTypeAdapter)obj).getId());
- }
-
- /*
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return fContentType.getId().hashCode();
- }
- }
-
- private final static String WILDCARD= "*"; //$NON-NLS-1$
-
- /** The mapping between file attributes and configuration elements describing document factories. */
- private Map fFactoryDescriptors= new HashMap();
- /** The mapping between configuration elements for document factories and instantiated document factories. */
- private Map fFactories= new HashMap();
- /** The mapping between file attributes and configuration elements describing document setup participants. */
- private Map fSetupParticipantDescriptors= new HashMap();
- /** The mapping between configuration elements for setup participants and instantiated setup participants. */
- private Map fSetupParticipants= new HashMap();
- /** The mapping between file attributes and configuration elements describing annotation model factories. */
- private Map fAnnotationModelFactoryDescriptors= new HashMap();
- /** The mapping between configuration elements for annotation model factories */
- private Map fAnnotationModelFactories= new HashMap();
- /** The content type manager. */
- private IContentTypeManager fContentTypeManager= Platform.getContentTypeManager();
-
-
- /**
- * Creates a new document factory registry and initializes it with the information
- * found in the plug-in registry.
- */
- public ExtensionsRegistry() {
- initialize("documentCreation", "contentTypeId", true, fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentCreation", "fileNames", false, fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentCreation", "extensions", false, fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentSetup", "contentTypeId", true, fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentSetup", "fileNames", false, fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentSetup", "extensions", false, fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("annotationModelCreation", "contentTypeId", true, fAnnotationModelFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("annotationModelCreation", "fileNames", false, fAnnotationModelFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("annotationModelCreation", "extensions", false, fAnnotationModelFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
-
- /**
- * Reads the comma-separated value from the given configuration element for the given attribute name and remembers
- * the configuration element in the given map under the individual tokens of the attribute value.
- *
- * @param attributeName the name of the attribute
- * @param element the configuration element
- * @param map the map which remembers the configuration element
- */
- private void read(String attributeName, IConfigurationElement element, Map map) {
- String value= element.getAttribute(attributeName);
- if (value != null) {
- StringTokenizer tokenizer= new StringTokenizer(value, ","); //$NON-NLS-1$
- while (tokenizer.hasMoreTokens()) {
- String token= tokenizer.nextToken().trim();
-
- Set s= (Set) map.get(token);
- if (s == null) {
- s= new HashSet();
- map.put(token, s);
- }
- s.add(element);
- }
- }
- }
-
- /**
- * Reads the value from the given configuration element for the given attribute name and remembers
- * the configuration element in the given map under the individual content type of the attribute value.
- *
- * @param attributeName the name of the attribute
- * @param element the configuration element
- * @param map the map which remembers the configuration element
- */
- private void readContentType(String attributeName, IConfigurationElement element, Map map) {
- String value= element.getAttribute(attributeName);
- if (value != null) {
- IContentType contentType= fContentTypeManager.getContentType(value);
- if (contentType == null) {
- log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, 0, FileBuffersMessages.getFormattedString("ExtensionsRegistry.error.contentTypeDoesNotExist", new Object[] { value }), null)); //$NON-NLS-1$
- return;
- }
- ContentTypeAdapter adapter= new ContentTypeAdapter(contentType);
- Set s= (Set) map.get(adapter);
- if (s == null) {
- s= new HashSet();
- map.put(adapter, s);
- }
- s.add(element);
- }
- }
-
- /**
- * Adds an entry to the log of this plug-in for the given status
- * @param status the status to log
- */
- private void log(IStatus status) {
- ILog log= FileBuffersPlugin.getDefault().getLog();
- log.log(status);
- }
-
- /**
- * Initializes this registry. It retrieves all implementers of the given
- * extension point and remembers those implementers based on the
- * file name extensions in the given map.
- *
- * @param extensionPointName the name of the extension point
- * @param childElementName the name of the child elements
- * @param isContentTypeId the child element is a content type id
- * @param descriptors the map to be filled
- */
- private void initialize(String extensionPointName, String childElementName, boolean isContentTypeId, Map descriptors) {
-
- IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(FileBuffersPlugin.PLUGIN_ID, extensionPointName);
- if (extensionPoint == null) {
- log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, 0, FileBuffersMessages.getFormattedString("ExtensionsRegistry.error.extensionPointNotFound", new Object[] { extensionPointName}), null)); //$NON-NLS-1$
- return;
- }
-
- IConfigurationElement[] elements= extensionPoint.getConfigurationElements();
- for (int i= 0; i < elements.length; i++) {
- if (isContentTypeId)
- readContentType(childElementName, elements[i], descriptors);
- else
- read(childElementName, elements[i], descriptors);
- }
- }
-
- /**
- * Returns the executable extension for the given configuration element.
- * If there is no instantiated extension remembered for this
- * element, a new extension is created and put into the cache if it is of the requested type.
- *
- * @param entry the configuration element
- * @param extensions the map of instantiated extensions
- * @param extensionType the requested result type
- * @return the executable extension for the given configuration element.
- */
- private Object getExtension(IConfigurationElement entry, Map extensions, Class extensionType) {
- Object extension= extensions.get(entry);
- if (extension != null)
- return extension;
-
- try {
- extension= entry.createExecutableExtension("class"); //$NON-NLS-1$
- } catch (CoreException x) {
- log(x.getStatus());
- }
-
- if (extensionType.isInstance(extension)) {
- extensions.put(entry, extension);
- return extension;
- }
-
- return null;
- }
-
- /**
- * Returns the first enumerated element of the given set.
- *
- * @param set the set from which to choose
- * @return the selected configuration element
- */
- private IConfigurationElement selectConfigurationElement(Set set) {
- if (set != null && !set.isEmpty()) {
- Iterator e= set.iterator();
- return (IConfigurationElement) e.next();
- }
- return null;
- }
-
- /**
- * Returns a sharable document factory for the given file name or file extension.
- *
- * @param nameOrExtension the name or extension to be used for lookup
- * @return the sharable document factory or <code>null</code>
- */
- private IDocumentFactory getDocumentFactory(String nameOrExtension) {
- Set set= (Set) fFactoryDescriptors.get(nameOrExtension);
- if (set != null) {
- IConfigurationElement entry= selectConfigurationElement(set);
- return (IDocumentFactory) getExtension(entry, fFactories, IDocumentFactory.class);
- }
- return null;
- }
-
- /**
- * Returns a sharable document factory for the given content types.
- *
- * @param contentTypes the content types used to find the factory
- * @return the sharable document factory or <code>null</code>
- */
- private IDocumentFactory doGetDocumentFactory(IContentType[] contentTypes) {
- Set set= null;
- int i= 0;
- while (i < contentTypes.length && set == null) {
- set= (Set) fFactoryDescriptors.get(new ContentTypeAdapter(contentTypes[i++]));
- }
-
- if (set != null) {
- IConfigurationElement entry= selectConfigurationElement(set);
- return (IDocumentFactory) getExtension(entry, fFactories, IDocumentFactory.class);
- }
- return null;
- }
-
- /**
- * Returns a sharable document factory for the given content types. This
- * method considers the base content types of the given set of content
- * types.
- *
- * @param contentTypes the content types used to find the factory
- * @return the sharable document factory or <code>null</code>
- */
- private IDocumentFactory getDocumentFactory(IContentType[] contentTypes) {
- IDocumentFactory factory= doGetDocumentFactory(contentTypes);
- while (factory == null) {
- contentTypes= computeBaseContentTypes(contentTypes);
- if (contentTypes == null)
- break;
- factory= doGetDocumentFactory(contentTypes);
- }
- return factory;
- }
-
- /**
- * Returns the set of setup participants for the given file name or extension.
- *
- * @param nameOrExtension the name or extension to be used for lookup
- * @return the sharable set of document setup participants
- */
- private List getDocumentSetupParticipants(String nameOrExtension) {
- Set set= (Set) fSetupParticipantDescriptors.get(nameOrExtension);
- if (set == null)
- return null;
-
- List participants= new ArrayList();
- Iterator e= set.iterator();
- while (e.hasNext()) {
- IConfigurationElement entry= (IConfigurationElement) e.next();
- Object participant= getExtension(entry, fSetupParticipants, IDocumentSetupParticipant.class);
- if (participant != null)
- participants.add(participant);
- }
-
- return participants;
- }
-
- /**
- * Returns the set of setup participants for the given content types.
- *
- * @param contentTypes the contentTypes to be used for lookup
- * @return the sharable set of document setup participants
- */
- private List doGetDocumentSetupParticipants(IContentType[] contentTypes) {
- Set resultSet= new HashSet();
- int i= 0;
- while (i < contentTypes.length) {
- Set set= (Set) fSetupParticipantDescriptors.get(new ContentTypeAdapter(contentTypes[i++]));
- if (set != null)
- resultSet.addAll(set);
- }
-
- List participants= new ArrayList();
- Iterator e= resultSet.iterator();
- while (e.hasNext()) {
- IConfigurationElement entry= (IConfigurationElement) e.next();
- Object participant= getExtension(entry, fSetupParticipants, IDocumentSetupParticipant.class);
- if (participant != null)
- participants.add(participant);
- }
-
- return participants.isEmpty() ? null : participants;
- }
-
- /**
- * Returns the set of setup participants for the given content types. This
- * method considers the base content types of the given set of content
- * types.
- *
- * @param contentTypes the contentTypes to be used for lookup
- * @return the sharable set of document setup participants
- */
- private List getDocumentSetupParticipants(IContentType[] contentTypes) {
- List participants= doGetDocumentSetupParticipants(contentTypes);
- while (participants == null) {
- contentTypes= computeBaseContentTypes(contentTypes);
- if (contentTypes == null)
- break;
- participants= doGetDocumentSetupParticipants(contentTypes);
- }
- return participants;
- }
-
- /**
- * Returns a sharable annotation model factory for the given content types.
- *
- * @param contentTypes the content types used to find the factory
- * @return the sharable annotation model factory or <code>null</code>
- */
- private IAnnotationModelFactory doGetAnnotationModelFactory(IContentType[] contentTypes) {
- Set set= null;
- int i= 0;
- while (i < contentTypes.length && set == null) {
- set= (Set) fAnnotationModelFactoryDescriptors.get(new ContentTypeAdapter(contentTypes[i++]));
- }
-
- if (set != null) {
- IConfigurationElement entry= selectConfigurationElement(set);
- return (IAnnotationModelFactory) getExtension(entry, fAnnotationModelFactories, IAnnotationModelFactory.class);
- }
- return null;
- }
-
- /**
- * Returns a sharable annotation model factory for the given content types.
- * This method considers the base content types of the given set of content
- * types.
- *
- * @param contentTypes the content types used to find the factory
- * @return the sharable annotation model factory or <code>null</code>
- */
- private IAnnotationModelFactory getAnnotationModelFactory(IContentType[] contentTypes) {
- IAnnotationModelFactory factory= doGetAnnotationModelFactory(contentTypes);
- while (factory == null) {
- contentTypes= computeBaseContentTypes(contentTypes);
- if (contentTypes == null)
- break;
- factory= doGetAnnotationModelFactory(contentTypes);
- }
- return factory;
- }
-
- /**
- * Returns a sharable annotation model factory for the given file name or file extension.
- *
- * @param extension the name or extension to be used for lookup
- * @return the sharable document factory or <code>null</code>
- */
- private IAnnotationModelFactory getAnnotationModelFactory(String extension) {
- Set set= (Set) fAnnotationModelFactoryDescriptors.get(extension);
- if (set != null) {
- IConfigurationElement entry= selectConfigurationElement(set);
- return (IAnnotationModelFactory) getExtension(entry, fAnnotationModelFactories, IAnnotationModelFactory.class);
- }
- return null;
- }
-
- /**
- * Returns the set of content types for the given location.
- *
- * @param location the location for which to look up the content types
- * @return the set of content types for the location
- */
- private IContentType[] findContentTypes(IPath location) {
- IFile file= FileBuffers.getWorkspaceFileAtLocation(location);
- if (file != null) {
- try {
- IContentDescription contentDescription= file.getContentDescription();
- if (contentDescription != null) {
- IContentType contentType= contentDescription.getContentType();
- if (contentType != null)
- return new IContentType[] {contentType};
- }
- } catch (CoreException x) {
- // go for the default
- }
- }
- return fContentTypeManager.findContentTypesFor(location.lastSegment());
- }
-
- /**
- * Returns the set of direct base content types for the given set of content
- * types. Returns <code>null</code> if non of the given content types has
- * a direct base content type.
- *
- * @param contentTypes the content types
- * @return the set of direct base content types
- */
- private IContentType[] computeBaseContentTypes(IContentType[] contentTypes) {
- List baseTypes= new ArrayList();
- for (int i= 0; i < contentTypes.length; i++) {
- IContentType baseType= contentTypes[i].getBaseType();
- if (baseType != null)
- baseTypes.add(baseType);
- }
-
- IContentType[] result= null;
- int size= baseTypes.size();
- if (size > 0) {
- result= new IContentType[size];
- baseTypes.toArray(result);
- }
- return result;
- }
-
- /**
- * Returns the sharable document factory for the given location.
- *
- * @param location the location for which to looked up the factory
- * @return the sharable document factory
- */
- public IDocumentFactory getDocumentFactory(IPath location) {
- IDocumentFactory factory= getDocumentFactory(findContentTypes(location));
- if (factory == null)
- factory= getDocumentFactory(location.lastSegment());
- if (factory == null)
- factory= getDocumentFactory(location.getFileExtension());
- if (factory == null)
- factory= getDocumentFactory(WILDCARD);
- return factory;
- }
-
- /**
- * Returns the sharable set of document setup participants for the given location.
- *
- * @param location the location for which to look up the setup participants
- * @return the sharable set of document setup participants
- */
- public IDocumentSetupParticipant[] getDocumentSetupParticipants(IPath location) {
- List participants= new ArrayList();
-
- List p= getDocumentSetupParticipants(findContentTypes(location));
- if (p != null)
- participants.addAll(p);
-
- p= getDocumentSetupParticipants(location.lastSegment());
- if (p != null)
- participants.addAll(p);
-
- p= getDocumentSetupParticipants(location.getFileExtension());
- if (p != null)
- participants.addAll(p);
-
- p= getDocumentSetupParticipants(WILDCARD);
- if (p != null)
- participants.addAll(p);
-
- IDocumentSetupParticipant[] result= new IDocumentSetupParticipant[participants.size()];
- participants.toArray(result);
- return result;
- }
-
- /**
- * Returns the sharable annotation model factory for the given location.
- *
- * @param location the location for which to look up the factory
- * @return the sharable annotation model factory
- */
- public IAnnotationModelFactory getAnnotationModelFactory(IPath location) {
- IAnnotationModelFactory factory= getAnnotationModelFactory(findContentTypes(location));
- if (factory == null)
- factory= getAnnotationModelFactory(location.lastSegment());
- if (factory == null)
- factory= getAnnotationModelFactory(location.getFileExtension());
- if (factory == null)
- factory= getAnnotationModelFactory(WILDCARD);
- return factory;
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.java
deleted file mode 100644
index e3230fff257..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.core.internal.filebuffers;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-
-/**
- * Helper class to get NLSed messages.
- *
- * @since 3.0
- */
-class FileBuffersMessages {
-
- private static final String RESOURCE_BUNDLE= FileBuffersMessages.class.getName();
-
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private FileBuffersMessages() {
- }
-
- /**
- * Gets a string from the resource bundle.
- *
- * @param key the string used to get the bundle value, must not be <code>null</code>
- * @return the string from the resource bundle
- */
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- }
-
- /**
- * Gets a string from the resource bundle and formats it with the given arguments.
- *
- * @param key the string used to get the bundle value, must not be <code>null</code>
- * @param args the arguments used to format the string
- * @return the formatted string
- */
- public static String getFormattedString(String key, Object[] args) {
- String format= null;
- try {
- format= fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- return MessageFormat.format(format, args);
- }
-
- /**
- * Gets a string from the resource bundle and formats it with the given argument.
- *
- * @param key the string used to get the bundle value, must not be <code>null</code>
- * @param arg the argument used to format the string
- * @return the formatted string
- */
- public static String getFormattedString(String key, Object arg) {
- String format= null;
- try {
- format= fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- if (arg == null)
- arg= ""; //$NON-NLS-1$
- return MessageFormat.format(format, new Object[] { arg });
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.properties b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.properties
deleted file mode 100644
index efbe8b0d373..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.properties
+++ /dev/null
@@ -1,29 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Common Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/cpl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-ExtensionsRegistry.error.extensionPointNotFound= Extension point "{0}" not found.
-ExtensionsRegistry.error.contentTypeDoesNotExist= The content type with id "{0}" specified in the extension point does not exist.
-
-FileBuffer.error.fileDoesNotExist= The file does not exist.
-FileBuffer.error.outOfSync= The file is not synchronized with the the local file system.
-
-FileBuffer.status.ok= OK
-FileBuffer.status.error= Error
-
-FileBufferManager.error.canNotCreateFilebuffer= Cannot create file buffer.
-
-ContainerGenerator.task.creatingContainer= Creating container...
-ContainerGenerator.destinationMustBeAContainer=Specified path is not a folder: {0}
-
-ResourceTextFileBuffer.error.unsupported_encoding.message_arg= Character encoding \"{0}\" is not supported by this platform.
-ResourceTextFileBuffer.error.closeReader= Could not close reader.
-
-JavaTextFileBuffer.error.closeStream= Could not close stream.
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersPlugin.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersPlugin.java
deleted file mode 100644
index 14610ace3a2..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersPlugin.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import org.eclipse.core.runtime.Plugin;
-
-import org.eclipse.core.filebuffers.ITextFileBufferManager;
-
-import org.eclipse.jface.text.Assert;
-
-
-/**
- * The plug-in runtime class for the file buffers plug-in (id <code>"org.eclipse.core.filebuffers"</code>).
- *
- * @since 3.0
- */
-public class FileBuffersPlugin extends Plugin {
-
- public final static String PLUGIN_ID= "org.eclipse.core.filebuffers"; //$NON-NLS-1$
-
- /** The shared plug-in instance */
- private static FileBuffersPlugin fgPlugin;
- /** The resource bundle */
- private ResourceBundle fResourceBundle;
- /** The file buffer manager */
- private ITextFileBufferManager fTextFileBufferManager;
-
- /**
- * Creates a plug-in instance.
- */
- public FileBuffersPlugin() {
- Assert.isTrue(fgPlugin == null);
- fgPlugin= this;
- try {
- fResourceBundle= ResourceBundle.getBundle("org.eclipse.core.internal.filebuffers.FileBuffersPlugin"); //$NON-NLS-1$
- } catch (MissingResourceException x) {
- fResourceBundle = null;
- }
- }
-
- /**
- * Returns the shared instance.
- *
- * @return the default plug-in instance
- */
- public static FileBuffersPlugin getDefault() {
- return fgPlugin;
- }
-
- /**
- * Returns the string from the plugin's resource bundle,
- * or 'key' if not found.
- *
- * @param key the resource string key
- * @return the resource string for the given key
- */
- public static String getResourceString(String key) {
- ResourceBundle bundle= FileBuffersPlugin.getDefault().getResourceBundle();
- try {
- return (bundle!=null ? bundle.getString(key) : key);
- } catch (MissingResourceException e) {
- return key;
- }
- }
-
- /**
- * Returns the plugin's resource bundle.
- *
- * @return the resource bundle
- */
- private ResourceBundle getResourceBundle() {
- return fResourceBundle;
- }
-
- /**
- * Returns the text file buffer manager of this plug-in.
- *
- * @return the text file buffer manager of this plug-in
- */
- public ITextFileBufferManager getFileBufferManager() {
- if (fTextFileBufferManager == null)
- fTextFileBufferManager= new TextFileBufferManager();
- return fTextFileBufferManager;
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaFileBuffer.java
deleted file mode 100644
index 5b8b3535f5d..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaFileBuffer.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import java.io.File;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-import org.eclipse.core.filebuffers.FileBuffers;
-
-/**
- * @since 3.0
- */
-public abstract class JavaFileBuffer extends AbstractFileBuffer {
-
- /** The location */
- protected IPath fLocation;
- /** The element for which the info is stored */
- protected File fFile;
- /** How often the element has been connected */
- protected int fReferenceCount;
- /** Can the element be saved */
- protected boolean fCanBeSaved= false;
- /** The status of this element */
- protected IStatus fStatus;
- /** The time stamp at which this buffer synchronized with the underlying file. */
- protected long fSynchronizationStamp= IFile.NULL_STAMP;
- /** How often the synchronization context has been requested */
- protected int fSynchronizationContextCount;
- /** The text file buffer manager */
- protected TextFileBufferManager fManager;
-
-
- public JavaFileBuffer(TextFileBufferManager manager) {
- super();
- fManager= manager;
- }
-
- abstract protected void addFileBufferContentListeners();
-
- abstract protected void removeFileBufferContentListeners();
-
- abstract protected void initializeFileBufferContent(IProgressMonitor monitor) throws CoreException;
-
- abstract protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException;
-
- /**
- * Returns the file at the given location or <code>null</code> if
- * there is no such file.
- *
- * @param location the location
- * @return the file at the given location
- */
- private File getFileAtLocation(IPath location) {
- File file= FileBuffers.getSystemFileAtLocation(location);
- return file.exists() ? file : null;
- }
-
- public void create(IPath location, IProgressMonitor monitor) throws CoreException {
- File file= getFileAtLocation(location);
- if (file == null)
- throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("FileBuffer.error.fileDoesNotExist"), null)); //$NON-NLS-1$
-
- fLocation= location;
- fFile= file;
- initializeFileBufferContent(monitor);
- fSynchronizationStamp= fFile.lastModified();
-
- addFileBufferContentListeners();
- }
-
- public void connect() {
- ++ fReferenceCount;
- }
-
- public void disconnect() throws CoreException {
- -- fReferenceCount;
- }
-
- /**
- * Returns whether this file buffer has already been disposed.
- *
- * @return <code>true</code> if already disposed, <code>false</code> otherwise
- */
- public boolean isDisposed() {
- return fReferenceCount <= 0;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#getLocation()
- */
- public IPath getLocation() {
- return fLocation;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#commit(org.eclipse.core.runtime.IProgressMonitor, boolean)
- */
- public void commit(IProgressMonitor monitor, boolean overwrite) throws CoreException {
- if (!isDisposed() && fCanBeSaved) {
-
- fManager.fireStateChanging(this);
-
- try {
- commitFileBufferContent(monitor, overwrite);
- } catch (CoreException x) {
- fManager.fireStateChangeFailed(this);
- throw x;
- } catch (RuntimeException x) {
- fManager.fireStateChangeFailed(this);
- throw x;
- }
-
- fCanBeSaved= false;
- addFileBufferContentListeners();
- fManager.fireDirtyStateChanged(this, fCanBeSaved);
- }
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#isDirty()
- */
- public boolean isDirty() {
- return fCanBeSaved;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#isShared()
- */
- public boolean isShared() {
- return fReferenceCount > 1;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#validateState(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object)
- */
- public void validateState(IProgressMonitor monitor, Object computationContext) throws CoreException {
- // nop
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#isStateValidated()
- */
- public boolean isStateValidated() {
- return true;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#resetStateValidation()
- */
- public void resetStateValidation() {
- // nop
- }
-
- /**
- * Sends out the notification that the file serving as document input has been moved.
- *
- * @param newLocation the path of the new location of the file
- */
- protected void handleFileMoved(IPath newLocation) {
- fManager.fireUnderlyingFileMoved(this, newLocation);
- }
-
- /**
- * Defines the standard procedure to handle <code>CoreExceptions</code>. Exceptions
- * are written to the plug-in log.
- *
- * @param exception the exception to be logged
- * @param message the message to be logged
- */
- protected void handleCoreException(CoreException exception) {
- ILog log= FileBuffersPlugin.getDefault().getLog();
- log.log(exception.getStatus());
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#isSynchronized()
- */
- public boolean isSynchronized() {
- return fSynchronizationStamp == fFile.lastModified();
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#getModificationStamp()
- */
- public long getModificationStamp() {
- return fFile.lastModified();
- }
-
- /**
- * Requests the file buffer manager's synchronization context for this file buffer.
- */
- public void requestSynchronizationContext() {
- ++ fSynchronizationContextCount;
- }
-
- /**
- * Releases the file buffer manager's synchronization context for this file buffer.
- */
- public void releaseSynchronizationContext() {
- -- fSynchronizationContextCount;
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java
deleted file mode 100644
index 28bdfcda6a9..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-
-import org.eclipse.core.resources.IResourceStatus;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.content.IContentDescription;
-
-import org.eclipse.core.filebuffers.ITextFileBuffer;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.source.IAnnotationModel;
-
-/**
- * @since 3.0
- */
-public class JavaTextFileBuffer extends JavaFileBuffer implements ITextFileBuffer {
-
-
- private class DocumentListener implements IDocumentListener {
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent event) {
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentChanged(DocumentEvent event) {
- fCanBeSaved= true;
- removeFileBufferContentListeners();
- fManager.fireDirtyStateChanged(JavaTextFileBuffer.this, fCanBeSaved);
- }
- }
-
- /**
- * Reader chunk size.
- */
- private static final int READER_CHUNK_SIZE= 2048;
- /**
- * Buffer size.
- */
- private static final int BUFFER_SIZE= 8 * READER_CHUNK_SIZE;
- /**
- * Constant for representing the OK status. This is considered a value object.
- */
- private static final IStatus STATUS_OK= new Status(IStatus.OK, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("FileBuffer.status.ok"), null); //$NON-NLS-1$
- /**
- * Constant for representing the error status. This is considered a value object.
- */
- private static final IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.INFO, FileBuffersMessages.getString("FileBuffer.status.error"), null); //$NON-NLS-1$
- /**
- * Constant denoting UTF-8 encoding.
- */
- private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
-
-
- /** The element's document */
- protected IDocument fDocument;
- /** The encoding used to create the document from the storage or <code>null</code> for workbench encoding. */
- protected String fEncoding;
- /** Internal document listener */
- protected IDocumentListener fDocumentListener= new DocumentListener();
- /**
- * The encoding which has explicitly been set on the file.
- */
- private String fExplicitEncoding;
- /**
- * Tells whether the file on disk has a BOM.
- */
- private boolean fHasBOM;
-
-
- public JavaTextFileBuffer(TextFileBufferManager manager) {
- super(manager);
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedTextFile#getDocument()
- */
- public IDocument getDocument() {
- return fDocument;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.ITextFileBuffer#getAnnotationModel()
- */
- public IAnnotationModel getAnnotationModel() {
- return null;
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedTextFile#getEncoding()
- */
- public String getEncoding() {
- return fEncoding;
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedTextFile#setEncoding(java.lang.String)
- */
- public void setEncoding(String encoding) {
- fEncoding= encoding;
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedFile#getStatus()
- */
- public IStatus getStatus() {
- if (!isDisposed()) {
- if (fStatus != null)
- return fStatus;
- return (fDocument == null ? STATUS_ERROR : STATUS_OK);
- }
- return STATUS_ERROR;
- }
-
- private InputStream getFileContents(IProgressMonitor monitor) {
- try {
- return new FileInputStream(fFile);
- } catch (FileNotFoundException e) {
- }
- return null;
- }
-
- private void setFileContents(InputStream stream, boolean overwrite, IProgressMonitor monitor) {
- try {
- OutputStream out= new FileOutputStream(fFile, false);
-
- try {
- byte[] buffer = new byte[8192];
- while (true) {
- int bytesRead = -1;
- try {
- bytesRead = stream.read(buffer);
- } catch (IOException e) {
- }
- if (bytesRead == -1)
- break;
- try {
- out.write(buffer, 0, bytesRead);
- } catch (IOException e) {
- }
- monitor.worked(1);
- }
- } finally {
- try {
- stream.close();
- } catch (IOException e) {
- } finally {
- try {
- out.close();
- } catch (IOException e) {
- }
- }
- }
- } catch (FileNotFoundException e) {
- }
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#revert(org.eclipse.core.runtime.IProgressMonitor)
- */
- public void revert(IProgressMonitor monitor) throws CoreException {
- if (isDisposed())
- return;
-
- IDocument original= null;
- IStatus status= null;
-
- try {
- original= fManager.createEmptyDocument(getLocation());
- setDocumentContent(original, getFileContents(monitor), fEncoding);
- } catch (CoreException x) {
- status= x.getStatus();
- }
-
- fStatus= status;
-
- if (original != null) {
-
- String originalContents= original.get();
- boolean replaceContents= !originalContents.equals(fDocument.get());
-
- if (replaceContents) {
- fManager.fireBufferContentAboutToBeReplaced(this);
- fDocument.set(original.get());
- }
-
- if (fCanBeSaved) {
- fCanBeSaved= false;
- addFileBufferContentListeners();
- }
-
- if (replaceContents)
- fManager.fireBufferContentReplaced(this);
-
- fManager.fireDirtyStateChanged(this, fCanBeSaved);
- }
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.FileBuffer#addFileBufferContentListeners()
- */
- protected void addFileBufferContentListeners() {
- if (fDocument != null)
- fDocument.addDocumentListener(fDocumentListener);
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.FileBuffer#removeFileBufferContentListeners()
- */
- protected void removeFileBufferContentListeners() {
- if (fDocument != null)
- fDocument.removeDocumentListener(fDocumentListener);
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.FileBuffer#initializeFileBufferContent(org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void initializeFileBufferContent(IProgressMonitor monitor) throws CoreException {
- try {
- fDocument= fManager.createEmptyDocument(getLocation());
- fEncoding= null;
- fHasBOM= false;
-
- InputStream stream= getFileContents(monitor);
- try {
- QualifiedName[] options= new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
- IContentDescription description= Platform.getContentTypeManager().getDescriptionFor(stream, fFile.getName(), options);
- if (description != null) {
- fEncoding= description.getCharset();
- fHasBOM= description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null;
- }
- } catch (IOException e) {
- // do nothing
- } finally {
- try {
- stream.close();
- } catch (IOException ex) {
- FileBuffersPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("JavaTextFileBuffer.error.closeStream"), ex)); //$NON-NLS-1$
- }
- }
-
- setDocumentContent(fDocument, getFileContents(monitor), fEncoding);
- } catch (CoreException x) {
- fDocument= fManager.createEmptyDocument(getLocation());
- fStatus= x.getStatus();
- }
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.FileBuffer#commitFileBufferContent(org.eclipse.core.runtime.IProgressMonitor, boolean)
- */
- protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException {
- String encoding= computeEncoding();
- try {
-
- byte[] bytes= fDocument.get().getBytes(encoding);
-
- /*
- * XXX:
- * This is a workaround for a corresponding bug in Java readers and writer,
- * see: http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
- */
- if (fHasBOM && CHARSET_UTF_8.equals(encoding)) {
- int bomLength= IContentDescription.BOM_UTF_8.length;
- byte[] bytesWithBOM= new byte[bytes.length + bomLength];
- System.arraycopy(IContentDescription.BOM_UTF_8, 0, bytesWithBOM, 0, bomLength);
- System.arraycopy(bytes, 0, bytesWithBOM, bomLength, bytes.length);
- bytes= bytesWithBOM;
- }
-
- InputStream stream= new ByteArrayInputStream(bytes);
-
- if (fFile.exists()) {
-
- if (!overwrite)
- checkSynchronizationState();
-
-
- // here the file synchronizer should actually be removed and afterwards added again. However,
- // we are already inside an operation, so the delta is sent AFTER we have added the listener
- setFileContents(stream, overwrite, monitor);
- // set synchronization stamp to know whether the file synchronizer must become active
- fSynchronizationStamp= fFile.lastModified();
-
- // TODO if there is an annotation model update it here
-
- } else {
-
-// try {
-// monitor.beginTask("Saving", 2000); //$NON-NLS-1$
-// ContainerGenerator generator = new ContainerGenerator(fFile.getWorkspace(), fFile.getParent().getFullPath());
-// generator.generateContainer(new SubProgressMonitor(monitor, 1000));
-// fFile.create(stream, false, new SubProgressMonitor(monitor, 1000));
-// }
-// finally {
-// monitor.done();
-// }
-
- }
-
- } catch (UnsupportedEncodingException x) {
- String message= FileBuffersMessages.getFormattedString("ResourceTextFileBuffer.error.unsupported_encoding.message_arg", encoding); //$NON-NLS-1$
- IStatus s= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, x);
- throw new CoreException(s);
- }
- }
-
- private String computeEncoding() {
- // User-defined encoding has first priority
- if (fExplicitEncoding != null)
- return fExplicitEncoding;
-
- // Probe content
- Reader reader= new BufferedReader(new StringReader(fDocument.get()));
- try {
- QualifiedName[] options= new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
- IContentDescription description= Platform.getContentTypeManager().getDescriptionFor(reader, fFile.getName(), options);
- if (description != null) {
- String encoding= description.getCharset();
- if (encoding != null)
- return encoding;
- }
- } catch (IOException ex) {
- // try next strategy
- } finally {
- try {
- reader.close();
- } catch (IOException ex) {
- FileBuffersPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("ResourceTextFileBuffer.error.closeReader"), ex)); //$NON-NLS-1$
- }
- }
-
- // Use file's encoding if the file has a BOM
- if (fHasBOM)
- return fEncoding;
-
- // Use global default
- return fManager.getDefaultEncoding();
- }
-
- /**
- * Intitializes the given document with the given stream using the given encoding.
- *
- * @param document the document to be initialized
- * @param contentStream the stream which delivers the document content
- * @param encoding the character encoding for reading the given stream
- * @exception CoreException if the given stream can not be read
- */
- private void setDocumentContent(IDocument document, InputStream contentStream, String encoding) throws CoreException {
- Reader in= null;
- try {
-
- if (encoding == null)
- encoding= fManager.getDefaultEncoding();
-
- /*
- * XXX:
- * This is a workaround for a corresponding bug in Java readers and writer,
- * see: http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
- * </p>
- */
- if (fHasBOM && CHARSET_UTF_8.equals(encoding))
- contentStream.read(new byte[IContentDescription.BOM_UTF_8.length]);
-
- in= new BufferedReader(new InputStreamReader(contentStream, encoding), BUFFER_SIZE);
- StringBuffer buffer= new StringBuffer(BUFFER_SIZE);
- char[] readBuffer= new char[READER_CHUNK_SIZE];
- int n= in.read(readBuffer);
- while (n > 0) {
- buffer.append(readBuffer, 0, n);
- n= in.read(readBuffer);
- }
-
- document.set(buffer.toString());
-
- } catch (IOException x) {
- String msg= x.getMessage() == null ? "" : x.getMessage(); //$NON-NLS-1$
- IStatus s= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, msg, x);
- throw new CoreException(s);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException x) {
- }
- }
- }
- }
-
- /**
- * Checks whether the given file is synchronized with the the local file system.
- * If the file has been changed, a <code>CoreException</code> is thrown.
- *
- * @param file the file to check
- * @exception CoreException if file has been changed on the file system
- */
- private void checkSynchronizationState() throws CoreException {
- if (!isSynchronized()) {
- Status status= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IResourceStatus.OUT_OF_SYNC_LOCAL, FileBuffersMessages.getString("FileBuffer.error.outOfSync"), null); //$NON-NLS-1$
- throw new CoreException(status);
- }
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java
deleted file mode 100644
index d8acbd11282..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java
+++ /dev/null
@@ -1,426 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import java.io.File;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Status;
-
-import org.eclipse.core.filebuffers.FileBuffers;
-
-
-public abstract class ResourceFileBuffer extends AbstractFileBuffer {
-
- /**
- * Runnable encapsulating an element state change. This runnable ensures
- * that a element change failed message is sent out to the element state
- * listeners in case an exception occurred.
- */
- private class SafeFileChange implements Runnable {
-
- /**
- * Creates a new safe runnable for the given file.
- */
- public SafeFileChange() {
- }
-
- /**
- * Execute the change.
- * Subclass responsibility.
- *
- * @exception an exception in case of error
- */
- protected void execute() throws Exception {
- }
-
- /**
- * Does everything necessary prior to execution.
- */
- public void preRun() {
- fManager.fireStateChanging(ResourceFileBuffer.this);
- }
-
- /*
- * @see java.lang.Runnable#run()
- */
- public void run() {
-
- if (isDisposed()) {
- fManager.fireStateChangeFailed(ResourceFileBuffer.this);
- return;
- }
-
- try {
- execute();
- } catch (Exception x) {
- FileBuffersPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, "Exception when synchronizing", x)); //$NON-NLS-1$
- fManager.fireStateChangeFailed(ResourceFileBuffer.this);
- }
- }
- }
-
- /**
- * Synchronizes the document with external resource changes.
- */
- private class FileSynchronizer implements IResourceChangeListener, IResourceDeltaVisitor {
-
- /** A flag indicating whether this synchronizer is installed or not. */
- private boolean fIsInstalled= false;
-
- /**
- * Creates a new file synchronizer. Is not yet installed on a file.
- */
- public FileSynchronizer() {
- }
-
- /**
- * Installs the synchronizer on the file.
- */
- public void install() {
- fFile.getWorkspace().addResourceChangeListener(this);
- fIsInstalled= true;
- }
-
- /**
- * Uninstalls the synchronizer from the file.
- */
- public void uninstall() {
- fFile.getWorkspace().removeResourceChangeListener(this);
- fIsInstalled= false;
- }
-
- /*
- * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent)
- */
- public void resourceChanged(IResourceChangeEvent e) {
- IResourceDelta delta= e.getDelta();
- try {
- if (delta != null && fIsInstalled)
- delta.accept(this);
- } catch (CoreException x) {
- handleCoreException(x);
- }
- }
-
- /*
- * @see IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
- */
- public boolean visit(IResourceDelta delta) throws CoreException {
-
- if (delta != null && fFile.equals(delta.getResource())) {
-
- SafeFileChange fileChange= null;
-
- switch (delta.getKind()) {
- case IResourceDelta.CHANGED:
- if ((IResourceDelta.CONTENT & delta.getFlags()) != 0) {
- if (!isDisposed() && !fCanBeSaved && !isSynchronized()) {
- fileChange= new SafeFileChange() {
- protected void execute() throws Exception {
- handleFileContentChanged();
- }
- };
- }
- }
- break;
- case IResourceDelta.REMOVED:
- if ((IResourceDelta.MOVED_TO & delta.getFlags()) != 0) {
- final IPath path= delta.getMovedToPath();
- fileChange= new SafeFileChange() {
- protected void execute() throws Exception {
- handleFileMoved(path);
- }
- };
- } else {
- if (!isDisposed() && !fCanBeSaved) {
- fileChange= new SafeFileChange() {
- protected void execute() throws Exception {
- handleFileDeleted();
- }
- };
- }
- }
- break;
- }
-
- if (fileChange != null) {
- fileChange.preRun();
- fManager.execute(fileChange, fSynchronizationContextCount > 0);
- }
- }
-
- return true; // because we are sitting on files anyway
- }
- }
-
-
-
- /** The location */
- protected IPath fLocation;
- /** The element for which the info is stored */
- protected IFile fFile;
- /** How often the element has been connected */
- protected int fReferenceCount;
- /** Can the element be saved */
- protected boolean fCanBeSaved= false;
- /** Has element state been validated */
- protected boolean fIsStateValidated= false;
- /** The status of this element */
- protected IStatus fStatus;
- /** The file synchronizer. */
- protected FileSynchronizer fFileSynchronizer;
- /** The time stamp at which this buffer synchronized with the underlying file. */
- protected long fSynchronizationStamp= IFile.NULL_STAMP;
- /** How often the synchronization context has been requested */
- protected int fSynchronizationContextCount;
- /** The text file buffer manager */
- protected TextFileBufferManager fManager;
-
-
-
-
- public ResourceFileBuffer(TextFileBufferManager manager) {
- super();
- fManager= manager;
- }
-
- abstract protected void handleFileContentChanged();
-
- abstract protected void addFileBufferContentListeners();
-
- abstract protected void removeFileBufferContentListeners();
-
- abstract protected void initializeFileBufferContent(IProgressMonitor monitor) throws CoreException;
-
- abstract protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException;
-
- public void create(IPath location, IProgressMonitor monitor) throws CoreException {
- IFile file= FileBuffers.getWorkspaceFileAtLocation(location);
- if (file == null || !file.exists())
- throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("FileBuffer.error.fileDoesNotExist"), null)); //$NON-NLS-1$
-
- fLocation= location;
- fFile= file;
- fFileSynchronizer= new FileSynchronizer();
-
- refreshFile(monitor);
- initializeFileBufferContent(monitor);
- fSynchronizationStamp= fFile.getModificationStamp();
-
- addFileBufferContentListeners();
- }
-
- public void connect() {
- ++ fReferenceCount;
- if (fReferenceCount == 1)
- connected();
- }
-
- /**
- * Called when this file buffer has been connected. This is the case when
- * there is exactly one connection.
- * <p>
- * Clients may extend this method.
- */
- protected void connected() {
- fFileSynchronizer.install();
- }
-
- public void disconnect() throws CoreException {
- -- fReferenceCount;
- if (fReferenceCount == 0)
- disconnected();
- }
-
- /**
- * Called when this file buffer has been disconnected. This is the case when
- * the number of connections drops to <code>0</code>.
- * <p>
- * Clients may extend this method.
- */
- protected void disconnected() {
- if (fFileSynchronizer != null)
- fFileSynchronizer.uninstall();
- fFileSynchronizer= null;
- }
-
- /**
- * Returns whether this file buffer has already been disposed.
- *
- * @return <code>true</code> if already disposed, <code>false</code> otherwise
- */
- public boolean isDisposed() {
- return fFileSynchronizer == null;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#getLocation()
- */
- public IPath getLocation() {
- return fLocation;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#commit(org.eclipse.core.runtime.IProgressMonitor, boolean)
- */
- public void commit(IProgressMonitor monitor, boolean overwrite) throws CoreException {
- if (!isDisposed() && fCanBeSaved) {
-
- fManager.fireStateChanging(this);
-
- try {
- commitFileBufferContent(monitor, overwrite);
- } catch (CoreException x) {
- fManager.fireStateChangeFailed(this);
- throw x;
- } catch (RuntimeException x) {
- fManager.fireStateChangeFailed(this);
- throw x;
- }
-
- fCanBeSaved= false;
- addFileBufferContentListeners();
- fManager.fireDirtyStateChanged(this, fCanBeSaved);
- }
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#isDirty()
- */
- public boolean isDirty() {
- return fCanBeSaved;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#isShared()
- */
- public boolean isShared() {
- return fReferenceCount > 1;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#validateState(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object)
- */
- public void validateState(IProgressMonitor monitor, Object computationContext) throws CoreException {
- if (!isDisposed() && !fIsStateValidated) {
-
- if (fFile.isReadOnly()) {
- IWorkspace workspace= fFile.getWorkspace();
- fStatus= workspace.validateEdit(new IFile[] { fFile }, computationContext);
- if (fStatus.isOK())
- handleFileContentChanged();
- }
- fIsStateValidated= true;
- fManager.fireStateValidationChanged(this, fIsStateValidated);
- }
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#isStateValidated()
- */
- public boolean isStateValidated() {
- return fIsStateValidated;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#resetStateValidation()
- */
- public void resetStateValidation() {
- if (fIsStateValidated) {
- fIsStateValidated= false;
- fManager.fireStateValidationChanged(this, fIsStateValidated);
- }
- }
-
- /**
- * Sends out the notification that the file serving as document input has been moved.
- *
- * @param newLocation the path of the new location of the file
- */
- protected void handleFileMoved(IPath newLocation) {
- fManager.fireUnderlyingFileMoved(this, newLocation);
- }
-
- /**
- * Sends out the notification that the file serving as document input has been deleted.
- */
- protected void handleFileDeleted() {
- fManager.fireUnderlyingFileDeleted(this);
- }
-
- /**
- * Refreshes the given file.
- */
- protected void refreshFile(IProgressMonitor monitor) {
- try {
- fFile.refreshLocal(IFile.DEPTH_INFINITE, monitor);
- } catch (OperationCanceledException x) {
- } catch (CoreException x) {
- handleCoreException(x);
- }
- }
-
- /**
- * Defines the standard procedure to handle <code>CoreExceptions</code>. Exceptions
- * are written to the plug-in log.
- *
- * @param exception the exception to be logged
- * @param message the message to be logged
- */
- protected void handleCoreException(CoreException exception) {
- ILog log= FileBuffersPlugin.getDefault().getLog();
- log.log(exception.getStatus());
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#isSynchronized()
- */
- public boolean isSynchronized() {
- return fSynchronizationStamp == fFile.getModificationStamp() && fFile.isSynchronized(IResource.DEPTH_ZERO);
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#getModificationStamp()
- */
- public long getModificationStamp() {
- File file= FileBuffers.getSystemFileAtLocation(getLocation());
- if (file != null)
- return file.lastModified();
- return IResource.NULL_STAMP;
- }
-
- /**
- * Requests the file buffer manager's synchronization context for this file buffer.
- */
- public void requestSynchronizationContext() {
- ++ fSynchronizationContextCount;
- }
-
- /**
- * Releases the file buffer manager's synchronization context for this file buffer.
- */
- public void releaseSynchronizationContext() {
- -- fSynchronizationContextCount;
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
deleted file mode 100644
index c1d7612acfc..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
+++ /dev/null
@@ -1,523 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResourceStatus;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.core.runtime.content.IContentDescription;
-
-import org.eclipse.core.filebuffers.IPersistableAnnotationModel;
-import org.eclipse.core.filebuffers.ITextFileBuffer;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.source.IAnnotationModel;
-
-/**
- * @since 3.0
- */
-public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextFileBuffer {
-
-
- private class DocumentListener implements IDocumentListener {
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent event) {
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentChanged(DocumentEvent event) {
- fCanBeSaved= true;
- removeFileBufferContentListeners();
- fManager.fireDirtyStateChanged(ResourceTextFileBuffer.this, fCanBeSaved);
- }
- }
-
- /**
- * Reader chunk size.
- */
- static final private int READER_CHUNK_SIZE= 2048;
- /**
- * Buffer size.
- */
- static final private int BUFFER_SIZE= 8 * READER_CHUNK_SIZE;
- /**
- * Qualified name for the encoding key.
- */
- static final private QualifiedName ENCODING_KEY= new QualifiedName(FileBuffersPlugin.PLUGIN_ID, "encoding"); //$NON-NLS-1$
- /**
- * Constant for representing the OK status. This is considered a value object.
- */
- static final private IStatus STATUS_OK= new Status(IStatus.OK, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("FileBuffer.status.ok"), null); //$NON-NLS-1$
- /**
- * Constant for representing the error status. This is considered a value object.
- */
- static final private IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.INFO, FileBuffersMessages.getString("FileBuffer.status.error"), null); //$NON-NLS-1$
- /**
- * Constant denoting UTF-8 encoding.
- */
- private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
-
-
- /** The element's document */
- protected IDocument fDocument;
- /** The encoding used to create the document from the storage or <code>null</code> for workbench encoding. */
- protected String fEncoding;
- /** Internal document listener */
- protected IDocumentListener fDocumentListener= new DocumentListener();
- /** The element's annotation model */
- protected IAnnotationModel fAnnotationModel;
- /**
- * The encoding which has explicitly been set on the file.
- */
- private String fExplicitEncoding;
- /**
- * Tells whether the file on disk has a BOM.
- */
- private boolean fHasBOM;
-
-
- public ResourceTextFileBuffer(TextFileBufferManager manager) {
- super(manager);
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedTextFile#getDocument()
- */
- public IDocument getDocument() {
- return fDocument;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.ITextFileBuffer#getAnnotationModel()
- */
- public IAnnotationModel getAnnotationModel() {
- return fAnnotationModel;
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedTextFile#getEncoding()
- */
- public String getEncoding() {
- return fEncoding;
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedTextFile#setEncoding(java.lang.String)
- */
- public void setEncoding(String encoding) {
- fEncoding= encoding;
- fExplicitEncoding= encoding;
- fHasBOM= false;
- try {
- fFile.setCharset(encoding);
- if (encoding == null)
- fEncoding= fFile.getCharset();
- setHasBOM();
- } catch (CoreException x) {
- handleCoreException(x);
- }
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedFile#getStatus()
- */
- public IStatus getStatus() {
- if (!isDisposed()) {
- if (fStatus != null)
- return fStatus;
- return (fDocument == null ? STATUS_ERROR : STATUS_OK);
- }
- return STATUS_ERROR;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBuffer#revert(org.eclipse.core.runtime.IProgressMonitor)
- */
- public void revert(IProgressMonitor monitor) throws CoreException {
- if (isDisposed())
- return;
-
- refreshFile(monitor);
-
- IDocument original= null;
- IStatus status= null;
-
- try {
- original= fManager.createEmptyDocument(fFile.getLocation());
- setDocumentContent(original, fFile.getContents(), fEncoding);
- } catch (CoreException x) {
- status= x.getStatus();
- }
-
- fStatus= status;
-
- if (original != null) {
-
- String originalContents= original.get();
- boolean replaceContents= !originalContents.equals(fDocument.get());
-
- if (replaceContents) {
- fManager.fireBufferContentAboutToBeReplaced(this);
- fDocument.set(original.get());
- }
-
- if (fCanBeSaved) {
- fCanBeSaved= false;
- addFileBufferContentListeners();
- }
-
- if (replaceContents)
- fManager.fireBufferContentReplaced(this);
-
- if (fAnnotationModel instanceof IPersistableAnnotationModel) {
- IPersistableAnnotationModel persistableModel= (IPersistableAnnotationModel) fAnnotationModel;
- persistableModel.revert(fDocument);
- }
-
- fManager.fireDirtyStateChanged(this, fCanBeSaved);
- }
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.FileBuffer#addFileBufferContentListeners()
- */
- protected void addFileBufferContentListeners() {
- if (fDocument != null)
- fDocument.addDocumentListener(fDocumentListener);
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.FileBuffer#removeFileBufferContentListeners()
- */
- protected void removeFileBufferContentListeners() {
- if (fDocument != null)
- fDocument.removeDocumentListener(fDocumentListener);
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.FileBuffer#initializeFileBufferContent(org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void initializeFileBufferContent(IProgressMonitor monitor) throws CoreException {
- try {
- fEncoding= null;
- fExplicitEncoding= null;
- try {
- fEncoding= fFile.getPersistentProperty(ENCODING_KEY);
- } catch (CoreException x) {
- // we ignore exceptions here because we support the ENCODING_KEY property only for compatibility reasons
- }
- if (fEncoding != null) {
- // if we found an old encoding property, we try to migrate it to the new core.resources encoding support
- try {
- fExplicitEncoding= fEncoding;
- fFile.setCharset(fEncoding);
- // if successful delete old property
- fFile.setPersistentProperty(ENCODING_KEY, null);
- } catch (CoreException ex) {
- // log problem because we could not migrate the property successfully
- handleCoreException(ex);
- }
- } else {
- fExplicitEncoding= fFile.getCharset(false);
- if (fExplicitEncoding != null)
- fEncoding= fExplicitEncoding;
- else
- fEncoding= fFile.getCharset();
- }
-
- setHasBOM();
-
- fDocument= fManager.createEmptyDocument(fFile.getLocation());
- setDocumentContent(fDocument, fFile.getContents(), fEncoding);
-
- fAnnotationModel= fManager.createAnnotationModel(fFile.getLocation());
-
- } catch (CoreException x) {
- fDocument= fManager.createEmptyDocument(fFile.getLocation());
- fStatus= x.getStatus();
- }
- }
-
- /**
- * Sets whether the underlying file has a BOM.
- *
- * @throws CoreException if reading of file's content description fails
- */
- protected void setHasBOM() throws CoreException {
- fHasBOM= false;
- IContentDescription description= fFile.getContentDescription();
- fHasBOM= description != null && description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null;
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.ResourceFileBuffer#connected()
- */
- protected void connected() {
- super.connected();
- if (fAnnotationModel != null)
- fAnnotationModel.connect(fDocument);
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.ResourceFileBuffer#disconnected()
- */
- protected void disconnected() {
- if (fAnnotationModel != null)
- fAnnotationModel.disconnect(fDocument);
- super.disconnected();
- }
-
- /*
- * @see org.eclipse.core.internal.filebuffers.FileBuffer#commitFileBufferContent(org.eclipse.core.runtime.IProgressMonitor, boolean)
- */
- protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException {
- String encoding= computeEncoding();
- try {
-
- byte[] bytes= fDocument.get().getBytes(encoding);
-
- /*
- * XXX:
- * This is a workaround for a corresponding bug in Java readers and writer,
- * see: http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
- */
- if (fHasBOM && CHARSET_UTF_8.equals(encoding)) {
- int bomLength= IContentDescription.BOM_UTF_8.length;
- byte[] bytesWithBOM= new byte[bytes.length + bomLength];
- System.arraycopy(IContentDescription.BOM_UTF_8, 0, bytesWithBOM, 0, bomLength);
- System.arraycopy(bytes, 0, bytesWithBOM, bomLength, bytes.length);
- bytes= bytesWithBOM;
- }
-
- InputStream stream= new ByteArrayInputStream(bytes);
- if (fFile.exists()) {
-
- if (!overwrite)
- checkSynchronizationState();
-
-
- // here the file synchronizer should actually be removed and afterwards added again. However,
- // we are already inside an operation, so the delta is sent AFTER we have added the listener
- fFile.setContents(stream, overwrite, true, monitor);
- // set synchronization stamp to know whether the file synchronizer must become active
- fSynchronizationStamp= fFile.getModificationStamp();
-
- if (fAnnotationModel instanceof IPersistableAnnotationModel) {
- IPersistableAnnotationModel persistableModel= (IPersistableAnnotationModel) fAnnotationModel;
- persistableModel.commit(fDocument);
- }
-
- } else {
-
- try {
- monitor.beginTask("Saving", 2000); //$NON-NLS-1$
- ContainerGenerator generator = new ContainerGenerator(fFile.getWorkspace(), fFile.getParent().getFullPath());
- generator.generateContainer(new SubProgressMonitor(monitor, 1000));
- fFile.create(stream, false, new SubProgressMonitor(monitor, 1000));
- }
- finally {
- monitor.done();
- }
- }
-
- } catch (UnsupportedEncodingException x) {
- String message= FileBuffersMessages.getFormattedString("ResourceTextFileBuffer.error.unsupported_encoding.message_arg", encoding); //$NON-NLS-1$
- IStatus s= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, x);
- throw new CoreException(s);
- }
- }
-
- private String computeEncoding() {
- // User-defined encoding has first priority
- if (fExplicitEncoding != null)
- return fExplicitEncoding;
- try {
- /*
- * FIXME
- * Check whether explicit encoding has been set via properties dialog.
- * This is needed because no notification is sent when this property
- * changes, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=64077
- */
- fExplicitEncoding= fFile.getCharset(false);
- if (fExplicitEncoding != null)
- return fExplicitEncoding;
- } catch (CoreException e) {
- }
-
- // Probe content
- Reader reader= new BufferedReader(new StringReader(fDocument.get()));
- try {
- QualifiedName[] options= new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
- IContentDescription description= Platform.getContentTypeManager().getDescriptionFor(reader, fFile.getName(), options);
- if (description != null) {
- String encoding= description.getCharset();
- if (encoding != null)
- return encoding;
- }
- } catch (IOException ex) {
- // try next strategy
- } finally {
- try {
- reader.close();
- } catch (IOException ex) {
- FileBuffersPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("ResourceTextFileBuffer.error.closeReader"), ex)); //$NON-NLS-1$
- }
- }
-
- // Use file's encoding if the file has a BOM
- if (fHasBOM)
- return fEncoding;
-
- // Use parent chain
- try {
- return fFile.getParent().getDefaultCharset();
- } catch (CoreException ex) {
- // Use global default
- return fManager.getDefaultEncoding();
- }
- }
-
- /**
- * Updates the element info to a change of the file content and sends out appropriate notifications.
- */
- protected void handleFileContentChanged() {
- if (isDisposed())
- return;
-
- IDocument document= fManager.createEmptyDocument(fFile.getLocation());
- IStatus status= null;
-
- try {
- setDocumentContent(document, fFile.getContents(false), fEncoding);
- } catch (CoreException x) {
- status= x.getStatus();
- }
-
- String newContent= document.get();
-
- if ( !newContent.equals(fDocument.get())) {
-
- fManager.fireBufferContentAboutToBeReplaced(this);
-
- removeFileBufferContentListeners();
- fDocument.set(newContent);
- fCanBeSaved= false;
- fSynchronizationStamp= fFile.getModificationStamp();
- fStatus= status;
- addFileBufferContentListeners();
-
- fManager.fireBufferContentReplaced(this);
-
- if (fAnnotationModel instanceof IPersistableAnnotationModel) {
- IPersistableAnnotationModel persistableModel= (IPersistableAnnotationModel) fAnnotationModel;
- try {
- persistableModel.reinitialize(fDocument);
- } catch (CoreException x) {
- fStatus= status;
- }
- }
-
- } else {
-
- removeFileBufferContentListeners();
- fCanBeSaved= false;
- fSynchronizationStamp= fFile.getModificationStamp();
- fStatus= status;
- addFileBufferContentListeners();
-
- fManager.fireDirtyStateChanged(this, fCanBeSaved);
- }
- }
-
- /**
- * Intitializes the given document with the given stream using the given encoding.
- *
- * @param document the document to be initialized
- * @param contentStream the stream which delivers the document content
- * @param encoding the character encoding for reading the given stream
- * @exception CoreException if the given stream can not be read
- */
- private void setDocumentContent(IDocument document, InputStream contentStream, String encoding) throws CoreException {
- Reader in= null;
- try {
-
- if (encoding == null)
- encoding= fManager.getDefaultEncoding();
-
- /*
- * XXX:
- * This is a workaround for a corresponding bug in Java readers and writer,
- * see: http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
- */
- if (fHasBOM && CHARSET_UTF_8.equals(encoding))
- contentStream.read(new byte[IContentDescription.BOM_UTF_8.length]);
-
- in= new BufferedReader(new InputStreamReader(contentStream, encoding), BUFFER_SIZE);
- StringBuffer buffer= new StringBuffer(BUFFER_SIZE);
- char[] readBuffer= new char[READER_CHUNK_SIZE];
- int n= in.read(readBuffer);
- while (n > 0) {
- buffer.append(readBuffer, 0, n);
- n= in.read(readBuffer);
- }
-
- document.set(buffer.toString());
-
- } catch (IOException x) {
- String message= (x.getMessage() != null ? x.getMessage() : ""); //$NON-NLS-1$
- IStatus s= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, x);
- throw new CoreException(s);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException x) {
- }
- }
- }
- }
-
- /**
- * Checks whether the given file is synchronized with the the local file system.
- * If the file has been changed, a <code>CoreException</code> is thrown.
- *
- * @param file the file to check
- * @exception CoreException if file has been changed on the file system
- */
- private void checkSynchronizationState() throws CoreException {
- if (!fFile.isSynchronized(IFile.DEPTH_ZERO)) {
- Status status= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IResourceStatus.OUT_OF_SYNC_LOCAL, FileBuffersMessages.getString("FileBuffer.error.outOfSync"), null); //$NON-NLS-1$
- throw new CoreException(status);
- }
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java
deleted file mode 100644
index c179f10286b..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.filebuffers;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-import org.eclipse.core.filebuffers.FileBuffers;
-import org.eclipse.core.filebuffers.IAnnotationModelFactory;
-import org.eclipse.core.filebuffers.IDocumentFactory;
-import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
-import org.eclipse.core.filebuffers.IFileBuffer;
-import org.eclipse.core.filebuffers.IFileBufferListener;
-import org.eclipse.core.filebuffers.ISynchronizationContext;
-import org.eclipse.core.filebuffers.ITextFileBuffer;
-import org.eclipse.core.filebuffers.ITextFileBufferManager;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.source.IAnnotationModel;
-
-/**
- * @since 3.0
- */
-public class TextFileBufferManager implements ITextFileBufferManager {
-
- private Map fFilesBuffers= new HashMap();
- private List fFileBufferListeners= new ArrayList();
- private ExtensionsRegistry fRegistry;
- private ISynchronizationContext fSynchronizationContext;
-
-
- public TextFileBufferManager() {
- fRegistry= new ExtensionsRegistry();
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBufferManager#connect(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IProgressMonitor)
- */
- public void connect(IPath location, IProgressMonitor monitor) throws CoreException {
- Assert.isNotNull(location);
- location= FileBuffers.normalizeLocation(location);
-
- AbstractFileBuffer fileBuffer= (AbstractFileBuffer) fFilesBuffers.get(location);
- if (fileBuffer == null) {
-
- fileBuffer= createFileBuffer(location);
- if (fileBuffer == null)
- throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, 0, FileBuffersMessages.getString("FileBufferManager.error.canNotCreateFilebuffer"), null)); //$NON-NLS-1$
-
- fileBuffer.create(location, monitor);
- fileBuffer.connect();
- fFilesBuffers.put(location, fileBuffer);
- fireBufferCreated(fileBuffer);
-
- } else {
- fileBuffer.connect();
- }
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBufferManager#disconnect(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IProgressMonitor)
- */
- public void disconnect(IPath location, IProgressMonitor monitor) throws CoreException {
- Assert.isNotNull(location);
- location= FileBuffers.normalizeLocation(location);
-
- AbstractFileBuffer fileBuffer= (AbstractFileBuffer) fFilesBuffers.get(location);
- if (fileBuffer != null) {
- fileBuffer.disconnect();
- if (fileBuffer.isDisposed()) {
- fFilesBuffers.remove(location);
- fireBufferDisposed(fileBuffer);
- }
- }
- }
-
- private AbstractFileBuffer createFileBuffer(IPath location) {
- if (!isTextFile(location))
- return null;
-
- if (isWorkspaceResource(location))
- return new ResourceTextFileBuffer(this);
-
- return new JavaTextFileBuffer(this);
- }
-
- private boolean isWorkspaceResource(IPath location) {
- return FileBuffers.getWorkspaceFileAtLocation(location) != null;
- }
-
- private boolean isTextFile(IPath location) {
- return true;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBufferManager#getFileBuffer(org.eclipse.core.runtime.IPath)
- */
- public IFileBuffer getFileBuffer(IPath location) {
- location= FileBuffers.normalizeLocation(location);
- return (IFileBuffer) fFilesBuffers.get(location);
- }
-
- /*
- * @see org.eclipse.core.filebuffers.ITextFileBufferManager#getTextFileBuffer(org.eclipse.core.runtime.IPath)
- */
- public ITextFileBuffer getTextFileBuffer(IPath location) {
- location= FileBuffers.normalizeLocation(location);
- return (ITextFileBuffer) fFilesBuffers.get(location);
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedFileManager#getDefaultEncoding()
- */
- public String getDefaultEncoding() {
- return ResourcesPlugin.getEncoding();
- }
-
- /*
- * @see org.eclipse.core.filebuffers.ITextFileBufferManager#createEmptyDocument(org.eclipse.core.runtime.IPath)
- */
- public IDocument createEmptyDocument(IPath location) {
- Assert.isNotNull(location);
- location= FileBuffers.normalizeLocation(location);
-
- IDocumentFactory factory= fRegistry.getDocumentFactory(location);
-
- IDocument document= null;
- if (factory != null)
- document= factory.createDocument();
- else
- document= new Document();
-
- IDocumentSetupParticipant[] participants= fRegistry.getDocumentSetupParticipants(location);
- if (participants != null) {
- for (int i= 0; i < participants.length; i++)
- participants[i].setup(document);
- }
-
- return document;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.ITextFileBufferManager#createAnnotationModel(org.eclipse.core.runtime.IPath)
- */
- public IAnnotationModel createAnnotationModel(IPath location) {
- Assert.isNotNull(location);
- location= FileBuffers.normalizeLocation(location);
- IAnnotationModelFactory factory= fRegistry.getAnnotationModelFactory(location);
- if (factory != null)
- return factory.createAnnotationModel(location);
- return null;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBufferManager#addFileBufferListener(org.eclipse.core.filebuffers.IFileBufferListener)
- */
- public void addFileBufferListener(IFileBufferListener listener) {
- Assert.isNotNull(listener);
- if (!fFileBufferListeners.contains(listener))
- fFileBufferListeners.add(listener);
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBufferManager#removeFileBufferListener(org.eclipse.core.filebuffers.IFileBufferListener)
- */
- public void removeFileBufferListener(IFileBufferListener listener) {
- Assert.isNotNull(listener);
- fFileBufferListeners.remove(listener);
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBufferManager#setSynchronizationContext(org.eclipse.core.filebuffers.ISynchronizationContext)
- */
- public void setSynchronizationContext(ISynchronizationContext context) {
- fSynchronizationContext= context;
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBufferManager#requestSynchronizationContext(org.eclipse.core.runtime.IPath)
- */
- public void requestSynchronizationContext(IPath location) {
- Assert.isNotNull(location);
- location= FileBuffers.normalizeLocation(location);
-
- AbstractFileBuffer fileBuffer= (AbstractFileBuffer) fFilesBuffers.get(location);
- if (fileBuffer != null)
- fileBuffer.requestSynchronizationContext();
- }
-
- /*
- * @see org.eclipse.core.filebuffers.IFileBufferManager#releaseSynchronizationContext(org.eclipse.core.runtime.IPath)
- */
- public void releaseSynchronizationContext(IPath location) {
- Assert.isNotNull(location);
- location= FileBuffers.normalizeLocation(location);
-
- AbstractFileBuffer fileBuffer= (AbstractFileBuffer) fFilesBuffers.get(location);
- if (fileBuffer != null)
- fileBuffer.releaseSynchronizationContext();
- }
-
- /**
- * Executes the given runnable in the synchronization context of this file buffer manager.
- * If there is no synchronization context connected with this manager, the runnable is
- * directly executed.
- *
- * @param runnable the runnable to be executed
- */
- public void execute(Runnable runnable, boolean requestSynchronizationContext) {
- if (requestSynchronizationContext && fSynchronizationContext != null)
- fSynchronizationContext.run(runnable);
- else
- runnable.run();
- }
-
- protected void fireDirtyStateChanged(IFileBuffer buffer, boolean isDirty) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.dirtyStateChanged(buffer, isDirty);
- }
- }
-
- protected void fireBufferContentAboutToBeReplaced(IFileBuffer buffer) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.bufferContentAboutToBeReplaced(buffer);
- }
- }
-
- protected void fireBufferContentReplaced(IFileBuffer buffer) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.bufferContentReplaced(buffer);
- }
- }
-
- protected void fireUnderlyingFileMoved(IFileBuffer buffer, IPath target) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.underlyingFileMoved(buffer, target);
- }
- }
-
- protected void fireUnderlyingFileDeleted(IFileBuffer buffer) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.underlyingFileDeleted(buffer);
- }
- }
-
- protected void fireStateValidationChanged(IFileBuffer buffer, boolean isStateValidated) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.stateValidationChanged(buffer, isStateValidated);
- }
- }
-
- protected void fireStateChanging(IFileBuffer buffer) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.stateChanging(buffer);
- }
- }
-
- protected void fireStateChangeFailed(IFileBuffer buffer) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.stateChangeFailed(buffer);
- }
- }
-
- protected void fireBufferCreated(IFileBuffer buffer) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.bufferCreated(buffer);
- }
- }
-
- protected void fireBufferDisposed(IFileBuffer buffer) {
- Iterator e= new ArrayList(fFileBufferListeners).iterator();
- while (e.hasNext()) {
- IFileBufferListener l= (IFileBufferListener) e.next();
- l.bufferDisposed(buffer);
- }
- }
-}

Back to the top