Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Maeder2004-03-10 16:15:59 +0000
committerThomas Maeder2004-03-10 16:15:59 +0000
commit0e18025f823a3c052005ae0c54c981319a86f337 (patch)
tree4fc163830a2d4cc8a923bd7a36ac0a8fa55826a8
parent840398f6cc3819e33510697150b142b151861eb1 (diff)
downloadeclipse.platform.text-0e18025f823a3c052005ae0c54c981319a86f337.tar.gz
eclipse.platform.text-0e18025f823a3c052005ae0c54c981319a86f337.tar.xz
eclipse.platform.text-0e18025f823a3c052005ae0c54c981319a86f337.zip
Using adapter to get annotation model
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java47
1 files changed, 29 insertions, 18 deletions
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java
index 0fed09607..8b491b229 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java
@@ -41,7 +41,7 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
private AbstractTextSearchResult fResult;
private Map fMatchesToAnnotations;
private AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup();
- private ITextEditor fEditor;
+ private IEditorPart fEditor;
private IWorkbenchWindow fWindow;
private static HashMap fSearchResultMap;
private static AnnotationManager fgManager;
@@ -113,10 +113,11 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
}
public synchronized void partActivated(IWorkbenchPart part) {
- if (part instanceof ITextEditor && part != fEditor) {
+
+ if (part instanceof IEditorPart && part != fEditor) {
if (fResult != null)
removeAnnotations();
- fEditor= (ITextEditor) part;
+ fEditor= (IEditorPart) part;
addAnnotations();
}
}
@@ -131,7 +132,7 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
}
private void removeAnnotations() {
- ITextEditor editor= fEditor;
+ IEditorPart editor= fEditor;
if (editor == null)
return;
Set matchSet= fMatchesToAnnotations.keySet();
@@ -155,7 +156,9 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
fWindow.getPartService().removePartListener(AnnotationManager.this);
fWindow= window;
fWindow.getPartService().addPartListener(this);
- partActivated(window.getActivePage().getActiveEditor());
+ IEditorPart editor= window.getActivePage().getActiveEditor();
+ if (editor != null)
+ partActivated(editor);
}
public void partDeactivated(IWorkbenchPart part) {
@@ -195,14 +198,8 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
* @param annotions A set containing the annotations to be removed.
* @see Annotation
*/
- private void removeAnnotations(IEditorPart editor, Set annotations) {
- if (!(editor instanceof ITextEditor))
- return;
- ITextEditor textEditor= (ITextEditor) editor;
- IDocumentProvider dp= textEditor.getDocumentProvider();
- if (dp == null)
- return;
- IAnnotationModel model= dp.getAnnotationModel(textEditor.getEditorInput());
+ private void removeAnnotations(IWorkbenchPart editor, Set annotations) {
+ IAnnotationModel model= getAnnotationModel(editor);
if (model == null)
return;
if (model instanceof IAnnotationModelExtension) {
@@ -226,11 +223,8 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
* @see Annotation
* @see Position
*/
- private void addAnnotations(IEditorPart editor, Map annotationToPositionMap) {
- if (!(editor instanceof ITextEditor))
- return;
- ITextEditor textEditor= (ITextEditor) editor;
- IAnnotationModel model= textEditor.getDocumentProvider().getAnnotationModel(textEditor.getEditorInput());
+ private void addAnnotations(IWorkbenchPart editor, Map annotationToPositionMap) {
+ IAnnotationModel model= getAnnotationModel(editor);
if (model == null) {
return;
}
@@ -246,4 +240,21 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
}
}
+ private IAnnotationModel getAnnotationModel(IWorkbenchPart part) {
+ IAnnotationModel model= null;
+ model= (IAnnotationModel) part.getAdapter(IAnnotationModel.class);
+ if (model == null) {
+ ITextEditor textEditor= null;
+ if (part instanceof ITextEditor) {
+ textEditor= (ITextEditor) part;
+ }
+ if (textEditor != null) {
+ IDocumentProvider dp= textEditor.getDocumentProvider();
+ if (dp != null)
+ model= dp.getAnnotationModel(textEditor.getEditorInput());
+ }
+ }
+ return model;
+ }
+
}

Back to the top