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