Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2015-02-06 08:28:38 +0000
committerTom Schindl2015-02-06 08:28:38 +0000
commitaa9a667672097c59ff9a7bbdb5f31acffaf69aef (patch)
tree2a14d5b9d0f79d3d06d314d2b6f047fec4719626 /experimental
parent7232dafcf353e89efb9a4c313aa2929dde3bbf10 (diff)
downloadorg.eclipse.efxclipse-aa9a667672097c59ff9a7bbdb5f31acffaf69aef.tar.gz
org.eclipse.efxclipse-aa9a667672097c59ff9a7bbdb5f31acffaf69aef.tar.xz
org.eclipse.efxclipse-aa9a667672097c59ff9a7bbdb5f31acffaf69aef.zip
start on annotion support
Diffstat (limited to 'experimental')
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/.settings/org.eclipse.jdt.core.prefs107
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/DefaultDocumentAdapter.java10
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewer.java3
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension2.java7
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension4.java16
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextPresentation.java9
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextViewer.java54
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPainter.java620
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPresenter.java4
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccess.java66
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java97
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationPresentation.java45
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewer.java1
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewer.java76
-rw-r--r--experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java21
15 files changed, 1074 insertions, 62 deletions
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/.settings/org.eclipse.jdt.core.prefs b/experimental/compensator/org.eclipse.fx.text.ui/.settings/org.eclipse.jdt.core.prefs
index 0c68a61dc..8d88004d6 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/.settings/org.eclipse.jdt.core.prefs
+++ b/experimental/compensator/org.eclipse.fx.text.ui/.settings/org.eclipse.jdt.core.prefs
@@ -1,7 +1,114 @@
eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=warning
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
+org.eclipse.jdt.core.compiler.problem.nullReference=error
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=error
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.8
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/DefaultDocumentAdapter.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/DefaultDocumentAdapter.java
index 462db1fd5..cd76d6c45 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/DefaultDocumentAdapter.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/DefaultDocumentAdapter.java
@@ -159,6 +159,7 @@ class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDo
return fDocument;
}
+ @Override
public String getLine(int line) {
IDocument document= getDocumentForRead();
@@ -169,12 +170,9 @@ class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDo
try {
return doGetLine(document, line);
} catch (BadLocationException x2) {
+ throw new IllegalStateException(x2);
}
}
-
- //TODO Log it
- System.err.println("invalid argument");
- return null;
}
public int getLineAtOffset(int offset) {
@@ -219,9 +217,7 @@ class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDo
try {
return getDocumentForRead().get(offset, length);
} catch (BadLocationException x) {
- //TODO Log it
- x.printStackTrace();
- return null;
+ throw new IllegalStateException(x);
}
}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewer.java
index 105d3a4e9..9caa5e3be 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewer.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewer.java
@@ -13,4 +13,7 @@ public interface ITextViewer {
void removeTextInputListener(ITextInputListener listener);
void changeTextPresentation(TextPresentation presentation, boolean controlRedraw);
StyledTextArea getTextWidget();
+ public boolean overlapsWithVisibleRegion(int start, int length);
+ public void invalidateTextPresentation();
+
}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension2.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension2.java
index 80730e025..78da514dc 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension2.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension2.java
@@ -1,5 +1,12 @@
package org.eclipse.jface.text;
public interface ITextViewerExtension2 {
+ /**
+ * Invalidates the viewer's text presentation for the given range.
+ *
+ * @param offset the offset of the first character to be redrawn
+ * @param length the length of the range to be redrawn
+ */
+ void invalidateTextPresentation(int offset, int length);
}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension4.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension4.java
index e04cb953b..6e7ee0c6b 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension4.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/ITextViewerExtension4.java
@@ -1,5 +1,21 @@
package org.eclipse.jface.text;
public interface ITextViewerExtension4 {
+ /**
+ * Adds the given text presentation listener to this text viewer.
+ * This call has no effect if the listener is already registered
+ * with this text viewer.
+ *
+ * @param listener the text presentation listener
+ */
+ void addTextPresentationListener(ITextPresentationListener listener);
+ /**
+ * Removes the given text presentation listener from this text viewer.
+ * This call has no effect if the listener is not registered with this
+ * text viewer.
+ *
+ * @param listener the text presentation listener
+ */
+ void removeTextPresentationListener(ITextPresentationListener listener);
}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextPresentation.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextPresentation.java
index 9fec6169c..fc26ba283 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextPresentation.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextPresentation.java
@@ -159,7 +159,7 @@ public class TextPresentation {
/**
* Creates a new empty text presentation. <code>sizeHint</code> tells the expected size of this
* presentation.
- *
+ *
* @param sizeHint the expected size of this presentation, must be positive
*/
public TextPresentation(int sizeHint) {
@@ -170,7 +170,7 @@ public class TextPresentation {
/**
* Creates a new empty text presentation with the given extent. <code>sizeHint</code> tells the
* expected size of this presentation.
- *
+ *
* @param extent the extent of the created <code>TextPresentation</code>
* @param sizeHint the expected size of this presentation, must be positive
* @since 3.0
@@ -346,7 +346,7 @@ public class TextPresentation {
current.length= Math.min(end, currentEnd) - start;
}
- if (end < currentEnd) {
+ if (end < currentEnd && currentCopy != null) {
// Add rest of current range
currentCopy.start= end;
currentCopy.length= currentEnd - end;
@@ -441,7 +441,8 @@ public class TextPresentation {
// if (template.metrics != null)
// target.metrics= template.metrics;
target.stylename = template.stylename;
-
+ target.decorationStyleClasses = template.decorationStyleClasses;
+
if (template.foreground != null || template.underlineStyle == StyleRange.UNDERLINE_LINK)
target.foreground= template.foreground;
if (template.background != null)
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextViewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextViewer.java
index 32dcec58a..513c96eb6 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextViewer.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/TextViewer.java
@@ -663,6 +663,60 @@ public class TextViewer extends Viewer implements
}
}
+ public boolean overlapsWithVisibleRegion(int start, int length) {
+ IDocument document= getVisibleDocument();
+ if (document instanceof ChildDocument) {
+ ChildDocument cdoc= (ChildDocument) document;
+ return cdoc.getParentDocumentRange().overlapsWith(start, length);
+ } else if (document != null) {
+ int size= document.getLength();
+ return (start >= 0 && length >= 0 && start + length <= size);
+ }
+ return false;
+ }
+
+ public final void invalidateTextPresentation(int offset, int length) {
+ if (fVisibleDocument != null) {
+
+ IRegion widgetRange= modelRange2WidgetRange(new Region(offset, length));
+ if (widgetRange != null) {
+
+ fWidgetCommand.event= null;
+ fWidgetCommand.start= widgetRange.getOffset();
+ fWidgetCommand.length= widgetRange.getLength();
+
+ try {
+ fWidgetCommand.text= fVisibleDocument.get(widgetRange.getOffset(), widgetRange.getLength());
+ updateTextListeners(fWidgetCommand);
+ } catch (BadLocationException x) {
+ // can not happen because of previous checking
+ }
+ }
+ }
+ }
+
+ public void addTextPresentationListener(ITextPresentationListener listener) {
+
+ Assert.isNotNull(listener);
+
+ if (fTextPresentationListeners == null)
+ fTextPresentationListeners= new ArrayList();
+
+ if (!fTextPresentationListeners.contains(listener))
+ fTextPresentationListeners.add(listener);
+ }
+
+ public void removeTextPresentationListener(ITextPresentationListener listener) {
+
+ Assert.isNotNull(listener);
+
+ if (fTextPresentationListeners != null) {
+ fTextPresentationListeners.remove(listener);
+ if (fTextPresentationListeners.size() == 0)
+ fTextPresentationListeners= null;
+ }
+ }
+
/**
* The viewer's rewrite target.
* @since 2.0
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPainter.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPainter.java
index 1a5f3326e..5b062132c 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPainter.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPainter.java
@@ -1,26 +1,638 @@
package org.eclipse.jface.text.source;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javafx.application.Platform;
+import javafx.scene.paint.Color;
+
+import org.eclipse.fx.ui.controls.styledtext.StyleRange;
+import org.eclipse.fx.ui.controls.styledtext.StyledTextArea;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextInputListener;
import org.eclipse.jface.text.ITextPresentationListener;
+import org.eclipse.jface.text.ITextViewerExtension2;
+import org.eclipse.jface.text.ITextViewerExtension5;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextPresentation;
public class AnnotationPainter implements IAnnotationModelListener, IAnnotationModelListenerExtension, ITextPresentationListener {
+ /**
+ * Mutex for for decorations map.
+ * @since 3.0
+ */
+ private Object fHighlightedDecorationsMapLock= new Object();
+
+ private Map<Annotation,Decoration> fHighlightedDecorationsMap= new HashMap<>(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=50767
+
+ /**
+ * The presentation information (decoration) for an annotation. Each such
+ * object represents one decoration drawn on the text area, such as squiggly lines
+ * and underlines.
+ */
+ private static class Decoration {
+ /** The position of this decoration */
+ private Position fPosition;
+ /** The color of this decoration */
+ private String fAnnotationClass;
+ /**
+ * The annotation's layer
+ * @since 3.0
+ */
+ private int fLayer;
+ /**
+ * The painting strategy for this decoration.
+ * @since 3.0
+ */
+ private Object fPaintingStrategy;
+ }
+
+ /**
+ * A text style painting strategy draws the decoration for an annotation
+ * onto the text widget by applying a {@link TextStyle} on a given
+ * {@link StyleRange}.
+ *
+ * @since 3.4
+ */
+ public interface ITextStyleStrategy {
+
+ /**
+ * Applies a text style on the given <code>StyleRange</code>.
+ *
+ * @param styleRange the style range on which to apply the text style
+ * @param annotationColor the color of the annotation
+ */
+// void applyTextStyle(StyleRange styleRange, Color annotationColor);
+ void applyTextStyle(StyleRange styleRange, String annotationStyleClass);
+ }
+
+
+ private ISourceViewer fSourceViewer;
+ /** The cached widget of the source viewer */
+ private StyledTextArea fTextWidget;
+ /** The annotation model providing the annotations to be drawn */
+// private IAnnotationModel fModel;
+ /** The annotation access */
+ private IAnnotationAccess fAnnotationAccess;
+
+ private Object fDecorationMapLock= new Object();
+// private Map fDecorationsMap= new HashMap(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=50767
+
+ private Position fTotalHighlightAnnotationRange= null;
+
+ /**
+ * The range in which the current highlight annotations can be found.
+ * @since 3.0
+ */
+ private Position fCurrentHighlightAnnotationRange= null;
+ private Map fCachedAnnotationType2PaintingStrategy= new HashMap();
+ private Map fPaintingStrategyId2PaintingStrategy= new HashMap();
+ private Map fAnnotationType2PaintingStrategyId= new HashMap();
+ private Map fCachedAnnotationType2Color= new HashMap();
+ private Map fAnnotationType2Color= new HashMap();
+
+ private volatile boolean fIsSettingModel= false;
+ private boolean fInputDocumentAboutToBeChanged;
+ private ITextInputListener fTextInputListener;
+
+ /**
+ * Creates a new annotation painter for the given source viewer and with the
+ * given annotation access. The painter is not initialized, i.e. no
+ * annotation types are configured to be painted.
+ *
+ * @param sourceViewer the source viewer for this painter
+ * @param access the annotation access for this painter
+ */
+ public AnnotationPainter(ISourceViewer sourceViewer, IAnnotationAccess access) {
+ fSourceViewer= sourceViewer;
+ fAnnotationAccess= access;
+ fTextWidget= sourceViewer.getTextWidget();
+ }
+
+ /**
+ * Updates the set of decorations based on the current state of
+ * the painter's annotation model.
+ *
+ * @param event the annotation model event
+ */
+ private void catchupWithModel(AnnotationModelEvent event) {
+
+ synchronized (fDecorationMapLock) {
+// if (fDecorationsMap == null)
+// return;
+ }
+
+ if (fSourceViewer.getAnnotationModel() == null) {
+ // annotation model is null -> clear all
+// synchronized (fDecorationMapLock) {
+// fDecorationsMap.clear();
+// }
+ synchronized (fHighlightedDecorationsMapLock) {
+ fHighlightedDecorationsMap.clear();
+ }
+ return;
+ }
+
+// IRegion clippingRegion= computeClippingRegion(null, true);
+ IDocument document= fSourceViewer.getDocument();
+
+ int highlightAnnotationRangeStart= Integer.MAX_VALUE;
+ int highlightAnnotationRangeEnd= -1;
+
+ int drawRangeStart= Integer.MAX_VALUE;
+ int drawRangeEnd= -1;
+
+// Map decorationsMap;
+ Map highlightedDecorationsMap;
+
+ // Clone decoration maps
+// synchronized (fDecorationMapLock) {
+// decorationsMap= new HashMap(fDecorationsMap);
+// }
+ synchronized (fHighlightedDecorationsMapLock) {
+ highlightedDecorationsMap= new HashMap<>(fHighlightedDecorationsMap);
+ }
+
+ boolean isWorldChange= false;
+
+ Iterator e;
+ if (event == null || event.isWorldChange()) {
+ isWorldChange= true;
+
+// if (DEBUG && event == null)
+// System.out.println("AP: INTERNAL CHANGE"); //$NON-NLS-1$
+
+// Iterator iter= decorationsMap.entrySet().iterator();
+// while (iter.hasNext()) {
+// Map.Entry entry= (Map.Entry)iter.next();
+// Annotation annotation= (Annotation)entry.getKey();
+// Decoration decoration= (Decoration)entry.getValue();
+//// drawDecoration(decoration, null, annotation, clippingRegion, document);
+// }
+
+// decorationsMap.clear();
+
+ highlightedDecorationsMap.clear();
+
+ e= fSourceViewer.getAnnotationModel().getAnnotationIterator();
+
+
+ } else {
+
+ // Remove annotations
+ Annotation[] removedAnnotations= event.getRemovedAnnotations();
+ for (int i= 0, length= removedAnnotations.length; i < length; i++) {
+ Annotation annotation= removedAnnotations[i];
+ Decoration decoration= (Decoration)highlightedDecorationsMap.remove(annotation);
+ if (decoration != null) {
+ Position position= decoration.fPosition;
+ if (position != null) {
+ highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, position.offset);
+ highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, position.offset + position.length);
+ }
+ }
+// decoration= (Decoration)decorationsMap.remove(annotation);
+// if (decoration != null) {
+//// drawDecoration(decoration, null, annotation, clippingRegion, document);
+// Position position= decoration.fPosition;
+// if (position != null) {
+// drawRangeStart= Math.min(drawRangeStart, position.offset);
+// drawRangeEnd= Math.max(drawRangeEnd, position.offset + position.length);
+// }
+// }
+
+ }
+
+ // Update existing annotations
+ Annotation[] changedAnnotations= event.getChangedAnnotations();
+ for (int i= 0, length= changedAnnotations.length; i < length; i++) {
+ Annotation annotation= changedAnnotations[i];
+
+ boolean isHighlighting= false;
+
+ Decoration decoration= (Decoration)highlightedDecorationsMap.get(annotation);
+
+ if (decoration != null) {
+ isHighlighting= true;
+ // The call below updates the decoration - no need to create new decoration
+ decoration= getDecoration(annotation, decoration);
+ if (decoration == null) {
+ Decoration removedDecoration= (Decoration)highlightedDecorationsMap.remove(annotation);
+ if (removedDecoration != null) {
+ highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, removedDecoration.fPosition.offset);
+ highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, removedDecoration.fPosition.offset + removedDecoration.fPosition.length);
+ }
+ }
+
+ } else {
+ decoration= getDecoration(annotation, decoration);
+ if (decoration != null && decoration.fPaintingStrategy instanceof ITextStyleStrategy) {
+ highlightedDecorationsMap.put(annotation, decoration);
+ isHighlighting= true;
+ }
+ }
+
+ boolean usesDrawingStrategy= !isHighlighting && decoration != null;
+
+ Position position= null;
+ if (decoration == null)
+ position= fSourceViewer.getAnnotationModel().getPosition(annotation);
+ else
+ position= decoration.fPosition;
+
+ if (position != null && !position.isDeleted()) {
+ if (isHighlighting) {
+ highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, position.offset);
+ highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, position.offset + position.length);
+ }
+ if (usesDrawingStrategy) {
+ drawRangeStart= Math.min(drawRangeStart, position.offset);
+ drawRangeEnd= Math.max(drawRangeEnd, position.offset + position.length);
+ }
+ } else {
+ Decoration removedDecoration= (Decoration)highlightedDecorationsMap.remove(annotation);
+ if (removedDecoration != null) {
+ highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, removedDecoration.fPosition.offset);
+ highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, removedDecoration.fPosition.offset + removedDecoration.fPosition.length);
+ }
+ }
+
+// if (usesDrawingStrategy) {
+// Decoration oldDecoration= (Decoration)decorationsMap.get(annotation);
+// if (oldDecoration != null) {
+//// drawDecoration(oldDecoration, null, annotation, clippingRegion, document);
+// if (decoration != null)
+// decorationsMap.put(annotation, decoration);
+// else
+// decorationsMap.remove(annotation);
+// }
+// }
+ }
+
+ e= Arrays.asList(event.getAddedAnnotations()).iterator();
+ }
+
+ // Add new annotations
+ while (e.hasNext()) {
+ Annotation annotation= (Annotation)e.next();
+ Decoration pp= getDecoration(annotation, null);
+ if (pp != null) {
+// if (pp.fPaintingStrategy instanceof IDrawingStrategy) {
+// decorationsMap.put(annotation, pp);
+// drawRangeStart= Math.min(drawRangeStart, pp.fPosition.offset);
+// drawRangeEnd= Math.max(drawRangeEnd, pp.fPosition.offset + pp.fPosition.length);
+// } else
+ if (pp.fPaintingStrategy instanceof ITextStyleStrategy) {
+ highlightedDecorationsMap.put(annotation, pp);
+ highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, pp.fPosition.offset);
+ highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, pp.fPosition.offset + pp.fPosition.length);
+ }
+
+ }
+ }
+
+// synchronized (fDecorationMapLock) {
+// fDecorationsMap= decorationsMap;
+// updateDrawRanges(drawRangeStart, drawRangeEnd, isWorldChange);
+// }
+
+ synchronized (fHighlightedDecorationsMapLock) {
+ fHighlightedDecorationsMap= highlightedDecorationsMap;
+ updateHighlightRanges(highlightAnnotationRangeStart, highlightAnnotationRangeEnd, isWorldChange);
+ }
+ }
@Override
- public void applyTextPresentation(TextPresentation textPresentation) {
- // TODO Auto-generated method stub
+ public void applyTextPresentation(TextPresentation tp) {
+ Set<Entry<Annotation,Decoration>> decorations;
+
+ synchronized (fHighlightedDecorationsMapLock) {
+ if (fHighlightedDecorationsMap == null || fHighlightedDecorationsMap.isEmpty())
+ return;
+
+ decorations= new HashSet<>(fHighlightedDecorationsMap.entrySet());
+ }
+
+ IRegion region= tp.getExtent();
+
+// if (DEBUG)
+// System.out.println("AP: applying text presentation offset: " + region.getOffset() + ", length= " + region.getLength()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ for (int layer= 0, maxLayer= 1; layer < maxLayer; layer++) {
+
+ for (Iterator<?> iter= decorations.iterator(); iter.hasNext();) {
+ Map.Entry entry= (Map.Entry)iter.next();
+
+ Annotation a= (Annotation)entry.getKey();
+ if (a.isMarkedDeleted())
+ continue;
+
+ Decoration pp = (Decoration)entry.getValue();
+
+ maxLayer= Math.max(maxLayer, pp.fLayer + 1); // dynamically update layer maximum
+ if (pp.fLayer != layer) // wrong layer: skip annotation
+ continue;
+
+ Position p= pp.fPosition;
+ if (fSourceViewer instanceof ITextViewerExtension5) {
+ ITextViewerExtension5 extension3= (ITextViewerExtension5) fSourceViewer;
+ if (null == extension3.modelRange2WidgetRange(new Region(p.getOffset(), p.getLength())))
+ continue;
+ } else if (!fSourceViewer.overlapsWithVisibleRegion(p.offset, p.length)) {
+ continue;
+ }
+
+ int regionEnd= region.getOffset() + region.getLength();
+ int pEnd= p.getOffset() + p.getLength();
+ if (pEnd >= region.getOffset() && regionEnd > p.getOffset()) {
+ int start= Math.max(p.getOffset(), region.getOffset());
+ int end= Math.min(regionEnd, pEnd);
+ int length= Math.max(end - start, 0);
+ StyleRange styleRange= new StyleRange(null,start, length, null, null);
+ ((ITextStyleStrategy)pp.fPaintingStrategy).applyTextStyle(styleRange, pp.fAnnotationClass);
+ tp.mergeStyleRange(styleRange);
+ }
+ }
+ }
+ }
+
+ private Decoration getDecoration(Annotation annotation, Decoration decoration) {
+
+ if (annotation.isMarkedDeleted())
+ return null;
+
+ String type= annotation.getType();
+
+ Object paintingStrategy= getPaintingStrategy(type);
+ if (paintingStrategy == null)
+ return null;
+
+ String color= getColor(type);
+ if (color == null)
+ return null;
+
+ Position position= fSourceViewer.getAnnotationModel().getPosition(annotation);
+ if (position == null || position.isDeleted())
+ return null;
+
+ if (decoration == null)
+ decoration= new Decoration();
+
+ decoration.fPosition= position;
+ decoration.fAnnotationClass= color;
+// if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+// IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+// decoration.fLayer= extension.getLayer(annotation);
+// } else {
+// decoration.fLayer= IAnnotationAccessExtension.DEFAULT_LAYER;
+// }
+
+ decoration.fPaintingStrategy= paintingStrategy;
+
+ return decoration;
+ }
+
+ private void updateHighlightRanges(int highlightAnnotationRangeStart, int highlightAnnotationRangeEnd, boolean isWorldChange) {
+ if (highlightAnnotationRangeStart != Integer.MAX_VALUE) {
+
+ int maxRangeStart= highlightAnnotationRangeStart;
+ int maxRangeEnd= highlightAnnotationRangeEnd;
+
+ if (fTotalHighlightAnnotationRange != null) {
+ maxRangeStart= Math.min(maxRangeStart, fTotalHighlightAnnotationRange.offset);
+ maxRangeEnd= Math.max(maxRangeEnd, fTotalHighlightAnnotationRange.offset + fTotalHighlightAnnotationRange.length);
+ }
+
+ if (fTotalHighlightAnnotationRange == null)
+ fTotalHighlightAnnotationRange= new Position(0);
+ if (fCurrentHighlightAnnotationRange == null)
+ fCurrentHighlightAnnotationRange= new Position(0);
+
+ if (isWorldChange) {
+ fTotalHighlightAnnotationRange.offset= highlightAnnotationRangeStart;
+ fTotalHighlightAnnotationRange.length= highlightAnnotationRangeEnd - highlightAnnotationRangeStart;
+ fCurrentHighlightAnnotationRange.offset= maxRangeStart;
+ fCurrentHighlightAnnotationRange.length= maxRangeEnd - maxRangeStart;
+ } else {
+ fTotalHighlightAnnotationRange.offset= maxRangeStart;
+ fTotalHighlightAnnotationRange.length= maxRangeEnd - maxRangeStart;
+ fCurrentHighlightAnnotationRange.offset=highlightAnnotationRangeStart;
+ fCurrentHighlightAnnotationRange.length= highlightAnnotationRangeEnd - highlightAnnotationRangeStart;
+ }
+ } else {
+ if (isWorldChange) {
+ fCurrentHighlightAnnotationRange= fTotalHighlightAnnotationRange;
+ fTotalHighlightAnnotationRange= null;
+ } else {
+ fCurrentHighlightAnnotationRange= null;
+ }
+ }
+
+ adaptToDocumentLength(fCurrentHighlightAnnotationRange);
+ adaptToDocumentLength(fTotalHighlightAnnotationRange);
+ }
+
+ private void adaptToDocumentLength(Position position) {
+ if (position == null)
+ return;
+
+ int length= fSourceViewer.getDocument().getLength();
+ position.offset= Math.min(position.offset, length);
+ position.length= Math.min(position.length, length - position.offset);
+ }
+
+ /**
+ * Returns the painting strategy for the given annotation.
+ *
+ * @param type the annotation type
+ * @return the annotation painter
+ * @since 3.0
+ */
+ private Object getPaintingStrategy(final String type) {
+ Object strategy= fCachedAnnotationType2PaintingStrategy.get(type);
+ if (strategy != null)
+ return strategy;
+
+ strategy= fPaintingStrategyId2PaintingStrategy.get(fAnnotationType2PaintingStrategyId.get(type));
+ if (strategy != null) {
+ fCachedAnnotationType2PaintingStrategy.put(type, strategy);
+ return strategy;
+ }
+
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension ext = (IAnnotationAccessExtension) fAnnotationAccess;
+ Object[] sts = ext.getSupertypes(type);
+ for (int i= 0; i < sts.length; i++) {
+ strategy= fPaintingStrategyId2PaintingStrategy.get(fAnnotationType2PaintingStrategyId.get(sts[i]));
+ if (strategy != null) {
+ fCachedAnnotationType2PaintingStrategy.put(type, strategy);
+ return strategy;
+ }
+ }
+ }
+
+ fCachedAnnotationType2PaintingStrategy.put(type, null);
+ return null;
}
+ private String getColor(final Object annotationType) {
+ String color= (String)fCachedAnnotationType2Color.get(annotationType);
+ if (color != null)
+ return color;
+
+ color= (String)fAnnotationType2Color.get(annotationType);
+ if (color != null) {
+ fCachedAnnotationType2Color.put(annotationType, color);
+ return color;
+ }
+
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+ Object[] superTypes= extension.getSupertypes(annotationType);
+ if (superTypes != null) {
+ for (int i= 0; i < superTypes.length; i++) {
+ color= (String)fAnnotationType2Color.get(superTypes[i]);
+ if (color != null) {
+ fCachedAnnotationType2Color.put(annotationType, color);
+ return color;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private void updatePainting(AnnotationModelEvent event) {
+// disablePainting(event == null);
+
+ catchupWithModel(event);
+
+ if (!fInputDocumentAboutToBeChanged)
+ invalidateTextPresentation();
+
+// enablePainting();
+ }
+
+ private void invalidateTextPresentation() {
+ IRegion r= null;
+ synchronized (fHighlightedDecorationsMapLock) {
+ if (fCurrentHighlightAnnotationRange != null)
+ r= new Region(fCurrentHighlightAnnotationRange.getOffset(), fCurrentHighlightAnnotationRange.getLength());
+ }
+ if (r == null)
+ return;
+
+ if (fSourceViewer instanceof ITextViewerExtension2) {
+// if (DEBUG)
+// System.out.println("AP: invalidating offset: " + r.getOffset() + ", length= " + r.getLength()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ ((ITextViewerExtension2)fSourceViewer).invalidateTextPresentation(r.getOffset(), r.getLength());
+
+ } else {
+ fSourceViewer.invalidateTextPresentation();
+ }
+ }
+
+
+
@Override
public void modelChanged(AnnotationModelEvent event) {
- // TODO Auto-generated method stub
+// Display textWidgetDisplay;
+// try {
+// StyledText textWidget= fTextWidget;
+// if (textWidget == null || textWidget.isDisposed())
+// return;
+// textWidgetDisplay= textWidget.getDisplay();
+// } catch (SWTException ex) {
+// if (ex.code == SWT.ERROR_WIDGET_DISPOSED)
+// return;
+// throw ex;
+// }
+
+ if (fIsSettingModel) {
+ // inside the UI thread -> no need for posting
+ if( Platform.isFxApplicationThread() ) {
+ updatePainting(event);
+ }
+ else {
+ /*
+ * we can throw away the changes since
+ * further update painting will happen
+ */
+ return;
+ }
+ } else {
+// if (DEBUG && event != null && event.isWorldChange()) {
+// System.out.println("AP: WORLD CHANGED, stack trace follows:"); //$NON-NLS-1$
+// new Throwable().printStackTrace(System.out);
+// }
+
+ // XXX: posting here is a problem for annotations that are being
+ // removed and the positions of which are not updated to document
+ // changes any more. If the document gets modified between
+ // now and running the posted runnable, the position information
+ // is not accurate any longer.
+ Platform.runLater(() -> updatePainting(event));
+ }
}
@Override
public void modelChanged(IAnnotationModel model) {
- // TODO Auto-generated method stub
+ modelChanged(new AnnotationModelEvent(model));
+ }
+
+
+ public void addAnnotationType(Object annotationType, Object strategyID) {
+ fAnnotationType2PaintingStrategyId.put(annotationType, strategyID);
+ fCachedAnnotationType2PaintingStrategy.clear();
+
+ if (fTextInputListener == null) {
+ fTextInputListener= new ITextInputListener() {
+
+ /*
+ * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
+ */
+ public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
+ fInputDocumentAboutToBeChanged= true;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
+ */
+ public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
+ fInputDocumentAboutToBeChanged= false;
+ }
+ };
+ fSourceViewer.addTextInputListener(fTextInputListener);
+ }
+
+ }
+
+ public void setAnnotationTypeColor(Object annotationType, String color) {
+ if (color != null)
+ fAnnotationType2Color.put(annotationType, color);
+ else
+ fAnnotationType2Color.remove(annotationType);
+ fCachedAnnotationType2Color.clear();
+ }
+ public void addTextStyleStrategy(Object id, ITextStyleStrategy strategy) {
+ // don't permit null as null is used to signal that an annotation type is not
+ // registered with a specific strategy, and that its annotation hierarchy should be searched
+ if (id == null)
+ throw new IllegalArgumentException();
+ fPaintingStrategyId2PaintingStrategy.put(id, strategy);
+ fCachedAnnotationType2PaintingStrategy.clear();
}
}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPresenter.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPresenter.java
index 1d2f49511..f0bfca63c 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPresenter.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/AnnotationPresenter.java
@@ -1,10 +1,12 @@
package org.eclipse.jface.text.source;
+import java.util.List;
+
import org.eclipse.fx.ui.services.resources.GraphicsLoader;
import javafx.scene.Node;
public interface AnnotationPresenter {
- public String getType();
+ public List<String> getTypes();
public Node getPresentation(Annotation annotation, GraphicsLoader loader);
}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccess.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccess.java
new file mode 100644
index 000000000..06c6ab185
--- /dev/null
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccess.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.source;
+
+/**
+ * An annotation access provides access to information that is not available via
+ * the API of {@link org.eclipse.jface.text.source.Annotation}. With version
+ * 3.0 all this information is now available from the annotation itself.
+ * <p>
+ *
+ * In order to provide backward compatibility for clients of
+ * <code>IAnnotationAccess</code>, extension interfaces are used as a means
+ * of evolution. The following extension interfaces exist:
+ * <ul>
+ * <li>{@link org.eclipse.jface.text.source.IAnnotationAccessExtension} since
+ * version 3.0 replacing all methods in that interface</li>
+ * <li>{@link IAnnotationAccessExtension2} since
+ * version 3.2 allowing to set a quick assist assistant to an annotation access.</li>
+ * </ul></p>
+ * <p>
+ * Clients usually implement this interface and its extension interfaces.</p>
+ *
+ * @see org.eclipse.jface.text.source.IAnnotationAccessExtension
+ * @see org.eclipse.jface.text.source.Annotation
+ * @since 2.1
+ */
+public interface IAnnotationAccess {
+
+ /**
+ * Returns the type of the given annotation.
+ *
+ * @param annotation the annotation
+ * @return the type of the given annotation or <code>null</code> if it has none.
+ * @deprecated use <code>Annotation.getType()</code>
+ */
+ Object getType(Annotation annotation);
+
+ /**
+ * Returns whether the given annotation spans multiple lines.
+ *
+ * @param annotation the annotation
+ * @return <code>true</code> if the annotation spans multiple lines,
+ * <code>false</code> otherwise
+ *
+ * @deprecated assumed to always return <code>true</code>
+ */
+ boolean isMultiLine(Annotation annotation);
+
+ /**
+ * Returns whether the given annotation is temporary rather than persistent.
+ *
+ * @param annotation the annotation
+ * @return <code>true</code> if the annotation is temporary,
+ * <code>false</code> otherwise
+ * @deprecated use <code>Annotation.isPersistent()</code>
+ */
+ boolean isTemporary(Annotation annotation);
+}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
new file mode 100644
index 000000000..7c500fc5c
--- /dev/null
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.source;
+
+/**
+ * Extension interface for {@link org.eclipse.jface.text.source.IAnnotationAccess}.<p>
+ * This interface replaces the methods of <code>IAnnotationAccess</code>.<p>
+ * This interface provides
+ * <ul>
+ * <li> a label for the annotation type of a given annotation</li>
+ * <li> the paint layer of a given annotation</li>
+ * <li> means to paint a given annotation</li>
+ * <li> information about the type hierarchy of the annotation type of a given annotation</li>
+ * <ul>.
+ *
+ * @see org.eclipse.jface.text.source.IAnnotationAccess
+ * @since 3.0
+ */
+public interface IAnnotationAccessExtension {
+
+ /**
+ * The default annotation layer.
+ */
+ static final int DEFAULT_LAYER= IAnnotationPresentation.DEFAULT_LAYER;
+
+ /**
+ * Returns the label for the given annotation's type.
+ *
+ * @param annotation the annotation
+ * @return the label the given annotation's type or <code>null</code> if no such label exists
+ */
+ String getTypeLabel(Annotation annotation);
+
+ /**
+ * Returns the layer for given annotation. Annotations are considered
+ * being located at layers and are considered being painted starting with
+ * layer 0 upwards. Thus an annotation at layer 5 will be drawn on top of
+ * all co-located annotations at the layers 4 - 0.
+ *
+ * @param annotation the annotation
+ * @return the layer of the given annotation
+ */
+ int getLayer(Annotation annotation);
+
+// /**
+// * Draws a graphical representation of the given annotation within the given bounds.
+// * <p>
+// * <em>Note that this method is not used when drawing annotations on the editor's
+// * text widget. This is handled trough a {@link org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy}.</em>
+// * </p>
+// * @param annotation the given annotation
+// * @param gc the drawing GC
+// * @param canvas the canvas to draw on
+// * @param bounds the bounds inside the canvas to draw on
+// */
+// void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds);
+
+ /**
+ * Returns <code>true</code> if painting <code>annotation</code> will produce something
+ * meaningful, <code>false</code> if not. E.g. if no image is available.
+ * <p>
+ * <em>Note that this method is not used when drawing annotations on the editor's
+ * text widget. This is handled trough a {@link org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy}.</em>
+ * </p>
+ * @param annotation the annotation to check whether it can be painted
+ * @return <code>true</code> if painting <code>annotation</code> will succeed
+ */
+ boolean isPaintable(Annotation annotation);
+
+ /**
+ * Returns <code>true</code> if the given annotation is of the given type
+ * or <code>false</code> otherwise.
+ *
+ * @param annotationType the annotation type
+ * @param potentialSupertype the potential super annotation type
+ * @return <code>true</code> if annotation type is a sub-type of the potential annotation super type
+ */
+ boolean isSubtype(Object annotationType, Object potentialSupertype);
+
+ /**
+ * Returns the list of super types for the given annotation type. This does not include the type
+ * itself. The index in the array of super types indicates the length of the path in the hierarchy
+ * graph to the given annotation type.
+ *
+ * @param annotationType the annotation type to check
+ * @return the super types for the given annotation type
+ */
+ Object[] getSupertypes(Object annotationType);
+}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationPresentation.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationPresentation.java
new file mode 100644
index 000000000..0a44ef928
--- /dev/null
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/IAnnotationPresentation.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.source;
+
+/**
+ * Interface for annotations that can take care of their own visible representation.
+ *
+ * @since 3.0
+ */
+public interface IAnnotationPresentation {
+
+ /**
+ * The default annotation layer.
+ */
+ static final int DEFAULT_LAYER= 0;
+
+
+ /**
+ * Returns the annotations drawing layer.
+ *
+ * @return the annotations drawing layer
+ */
+ int getLayer();
+
+// /**
+// * Implement this method to draw a graphical representation
+// * of this annotation within the given bounds.
+// * <p>
+// * <em>Note that this method is not used when drawing annotations on the editor's
+// * text widget. This is handled trough a {@link org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy}.</em>
+// * </p>
+// * @param gc the drawing GC
+// * @param canvas the canvas to draw on
+// * @param bounds the bounds inside the canvas to draw on
+// */
+// void paint(GC gc, Canvas canvas, Rectangle bounds);
+}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewer.java
index b2fb2f1b9..b8722e129 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewer.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/ISourceViewer.java
@@ -7,4 +7,5 @@ public interface ISourceViewer extends ITextViewer {
void configure(SourceViewerConfiguration configuration);
void setDocument(IDocument document, IAnnotationModel annotationModel);
public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength);
+ IAnnotationModel getAnnotationModel();
}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewer.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewer.java
index 4e47d6a67..8dc8ed3e8 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewer.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewer.java
@@ -43,19 +43,21 @@ public class SourceViewer extends TextViewer implements ISourceViewer, ISourceVi
public void configure(SourceViewerConfiguration configuration) {
if (getTextWidget() == null)
return;
-
- if( configuration.getDefaultStylesheet().getValue() != null ) {
- getTextWidget().getStylesheets().add(configuration.getDefaultStylesheet().getValue().toExternalForm());
- }
-
- configuration.getDefaultStylesheet().addListener((obs,oldVal,newVal) -> {
- if( oldVal != null ) {
- getTextWidget().getStylesheets().remove(oldVal.toExternalForm());
- }
- if( newVal != null ) {
- getTextWidget().getStylesheets().add(newVal.toExternalForm());
- }
- });
+
+ getTextWidget().getStyleClass().add(configuration.getStyleclassName());
+
+// if( configuration.getDefaultStylesheet().getValue() != null ) {
+// getTextWidget().getStylesheets().add(configuration.getDefaultStylesheet().getValue().toExternalForm());
+// }
+//
+// configuration.getDefaultStylesheet().addListener((obs,oldVal,newVal) -> {
+// if( oldVal != null ) {
+// getTextWidget().getStylesheets().remove(oldVal.toExternalForm());
+// }
+// if( newVal != null ) {
+// getTextWidget().getStylesheets().add(newVal.toExternalForm());
+// }
+// });
setDocumentPartitioning(configuration.getConfiguredDocumentPartitioning(this));
@@ -77,28 +79,35 @@ public class SourceViewer extends TextViewer implements ISourceViewer, ISourceVi
IAnnotationModel annotationModel = configuration.getAnnotationModel();
if( annotationModel != null ) {
getTextWidget().setLineRulerGraphicNodeFactory(this::annotationFactory);
- }
-
- presenterMap.putAll(configuration.getAnnotationPresenters().stream().collect(Collectors.toMap(p -> p.getType(), p -> p)));
- graphicsLoader = configuration.getGraphicsLoader();
+ annotationModel.addAnnotationModelListener(new IAnnotationModelListener() {
+
+ private boolean scheduled = false;
+
+ @Override
+ public void modelChanged(IAnnotationModel model) {
+ if( ! scheduled ) {
+ scheduled = true;
+ Platform.runLater(() -> {
+ scheduled = false;
+ System.err.println("REFRESHING");
+ getTextWidget().refreshLineRuler();
+ });
+ }
+ }
- annotationModel.addAnnotationModelListener(new IAnnotationModelListener() {
+ });
+ }
- private boolean scheduled = false;
+ configuration.getAnnotationPresenters().stream().forEach(p -> p.getTypes().forEach( s -> presenterMap.put(s,p)));
- @Override
- public void modelChanged(IAnnotationModel model) {
- if( ! scheduled ) {
- scheduled = true;
- Platform.runLater(() -> {
- scheduled = false;
- System.err.println("REFRESHING");
- getTextWidget().refreshLineRuler();
- });
- }
- }
+// presenterMap.putAll(configuration.getAnnotationPresenters().stream().collect(Collectors.toMap(p -> p.getType(), p -> p)));
+ graphicsLoader = configuration.getGraphicsLoader();
- });
+ AnnotationPainter annotationPainter = configuration.getAnnotationPainter(this);
+ if( annotationModel != null && annotationPainter != null ) {
+ annotationModel.addAnnotationModelListener(annotationPainter);
+ addTextPresentationListener(annotationPainter);
+ }
}
private Node annotationFactory(StyledTextLine l) {
@@ -175,4 +184,9 @@ public class SourceViewer extends TextViewer implements ISourceViewer, ISourceVi
else
super.setDocument(document, modelRangeOffset, modelRangeLength);
}
+
+ @Override
+ public IAnnotationModel getAnnotationModel() {
+ return fVisualAnnotationModel;
+ }
}
diff --git a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java
index fe8a88dd3..f92067b93 100644
--- a/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java
+++ b/experimental/compensator/org.eclipse.fx.text.ui/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java
@@ -10,14 +10,11 @@
*******************************************************************************/
package org.eclipse.jface.text.source;
-import java.net.URL;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
-import javafx.beans.property.ReadOnlyProperty;
-
import org.eclipse.fx.ui.services.resources.GraphicsLoader;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.contentassist.IContentAssistant;
@@ -26,16 +23,6 @@ import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.reconciler.IReconciler;
public abstract class SourceViewerConfiguration {
- private String themeId;
-
- public void setThemeId(String themeId) {
- this.themeId = themeId;
- }
-
- public String getThemeId() {
- return this.themeId;
- }
-
public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
return IDocumentExtension3.DEFAULT_PARTITIONING;
}
@@ -45,8 +32,8 @@ public abstract class SourceViewerConfiguration {
reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
return reconciler;
}
-
- public abstract ReadOnlyProperty<URL> getDefaultStylesheet();
+
+ public abstract String getStyleclassName();
public IReconciler getReconciler(ISourceViewer sourceViewer) {
return null;
@@ -64,6 +51,10 @@ public abstract class SourceViewerConfiguration {
return Collections.emptyList();
}
+ public AnnotationPainter getAnnotationPainter(ISourceViewer sourceViewer) {
+ return null;
+ }
+
@Inject
GraphicsLoader graphicsLoader;

Back to the top