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