Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-04-29 16:36:01 +0000
committerKai Maetzel2004-04-29 16:36:01 +0000
commit53c5e287ed07c2abe65072cd9a719f8c264a4389 (patch)
treed531dcd47043e9eb0b4ba130d24a1df9db5f8fc0 /org.eclipse.core.filebuffers
parentfb68c2b9f8eb62993cc08bf4186e8df246b42f20 (diff)
downloadeclipse.platform.text-53c5e287ed07c2abe65072cd9a719f8c264a4389.tar.gz
eclipse.platform.text-53c5e287ed07c2abe65072cd9a719f8c264a4389.tar.xz
eclipse.platform.text-53c5e287ed07c2abe65072cd9a719f8c264a4389.zip
headless annotation model support
Diffstat (limited to 'org.eclipse.core.filebuffers')
-rw-r--r--org.eclipse.core.filebuffers/plugin.properties1
-rw-r--r--org.eclipse.core.filebuffers/plugin.xml4
-rw-r--r--org.eclipse.core.filebuffers/schema/annotationModelCreation.exsd123
-rw-r--r--org.eclipse.core.filebuffers/schema/documentCreation.exsd2
-rw-r--r--org.eclipse.core.filebuffers/schema/documentSetup.exsd2
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IAnnotationModelFactory.java33
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IPersistableAnnotationModel.java42
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBuffer.java8
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java9
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ExtensionsRegistry.java112
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java8
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java31
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java55
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java14
14 files changed, 401 insertions, 43 deletions
diff --git a/org.eclipse.core.filebuffers/plugin.properties b/org.eclipse.core.filebuffers/plugin.properties
index 23d210cea..053aa022c 100644
--- a/org.eclipse.core.filebuffers/plugin.properties
+++ b/org.eclipse.core.filebuffers/plugin.properties
@@ -12,4 +12,5 @@ pluginName= File Buffers
providerName= Eclipse.org
documentCreationPoint= Document Creation
documentSetupPoint= Document Setup
+annotationModelCreationPoint= Annotation Model Creation
defaultDocumentFactory= Default Document Factory
diff --git a/org.eclipse.core.filebuffers/plugin.xml b/org.eclipse.core.filebuffers/plugin.xml
index 5d5802fd4..e1f786cbc 100644
--- a/org.eclipse.core.filebuffers/plugin.xml
+++ b/org.eclipse.core.filebuffers/plugin.xml
@@ -14,7 +14,7 @@
</library>
</runtime>
<requires>
- <import plugin="org.eclipse.core.runtime"/>
+ <import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.text"/>
</requires>
@@ -22,6 +22,7 @@
<extension-point id="documentCreation" name="%documentCreationPoint" schema="schema/documentCreation.exsd"/>
<extension-point id="documentSetup" name="%documentSetupPoint" schema="schema/documentSetup.exsd"/>
+ <extension-point id="annotationModelCreation" name="%annotationModelCreationPoint" schema="schema/annotationModelCreation.exsd"/>
<extension
id="DefaultDocumentFactory"
@@ -32,4 +33,5 @@
class="org.eclipse.core.internal.filebuffers.DefaultDocumentFactory">
</factory>
</extension>
+
</plugin>
diff --git a/org.eclipse.core.filebuffers/schema/annotationModelCreation.exsd b/org.eclipse.core.filebuffers/schema/annotationModelCreation.exsd
new file mode 100644
index 000000000..47e2ef989
--- /dev/null
+++ b/org.eclipse.core.filebuffers/schema/annotationModelCreation.exsd
@@ -0,0 +1,123 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.core.filebuffers">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.core.filebuffers" id="annotationModelCreation" name="Annotation Model Creation"/>
+ </appInfo>
+ <documentation>
+ This extension point is interesting for your if you want the file buffer manager to instantiate a specific annotation models for certain file content types, file extensions, or file names.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="factory"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="factory">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.core.filebuffers.IAnnotationModelFactory"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="extensions" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="fileNames" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="contentTypeId" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.core.filebuffers/schema/documentCreation.exsd b/org.eclipse.core.filebuffers/schema/documentCreation.exsd
index 0c7970123..3313b8a89 100644
--- a/org.eclipse.core.filebuffers/schema/documentCreation.exsd
+++ b/org.eclipse.core.filebuffers/schema/documentCreation.exsd
@@ -6,7 +6,7 @@
<meta.schema plugin="org.eclipse.core.filebuffers" id="documentCreation" name="Document Creation"/>
</appInfo>
<documentation>
- This extension point is interesting for your if you want the file buffer manager to instantiate a specific document implementation for certain file extensions or file names.
+ This extension point is interesting for your if you want the file buffer manager to instantiate a specific document implementation for certain file content types, file extensions, or file names.
</documentation>
</annotation>
diff --git a/org.eclipse.core.filebuffers/schema/documentSetup.exsd b/org.eclipse.core.filebuffers/schema/documentSetup.exsd
index d53189cca..0c84681af 100644
--- a/org.eclipse.core.filebuffers/schema/documentSetup.exsd
+++ b/org.eclipse.core.filebuffers/schema/documentSetup.exsd
@@ -6,7 +6,7 @@
<meta.schema plugin="org.eclipse.core.filebuffers" id="documentSetup" name="Document Setup"/>
</appInfo>
<documentation>
- This extension point is interesting if you want to install specific partitioners etc. on documents created by the file buffer manager for certain file extensions or file names.
+ This extension point is interesting if you want to install specific partitioners etc. on documents created by the file buffer manager for certain file content types, file extensions, or file names.
</documentation>
</annotation>
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IAnnotationModelFactory.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IAnnotationModelFactory.java
new file mode 100644
index 000000000..22866c1c9
--- /dev/null
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IAnnotationModelFactory.java
@@ -0,0 +1,33 @@
+/**********************************************************************
+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.source.IAnnotationModel;
+
+
+/**
+ * Factory for text file buffer annotation models. Used by the text file buffer
+ * manager to create the annotation model for a new text file buffer.
+ *
+ * @since 3.0
+ */
+public interface IAnnotationModelFactory {
+
+ /**
+ * Creates and returns a new annotation model.
+ *
+ * @return a new annotation model
+ */
+ IAnnotationModel createAnnotationModel(IPath location);
+}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IPersistableAnnotationModel.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IPersistableAnnotationModel.java
new file mode 100644
index 000000000..11a4a9a5e
--- /dev/null
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IPersistableAnnotationModel.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.filebuffers;
+
+
+import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.jface.text.IDocument;
+
+
+
+/**
+ * Interface implemented by <code>IAnnotationModel</code> implementers that offer
+ * persistable state.
+ *
+ * @since 3.0
+ */
+public interface IPersistableAnnotationModel {
+
+ /**
+ * @param document
+ */
+ void commit(IDocument document) throws CoreException;
+
+ /**
+ * @param document
+ */
+ void revert(IDocument document) throws CoreException;
+
+ /**
+ * @param document
+ */
+ void reinitialize(IDocument document) throws CoreException;
+}
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
index d5676f677..2bdd4b5bc 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBuffer.java
@@ -12,6 +12,7 @@ package org.eclipse.core.filebuffers;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.IAnnotationModel;
/**
* A text file buffer is a file buffer for text files. The contents of a text file buffe is
@@ -45,4 +46,11 @@ public interface ITextFileBuffer extends IFileBuffer {
* @param encoding the encoding
*/
void setEncoding(String encoding);
+
+ /**
+ * Returns the annotation model of this text file buffer.
+ *
+ * @return the annotation model of this text file buffer
+ */
+ IAnnotationModel getAnnotationModel();
}
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
index 6897cdf56..74dd895c9 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java
@@ -14,6 +14,7 @@ package org.eclipse.core.filebuffers;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.IAnnotationModel;
/**
@@ -61,4 +62,12 @@ public interface ITextFileBufferManager extends IFileBufferManager {
* @return a new empty document
*/
IDocument createEmptyDocument(IPath location);
+
+ /**
+ * Creates a new annotation for the given location.
+ *
+ * @param location the location
+ * @return the newly created annotation model
+ */
+ IAnnotationModel createAnnotationModel(IPath location);
}
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
index 83999e4d6..ca0c77e13 100644
--- 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
@@ -22,7 +22,6 @@ import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
@@ -35,6 +34,8 @@ import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.IAnnotationModelFactory;
import org.eclipse.core.filebuffers.IDocumentFactory;
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
@@ -102,15 +103,19 @@ public class ExtensionsRegistry {
private final static String WILDCARD= "*"; //$NON-NLS-1$
- /** The mapping between name extensions and configuration elements describing document factories. */
+ /** The mapping between file attributes and configuration elements describing document factories. */
private Map fFactoryDescriptors= new HashMap();
/** The mapping between configuration elements for document factories and instantiated document factories. */
private Map fFactories= new HashMap();
- /** The mapping between name extensions and configuration elements describing document setup participants. */
+ /** The mapping between file attributes and configuration elements describing document setup participants. */
private Map fSetupParticipantDescriptors= new HashMap();
/** The mapping between configuration elements for setup participants and instantiated setup participants. */
private Map fSetupParticipants= new HashMap();
-
+ /** The mapping between file attributes and configuration elements describing annotation model factories. */
+ private Map fAnnotationModelFactoryDescriptors= new HashMap();
+ /** The mapping between configuration elements for annotation model factories */
+ private Map fAnnotationModelFactories= new HashMap();
+ /** The content type manager. */
private IContentTypeManager fContentTypeManager= Platform.getContentTypeManager();
@@ -120,11 +125,15 @@ public class ExtensionsRegistry {
*/
public ExtensionsRegistry() {
initialize("documentCreation", "contentTypeId", true, fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentCreation", "fileNames", fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentCreation", "extensions", fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentSetup", "contentTypeId", fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentSetup", "fileNames", fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
- initialize("documentSetup", "extensions", fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+ initialize("documentCreation", "fileNames", false, fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+ initialize("documentCreation", "extensions", false, fFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+ initialize("documentSetup", "contentTypeId", true, fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+ initialize("documentSetup", "fileNames", false, fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+ initialize("documentSetup", "extensions", false, fSetupParticipantDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+ initialize("annotationModelCreation", "contentTypeId", true, fAnnotationModelFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+ initialize("annotationModelCreation", "fileNames", false, fAnnotationModelFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+ initialize("annotationModelCreation", "extensions", false, fAnnotationModelFactoryDescriptors); //$NON-NLS-1$ //$NON-NLS-2$
+
}
/**
@@ -186,19 +195,6 @@ public class ExtensionsRegistry {
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) {
- initialize(extensionPointName, childElementName, false, descriptors);
- }
/**
* Initializes this registry. It retrieves all implementers of the given
@@ -271,13 +267,13 @@ public class ExtensionsRegistry {
}
/**
- * Returns a sharable document factory for the given file name extension.
+ * Returns a sharable document factory for the given file name or file extension.
*
- * @param extension the name extension to be used for lookup
+ * @param nameOrExtension the name or extension to be used for lookup
* @return the sharable document factory or <code>null</code>
*/
- private IDocumentFactory getDocumentFactory(String extension) {
- Set set= (Set) fFactoryDescriptors.get(extension);
+ private IDocumentFactory getDocumentFactory(String nameOrExtension) {
+ Set set= (Set) fFactoryDescriptors.get(nameOrExtension);
if (set != null) {
IConfigurationElement entry= selectConfigurationElement(set);
return (IDocumentFactory) getExtension(entry, fFactories, IDocumentFactory.class);
@@ -306,13 +302,13 @@ public class ExtensionsRegistry {
}
/**
- * Returns the set of setup participants for the given file name.
+ * Returns the set of setup participants for the given file name or extension.
*
- * @param extension the name extension to be used for lookup
+ * @param nameOrExtension the name or extension to be used for lookup
* @return the sharable set of document setup participants
*/
- private List getDocumentSetupParticipants(String extension) {
- Set set= (Set) fSetupParticipantDescriptors.get(extension);
+ private List getDocumentSetupParticipants(String nameOrExtension) {
+ Set set= (Set) fSetupParticipantDescriptors.get(nameOrExtension);
if (set == null)
return null;
@@ -355,8 +351,45 @@ public class ExtensionsRegistry {
return participants;
}
+ /**
+ * Returns a sharable annotation model factory for the given content types.
+ *
+ * @param contentTypes the content types used to find the factory
+ * @return the sharable annotation model factory or <code>null</code>
+ */
+ private IAnnotationModelFactory getAnnotationModelFactory(IContentType[] contentTypes) {
+ Set set= null;
+ int i= 0;
+ while (i < contentTypes.length && set == null) {
+ set= (Set) fAnnotationModelFactoryDescriptors.get(new ContentTypeAdapter(contentTypes[i++]));
+ }
+
+ if (set != null) {
+ IConfigurationElement entry= selectConfigurationElement(set);
+ return (IAnnotationModelFactory) getExtension(entry, fAnnotationModelFactories, IAnnotationModelFactory.class);
+ }
+ return null;
+ }
+
+ /**
+ * Returns a sharable annotation model factory for the given file name or file extension.
+ *
+ * @param extension the name or extension to be used for lookup
+ * @return the sharable document factory or <code>null</code>
+ */
+ private IAnnotationModelFactory getAnnotationModelFactory(String extension) {
+ Set set= (Set) fAnnotationModelFactoryDescriptors.get(extension);
+ if (set != null) {
+ IConfigurationElement entry= selectConfigurationElement(set);
+ return (IAnnotationModelFactory) getExtension(entry, fAnnotationModelFactories, IAnnotationModelFactory.class);
+ }
+ return null;
+ }
+
private IContentType[] findContentTypes(IPath path) {
- IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ IFile file= FileBuffers.getWorkspaceFileAtLocation(path);
+ if (file == null)
+ return new IContentType[0];
IContentDescription contentDescription;
try {
@@ -420,4 +453,21 @@ public class ExtensionsRegistry {
participants.toArray(result);
return result;
}
+
+ /**
+ * Returns the sharable annotation model factory for the given location.
+ *
+ * @param location the location for which to look up the factory
+ * @return the sharable annotation model factory
+ */
+ public IAnnotationModelFactory getAnnotationModelFactory(IPath location) {
+ IAnnotationModelFactory factory= getAnnotationModelFactory(findContentTypes(location));
+ if (factory == null)
+ factory= getAnnotationModelFactory(location.lastSegment());
+ if (factory == null)
+ factory= getAnnotationModelFactory(location.getFileExtension());
+ if (factory == null)
+ factory= getAnnotationModelFactory(WILDCARD);
+ return factory;
+ }
}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java
index d4b05920b..5adcde2bd 100644
--- 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
@@ -32,6 +32,7 @@ import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.source.IAnnotationModel;
/**
* @since 3.0
@@ -95,6 +96,13 @@ public class JavaTextFileBuffer extends JavaFileBuffer implements ITextFileBuffe
public IDocument getDocument() {
return fDocument;
}
+
+ /*
+ * @see org.eclipse.core.filebuffers.ITextFileBuffer#getAnnotationModel()
+ */
+ public IAnnotationModel getAnnotationModel() {
+ return null;
+ }
/*
* @see org.eclipse.core.buffer.text.IBufferedTextFile#getEncoding()
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
index d28d10ba0..347643fc0 100644
--- 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
@@ -235,19 +235,38 @@ public abstract class ResourceFileBuffer extends AbstractFileBuffer {
public void connect() {
++ fReferenceCount;
if (fReferenceCount == 1)
- fFileSynchronizer.install();
+ connected();
}
+ /**
+ * Called when this file buffer has been connected. This is the case when
+ * there is exactly one connection.
+ * <p>
+ * Clients may extend this method.
+ */
+ protected void connected() {
+ fFileSynchronizer.install();
+ }
+
public void disconnect() throws CoreException {
-- fReferenceCount;
- if (fReferenceCount == 0) {
- if (fFileSynchronizer != null)
- fFileSynchronizer.uninstall();
- fFileSynchronizer= null;
- }
+ if (fReferenceCount == 0)
+ disconnected();
}
/**
+ * Called when this file buffer has been disconnected. This is the case when
+ * the number of connections drops to <code>0</code>.
+ * <p>
+ * Clients may extend this method.
+ */
+ protected void disconnected() {
+ if (fFileSynchronizer != null)
+ fFileSynchronizer.uninstall();
+ fFileSynchronizer= null;
+ }
+
+ /**
* Returns whether this file buffer has already been disposed.
*
* @return <code>true</code> if already disposed, <code>false</code> otherwise
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
index 9a3535835..36f3c0c68 100644
--- 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
@@ -17,6 +17,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import org.eclipse.core.filebuffers.IPersistableAnnotationModel;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResourceStatus;
@@ -30,6 +31,7 @@ import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.source.IAnnotationModel;
/**
*
@@ -84,7 +86,8 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
protected String fEncoding;
/** Internal document listener */
protected IDocumentListener fDocumentListener= new DocumentListener();
-
+ /** The element's annotation model */
+ protected IAnnotationModel fAnnotationModel;
public ResourceTextFileBuffer(TextFileBufferManager manager) {
@@ -97,6 +100,13 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
public IDocument getDocument() {
return fDocument;
}
+
+ /*
+ * @see org.eclipse.core.filebuffers.ITextFileBuffer#getAnnotationModel()
+ */
+ public IAnnotationModel getAnnotationModel() {
+ return fAnnotationModel;
+ }
/*
* @see org.eclipse.core.buffer.text.IBufferedTextFile#getEncoding()
@@ -167,7 +177,12 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
if (replaceContents)
fManager.fireBufferContentReplaced(this);
-
+
+ if (fAnnotationModel instanceof IPersistableAnnotationModel) {
+ IPersistableAnnotationModel persistableModel= (IPersistableAnnotationModel) fAnnotationModel;
+ persistableModel.revert(fDocument);
+ }
+
fManager.fireDirtyStateChanged(this, fCanBeSaved);
}
}
@@ -212,8 +227,12 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
} else {
fEncoding= fFile.getCharset();
}
+
fDocument= fManager.createEmptyDocument(fFile.getLocation());
setDocumentContent(fDocument, fFile.getContents(), fEncoding);
+
+ fAnnotationModel= fManager.createAnnotationModel(fFile.getLocation());
+
} catch (CoreException x) {
fDocument= fManager.createEmptyDocument(fFile.getLocation());
fStatus= x.getStatus();
@@ -221,6 +240,24 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
}
/*
+ * @see org.eclipse.core.internal.filebuffers.ResourceFileBuffer#connected()
+ */
+ protected void connected() {
+ super.connected();
+ if (fAnnotationModel != null)
+ fAnnotationModel.connect(fDocument);
+ }
+
+ /*
+ * @see org.eclipse.core.internal.filebuffers.ResourceFileBuffer#disconnected()
+ */
+ protected void disconnected() {
+ if (fAnnotationModel != null)
+ fAnnotationModel.disconnect(fDocument);
+ super.disconnected();
+ }
+
+ /*
* @see org.eclipse.core.internal.filebuffers.FileBuffer#commitFileBufferContent(org.eclipse.core.runtime.IProgressMonitor, boolean)
*/
protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException {
@@ -244,7 +281,10 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
// 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
+ if (fAnnotationModel instanceof IPersistableAnnotationModel) {
+ IPersistableAnnotationModel persistableModel= (IPersistableAnnotationModel) fAnnotationModel;
+ persistableModel.commit(fDocument);
+ }
} else {
@@ -297,6 +337,15 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
fManager.fireBufferContentReplaced(this);
+ if (fAnnotationModel instanceof IPersistableAnnotationModel) {
+ IPersistableAnnotationModel persistableModel= (IPersistableAnnotationModel) fAnnotationModel;
+ try {
+ persistableModel.reinitialize(fDocument);
+ } catch (CoreException x) {
+ fStatus= status;
+ }
+ }
+
} else {
removeFileBufferContentListeners();
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
index e26855620..3e967111d 100644
--- 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
@@ -24,6 +24,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.IAnnotationModelFactory;
import org.eclipse.core.filebuffers.IDocumentFactory;
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
import org.eclipse.core.filebuffers.IFileBuffer;
@@ -35,6 +36,7 @@ import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.IAnnotationModel;
/**
* @since 3.0
@@ -158,6 +160,18 @@ public class TextFileBufferManager implements ITextFileBufferManager {
}
/*
+ * @see org.eclipse.core.filebuffers.ITextFileBufferManager#createAnnotationModel(org.eclipse.core.runtime.IPath)
+ */
+ public IAnnotationModel createAnnotationModel(IPath location) {
+ Assert.isNotNull(location);
+ location= FileBuffers.normalizeLocation(location);
+ IAnnotationModelFactory factory= fRegistry.getAnnotationModelFactory(location);
+ if (factory != null)
+ return factory.createAnnotationModel(location);
+ return null;
+ }
+
+ /*
* @see org.eclipse.core.filebuffers.IFileBufferManager#addFileBufferListener(org.eclipse.core.filebuffers.IFileBufferListener)
*/
public void addFileBufferListener(IFileBufferListener listener) {

Back to the top