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