1abf58d17da30a2ab7604d328bc624a78a7b54c0
[phpeclipse.git] /
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.ResourceBundle;
14
15 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
16
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.text.ITextOperationTarget;
19 import org.eclipse.jface.text.Position;
20 import org.eclipse.jface.text.source.Annotation;
21 import org.eclipse.jface.text.source.IAnnotationModel;
22 import org.eclipse.jface.text.source.VerticalRulerEvent;
23 import org.eclipse.ui.ISelectionListener;
24 import org.eclipse.ui.help.WorkbenchHelp;
25 import org.eclipse.ui.texteditor.ITextEditor;
26 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
27 import org.eclipse.ui.texteditor.IUpdate;
28 import org.eclipse.ui.texteditor.SelectAnnotationRulerAction;
29
30 //import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
31 //import org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor;
32 //import org.eclipse.jdt.internal.ui.text.correction.QuickAssistLightBulbUpdater.AssistAnnotation;
33 //import org.eclipse.jdt.internal.ui.text.java.hover.JavaExpandHover;
34
35 /**
36  * A special select marker ruler action which activates quick fix if clicked on a quick fixable problem.
37  */
38 public class JavaSelectMarkerRulerAction2 extends SelectAnnotationRulerAction {
39
40         public JavaSelectMarkerRulerAction2(ResourceBundle bundle, String prefix, ITextEditor editor) {
41                 super(bundle, prefix, editor);
42                 WorkbenchHelp.setHelp(this, IJavaHelpContextIds.JAVA_SELECT_MARKER_RULER_ACTION);
43         }
44         
45         /*
46          * @see org.eclipse.ui.texteditor.IVerticalRulerListener#annotationDefaultSelected(org.eclipse.ui.texteditor.VerticalRulerEvent)
47          */
48         public void annotationDefaultSelected(VerticalRulerEvent event) {
49                 Annotation annotation= event.getSelectedAnnotation();
50                 IAnnotationModel model= getAnnotationModel();
51                 
52 //              if (isOverrideIndicator(annotation)) {
53 //                      ((OverrideIndicatorManager.OverrideIndicator)annotation).open();
54 //                      return;
55 //              }
56                 
57                 if (isBreakpoint(annotation))
58                         triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK);
59                 
60                 Position position= model.getPosition(annotation);
61                 if (position == null)
62                         return;
63                 
64 //              if (isQuickFixTarget(annotation)) {
65 //                      ITextOperationTarget operation= (ITextOperationTarget) getTextEditor().getAdapter(ITextOperationTarget.class);
66 //                      final int opCode= PHPUnitEditor.CORRECTIONASSIST_PROPOSALS;
67 //                      if (operation != null && operation.canDoOperation(opCode)) {
68 //                              getTextEditor().selectAndReveal(position.getOffset(), position.getLength());
69 //                              operation.doOperation(opCode);
70 //                              return;
71 //                      }
72 //              }
73                 
74                 // default:
75                 super.annotationDefaultSelected(event);
76         }
77
78         /**
79          * Tells whether the given annotation is an override annotation.
80          *
81          * @param annotation the annotation
82          * @return <code>true</code> iff the annotation is an override annotation
83          */
84         private boolean isOverrideIndicator(Annotation annotation) {
85                 return false; //annotation instanceof OverrideIndicatorManager.OverrideIndicator;
86         }
87
88         /**
89          * @param annotation
90          * @return
91          */
92         private boolean isBreakpoint(Annotation annotation) {
93                 return annotation.getType().equals("org.eclipse.debug.core.breakpoint"); 
94                 //|| annotation.getType().equals(JavaExpandHover.NO_BREAKPOINT_ANNOTATION); //$NON-NLS-1$
95                 
96         }
97
98         private boolean isQuickFixTarget(Annotation a) {
99                 return false; //JavaCorrectionProcessor.hasCorrections(a) || a instanceof AssistAnnotation;
100         }
101
102         private void triggerAction(String actionID) {
103                 IAction action= getTextEditor().getAction(actionID);
104                 if (action != null) {
105                         if (action instanceof IUpdate)
106                                 ((IUpdate) action).update();
107                         // hack to propagate line change
108                         if (action instanceof ISelectionListener) {
109                                 ((ISelectionListener)action).selectionChanged(null, null);
110                         }
111                         if (action.isEnabled())
112                                 action.run();
113                 }
114         }
115
116 }