1 11 package org.eclipse.pde.internal.ui.editor.text; 12 13 import java.util.Iterator ; 14 import java.util.ResourceBundle ; 15 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.jface.text.ITextOperationTarget; 18 import org.eclipse.jface.text.Position; 19 import org.eclipse.jface.text.source.Annotation; 20 import org.eclipse.jface.text.source.IAnnotationAccessExtension; 21 import org.eclipse.jface.text.source.ISourceViewer; 22 import org.eclipse.jface.text.source.IVerticalRulerInfo; 23 import org.eclipse.swt.widgets.Event; 24 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel; 25 import org.eclipse.ui.texteditor.ITextEditor; 26 import org.eclipse.ui.texteditor.ITextEditorExtension; 27 import org.eclipse.ui.texteditor.SelectMarkerRulerAction; 28 29 public class PDESelectAnnotationRulerAction extends SelectMarkerRulerAction { 30 31 private boolean fIsEditable; 32 private ITextEditor fTextEditor; 33 private Position fPosition; 34 private ResourceBundle fBundle; 35 private String fPrefix; 36 37 public PDESelectAnnotationRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo ruler) { 38 super(bundle, prefix, editor, ruler); 39 fTextEditor = editor; 40 fBundle = bundle; 41 fPrefix = prefix; 42 } 43 44 public void run() { 45 runWithEvent(null); 46 } 47 48 52 public void runWithEvent(Event event) { 53 if (fIsEditable) { 54 ITextOperationTarget operation = (ITextOperationTarget) fTextEditor.getAdapter(ITextOperationTarget.class); 55 final int opCode= ISourceViewer.QUICK_ASSIST; 56 if (operation != null && operation.canDoOperation(opCode)) { 57 fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength()); 58 operation.doOperation(opCode); 59 } 60 return; 61 } 62 63 super.run(); 64 } 65 66 public void update() { 67 checkReadOnly(); 68 69 if (fIsEditable) { 70 initialize(fBundle, fPrefix + "QuickFix."); } 72 73 super.update(); 74 } 75 76 private void checkReadOnly() { 77 fPosition = null; 78 fIsEditable = false; 79 80 AbstractMarkerAnnotationModel model = getAnnotationModel(); 81 IAnnotationAccessExtension annotationAccess = getAnnotationAccessExtension(); 82 83 IDocument document= getDocument(); 84 if (model == null) 85 return; 86 87 Iterator iter = model.getAnnotationIterator(); 88 int layer = Integer.MIN_VALUE; 89 90 while (iter.hasNext()) { 91 Annotation annotation= (Annotation) iter.next(); 92 if (annotation.isMarkedDeleted()) 93 continue; 94 95 int annotationLayer = annotationAccess.getLayer(annotation); 96 if (annotationAccess != null) 97 if (annotationLayer < layer) 98 continue; 99 100 Position position = model.getPosition(annotation); 101 if (!includesRulerLine(position, document)) 102 continue; 103 104 boolean isReadOnly = fTextEditor instanceof ITextEditorExtension && ((ITextEditorExtension)fTextEditor).isEditorInputReadOnly(); 105 if (!isReadOnly) { 106 fPosition = position; 107 fIsEditable = true; 108 layer = annotationLayer; 109 continue; 110 } 111 } 112 } 113 } 114 | Popular Tags |