1 11 12 13 package org.eclipse.ui.texteditor; 14 15 16 import java.util.ResourceBundle ; 17 18 import org.eclipse.swt.widgets.Menu; 19 20 import org.eclipse.jface.text.Position; 21 import org.eclipse.jface.text.source.Annotation; 22 import org.eclipse.jface.text.source.IVerticalRulerListener; 23 import org.eclipse.jface.text.source.IAnnotationModel; 24 import org.eclipse.jface.text.source.IVerticalRulerInfo; 25 import org.eclipse.jface.text.source.IVerticalRulerInfoExtension; 26 import org.eclipse.jface.text.source.VerticalRulerEvent; 27 28 34 public class SelectAnnotationRulerAction extends TextEditorAction implements IVerticalRulerListener { 35 36 47 public SelectAnnotationRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor) { 48 super(bundle, prefix, editor); 49 } 50 51 54 public void setEditor(ITextEditor editor) { 55 if (getTextEditor() != null) { 56 IVerticalRulerInfo service= (IVerticalRulerInfo) getTextEditor().getAdapter(IVerticalRulerInfo.class); 57 if (service instanceof IVerticalRulerInfoExtension) 58 ((IVerticalRulerInfoExtension) service).removeVerticalRulerListener(this); 59 } 60 super.setEditor(editor); 61 if (getTextEditor() != null) { 62 IVerticalRulerInfo service= (IVerticalRulerInfo) getTextEditor().getAdapter(IVerticalRulerInfo.class); 63 if (service instanceof IVerticalRulerInfoExtension) 64 ((IVerticalRulerInfoExtension) service).addVerticalRulerListener(this); 65 } 66 } 67 68 73 protected IAnnotationModel getAnnotationModel() { 74 IDocumentProvider provider= getTextEditor().getDocumentProvider(); 75 return provider.getAnnotationModel(getTextEditor().getEditorInput()); 76 } 77 78 81 public void annotationSelected(VerticalRulerEvent event) { 82 } 83 84 87 public void annotationDefaultSelected(VerticalRulerEvent event) { 88 Annotation a= event.getSelectedAnnotation(); 89 IAnnotationModel model= getAnnotationModel(); 90 Position position= model.getPosition(a); 91 if (position == null) 92 return; 93 94 getTextEditor().selectAndReveal(position.offset, position.length); 95 } 96 97 100 public void annotationContextMenuAboutToShow(VerticalRulerEvent event, Menu menu) { 101 } 102 } 103 | Popular Tags |