Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-04-01 17:42:11 +0000
committerKai Maetzel2004-04-01 17:42:11 +0000
commit9b4796ef6116203821688c90c36a865997b6e34f (patch)
treea61f4cc304775f657e7e17ad36a66c5b7e96fd13 /org.eclipse.text/projection/org
parentb3162b9dc2bb8ea61fd588ca943608ff7c748833 (diff)
downloadeclipse.platform.text-9b4796ef6116203821688c90c36a865997b6e34f.tar.gz
eclipse.platform.text-9b4796ef6116203821688c90c36a865997b6e34f.tar.xz
eclipse.platform.text-9b4796ef6116203821688c90c36a865997b6e34f.zip
fixed problem interfering slaves
Diffstat (limited to 'org.eclipse.text/projection/org')
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java7
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java11
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java57
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java50
4 files changed, 58 insertions, 67 deletions
diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java
index b726b8b5dec..c25d65ffc0c 100644
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java
+++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocument.java
@@ -49,12 +49,9 @@ public class ChildDocument extends ProjectionDocument {
* Creates a new child document.
*
* @param masterDocument @inheritDoc
- * @param fragmentsCategory @inheritDoc
- * @param fragmentUpdater @inheritDoc
- * @param segmentsCategory @inheritDoc
*/
- public ChildDocument(IDocument masterDocument, String fragmentsCategory, FragmentUpdater fragmentUpdater, String segmentsCategory) {
- super(masterDocument, fragmentsCategory, fragmentUpdater, segmentsCategory);
+ public ChildDocument(IDocument masterDocument) {
+ super(masterDocument);
}
/**
diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java
index e8a91f2e8b5..cebc9f6964a 100644
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java
+++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ChildDocumentManager.java
@@ -23,15 +23,10 @@ import org.eclipse.jface.text.IDocument;
*/
public class ChildDocumentManager extends ProjectionDocumentManager {
- /**
- * The position category used to manage the child documents.
- */
- public final static String CHILDDOCUMENTS= FRAGMENTS_CATEGORY;
-
/*
- * @see org.eclipse.jface.text.projection.ProjectionDocumentManager#createProjectionDocument(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.projection.FragmentUpdater)
+ * @see org.eclipse.jface.text.projection.ProjectionDocumentManager#createProjectionDocument(org.eclipse.jface.text.IDocument)
*/
- protected ProjectionDocument createProjectionDocument(IDocument master, FragmentUpdater fragmentUpdater) {
- return new ChildDocument(master, FRAGMENTS_CATEGORY, fragmentUpdater, SEGMENTS_CATEGORY);
+ protected ProjectionDocument createProjectionDocument(IDocument master) {
+ return new ChildDocument(master);
}
}
diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java
index 88aec1f148b..20906e90627 100644
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java
+++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java
@@ -45,14 +45,30 @@ import org.eclipse.jface.text.Region;
*/
public class ProjectionDocument extends AbstractDocument {
+
+ /**
+ * Prefix of the name of the position category used to keep track of the master
+ * document's fragments that correspond to the segments of the projection
+ * document.
+ */
+ private final static String FRAGMENTS_CATEGORY_PREFIX= "__fragmentsCategory"; //$NON-NLS-1$
+
+ /**
+ * Name of the position category used to keep track of the project
+ * document's segments that correspond to the fragments of the master
+ * document.
+ */
+ private final static String SEGMENTS_CATEGORY= "__segmentsCategory"; //$NON-NLS-1$
+
+
/** The master document */
- protected IDocument fMasterDocument;
+ private IDocument fMasterDocument;
/** The master document as document extension */
- protected IDocumentExtension fMasterDocumentExtension;
+ private IDocumentExtension fMasterDocumentExtension;
/** The fragments' position category */
- protected String fFragmentsCategory;
+ private String fFragmentsCategory;
/** The segment's position category */
- protected String fSegmentsCategory;
+ private String fSegmentsCategory;
/** The document event issued by the master document */
private DocumentEvent fMasterEvent;
/** The document event to be issued by the projection document */
@@ -74,21 +90,21 @@ public class ProjectionDocument extends AbstractDocument {
* Creates a projection document for the given master document.
*
* @param masterDocument the master document
- * @param fragmentsCategory the document position category managing the master's fragments
- * @param fragmentUpdater the fragment position updater of the master document
- * @param segmentsCategory the document position category managing the segments
*/
- public ProjectionDocument(IDocument masterDocument, String fragmentsCategory, FragmentUpdater fragmentUpdater, String segmentsCategory) {
+ public ProjectionDocument(IDocument masterDocument) {
super();
fMasterDocument= masterDocument;
if (fMasterDocument instanceof IDocumentExtension)
fMasterDocumentExtension= (IDocumentExtension) fMasterDocument;
- fFragmentsCategory= fragmentsCategory;
- fFragmentsUpdater= fragmentUpdater;
- fSegmentsCategory= segmentsCategory;
- fMapping= new ProjectionMapping(masterDocument, fragmentsCategory, this, segmentsCategory);
+ fSegmentsCategory= SEGMENTS_CATEGORY;
+ fFragmentsCategory= FRAGMENTS_CATEGORY_PREFIX + hashCode();
+ fMasterDocument.addPositionCategory(fFragmentsCategory);
+ fFragmentsUpdater= new FragmentUpdater(fFragmentsCategory);
+ fMasterDocument.addPositionUpdater(fFragmentsUpdater);
+
+ fMapping= new ProjectionMapping(masterDocument, fFragmentsCategory, this, fSegmentsCategory);
ITextStore s= new ProjectionTextStore(masterDocument, fMapping);
ILineTracker tracker= new DefaultLineTracker();
@@ -101,6 +117,18 @@ public class ProjectionDocument extends AbstractDocument {
initializeProjection();
tracker.set(s.get(0, s.getLength()));
}
+
+ /**
+ * Disposes this projection document.
+ */
+ public void dispose() {
+ fMasterDocument.removePositionUpdater(fFragmentsUpdater);
+ try {
+ fMasterDocument.removePositionCategory(fFragmentsCategory);
+ } catch (BadPositionCategoryException x) {
+ // allow multiple dispose calls
+ }
+ }
private void internalError() {
throw new IllegalStateException();
@@ -430,6 +458,11 @@ public class ProjectionDocument extends AbstractDocument {
}
}
+ /**
+ * Returns whether this project is being updated.
+ *
+ * @return <code>true</code> if the document is updating
+ */
protected boolean isUpdating() {
return fIsUpdating;
}
diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java
index ff794113c5a..9e6bbc8e086 100644
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java
+++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocumentManager.java
@@ -17,7 +17,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.eclipse.jface.text.BadPositionCategoryException;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentInformationMapping;
@@ -43,29 +42,10 @@ import org.eclipse.jface.text.ISlaveDocumentManagerExtension;
*
* @since 3.0
*/
-public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocumentManager, ISlaveDocumentManagerExtension {
-
-
- /**
- * Name of the position category used to keep track of the master
- * document's fragments that correspond to the segments of the projection
- * documents.
- */
- protected final static String FRAGMENTS_CATEGORY= "__fragmentsCategory"; //$NON-NLS-1$
-
- /**
- * Name of the position category used to keep track of the project
- * document's segments that correspond to the fragments of the master
- * documents.
- */
- protected final static String SEGMENTS_CATEGORY= "__segmentsCategory"; //$NON-NLS-1$
-
+public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocumentManager, ISlaveDocumentManagerExtension {
/** Registry for master documents and their projection documents. */
private Map fProjectionRegistry= new HashMap();
- /** Registry for master documents and their fragment updaters. */
- private Map fUpdaterRegistry= new HashMap();
-
/**
* Registers the given projection document for the given master document.
@@ -171,15 +151,9 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum
* @see org.eclipse.jface.text.ISlaveDocumentManager#createSlaveDocument(org.eclipse.jface.text.IDocument)
*/
public IDocument createSlaveDocument(IDocument master) {
- if (!master.containsPositionCategory(FRAGMENTS_CATEGORY)) {
- FragmentUpdater updater= new FragmentUpdater(FRAGMENTS_CATEGORY);
- fUpdaterRegistry.put(master, updater);
- master.addPositionCategory(FRAGMENTS_CATEGORY);
- master.addPositionUpdater(updater);
+ if (!hasProjection(master))
master.addDocumentListener(this);
- }
- FragmentUpdater updater= (FragmentUpdater) fUpdaterRegistry.get(master);
- ProjectionDocument slave= createProjectionDocument(master, updater);
+ ProjectionDocument slave= createProjectionDocument(master);
add(master, slave);
return slave;
}
@@ -188,11 +162,10 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum
* Factory method for projection documents.
*
* @param master the master document
- * @param fragmentUpdater the fragment updater of the master document
* @return the newly created projection document
*/
- protected ProjectionDocument createProjectionDocument(IDocument master, FragmentUpdater fragmentUpdater) {
- return new ProjectionDocument(master, FRAGMENTS_CATEGORY, fragmentUpdater, SEGMENTS_CATEGORY);
+ protected ProjectionDocument createProjectionDocument(IDocument master) {
+ return new ProjectionDocument(master);
}
/*
@@ -203,16 +176,9 @@ public class ProjectionDocumentManager implements IDocumentListener, ISlaveDocum
ProjectionDocument projectionDocument= (ProjectionDocument) slave;
IDocument master= projectionDocument.getMasterDocument();
remove(master, projectionDocument);
-
- try {
- if (!hasProjection(master)) {
- FragmentUpdater updater= (FragmentUpdater) fUpdaterRegistry.remove(master);
- master.removeDocumentListener(this);
- master.removePositionUpdater(updater);
- master.removePositionCategory(FRAGMENTS_CATEGORY);
- }
- } catch (BadPositionCategoryException x) {
- }
+ projectionDocument.dispose();
+ if (!hasProjection(master))
+ master.removeDocumentListener(this);
}
}

Back to the top