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