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.core.ICompilationUnit;
17 import net.sourceforge.phpdt.core.IJavaElement;
18 import net.sourceforge.phpdt.core.JavaCore;
19 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
21 import org.eclipse.core.resources.IFile;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.text.ITextOperationTarget;
24 import org.eclipse.jface.text.Position;
25 import org.eclipse.jface.text.source.Annotation;
26 import org.eclipse.jface.text.source.IVerticalRulerInfo;
27 import org.eclipse.ui.IEditorInput;
28 import org.eclipse.ui.IFileEditorInput;
29 import org.eclipse.ui.PlatformUI;
30 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
31 import org.eclipse.ui.texteditor.ITextEditor;
32 import org.eclipse.ui.texteditor.ITextEditorExtension;
33 import org.eclipse.ui.texteditor.SelectMarkerRulerAction;
36 * A special select marker ruler action which activates quick fix if clicked on
37 * a quick fixable problem.
39 public class JavaSelectMarkerRulerAction extends SelectMarkerRulerAction {
41 private ITextEditor fTextEditor;
43 private Position fPosition;
45 public JavaSelectMarkerRulerAction(ResourceBundle bundle, String prefix,
46 ITextEditor editor, IVerticalRulerInfo ruler) {
47 super(bundle, prefix, editor, ruler);
49 PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
50 IJavaHelpContextIds.JAVA_SELECT_MARKER_RULER_ACTION);
55 // (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
58 if (fPosition != null) {
59 ITextOperationTarget operation = (ITextOperationTarget) fTextEditor
60 .getAdapter(ITextOperationTarget.class);
61 // final int opCode= PHPUnitEditor.CORRECTIONASSIST_PROPOSALS;
62 // if (operation != null && operation.canDoOperation(opCode)) {
63 // fTextEditor.selectAndReveal(fPosition.getOffset(),
64 // fPosition.getLength());
65 // operation.doOperation(opCode);
73 public void update() {
74 // Begin Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
75 if (!(fTextEditor instanceof ITextEditorExtension)
76 || ((ITextEditorExtension) fTextEditor).isEditorInputReadOnly()) {
81 // End Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
82 fPosition = getJavaAnnotationPosition();
83 if (fPosition != null)
89 private Position getJavaAnnotationPosition() {
90 AbstractMarkerAnnotationModel model = getAnnotationModel();
91 IDocument document = getDocument();
94 ICompilationUnit cu = getCompilationUnit();
99 // boolean hasAssistLightbulb=
100 // PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.APPEARANCE_QUICKASSIST_LIGHTBULB);
101 Annotation assistAnnotation = null;
103 Iterator iter = model.getAnnotationIterator();
104 while (iter.hasNext()) {
105 Annotation annotation = (Annotation) iter.next();
106 if (annotation instanceof IJavaAnnotation) {
107 IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
108 if (!javaAnnotation.isMarkedDeleted()) {
109 Position position = model.getPosition(annotation);
110 // if (includesRulerLine(position, document) &&
111 // JavaCorrectionProcessor.hasCorrections(javaAnnotation))
115 // else if (hasAssistLightbulb && annotation instanceof
116 // AssistAnnotation) {
117 // // there is only one AssistAnnotation at a time
118 // assistAnnotation= annotation;
121 if (assistAnnotation != null) {
122 Position position = model.getPosition(assistAnnotation);
123 // no need to check 'JavaCorrectionProcessor.hasAssists': annotation
126 if (includesRulerLine(position, document))
132 private ICompilationUnit getCompilationUnit() {
133 IEditorInput input = fTextEditor.getEditorInput();
134 if (input instanceof IFileEditorInput) {
135 IFile file = ((IFileEditorInput) input).getFile();
136 IJavaElement element = JavaCore.create(file);
137 if (element instanceof ICompilationUnit)
138 return (ICompilationUnit) element;