Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java')
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java102
1 files changed, 100 insertions, 2 deletions
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java
index aac5b27369a..72c9779eb22 100644
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java
+++ b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java
@@ -11,7 +11,11 @@
package org.eclipse.jface.text.source.projection;
import java.util.Iterator;
+import java.util.Map;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
@@ -25,6 +29,61 @@ import org.eclipse.jface.text.source.AnnotationModel;
* @since 3.0
*/
public class ProjectionAnnotationModel extends AnnotationModel {
+
+
+ private class Summarizer extends Thread {
+
+ public Summarizer() {
+ setDaemon(true);
+ start();
+ synchronized (fLock) {
+ fHasStarted= false;
+ }
+ }
+
+ /*
+ * @see java.lang.Thread#run()
+ */
+ public void run() {
+
+ synchronized (fLock) {
+ fHasStarted= true;
+ }
+
+ fProjectionSummary.updateSummaries(new NullProgressMonitor());
+
+ synchronized (fLock) {
+ if (fSummarizer == this)
+ fSummarizer= null;
+ }
+ }
+ }
+
+
+ private ProjectionSummary fProjectionSummary;
+
+ private Object fLock= new Object();
+ private volatile Summarizer fSummarizer;
+ private volatile boolean fHasStarted= false;
+
+
+ public ProjectionAnnotationModel(ProjectionSummary summary) {
+ fProjectionSummary= summary;
+ }
+
+ public void setProjectionSummary(ProjectionSummary summary) {
+ fProjectionSummary= summary;
+ }
+
+ private void updateSummaries() {
+ if (fProjectionSummary == null)
+ return;
+
+ synchronized (fLock) {
+ if (fSummarizer == null || fHasStarted)
+ fSummarizer= new Summarizer();
+ }
+ }
/**
* Changes the state of the given annotation to collapsed. An appropriate
@@ -38,6 +97,7 @@ public class ProjectionAnnotationModel extends AnnotationModel {
if (!projection.isCollapsed()) {
projection.markCollapsed();
modifyAnnotation(projection, true);
+ updateSummaries();
}
}
}
@@ -54,6 +114,7 @@ public class ProjectionAnnotationModel extends AnnotationModel {
if (projection.isCollapsed()) {
projection.markExpanded();
modifyAnnotation(projection, true);
+ updateSummaries();
}
}
}
@@ -74,6 +135,7 @@ public class ProjectionAnnotationModel extends AnnotationModel {
projection.markCollapsed();
modifyAnnotation(projection, true);
+ updateSummaries();
}
}
@@ -85,6 +147,20 @@ public class ProjectionAnnotationModel extends AnnotationModel {
* @return <code>true</code> if any annotation has been expanded, <code>false</code> otherwise
*/
public boolean expandAll(int offset, int length) {
+ return expandAll(offset, length, true);
+ }
+
+ /**
+ * Expands all annotations that overlap with the given range and are collapsed. Fires a model change event if
+ * requested.
+ *
+ * @param offset the offset of the range
+ * @param length the length of the range
+ * @param fireModelChanged <code>true</code> if a model change event
+ * should be fired, <code>false</code> otherwise
+ * @return <code>true</code> if any annotation has been expanded, <code>false</code> otherwise
+ */
+ protected boolean expandAll(int offset, int length, boolean fireModelChanged) {
boolean expanding= false;
@@ -101,9 +177,31 @@ public class ProjectionAnnotationModel extends AnnotationModel {
}
}
- if (expanding)
- fireModelChanged();
+ if (expanding) {
+ if (fireModelChanged)
+ fireModelChanged();
+ updateSummaries();
+ }
return expanding;
}
+
+ /**
+ * Modifies the annotation model.
+ *
+ * @param deletions the list of deleted annotations
+ * @param additions the set of annotations to add together with their associated position
+ * @param modifications the list of modified annotations
+ */
+ public void modifyAnnotations(Annotation[] deletions, Map additions, Annotation[] modifications) {
+ try {
+ replaceAnnotations(deletions, additions, false);
+ if (modifications != null) {
+ for (int i= 0; i < modifications.length; i++)
+ modifyAnnotation(modifications[i], false);
+ }
+ } catch (BadLocationException x) {
+ }
+ fireModelChanged();
+ }
} \ No newline at end of file

Back to the top