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;
20 import net.sourceforge.phpdt.ui.PreferenceConstants;
21 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
23 import org.eclipse.core.resources.IFile;
24 import org.eclipse.jface.text.IDocument;
25 import org.eclipse.jface.text.ITextOperationTarget;
26 import org.eclipse.jface.text.Position;
27 import org.eclipse.jface.text.source.Annotation;
28 import org.eclipse.jface.text.source.IVerticalRulerInfo;
29 import org.eclipse.ui.IEditorInput;
30 import org.eclipse.ui.IFileEditorInput;
31 import org.eclipse.ui.help.WorkbenchHelp;
32 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
33 import org.eclipse.ui.texteditor.ITextEditor;
34 import org.eclipse.ui.texteditor.ITextEditorExtension;
35 import org.eclipse.ui.texteditor.SelectMarkerRulerAction;
39 * A special select marker ruler action which activates quick fix if clicked on a quick fixable problem.
41 public class JavaSelectMarkerRulerAction extends SelectMarkerRulerAction {
43 private ITextEditor fTextEditor;
44 private Position fPosition;
46 public JavaSelectMarkerRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo ruler) {
47 super(bundle, prefix, editor, ruler);
49 WorkbenchHelp.setHelp(this, IJavaHelpContextIds.JAVA_SELECT_MARKER_RULER_ACTION);
53 // if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
56 if (fPosition != null) {
57 ITextOperationTarget operation= (ITextOperationTarget) fTextEditor.getAdapter(ITextOperationTarget.class);
58 // final int opCode= PHPUnitEditor.CORRECTIONASSIST_PROPOSALS;
59 // if (operation != null && operation.canDoOperation(opCode)) {
60 // fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength());
61 // operation.doOperation(opCode);
69 public void update() {
70 // Begin Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
71 if (!(fTextEditor instanceof ITextEditorExtension) || ((ITextEditorExtension) fTextEditor).isEditorInputReadOnly()) {
76 // End Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
77 fPosition= getJavaAnnotationPosition();
78 if (fPosition != null)
84 private Position getJavaAnnotationPosition() {
85 AbstractMarkerAnnotationModel model= getAnnotationModel();
86 IDocument document= getDocument();
89 ICompilationUnit cu= getCompilationUnit();
94 // boolean hasAssistLightbulb= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.APPEARANCE_QUICKASSIST_LIGHTBULB);
95 Annotation assistAnnotation= null;
97 Iterator iter= model.getAnnotationIterator();
98 while (iter.hasNext()) {
99 Annotation annotation= (Annotation) iter.next();
100 if (annotation instanceof IJavaAnnotation) {
101 IJavaAnnotation javaAnnotation= (IJavaAnnotation)annotation;
102 if (!javaAnnotation.isMarkedDeleted()) {
103 Position position= model.getPosition(annotation);
104 // if (includesRulerLine(position, document) && JavaCorrectionProcessor.hasCorrections(javaAnnotation))
108 // else if (hasAssistLightbulb && annotation instanceof AssistAnnotation) {
109 // // there is only one AssistAnnotation at a time
110 // assistAnnotation= annotation;
113 if (assistAnnotation != null) {
114 Position position= model.getPosition(assistAnnotation);
115 // no need to check 'JavaCorrectionProcessor.hasAssists': annotation only created when
117 if (includesRulerLine(position, document))
123 private ICompilationUnit getCompilationUnit() {
124 IEditorInput input= fTextEditor.getEditorInput();
125 if (input instanceof IFileEditorInput) {
126 IFile file= ((IFileEditorInput) input).getFile();
127 IJavaElement element= JavaCore.create(file);
128 if (element instanceof ICompilationUnit)
129 return (ICompilationUnit) element;