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.help.WorkbenchHelp;
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;
37 * A special select marker ruler action which activates quick fix if clicked on a quick fixable problem.
39 public class JavaSelectMarkerRulerAction extends SelectMarkerRulerAction {
41 private ITextEditor fTextEditor;
42 private Position fPosition;
44 public JavaSelectMarkerRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo ruler) {
45 super(bundle, prefix, editor, ruler);
47 WorkbenchHelp.setHelp(this, IJavaHelpContextIds.JAVA_SELECT_MARKER_RULER_ACTION);
51 // if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
54 if (fPosition != null) {
55 ITextOperationTarget operation= (ITextOperationTarget) fTextEditor.getAdapter(ITextOperationTarget.class);
56 // final int opCode= PHPUnitEditor.CORRECTIONASSIST_PROPOSALS;
57 // if (operation != null && operation.canDoOperation(opCode)) {
58 // fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength());
59 // operation.doOperation(opCode);
67 public void update() {
68 // Begin Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
69 if (!(fTextEditor instanceof ITextEditorExtension) || ((ITextEditorExtension) fTextEditor).isEditorInputReadOnly()) {
74 // End Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
75 fPosition= getJavaAnnotationPosition();
76 if (fPosition != null)
82 private Position getJavaAnnotationPosition() {
83 AbstractMarkerAnnotationModel model= getAnnotationModel();
84 IDocument document= getDocument();
87 ICompilationUnit cu= getCompilationUnit();
92 // boolean hasAssistLightbulb= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.APPEARANCE_QUICKASSIST_LIGHTBULB);
93 Annotation assistAnnotation= null;
95 Iterator iter= model.getAnnotationIterator();
96 while (iter.hasNext()) {
97 Annotation annotation= (Annotation) iter.next();
98 if (annotation instanceof IJavaAnnotation) {
99 IJavaAnnotation javaAnnotation= (IJavaAnnotation)annotation;
100 if (!javaAnnotation.isMarkedDeleted()) {
101 Position position= model.getPosition(annotation);
102 // if (includesRulerLine(position, document) && JavaCorrectionProcessor.hasCorrections(javaAnnotation))
106 // else if (hasAssistLightbulb && annotation instanceof AssistAnnotation) {
107 // // there is only one AssistAnnotation at a time
108 // assistAnnotation= annotation;
111 if (assistAnnotation != null) {
112 Position position= model.getPosition(assistAnnotation);
113 // no need to check 'JavaCorrectionProcessor.hasAssists': annotation only created when
115 if (includesRulerLine(position, document))
121 private ICompilationUnit getCompilationUnit() {
122 IEditorInput input= fTextEditor.getEditorInput();
123 if (input instanceof IFileEditorInput) {
124 IFile file= ((IFileEditorInput) input).getFile();
125 IJavaElement element= JavaCore.create(file);
126 if (element instanceof ICompilationUnit)
127 return (ICompilationUnit) element;