1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
13 import java.util.Iterator;
14 import java.util.ResourceBundle;
16 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
18 import org.eclipse.jface.text.IDocument;
19 import org.eclipse.jface.text.ITextOperationTarget;
20 import org.eclipse.jface.text.Position;
21 import org.eclipse.jface.text.source.Annotation;
22 import org.eclipse.jface.text.source.IVerticalRulerInfo;
23 import org.eclipse.ui.help.WorkbenchHelp;
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;
30 * A special select marker ruler action which activates quick fix if clicked on a quick fixable problem.
32 public class JavaSelectMarkerRulerAction extends SelectMarkerRulerAction {
34 private ITextEditor fMyTextEditor;
35 private Position fPosition;
37 public JavaSelectMarkerRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo ruler) {
38 super(bundle, prefix, editor, ruler);
39 fMyTextEditor= editor;
40 WorkbenchHelp.setHelp(this, IJavaHelpContextIds.JAVA_SELECT_MARKER_RULER_ACTION);
45 if (fPosition == null)
47 ITextOperationTarget operation= (ITextOperationTarget) fMyTextEditor.getAdapter(ITextOperationTarget.class);
48 // final int opCode= CompilationUnitEditor.CORRECTIONASSIST_PROPOSALS;
49 if (operation == null ) { //|| !operation.canDoOperation(opCode)) {
52 fMyTextEditor.selectAndReveal(fPosition.getOffset(), 0);
53 // operation.doOperation(opCode);
59 public void update() {
60 // Begin Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
61 if (!(fMyTextEditor instanceof ITextEditorExtension) || ((ITextEditorExtension) fMyTextEditor).isEditorInputReadOnly()) {
66 // End Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
67 fPosition= getJavaAnnotationPosition();
68 if (fPosition != null)
74 private Position getJavaAnnotationPosition() {
75 AbstractMarkerAnnotationModel model= getAnnotationModel();
76 IDocument document= getDocument();
79 Iterator iter= model.getAnnotationIterator();
80 while (iter.hasNext()) {
81 Annotation annotation= (Annotation) iter.next();
82 if (annotation instanceof IJavaAnnotation) {
83 IJavaAnnotation javaAnnotation= (IJavaAnnotation)annotation;
84 if (javaAnnotation.isRelevant()) {
85 Position position= model.getPosition(annotation);
86 // if (includesRulerLine(position, document) && JavaCorrectionProcessor.hasCorrections(javaAnnotation))