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