new version with WorkingCopy Management
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / JavaSelectMarkerRulerAction.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
12
13 import java.util.Iterator;
14 import java.util.ResourceBundle;
15
16 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
17
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;
28
29 /**
30  * A special select marker ruler action which activates quick fix if clicked on a quick fixable problem.
31  */
32 public class JavaSelectMarkerRulerAction extends SelectMarkerRulerAction {
33
34         private ITextEditor fMyTextEditor;
35         private Position fPosition;
36
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);
41         }
42         
43         public void run() {
44                 superCall: {
45                         if (fPosition == null)
46                                 break superCall;
47                         ITextOperationTarget operation= (ITextOperationTarget) fMyTextEditor.getAdapter(ITextOperationTarget.class);
48 //                      final int opCode= CompilationUnitEditor.CORRECTIONASSIST_PROPOSALS;
49                         if (operation == null ) { //|| !operation.canDoOperation(opCode)) {
50                                 break superCall;
51                         }
52                         fMyTextEditor.selectAndReveal(fPosition.getOffset(), 0);
53 //                      operation.doOperation(opCode);
54                         return;
55                 }
56                 super.run();
57         }
58         
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()) {
62                         fPosition= null;
63                         super.update();
64                         return;
65                 }
66                 // End Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114
67                 fPosition= getJavaAnnotationPosition();
68                 if (fPosition != null)
69                         setEnabled(true);
70                 else
71                         super.update();
72         }
73         
74         private Position getJavaAnnotationPosition() {
75                 AbstractMarkerAnnotationModel model= getAnnotationModel();
76                 IDocument document= getDocument();
77                 if (model == null)
78                         return null;
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))
87 //                                              return position;
88                                 }
89                         }
90                 }
91                 return null;
92         }
93 }
94