Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.core.filebuffers/src/org/eclipse/core')
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/FileBuffers.java100
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IDocumentFactory.java29
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IDocumentSetupParticipant.java28
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBuffer.java130
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferListener.java98
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferManager.java138
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ISynchronizationContext.java26
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBuffer.java48
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java64
-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.java111
-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.java231
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersPlugin.java84
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaFileBuffer.java218
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java337
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java406
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java346
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java301
19 files changed, 0 insertions, 2763 deletions
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/FileBuffers.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/FileBuffers.java
deleted file mode 100644
index 99752828a0a..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/FileBuffers.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-package org.eclipse.core.filebuffers;
-
-import java.io.File;
-
-import org.eclipse.core.internal.filebuffers.FileBuffersPlugin;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-
-/**
- * Facade for the file buffers plug-in. Provides access to the
- * text file buffer manager.
- *
- * @since 3.0
- */
-public final class FileBuffers {
-
- /**
- * Cannot be instantiated.
- */
- private FileBuffers() {
- }
-
- /**
- * Returns the text file buffer manager.
- *
- * @return the text file buffer manager
- */
- public static ITextFileBufferManager getTextFileBufferManager() {
- return FileBuffersPlugin.getDefault().getFileBufferManager();
- }
-
- /**
- * Returns the workspace file at the given location or <code>null</code> if
- * the location is not a valid location in the workspace.
- *
- * @param location the location
- * @return the workspace file at the location or <code>null</code>
- */
- public static IFile getWorkspaceFileAtLocation(IPath location) {
- IPath normalized= normalizeLocation(location);
- IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
- IFile file= workspaceRoot.getFile(normalized);
- if (file != null && file.exists())
- return file;
- return null;
- }
-
- /**
- * Returns a copy of the given location in a normalized form.
- *
- * @param location the location to be normalized
- * @return normalized copy of location
- */
- public static IPath normalizeLocation(IPath location) {
- IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
- IPath workspacePath= workspaceRoot.getLocation();
- if (!workspacePath.isPrefixOf(location))
- return location.makeAbsolute();
-
- IPath fileLocation= location.removeFirstSegments(workspacePath.segmentCount());
- fileLocation= fileLocation.setDevice(null);
- return fileLocation.makeAbsolute();
-
- }
-
- /**
- * Returns the file in the local file system for the given location.
- * <p>
- * The location is either a full path of a workspace resource or an
- * absolute path in the local file system.
- * </p>
- *
- * @param location
- * @return
- */
- public static File getSystemFileAtLocation(IPath location) {
- if (location == null)
- return null;
-
- IFile file= getWorkspaceFileAtLocation(location);
- if (file != null) {
- IPath path= file.getLocation();
- return path.toFile();
- }
-
- return location.toFile();
- }
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IDocumentFactory.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IDocumentFactory.java
deleted file mode 100644
index 989ecf993c3..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IDocumentFactory.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-package org.eclipse.core.filebuffers;
-
-import org.eclipse.jface.text.IDocument;
-
-/**
- * Factory for text file buffer documents. Used by the text file buffer
- * manager to create the document for a new text file buffer.
- *
- * @since 3.0
- */
-public interface IDocumentFactory {
-
- /**
- * Creates and returns a new, empty document.
- *
- * @return a new, empty document
- */
- IDocument createDocument();
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IDocumentSetupParticipant.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IDocumentSetupParticipant.java
deleted file mode 100644
index 93a5d5ad871..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IDocumentSetupParticipant.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-package org.eclipse.core.filebuffers;
-
-import org.eclipse.jface.text.IDocument;
-
-/**
- * Participates in the setup of a text file buffer document.
- *
- * @since 3.0
- */
-public interface IDocumentSetupParticipant {
-
- /**
- * Sets up the document to be ready for use by a text file buffer.
- *
- * @param document the document to be set up
- */
- void setup(IDocument document);
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBuffer.java
deleted file mode 100644
index 8ae2afeea1a..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBuffer.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-package org.eclipse.core.filebuffers;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-
-/**
- * A file buffer represents a file that can be edited by more than one client. Editing is
- * session oriented. This means that editing is a sequence of modification steps. The
- * start of the sequence and the end of the sequence are explicitly indicated. There are
- * no time constraints connected with the sequence of modification steps. A file buffer
- * reifies editing sessions and allows them to interleave.<p>
- * It is not specified whether simultaneous editing sessions can be owned by different
- * threads.
- *
- * @since 3.0
- */
-public interface IFileBuffer {
-
- /**
- * Returns the location of this file buffer.
- * <p>
- * The location is either a full path of a workspace resource or an
- * absolute path in the local file system.
- * </p>
- *
- * @return the location of this file buffer
- */
- IPath getLocation();
-
- /**
- * Returns whether this file buffer is synchronized with the file system. This is when
- * the file buffer's underlying file is in sync with the file system and the file buffer
- * has been initialized after the underlying files has been modified the last time.
- *
- * @return <code>true</code> if the file buffer is synchronized with the file system
- */
- boolean isSynchronized();
-
- /**
- * Reverts the contents of this file buffer to the content of its underlying file. After
- * that call successfully returned, <code>isDirty</code> returns <code>false</code> and
- * <code>isSynchronized</code> returns <code>true</code>.
- *
- * @param monitor the progress monitor
- * @throws CoreException if reading or accessing the underlying file fails
- */
- void revert(IProgressMonitor monitor) throws CoreException;
-
- /**
- * Commits this file buffer by changing the contents of th underlying file to
- * the contents of this file buffer. After that call, <code>isDirty</code>
- * returns <code>false</code> and <code>isSynchronized</code> returns
- * <code>true</code>.
- *
- * @param monitor the progress monitor
- * @param overwrite indicates whether the underlying file should be overwritten if it is not synchronized with the file system
- * @throws CoreException if writing or accessing the underlying file fails
- */
- void commit(IProgressMonitor monitor, boolean overwrite) throws CoreException;
-
- /**
- * Returns whether changes have been applied to this file buffer since initialization, or the most
- * recent <code>revert</code> or <code>commit</code> call.
- *
- * @return <code>true</code> if changes have been applied to this buffer
- */
- boolean isDirty();
-
- /**
- * Returns whether this file buffer is shared by more than one client.
- *
- * @return <code>true</code> if this file buffer is shared by more than one client
- */
- boolean isShared();
-
- /**
- * Validates the state of this file buffer and tries to bring the buffer's
- * underlying file into a state in which it can be modified. If state
- * validation is not supported this operation does nothing.
- *
- * @param monitor the progress monitor
- * @param computationContext the context in which the validation is
- * performed, e.g., a SWT shell
- * @exception CoreException if the underlying file can not be accessed to
- * it's state cannot be changed
- */
- void validateState(IProgressMonitor monitor, Object computationContext) throws CoreException;
-
- /**
- * Returns whether the state of this file buffer has been validated. If
- * state validation is not supported this method always returns <code>true</code>.
- *
- * @return <code>true</code> if the state has been validated, <code>false</code>
- * otherwise
- */
- boolean isStateValidated();
-
- /**
- * Resets state validation. If state validation is supported, <code>isStateValidated</code>
- * afterwars returns <code>false</code> unti the state is revalidated.
- */
- void resetStateValidation();
-
- /**
- * Returns the status of this file buffer. This is the result of the last operation peformed on this file buffer or
- * internally initiated by this file buffer.
- *
- * @return the status of this file buffer
- */
- IStatus getStatus();
-
- /**
- * Returns the modification stamp of the file underlying this file buffer.
- *
- * @return the modification stamp of the file underlying this file buffer
- */
- long getModifcationStamp();
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferListener.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferListener.java
deleted file mode 100644
index 06f8e244f33..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferListener.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-package org.eclipse.core.filebuffers;
-
-import org.eclipse.core.runtime.IPath;
-
-/**
- * Interface for listeners of file buffer changes.
- *
- * @since 3.0
- */
-public interface IFileBufferListener {
-
- /**
- * Informs the listener about the creation of the given buffer.
- *
- * @param buffer the created file buffer
- */
- void bufferCreated(IFileBuffer buffer);
-
- /**
- * Informs the listener about the disposal of the given buffer.
- *
- * @param buffer
- */
- void bufferDisposed(IFileBuffer buffer);
-
- /**
- * Informs the listener about an upcoming replace of the contents of the given buffer.
- *
- * @param buffer the effected file buffer
- */
- void bufferContentAboutToBeReplaced(IFileBuffer buffer);
-
- /**
- * Informs the listener that the buffer of the given buffer has been replaced.
- *
- * @param buffer the effected file buffer
- */
- void bufferContentReplaced(IFileBuffer buffer);
-
- /**
- * Informs the listener about the start of a state changing operation on
- * the given buffer.
- *
- * @param buffer the effected file buffer
- */
- void stateChanging(IFileBuffer buffer);
-
- /**
- * Informs the listener that the dirty state of the given buffer changed
- * to the specified value
- *
- * @param buffer the effected file buffer
- * @param isDirty <code>true</code> if the buffer is dirty, <code>false</code> otherwise
- */
- void dirtyStateChanged(IFileBuffer buffer, boolean isDirty);
-
- /**
- * Informs the listener that the state validation changed to the specified value.
- *
- * @param buffer the effected file buffer
- * @param isStateValidated <code>true</code> if the buffer state is validated, <code>false</code> otherwise
- */
- void stateValidationChanged(IFileBuffer buffer, boolean isStateValidated);
-
- /**
- * Informs the listener that the file underlying the given file buffer has been moved to the
- * given location.
- *
- * @param buffer the effected file buffer
- * @param target the new location (not just the container)
- */
- void underlyingFileMoved(IFileBuffer buffer, IPath path);
-
- /**
- * Informs the listener that the file underlying the given file buffer has been deleted.
- *
- * @param buffer the effected file buffer
- */
- void underlyingFileDeleted(IFileBuffer buffer);
-
- /**
- * Informs the listener that a state changing operation on the given
- * file buffer failed.
- *
- * @param buffer the effected file buffer
- */
- void stateChangeFailed(IFileBuffer buffer);
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferManager.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferManager.java
deleted file mode 100644
index f0e7cae7f1c..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferManager.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-
-package org.eclipse.core.filebuffers;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-/**
- * A file buffer manager manages file buffers for files while the files are
- * connected to the file buffer manager. In order to connect a file to a file
- * buffer manager call <code>connect</code>. After that call has
- * successfully completed the file buffer can be obtained by <code>getFileBuffer</code>.
- * The file buffer is created on the first connect and destroyed on the last
- * disconnect. I.e. the file buffer manager keeps track of how often a file is
- * connected and returns the same file buffer to each client as long as the
- * file is connected.
- *
- * @since 3.0
- */
-public interface IFileBufferManager {
-
- /**
- * Connects the file at the given location to this manager. After that call
- * successfully completed it is guaranteed that each call to <code>getFileBuffer</code>
- * returns the same file buffer until <code>disconnect</code> is called.
- * <p>
- * The provided location is either a full path of a workspace resource or
- * an absolute path in the local file system. The file buffer manager does
- * not resolve the location of workspace resources in the case of linked
- * resources.
- * </p>
- *
- * @param location the location of the file to be connected
- * @param monitor the progress monitor
- * @throws CoreException if the file could not successfully be connected
- */
- void connect(IPath location, IProgressMonitor monitor) throws CoreException;
-
- /**
- * Disconnects the file at the given location from this manager. After that
- * call successfully completed there is no guarantee that <code>getFileBuffer</code>
- * will return a valid file buffer.
- * <p>
- * The provided location is either a full path of a workspace resource or
- * an absolute path in the local file system. The file buffer manager does
- * not resolve the location of workspace resources in the case of linked
- * resources.
- * </p>
- *
- * @param location the location of the file to be disconnected
- * @param monitor the progress monitor
- * @throws CoreException if the file could not successfully be disconnected
- */
- void disconnect(IPath location, IProgressMonitor monitor) throws CoreException;
-
- /**
- * Returns the file buffer managed for the given location or <code>null</code>
- * if there is no such file buffer.
- * <p>
- * The provided location is either a full path of a workspace resource or
- * an absolute path in the local file system. The file buffer manager does
- * not resolve the location of workspace resources in the case of linked
- * resources.
- * </p>
- *
- * @param location the location
- * @return the file buffer managed for that location or <code>null</code>
- */
- IFileBuffer getFileBuffer(IPath location);
-
- /**
- * Sets the synchronization context for this file buffer manager, i.e., for
- * all file buffers this manager manages.
- *
- * @param context the synchronization context managed by this file buffer
- * manager
- */
- void setSynchronizationContext(ISynchronizationContext context);
-
- /**
- * Requests that the synchronization context is used to synchronize the
- * given location with its file buffer. This call as no effect if there is
- * no file buffer managed for the given location.
- * <p>
- * The provided location is either a full path of a workspace resource or
- * an absolute path in the local file system. The file buffer manager does
- * not resolve the location of workspace resources in the case of linked
- * resources.
- * </p>
- *
- * @param location the location
- */
- void requestSynchronizationContext(IPath location);
-
- /**
- * No longer requests the synchronization context for the filebuffer for
- * the given location. This method has no effect if there is no file buffer
- * managed for this location.
- * <p>
- * The provided location is either a full path of a workspace resource or
- * an absolute path in the local file system. The file buffer manager does
- * not resolve the location of workspace resources in the case of linked
- * resources.
- * </p>
- *
- * @param location the location
- */
- void releaseSynchronizationContext(IPath location);
-
- /**
- * Adds the given listener to the list of file buffer listeners. After that
- * call the listener is informated about changes related to this file
- * buffer. If the listener is already registered with the file buffer, this
- * call has no effect.
- *
- * @param listener the listener to be added
- */
- void addFileBufferListener(IFileBufferListener listener);
-
- /**
- * Removes the given listener from the list of file buffer listeners. If
- * the listener is not registered with this file buffer, this call has no
- * effect.
- *
- * @param listener the listener to be removed
- */
- void removeFileBufferListener(IFileBufferListener listener);
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ISynchronizationContext.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ISynchronizationContext.java
deleted file mode 100644
index 046e9a93da1..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ISynchronizationContext.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-package org.eclipse.core.filebuffers;
-
-/**
- * Executes runnables that describe how to synchronize a file buffer with its underlying file.
- *
- * @since 3.0
- */
-public interface ISynchronizationContext {
-
- /**
- * Executes the given runnable.
- *
- * @param runnable the runnable to be executed
- */
- void run(Runnable runnable);
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBuffer.java
deleted file mode 100644
index 60da3a8bb73..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBuffer.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-package org.eclipse.core.filebuffers;
-
-
-import org.eclipse.jface.text.IDocument;
-
-/**
- * A text file buffer is a file buffer for text files. The contents of a text file buffe is
- * given in the form of a document. Also, the text file buffer provides methods to
- * manage the character encoding used to read and write the buffer's underlying
- * text file.
- *
- * @since 3.0
- */
-public interface ITextFileBuffer extends IFileBuffer {
-
- /**
- * Returns the document of this text file buffer.
- *
- * @return the document of this text file buffer
- */
- IDocument getDocument();
-
- /**
- * Returns the character encoding to be used for reading and writing the
- * buffer's underlying file.
- *
- * @return the character encoding
- */
- String getEncoding();
-
- /**
- * Sets the character encoding to be used for reading and writing the buffer's
- * underlyning file.
- *
- * @param encoding the encoding
- */
- void setEncoding(String encoding);
-}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java
deleted file mode 100644
index 6897cdf56fa..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 implementation
-**********************************************************************/
-
-package org.eclipse.core.filebuffers;
-
-import org.eclipse.core.runtime.IPath;
-
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * A text file buffer manager manages text file buffers for files whose contents
- * could be considered text.
- *
- * @since 3.0
- */
-public interface ITextFileBufferManager extends IFileBufferManager {
-
- /**
- * Returns the text file buffer managed for the file at the given location
- * or <code>null</code> if either there is no such text file buffer.
- * <p>
- * The provided location is either a full path of a workspace resource or
- * an absolute path in the local file system. The file buffer manager does
- * not resolve the location of workspace resources in the case of linked
- * resources.
- * </p>
- *
- * @param location the location
- * @return the text file buffer managed for that location or <code>null</code>
- */
- ITextFileBuffer getTextFileBuffer(IPath location);
-
- /**
- * Returns the default encoding that is used to read the contents of text files
- * if no other encoding is specified.
- *
- * @return the default text file encoding
- */
- String getDefaultEncoding();
-
- /**
- * Creates a new empty document . The document is set up in the same way as
- * it would be used in a text file buffer for a file at the given location.
- * <p>
- * The provided location is either a full path of a workspace resource or
- * an absolute path in the local file system. The file buffer manager does
- * not resolve the location of workspace resources in the case of linked
- * resources.
- * </p>
- *
- * @param location the location used to set up the newly created document
- * @return a new empty document
- */
- IDocument createEmptyDocument(IPath location);
-}
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 6be8c2a9e34..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 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 9661c7c2a47..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 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.OperationCanceledException;
-import org.eclipse.core.runtime.Path;
-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("creating container", 1000 * fContainerFullPath.segmentCount());
- if (fContainer != null)
- return;
-
- // Does the container exist already?
- IWorkspaceRoot root= fWorkspace.getRoot();
- fContainer= (IContainer) root.findMember(fContainerFullPath);
- if (fContainer != null)
- return;
-
- // 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) {
- fContainer= (IContainer) resource;
- monitor.worked(1000);
- }
- 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));
- }
- }
- }
- }
- };
-
- fWorkspace.run(runnable, 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 0a4973ab22d..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DefaultDocumentFactory.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 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 f8fc178c3fd..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ExtensionsRegistry.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 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.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.filebuffers.IDocumentFactory;
-import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
-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;
-
-
-/**
- * This registry manages shareable document factories. Document factories are specified
- * in <code>plugin.xml</code> per file name extension.
- */
-public class ExtensionsRegistry {
-
- private final static String WILDCARD= "*"; //$NON-NLS-1$
-
- /** The mapping between name extensions 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 name extensions 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();
-
-
- /**
- * Creates a new document factory registry and intializes it with the information
- * found in the plugin registry.
- */
- public ExtensionsRegistry() {
- initialize("documentCreation", "extensions", fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentSetup", "extensions", fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Reads the comma-separated value of 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.
- */
- 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);
- }
- }
- }
-
- /**
- * Adds an entry to the log of this plugin for the given status
- * @param status the status to log
- */
- private void log(IStatus status) {
- ILog log= Platform.getPlugin(FileBuffersPlugin.PLUGIN_ID).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 descriptors the map to be filled
- */
- private void initialize(String extensionPointName, String childElementName, Map descriptors) {
-
- IExtensionPoint extensionPoint= Platform.getPluginRegistry().getExtensionPoint(FileBuffersPlugin.PLUGIN_ID, extensionPointName);
- if (extensionPoint == null) {
- log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, 0, MessageFormat.format("Extension point \"{0}\" not found.", new Object[] { extensionPointName}), null));
- return;
- }
-
- IConfigurationElement[] elements= extensionPoint.getConfigurationElements();
- for (int i= 0; i < elements.length; i++)
- 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
- */
- 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
- */
- private IConfigurationElement selectConfigurationElement(Set set) {
- if (set != null && !set.isEmpty()) {
- Iterator e= set.iterator();
- return (IConfigurationElement) e.next();
- }
- return null;
- }
-
- /**
- * Returns a shareable document factory for the given file name extension.
- *
- * @param extension the name extension to be used for lookup
- * @return the shareable document factory or <code>null</code>
- */
- private IDocumentFactory getDocumentFactory(String extension) {
-
- Set set= (Set) fFactoryDescriptors.get(extension);
- if (set != null) {
- IConfigurationElement entry= selectConfigurationElement(set);
- return (IDocumentFactory) getExtension(entry, fFactories, IDocumentFactory.class);
- }
- return null;
- }
-
- /**
- * Returns the set of setup participants for the given file name.
- *
- * @param extension the name extension to be used for lookup
- * @return the shareable set of document setup participants
- */
- private List getDocumentSetupParticipants(String extension) {
-
- Set set= (Set) fSetupParticipantDescriptors.get(extension);
- 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 shareable document factory for the given location.
- *
- * @param location the location for which to looked up the factory
- * @return the shareable document factory
- */
- public IDocumentFactory getDocumentFactory(IPath location) {
- IDocumentFactory factory= getDocumentFactory(location.getFileExtension());
- if (factory == null)
- factory= getDocumentFactory(WILDCARD);
- return factory;
- }
-
- /**
- * Returns the shareable set of document setup participants for the given location.
- *
- * @param location the location for which to look up the setup participants
- * @return the shareable set of document setup participants
- */
- public IDocumentSetupParticipant[] getDocumentSetupParticipants(IPath location) {
- List participants= new ArrayList();
-
- List 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;
- }
-}
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 752cffe2826..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersPlugin.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.eclipse.core.internal.filebuffers;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import org.eclipse.core.filebuffers.ITextFileBufferManager;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPluginDescriptor;
-import org.eclipse.core.runtime.Plugin;
-
-
-/**
- * The main plugin class to be used in the desktop.
- */
-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;
-
- /**
- * The constructor.
- */
- public FileBuffersPlugin(IPluginDescriptor descriptor) {
- super(descriptor);
- fgPlugin = this;
- try {
- fResourceBundle= ResourceBundle.getBundle("org.eclipse.core.internal.filebuffers.FileBuffersPlugin"); //$NON-NLS-1$
- } catch (MissingResourceException x) {
- fResourceBundle = null;
- }
- }
-
- /**
- * Returns the shared instance.
- */
- public static FileBuffersPlugin getDefault() {
- return fgPlugin;
- }
-
- /**
- * Returns the workspace instance.
- */
- public static IWorkspace getWorkspace() {
- return ResourcesPlugin.getWorkspace();
- }
-
- /**
- * Returns the string from the plugin's resource bundle,
- * or 'key' if not found.
- */
- 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,
- */
- public 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 e7b6c506d1e..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaFileBuffer.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 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.Platform;
-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, "File does not exist", null));
-
- 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= Platform.getPlugin(FileBuffersPlugin.PLUGIN_ID).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#getModifcationStamp()
- */
- public long getModifcationStamp() {
- 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 83034b0b1ee..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java
+++ /dev/null
@@ -1,337 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 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 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.Status;
-
-import org.eclipse.core.filebuffers.ITextFileBuffer;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-
-/**
- * @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.
- */
- static final private int READER_CHUNK_SIZE= 2048;
- /**
- * Buffer size.
- */
- static final private int BUFFER_SIZE= 8 * READER_CHUNK_SIZE;
- /**
- * 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, "OK", null);
- /**
- * 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, "Error", null);
-
-
-
- /** 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();
-
-
-
- public JavaTextFileBuffer(TextFileBufferManager manager) {
- super(manager);
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedTextFile#getDocument()
- */
- public IDocument getDocument() {
- return fDocument;
- }
-
- /*
- * @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());
- 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 {
- try {
-
- String encoding= getEncoding();
- if (encoding == null)
- encoding= fManager.getDefaultEncoding();
-
- InputStream stream= new ByteArrayInputStream(fDocument.get().getBytes(encoding));
-
- 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 (IOException x) {
- IStatus s= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, x.getMessage(), x);
- throw new CoreException(s);
- }
- }
-
- /**
- * 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();
-
- 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, "out of sync", null);
- 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 0024eff3860..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 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.Platform;
-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, "File does not exist", null));
-
- fLocation= location;
- fFile= file;
- fFileSynchronizer= new FileSynchronizer();
-
- refreshFile(monitor);
- initializeFileBufferContent(monitor);
- fSynchronizationStamp= fFile.getModificationStamp();
-
- addFileBufferContentListeners();
- }
-
- public void connect() {
- ++ fReferenceCount;
- if (fReferenceCount == 1)
- fFileSynchronizer.install();
- }
-
- public void disconnect() throws CoreException {
- -- fReferenceCount;
- if (fReferenceCount == 0) {
- 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);
- }
- 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= Platform.getPlugin(FileBuffersPlugin.PLUGIN_ID).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#getModifcationStamp()
- */
- public long getModifcationStamp() {
- 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 08a363c50fd..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 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 org.eclipse.core.filebuffers.ITextFileBuffer;
-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.QualifiedName;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-
-/**
- *
- */
-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, "OK", null);
- /**
- * 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, "Error", null);
-
-
-
- /** 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();
-
-
-
- public ResourceTextFileBuffer(TextFileBufferManager manager) {
- super(manager);
- }
-
- /*
- * @see org.eclipse.core.buffer.text.IBufferedTextFile#getDocument()
- */
- public IDocument getDocument() {
- return fDocument;
- }
-
- /*
- * @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;
- try {
- fFile.setPersistentProperty(ENCODING_KEY, encoding);
- } 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);
-
- 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= fFile.getPersistentProperty(ENCODING_KEY);
- fDocument= fManager.createEmptyDocument(fFile.getLocation());
- setDocumentContent(fDocument, fFile.getContents(), fEncoding);
- } catch (CoreException x) {
- fDocument= fManager.createEmptyDocument(fFile.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 {
- try {
-
- String encoding= getEncoding();
- if (encoding == null)
- encoding= fManager.getDefaultEncoding();
-
- InputStream stream= new ByteArrayInputStream(fDocument.get().getBytes(encoding));
-
- 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();
-
- // 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 (IOException x) {
- IStatus s= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, x.getMessage(), x);
- throw new CoreException(s);
- }
- }
-
- /**
- * 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);
-
- } 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();
-
- 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 (!fFile.isSynchronized(IFile.DEPTH_ZERO)) {
- Status status= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IResourceStatus.OUT_OF_SYNC_LOCAL, "out of sync", null);
- 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 e2685562031..00000000000
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/**********************************************************************
-Copyright (c) 2000, 2003 IBM Corp. 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 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.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;
-
-/**
- * @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, "Cannot create file buffer.", null));
-
- 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.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