Organized imports.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPEditor.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 /**********************************************************************
4  Copyright (c) 2000, 2002 IBM Corp. and others.
5  All rights reserved. This program and the accompanying materials
6  are made available under the terms of the Common Public License v1.0
7  which accompanies this distribution, and is available at
8  http://www.eclipse.org/legal/cpl-v10.html
9
10  Contributors:
11  IBM Corporation - Initial implementation
12  www.phpeclipse.de
13  **********************************************************************/
14 import java.lang.reflect.InvocationTargetException;
15 import java.lang.reflect.Method;
16 import java.text.BreakIterator;
17 import java.text.CharacterIterator;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.ResourceBundle;
24 import java.util.StringTokenizer;
25
26 import net.sourceforge.phpdt.core.ICompilationUnit;
27 import net.sourceforge.phpdt.core.IImportContainer;
28 import net.sourceforge.phpdt.core.IImportDeclaration;
29 import net.sourceforge.phpdt.core.IJavaElement;
30 import net.sourceforge.phpdt.core.IJavaProject;
31 import net.sourceforge.phpdt.core.IMember;
32 import net.sourceforge.phpdt.core.ISourceRange;
33 import net.sourceforge.phpdt.core.ISourceReference;
34 import net.sourceforge.phpdt.core.JavaCore;
35 import net.sourceforge.phpdt.core.JavaModelException;
36 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
37 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
38 import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
39 import net.sourceforge.phpdt.internal.ui.actions.SelectionConverter;
40 import net.sourceforge.phpdt.internal.ui.text.CustomSourceInformationControl;
41 import net.sourceforge.phpdt.internal.ui.text.DocumentCharacterIterator;
42 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
43 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
44 import net.sourceforge.phpdt.internal.ui.text.JavaWordIterator;
45 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
46 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
47 import net.sourceforge.phpdt.internal.ui.text.java.JavaExpandHover;
48 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
49 import net.sourceforge.phpdt.ui.IContextMenuConstants;
50 import net.sourceforge.phpdt.ui.JavaUI;
51 import net.sourceforge.phpdt.ui.PreferenceConstants;
52 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
53 import net.sourceforge.phpdt.ui.actions.OpenEditorActionGroup;
54 import net.sourceforge.phpdt.ui.text.JavaTextTools;
55 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
56 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
57 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
58
59 import org.eclipse.core.resources.IMarker;
60 import org.eclipse.core.resources.IResource;
61 import org.eclipse.core.runtime.CoreException;
62 import org.eclipse.core.runtime.IProgressMonitor;
63 import org.eclipse.core.runtime.IStatus;
64 import org.eclipse.core.runtime.Preferences;
65 import org.eclipse.core.runtime.Status;
66 import org.eclipse.core.runtime.jobs.Job;
67 import org.eclipse.jface.action.Action;
68 import org.eclipse.jface.action.GroupMarker;
69 import org.eclipse.jface.action.IAction;
70 import org.eclipse.jface.action.MenuManager;
71 import org.eclipse.jface.action.Separator;
72 import org.eclipse.jface.preference.IPreferenceStore;
73 import org.eclipse.jface.preference.PreferenceConverter;
74 import org.eclipse.jface.text.BadLocationException;
75 import org.eclipse.jface.text.DefaultInformationControl;
76 import org.eclipse.jface.text.DocumentEvent;
77 import org.eclipse.jface.text.IDocument;
78 import org.eclipse.jface.text.IDocumentListener;
79 import org.eclipse.jface.text.IInformationControl;
80 import org.eclipse.jface.text.IInformationControlCreator;
81 import org.eclipse.jface.text.IRegion;
82 import org.eclipse.jface.text.ISynchronizable;
83 import org.eclipse.jface.text.ITextHover;
84 import org.eclipse.jface.text.ITextInputListener;
85 import org.eclipse.jface.text.ITextPresentationListener;
86 import org.eclipse.jface.text.ITextSelection;
87 import org.eclipse.jface.text.ITextViewer;
88 import org.eclipse.jface.text.ITextViewerExtension2;
89 import org.eclipse.jface.text.ITextViewerExtension3;
90 import org.eclipse.jface.text.ITextViewerExtension4;
91 import org.eclipse.jface.text.ITextViewerExtension5;
92 import org.eclipse.jface.text.ITypedRegion;
93 import org.eclipse.jface.text.Position;
94 import org.eclipse.jface.text.Region;
95 import org.eclipse.jface.text.TextPresentation;
96 import org.eclipse.jface.text.TextSelection;
97 import org.eclipse.jface.text.TextUtilities;
98 import org.eclipse.jface.text.information.IInformationProvider;
99 import org.eclipse.jface.text.information.InformationPresenter;
100 import org.eclipse.jface.text.reconciler.IReconciler;
101 import org.eclipse.jface.text.source.Annotation;
102 import org.eclipse.jface.text.source.AnnotationRulerColumn;
103 import org.eclipse.jface.text.source.CompositeRuler;
104 import org.eclipse.jface.text.source.IAnnotationModel;
105 import org.eclipse.jface.text.source.IAnnotationModelExtension;
106 import org.eclipse.jface.text.source.IOverviewRuler;
107 import org.eclipse.jface.text.source.ISourceViewer;
108 import org.eclipse.jface.text.source.ISourceViewerExtension2;
109 import org.eclipse.jface.text.source.IVerticalRuler;
110 import org.eclipse.jface.text.source.OverviewRuler;
111 import org.eclipse.jface.text.source.SourceViewerConfiguration;
112 import org.eclipse.jface.text.source.projection.ProjectionSupport;
113 import org.eclipse.jface.text.source.projection.ProjectionViewer;
114 import org.eclipse.jface.util.IPropertyChangeListener;
115 import org.eclipse.jface.util.ListenerList;
116 import org.eclipse.jface.util.PropertyChangeEvent;
117 import org.eclipse.jface.viewers.DoubleClickEvent;
118 import org.eclipse.jface.viewers.IDoubleClickListener;
119 import org.eclipse.jface.viewers.IPostSelectionProvider;
120 import org.eclipse.jface.viewers.ISelection;
121 import org.eclipse.jface.viewers.ISelectionChangedListener;
122 import org.eclipse.jface.viewers.ISelectionProvider;
123 import org.eclipse.jface.viewers.IStructuredSelection;
124 import org.eclipse.jface.viewers.SelectionChangedEvent;
125 import org.eclipse.jface.viewers.StructuredSelection;
126 import org.eclipse.swt.SWT;
127 import org.eclipse.swt.custom.BidiSegmentEvent;
128 import org.eclipse.swt.custom.BidiSegmentListener;
129 import org.eclipse.swt.custom.ST;
130 import org.eclipse.swt.custom.StyleRange;
131 import org.eclipse.swt.custom.StyledText;
132 import org.eclipse.swt.events.FocusEvent;
133 import org.eclipse.swt.events.FocusListener;
134 import org.eclipse.swt.events.KeyEvent;
135 import org.eclipse.swt.events.KeyListener;
136 import org.eclipse.swt.events.MouseEvent;
137 import org.eclipse.swt.events.MouseListener;
138 import org.eclipse.swt.events.MouseMoveListener;
139 import org.eclipse.swt.events.PaintEvent;
140 import org.eclipse.swt.events.PaintListener;
141 import org.eclipse.swt.graphics.Color;
142 import org.eclipse.swt.graphics.Cursor;
143 import org.eclipse.swt.graphics.GC;
144 import org.eclipse.swt.graphics.Image;
145 import org.eclipse.swt.graphics.Point;
146 import org.eclipse.swt.graphics.RGB;
147 import org.eclipse.swt.widgets.Composite;
148 import org.eclipse.swt.widgets.Control;
149 import org.eclipse.swt.widgets.Display;
150 import org.eclipse.swt.widgets.Shell;
151 import org.eclipse.ui.IEditorInput;
152 import org.eclipse.ui.IPageLayout;
153 import org.eclipse.ui.IPartService;
154 import org.eclipse.ui.ISelectionListener;
155 import org.eclipse.ui.IViewPart;
156 import org.eclipse.ui.IWorkbenchPage;
157 import org.eclipse.ui.IWorkbenchPart;
158 import org.eclipse.ui.IWorkbenchWindow;
159 import org.eclipse.ui.actions.ActionContext;
160 import org.eclipse.ui.actions.ActionGroup;
161 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
162 import org.eclipse.ui.editors.text.EditorsUI;
163 import org.eclipse.ui.editors.text.IEncodingSupport;
164 import org.eclipse.ui.part.IShowInTargetList;
165 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
166 import org.eclipse.ui.texteditor.AnnotationPreference;
167 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
168 import org.eclipse.ui.texteditor.IDocumentProvider;
169 import org.eclipse.ui.texteditor.IEditorStatusLine;
170 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
171 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
172 import org.eclipse.ui.texteditor.IUpdate;
173 import org.eclipse.ui.texteditor.MarkerAnnotation;
174 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
175 import org.eclipse.ui.texteditor.TextEditorAction;
176 import org.eclipse.ui.texteditor.TextNavigationAction;
177 import org.eclipse.ui.texteditor.TextOperationAction;
178 import org.eclipse.ui.views.contentoutline.ContentOutline;
179 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
180 import org.eclipse.ui.views.tasklist.TaskList;
181
182 /**
183  * PHP specific text editor.
184  */
185 public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider {
186   //extends StatusTextEditor implements IViewPartInputProvider { // extends
187   // TextEditor {
188
189   /**
190    * Internal implementation class for a change listener.
191    * 
192    * @since 3.0
193    */
194   protected abstract class AbstractSelectionChangedListener implements ISelectionChangedListener {
195
196     /**
197      * Installs this selection changed listener with the given selection provider. If the selection provider is a post selection
198      * provider, post selection changed events are the preferred choice, otherwise normal selection changed events are requested.
199      * 
200      * @param selectionProvider
201      */
202     public void install(ISelectionProvider selectionProvider) {
203       if (selectionProvider == null)
204         return;
205
206       if (selectionProvider instanceof IPostSelectionProvider) {
207         IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
208         provider.addPostSelectionChangedListener(this);
209       } else {
210         selectionProvider.addSelectionChangedListener(this);
211       }
212     }
213
214     /**
215      * Removes this selection changed listener from the given selection provider.
216      * 
217      * @param selectionProvider
218      *          the selection provider
219      */
220     public void uninstall(ISelectionProvider selectionProvider) {
221       if (selectionProvider == null)
222         return;
223
224       if (selectionProvider instanceof IPostSelectionProvider) {
225         IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
226         provider.removePostSelectionChangedListener(this);
227       } else {
228         selectionProvider.removeSelectionChangedListener(this);
229       }
230     }
231   }
232
233   /**
234    * Updates the Java outline page selection and this editor's range indicator.
235    * 
236    * @since 3.0
237    */
238   private class EditorSelectionChangedListener extends AbstractSelectionChangedListener {
239
240     /*
241      * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
242      */
243     public void selectionChanged(SelectionChangedEvent event) {
244       // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161
245       PHPEditor.this.selectionChanged();
246     }
247   }
248
249   /**
250    * "Smart" runnable for updating the outline page's selection.
251    */
252   //  class OutlinePageSelectionUpdater implements Runnable {
253   //
254   //    /** Has the runnable already been posted? */
255   //    private boolean fPosted = false;
256   //
257   //    public OutlinePageSelectionUpdater() {
258   //    }
259   //
260   //    /*
261   //     * @see Runnable#run()
262   //     */
263   //    public void run() {
264   //      synchronizeOutlinePageSelection();
265   //      fPosted = false;
266   //    }
267   //
268   //    /**
269   //     * Posts this runnable into the event queue.
270   //     */
271   //    public void post() {
272   //      if (fPosted)
273   //        return;
274   //
275   //      Shell shell = getSite().getShell();
276   //      if (shell != null & !shell.isDisposed()) {
277   //        fPosted = true;
278   //        shell.getDisplay().asyncExec(this);
279   //      }
280   //    }
281   //  };
282   class SelectionChangedListener implements ISelectionChangedListener {
283     public void selectionChanged(SelectionChangedEvent event) {
284       doSelectionChanged(event);
285     }
286   };
287
288   /**
289    * Adapts an options {@link java.util.Map}to {@link org.eclipse.jface.preference.IPreferenceStore}.
290    * <p>
291    * This preference store is read-only i.e. write access throws an {@link java.lang.UnsupportedOperationException}.
292    * </p>
293    * 
294    * @since 3.0
295    */
296   private static class OptionsAdapter implements IPreferenceStore {
297
298     /**
299      * A property change event filter.
300      */
301     public interface IPropertyChangeEventFilter {
302
303       /**
304        * Should the given event be filtered?
305        * 
306        * @param event
307        *          The property change event.
308        * @return <code>true</code> iff the given event should be filtered.
309        */
310       public boolean isFiltered(PropertyChangeEvent event);
311
312     }
313
314     /**
315      * Property change listener. Listens for events in the options Map and fires a
316      * {@link org.eclipse.jface.util.PropertyChangeEvent}on this adapter with arguments from the received event.
317      */
318     private class PropertyChangeListener implements IPropertyChangeListener {
319
320       /**
321        * {@inheritDoc}
322        */
323       public void propertyChange(PropertyChangeEvent event) {
324         if (getFilter().isFiltered(event))
325           return;
326
327         if (event.getNewValue() == null)
328           fOptions.remove(event.getProperty());
329         else
330           fOptions.put(event.getProperty(), event.getNewValue());
331
332         firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
333       }
334     }
335
336     /** Listeners on this adapter */
337     private ListenerList fListeners = new ListenerList();
338
339     /** Listener on the adapted options Map */
340     private IPropertyChangeListener fListener = new PropertyChangeListener();
341
342     /** Adapted options Map */
343     private Map fOptions;
344
345     /** Preference store through which events are received. */
346     private IPreferenceStore fMockupPreferenceStore;
347
348     /** Property event filter. */
349     private IPropertyChangeEventFilter fFilter;
350
351     /**
352      * Initialize with the given options.
353      * 
354      * @param options
355      *          The options to wrap
356      * @param mockupPreferenceStore
357      *          the mock-up preference store
358      * @param filter
359      *          the property change filter
360      */
361     public OptionsAdapter(Map options, IPreferenceStore mockupPreferenceStore, IPropertyChangeEventFilter filter) {
362       fMockupPreferenceStore = mockupPreferenceStore;
363       fOptions = options;
364       setFilter(filter);
365     }
366
367     /**
368      * {@inheritDoc}
369      */
370     public void addPropertyChangeListener(IPropertyChangeListener listener) {
371       if (fListeners.size() == 0)
372         fMockupPreferenceStore.addPropertyChangeListener(fListener);
373       fListeners.add(listener);
374     }
375
376     /**
377      * {@inheritDoc}
378      */
379     public void removePropertyChangeListener(IPropertyChangeListener listener) {
380       fListeners.remove(listener);
381       if (fListeners.size() == 0)
382         fMockupPreferenceStore.removePropertyChangeListener(fListener);
383     }
384
385     /**
386      * {@inheritDoc}
387      */
388     public boolean contains(String name) {
389       return fOptions.containsKey(name);
390     }
391
392     /**
393      * {@inheritDoc}
394      */
395     public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
396       PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
397       Object[] listeners = fListeners.getListeners();
398       for (int i = 0; i < listeners.length; i++)
399         ((IPropertyChangeListener) listeners[i]).propertyChange(event);
400     }
401
402     /**
403      * {@inheritDoc}
404      */
405     public boolean getBoolean(String name) {
406       boolean value = BOOLEAN_DEFAULT_DEFAULT;
407       String s = (String) fOptions.get(name);
408       if (s != null)
409         value = s.equals(TRUE);
410       return value;
411     }
412
413     /**
414      * {@inheritDoc}
415      */
416     public boolean getDefaultBoolean(String name) {
417       return BOOLEAN_DEFAULT_DEFAULT;
418     }
419
420     /**
421      * {@inheritDoc}
422      */
423     public double getDefaultDouble(String name) {
424       return DOUBLE_DEFAULT_DEFAULT;
425     }
426
427     /**
428      * {@inheritDoc}
429      */
430     public float getDefaultFloat(String name) {
431       return FLOAT_DEFAULT_DEFAULT;
432     }
433
434     /**
435      * {@inheritDoc}
436      */
437     public int getDefaultInt(String name) {
438       return INT_DEFAULT_DEFAULT;
439     }
440
441     /**
442      * {@inheritDoc}
443      */
444     public long getDefaultLong(String name) {
445       return LONG_DEFAULT_DEFAULT;
446     }
447
448     /**
449      * {@inheritDoc}
450      */
451     public String getDefaultString(String name) {
452       return STRING_DEFAULT_DEFAULT;
453     }
454
455     /**
456      * {@inheritDoc}
457      */
458     public double getDouble(String name) {
459       double value = DOUBLE_DEFAULT_DEFAULT;
460       String s = (String) fOptions.get(name);
461       if (s != null) {
462         try {
463           value = new Double(s).doubleValue();
464         } catch (NumberFormatException e) {
465         }
466       }
467       return value;
468     }
469
470     /**
471      * {@inheritDoc}
472      */
473     public float getFloat(String name) {
474       float value = FLOAT_DEFAULT_DEFAULT;
475       String s = (String) fOptions.get(name);
476       if (s != null) {
477         try {
478           value = new Float(s).floatValue();
479         } catch (NumberFormatException e) {
480         }
481       }
482       return value;
483     }
484
485     /**
486      * {@inheritDoc}
487      */
488     public int getInt(String name) {
489       int value = INT_DEFAULT_DEFAULT;
490       String s = (String) fOptions.get(name);
491       if (s != null) {
492         try {
493           value = new Integer(s).intValue();
494         } catch (NumberFormatException e) {
495         }
496       }
497       return value;
498     }
499
500     /**
501      * {@inheritDoc}
502      */
503     public long getLong(String name) {
504       long value = LONG_DEFAULT_DEFAULT;
505       String s = (String) fOptions.get(name);
506       if (s != null) {
507         try {
508           value = new Long(s).longValue();
509         } catch (NumberFormatException e) {
510         }
511       }
512       return value;
513     }
514
515     /**
516      * {@inheritDoc}
517      */
518     public String getString(String name) {
519       String value = (String) fOptions.get(name);
520       if (value == null)
521         value = STRING_DEFAULT_DEFAULT;
522       return value;
523     }
524
525     /**
526      * {@inheritDoc}
527      */
528     public boolean isDefault(String name) {
529       return false;
530     }
531
532     /**
533      * {@inheritDoc}
534      */
535     public boolean needsSaving() {
536       return !fOptions.isEmpty();
537     }
538
539     /**
540      * {@inheritDoc}
541      */
542     public void putValue(String name, String value) {
543       throw new UnsupportedOperationException();
544     }
545
546     /**
547      * {@inheritDoc}
548      */
549     public void setDefault(String name, double value) {
550       throw new UnsupportedOperationException();
551     }
552
553     /**
554      * {@inheritDoc}
555      */
556     public void setDefault(String name, float value) {
557       throw new UnsupportedOperationException();
558     }
559
560     /**
561      * {@inheritDoc}
562      */
563     public void setDefault(String name, int value) {
564       throw new UnsupportedOperationException();
565     }
566
567     /**
568      * {@inheritDoc}
569      */
570     public void setDefault(String name, long value) {
571       throw new UnsupportedOperationException();
572     }
573
574     /**
575      * {@inheritDoc}
576      */
577     public void setDefault(String name, String defaultObject) {
578       throw new UnsupportedOperationException();
579     }
580
581     /**
582      * {@inheritDoc}
583      */
584     public void setDefault(String name, boolean value) {
585       throw new UnsupportedOperationException();
586     }
587
588     /**
589      * {@inheritDoc}
590      */
591     public void setToDefault(String name) {
592       throw new UnsupportedOperationException();
593     }
594
595     /**
596      * {@inheritDoc}
597      */
598     public void setValue(String name, double value) {
599       throw new UnsupportedOperationException();
600     }
601
602     /**
603      * {@inheritDoc}
604      */
605     public void setValue(String name, float value) {
606       throw new UnsupportedOperationException();
607     }
608
609     /**
610      * {@inheritDoc}
611      */
612     public void setValue(String name, int value) {
613       throw new UnsupportedOperationException();
614     }
615
616     /**
617      * {@inheritDoc}
618      */
619     public void setValue(String name, long value) {
620       throw new UnsupportedOperationException();
621     }
622
623     /**
624      * {@inheritDoc}
625      */
626     public void setValue(String name, String value) {
627       throw new UnsupportedOperationException();
628     }
629
630     /**
631      * {@inheritDoc}
632      */
633     public void setValue(String name, boolean value) {
634       throw new UnsupportedOperationException();
635     }
636
637     /**
638      * Returns the adapted options Map.
639      * 
640      * @return Returns the adapted options Map.
641      */
642     public Map getOptions() {
643       return fOptions;
644     }
645
646     /**
647      * Returns the mock-up preference store, events are received through this preference store.
648      * 
649      * @return Returns the mock-up preference store.
650      */
651     public IPreferenceStore getMockupPreferenceStore() {
652       return fMockupPreferenceStore;
653     }
654
655     /**
656      * Set the event filter to the given filter.
657      * 
658      * @param filter
659      *          The new filter.
660      */
661     public void setFilter(IPropertyChangeEventFilter filter) {
662       fFilter = filter;
663     }
664
665     /**
666      * Returns the event filter.
667      * 
668      * @return The event filter.
669      */
670     public IPropertyChangeEventFilter getFilter() {
671       return fFilter;
672     }
673   }
674
675   /*
676    * Link mode.
677    */
678   //  class MouseClickListener implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener,
679   //      IPropertyChangeListener, IDocumentListener, ITextInputListener {
680   //
681   //    /** The session is active. */
682   //    private boolean fActive;
683   //
684   //    /** The currently active style range. */
685   //    private IRegion fActiveRegion;
686   //
687   //    /** The currently active style range as position. */
688   //    private Position fRememberedPosition;
689   //
690   //    /** The hand cursor. */
691   //    private Cursor fCursor;
692   //
693   //    /** The link color. */
694   //    private Color fColor;
695   //
696   //    /** The key modifier mask. */
697   //    private int fKeyModifierMask;
698   //
699   //    public void deactivate() {
700   //      deactivate(false);
701   //    }
702   //
703   //    public void deactivate(boolean redrawAll) {
704   //      if (!fActive)
705   //        return;
706   //
707   //      repairRepresentation(redrawAll);
708   //      fActive = false;
709   //    }
710   //
711   //    public void install() {
712   //
713   //      ISourceViewer sourceViewer = getSourceViewer();
714   //      if (sourceViewer == null)
715   //        return;
716   //
717   //      StyledText text = sourceViewer.getTextWidget();
718   //      if (text == null || text.isDisposed())
719   //        return;
720   //
721   //      updateColor(sourceViewer);
722   //
723   //      sourceViewer.addTextInputListener(this);
724   //
725   //      IDocument document = sourceViewer.getDocument();
726   //      if (document != null)
727   //        document.addDocumentListener(this);
728   //
729   //      text.addKeyListener(this);
730   //      text.addMouseListener(this);
731   //      text.addMouseMoveListener(this);
732   //      text.addFocusListener(this);
733   //      text.addPaintListener(this);
734   //
735   //      updateKeyModifierMask();
736   //
737   //      IPreferenceStore preferenceStore = getPreferenceStore();
738   //      preferenceStore.addPropertyChangeListener(this);
739   //    }
740   //
741   //    private void updateKeyModifierMask() {
742   //      String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
743   //      fKeyModifierMask = computeStateMask(modifiers);
744   //      if (fKeyModifierMask == -1) {
745   //        // Fallback to stored state mask
746   //        fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
747   //      }
748   //      ;
749   //    }
750   //
751   //    private int computeStateMask(String modifiers) {
752   //      if (modifiers == null)
753   //        return -1;
754   //
755   //      if (modifiers.length() == 0)
756   //        return SWT.NONE;
757   //
758   //      int stateMask = 0;
759   //      StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
760   //      while (modifierTokenizer.hasMoreTokens()) {
761   //        int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
762   //        if (modifier == 0 || (stateMask & modifier) == modifier)
763   //          return -1;
764   //        stateMask = stateMask | modifier;
765   //      }
766   //      return stateMask;
767   //    }
768   //
769   //    public void uninstall() {
770   //
771   //      if (fColor != null) {
772   //        fColor.dispose();
773   //        fColor = null;
774   //      }
775   //
776   //      if (fCursor != null) {
777   //        fCursor.dispose();
778   //        fCursor = null;
779   //      }
780   //
781   //      ISourceViewer sourceViewer = getSourceViewer();
782   //      if (sourceViewer == null)
783   //        return;
784   //
785   //      sourceViewer.removeTextInputListener(this);
786   //
787   //      IDocument document = sourceViewer.getDocument();
788   //      if (document != null)
789   //        document.removeDocumentListener(this);
790   //
791   //      IPreferenceStore preferenceStore = getPreferenceStore();
792   //      if (preferenceStore != null)
793   //        preferenceStore.removePropertyChangeListener(this);
794   //
795   //      StyledText text = sourceViewer.getTextWidget();
796   //      if (text == null || text.isDisposed())
797   //        return;
798   //
799   //      text.removeKeyListener(this);
800   //      text.removeMouseListener(this);
801   //      text.removeMouseMoveListener(this);
802   //      text.removeFocusListener(this);
803   //      text.removePaintListener(this);
804   //    }
805   //
806   //    /*
807   //     * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
808   //     */
809   //    public void propertyChange(PropertyChangeEvent event) {
810   //      if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
811   //        ISourceViewer viewer = getSourceViewer();
812   //        if (viewer != null)
813   //          updateColor(viewer);
814   //      } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
815   //        updateKeyModifierMask();
816   //      }
817   //    }
818   //
819   //    private void updateColor(ISourceViewer viewer) {
820   //      if (fColor != null)
821   //        fColor.dispose();
822   //
823   //      StyledText text = viewer.getTextWidget();
824   //      if (text == null || text.isDisposed())
825   //        return;
826   //
827   //      Display display = text.getDisplay();
828   //      fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
829   //    }
830   //
831   //    /**
832   //     * Creates a color from the information stored in the given preference store. Returns <code>null</code> if there is no such
833   //     * information available.
834   //     */
835   //    private Color createColor(IPreferenceStore store, String key, Display display) {
836   //
837   //      RGB rgb = null;
838   //
839   //      if (store.contains(key)) {
840   //
841   //        if (store.isDefault(key))
842   //          rgb = PreferenceConverter.getDefaultColor(store, key);
843   //        else
844   //          rgb = PreferenceConverter.getColor(store, key);
845   //
846   //        if (rgb != null)
847   //          return new Color(display, rgb);
848   //      }
849   //
850   //      return null;
851   //    }
852   //
853   //    private void repairRepresentation() {
854   //      repairRepresentation(false);
855   //    }
856   //
857   //    private void repairRepresentation(boolean redrawAll) {
858   //
859   //      if (fActiveRegion == null)
860   //        return;
861   //
862   //      ISourceViewer viewer = getSourceViewer();
863   //      if (viewer != null) {
864   //        resetCursor(viewer);
865   //
866   //        int offset = fActiveRegion.getOffset();
867   //        int length = fActiveRegion.getLength();
868   //
869   //        // remove style
870   //        if (!redrawAll && viewer instanceof ITextViewerExtension2)
871   //          ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
872   //        else
873   //          viewer.invalidateTextPresentation();
874   //
875   //        // remove underline
876   //        if (viewer instanceof ITextViewerExtension3) {
877   //          ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
878   //          offset = extension.modelOffset2WidgetOffset(offset);
879   //        } else {
880   //          offset -= viewer.getVisibleRegion().getOffset();
881   //        }
882   //
883   //        StyledText text = viewer.getTextWidget();
884   //        try {
885   //          text.redrawRange(offset, length, true);
886   //        } catch (IllegalArgumentException x) {
887   //          PHPeclipsePlugin.log(x);
888   //        }
889   //      }
890   //
891   //      fActiveRegion = null;
892   //    }
893   //
894   //    // will eventually be replaced by a method provided by jdt.core
895   //    private IRegion selectWord(IDocument document, int anchor) {
896   //
897   //      try {
898   //        int offset = anchor;
899   //        char c;
900   //
901   //        while (offset >= 0) {
902   //          c = document.getChar(offset);
903   //          if (!Scanner.isPHPIdentifierPart(c))
904   //            break;
905   //          --offset;
906   //        }
907   //
908   //        int start = offset;
909   //
910   //        offset = anchor;
911   //        int length = document.getLength();
912   //
913   //        while (offset < length) {
914   //          c = document.getChar(offset);
915   //          if (!Scanner.isPHPIdentifierPart(c))
916   //            break;
917   //          ++offset;
918   //        }
919   //
920   //        int end = offset;
921   //
922   //        if (start == end)
923   //          return new Region(start, 0);
924   //        else
925   //          return new Region(start + 1, end - start - 1);
926   //
927   //      } catch (BadLocationException x) {
928   //        return null;
929   //      }
930   //    }
931   //
932   //    IRegion getCurrentTextRegion(ISourceViewer viewer) {
933   //
934   //      int offset = getCurrentTextOffset(viewer);
935   //      if (offset == -1)
936   //        return null;
937   //
938   //      return null;
939   //      // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
940   //      // if (input == null)
941   //      // return null;
942   //      //
943   //      // try {
944   //      //
945   //      // IJavaElement[] elements= null;
946   //      // synchronized (input) {
947   //      // elements= ((ICodeAssist) input).codeSelect(offset, 0);
948   //      // }
949   //      //
950   //      // if (elements == null || elements.length == 0)
951   //      // return null;
952   //      //
953   //      // return selectWord(viewer.getDocument(), offset);
954   //      //
955   //      // } catch (JavaModelException e) {
956   //      // return null;
957   //      // }
958   //    }
959   //
960   //    private int getCurrentTextOffset(ISourceViewer viewer) {
961   //
962   //      try {
963   //        StyledText text = viewer.getTextWidget();
964   //        if (text == null || text.isDisposed())
965   //          return -1;
966   //
967   //        Display display = text.getDisplay();
968   //        Point absolutePosition = display.getCursorLocation();
969   //        Point relativePosition = text.toControl(absolutePosition);
970   //
971   //        int widgetOffset = text.getOffsetAtLocation(relativePosition);
972   //        if (viewer instanceof ITextViewerExtension3) {
973   //          ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
974   //          return extension.widgetOffset2ModelOffset(widgetOffset);
975   //        } else {
976   //          return widgetOffset + viewer.getVisibleRegion().getOffset();
977   //        }
978   //
979   //      } catch (IllegalArgumentException e) {
980   //        return -1;
981   //      }
982   //    }
983   //
984   //    private void highlightRegion(ISourceViewer viewer, IRegion region) {
985   //
986   //      if (region.equals(fActiveRegion))
987   //        return;
988   //
989   //      repairRepresentation();
990   //
991   //      StyledText text = viewer.getTextWidget();
992   //      if (text == null || text.isDisposed())
993   //        return;
994   //
995   //      // highlight region
996   //      int offset = 0;
997   //      int length = 0;
998   //
999   //      if (viewer instanceof ITextViewerExtension3) {
1000   //        ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1001   //        IRegion widgetRange = extension.modelRange2WidgetRange(region);
1002   //        if (widgetRange == null)
1003   //          return;
1004   //
1005   //        offset = widgetRange.getOffset();
1006   //        length = widgetRange.getLength();
1007   //
1008   //      } else {
1009   //        offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
1010   //        length = region.getLength();
1011   //      }
1012   //
1013   //      StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
1014   //      Color foregroundColor = fColor;
1015   //      Color backgroundColor = oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
1016   //      StyleRange styleRange = new StyleRange(offset, length, foregroundColor, backgroundColor);
1017   //      text.setStyleRange(styleRange);
1018   //
1019   //      // underline
1020   //      text.redrawRange(offset, length, true);
1021   //
1022   //      fActiveRegion = region;
1023   //    }
1024   //
1025   //    private void activateCursor(ISourceViewer viewer) {
1026   //      StyledText text = viewer.getTextWidget();
1027   //      if (text == null || text.isDisposed())
1028   //        return;
1029   //      Display display = text.getDisplay();
1030   //      if (fCursor == null)
1031   //        fCursor = new Cursor(display, SWT.CURSOR_HAND);
1032   //      text.setCursor(fCursor);
1033   //    }
1034   //
1035   //    private void resetCursor(ISourceViewer viewer) {
1036   //      StyledText text = viewer.getTextWidget();
1037   //      if (text != null && !text.isDisposed())
1038   //        text.setCursor(null);
1039   //
1040   //      if (fCursor != null) {
1041   //        fCursor.dispose();
1042   //        fCursor = null;
1043   //      }
1044   //    }
1045   //
1046   //    /*
1047   //     * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1048   //     */
1049   //    public void keyPressed(KeyEvent event) {
1050   //
1051   //      if (fActive) {
1052   //        deactivate();
1053   //        return;
1054   //      }
1055   //
1056   //      if (event.keyCode != fKeyModifierMask) {
1057   //        deactivate();
1058   //        return;
1059   //      }
1060   //
1061   //      fActive = true;
1062   //
1063   //      // removed for #25871
1064   //      //
1065   //      // ISourceViewer viewer= getSourceViewer();
1066   //      // if (viewer == null)
1067   //      // return;
1068   //      //
1069   //      // IRegion region= getCurrentTextRegion(viewer);
1070   //      // if (region == null)
1071   //      // return;
1072   //      //
1073   //      // highlightRegion(viewer, region);
1074   //      // activateCursor(viewer);
1075   //    }
1076   //
1077   //    /*
1078   //     * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1079   //     */
1080   //    public void keyReleased(KeyEvent event) {
1081   //
1082   //      if (!fActive)
1083   //        return;
1084   //
1085   //      deactivate();
1086   //    }
1087   //
1088   //    /*
1089   //     * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1090   //     */
1091   //    public void mouseDoubleClick(MouseEvent e) {
1092   //    }
1093   //
1094   //    /*
1095   //     * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1096   //     */
1097   //    public void mouseDown(MouseEvent event) {
1098   //
1099   //      if (!fActive)
1100   //        return;
1101   //
1102   //      if (event.stateMask != fKeyModifierMask) {
1103   //        deactivate();
1104   //        return;
1105   //      }
1106   //
1107   //      if (event.button != 1) {
1108   //        deactivate();
1109   //        return;
1110   //      }
1111   //    }
1112   //
1113   //    /*
1114   //     * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1115   //     */
1116   //    public void mouseUp(MouseEvent e) {
1117   //
1118   //      if (!fActive)
1119   //        return;
1120   //
1121   //      if (e.button != 1) {
1122   //        deactivate();
1123   //        return;
1124   //      }
1125   //
1126   //      boolean wasActive = fCursor != null;
1127   //
1128   //      deactivate();
1129   //
1130   //      if (wasActive) {
1131   //        IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1132   //        if (action != null)
1133   //          action.run();
1134   //      }
1135   //    }
1136   //
1137   //    /*
1138   //     * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1139   //     */
1140   //    public void mouseMove(MouseEvent event) {
1141   //
1142   //      if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
1143   //        deactivate();
1144   //        return;
1145   //      }
1146   //
1147   //      if (!fActive) {
1148   //        if (event.stateMask != fKeyModifierMask)
1149   //          return;
1150   //        // modifier was already pressed
1151   //        fActive = true;
1152   //      }
1153   //
1154   //      ISourceViewer viewer = getSourceViewer();
1155   //      if (viewer == null) {
1156   //        deactivate();
1157   //        return;
1158   //      }
1159   //
1160   //      StyledText text = viewer.getTextWidget();
1161   //      if (text == null || text.isDisposed()) {
1162   //        deactivate();
1163   //        return;
1164   //      }
1165   //
1166   //      if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
1167   //        deactivate();
1168   //        return;
1169   //      }
1170   //
1171   //      IRegion region = getCurrentTextRegion(viewer);
1172   //      if (region == null || region.getLength() == 0) {
1173   //        repairRepresentation();
1174   //        return;
1175   //      }
1176   //
1177   //      highlightRegion(viewer, region);
1178   //      activateCursor(viewer);
1179   //    }
1180   //
1181   //    /*
1182   //     * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1183   //     */
1184   //    public void focusGained(FocusEvent e) {
1185   //    }
1186   //
1187   //    /*
1188   //     * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1189   //     */
1190   //    public void focusLost(FocusEvent event) {
1191   //      deactivate();
1192   //    }
1193   //
1194   //    /*
1195   //     * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1196   //     */
1197   //    public void documentAboutToBeChanged(DocumentEvent event) {
1198   //      if (fActive && fActiveRegion != null) {
1199   //        fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
1200   //        try {
1201   //          event.getDocument().addPosition(fRememberedPosition);
1202   //        } catch (BadLocationException x) {
1203   //          fRememberedPosition = null;
1204   //        }
1205   //      }
1206   //    }
1207   //
1208   //    /*
1209   //     * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1210   //     */
1211   //    public void documentChanged(DocumentEvent event) {
1212   //      if (fRememberedPosition != null && !fRememberedPosition.isDeleted()) {
1213   //        event.getDocument().removePosition(fRememberedPosition);
1214   //        fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
1215   //      }
1216   //      fRememberedPosition = null;
1217   //
1218   //      ISourceViewer viewer = getSourceViewer();
1219   //      if (viewer != null) {
1220   //        StyledText widget = viewer.getTextWidget();
1221   //        if (widget != null && !widget.isDisposed()) {
1222   //          widget.getDisplay().asyncExec(new Runnable() {
1223   //            public void run() {
1224   //              deactivate();
1225   //            }
1226   //          });
1227   //        }
1228   //      }
1229   //    }
1230   //
1231   //    /*
1232   //     * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
1233   //     * org.eclipse.jface.text.IDocument)
1234   //     */
1235   //    public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
1236   //      if (oldInput == null)
1237   //        return;
1238   //      deactivate();
1239   //      oldInput.removeDocumentListener(this);
1240   //    }
1241   //
1242   //    /*
1243   //     * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
1244   //     * org.eclipse.jface.text.IDocument)
1245   //     */
1246   //    public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
1247   //      if (newInput == null)
1248   //        return;
1249   //      newInput.addDocumentListener(this);
1250   //    }
1251   //
1252   //    /*
1253   //     * @see PaintListener#paintControl(PaintEvent)
1254   //     */
1255   //    public void paintControl(PaintEvent event) {
1256   //      if (fActiveRegion == null)
1257   //        return;
1258   //
1259   //      ISourceViewer viewer = getSourceViewer();
1260   //      if (viewer == null)
1261   //        return;
1262   //
1263   //      StyledText text = viewer.getTextWidget();
1264   //      if (text == null || text.isDisposed())
1265   //        return;
1266   //
1267   //      int offset = 0;
1268   //      int length = 0;
1269   //
1270   //      if (viewer instanceof ITextViewerExtension3) {
1271   //
1272   //        ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1273   //        IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
1274   //        if (widgetRange == null)
1275   //          return;
1276   //
1277   //        offset = widgetRange.getOffset();
1278   //        length = widgetRange.getLength();
1279   //
1280   //      } else {
1281   //
1282   //        IRegion region = viewer.getVisibleRegion();
1283   //        if (!includes(region, fActiveRegion))
1284   //          return;
1285   //
1286   //        offset = fActiveRegion.getOffset() - region.getOffset();
1287   //        length = fActiveRegion.getLength();
1288   //      }
1289   //
1290   //      // support for bidi
1291   //      Point minLocation = getMinimumLocation(text, offset, length);
1292   //      Point maxLocation = getMaximumLocation(text, offset, length);
1293   //
1294   //      int x1 = minLocation.x;
1295   //      int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
1296   //      int y = minLocation.y + text.getLineHeight() - 1;
1297   //
1298   //      GC gc = event.gc;
1299   //      if (fColor != null && !fColor.isDisposed())
1300   //        gc.setForeground(fColor);
1301   //      gc.drawLine(x1, y, x2, y);
1302   //    }
1303   //
1304   //    private boolean includes(IRegion region, IRegion position) {
1305   //      return position.getOffset() >= region.getOffset()
1306   //          && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
1307   //    }
1308   //
1309   //    private Point getMinimumLocation(StyledText text, int offset, int length) {
1310   //      Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
1311   //
1312   //      for (int i = 0; i <= length; i++) {
1313   //        Point location = text.getLocationAtOffset(offset + i);
1314   //
1315   //        if (location.x < minLocation.x)
1316   //          minLocation.x = location.x;
1317   //        if (location.y < minLocation.y)
1318   //          minLocation.y = location.y;
1319   //      }
1320   //
1321   //      return minLocation;
1322   //    }
1323   //
1324   //    private Point getMaximumLocation(StyledText text, int offset, int length) {
1325   //      Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
1326   //
1327   //      for (int i = 0; i <= length; i++) {
1328   //        Point location = text.getLocationAtOffset(offset + i);
1329   //
1330   //        if (location.x > maxLocation.x)
1331   //          maxLocation.x = location.x;
1332   //        if (location.y > maxLocation.y)
1333   //          maxLocation.y = location.y;
1334   //      }
1335   //
1336   //      return maxLocation;
1337   //    }
1338   //  };
1339   /*
1340    * Link mode.
1341    */
1342   class MouseClickListener implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener,
1343       IPropertyChangeListener, IDocumentListener, ITextInputListener, ITextPresentationListener {
1344
1345     /** The session is active. */
1346     private boolean fActive;
1347
1348     /** The currently active style range. */
1349     private IRegion fActiveRegion;
1350
1351     /** The currently active style range as position. */
1352     private Position fRememberedPosition;
1353
1354     /** The hand cursor. */
1355     private Cursor fCursor;
1356
1357     /** The link color. */
1358     private Color fColor;
1359
1360     /** The key modifier mask. */
1361     private int fKeyModifierMask;
1362
1363     public void deactivate() {
1364       deactivate(false);
1365     }
1366
1367     public void deactivate(boolean redrawAll) {
1368       if (!fActive)
1369         return;
1370
1371       repairRepresentation(redrawAll);
1372       fActive = false;
1373     }
1374
1375     public void install() {
1376       ISourceViewer sourceViewer = getSourceViewer();
1377       if (sourceViewer == null)
1378         return;
1379
1380       StyledText text = sourceViewer.getTextWidget();
1381       if (text == null || text.isDisposed())
1382         return;
1383
1384       updateColor(sourceViewer);
1385
1386       sourceViewer.addTextInputListener(this);
1387
1388       IDocument document = sourceViewer.getDocument();
1389       if (document != null)
1390         document.addDocumentListener(this);
1391
1392       text.addKeyListener(this);
1393       text.addMouseListener(this);
1394       text.addMouseMoveListener(this);
1395       text.addFocusListener(this);
1396       text.addPaintListener(this);
1397
1398       ((ITextViewerExtension4) sourceViewer).addTextPresentationListener(this);
1399
1400       updateKeyModifierMask();
1401
1402       IPreferenceStore preferenceStore = getPreferenceStore();
1403       preferenceStore.addPropertyChangeListener(this);
1404     }
1405
1406     private void updateKeyModifierMask() {
1407       String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
1408       fKeyModifierMask = computeStateMask(modifiers);
1409       if (fKeyModifierMask == -1) {
1410         // Fall back to stored state mask
1411         fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
1412       }
1413     }
1414
1415     private int computeStateMask(String modifiers) {
1416       if (modifiers == null)
1417         return -1;
1418
1419       if (modifiers.length() == 0)
1420         return SWT.NONE;
1421
1422       int stateMask = 0;
1423       StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
1424       while (modifierTokenizer.hasMoreTokens()) {
1425         int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
1426         if (modifier == 0 || (stateMask & modifier) == modifier)
1427           return -1;
1428         stateMask = stateMask | modifier;
1429       }
1430       return stateMask;
1431     }
1432
1433     public void uninstall() {
1434
1435       if (fColor != null) {
1436         fColor.dispose();
1437         fColor = null;
1438       }
1439
1440       if (fCursor != null) {
1441         fCursor.dispose();
1442         fCursor = null;
1443       }
1444
1445       ISourceViewer sourceViewer = getSourceViewer();
1446       if (sourceViewer != null)
1447         sourceViewer.removeTextInputListener(this);
1448
1449       IDocumentProvider documentProvider = getDocumentProvider();
1450       if (documentProvider != null) {
1451         IDocument document = documentProvider.getDocument(getEditorInput());
1452         if (document != null)
1453           document.removeDocumentListener(this);
1454       }
1455
1456       IPreferenceStore preferenceStore = getPreferenceStore();
1457       if (preferenceStore != null)
1458         preferenceStore.removePropertyChangeListener(this);
1459
1460       if (sourceViewer == null)
1461         return;
1462
1463       StyledText text = sourceViewer.getTextWidget();
1464       if (text == null || text.isDisposed())
1465         return;
1466
1467       text.removeKeyListener(this);
1468       text.removeMouseListener(this);
1469       text.removeMouseMoveListener(this);
1470       text.removeFocusListener(this);
1471       text.removePaintListener(this);
1472
1473       ((ITextViewerExtension4) sourceViewer).removeTextPresentationListener(this);
1474     }
1475
1476     /*
1477      * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
1478      */
1479     public void propertyChange(PropertyChangeEvent event) {
1480       if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
1481         ISourceViewer viewer = getSourceViewer();
1482         if (viewer != null)
1483           updateColor(viewer);
1484       } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
1485         updateKeyModifierMask();
1486       }
1487     }
1488
1489     private void updateColor(ISourceViewer viewer) {
1490       if (fColor != null)
1491         fColor.dispose();
1492
1493       StyledText text = viewer.getTextWidget();
1494       if (text == null || text.isDisposed())
1495         return;
1496
1497       Display display = text.getDisplay();
1498       fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
1499     }
1500
1501     /**
1502      * Creates a color from the information stored in the given preference store.
1503      * 
1504      * @param store
1505      *          the preference store
1506      * @param key
1507      *          the key
1508      * @param display
1509      *          the display
1510      * @return the color or <code>null</code> if there is no such information available
1511      */
1512     private Color createColor(IPreferenceStore store, String key, Display display) {
1513
1514       RGB rgb = null;
1515
1516       if (store.contains(key)) {
1517
1518         if (store.isDefault(key))
1519           rgb = PreferenceConverter.getDefaultColor(store, key);
1520         else
1521           rgb = PreferenceConverter.getColor(store, key);
1522
1523         if (rgb != null)
1524           return new Color(display, rgb);
1525       }
1526
1527       return null;
1528     }
1529
1530     private void repairRepresentation() {
1531       repairRepresentation(false);
1532     }
1533
1534     private void repairRepresentation(boolean redrawAll) {
1535
1536       if (fActiveRegion == null)
1537         return;
1538
1539       int offset = fActiveRegion.getOffset();
1540       int length = fActiveRegion.getLength();
1541       fActiveRegion = null;
1542
1543       ISourceViewer viewer = getSourceViewer();
1544       if (viewer != null) {
1545
1546         resetCursor(viewer);
1547
1548         // Invalidate ==> remove applied text presentation
1549         if (!redrawAll && viewer instanceof ITextViewerExtension2)
1550           ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
1551         else
1552           viewer.invalidateTextPresentation();
1553
1554         // Remove underline
1555         if (viewer instanceof ITextViewerExtension5) {
1556           ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1557           offset = extension.modelOffset2WidgetOffset(offset);
1558         } else {
1559           offset -= viewer.getVisibleRegion().getOffset();
1560         }
1561         try {
1562           StyledText text = viewer.getTextWidget();
1563
1564           text.redrawRange(offset, length, false);
1565         } catch (IllegalArgumentException x) {
1566           //                                    JavaPlugin.log(x);
1567         }
1568       }
1569     }
1570
1571     // will eventually be replaced by a method provided by jdt.core
1572     private IRegion selectWord(IDocument document, int anchor) {
1573
1574       try {
1575         int offset = anchor;
1576         char c;
1577
1578         while (offset >= 0) {
1579           c = document.getChar(offset);
1580           if (!Scanner.isPHPIdentifierPart(c) && c != '$')
1581             break;
1582           --offset;
1583         }
1584
1585         int start = offset;
1586
1587         offset = anchor;
1588         int length = document.getLength();
1589
1590         while (offset < length) {
1591           c = document.getChar(offset);
1592           if (!Scanner.isPHPIdentifierPart(c) && c != '$')
1593             break;
1594           ++offset;
1595         }
1596
1597         int end = offset;
1598
1599         if (start == end)
1600           return new Region(start, 0);
1601         else
1602           return new Region(start + 1, end - start - 1);
1603
1604       } catch (BadLocationException x) {
1605         return null;
1606       }
1607     }
1608
1609     IRegion getCurrentTextRegion(ISourceViewer viewer) {
1610
1611       int offset = getCurrentTextOffset(viewer);
1612       if (offset == -1)
1613         return null;
1614
1615       IJavaElement input = SelectionConverter.getInput(PHPEditor.this);
1616       if (input == null)
1617         return null;
1618
1619       //                        try {
1620
1621       //                                IJavaElement[] elements= null;
1622       //                                synchronized (input) {
1623       //                                        elements= ((ICodeAssist) input).codeSelect(offset, 0);
1624       //                                }
1625       //                                
1626       //                                if (elements == null || elements.length == 0)
1627       //                                        return null;
1628
1629       return selectWord(viewer.getDocument(), offset);
1630
1631       //                        } catch (JavaModelException e) {
1632       //                                return null;
1633       //                        }
1634     }
1635
1636     private int getCurrentTextOffset(ISourceViewer viewer) {
1637
1638       try {
1639         StyledText text = viewer.getTextWidget();
1640         if (text == null || text.isDisposed())
1641           return -1;
1642
1643         Display display = text.getDisplay();
1644         Point absolutePosition = display.getCursorLocation();
1645         Point relativePosition = text.toControl(absolutePosition);
1646
1647         int widgetOffset = text.getOffsetAtLocation(relativePosition);
1648         if (viewer instanceof ITextViewerExtension5) {
1649           ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1650           return extension.widgetOffset2ModelOffset(widgetOffset);
1651         } else {
1652           return widgetOffset + viewer.getVisibleRegion().getOffset();
1653         }
1654
1655       } catch (IllegalArgumentException e) {
1656         return -1;
1657       }
1658     }
1659
1660     public void applyTextPresentation(TextPresentation textPresentation) {
1661       if (fActiveRegion == null)
1662         return;
1663       IRegion region = textPresentation.getExtent();
1664       if (fActiveRegion.getOffset() + fActiveRegion.getLength() >= region.getOffset()
1665           && region.getOffset() + region.getLength() > fActiveRegion.getOffset())
1666         textPresentation.mergeStyleRange(new StyleRange(fActiveRegion.getOffset(), fActiveRegion.getLength(), fColor, null));
1667     }
1668
1669     private void highlightRegion(ISourceViewer viewer, IRegion region) {
1670
1671       if (region.equals(fActiveRegion))
1672         return;
1673
1674       repairRepresentation();
1675
1676       StyledText text = viewer.getTextWidget();
1677       if (text == null || text.isDisposed())
1678         return;
1679
1680       // Underline
1681       int offset = 0;
1682       int length = 0;
1683       if (viewer instanceof ITextViewerExtension5) {
1684         ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1685         IRegion widgetRange = extension.modelRange2WidgetRange(region);
1686         if (widgetRange == null)
1687           return;
1688
1689         offset = widgetRange.getOffset();
1690         length = widgetRange.getLength();
1691
1692       } else {
1693         offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
1694         length = region.getLength();
1695       }
1696       text.redrawRange(offset, length, false);
1697
1698       // Invalidate region ==> apply text presentation
1699       fActiveRegion = region;
1700       if (viewer instanceof ITextViewerExtension2)
1701         ((ITextViewerExtension2) viewer).invalidateTextPresentation(region.getOffset(), region.getLength());
1702       else
1703         viewer.invalidateTextPresentation();
1704     }
1705
1706     private void activateCursor(ISourceViewer viewer) {
1707       StyledText text = viewer.getTextWidget();
1708       if (text == null || text.isDisposed())
1709         return;
1710       Display display = text.getDisplay();
1711       if (fCursor == null)
1712         fCursor = new Cursor(display, SWT.CURSOR_HAND);
1713       text.setCursor(fCursor);
1714     }
1715
1716     private void resetCursor(ISourceViewer viewer) {
1717       StyledText text = viewer.getTextWidget();
1718       if (text != null && !text.isDisposed())
1719         text.setCursor(null);
1720
1721       if (fCursor != null) {
1722         fCursor.dispose();
1723         fCursor = null;
1724       }
1725     }
1726
1727     /*
1728      * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1729      */
1730     public void keyPressed(KeyEvent event) {
1731
1732       if (fActive) {
1733         deactivate();
1734         return;
1735       }
1736
1737       if (event.keyCode != fKeyModifierMask) {
1738         deactivate();
1739         return;
1740       }
1741
1742       fActive = true;
1743
1744       //                        removed for #25871
1745       //
1746       //                        ISourceViewer viewer= getSourceViewer();
1747       //                        if (viewer == null)
1748       //                                return;
1749       //                        
1750       //                        IRegion region= getCurrentTextRegion(viewer);
1751       //                        if (region == null)
1752       //                                return;
1753       //                        
1754       //                        highlightRegion(viewer, region);
1755       //                        activateCursor(viewer);
1756     }
1757
1758     /*
1759      * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1760      */
1761     public void keyReleased(KeyEvent event) {
1762
1763       if (!fActive)
1764         return;
1765
1766       deactivate();
1767     }
1768
1769     /*
1770      * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1771      */
1772     public void mouseDoubleClick(MouseEvent e) {
1773     }
1774
1775     /*
1776      * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1777      */
1778     public void mouseDown(MouseEvent event) {
1779
1780       if (!fActive)
1781         return;
1782
1783       if (event.stateMask != fKeyModifierMask) {
1784         deactivate();
1785         return;
1786       }
1787
1788       if (event.button != 1) {
1789         deactivate();
1790         return;
1791       }
1792     }
1793
1794     /*
1795      * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1796      */
1797     public void mouseUp(MouseEvent e) {
1798
1799       if (!fActive)
1800         return;
1801
1802       if (e.button != 1) {
1803         deactivate();
1804         return;
1805       }
1806
1807       boolean wasActive = fCursor != null;
1808
1809       deactivate();
1810
1811       if (wasActive) {
1812         IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1813         if (action != null)
1814           action.run();
1815       }
1816     }
1817
1818     /*
1819      * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1820      */
1821     public void mouseMove(MouseEvent event) {
1822
1823       if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
1824         deactivate();
1825         return;
1826       }
1827
1828       if (!fActive) {
1829         if (event.stateMask != fKeyModifierMask)
1830           return;
1831         // modifier was already pressed
1832         fActive = true;
1833       }
1834
1835       ISourceViewer viewer = getSourceViewer();
1836       if (viewer == null) {
1837         deactivate();
1838         return;
1839       }
1840
1841       StyledText text = viewer.getTextWidget();
1842       if (text == null || text.isDisposed()) {
1843         deactivate();
1844         return;
1845       }
1846
1847       if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
1848         deactivate();
1849         return;
1850       }
1851
1852       IRegion region = getCurrentTextRegion(viewer);
1853       if (region == null || region.getLength() == 0) {
1854         repairRepresentation();
1855         return;
1856       }
1857
1858       highlightRegion(viewer, region);
1859       activateCursor(viewer);
1860     }
1861
1862     /*
1863      * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1864      */
1865     public void focusGained(FocusEvent e) {
1866     }
1867
1868     /*
1869      * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1870      */
1871     public void focusLost(FocusEvent event) {
1872       deactivate();
1873     }
1874
1875     /*
1876      * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1877      */
1878     public void documentAboutToBeChanged(DocumentEvent event) {
1879       if (fActive && fActiveRegion != null) {
1880         fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
1881         try {
1882           event.getDocument().addPosition(fRememberedPosition);
1883         } catch (BadLocationException x) {
1884           fRememberedPosition = null;
1885         }
1886       }
1887     }
1888
1889     /*
1890      * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1891      */
1892     public void documentChanged(DocumentEvent event) {
1893       if (fRememberedPosition != null) {
1894         if (!fRememberedPosition.isDeleted()) {
1895
1896           event.getDocument().removePosition(fRememberedPosition);
1897           fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
1898           fRememberedPosition = null;
1899
1900           ISourceViewer viewer = getSourceViewer();
1901           if (viewer != null) {
1902             StyledText widget = viewer.getTextWidget();
1903             if (widget != null && !widget.isDisposed()) {
1904               widget.getDisplay().asyncExec(new Runnable() {
1905                 public void run() {
1906                   deactivate();
1907                 }
1908               });
1909             }
1910           }
1911
1912         } else {
1913           fActiveRegion = null;
1914           fRememberedPosition = null;
1915           deactivate();
1916         }
1917       }
1918     }
1919
1920     /*
1921      * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
1922      *      org.eclipse.jface.text.IDocument)
1923      */
1924     public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
1925       if (oldInput == null)
1926         return;
1927       deactivate();
1928       oldInput.removeDocumentListener(this);
1929     }
1930
1931     /*
1932      * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
1933      *      org.eclipse.jface.text.IDocument)
1934      */
1935     public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
1936       if (newInput == null)
1937         return;
1938       newInput.addDocumentListener(this);
1939     }
1940
1941     /*
1942      * @see PaintListener#paintControl(PaintEvent)
1943      */
1944     public void paintControl(PaintEvent event) {
1945       if (fActiveRegion == null)
1946         return;
1947
1948       ISourceViewer viewer = getSourceViewer();
1949       if (viewer == null)
1950         return;
1951
1952       StyledText text = viewer.getTextWidget();
1953       if (text == null || text.isDisposed())
1954         return;
1955
1956       int offset = 0;
1957       int length = 0;
1958
1959       if (viewer instanceof ITextViewerExtension5) {
1960
1961         ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1962         IRegion widgetRange = extension.modelRange2WidgetRange(fActiveRegion);
1963         if (widgetRange == null)
1964           return;
1965
1966         offset = widgetRange.getOffset();
1967         length = widgetRange.getLength();
1968
1969       } else {
1970
1971         IRegion region = viewer.getVisibleRegion();
1972         if (!includes(region, fActiveRegion))
1973           return;
1974
1975         offset = fActiveRegion.getOffset() - region.getOffset();
1976         length = fActiveRegion.getLength();
1977       }
1978
1979       // support for bidi
1980       Point minLocation = getMinimumLocation(text, offset, length);
1981       Point maxLocation = getMaximumLocation(text, offset, length);
1982
1983       int x1 = minLocation.x;
1984       int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
1985       int y = minLocation.y + text.getLineHeight() - 1;
1986
1987       GC gc = event.gc;
1988       if (fColor != null && !fColor.isDisposed())
1989         gc.setForeground(fColor);
1990       gc.drawLine(x1, y, x2, y);
1991     }
1992
1993     private boolean includes(IRegion region, IRegion position) {
1994       return position.getOffset() >= region.getOffset()
1995           && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
1996     }
1997
1998     private Point getMinimumLocation(StyledText text, int offset, int length) {
1999       Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
2000
2001       for (int i = 0; i <= length; i++) {
2002         Point location = text.getLocationAtOffset(offset + i);
2003
2004         if (location.x < minLocation.x)
2005           minLocation.x = location.x;
2006         if (location.y < minLocation.y)
2007           minLocation.y = location.y;
2008       }
2009
2010       return minLocation;
2011     }
2012
2013     private Point getMaximumLocation(StyledText text, int offset, int length) {
2014       Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
2015
2016       for (int i = 0; i <= length; i++) {
2017         Point location = text.getLocationAtOffset(offset + i);
2018
2019         if (location.x > maxLocation.x)
2020           maxLocation.x = location.x;
2021         if (location.y > maxLocation.y)
2022           maxLocation.y = location.y;
2023       }
2024
2025       return maxLocation;
2026     }
2027   }
2028
2029   /**
2030    * This action dispatches into two behaviours: If there is no current text hover, the javadoc is displayed using information
2031    * presenter. If there is a current text hover, it is converted into a information presenter in order to make it sticky.
2032    */
2033   class InformationDispatchAction extends TextEditorAction {
2034
2035     /** The wrapped text operation action. */
2036     private final TextOperationAction fTextOperationAction;
2037
2038     /**
2039      * Creates a dispatch action.
2040      */
2041     public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
2042       super(resourceBundle, prefix, PHPEditor.this);
2043       if (textOperationAction == null)
2044         throw new IllegalArgumentException();
2045       fTextOperationAction = textOperationAction;
2046     }
2047
2048     /*
2049      * @see org.eclipse.jface.action.IAction#run()
2050      */
2051     public void run() {
2052
2053       ISourceViewer sourceViewer = getSourceViewer();
2054       if (sourceViewer == null) {
2055         fTextOperationAction.run();
2056         return;
2057       }
2058
2059       if (!(sourceViewer instanceof ITextViewerExtension2)) {
2060         fTextOperationAction.run();
2061         return;
2062       }
2063
2064       ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
2065
2066       // does a text hover exist?
2067       ITextHover textHover = textViewerExtension2.getCurrentTextHover();
2068       if (textHover == null) {
2069         fTextOperationAction.run();
2070         return;
2071       }
2072
2073       Point hoverEventLocation = textViewerExtension2.getHoverEventLocation();
2074       int offset = computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
2075       if (offset == -1) {
2076         fTextOperationAction.run();
2077         return;
2078       }
2079
2080       try {
2081         // get the text hover content
2082         IDocument document = sourceViewer.getDocument();
2083         String contentType = document.getContentType(offset);
2084
2085         final IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
2086         if (hoverRegion == null)
2087           return;
2088
2089         final String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);
2090
2091         // with information provider
2092         IInformationProvider informationProvider = new IInformationProvider() {
2093           /*
2094            * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
2095            */
2096           public IRegion getSubject(ITextViewer textViewer, int offset) {
2097             return hoverRegion;
2098           }
2099
2100           /*
2101            * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer,
2102            *      org.eclipse.jface.text.IRegion)
2103            */
2104           public String getInformation(ITextViewer textViewer, IRegion subject) {
2105             return hoverInfo;
2106           }
2107         };
2108
2109         fInformationPresenter.setOffset(offset);
2110         fInformationPresenter.setInformationProvider(informationProvider, contentType);
2111         fInformationPresenter.showInformation();
2112
2113       } catch (BadLocationException e) {
2114       }
2115     }
2116
2117     // modified version from TextViewer
2118     private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
2119
2120       StyledText styledText = textViewer.getTextWidget();
2121       IDocument document = textViewer.getDocument();
2122
2123       if (document == null)
2124         return -1;
2125
2126       try {
2127         int widgetLocation = styledText.getOffsetAtLocation(new Point(x, y));
2128         if (textViewer instanceof ITextViewerExtension3) {
2129           ITextViewerExtension3 extension = (ITextViewerExtension3) textViewer;
2130           return extension.widgetOffset2ModelOffset(widgetLocation);
2131         } else {
2132           IRegion visibleRegion = textViewer.getVisibleRegion();
2133           return widgetLocation + visibleRegion.getOffset();
2134         }
2135       } catch (IllegalArgumentException e) {
2136         return -1;
2137       }
2138
2139     }
2140   };
2141
2142   /**
2143    * This action implements smart home.
2144    * 
2145    * Instead of going to the start of a line it does the following:
2146    *  - if smart home/end is enabled and the caret is after the line's first non-whitespace then the caret is moved directly before
2147    * it, taking JavaDoc and multi-line comments into account. - if the caret is before the line's first non-whitespace the caret is
2148    * moved to the beginning of the line - if the caret is at the beginning of the line see first case.
2149    * 
2150    * @since 3.0
2151    */
2152   protected class SmartLineStartAction extends LineStartAction {
2153
2154     /**
2155      * Creates a new smart line start action
2156      * 
2157      * @param textWidget
2158      *          the styled text widget
2159      * @param doSelect
2160      *          a boolean flag which tells if the text up to the beginning of the line should be selected
2161      */
2162     public SmartLineStartAction(final StyledText textWidget, final boolean doSelect) {
2163       super(textWidget, doSelect);
2164     }
2165
2166     /*
2167      * @see org.eclipse.ui.texteditor.AbstractTextEditor.LineStartAction#getLineStartPosition(java.lang.String, int,
2168      *      java.lang.String)
2169      */
2170     protected int getLineStartPosition(final IDocument document, final String line, final int length, final int offset) {
2171
2172       String type = IDocument.DEFAULT_CONTENT_TYPE;
2173       try {
2174         type = TextUtilities.getContentType(document, IPHPPartitions.PHP_PARTITIONING, offset, true);
2175       } catch (BadLocationException exception) {
2176         // Should not happen
2177       }
2178
2179       int index = super.getLineStartPosition(document, line, length, offset);
2180       if (type.equals(IPHPPartitions.PHP_PHPDOC_COMMENT) || type.equals(IPHPPartitions.PHP_MULTILINE_COMMENT)) {
2181         if (index < length - 1 && line.charAt(index) == '*' && line.charAt(index + 1) != '/') {
2182           do {
2183             ++index;
2184           } while (index < length && Character.isWhitespace(line.charAt(index)));
2185         }
2186       } else {
2187         if (index < length - 1 && line.charAt(index) == '/' && line.charAt(index + 1) == '/') {
2188           index++;
2189           do {
2190             ++index;
2191           } while (index < length && Character.isWhitespace(line.charAt(index)));
2192         }
2193       }
2194       return index;
2195     }
2196   }
2197
2198   /**
2199    * Text navigation action to navigate to the next sub-word.
2200    * 
2201    * @since 3.0
2202    */
2203   protected abstract class NextSubWordAction extends TextNavigationAction {
2204
2205     protected JavaWordIterator fIterator = new JavaWordIterator();
2206
2207     /**
2208      * Creates a new next sub-word action.
2209      * 
2210      * @param code
2211      *          Action code for the default operation. Must be an action code from
2212      * @see org.eclipse.swt.custom.ST.
2213      */
2214     protected NextSubWordAction(int code) {
2215       super(getSourceViewer().getTextWidget(), code);
2216     }
2217
2218     /*
2219      * @see org.eclipse.jface.action.IAction#run()
2220      */
2221     public void run() {
2222       // Check whether we are in a java code partition and the preference is enabled
2223       final IPreferenceStore store = getPreferenceStore();
2224       if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
2225         super.run();
2226         return;
2227       }
2228
2229       final ISourceViewer viewer = getSourceViewer();
2230       final IDocument document = viewer.getDocument();
2231       fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document));
2232       int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2233       if (position == -1)
2234         return;
2235
2236       int next = findNextPosition(position);
2237       if (next != BreakIterator.DONE) {
2238         setCaretPosition(next);
2239         getTextWidget().showSelection();
2240         fireSelectionChanged();
2241       }
2242
2243     }
2244
2245     /**
2246      * Finds the next position after the given position.
2247      * 
2248      * @param position
2249      *          the current position
2250      * @return the next position
2251      */
2252     protected int findNextPosition(int position) {
2253       ISourceViewer viewer = getSourceViewer();
2254       int widget = -1;
2255       while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize
2256         position = fIterator.following(position);
2257         if (position != BreakIterator.DONE)
2258           widget = modelOffset2WidgetOffset(viewer, position);
2259       }
2260       return position;
2261     }
2262
2263     /**
2264      * Sets the caret position to the sub-word boundary given with <code>position</code>.
2265      * 
2266      * @param position
2267      *          Position where the action should move the caret
2268      */
2269     protected abstract void setCaretPosition(int position);
2270   }
2271
2272   /**
2273    * Text navigation action to navigate to the next sub-word.
2274    * 
2275    * @since 3.0
2276    */
2277   protected class NavigateNextSubWordAction extends NextSubWordAction {
2278
2279     /**
2280      * Creates a new navigate next sub-word action.
2281      */
2282     public NavigateNextSubWordAction() {
2283       super(ST.WORD_NEXT);
2284     }
2285
2286     /*
2287      * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2288      */
2289     protected void setCaretPosition(final int position) {
2290       getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position));
2291     }
2292   }
2293
2294   /**
2295    * Text operation action to delete the next sub-word.
2296    * 
2297    * @since 3.0
2298    */
2299   protected class DeleteNextSubWordAction extends NextSubWordAction implements IUpdate {
2300
2301     /**
2302      * Creates a new delete next sub-word action.
2303      */
2304     public DeleteNextSubWordAction() {
2305       super(ST.DELETE_WORD_NEXT);
2306     }
2307
2308     /*
2309      * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2310      */
2311     protected void setCaretPosition(final int position) {
2312       if (!validateEditorInputState())
2313         return;
2314
2315       final ISourceViewer viewer = getSourceViewer();
2316       final int caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2317
2318       try {
2319         viewer.getDocument().replace(caret, position - caret, ""); //$NON-NLS-1$
2320       } catch (BadLocationException exception) {
2321         // Should not happen
2322       }
2323     }
2324
2325     /*
2326      * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#findNextPosition(int)
2327      */
2328     protected int findNextPosition(int position) {
2329       return fIterator.following(position);
2330     }
2331
2332     /*
2333      * @see org.eclipse.ui.texteditor.IUpdate#update()
2334      */
2335     public void update() {
2336       setEnabled(isEditorInputModifiable());
2337     }
2338   }
2339
2340   /**
2341    * Text operation action to select the next sub-word.
2342    * 
2343    * @since 3.0
2344    */
2345   protected class SelectNextSubWordAction extends NextSubWordAction {
2346
2347     /**
2348      * Creates a new select next sub-word action.
2349      */
2350     public SelectNextSubWordAction() {
2351       super(ST.SELECT_WORD_NEXT);
2352     }
2353
2354     /*
2355      * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2356      */
2357     protected void setCaretPosition(final int position) {
2358       final ISourceViewer viewer = getSourceViewer();
2359
2360       final StyledText text = viewer.getTextWidget();
2361       if (text != null && !text.isDisposed()) {
2362
2363         final Point selection = text.getSelection();
2364         final int caret = text.getCaretOffset();
2365         final int offset = modelOffset2WidgetOffset(viewer, position);
2366
2367         if (caret == selection.x)
2368           text.setSelectionRange(selection.y, offset - selection.y);
2369         else
2370           text.setSelectionRange(selection.x, offset - selection.x);
2371       }
2372     }
2373   }
2374
2375   /**
2376    * Text navigation action to navigate to the previous sub-word.
2377    * 
2378    * @since 3.0
2379    */
2380   protected abstract class PreviousSubWordAction extends TextNavigationAction {
2381
2382     protected JavaWordIterator fIterator = new JavaWordIterator();
2383
2384     /**
2385      * Creates a new previous sub-word action.
2386      * 
2387      * @param code
2388      *          Action code for the default operation. Must be an action code from
2389      * @see org.eclipse.swt.custom.ST.
2390      */
2391     protected PreviousSubWordAction(final int code) {
2392       super(getSourceViewer().getTextWidget(), code);
2393     }
2394
2395     /*
2396      * @see org.eclipse.jface.action.IAction#run()
2397      */
2398     public void run() {
2399       // Check whether we are in a java code partition and the preference is enabled
2400       final IPreferenceStore store = getPreferenceStore();
2401       if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
2402         super.run();
2403         return;
2404       }
2405
2406       final ISourceViewer viewer = getSourceViewer();
2407       final IDocument document = viewer.getDocument();
2408       fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document));
2409       int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2410       if (position == -1)
2411         return;
2412
2413       int previous = findPreviousPosition(position);
2414       if (previous != BreakIterator.DONE) {
2415         setCaretPosition(previous);
2416         getTextWidget().showSelection();
2417         fireSelectionChanged();
2418       }
2419
2420     }
2421
2422     /**
2423      * Finds the previous position before the given position.
2424      * 
2425      * @param position
2426      *          the current position
2427      * @return the previous position
2428      */
2429     protected int findPreviousPosition(int position) {
2430       ISourceViewer viewer = getSourceViewer();
2431       int widget = -1;
2432       while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize
2433         position = fIterator.preceding(position);
2434         if (position != BreakIterator.DONE)
2435           widget = modelOffset2WidgetOffset(viewer, position);
2436       }
2437       return position;
2438     }
2439
2440     /**
2441      * Sets the caret position to the sub-word boundary given with <code>position</code>.
2442      * 
2443      * @param position
2444      *          Position where the action should move the caret
2445      */
2446     protected abstract void setCaretPosition(int position);
2447   }
2448
2449   /**
2450    * Text navigation action to navigate to the previous sub-word.
2451    * 
2452    * @since 3.0
2453    */
2454   protected class NavigatePreviousSubWordAction extends PreviousSubWordAction {
2455
2456     /**
2457      * Creates a new navigate previous sub-word action.
2458      */
2459     public NavigatePreviousSubWordAction() {
2460       super(ST.WORD_PREVIOUS);
2461     }
2462
2463     /*
2464      * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2465      */
2466     protected void setCaretPosition(final int position) {
2467       getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position));
2468     }
2469   }
2470
2471   /**
2472    * Text operation action to delete the previous sub-word.
2473    * 
2474    * @since 3.0
2475    */
2476   protected class DeletePreviousSubWordAction extends PreviousSubWordAction implements IUpdate {
2477
2478     /**
2479      * Creates a new delete previous sub-word action.
2480      */
2481     public DeletePreviousSubWordAction() {
2482       super(ST.DELETE_WORD_PREVIOUS);
2483     }
2484
2485     /*
2486      * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2487      */
2488     protected void setCaretPosition(final int position) {
2489       if (!validateEditorInputState())
2490         return;
2491
2492       final ISourceViewer viewer = getSourceViewer();
2493       final int caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2494
2495       try {
2496         viewer.getDocument().replace(position, caret - position, ""); //$NON-NLS-1$
2497       } catch (BadLocationException exception) {
2498         // Should not happen
2499       }
2500     }
2501
2502     /*
2503      * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#findPreviousPosition(int)
2504      */
2505     protected int findPreviousPosition(int position) {
2506       return fIterator.preceding(position);
2507     }
2508
2509     /*
2510      * @see org.eclipse.ui.texteditor.IUpdate#update()
2511      */
2512     public void update() {
2513       setEnabled(isEditorInputModifiable());
2514     }
2515   }
2516
2517   /**
2518    * Text operation action to select the previous sub-word.
2519    * 
2520    * @since 3.0
2521    */
2522   protected class SelectPreviousSubWordAction extends PreviousSubWordAction {
2523
2524     /**
2525      * Creates a new select previous sub-word action.
2526      */
2527     public SelectPreviousSubWordAction() {
2528       super(ST.SELECT_WORD_PREVIOUS);
2529     }
2530
2531     /*
2532      * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2533      */
2534     protected void setCaretPosition(final int position) {
2535       final ISourceViewer viewer = getSourceViewer();
2536
2537       final StyledText text = viewer.getTextWidget();
2538       if (text != null && !text.isDisposed()) {
2539
2540         final Point selection = text.getSelection();
2541         final int caret = text.getCaretOffset();
2542         final int offset = modelOffset2WidgetOffset(viewer, position);
2543
2544         if (caret == selection.x)
2545           text.setSelectionRange(selection.y, offset - selection.y);
2546         else
2547           text.setSelectionRange(selection.x, offset - selection.x);
2548       }
2549     }
2550   }
2551
2552   //  static protected class AnnotationAccess implements IAnnotationAccess {
2553   //    /*
2554   //     * @see
2555   // org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
2556   //     */
2557   //    public Object getType(Annotation annotation) {
2558   //      if (annotation instanceof IJavaAnnotation) {
2559   //        IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
2560   //   // if (javaAnnotation.isRelevant())
2561   //   // return javaAnnotation.getAnnotationType();
2562   //      }
2563   //      return null;
2564   //    }
2565   //
2566   //    /*
2567   //     * @see
2568   // org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
2569   //     */
2570   //    public boolean isMultiLine(Annotation annotation) {
2571   //      return true;
2572   //    }
2573   //
2574   //    /*
2575   //     * @see
2576   // org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
2577   //     */
2578   //    public boolean isTemporary(Annotation annotation) {
2579   //      if (annotation instanceof IJavaAnnotation) {
2580   //        IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
2581   //        if (javaAnnotation.isRelevant())
2582   //          return javaAnnotation.isTemporary();
2583   //      }
2584   //      return false;
2585   //    }
2586   //  };
2587
2588   private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
2589     /*
2590      * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
2591      */
2592     public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
2593       handlePreferencePropertyChanged(event);
2594     }
2595   };
2596
2597   /**
2598    * Finds and marks occurrence annotations.
2599    * 
2600    * @since 3.0
2601    */
2602   class OccurrencesFinderJob extends Job implements IDocumentListener {
2603
2604     private IDocument fDocument;
2605
2606     private boolean fCancelled = false;
2607
2608     private IProgressMonitor fProgressMonitor;
2609
2610     private Position[] fPositions;
2611
2612     public OccurrencesFinderJob(IDocument document, Position[] positions) {
2613       super("Occurrences Marker"); //$NON-NLS-1$
2614       fDocument = document;
2615       fPositions = positions;
2616       fDocument.addDocumentListener(this);
2617     }
2618
2619     private boolean isCancelled() {
2620       return fCancelled || fProgressMonitor.isCanceled();
2621     }
2622
2623     /*
2624      * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
2625      */
2626     public IStatus run(IProgressMonitor progressMonitor) {
2627
2628       fProgressMonitor = progressMonitor;
2629
2630       try {
2631
2632         if (isCancelled())
2633           return Status.CANCEL_STATUS;
2634
2635         ITextViewer textViewer = getViewer();
2636         if (textViewer == null)
2637           return Status.CANCEL_STATUS;
2638
2639         IDocument document = textViewer.getDocument();
2640         if (document == null)
2641           return Status.CANCEL_STATUS;
2642
2643         IDocumentProvider documentProvider = getDocumentProvider();
2644         if (documentProvider == null)
2645           return Status.CANCEL_STATUS;
2646
2647         IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
2648         if (annotationModel == null)
2649           return Status.CANCEL_STATUS;
2650
2651         // Add occurrence annotations
2652         int length = fPositions.length;
2653         Map annotationMap = new HashMap(length);
2654         for (int i = 0; i < length; i++) {
2655
2656           if (isCancelled())
2657             return Status.CANCEL_STATUS;
2658
2659           String message;
2660           Position position = fPositions[i];
2661
2662           // Create & add annotation
2663           try {
2664             message = document.get(position.offset, position.length);
2665           } catch (BadLocationException ex) {
2666             // Skip this match
2667             continue;
2668           }
2669           annotationMap.put(new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
2670               position);
2671         }
2672
2673         if (isCancelled())
2674           return Status.CANCEL_STATUS;
2675
2676         synchronized (annotationModel) {
2677           if (annotationModel instanceof IAnnotationModelExtension) {
2678             ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
2679           } else {
2680             removeOccurrenceAnnotations();
2681             Iterator iter = annotationMap.entrySet().iterator();
2682             while (iter.hasNext()) {
2683               Map.Entry mapEntry = (Map.Entry) iter.next();
2684               annotationModel.addAnnotation((Annotation) mapEntry.getKey(), (Position) mapEntry.getValue());
2685             }
2686           }
2687           fOccurrenceAnnotations = (Annotation[]) annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
2688         }
2689       } finally {
2690         fDocument.removeDocumentListener(this);
2691       }
2692       return Status.OK_STATUS;
2693     }
2694
2695     /*
2696      * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
2697      */
2698     public void documentAboutToBeChanged(DocumentEvent event) {
2699       fCancelled = true;
2700     }
2701
2702     /*
2703      * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
2704      */
2705     public void documentChanged(DocumentEvent event) {
2706     }
2707   }
2708
2709   /**
2710    * Updates the selection in the editor's widget with the selection of the outline page.
2711    */
2712   class OutlineSelectionChangedListener extends AbstractSelectionChangedListener {
2713     public void selectionChanged(SelectionChangedEvent event) {
2714       doSelectionChanged(event);
2715     }
2716   }
2717
2718   /**
2719    * Holds the current occurrence annotations.
2720    * 
2721    * @since 3.0
2722    */
2723   private Annotation[] fOccurrenceAnnotations = null;
2724
2725   private Job fOccurrencesFinderJob;
2726
2727   /** Preference key for showing the line number ruler */
2728   //  private final static String LINE_NUMBER_RULER =
2729   // PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
2730   /** Preference key for the foreground color of the line numbers */
2731   // private final static String LINE_NUMBER_COLOR =
2732   // PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
2733   /** Preference key for the link color */
2734   private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
2735
2736   /** Preference key for compiler task tags */
2737   private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
2738
2739   // protected PHPActionGroup fActionGroups;
2740   //  /** The outline page */
2741   //  private AbstractContentOutlinePage fOutlinePage;
2742   /** The outline page */
2743   protected JavaOutlinePage fOutlinePage;
2744
2745   /** Outliner context menu Id */
2746   protected String fOutlinerContextMenuId;
2747
2748   /**
2749    * Indicates whether this editor should react on outline page selection changes
2750    */
2751   private int fIgnoreOutlinePageSelection;
2752
2753   /** The outline page selection updater */
2754   //  private OutlinePageSelectionUpdater fUpdater;
2755   //  protected PHPSyntaxParserThread fValidationThread = null;
2756   // private IPreferenceStore fPHPPrefStore;
2757   /** The selection changed listener */
2758   //  protected ISelectionChangedListener fSelectionChangedListener = new
2759   // SelectionChangedListener();
2760   /**
2761    * The editor selection changed listener.
2762    * 
2763    * @since 3.0
2764    */
2765   private EditorSelectionChangedListener fEditorSelectionChangedListener;
2766
2767   /** The selection changed listener */
2768   protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener();
2769
2770   /** The editor's bracket matcher */
2771   private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS);
2772
2773   /** The line number ruler column */
2774   //  private LineNumberRulerColumn fLineNumberRulerColumn;
2775   /** This editor's encoding support */
2776   private DefaultEncodingSupport fEncodingSupport;
2777
2778   /** The mouse listener */
2779   private MouseClickListener fMouseListener;
2780
2781   /**
2782    * Indicates whether this editor is about to update any annotation views.
2783    * 
2784    * @since 3.0
2785    */
2786   private boolean fIsUpdatingAnnotationViews = false;
2787
2788   /**
2789    * The marker that served as last target for a goto marker request.
2790    * 
2791    * @since 3.0
2792    */
2793   private IMarker fLastMarkerTarget = null;
2794
2795   protected CompositeActionGroup fActionGroups;
2796
2797   protected CompositeActionGroup fContextMenuGroup;
2798
2799   /**
2800    * This editor's projection support
2801    * 
2802    * @since 3.0
2803    */
2804   private ProjectionSupport fProjectionSupport;
2805
2806   /**
2807    * This editor's projection model updater
2808    * 
2809    * @since 3.0
2810    */
2811   private IJavaFoldingStructureProvider fProjectionModelUpdater;
2812
2813   /**
2814    * The override and implements indicator manager for this editor.
2815    * 
2816    * @since 3.0
2817    */
2818   //    protected OverrideIndicatorManager fOverrideIndicatorManager;
2819   /**
2820    * The action group for folding.
2821    * 
2822    * @since 3.0
2823    */
2824   private FoldingActionGroup fFoldingGroup;
2825
2826   /** The information presenter. */
2827   private InformationPresenter fInformationPresenter;
2828
2829   /** The annotation access */
2830   //  protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
2831   /** The overview ruler */
2832   protected OverviewRuler isOverviewRulerVisible;
2833
2834   /** The source viewer decoration support */
2835   //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
2836   /** The overview ruler */
2837   //protected OverviewRuler fOverviewRuler;
2838   /** The preference property change listener for java core. */
2839   private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
2840
2841   /**
2842    * Returns the most narrow java element including the given offset
2843    * 
2844    * @param offset
2845    *          the offset inside of the requested element
2846    */
2847   abstract protected IJavaElement getElementAt(int offset);
2848
2849   /**
2850    * Returns the java element of this editor's input corresponding to the given IJavaElement
2851    */
2852   abstract protected IJavaElement getCorrespondingElement(IJavaElement element);
2853
2854   /**
2855    * Sets the input of the editor's outline page.
2856    */
2857   abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input);
2858
2859   /**
2860    * Default constructor.
2861    */
2862   public PHPEditor() {
2863     super();
2864   }
2865
2866   /*
2867    * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
2868    */
2869   protected void initializeKeyBindingScopes() {
2870     setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
2871   }
2872
2873   /*
2874    * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
2875    */
2876   protected void initializeEditor() {
2877     //jsurfer old code
2878     //    JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2879     //    setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this, IPHPPartitions.PHP_PARTITIONING)); //,
2880     // IJavaPartitions.JAVA_PARTITIONING));
2881     IPreferenceStore store = createCombinedPreferenceStore(null);
2882     setPreferenceStore(store);
2883     JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2884     setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
2885         IPHPPartitions.PHP_PARTITIONING));
2886     // TODO changed in 3.x ?
2887     //    setRangeIndicator(new DefaultRangeIndicator());
2888     //    if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
2889     //      fUpdater = new OutlinePageSelectionUpdater();
2890     // jsurfer end
2891
2892     //          IPreferenceStore store= createCombinedPreferenceStore(null);
2893     //          setPreferenceStore(store);
2894     //          JavaTextTools textTools=
2895     // PHPeclipsePlugin.getDefault().getJavaTextTools();
2896     //          setSourceViewerConfiguration(new
2897     // JavaSourceViewerConfiguration(textTools.getColorManager(), store,
2898     // this, IJavaPartitions.JAVA_PARTITIONING));
2899     //          fMarkOccurrenceAnnotations=
2900     // store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
2901     //          fStickyOccurrenceAnnotations=
2902     // store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
2903     //          fMarkTypeOccurrences=
2904     // store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
2905     //          fMarkMethodOccurrences=
2906     // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
2907     //          fMarkConstantOccurrences=
2908     // store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
2909     //          fMarkFieldOccurrences=
2910     // store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
2911     //          fMarkLocalVariableypeOccurrences=
2912     // store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
2913     //          fMarkExceptionOccurrences=
2914     // store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
2915     //          fMarkMethodExitPoints=
2916     // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
2917   }
2918
2919   /*
2920    * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
2921    */
2922   protected void updatePropertyDependentActions() {
2923     super.updatePropertyDependentActions();
2924     if (fEncodingSupport != null)
2925       fEncodingSupport.reset();
2926   }
2927
2928   /*
2929    * Update the hovering behavior depending on the preferences.
2930    */
2931   private void updateHoverBehavior() {
2932     SourceViewerConfiguration configuration = getSourceViewerConfiguration();
2933     String[] types = configuration.getConfiguredContentTypes(getSourceViewer());
2934
2935     for (int i = 0; i < types.length; i++) {
2936
2937       String t = types[i];
2938
2939       int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
2940
2941       ISourceViewer sourceViewer = getSourceViewer();
2942       if (sourceViewer instanceof ITextViewerExtension2) {
2943         if (stateMasks != null) {
2944           for (int j = 0; j < stateMasks.length; j++) {
2945             int stateMask = stateMasks[j];
2946             ITextHover textHover = configuration.getTextHover(sourceViewer, t, stateMask);
2947             ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, stateMask);
2948           }
2949         } else {
2950           ITextHover textHover = configuration.getTextHover(sourceViewer, t);
2951           ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
2952         }
2953       } else
2954         sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t);
2955     }
2956   }
2957
2958   public void updatedTitleImage(Image image) {
2959     setTitleImage(image);
2960   }
2961
2962   /*
2963    * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
2964    */
2965   public Object getViewPartInput() {
2966     return getEditorInput().getAdapter(IResource.class);
2967   }
2968
2969   /*
2970    * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
2971    */
2972   protected void doSetSelection(ISelection selection) {
2973     super.doSetSelection(selection);
2974     synchronizeOutlinePageSelection();
2975   }
2976
2977   boolean isFoldingEnabled() {
2978     return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
2979   }
2980
2981   /*
2982    * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt. widgets.Composite)
2983    */
2984   public void createPartControl(Composite parent) {
2985     super.createPartControl(parent);
2986
2987     //fSourceViewerDecorationSupport.install(getPreferenceStore());
2988
2989     ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
2990
2991     fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
2992     fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
2993     fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
2994     fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() {
2995       public IInformationControl createInformationControl(Shell shell) {
2996         return new CustomSourceInformationControl(shell, IDocument.DEFAULT_CONTENT_TYPE);
2997       }
2998     });
2999     fProjectionSupport.install();
3000
3001     fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
3002     if (fProjectionModelUpdater != null)
3003       fProjectionModelUpdater.install(this, projectionViewer);
3004
3005     if (isFoldingEnabled())
3006       projectionViewer.doOperation(ProjectionViewer.TOGGLE);
3007     Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
3008     preferences.addPropertyChangeListener(fPropertyChangeListener);
3009
3010     IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
3011       public IInformationControl createInformationControl(Shell parent) {
3012         boolean cutDown = false;
3013         int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
3014         return new DefaultInformationControl(parent, SWT.RESIZE, style, new HTMLTextPresenter(cutDown));
3015       }
3016     };
3017
3018     fInformationPresenter = new InformationPresenter(informationControlCreator);
3019     fInformationPresenter.setSizeConstraints(60, 10, true, true);
3020     fInformationPresenter.install(getSourceViewer());
3021
3022     fEditorSelectionChangedListener = new EditorSelectionChangedListener();
3023     fEditorSelectionChangedListener.install(getSelectionProvider());
3024
3025     if (isBrowserLikeLinks())
3026       enableBrowserLikeLinks();
3027
3028     if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE))
3029       enableOverwriteMode(false);
3030
3031     setWordWrap();
3032     //    getEditorSite().getShell().addShellListener(fActivationListener);
3033   }
3034
3035   private void setWordWrap() {
3036     if (getSourceViewer() != null) {
3037       getSourceViewer().getTextWidget().setWordWrap(
3038           PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_WRAP_WORDS));
3039     }
3040   }
3041
3042   protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
3043
3044     support.setCharacterPairMatcher(fBracketMatcher);
3045     support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
3046
3047     super.configureSourceViewerDecorationSupport(support);
3048   }
3049
3050   /*
3051    * @see org.eclipse.ui.texteditor.AbstractTextEditor#gotoMarker(org.eclipse.core.resources.IMarker)
3052    */
3053   public void gotoMarker(IMarker marker) {
3054     fLastMarkerTarget = marker;
3055     if (!fIsUpdatingAnnotationViews) {
3056       super.gotoMarker(marker);
3057     }
3058   }
3059
3060   /**
3061    * Jumps to the next enabled annotation according to the given direction. An annotation type is enabled if it is configured to be
3062    * in the Next/Previous tool bar drop down menu and if it is checked.
3063    * 
3064    * @param forward
3065    *          <code>true</code> if search direction is forward, <code>false</code> if backward
3066    */
3067   public void gotoAnnotation(boolean forward) {
3068     ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
3069     Position position = new Position(0, 0);
3070     if (false /* delayed - see bug 18316 */) {
3071       getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
3072       selectAndReveal(position.getOffset(), position.getLength());
3073     } else /* no delay - see bug 18316 */{
3074       Annotation annotation = getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
3075       setStatusLineErrorMessage(null);
3076       setStatusLineMessage(null);
3077       if (annotation != null) {
3078         updateAnnotationViews(annotation);
3079         selectAndReveal(position.getOffset(), position.getLength());
3080         setStatusLineMessage(annotation.getText());
3081       }
3082     }
3083   }
3084
3085   /**
3086    * Returns the lock object for the given annotation model.
3087    * 
3088    * @param annotationModel
3089    *          the annotation model
3090    * @return the annotation model's lock object
3091    * @since 3.0
3092    */
3093   private Object getLockObject(IAnnotationModel annotationModel) {
3094     if (annotationModel instanceof ISynchronizable)
3095       return ((ISynchronizable) annotationModel).getLockObject();
3096     else
3097       return annotationModel;
3098   }
3099
3100   /**
3101    * Updates the annotation views that show the given annotation.
3102    * 
3103    * @param annotation
3104    *          the annotation
3105    */
3106   private void updateAnnotationViews(Annotation annotation) {
3107     IMarker marker = null;
3108     if (annotation instanceof MarkerAnnotation)
3109       marker = ((MarkerAnnotation) annotation).getMarker();
3110     else if (annotation instanceof IJavaAnnotation) {
3111       Iterator e = ((IJavaAnnotation) annotation).getOverlaidIterator();
3112       if (e != null) {
3113         while (e.hasNext()) {
3114           Object o = e.next();
3115           if (o instanceof MarkerAnnotation) {
3116             marker = ((MarkerAnnotation) o).getMarker();
3117             break;
3118           }
3119         }
3120       }
3121     }
3122
3123     if (marker != null && !marker.equals(fLastMarkerTarget)) {
3124       try {
3125         boolean isProblem = marker.isSubtypeOf(IMarker.PROBLEM);
3126         IWorkbenchPage page = getSite().getPage();
3127         IViewPart view = page.findView(isProblem ? IPageLayout.ID_PROBLEM_VIEW : IPageLayout.ID_TASK_LIST); //$NON-NLS-1$  //$NON-NLS-2$
3128         if (view != null) {
3129           Method method = view.getClass().getMethod("setSelection", new Class[] { IStructuredSelection.class, boolean.class }); //$NON-NLS-1$
3130           method.invoke(view, new Object[] { new StructuredSelection(marker), Boolean.TRUE });
3131         }
3132       } catch (CoreException x) {
3133       } catch (NoSuchMethodException x) {
3134       } catch (IllegalAccessException x) {
3135       } catch (InvocationTargetException x) {
3136       }
3137       // ignore exceptions, don't update any of the lists, just set status line
3138     }
3139   }
3140
3141   /**
3142    * Returns this document's complete text.
3143    * 
3144    * @return the document's complete text
3145    */
3146   public String get() {
3147     IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
3148     return doc.get();
3149   }
3150
3151   /**
3152    * Sets the outliner's context menu ID.
3153    */
3154   protected void setOutlinerContextMenuId(String menuId) {
3155     fOutlinerContextMenuId = menuId;
3156   }
3157
3158   /**
3159    * Returns the standard action group of this editor.
3160    */
3161   protected ActionGroup getActionGroup() {
3162     return fActionGroups;
3163   }
3164
3165   //  public JavaOutlinePage getfOutlinePage() {
3166   //    return fOutlinePage;
3167   //  }
3168
3169   /**
3170    * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method extend the actions to add those
3171    * specific to the receiver
3172    */
3173   protected void createActions() {
3174     super.createActions();
3175
3176     ActionGroup oeg, ovg, jsg, sg;
3177     fActionGroups = new CompositeActionGroup(new ActionGroup[] { oeg = new OpenEditorActionGroup(this),
3178     //          sg= new ShowActionGroup(this),
3179         //              ovg= new OpenViewActionGroup(this),
3180         //              jsg= new JavaSearchActionGroup(this)
3181         });
3182     fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { oeg });
3183     //, ovg, sg, jsg});
3184
3185     fFoldingGroup = new FoldingActionGroup(this, getViewer());
3186
3187 //    ResourceAction resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
3188 //        "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
3189 //    resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(),
3190 //        "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
3191 //    resAction.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
3192 //    setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
3193     
3194     //  WorkbenchHelp.setHelp(resAction,
3195     // IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
3196
3197     Action action = new GotoMatchingBracketAction(this);
3198     action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
3199     setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
3200
3201     //  action= new
3202     // TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.",
3203     // this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
3204     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
3205     //  setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action);
3206     //// WorkbenchHelp.setHelp(action,
3207     // IJavaHelpContextIds.SHOW_OUTLINE_ACTION);
3208     //
3209     //  action= new
3210     // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.",
3211     // this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$
3212     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE);
3213     //  setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE,
3214     // action);
3215     //// WorkbenchHelp.setHelp(action,
3216     // IJavaHelpContextIds.OPEN_STRUCTURE_ACTION);
3217     //  
3218     //  action= new
3219     // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.",
3220     // this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
3221     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY);
3222     //  setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY,
3223     // action);
3224     //// WorkbenchHelp.setHelp(action,
3225     // IJavaHelpContextIds.OPEN_HIERARCHY_ACTION);
3226
3227     fEncodingSupport = new DefaultEncodingSupport();
3228     fEncodingSupport.initialize(this);
3229
3230     //  fSelectionHistory= new SelectionHistory(this);
3231     //
3232     //  action= new StructureSelectEnclosingAction(this, fSelectionHistory);
3233     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
3234     //  setAction(StructureSelectionAction.ENCLOSING, action);
3235     //
3236     //  action= new StructureSelectNextAction(this, fSelectionHistory);
3237     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
3238     //  setAction(StructureSelectionAction.NEXT, action);
3239     //
3240     //  action= new StructureSelectPreviousAction(this, fSelectionHistory);
3241     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
3242     //  setAction(StructureSelectionAction.PREVIOUS, action);
3243     //
3244     //  StructureSelectHistoryAction historyAction= new
3245     // StructureSelectHistoryAction(this, fSelectionHistory);
3246     //  historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
3247     //  setAction(StructureSelectionAction.HISTORY, historyAction);
3248     //  fSelectionHistory.setHistoryAction(historyAction);
3249     //                  
3250     //  action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this);
3251     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
3252     //  setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action);
3253     //
3254     //  action=
3255     // GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this);
3256     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
3257     //  setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
3258     //  
3259     //  action= new QuickFormatAction();
3260     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT);
3261     //  setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action);
3262     //
3263     //  action= new RemoveOccurrenceAnnotations(this);
3264     //  action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
3265     //  setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$
3266
3267     // add annotation actions
3268     action = new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
3269     setAction("AnnotationAction", action); //$NON-NLS-1$
3270   }
3271
3272   private void internalDoSetInput(IEditorInput input) throws CoreException {
3273     super.doSetInput(input);
3274
3275     if (getSourceViewer() instanceof JavaSourceViewer) {
3276       JavaSourceViewer viewer = (JavaSourceViewer) getSourceViewer();
3277       if (viewer.getReconciler() == null) {
3278         IReconciler reconciler = getSourceViewerConfiguration().getReconciler(viewer);
3279         if (reconciler != null) {
3280           reconciler.install(viewer);
3281           viewer.setReconciler(reconciler);
3282         }
3283       }
3284     }
3285
3286     if (fEncodingSupport != null)
3287       fEncodingSupport.reset();
3288
3289     setOutlinePageInput(fOutlinePage, input);
3290
3291     if (fProjectionModelUpdater != null)
3292       fProjectionModelUpdater.initialize();
3293
3294     //        if (isShowingOverrideIndicators())
3295     //                  installOverrideIndicator(false);
3296   }
3297
3298   /*
3299    * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)
3300    * @since 3.0
3301    */
3302   protected void setPreferenceStore(IPreferenceStore store) {
3303     super.setPreferenceStore(store);
3304     if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) {
3305       JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
3306       setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
3307           IPHPPartitions.PHP_PARTITIONING));
3308     }
3309     if (getSourceViewer() instanceof JavaSourceViewer)
3310       ((JavaSourceViewer) getSourceViewer()).setPreferenceStore(store);
3311   }
3312
3313   /**
3314    * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra disposal
3315    * actions required by the php editor.
3316    */
3317   public void dispose() {
3318     if (fProjectionModelUpdater != null) {
3319       fProjectionModelUpdater.uninstall();
3320       fProjectionModelUpdater = null;
3321     }
3322
3323     if (fProjectionSupport != null) {
3324       fProjectionSupport.dispose();
3325       fProjectionSupport = null;
3326     }
3327     //   PHPEditorEnvironment.disconnect(this);
3328     if (fOutlinePage != null)
3329       fOutlinePage.setInput(null);
3330
3331     if (fActionGroups != null)
3332       fActionGroups.dispose();
3333
3334     if (isBrowserLikeLinks())
3335       disableBrowserLikeLinks();
3336
3337     if (fEncodingSupport != null) {
3338       fEncodingSupport.dispose();
3339       fEncodingSupport = null;
3340     }
3341
3342     if (fPropertyChangeListener != null) {
3343       Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
3344       preferences.removePropertyChangeListener(fPropertyChangeListener);
3345       fPropertyChangeListener = null;
3346     }
3347
3348     //    if (fSourceViewerDecorationSupport != null) {
3349     //      fSourceViewerDecorationSupport.dispose();
3350     //      fSourceViewerDecorationSupport = null;
3351     //    }
3352
3353     if (fBracketMatcher != null) {
3354       fBracketMatcher.dispose();
3355       fBracketMatcher = null;
3356     }
3357
3358     if (fEditorSelectionChangedListener != null) {
3359       fEditorSelectionChangedListener.uninstall(getSelectionProvider());
3360       fEditorSelectionChangedListener = null;
3361     }
3362
3363     super.dispose();
3364   }
3365
3366   /**
3367    * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra revert behavior
3368    * required by the php editor.
3369    */
3370   //  public void doRevertToSaved() {
3371   //    super.doRevertToSaved();
3372   //    if (fOutlinePage != null)
3373   //      fOutlinePage.update();
3374   //  }
3375   /**
3376    * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra save behavior
3377    * required by the php editor.
3378    */
3379   //  public void doSave(IProgressMonitor monitor) {
3380   //    super.doSave(monitor);
3381   // compile or not, according to the user preferences
3382   // IPreferenceStore store = getPreferenceStore();
3383   // the parse on save was changed to the eclipse "builders" concept
3384   //    if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
3385   //      IAction a = PHPParserAction.getInstance();
3386   //      if (a != null)
3387   //        a.run();
3388   //    }
3389   //    if (SWT.getPlatform().equals("win32")) {
3390   //      IAction a = ShowExternalPreviewAction.getInstance();
3391   //      if (a != null)
3392   //        a.run();
3393   //    }
3394   //    if (fOutlinePage != null)
3395   //      fOutlinePage.update();
3396   //  }
3397   /**
3398    * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra save as
3399    * behavior required by the php editor.
3400    */
3401   //  public void doSaveAs() {
3402   //    super.doSaveAs();
3403   //    if (fOutlinePage != null)
3404   //      fOutlinePage.update();
3405   //  }
3406   /*
3407    * @see StatusTextEditor#getStatusHeader(IStatus)
3408    */
3409   protected String getStatusHeader(IStatus status) {
3410     if (fEncodingSupport != null) {
3411       String message = fEncodingSupport.getStatusHeader(status);
3412       if (message != null)
3413         return message;
3414     }
3415     return super.getStatusHeader(status);
3416   }
3417
3418   /*
3419    * @see StatusTextEditor#getStatusBanner(IStatus)
3420    */
3421   protected String getStatusBanner(IStatus status) {
3422     if (fEncodingSupport != null) {
3423       String message = fEncodingSupport.getStatusBanner(status);
3424       if (message != null)
3425         return message;
3426     }
3427     return super.getStatusBanner(status);
3428   }
3429
3430   /*
3431    * @see StatusTextEditor#getStatusMessage(IStatus)
3432    */
3433   protected String getStatusMessage(IStatus status) {
3434     if (fEncodingSupport != null) {
3435       String message = fEncodingSupport.getStatusMessage(status);
3436       if (message != null)
3437         return message;
3438     }
3439     return super.getStatusMessage(status);
3440   }
3441
3442   /**
3443    * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs sets the input of the
3444    * outline page after AbstractTextEditor has set input.
3445    */
3446   //  protected void doSetInput(IEditorInput input) throws CoreException {
3447   //    super.doSetInput(input);
3448   //    if (fEncodingSupport != null)
3449   //      fEncodingSupport.reset();
3450   //    setOutlinePageInput(fOutlinePage, input);
3451   //  }
3452   /*
3453    * @see AbstractTextEditor#doSetInput
3454    */
3455   protected void doSetInput(IEditorInput input) throws CoreException {
3456     ISourceViewer sourceViewer = getSourceViewer();
3457     if (!(sourceViewer instanceof ISourceViewerExtension2)) {
3458       setPreferenceStore(createCombinedPreferenceStore(input));
3459       internalDoSetInput(input);
3460       return;
3461     }
3462
3463     // uninstall & unregister preference store listener
3464     if (isBrowserLikeLinks())
3465       disableBrowserLikeLinks();
3466     getSourceViewerDecorationSupport(sourceViewer).uninstall();
3467     ((ISourceViewerExtension2) sourceViewer).unconfigure();
3468
3469     setPreferenceStore(createCombinedPreferenceStore(input));
3470
3471     // install & register preference store listener
3472     sourceViewer.configure(getSourceViewerConfiguration());
3473     getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
3474     if (isBrowserLikeLinks())
3475       enableBrowserLikeLinks();
3476
3477     internalDoSetInput(input);
3478   }
3479
3480   /*
3481    * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
3482    */
3483   //  public Object getViewPartInput() {
3484   //    return getEditorInput().getAdapter(IFile.class);
3485   //  }
3486   /**
3487    * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method adds any PHPEditor specific
3488    * entries.
3489    */
3490   public void editorContextMenuAboutToShow(MenuManager menu) {
3491     super.editorContextMenuAboutToShow(menu);
3492     menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, new Separator(IContextMenuConstants.GROUP_OPEN));
3493     menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));
3494
3495     ActionContext context = new ActionContext(getSelectionProvider().getSelection());
3496     fContextMenuGroup.setContext(context);
3497     fContextMenuGroup.fillContextMenu(menu);
3498     fContextMenuGroup.setContext(null);
3499     //    addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format");
3500     // //$NON-NLS-1$
3501     //
3502     //    ActionContext context =
3503     //      new ActionContext(getSelectionProvider().getSelection());
3504     //    fContextMenuGroup.setContext(context);
3505     //    fContextMenuGroup.fillContextMenu(menu);
3506     //    fContextMenuGroup.setContext(null);
3507   }
3508
3509   /**
3510    * Creates the outline page used with this editor.
3511    */
3512   protected JavaOutlinePage createOutlinePage() {
3513     JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this);
3514     fOutlineSelectionChangedListener.install(page);
3515     setOutlinePageInput(page, getEditorInput());
3516     return page;
3517   }
3518
3519   /**
3520    * Informs the editor that its outliner has been closed.
3521    */
3522   public void outlinePageClosed() {
3523     if (fOutlinePage != null) {
3524       fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3525       fOutlinePage = null;
3526       resetHighlightRange();
3527     }
3528   }
3529
3530   /**
3531    * Synchronizes the outliner selection with the given element position in the editor.
3532    * 
3533    * @param element
3534    *          the java element to select
3535    */
3536   protected void synchronizeOutlinePage(ISourceReference element) {
3537     synchronizeOutlinePage(element, true);
3538   }
3539
3540   /**
3541    * Synchronizes the outliner selection with the given element position in the editor.
3542    * 
3543    * @param element
3544    *          the java element to select
3545    * @param checkIfOutlinePageActive
3546    *          <code>true</code> if check for active outline page needs to be done
3547    */
3548   protected void synchronizeOutlinePage(ISourceReference element, boolean checkIfOutlinePageActive) {
3549     if (fOutlinePage != null && element != null && !(checkIfOutlinePageActive && isJavaOutlinePageActive())) {
3550       fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3551       fOutlinePage.select(element);
3552       fOutlineSelectionChangedListener.install(fOutlinePage);
3553     }
3554   }
3555
3556   /**
3557    * Synchronizes the outliner selection with the actual cursor position in the editor.
3558    */
3559   public void synchronizeOutlinePageSelection() {
3560     synchronizeOutlinePage(computeHighlightRangeSourceReference());
3561
3562     //    ISourceViewer sourceViewer = getSourceViewer();
3563     //    if (sourceViewer == null || fOutlinePage == null)
3564     //      return;
3565     //
3566     //    StyledText styledText = sourceViewer.getTextWidget();
3567     //    if (styledText == null)
3568     //      return;
3569     //
3570     //    int caret = 0;
3571     //    if (sourceViewer instanceof ITextViewerExtension3) {
3572     //      ITextViewerExtension3 extension = (ITextViewerExtension3)
3573     // sourceViewer;
3574     //      caret =
3575     // extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
3576     //    } else {
3577     //      int offset = sourceViewer.getVisibleRegion().getOffset();
3578     //      caret = offset + styledText.getCaretOffset();
3579     //    }
3580     //
3581     //    IJavaElement element = getElementAt(caret);
3582     //    if (element instanceof ISourceReference) {
3583     //      fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
3584     //      fOutlinePage.select((ISourceReference) element);
3585     //      fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
3586     //    }
3587   }
3588
3589   protected void setSelection(ISourceReference reference, boolean moveCursor) {
3590
3591     ISelection selection = getSelectionProvider().getSelection();
3592     if (selection instanceof TextSelection) {
3593       TextSelection textSelection = (TextSelection) selection;
3594       if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
3595         markInNavigationHistory();
3596     }
3597
3598     if (reference != null) {
3599
3600       StyledText textWidget = null;
3601
3602       ISourceViewer sourceViewer = getSourceViewer();
3603       if (sourceViewer != null)
3604         textWidget = sourceViewer.getTextWidget();
3605
3606       if (textWidget == null)
3607         return;
3608
3609       try {
3610
3611         ISourceRange range = reference.getSourceRange();
3612         if (range == null)
3613           return;
3614
3615         int offset = range.getOffset();
3616         int length = range.getLength();
3617
3618         if (offset < 0 || length < 0)
3619           return;
3620
3621         textWidget.setRedraw(false);
3622
3623         setHighlightRange(offset, length, moveCursor);
3624
3625         if (!moveCursor)
3626           return;
3627
3628         offset = -1;
3629         length = -1;
3630
3631         if (reference instanceof IMember) {
3632           range = ((IMember) reference).getNameRange();
3633           if (range != null) {
3634             offset = range.getOffset();
3635             length = range.getLength();
3636           }
3637         }
3638         //                                      else if (reference instanceof IImportDeclaration) {
3639         //                                              String name= ((IImportDeclaration)
3640         // reference).getElementName();
3641         //                                              if (name != null && name.length() > 0) {
3642         //                                                      String content= reference.getSource();
3643         //                                                      if (content != null) {
3644         //                                                              offset= range.getOffset() + content.indexOf(name);
3645         //                                                              length= name.length();
3646         //                                                      }
3647         //                                              }
3648         //                                      } else if (reference instanceof IPackageDeclaration) {
3649         //                                              String name= ((IPackageDeclaration)
3650         // reference).getElementName();
3651         //                                              if (name != null && name.length() > 0) {
3652         //                                                      String content= reference.getSource();
3653         //                                                      if (content != null) {
3654         //                                                              offset= range.getOffset() + content.indexOf(name);
3655         //                                                              length= name.length();
3656         //                                                      }
3657         //                                              }
3658         //                                      }
3659
3660         if (offset > -1 && length > 0) {
3661           sourceViewer.revealRange(offset, length);
3662           sourceViewer.setSelectedRange(offset, length);
3663         }
3664
3665       } catch (JavaModelException x) {
3666       } catch (IllegalArgumentException x) {
3667       } finally {
3668         if (textWidget != null)
3669           textWidget.setRedraw(true);
3670       }
3671
3672     } else if (moveCursor) {
3673       resetHighlightRange();
3674     }
3675
3676     markInNavigationHistory();
3677   }
3678
3679   public void setSelection(IJavaElement element) {
3680     if (element == null || element instanceof ICompilationUnit) { // ||
3681       // element
3682       // instanceof
3683       // IClassFile)
3684       // {
3685       /*
3686        * If the element is an ICompilationUnit this unit is either the input of this editor or not being displayed. In both cases,
3687        * nothing should happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
3688        */
3689       return;
3690     }
3691
3692     IJavaElement corresponding = getCorrespondingElement(element);
3693     if (corresponding instanceof ISourceReference) {
3694       ISourceReference reference = (ISourceReference) corresponding;
3695       // set highlight range
3696       setSelection(reference, true);
3697       // set outliner selection
3698       if (fOutlinePage != null) {
3699         fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3700         fOutlinePage.select(reference);
3701         fOutlineSelectionChangedListener.install(fOutlinePage);
3702       }
3703     }
3704   }
3705
3706   public synchronized void editingScriptStarted() {
3707     ++fIgnoreOutlinePageSelection;
3708   }
3709
3710   public synchronized void editingScriptEnded() {
3711     --fIgnoreOutlinePageSelection;
3712   }
3713
3714   public synchronized boolean isEditingScriptRunning() {
3715     return (fIgnoreOutlinePageSelection > 0);
3716   }
3717
3718   /**
3719    * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs gets the java content
3720    * outline page if request is for a an outline page.
3721    */
3722   public Object getAdapter(Class required) {
3723
3724     if (IContentOutlinePage.class.equals(required)) {
3725       if (fOutlinePage == null)
3726         fOutlinePage = createOutlinePage();
3727       return fOutlinePage;
3728     }
3729
3730     if (IEncodingSupport.class.equals(required))
3731       return fEncodingSupport;
3732
3733     if (required == IShowInTargetList.class) {
3734       return new IShowInTargetList() {
3735         public String[] getShowInTargetIds() {
3736           return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
3737         }
3738
3739       };
3740     }
3741     if (fProjectionSupport != null) {
3742       Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
3743       if (adapter != null)
3744         return adapter;
3745     }
3746
3747     return super.getAdapter(required);
3748   }
3749
3750   //  public Object getAdapter(Class required) {
3751   //    if (IContentOutlinePage.class.equals(required)) {
3752   //      if (fOutlinePage == null) {
3753   //        fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
3754   //        if (getEditorInput() != null)
3755   //          fOutlinePage.setInput(getEditorInput());
3756   //      }
3757   //      return fOutlinePage;
3758   //    }
3759   //
3760   //    if (IEncodingSupport.class.equals(required))
3761   //      return fEncodingSupport;
3762   //
3763   //    return super.getAdapter(required);
3764   //  }
3765
3766   protected void doSelectionChanged(SelectionChangedEvent event) {
3767     ISourceReference reference = null;
3768
3769     ISelection selection = event.getSelection();
3770     Iterator iter = ((IStructuredSelection) selection).iterator();
3771     while (iter.hasNext()) {
3772       Object o = iter.next();
3773       if (o instanceof ISourceReference) {
3774         reference = (ISourceReference) o;
3775         break;
3776       }
3777     }
3778
3779     if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
3780       PHPeclipsePlugin.getActivePage().bringToTop(this);
3781
3782     try {
3783       editingScriptStarted();
3784       setSelection(reference, !isActivePart());
3785     } finally {
3786       editingScriptEnded();
3787     }
3788   }
3789
3790   /*
3791    * @see AbstractTextEditor#adjustHighlightRange(int, int)
3792    */
3793   protected void adjustHighlightRange(int offset, int length) {
3794
3795     try {
3796
3797       IJavaElement element = getElementAt(offset);
3798       while (element instanceof ISourceReference) {
3799         ISourceRange range = ((ISourceReference) element).getSourceRange();
3800         if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) {
3801
3802           ISourceViewer viewer = getSourceViewer();
3803           if (viewer instanceof ITextViewerExtension5) {
3804             ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
3805             extension.exposeModelRange(new Region(range.getOffset(), range.getLength()));
3806           }
3807
3808           setHighlightRange(range.getOffset(), range.getLength(), true);
3809           if (fOutlinePage != null) {
3810             fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3811             fOutlinePage.select((ISourceReference) element);
3812             fOutlineSelectionChangedListener.install(fOutlinePage);
3813           }
3814
3815           return;
3816         }
3817         element = element.getParent();
3818       }
3819
3820     } catch (JavaModelException x) {
3821       PHPeclipsePlugin.log(x.getStatus());
3822     }
3823
3824     ISourceViewer viewer = getSourceViewer();
3825     if (viewer instanceof ITextViewerExtension5) {
3826       ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
3827       extension.exposeModelRange(new Region(offset, length));
3828     } else {
3829       resetHighlightRange();
3830     }
3831
3832   }
3833
3834   protected boolean isActivePart() {
3835     IWorkbenchWindow window = getSite().getWorkbenchWindow();
3836     IPartService service = window.getPartService();
3837     IWorkbenchPart part = service.getActivePart();
3838     return part != null && part.equals(this);
3839   }
3840
3841   //  public void openContextHelp() {
3842   //    IDocument doc =
3843   // this.getDocumentProvider().getDocument(this.getEditorInput());
3844   //    ITextSelection selection = (ITextSelection)
3845   // this.getSelectionProvider().getSelection();
3846   //    int pos = selection.getOffset();
3847   //    String word = getFunctionName(doc, pos);
3848   //    openContextHelp(word);
3849   //  }
3850   //
3851   //  private void openContextHelp(String word) {
3852   //    open(word);
3853   //  }
3854   //
3855   //  public static void open(String word) {
3856   //    IHelp help = WorkbenchHelp.getHelpSupport();
3857   //    if (help != null) {
3858   //      IHelpResource helpResource = new PHPFunctionHelpResource(word);
3859   //      WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
3860   //    } else {
3861   //      // showMessage(shell, dialogTitle, ActionMessages.getString("Open help
3862   // not available"), false); //$NON-NLS-1$
3863   //    }
3864   //  }
3865
3866   //    private String getFunctionName(IDocument doc, int pos) {
3867   //            Point word = PHPWordExtractor.findWord(doc, pos);
3868   //            if (word != null) {
3869   //                    try {
3870   //                            return doc.get(word.x, word.y).replace('_', '-');
3871   //                    } catch (BadLocationException e) {
3872   //                    }
3873   //            }
3874   //            return "";
3875   //    }
3876
3877   /*
3878    * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
3879    */
3880   protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
3881
3882     try {
3883
3884       ISourceViewer sourceViewer = getSourceViewer();
3885       if (sourceViewer == null)
3886         return;
3887
3888       String property = event.getProperty();
3889
3890       if (PreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
3891         Object value = event.getNewValue();
3892         if (value instanceof Integer) {
3893           sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
3894         } else if (value instanceof String) {
3895           try {
3896             sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
3897           } catch (NumberFormatException e) {
3898             // bug #1038071 - set default tab:
3899             sourceViewer.getTextWidget().setTabs(80);
3900           }
3901         }
3902         return;
3903       }
3904
3905       //      if (OVERVIEW_RULER.equals(property)) {
3906       //        if (isOverviewRulerVisible())
3907       //          showOverviewRuler();
3908       //        else
3909       //          hideOverviewRuler();
3910       //        return;
3911       //      }
3912
3913       //      if (LINE_NUMBER_RULER.equals(property)) {
3914       //        if (isLineNumberRulerVisible())
3915       //          showLineNumberRuler();
3916       //        else
3917       //          hideLineNumberRuler();
3918       //        return;
3919       //      }
3920
3921       //      if (fLineNumberRulerColumn != null
3922       //        && (LINE_NUMBER_COLOR.equals(property) ||
3923       // PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) ||
3924       // PREFERENCE_COLOR_BACKGROUND.equals(property))) {
3925       //
3926       //        initializeLineNumberRulerColumn(fLineNumberRulerColumn);
3927       //      }
3928
3929       if (isJavaEditorHoverProperty(property))
3930         updateHoverBehavior();
3931
3932       if (BROWSER_LIKE_LINKS.equals(property)) {
3933         if (isBrowserLikeLinks())
3934           enableBrowserLikeLinks();
3935         else
3936           disableBrowserLikeLinks();
3937         return;
3938       }
3939
3940       if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) {
3941         if ((event.getNewValue() instanceof Boolean) && ((Boolean) event.getNewValue()).booleanValue())
3942           selectionChanged();
3943         return;
3944       }
3945
3946       if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) {
3947         if (event.getNewValue() instanceof Boolean) {
3948           Boolean disable = (Boolean) event.getNewValue();
3949           enableOverwriteMode(!disable.booleanValue());
3950         }
3951         return;
3952       }
3953
3954       //        if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property))
3955       // {
3956       //                if (event.getNewValue() instanceof Boolean) {
3957       //                        boolean markOccurrenceAnnotations=
3958       // ((Boolean)event.getNewValue()).booleanValue();
3959       //                        if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) {
3960       //                                fMarkOccurrenceAnnotations= markOccurrenceAnnotations;
3961       //                                if (!fMarkOccurrenceAnnotations)
3962       //                                        uninstallOccurrencesFinder();
3963       //                                else
3964       //                                        installOccurrencesFinder();
3965       //                        }
3966       //                }
3967       //        }
3968       //        if
3969       // (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property))
3970       // {
3971       //                if (event.getNewValue() instanceof Boolean) {
3972       //                        boolean stickyOccurrenceAnnotations=
3973       // ((Boolean)event.getNewValue()).booleanValue();
3974       //                        if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations)
3975       // {
3976       //                                fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations;
3977       //// if (!fMarkOccurrenceAnnotations)
3978       //// uninstallOccurrencesFinder();
3979       //// else
3980       //// installOccurrencesFinder();
3981       //                        }
3982       //                }
3983       //        }
3984
3985       ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
3986
3987       //                if (affectsOverrideIndicatorAnnotations(event)) {
3988       //                        if (isShowingOverrideIndicators()) {
3989       //                                if (fOverrideIndicatorManager == null)
3990       //                                        installOverrideIndicator(true);
3991       //                        } else {
3992       //                                if (fOverrideIndicatorManager != null)
3993       //                                        uninstallOverrideIndicator();
3994       //                        }
3995       //                        return;
3996       //                }
3997
3998       if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
3999         if (sourceViewer instanceof ProjectionViewer) {
4000           ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer;
4001           if (fProjectionModelUpdater != null)
4002             fProjectionModelUpdater.uninstall();
4003           // either freshly enabled or provider changed
4004           fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
4005           if (fProjectionModelUpdater != null) {
4006             fProjectionModelUpdater.install(this, projectionViewer);
4007           }
4008         }
4009         return;
4010       }
4011     } finally {
4012       super.handlePreferenceStoreChanged(event);
4013     }
4014   }
4015
4016   //  /*
4017   //     * @see
4018   // AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
4019   //     */
4020   //  protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
4021   //
4022   //    try {
4023   //
4024   //      ISourceViewer sourceViewer = getSourceViewer();
4025   //      if (sourceViewer == null)
4026   //        return;
4027   //
4028   //      String property = event.getProperty();
4029   //
4030   //      // if
4031   // (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
4032   //      // Object value= event.getNewValue();
4033   //      // if (value instanceof Integer) {
4034   //      // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
4035   //      // } else if (value instanceof String) {
4036   //      // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String)
4037   // value));
4038   //      // }
4039   //      // return;
4040   //      // }
4041   //
4042   //      if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
4043   //        if (isLineNumberRulerVisible())
4044   //          showLineNumberRuler();
4045   //        else
4046   //          hideLineNumberRuler();
4047   //        return;
4048   //      }
4049   //
4050   //      if (fLineNumberRulerColumn != null
4051   //        && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
4052   //          || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
4053   //          || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
4054   //
4055   //        initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4056   //      }
4057   //
4058   //    } finally {
4059   //      super.handlePreferenceStoreChanged(event);
4060   //    }
4061   //  }
4062
4063   //  private boolean isJavaEditorHoverProperty(String property) {
4064   //    return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
4065   //      || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
4066   //      || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
4067   //      || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
4068   //      || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
4069   //      || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
4070   //      || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
4071   //      || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
4072   //  }
4073
4074   /**
4075    * Shows the line number ruler column.
4076    */
4077   //  private void showLineNumberRuler() {
4078   //    IVerticalRuler v = getVerticalRuler();
4079   //    if (v instanceof CompositeRuler) {
4080   //      CompositeRuler c = (CompositeRuler) v;
4081   //      c.addDecorator(1, createLineNumberRulerColumn());
4082   //    }
4083   //  }
4084   private boolean isJavaEditorHoverProperty(String property) {
4085     return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property);
4086   }
4087
4088   /**
4089    * Return whether the browser like links should be enabled according to the preference store settings.
4090    * 
4091    * @return <code>true</code> if the browser like links should be enabled
4092    */
4093   private boolean isBrowserLikeLinks() {
4094     IPreferenceStore store = getPreferenceStore();
4095     return store.getBoolean(BROWSER_LIKE_LINKS);
4096   }
4097
4098   /**
4099    * Enables browser like links.
4100    */
4101   private void enableBrowserLikeLinks() {
4102     if (fMouseListener == null) {
4103       fMouseListener = new MouseClickListener();
4104       fMouseListener.install();
4105     }
4106   }
4107
4108   /**
4109    * Disables browser like links.
4110    */
4111   private void disableBrowserLikeLinks() {
4112     if (fMouseListener != null) {
4113       fMouseListener.uninstall();
4114       fMouseListener = null;
4115     }
4116   }
4117
4118   /**
4119    * Handles a property change event describing a change of the java core's preferences and updates the preference related editor
4120    * properties.
4121    * 
4122    * @param event
4123    *          the property change event
4124    */
4125   protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
4126     if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
4127       ISourceViewer sourceViewer = getSourceViewer();
4128       if (sourceViewer != null
4129           && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event
4130               .getNewValue())))
4131         sourceViewer.invalidateTextPresentation();
4132     }
4133     if (PreferenceConstants.EDITOR_WRAP_WORDS.equals(event.getProperty())) {
4134       setWordWrap();
4135     }
4136   }
4137
4138   /**
4139    * Return whether the line number ruler column should be visible according to the preference store settings.
4140    * 
4141    * @return <code>true</code> if the line numbers should be visible
4142    */
4143   //  protected boolean isLineNumberRulerVisible() {
4144   //    IPreferenceStore store = getPreferenceStore();
4145   //    return store.getBoolean(LINE_NUMBER_RULER);
4146   //  }
4147   /**
4148    * Hides the line number ruler column.
4149    */
4150   //  private void hideLineNumberRuler() {
4151   //    IVerticalRuler v = getVerticalRuler();
4152   //    if (v instanceof CompositeRuler) {
4153   //      CompositeRuler c = (CompositeRuler) v;
4154   //      try {
4155   //        c.removeDecorator(1);
4156   //      } catch (Throwable e) {
4157   //      }
4158   //    }
4159   //  }
4160   /*
4161    * @see AbstractTextEditor#handleCursorPositionChanged()
4162    */
4163   //  protected void handleCursorPositionChanged() {
4164   //    super.handleCursorPositionChanged();
4165   //    if (!isEditingScriptRunning() && fUpdater != null)
4166   //      fUpdater.post();
4167   //  }
4168   /*
4169    * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced()
4170    */
4171   protected void handleElementContentReplaced() {
4172     super.handleElementContentReplaced();
4173     if (fProjectionModelUpdater != null)
4174       fProjectionModelUpdater.initialize();
4175   }
4176
4177   /**
4178    * Initializes the given line number ruler column from the preference store.
4179    * 
4180    * @param rulerColumn
4181    *          the ruler column to be initialized
4182    */
4183   //  protected void initializeLineNumberRulerColumn(LineNumberRulerColumn
4184   // rulerColumn) {
4185   //    JavaTextTools textTools =
4186   // PHPeclipsePlugin.getDefault().getJavaTextTools();
4187   //    IColorManager manager = textTools.getColorManager();
4188   //
4189   //    IPreferenceStore store = getPreferenceStore();
4190   //    if (store != null) {
4191   //
4192   //      RGB rgb = null;
4193   //      // foreground color
4194   //      if (store.contains(LINE_NUMBER_COLOR)) {
4195   //        if (store.isDefault(LINE_NUMBER_COLOR))
4196   //          rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
4197   //        else
4198   //          rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
4199   //      }
4200   //      rulerColumn.setForeground(manager.getColor(rgb));
4201   //
4202   //      rgb = null;
4203   //      // background color
4204   //      if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
4205   //        if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
4206   //          if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
4207   //            rgb = PreferenceConverter.getDefaultColor(store,
4208   // PREFERENCE_COLOR_BACKGROUND);
4209   //          else
4210   //            rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
4211   //        }
4212   //      }
4213   //      rulerColumn.setBackground(manager.getColor(rgb));
4214   //    }
4215   //  }
4216   /**
4217    * Creates a new line number ruler column that is appropriately initialized.
4218    */
4219   //  protected IVerticalRulerColumn createLineNumberRulerColumn() {
4220   //    fLineNumberRulerColumn = new LineNumberRulerColumn();
4221   //    initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4222   //    return fLineNumberRulerColumn;
4223   //  }
4224   /*
4225    * @see AbstractTextEditor#createVerticalRuler()
4226    */
4227   //  protected IVerticalRuler createVerticalRuler() {
4228   //    CompositeRuler ruler = new CompositeRuler();
4229   //    ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
4230   //    if (isLineNumberRulerVisible())
4231   //      ruler.addDecorator(1, createLineNumberRulerColumn());
4232   //    return ruler;
4233   //  }
4234   //  private static IRegion getSignedSelection(ITextViewer viewer) {
4235   //
4236   //    StyledText text = viewer.getTextWidget();
4237   //    int caretOffset = text.getCaretOffset();
4238   //    Point selection = text.getSelection();
4239   //
4240   //    // caret left
4241   //    int offset, length;
4242   //    if (caretOffset == selection.x) {
4243   //      offset = selection.y;
4244   //      length = selection.x - selection.y;
4245   //
4246   //      // caret right
4247   //    } else {
4248   //      offset = selection.x;
4249   //      length = selection.y - selection.x;
4250   //    }
4251   //
4252   //    return new Region(offset, length);
4253   //  }
4254   protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
4255     StyledText text = sourceViewer.getTextWidget();
4256     Point selection = text.getSelectionRange();
4257
4258     if (text.getCaretOffset() == selection.x) {
4259       selection.x = selection.x + selection.y;
4260       selection.y = -selection.y;
4261     }
4262
4263     selection.x = widgetOffset2ModelOffset(sourceViewer, selection.x);
4264
4265     return new Region(selection.x, selection.y);
4266   }
4267
4268   /** Preference key for matching brackets */
4269   protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
4270
4271   /** Preference key for matching brackets color */
4272   protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
4273
4274   /** Preference key for highlighting current line */
4275   //  protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
4276   /** Preference key for highlight color of current line */
4277   //  protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
4278   /** Preference key for showing print marging ruler */
4279   //  protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
4280   /** Preference key for print margin ruler color */
4281   //  protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
4282   /** Preference key for print margin ruler column */
4283   //  protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
4284   /** Preference key for error indication */
4285   //  protected final static String ERROR_INDICATION =
4286   // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
4287   /** Preference key for error color */
4288   //  protected final static String ERROR_INDICATION_COLOR =
4289   // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
4290   /** Preference key for warning indication */
4291   //  protected final static String WARNING_INDICATION =
4292   // PreferenceConstants.EDITOR_WARNING_INDICATION;
4293   /** Preference key for warning color */
4294   //  protected final static String WARNING_INDICATION_COLOR =
4295   // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
4296   /** Preference key for task indication */
4297   protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
4298
4299   /** Preference key for task color */
4300   protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
4301
4302   /** Preference key for bookmark indication */
4303   protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
4304
4305   /** Preference key for bookmark color */
4306   protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
4307
4308   /** Preference key for search result indication */
4309   protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
4310
4311   /** Preference key for search result color */
4312   protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
4313
4314   /** Preference key for unknown annotation indication */
4315   protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
4316
4317   /** Preference key for unknown annotation color */
4318   protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
4319
4320   /** Preference key for shwoing the overview ruler */
4321   protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
4322
4323   /** Preference key for error indication in overview ruler */
4324   protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
4325
4326   /** Preference key for warning indication in overview ruler */
4327   protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
4328
4329   /** Preference key for task indication in overview ruler */
4330   protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
4331
4332   /** Preference key for bookmark indication in overview ruler */
4333   protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
4334
4335   /** Preference key for search result indication in overview ruler */
4336   protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
4337
4338   /** Preference key for unknown annotation indication in overview ruler */
4339   protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
4340
4341   //            /** Preference key for compiler task tags */
4342   //            private final static String COMPILER_TASK_TAGS=
4343   // JavaCore.COMPILER_TASK_TAGS;
4344   /** Preference key for browser like links */
4345   private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS;
4346
4347   /** Preference key for key modifier of browser like links */
4348   private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER;
4349
4350   /**
4351    * Preference key for key modifier mask of browser like links. The value is only used if the value of
4352    * <code>EDITOR_BROWSER_LIKE_LINKS</code> cannot be resolved to valid SWT modifier bits.
4353    * 
4354    * @since 2.1.1
4355    */
4356   private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
4357
4358   private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
4359
4360   private static boolean isBracket(char character) {
4361     for (int i = 0; i != BRACKETS.length; ++i)
4362       if (character == BRACKETS[i])
4363         return true;
4364     return false;
4365   }
4366
4367   private static boolean isSurroundedByBrackets(IDocument document, int offset) {
4368     if (offset == 0 || offset == document.getLength())
4369       return false;
4370
4371     try {
4372       return isBracket(document.getChar(offset - 1)) && isBracket(document.getChar(offset));
4373
4374     } catch (BadLocationException e) {
4375       return false;
4376     }
4377   }
4378
4379   //  protected void configureSourceViewerDecorationSupport() {
4380   //
4381   //    fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
4382   //
4383   //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4384   //      AnnotationType.UNKNOWN,
4385   //      UNKNOWN_INDICATION_COLOR,
4386   //      UNKNOWN_INDICATION,
4387   //      UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
4388   //      0);
4389   //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4390   //      AnnotationType.BOOKMARK,
4391   //      BOOKMARK_INDICATION_COLOR,
4392   //      BOOKMARK_INDICATION,
4393   //      BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
4394   //      1);
4395   //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4396   //      AnnotationType.TASK,
4397   //      TASK_INDICATION_COLOR,
4398   //      TASK_INDICATION,
4399   //      TASK_INDICATION_IN_OVERVIEW_RULER,
4400   //      2);
4401   //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4402   //      AnnotationType.SEARCH,
4403   //      SEARCH_RESULT_INDICATION_COLOR,
4404   //      SEARCH_RESULT_INDICATION,
4405   //      SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
4406   //      3);
4407   //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4408   //      AnnotationType.WARNING,
4409   //      WARNING_INDICATION_COLOR,
4410   //      WARNING_INDICATION,
4411   //      WARNING_INDICATION_IN_OVERVIEW_RULER,
4412   //      4);
4413   //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4414   //      AnnotationType.ERROR,
4415   //      ERROR_INDICATION_COLOR,
4416   //      ERROR_INDICATION,
4417   //      ERROR_INDICATION_IN_OVERVIEW_RULER,
4418   //      5);
4419   //
4420   //    fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE,
4421   // CURRENT_LINE_COLOR);
4422   //    fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN,
4423   // PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
4424   //    fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS,
4425   // MATCHING_BRACKETS_COLOR);
4426   //
4427   //    fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
4428   //
4429   //  }
4430   /**
4431    * Returns the Java element wrapped by this editors input.
4432    * 
4433    * @return the Java element wrapped by this editors input.
4434    * @since 3.0
4435    */
4436   abstract protected IJavaElement getInputJavaElement();
4437
4438   protected void updateStatusLine() {
4439     ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
4440     Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength());
4441     setStatusLineErrorMessage(null);
4442     setStatusLineMessage(null);
4443     if (annotation != null) {
4444       try {
4445         fIsUpdatingAnnotationViews = true;
4446         updateAnnotationViews(annotation);
4447       } finally {
4448         fIsUpdatingAnnotationViews = false;
4449       }
4450       if (annotation instanceof IJavaAnnotation && ((IJavaAnnotation) annotation).isProblem())
4451         setStatusLineMessage(annotation.getText());
4452     }
4453   }
4454
4455   /**
4456    * Jumps to the matching bracket.
4457    */
4458   public void gotoMatchingBracket() {
4459
4460     ISourceViewer sourceViewer = getSourceViewer();
4461     IDocument document = sourceViewer.getDocument();
4462     if (document == null)
4463       return;
4464
4465     IRegion selection = getSignedSelection(sourceViewer);
4466
4467     int selectionLength = Math.abs(selection.getLength());
4468     if (selectionLength > 1) {
4469       setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$               
4470       sourceViewer.getTextWidget().getDisplay().beep();
4471       return;
4472     }
4473
4474     // #26314
4475     int sourceCaretOffset = selection.getOffset() + selection.getLength();
4476     if (isSurroundedByBrackets(document, sourceCaretOffset))
4477       sourceCaretOffset -= selection.getLength();
4478
4479     IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
4480     if (region == null) {
4481       setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$              
4482       sourceViewer.getTextWidget().getDisplay().beep();
4483       return;
4484     }
4485
4486     int offset = region.getOffset();
4487     int length = region.getLength();
4488
4489     if (length < 1)
4490       return;
4491
4492     int anchor = fBracketMatcher.getAnchor();
4493     int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
4494
4495     boolean visible = false;
4496     if (sourceViewer instanceof ITextViewerExtension3) {
4497       ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
4498       visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
4499     } else {
4500       IRegion visibleRegion = sourceViewer.getVisibleRegion();
4501       visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength());
4502     }
4503
4504     if (!visible) {
4505       setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$          
4506       sourceViewer.getTextWidget().getDisplay().beep();
4507       return;
4508     }
4509
4510     if (selection.getLength() < 0)
4511       targetOffset -= selection.getLength();
4512
4513     sourceViewer.setSelectedRange(targetOffset, selection.getLength());
4514     sourceViewer.revealRange(targetOffset, selection.getLength());
4515   }
4516
4517   /**
4518    * Ses the given message as error message to this editor's status line.
4519    * 
4520    * @param msg
4521    *          message to be set
4522    */
4523   protected void setStatusLineErrorMessage(String msg) {
4524     IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
4525     if (statusLine != null)
4526       statusLine.setMessage(true, msg, null);
4527   }
4528
4529   /**
4530    * Sets the given message as message to this editor's status line.
4531    * 
4532    * @param msg
4533    *          message to be set
4534    * @since 3.0
4535    */
4536   protected void setStatusLineMessage(String msg) {
4537     IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
4538     if (statusLine != null)
4539       statusLine.setMessage(false, msg, null);
4540   }
4541
4542   /**
4543    * Returns the annotation closest to the given range respecting the given direction. If an annotation is found, the annotations
4544    * current position is copied into the provided annotation position.
4545    * 
4546    * @param offset
4547    *          the region offset
4548    * @param length
4549    *          the region length
4550    * @param forward
4551    *          <code>true</code> for forwards, <code>false</code> for backward
4552    * @param annotationPosition
4553    *          the position of the found annotation
4554    * @return the found annotation
4555    */
4556   private Annotation getNextAnnotation(final int offset, final int length, boolean forward, Position annotationPosition) {
4557
4558     Annotation nextAnnotation = null;
4559     Position nextAnnotationPosition = null;
4560     Annotation containingAnnotation = null;
4561     Position containingAnnotationPosition = null;
4562     boolean currentAnnotation = false;
4563
4564     IDocument document = getDocumentProvider().getDocument(getEditorInput());
4565     int endOfDocument = document.getLength();
4566     int distance = Integer.MAX_VALUE;
4567
4568     IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
4569     Iterator e = new JavaAnnotationIterator(model, true, true);
4570     while (e.hasNext()) {
4571       Annotation a = (Annotation) e.next();
4572       if ((a instanceof IJavaAnnotation) && ((IJavaAnnotation) a).hasOverlay() || !isNavigationTarget(a))
4573         continue;
4574
4575       Position p = model.getPosition(a);
4576       if (p == null)
4577         continue;
4578
4579       if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {// || p.includes(offset)) {
4580         if (containingAnnotation == null
4581             || (forward && p.length >= containingAnnotationPosition.length || !forward
4582                 && p.length >= containingAnnotationPosition.length)) {
4583           containingAnnotation = a;
4584           containingAnnotationPosition = p;
4585           currentAnnotation = p.length == length;
4586         }
4587       } else {
4588         int currentDistance = 0;
4589
4590         if (forward) {
4591           currentDistance = p.getOffset() - offset;
4592           if (currentDistance < 0)
4593             currentDistance = endOfDocument + currentDistance;
4594
4595           if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
4596             distance = currentDistance;
4597             nextAnnotation = a;
4598             nextAnnotationPosition = p;
4599           }
4600         } else {
4601           currentDistance = offset + length - (p.getOffset() + p.length);
4602           if (currentDistance < 0)
4603             currentDistance = endOfDocument + currentDistance;
4604
4605           if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
4606             distance = currentDistance;
4607             nextAnnotation = a;
4608             nextAnnotationPosition = p;
4609           }
4610         }
4611       }
4612     }
4613     if (containingAnnotationPosition != null && (!currentAnnotation || nextAnnotation == null)) {
4614       annotationPosition.setOffset(containingAnnotationPosition.getOffset());
4615       annotationPosition.setLength(containingAnnotationPosition.getLength());
4616       return containingAnnotation;
4617     }
4618     if (nextAnnotationPosition != null) {
4619       annotationPosition.setOffset(nextAnnotationPosition.getOffset());
4620       annotationPosition.setLength(nextAnnotationPosition.getLength());
4621     }
4622
4623     return nextAnnotation;
4624   }
4625
4626   /**
4627    * Returns the annotation overlapping with the given range or <code>null</code>.
4628    * 
4629    * @param offset
4630    *          the region offset
4631    * @param length
4632    *          the region length
4633    * @return the found annotation or <code>null</code>
4634    * @since 3.0
4635    */
4636   private Annotation getAnnotation(int offset, int length) {
4637     IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
4638     Iterator e = new JavaAnnotationIterator(model, true, true);
4639     while (e.hasNext()) {
4640       Annotation a = (Annotation) e.next();
4641       if (!isNavigationTarget(a))
4642         continue;
4643
4644       Position p = model.getPosition(a);
4645       if (p != null && p.overlapsWith(offset, length))
4646         return a;
4647     }
4648
4649     return null;
4650   }
4651
4652   /**
4653    * Returns whether the given annotation is configured as a target for the "Go to Next/Previous Annotation" actions
4654    * 
4655    * @param annotation
4656    *          the annotation
4657    * @return <code>true</code> if this is a target, <code>false</code> otherwise
4658    * @since 3.0
4659    */
4660   private boolean isNavigationTarget(Annotation annotation) {
4661     Preferences preferences = EditorsUI.getPluginPreferences();
4662     AnnotationPreference preference = getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
4663     //          See bug 41689
4664     //          String key= forward ? preference.getIsGoToNextNavigationTargetKey() : preference.getIsGoToPreviousNavigationTargetKey();
4665     String key = preference == null ? null : preference.getIsGoToNextNavigationTargetKey();
4666     return (key != null && preferences.getBoolean(key));
4667   }
4668
4669   /**
4670    * Returns a segmentation of the line of the given document appropriate for bidi rendering. The default implementation returns
4671    * only the string literals of a php code line as segments.
4672    * 
4673    * @param document
4674    *          the document
4675    * @param lineOffset
4676    *          the offset of the line
4677    * @return the line's bidi segmentation
4678    * @throws BadLocationException
4679    *           in case lineOffset is not valid in document
4680    */
4681   public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException {
4682
4683     IRegion line = document.getLineInformationOfOffset(lineOffset);
4684     ITypedRegion[] linePartitioning = document.computePartitioning(lineOffset, line.getLength());
4685
4686     List segmentation = new ArrayList();
4687     for (int i = 0; i < linePartitioning.length; i++) {
4688       if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType()))
4689         segmentation.add(linePartitioning[i]);
4690     }
4691
4692     if (segmentation.size() == 0)
4693       return null;
4694
4695     int size = segmentation.size();
4696     int[] segments = new int[size * 2 + 1];
4697
4698     int j = 0;
4699     for (int i = 0; i < size; i++) {
4700       ITypedRegion segment = (ITypedRegion) segmentation.get(i);
4701
4702       if (i == 0)
4703         segments[j++] = 0;
4704
4705       int offset = segment.getOffset() - lineOffset;
4706       if (offset > segments[j - 1])
4707         segments[j++] = offset;
4708
4709       if (offset + segment.getLength() >= line.getLength())
4710         break;
4711
4712       segments[j++] = offset + segment.getLength();
4713     }
4714
4715     if (j < segments.length) {
4716       int[] result = new int[j];
4717       System.arraycopy(segments, 0, result, 0, j);
4718       segments = result;
4719     }
4720
4721     return segments;
4722   }
4723
4724   /**
4725    * Returns a segmentation of the given line appropriate for bidi rendering. The default implementation returns only the string
4726    * literals of a php code line as segments.
4727    * 
4728    * @param lineOffset
4729    *          the offset of the line
4730    * @param line
4731    *          the content of the line
4732    * @return the line's bidi segmentation
4733    */
4734   protected int[] getBidiLineSegments(int lineOffset, String line) {
4735     IDocumentProvider provider = getDocumentProvider();
4736     if (provider != null && line != null && line.length() > 0) {
4737       IDocument document = provider.getDocument(getEditorInput());
4738       if (document != null)
4739         try {
4740           return getBidiLineSegments(document, lineOffset);
4741         } catch (BadLocationException x) {
4742           // ignore
4743         }
4744     }
4745     return null;
4746   }
4747
4748   /*
4749    * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4750    */
4751   //  protected final ISourceViewer createSourceViewer(
4752   //    Composite parent,
4753   //    IVerticalRuler ruler,
4754   //    int styles) {
4755   //    ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
4756   //    StyledText text = viewer.getTextWidget();
4757   //    text.addBidiSegmentListener(new BidiSegmentListener() {
4758   //      public void lineGetSegments(BidiSegmentEvent event) {
4759   //        event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
4760   //      }
4761   //    });
4762   //    // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
4763   //    return viewer;
4764   //  }
4765   public final ISourceViewer getViewer() {
4766     return getSourceViewer();
4767   }
4768
4769   //  protected void showOverviewRuler() {
4770   //    if (fOverviewRuler != null) {
4771   //      if (getSourceViewer() instanceof ISourceViewerExtension) {
4772   //        ((ISourceViewerExtension)
4773   // getSourceViewer()).showAnnotationsOverview(true);
4774   //        fSourceViewerDecorationSupport.updateOverviewDecorations();
4775   //      }
4776   //    }
4777   //  }
4778   //
4779   //  protected void hideOverviewRuler() {
4780   //    if (getSourceViewer() instanceof ISourceViewerExtension) {
4781   //      fSourceViewerDecorationSupport.hideAnnotationOverview();
4782   //      ((ISourceViewerExtension)
4783   // getSourceViewer()).showAnnotationsOverview(false);
4784   //    }
4785   //  }
4786
4787   //  protected boolean isOverviewRulerVisible() {
4788   //    IPreferenceStore store = getPreferenceStore();
4789   //    return store.getBoolean(OVERVIEW_RULER);
4790   //  }
4791   /*
4792    * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4793    */
4794   //  protected ISourceViewer createJavaSourceViewer(
4795   //    Composite parent,
4796   //    IVerticalRuler ruler,
4797   //    IOverviewRuler overviewRuler,
4798   //    boolean isOverviewRulerVisible,
4799   //    int styles) {
4800   //    return new SourceViewer(parent, ruler, overviewRuler,
4801   // isOverviewRulerVisible(), styles);
4802   //  }
4803   /*
4804    * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4805    */
4806   protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
4807       boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
4808     return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, store);
4809   }
4810
4811   /*
4812    * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4813    */
4814   protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {
4815
4816     ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles,
4817         getPreferenceStore());
4818
4819     StyledText text = viewer.getTextWidget();
4820     text.addBidiSegmentListener(new BidiSegmentListener() {
4821       public void lineGetSegments(BidiSegmentEvent event) {
4822         event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
4823       }
4824     });
4825
4826     //          JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
4827
4828     // ensure source viewer decoration support has been created and
4829     // configured
4830     getSourceViewerDecorationSupport(viewer);
4831
4832     return viewer;
4833   }
4834
4835   /*
4836    * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
4837    */
4838   protected boolean affectsTextPresentation(PropertyChangeEvent event) {
4839     return ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).affectsTextPresentation(event)
4840         || super.affectsTextPresentation(event);
4841   }
4842
4843   //
4844   //      protected boolean affectsTextPresentation(PropertyChangeEvent event) {
4845   //        JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
4846   //        return textTools.affectsBehavior(event);
4847   //      }
4848   /**
4849    * Creates and returns the preference store for this Java editor with the given input.
4850    * 
4851    * @param input
4852    *          The editor input for which to create the preference store
4853    * @return the preference store for this editor
4854    * 
4855    * @since 3.0
4856    */
4857   private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
4858     List stores = new ArrayList(3);
4859
4860     IJavaProject project = EditorUtility.getJavaProject(input);
4861     if (project != null)
4862       stores.add(new OptionsAdapter(project.getOptions(false), PHPeclipsePlugin.getDefault().getMockupPreferenceStore(),
4863           new OptionsAdapter.IPropertyChangeEventFilter() {
4864
4865             public boolean isFiltered(PropertyChangeEvent event) {
4866               IJavaElement inputJavaElement = getInputJavaElement();
4867               IJavaProject javaProject = inputJavaElement != null ? inputJavaElement.getJavaProject() : null;
4868               if (javaProject == null)
4869                 return true;
4870
4871               return !javaProject.getProject().equals(event.getSource());
4872             }
4873
4874           }));
4875
4876     stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore());
4877     stores.add(new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()));
4878     stores.add(EditorsUI.getPreferenceStore());
4879
4880     return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
4881   }
4882
4883   /**
4884    * Jumps to the error next according to the given direction.
4885    */
4886   public void gotoError(boolean forward) {
4887
4888     ISelectionProvider provider = getSelectionProvider();
4889
4890     ITextSelection s = (ITextSelection) provider.getSelection();
4891     Position errorPosition = new Position(0, 0);
4892     IJavaAnnotation nextError = getNextError(s.getOffset(), forward, errorPosition);
4893
4894     if (nextError != null) {
4895
4896       IMarker marker = null;
4897       if (nextError instanceof MarkerAnnotation)
4898         marker = ((MarkerAnnotation) nextError).getMarker();
4899       else {
4900         Iterator e = nextError.getOverlaidIterator();
4901         if (e != null) {
4902           while (e.hasNext()) {
4903             Object o = e.next();
4904             if (o instanceof MarkerAnnotation) {
4905               marker = ((MarkerAnnotation) o).getMarker();
4906               break;
4907             }
4908           }
4909         }
4910       }
4911
4912       if (marker != null) {
4913         IWorkbenchPage page = getSite().getPage();
4914         IViewPart view = view = page.findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
4915         if (view instanceof TaskList) {
4916           StructuredSelection ss = new StructuredSelection(marker);
4917           ((TaskList) view).setSelection(ss, true);
4918         }
4919       }
4920
4921       selectAndReveal(errorPosition.getOffset(), errorPosition.getLength());
4922       //      setStatusLineErrorMessage(nextError.getMessage());
4923
4924     } else {
4925
4926       setStatusLineErrorMessage(null);
4927
4928     }
4929   }
4930
4931   private IJavaAnnotation getNextError(int offset, boolean forward, Position errorPosition) {
4932
4933     IJavaAnnotation nextError = null;
4934     Position nextErrorPosition = null;
4935
4936     IDocument document = getDocumentProvider().getDocument(getEditorInput());
4937     int endOfDocument = document.getLength();
4938     int distance = 0;
4939
4940     IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
4941     Iterator e = new JavaAnnotationIterator(model, false);
4942     while (e.hasNext()) {
4943
4944       IJavaAnnotation a = (IJavaAnnotation) e.next();
4945       if (a.hasOverlay() || !a.isProblem())
4946         continue;
4947
4948       Position p = model.getPosition((Annotation) a);
4949       if (!p.includes(offset)) {
4950
4951         int currentDistance = 0;
4952
4953         if (forward) {
4954           currentDistance = p.getOffset() - offset;
4955           if (currentDistance < 0)
4956             currentDistance = endOfDocument - offset + p.getOffset();
4957         } else {
4958           currentDistance = offset - p.getOffset();
4959           if (currentDistance < 0)
4960             currentDistance = offset + endOfDocument - p.getOffset();
4961         }
4962
4963         if (nextError == null || currentDistance < distance) {
4964           distance = currentDistance;
4965           nextError = a;
4966           nextErrorPosition = p;
4967         }
4968       }
4969     }
4970
4971     if (nextErrorPosition != null) {
4972       errorPosition.setOffset(nextErrorPosition.getOffset());
4973       errorPosition.setLength(nextErrorPosition.getLength());
4974     }
4975
4976     return nextError;
4977   }
4978
4979   void removeOccurrenceAnnotations() {
4980     IDocumentProvider documentProvider = getDocumentProvider();
4981     if (documentProvider == null)
4982       return;
4983
4984     IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
4985     if (annotationModel == null || fOccurrenceAnnotations == null)
4986       return;
4987
4988     synchronized (annotationModel) {
4989       if (annotationModel instanceof IAnnotationModelExtension) {
4990         ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
4991       } else {
4992         for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++)
4993           annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
4994       }
4995       fOccurrenceAnnotations = null;
4996     }
4997   }
4998
4999   protected void uninstallOverrideIndicator() {
5000     //          if (fOverrideIndicatorManager != null) {
5001     //                  fOverrideIndicatorManager.removeAnnotations();
5002     //                  fOverrideIndicatorManager= null;
5003     //          }
5004   }
5005
5006   protected void installOverrideIndicator(boolean waitForReconcilation) {
5007     uninstallOverrideIndicator();
5008     IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
5009     final IJavaElement inputElement = getInputJavaElement();
5010
5011     if (model == null || inputElement == null)
5012       return;
5013
5014     //  fOverrideIndicatorManager= new OverrideIndicatorManager(model, inputElement, null);
5015     //  
5016     //  if (provideAST) {
5017     //          Job job= new Job(JavaEditorMessages.getString("OverrideIndicatorManager.intallJob")) { //$NON-NLS-1$
5018     //                  /*
5019     //                   * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
5020     //                   * @since 3.0
5021     //                   */
5022     //                  protected IStatus run(IProgressMonitor monitor) {
5023     //                          CompilationUnit ast= JavaPlugin.getDefault().getASTProvider().getAST(inputElement, true, null);
5024     //                          if (fOverrideIndicatorManager != null) // editor might have been closed in the meanwhile
5025     //                                  fOverrideIndicatorManager.reconciled(ast, true, monitor);
5026     //                          return Status.OK_STATUS;
5027     //                  }
5028     //          };
5029     //          job.setPriority(Job.DECORATE);
5030     //          job.setSystem(true);
5031     //          job.schedule();
5032     //  }
5033   }
5034
5035   /**
5036    * Tells whether override indicators are shown.
5037    * 
5038    * @return <code>true</code> if the override indicators are shown
5039    * @since 3.0
5040    */
5041   //    protected boolean isShowingOverrideIndicators() {
5042   //            AnnotationPreference preference=
5043   // getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
5044   //            IPreferenceStore store= getPreferenceStore();
5045   //            return getBoolean(store, preference.getHighlightPreferenceKey())
5046   //                    || getBoolean(store, preference.getVerticalRulerPreferenceKey())
5047   //                    || getBoolean(store, preference.getOverviewRulerPreferenceKey())
5048   //                    || getBoolean(store, preference.getTextPreferenceKey());
5049   //    }
5050   /**
5051    * Returns the boolean preference for the given key.
5052    * 
5053    * @param store
5054    *          the preference store
5055    * @param key
5056    *          the preference key
5057    * @return <code>true</code> if the key exists in the store and its value is <code>true</code>
5058    * @since 3.0
5059    */
5060   private boolean getBoolean(IPreferenceStore store, String key) {
5061     return key != null && store.getBoolean(key);
5062   }
5063
5064   protected boolean isPrefQuickDiffAlwaysOn() {
5065     return false; // never show change ruler for the non-editable java editor. Overridden in subclasses like PHPUnitEditor
5066   }
5067
5068   /*
5069    * @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions()
5070    */
5071   protected void createNavigationActions() {
5072     super.createNavigationActions();
5073
5074     final StyledText textWidget = getSourceViewer().getTextWidget();
5075
5076     IAction action = new SmartLineStartAction(textWidget, false);
5077     action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
5078     setAction(ITextEditorActionDefinitionIds.LINE_START, action);
5079
5080     action = new SmartLineStartAction(textWidget, true);
5081     action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
5082     setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);
5083
5084     action = new NavigatePreviousSubWordAction();
5085     action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS);
5086     setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action);
5087     textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL);
5088
5089     action = new NavigateNextSubWordAction();
5090     action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT);
5091     setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action);
5092     textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL);
5093
5094     action = new SelectPreviousSubWordAction();
5095     action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS);
5096     setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action);
5097     textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL);
5098
5099     action = new SelectNextSubWordAction();
5100     action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT);
5101     setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action);
5102     textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL);
5103   }
5104
5105   /*
5106    * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createCompositeRuler()
5107    */
5108   protected CompositeRuler createCompositeRuler() {
5109     if (!getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
5110       return super.createCompositeRuler();
5111
5112     CompositeRuler ruler = new CompositeRuler();
5113     AnnotationRulerColumn column = new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess());
5114     column.setHover(new JavaExpandHover(ruler, getAnnotationAccess(), new IDoubleClickListener() {
5115
5116       public void doubleClick(DoubleClickEvent event) {
5117         // for now: just invoke ruler double click action
5118         triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK);
5119       }
5120
5121       private void triggerAction(String actionID) {
5122         IAction action = getAction(actionID);
5123         if (action != null) {
5124           if (action instanceof IUpdate)
5125             ((IUpdate) action).update();
5126           // hack to propagate line change
5127           if (action instanceof ISelectionListener) {
5128             ((ISelectionListener) action).selectionChanged(null, null);
5129           }
5130           if (action.isEnabled())
5131             action.run();
5132         }
5133       }
5134
5135     }));
5136     ruler.addDecorator(0, column);
5137
5138     if (isLineNumberRulerVisible())
5139       ruler.addDecorator(1, createLineNumberRulerColumn());
5140     else if (isPrefQuickDiffAlwaysOn())
5141       ruler.addDecorator(1, createChangeRulerColumn());
5142
5143     return ruler;
5144   }
5145
5146   /**
5147    * Returns the folding action group, or <code>null</code> if there is none.
5148    * 
5149    * @return the folding action group, or <code>null</code> if there is none
5150    * @since 3.0
5151    */
5152   protected FoldingActionGroup getFoldingActionGroup() {
5153     return fFoldingGroup;
5154   }
5155
5156   /*
5157    * @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert()
5158    */
5159   protected void performRevert() {
5160     ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
5161     projectionViewer.setRedraw(false);
5162     try {
5163
5164       boolean projectionMode = projectionViewer.isProjectionMode();
5165       if (projectionMode) {
5166         projectionViewer.disableProjection();
5167         if (fProjectionModelUpdater != null)
5168           fProjectionModelUpdater.uninstall();
5169       }
5170
5171       super.performRevert();
5172
5173       if (projectionMode) {
5174         if (fProjectionModelUpdater != null)
5175           fProjectionModelUpdater.install(this, projectionViewer);
5176         projectionViewer.enableProjection();
5177       }
5178
5179     } finally {
5180       projectionViewer.setRedraw(true);
5181     }
5182   }
5183
5184   /**
5185    * React to changed selection.
5186    * 
5187    * @since 3.0
5188    */
5189   protected void selectionChanged() {
5190     if (getSelectionProvider() == null)
5191       return;
5192     ISourceReference element = computeHighlightRangeSourceReference();
5193     if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
5194       synchronizeOutlinePage(element);
5195     setSelection(element, false);
5196     updateStatusLine();
5197   }
5198
5199   private boolean isJavaOutlinePageActive() {
5200     IWorkbenchPart part = getActivePart();
5201     return part instanceof ContentOutline && ((ContentOutline) part).getCurrentPage() == fOutlinePage;
5202   }
5203
5204   private IWorkbenchPart getActivePart() {
5205     IWorkbenchWindow window = getSite().getWorkbenchWindow();
5206     IPartService service = window.getPartService();
5207     IWorkbenchPart part = service.getActivePart();
5208     return part;
5209   }
5210
5211   /**
5212    * Computes and returns the source reference that includes the caret and serves as provider for the outline page selection and the
5213    * editor range indication.
5214    * 
5215    * @return the computed source reference
5216    * @since 3.0
5217    */
5218   protected ISourceReference computeHighlightRangeSourceReference() {
5219     ISourceViewer sourceViewer = getSourceViewer();
5220     if (sourceViewer == null)
5221       return null;
5222
5223     StyledText styledText = sourceViewer.getTextWidget();
5224     if (styledText == null)
5225       return null;
5226
5227     int caret = 0;
5228     if (sourceViewer instanceof ITextViewerExtension5) {
5229       ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
5230       caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
5231     } else {
5232       int offset = sourceViewer.getVisibleRegion().getOffset();
5233       caret = offset + styledText.getCaretOffset();
5234     }
5235
5236     IJavaElement element = getElementAt(caret, false);
5237
5238     if (!(element instanceof ISourceReference))
5239       return null;
5240
5241     if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) {
5242
5243       IImportDeclaration declaration = (IImportDeclaration) element;
5244       IImportContainer container = (IImportContainer) declaration.getParent();
5245       ISourceRange srcRange = null;
5246
5247       try {
5248         srcRange = container.getSourceRange();
5249       } catch (JavaModelException e) {
5250       }
5251
5252       if (srcRange != null && srcRange.getOffset() == caret)
5253         return container;
5254     }
5255
5256     return (ISourceReference) element;
5257   }
5258
5259   /**
5260    * Returns the most narrow java element including the given offset.
5261    * 
5262    * @param offset
5263    *          the offset inside of the requested element
5264    * @param reconcile
5265    *          <code>true</code> if editor input should be reconciled in advance
5266    * @return the most narrow java element
5267    * @since 3.0
5268    */
5269   protected IJavaElement getElementAt(int offset, boolean reconcile) {
5270     return getElementAt(offset);
5271   }
5272 }