1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 import java.util.ResourceBundle ; 14 15 import org.eclipse.jface.action.IAction; 16 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.IAnnotationModel; 21 import org.eclipse.jface.text.source.ISourceViewer; 22 import org.eclipse.jface.text.source.VerticalRulerEvent; 23 24 import org.eclipse.ui.ISelectionListener; 25 import org.eclipse.ui.PlatformUI; 26 import org.eclipse.ui.texteditor.ITextEditor; 27 import org.eclipse.ui.texteditor.ITextEditorActionConstants; 28 import org.eclipse.ui.texteditor.IUpdate; 29 import org.eclipse.ui.texteditor.SelectAnnotationRulerAction; 30 31 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 32 import org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor; 33 import org.eclipse.jdt.internal.ui.text.correction.QuickAssistLightBulbUpdater.AssistAnnotation; 34 import org.eclipse.jdt.internal.ui.text.java.hover.JavaExpandHover; 35 36 39 public class JavaSelectMarkerRulerAction2 extends SelectAnnotationRulerAction { 40 41 public JavaSelectMarkerRulerAction2(ResourceBundle bundle, String prefix, ITextEditor editor) { 42 super(bundle, prefix, editor); 43 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.JAVA_SELECT_MARKER_RULER_ACTION); 44 } 45 46 49 public void annotationDefaultSelected(VerticalRulerEvent event) { 50 Annotation annotation= event.getSelectedAnnotation(); 51 IAnnotationModel model= getAnnotationModel(); 52 53 if (isOverrideIndicator(annotation)) { 54 ((OverrideIndicatorManager.OverrideIndicator)annotation).open(); 55 return; 56 } 57 58 if (isBreakpoint(annotation)) 59 triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK); 60 61 Position position= model.getPosition(annotation); 62 if (position == null) 63 return; 64 65 if (isQuickFixTarget(annotation)) { 66 ITextOperationTarget operation= (ITextOperationTarget) getTextEditor().getAdapter(ITextOperationTarget.class); 67 final int opCode= ISourceViewer.QUICK_ASSIST; 68 if (operation != null && operation.canDoOperation(opCode)) { 69 getTextEditor().selectAndReveal(position.getOffset(), position.getLength()); 70 operation.doOperation(opCode); 71 return; 72 } 73 } 74 75 super.annotationDefaultSelected(event); 77 } 78 79 85 private boolean isOverrideIndicator(Annotation annotation) { 86 return annotation instanceof OverrideIndicatorManager.OverrideIndicator; 87 } 88 89 95 private boolean isBreakpoint(Annotation annotation) { 96 return annotation.getType().equals("org.eclipse.debug.core.breakpoint") || annotation.getType().equals(JavaExpandHover.NO_BREAKPOINT_ANNOTATION); } 98 99 private boolean isQuickFixTarget(Annotation a) { 100 return JavaCorrectionProcessor.hasCorrections(a) || a instanceof AssistAnnotation; 101 } 102 103 private void triggerAction(String actionID) { 104 IAction action= getTextEditor().getAction(actionID); 105 if (action != null) { 106 if (action instanceof IUpdate) 107 ((IUpdate) action).update(); 108 if (action instanceof ISelectionListener) { 110 ((ISelectionListener)action).selectionChanged(null, null); 111 } 112 if (action.isEnabled()) 113 action.run(); 114 } 115 } 116 117 } 118 119 | Popular Tags |