1 package net.sourceforge.phpeclipse.phpeditor;
 
   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
 
  11  IBM Corporation - Initial implementation
 
  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;
 
  23 import java.util.ResourceBundle;
 
  24 import java.util.StringTokenizer;
 
  26 import net.sourceforge.phpdt.core.ICompilationUnit;
 
  27 import net.sourceforge.phpdt.core.IImportContainer;
 
  28 import net.sourceforge.phpdt.core.IImportDeclaration;
 
  29 import net.sourceforge.phpdt.core.IJavaElement;
 
  30 import net.sourceforge.phpdt.core.IJavaProject;
 
  31 import net.sourceforge.phpdt.core.IMember;
 
  32 import net.sourceforge.phpdt.core.ISourceRange;
 
  33 import net.sourceforge.phpdt.core.ISourceReference;
 
  34 import net.sourceforge.phpdt.core.JavaCore;
 
  35 import net.sourceforge.phpdt.core.JavaModelException;
 
  36 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 
  37 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
 
  38 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
 
  39 import net.sourceforge.phpdt.internal.compiler.parser.SyntaxError;
 
  40 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
 
  41 import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
 
  42 import net.sourceforge.phpdt.internal.ui.actions.SelectionConverter;
 
  43 import net.sourceforge.phpdt.internal.ui.text.CustomSourceInformationControl;
 
  44 import net.sourceforge.phpdt.internal.ui.text.DocumentCharacterIterator;
 
  45 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
 
  46 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
 
  47 import net.sourceforge.phpdt.internal.ui.text.JavaWordFinder;
 
  48 import net.sourceforge.phpdt.internal.ui.text.JavaWordIterator;
 
  49 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
 
  50 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
 
  51 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaExpandHover;
 
  52 import net.sourceforge.phpdt.internal.ui.viewsupport.ISelectionListenerWithAST;
 
  53 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
 
  54 import net.sourceforge.phpdt.internal.ui.viewsupport.SelectionListenerWithASTManager;
 
  55 import net.sourceforge.phpdt.ui.IContextMenuConstants;
 
  56 import net.sourceforge.phpdt.ui.JavaUI;
 
  57 import net.sourceforge.phpdt.ui.PreferenceConstants;
 
  58 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
 
  59 import net.sourceforge.phpdt.ui.actions.OpenEditorActionGroup;
 
  60 import net.sourceforge.phpdt.ui.text.JavaTextTools;
 
  61 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
 
  62 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
 
  63 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
  64 import net.sourceforge.phpeclipse.ui.editor.BrowserUtil;
 
  65 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
 
  67 import org.eclipse.core.resources.IMarker;
 
  68 import org.eclipse.core.resources.IResource;
 
  69 import org.eclipse.core.runtime.CoreException;
 
  70 import org.eclipse.core.runtime.IProgressMonitor;
 
  71 import org.eclipse.core.runtime.IStatus;
 
  72 import org.eclipse.core.runtime.NullProgressMonitor;
 
  73 import org.eclipse.core.runtime.Preferences;
 
  74 import org.eclipse.core.runtime.Status;
 
  75 import org.eclipse.core.runtime.jobs.Job;
 
  76 import org.eclipse.jface.action.Action;
 
  77 import org.eclipse.jface.action.GroupMarker;
 
  78 import org.eclipse.jface.action.IAction;
 
  79 import org.eclipse.jface.action.MenuManager;
 
  80 import org.eclipse.jface.action.Separator;
 
  81 import org.eclipse.jface.preference.IPreferenceStore;
 
  82 import org.eclipse.jface.preference.PreferenceConverter;
 
  83 import org.eclipse.jface.text.BadLocationException;
 
  84 import org.eclipse.jface.text.DefaultInformationControl;
 
  85 import org.eclipse.jface.text.DocumentEvent;
 
  86 import org.eclipse.jface.text.IDocument;
 
  87 import org.eclipse.jface.text.IDocumentExtension4;
 
  88 import org.eclipse.jface.text.IDocumentListener;
 
  89 import org.eclipse.jface.text.IInformationControl;
 
  90 import org.eclipse.jface.text.IInformationControlCreator;
 
  91 import org.eclipse.jface.text.IRegion;
 
  92 import org.eclipse.jface.text.ISelectionValidator;
 
  93 import org.eclipse.jface.text.ISynchronizable;
 
  94 import org.eclipse.jface.text.ITextHover;
 
  95 import org.eclipse.jface.text.ITextInputListener;
 
  96 import org.eclipse.jface.text.ITextPresentationListener;
 
  97 import org.eclipse.jface.text.ITextSelection;
 
  98 import org.eclipse.jface.text.ITextViewer;
 
  99 import org.eclipse.jface.text.ITextViewerExtension2;
 
 100 import org.eclipse.jface.text.ITextViewerExtension4;
 
 101 import org.eclipse.jface.text.ITextViewerExtension5;
 
 102 import org.eclipse.jface.text.ITypedRegion;
 
 103 import org.eclipse.jface.text.Position;
 
 104 import org.eclipse.jface.text.Region;
 
 105 import org.eclipse.jface.text.TextPresentation;
 
 106 import org.eclipse.jface.text.TextSelection;
 
 107 import org.eclipse.jface.text.TextUtilities;
 
 108 import org.eclipse.jface.text.information.IInformationProvider;
 
 109 import org.eclipse.jface.text.information.InformationPresenter;
 
 110 import org.eclipse.jface.text.link.LinkedModeModel;
 
 111 import org.eclipse.jface.text.reconciler.IReconciler;
 
 112 import org.eclipse.jface.text.source.Annotation;
 
 113 import org.eclipse.jface.text.source.AnnotationRulerColumn;
 
 114 import org.eclipse.jface.text.source.CompositeRuler;
 
 115 import org.eclipse.jface.text.source.IAnnotationModel;
 
 116 import org.eclipse.jface.text.source.IAnnotationModelExtension;
 
 117 import org.eclipse.jface.text.source.IOverviewRuler;
 
 118 import org.eclipse.jface.text.source.ISourceViewer;
 
 119 import org.eclipse.jface.text.source.ISourceViewerExtension2;
 
 120 import org.eclipse.jface.text.source.IVerticalRuler;
 
 121 import org.eclipse.jface.text.source.IVerticalRulerColumn;
 
 122 import org.eclipse.jface.text.source.OverviewRuler;
 
 123 import org.eclipse.jface.text.source.SourceViewerConfiguration;
 
 124 import org.eclipse.jface.text.source.projection.ProjectionSupport;
 
 125 import org.eclipse.jface.text.source.projection.ProjectionViewer;
 
 126 import org.eclipse.jface.util.IPropertyChangeListener;
 
 127 import org.eclipse.jface.util.ListenerList;
 
 128 import org.eclipse.jface.util.PropertyChangeEvent;
 
 129 import org.eclipse.jface.viewers.DoubleClickEvent;
 
 130 import org.eclipse.jface.viewers.IDoubleClickListener;
 
 131 import org.eclipse.jface.viewers.IPostSelectionProvider;
 
 132 import org.eclipse.jface.viewers.ISelection;
 
 133 import org.eclipse.jface.viewers.ISelectionChangedListener;
 
 134 import org.eclipse.jface.viewers.ISelectionProvider;
 
 135 import org.eclipse.jface.viewers.IStructuredSelection;
 
 136 import org.eclipse.jface.viewers.SelectionChangedEvent;
 
 137 import org.eclipse.jface.viewers.StructuredSelection;
 
 138 import org.eclipse.swt.SWT;
 
 139 import org.eclipse.swt.custom.BidiSegmentEvent;
 
 140 import org.eclipse.swt.custom.BidiSegmentListener;
 
 141 import org.eclipse.swt.custom.ST;
 
 142 import org.eclipse.swt.custom.StyleRange;
 
 143 import org.eclipse.swt.custom.StyledText;
 
 144 import org.eclipse.swt.events.FocusEvent;
 
 145 import org.eclipse.swt.events.FocusListener;
 
 146 import org.eclipse.swt.events.KeyEvent;
 
 147 import org.eclipse.swt.events.KeyListener;
 
 148 import org.eclipse.swt.events.MouseEvent;
 
 149 import org.eclipse.swt.events.MouseListener;
 
 150 import org.eclipse.swt.events.MouseMoveListener;
 
 151 import org.eclipse.swt.events.PaintEvent;
 
 152 import org.eclipse.swt.events.PaintListener;
 
 153 import org.eclipse.swt.graphics.Color;
 
 154 import org.eclipse.swt.graphics.Cursor;
 
 155 import org.eclipse.swt.graphics.GC;
 
 156 import org.eclipse.swt.graphics.Image;
 
 157 import org.eclipse.swt.graphics.Point;
 
 158 import org.eclipse.swt.graphics.RGB;
 
 159 import org.eclipse.swt.widgets.Composite;
 
 160 import org.eclipse.swt.widgets.Control;
 
 161 import org.eclipse.swt.widgets.Display;
 
 162 import org.eclipse.swt.widgets.Shell;
 
 163 import org.eclipse.ui.IEditorInput;
 
 164 import org.eclipse.ui.IEditorPart;
 
 165 import org.eclipse.ui.IPageLayout;
 
 166 import org.eclipse.ui.IPartService;
 
 167 import org.eclipse.ui.ISelectionListener;
 
 168 import org.eclipse.ui.IViewPart;
 
 169 import org.eclipse.ui.IWindowListener;
 
 170 import org.eclipse.ui.IWorkbenchPage;
 
 171 import org.eclipse.ui.IWorkbenchPart;
 
 172 import org.eclipse.ui.IWorkbenchWindow;
 
 173 import org.eclipse.ui.PlatformUI;
 
 174 import org.eclipse.ui.actions.ActionContext;
 
 175 import org.eclipse.ui.actions.ActionGroup;
 
 176 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
 
 177 import org.eclipse.ui.editors.text.EditorsUI;
 
 178 import org.eclipse.ui.editors.text.IEncodingSupport;
 
 179 import org.eclipse.ui.part.FileEditorInput;
 
 180 import org.eclipse.ui.part.IShowInSource;
 
 181 import org.eclipse.ui.part.IShowInTargetList;
 
 182 import org.eclipse.ui.part.ShowInContext;
 
 183 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
 
 184 import org.eclipse.ui.texteditor.AnnotationPreference;
 
 185 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
 
 186 import org.eclipse.ui.texteditor.IDocumentProvider;
 
 187 import org.eclipse.ui.texteditor.IEditorStatusLine;
 
 188 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 
 189 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
 
 190 import org.eclipse.ui.texteditor.IUpdate;
 
 191 import org.eclipse.ui.texteditor.MarkerAnnotation;
 
 192 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
 
 193 import org.eclipse.ui.texteditor.TextEditorAction;
 
 194 import org.eclipse.ui.texteditor.TextNavigationAction;
 
 195 import org.eclipse.ui.texteditor.TextOperationAction;
 
 196 import org.eclipse.ui.views.contentoutline.ContentOutline;
 
 197 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 
 198 import org.eclipse.ui.views.tasklist.TaskList;
 
 201  * PHP specific text editor.
 
 203 public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider, IShowInTargetList,
 
 205         // extends StatusTextEditor implements IViewPartInputProvider { // extends
 
 209          * Internal implementation class for a change listener.
 
 213         protected abstract class AbstractSelectionChangedListener implements ISelectionChangedListener {
 
 216                  * Installs this selection changed listener with the given selection
 
 217                  * provider. If the selection provider is a post selection provider, post
 
 218                  * selection changed events are the preferred choice, otherwise normal
 
 219                  * selection changed events are requested.
 
 221                  * @param selectionProvider
 
 223                 public void install(ISelectionProvider selectionProvider) {
 
 224                         if (selectionProvider == null)
 
 227                         if (selectionProvider instanceof IPostSelectionProvider) {
 
 228                                 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
 
 229                                 provider.addPostSelectionChangedListener(this);
 
 231                                 selectionProvider.addSelectionChangedListener(this);
 
 236                  * Removes this selection changed listener from the given selection
 
 239                  * @param selectionProvider
 
 240                  *          the selection provider
 
 242                 public void uninstall(ISelectionProvider selectionProvider) {
 
 243                         if (selectionProvider == null)
 
 246                         if (selectionProvider instanceof IPostSelectionProvider) {
 
 247                                 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
 
 248                                 provider.removePostSelectionChangedListener(this);
 
 250                                 selectionProvider.removeSelectionChangedListener(this);
 
 256          * Updates the Java outline page selection and this editor's range indicator.
 
 260         private class EditorSelectionChangedListener extends AbstractSelectionChangedListener {
 
 263                  * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
 
 265                 public void selectionChanged(SelectionChangedEvent event) {
 
 266                         // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161
 
 267                         PHPEditor.this.selectionChanged();
 
 272          * "Smart" runnable for updating the outline page's selection.
 
 274         // class OutlinePageSelectionUpdater implements Runnable {
 
 276         // /** Has the runnable already been posted? */
 
 277         // private boolean fPosted = false;
 
 279         // public OutlinePageSelectionUpdater() {
 
 283         // * @see Runnable#run()
 
 285         // public void run() {
 
 286         // synchronizeOutlinePageSelection();
 
 291         // * Posts this runnable into the event queue.
 
 293         // public void post() {
 
 297         // Shell shell = getSite().getShell();
 
 298         // if (shell != null & !shell.isDisposed()) {
 
 300         // shell.getDisplay().asyncExec(this);
 
 304         class SelectionChangedListener implements ISelectionChangedListener {
 
 305                 public void selectionChanged(SelectionChangedEvent event) {
 
 306                         doSelectionChanged(event);
 
 311          * Adapts an options {@link java.util.Map}to
 
 312          * {@link org.eclipse.jface.preference.IPreferenceStore}.
 
 314          * This preference store is read-only i.e. write access throws an
 
 315          * {@link java.lang.UnsupportedOperationException}.
 
 320         private static class OptionsAdapter implements IPreferenceStore {
 
 323                  * A property change event filter.
 
 325                 public interface IPropertyChangeEventFilter {
 
 328                          * Should the given event be filtered?
 
 331                          *          The property change event.
 
 332                          * @return <code>true</code> iff the given event should be filtered.
 
 334                         public boolean isFiltered(PropertyChangeEvent event);
 
 339                  * Property change listener. Listens for events in the options Map and fires
 
 340                  * a {@link org.eclipse.jface.util.PropertyChangeEvent}on this adapter with
 
 341                  * arguments from the received event.
 
 343                 private class PropertyChangeListener implements IPropertyChangeListener {
 
 348                         public void propertyChange(PropertyChangeEvent event) {
 
 349                                 if (getFilter().isFiltered(event))
 
 352                                 if (event.getNewValue() == null)
 
 353                                         fOptions.remove(event.getProperty());
 
 355                                         fOptions.put(event.getProperty(), event.getNewValue());
 
 357                                 firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
 
 361                 /** Listeners on this adapter */
 
 362                 private ListenerList fListeners = new ListenerList();
 
 364                 /** Listener on the adapted options Map */
 
 365                 private IPropertyChangeListener fListener = new PropertyChangeListener();
 
 367                 /** Adapted options Map */
 
 368                 private Map fOptions;
 
 370                 /** Preference store through which events are received. */
 
 371                 private IPreferenceStore fMockupPreferenceStore;
 
 373                 /** Property event filter. */
 
 374                 private IPropertyChangeEventFilter fFilter;
 
 377                  * Initialize with the given options.
 
 380                  *          The options to wrap
 
 381                  * @param mockupPreferenceStore
 
 382                  *          the mock-up preference store
 
 384                  *          the property change filter
 
 386                 public OptionsAdapter(Map options, IPreferenceStore mockupPreferenceStore, IPropertyChangeEventFilter filter) {
 
 387                         fMockupPreferenceStore = mockupPreferenceStore;
 
 395                 public void addPropertyChangeListener(IPropertyChangeListener listener) {
 
 396                         if (fListeners.size() == 0)
 
 397                                 fMockupPreferenceStore.addPropertyChangeListener(fListener);
 
 398                         fListeners.add(listener);
 
 404                 public void removePropertyChangeListener(IPropertyChangeListener listener) {
 
 405                         fListeners.remove(listener);
 
 406                         if (fListeners.size() == 0)
 
 407                                 fMockupPreferenceStore.removePropertyChangeListener(fListener);
 
 413                 public boolean contains(String name) {
 
 414                         return fOptions.containsKey(name);
 
 420                 public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
 
 421                         PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
 
 422                         Object[] listeners = fListeners.getListeners();
 
 423                         for (int i = 0; i < listeners.length; i++)
 
 424                                 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
 
 430                 public boolean getBoolean(String name) {
 
 431                         boolean value = BOOLEAN_DEFAULT_DEFAULT;
 
 432                         String s = (String) fOptions.get(name);
 
 434                                 value = s.equals(TRUE);
 
 441                 public boolean getDefaultBoolean(String name) {
 
 442                         return BOOLEAN_DEFAULT_DEFAULT;
 
 448                 public double getDefaultDouble(String name) {
 
 449                         return DOUBLE_DEFAULT_DEFAULT;
 
 455                 public float getDefaultFloat(String name) {
 
 456                         return FLOAT_DEFAULT_DEFAULT;
 
 462                 public int getDefaultInt(String name) {
 
 463                         return INT_DEFAULT_DEFAULT;
 
 469                 public long getDefaultLong(String name) {
 
 470                         return LONG_DEFAULT_DEFAULT;
 
 476                 public String getDefaultString(String name) {
 
 477                         return STRING_DEFAULT_DEFAULT;
 
 483                 public double getDouble(String name) {
 
 484                         double value = DOUBLE_DEFAULT_DEFAULT;
 
 485                         String s = (String) fOptions.get(name);
 
 488                                         value = new Double(s).doubleValue();
 
 489                                 } catch (NumberFormatException e) {
 
 498                 public float getFloat(String name) {
 
 499                         float value = FLOAT_DEFAULT_DEFAULT;
 
 500                         String s = (String) fOptions.get(name);
 
 503                                         value = new Float(s).floatValue();
 
 504                                 } catch (NumberFormatException e) {
 
 513                 public int getInt(String name) {
 
 514                         int value = INT_DEFAULT_DEFAULT;
 
 515                         String s = (String) fOptions.get(name);
 
 518                                         value = new Integer(s).intValue();
 
 519                                 } catch (NumberFormatException e) {
 
 528                 public long getLong(String name) {
 
 529                         long value = LONG_DEFAULT_DEFAULT;
 
 530                         String s = (String) fOptions.get(name);
 
 533                                         value = new Long(s).longValue();
 
 534                                 } catch (NumberFormatException e) {
 
 543                 public String getString(String name) {
 
 544                         String value = (String) fOptions.get(name);
 
 546                                 value = STRING_DEFAULT_DEFAULT;
 
 553                 public boolean isDefault(String name) {
 
 560                 public boolean needsSaving() {
 
 561                         return !fOptions.isEmpty();
 
 567                 public void putValue(String name, String value) {
 
 568                         throw new UnsupportedOperationException();
 
 574                 public void setDefault(String name, double value) {
 
 575                         throw new UnsupportedOperationException();
 
 581                 public void setDefault(String name, float value) {
 
 582                         throw new UnsupportedOperationException();
 
 588                 public void setDefault(String name, int value) {
 
 589                         throw new UnsupportedOperationException();
 
 595                 public void setDefault(String name, long value) {
 
 596                         throw new UnsupportedOperationException();
 
 602                 public void setDefault(String name, String defaultObject) {
 
 603                         throw new UnsupportedOperationException();
 
 609                 public void setDefault(String name, boolean value) {
 
 610                         throw new UnsupportedOperationException();
 
 616                 public void setToDefault(String name) {
 
 617                         throw new UnsupportedOperationException();
 
 623                 public void setValue(String name, double value) {
 
 624                         throw new UnsupportedOperationException();
 
 630                 public void setValue(String name, float value) {
 
 631                         throw new UnsupportedOperationException();
 
 637                 public void setValue(String name, int value) {
 
 638                         throw new UnsupportedOperationException();
 
 644                 public void setValue(String name, long value) {
 
 645                         throw new UnsupportedOperationException();
 
 651                 public void setValue(String name, String value) {
 
 652                         throw new UnsupportedOperationException();
 
 658                 public void setValue(String name, boolean value) {
 
 659                         throw new UnsupportedOperationException();
 
 663                  * Returns the adapted options Map.
 
 665                  * @return Returns the adapted options Map.
 
 667                 public Map getOptions() {
 
 672                  * Returns the mock-up preference store, events are received through this
 
 675                  * @return Returns the mock-up preference store.
 
 677                 public IPreferenceStore getMockupPreferenceStore() {
 
 678                         return fMockupPreferenceStore;
 
 682                  * Set the event filter to the given filter.
 
 687                 public void setFilter(IPropertyChangeEventFilter filter) {
 
 692                  * Returns the event filter.
 
 694                  * @return The event filter.
 
 696                 public IPropertyChangeEventFilter getFilter() {
 
 704         // class MouseClickListener implements KeyListener, MouseListener,
 
 705         // MouseMoveListener, FocusListener, PaintListener,
 
 706         // IPropertyChangeListener, IDocumentListener, ITextInputListener {
 
 708         // /** The session is active. */
 
 709         // private boolean fActive;
 
 711         // /** The currently active style range. */
 
 712         // private IRegion fActiveRegion;
 
 714         // /** The currently active style range as position. */
 
 715         // private Position fRememberedPosition;
 
 717         // /** The hand cursor. */
 
 718         // private Cursor fCursor;
 
 720         // /** The link color. */
 
 721         // private Color fColor;
 
 723         // /** The key modifier mask. */
 
 724         // private int fKeyModifierMask;
 
 726         // public void deactivate() {
 
 727         // deactivate(false);
 
 730         // public void deactivate(boolean redrawAll) {
 
 734         // repairRepresentation(redrawAll);
 
 738         // public void install() {
 
 740         // ISourceViewer sourceViewer = getSourceViewer();
 
 741         // if (sourceViewer == null)
 
 744         // StyledText text = sourceViewer.getTextWidget();
 
 745         // if (text == null || text.isDisposed())
 
 748         // updateColor(sourceViewer);
 
 750         // sourceViewer.addTextInputListener(this);
 
 752         // IDocument document = sourceViewer.getDocument();
 
 753         // if (document != null)
 
 754         // document.addDocumentListener(this);
 
 756         // text.addKeyListener(this);
 
 757         // text.addMouseListener(this);
 
 758         // text.addMouseMoveListener(this);
 
 759         // text.addFocusListener(this);
 
 760         // text.addPaintListener(this);
 
 762         // updateKeyModifierMask();
 
 764         // IPreferenceStore preferenceStore = getPreferenceStore();
 
 765         // preferenceStore.addPropertyChangeListener(this);
 
 768         // private void updateKeyModifierMask() {
 
 769         // String modifiers =
 
 770         // getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
 
 771         // fKeyModifierMask = computeStateMask(modifiers);
 
 772         // if (fKeyModifierMask == -1) {
 
 773         // // Fallback to stored state mask
 
 774         // fKeyModifierMask =
 
 775         // getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
 
 780         // private int computeStateMask(String modifiers) {
 
 781         // if (modifiers == null)
 
 784         // if (modifiers.length() == 0)
 
 787         // int stateMask = 0;
 
 788         // StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-*
 
 790         // while (modifierTokenizer.hasMoreTokens()) {
 
 792         // EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
 
 793         // if (modifier == 0 || (stateMask & modifier) == modifier)
 
 795         // stateMask = stateMask | modifier;
 
 800         // public void uninstall() {
 
 802         // if (fColor != null) {
 
 807         // if (fCursor != null) {
 
 808         // fCursor.dispose();
 
 812         // ISourceViewer sourceViewer = getSourceViewer();
 
 813         // if (sourceViewer == null)
 
 816         // sourceViewer.removeTextInputListener(this);
 
 818         // IDocument document = sourceViewer.getDocument();
 
 819         // if (document != null)
 
 820         // document.removeDocumentListener(this);
 
 822         // IPreferenceStore preferenceStore = getPreferenceStore();
 
 823         // if (preferenceStore != null)
 
 824         // preferenceStore.removePropertyChangeListener(this);
 
 826         // StyledText text = sourceViewer.getTextWidget();
 
 827         // if (text == null || text.isDisposed())
 
 830         // text.removeKeyListener(this);
 
 831         // text.removeMouseListener(this);
 
 832         // text.removeMouseMoveListener(this);
 
 833         // text.removeFocusListener(this);
 
 834         // text.removePaintListener(this);
 
 838         // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
 
 840         // public void propertyChange(PropertyChangeEvent event) {
 
 841         // if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
 
 842         // ISourceViewer viewer = getSourceViewer();
 
 843         // if (viewer != null)
 
 844         // updateColor(viewer);
 
 845         // } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
 
 846         // updateKeyModifierMask();
 
 850         // private void updateColor(ISourceViewer viewer) {
 
 851         // if (fColor != null)
 
 854         // StyledText text = viewer.getTextWidget();
 
 855         // if (text == null || text.isDisposed())
 
 858         // Display display = text.getDisplay();
 
 859         // fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
 
 863         // * Creates a color from the information stored in the given preference
 
 864         // store. Returns <code>null</code> if there is no such
 
 865         // * information available.
 
 867         // private Color createColor(IPreferenceStore store, String key, Display
 
 872         // if (store.contains(key)) {
 
 874         // if (store.isDefault(key))
 
 875         // rgb = PreferenceConverter.getDefaultColor(store, key);
 
 877         // rgb = PreferenceConverter.getColor(store, key);
 
 880         // return new Color(display, rgb);
 
 886         // private void repairRepresentation() {
 
 887         // repairRepresentation(false);
 
 890         // private void repairRepresentation(boolean redrawAll) {
 
 892         // if (fActiveRegion == null)
 
 895         // ISourceViewer viewer = getSourceViewer();
 
 896         // if (viewer != null) {
 
 897         // resetCursor(viewer);
 
 899         // int offset = fActiveRegion.getOffset();
 
 900         // int length = fActiveRegion.getLength();
 
 903         // if (!redrawAll && viewer instanceof ITextViewerExtension2)
 
 904         // ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset,
 
 907         // viewer.invalidateTextPresentation();
 
 909         // // remove underline
 
 910         // if (viewer instanceof ITextViewerExtension3) {
 
 911         // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
 
 912         // offset = extension.modelOffset2WidgetOffset(offset);
 
 914         // offset -= viewer.getVisibleRegion().getOffset();
 
 917         // StyledText text = viewer.getTextWidget();
 
 919         // text.redrawRange(offset, length, true);
 
 920         // } catch (IllegalArgumentException x) {
 
 921         // PHPeclipsePlugin.log(x);
 
 925         // fActiveRegion = null;
 
 928         // // will eventually be replaced by a method provided by jdt.core
 
 929         // private IRegion selectWord(IDocument document, int anchor) {
 
 932         // int offset = anchor;
 
 935         // while (offset >= 0) {
 
 936         // c = document.getChar(offset);
 
 937         // if (!Scanner.isPHPIdentifierPart(c))
 
 942         // int start = offset;
 
 945         // int length = document.getLength();
 
 947         // while (offset < length) {
 
 948         // c = document.getChar(offset);
 
 949         // if (!Scanner.isPHPIdentifierPart(c))
 
 957         // return new Region(start, 0);
 
 959         // return new Region(start + 1, end - start - 1);
 
 961         // } catch (BadLocationException x) {
 
 966         // IRegion getCurrentTextRegion(ISourceViewer viewer) {
 
 968         // int offset = getCurrentTextOffset(viewer);
 
 973         // // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
 
 974         // // if (input == null)
 
 979         // // IJavaElement[] elements= null;
 
 980         // // synchronized (input) {
 
 981         // // elements= ((ICodeAssist) input).codeSelect(offset, 0);
 
 984         // // if (elements == null || elements.length == 0)
 
 987         // // return selectWord(viewer.getDocument(), offset);
 
 989         // // } catch (JavaModelException e) {
 
 994         // private int getCurrentTextOffset(ISourceViewer viewer) {
 
 997         // StyledText text = viewer.getTextWidget();
 
 998         // if (text == null || text.isDisposed())
 
1001         // Display display = text.getDisplay();
 
1002         // Point absolutePosition = display.getCursorLocation();
 
1003         // Point relativePosition = text.toControl(absolutePosition);
 
1005         // int widgetOffset = text.getOffsetAtLocation(relativePosition);
 
1006         // if (viewer instanceof ITextViewerExtension3) {
 
1007         // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
 
1008         // return extension.widgetOffset2ModelOffset(widgetOffset);
 
1010         // return widgetOffset + viewer.getVisibleRegion().getOffset();
 
1013         // } catch (IllegalArgumentException e) {
 
1018         // private void highlightRegion(ISourceViewer viewer, IRegion region) {
 
1020         // if (region.equals(fActiveRegion))
 
1023         // repairRepresentation();
 
1025         // StyledText text = viewer.getTextWidget();
 
1026         // if (text == null || text.isDisposed())
 
1029         // // highlight region
 
1033         // if (viewer instanceof ITextViewerExtension3) {
 
1034         // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
 
1035         // IRegion widgetRange = extension.modelRange2WidgetRange(region);
 
1036         // if (widgetRange == null)
 
1039         // offset = widgetRange.getOffset();
 
1040         // length = widgetRange.getLength();
 
1043         // offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
 
1044         // length = region.getLength();
 
1047         // StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
 
1048         // Color foregroundColor = fColor;
 
1049         // Color backgroundColor = oldStyleRange == null ? text.getBackground() :
 
1050         // oldStyleRange.background;
 
1051         // StyleRange styleRange = new StyleRange(offset, length, foregroundColor,
 
1052         // backgroundColor);
 
1053         // text.setStyleRange(styleRange);
 
1056         // text.redrawRange(offset, length, true);
 
1058         // fActiveRegion = region;
 
1061         // private void activateCursor(ISourceViewer viewer) {
 
1062         // StyledText text = viewer.getTextWidget();
 
1063         // if (text == null || text.isDisposed())
 
1065         // Display display = text.getDisplay();
 
1066         // if (fCursor == null)
 
1067         // fCursor = new Cursor(display, SWT.CURSOR_HAND);
 
1068         // text.setCursor(fCursor);
 
1071         // private void resetCursor(ISourceViewer viewer) {
 
1072         // StyledText text = viewer.getTextWidget();
 
1073         // if (text != null && !text.isDisposed())
 
1074         // text.setCursor(null);
 
1076         // if (fCursor != null) {
 
1077         // fCursor.dispose();
 
1084         // org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
 
1086         // public void keyPressed(KeyEvent event) {
 
1093         // if (event.keyCode != fKeyModifierMask) {
 
1100         // // removed for #25871
 
1102         // // ISourceViewer viewer= getSourceViewer();
 
1103         // // if (viewer == null)
 
1106         // // IRegion region= getCurrentTextRegion(viewer);
 
1107         // // if (region == null)
 
1110         // // highlightRegion(viewer, region);
 
1111         // // activateCursor(viewer);
 
1116         // org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
 
1118         // public void keyReleased(KeyEvent event) {
 
1128         // org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
 
1130         // public void mouseDoubleClick(MouseEvent e) {
 
1135         // org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
 
1137         // public void mouseDown(MouseEvent event) {
 
1142         // if (event.stateMask != fKeyModifierMask) {
 
1147         // if (event.button != 1) {
 
1155         // org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
 
1157         // public void mouseUp(MouseEvent e) {
 
1162         // if (e.button != 1) {
 
1167         // boolean wasActive = fCursor != null;
 
1172         // IAction action = getAction("OpenEditor"); //$NON-NLS-1$
 
1173         // if (action != null)
 
1180         // org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
 
1182         // public void mouseMove(MouseEvent event) {
 
1184         // if (event.widget instanceof Control && !((Control)
 
1185         // event.widget).isFocusControl()) {
 
1191         // if (event.stateMask != fKeyModifierMask)
 
1193         // // modifier was already pressed
 
1197         // ISourceViewer viewer = getSourceViewer();
 
1198         // if (viewer == null) {
 
1203         // StyledText text = viewer.getTextWidget();
 
1204         // if (text == null || text.isDisposed()) {
 
1209         // if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0)
 
1215         // IRegion region = getCurrentTextRegion(viewer);
 
1216         // if (region == null || region.getLength() == 0) {
 
1217         // repairRepresentation();
 
1221         // highlightRegion(viewer, region);
 
1222         // activateCursor(viewer);
 
1227         // org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
 
1229         // public void focusGained(FocusEvent e) {
 
1234         // org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
 
1236         // public void focusLost(FocusEvent event) {
 
1242         // org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
 
1244         // public void documentAboutToBeChanged(DocumentEvent event) {
 
1245         // if (fActive && fActiveRegion != null) {
 
1246         // fRememberedPosition = new Position(fActiveRegion.getOffset(),
 
1247         // fActiveRegion.getLength());
 
1249         // event.getDocument().addPosition(fRememberedPosition);
 
1250         // } catch (BadLocationException x) {
 
1251         // fRememberedPosition = null;
 
1258         // org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
 
1260         // public void documentChanged(DocumentEvent event) {
 
1261         // if (fRememberedPosition != null && !fRememberedPosition.isDeleted()) {
 
1262         // event.getDocument().removePosition(fRememberedPosition);
 
1263         // fActiveRegion = new Region(fRememberedPosition.getOffset(),
 
1264         // fRememberedPosition.getLength());
 
1266         // fRememberedPosition = null;
 
1268         // ISourceViewer viewer = getSourceViewer();
 
1269         // if (viewer != null) {
 
1270         // StyledText widget = viewer.getTextWidget();
 
1271         // if (widget != null && !widget.isDisposed()) {
 
1272         // widget.getDisplay().asyncExec(new Runnable() {
 
1273         // public void run() {
 
1283         // org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
 
1284         // * org.eclipse.jface.text.IDocument)
 
1286         // public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument
 
1288         // if (oldInput == null)
 
1291         // oldInput.removeDocumentListener(this);
 
1296         // org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
 
1297         // * org.eclipse.jface.text.IDocument)
 
1299         // public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
 
1300         // if (newInput == null)
 
1302         // newInput.addDocumentListener(this);
 
1306         // * @see PaintListener#paintControl(PaintEvent)
 
1308         // public void paintControl(PaintEvent event) {
 
1309         // if (fActiveRegion == null)
 
1312         // ISourceViewer viewer = getSourceViewer();
 
1313         // if (viewer == null)
 
1316         // StyledText text = viewer.getTextWidget();
 
1317         // if (text == null || text.isDisposed())
 
1323         // if (viewer instanceof ITextViewerExtension3) {
 
1325         // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
 
1326         // IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset,
 
1328         // if (widgetRange == null)
 
1331         // offset = widgetRange.getOffset();
 
1332         // length = widgetRange.getLength();
 
1336         // IRegion region = viewer.getVisibleRegion();
 
1337         // if (!includes(region, fActiveRegion))
 
1340         // offset = fActiveRegion.getOffset() - region.getOffset();
 
1341         // length = fActiveRegion.getLength();
 
1344         // // support for bidi
 
1345         // Point minLocation = getMinimumLocation(text, offset, length);
 
1346         // Point maxLocation = getMaximumLocation(text, offset, length);
 
1348         // int x1 = minLocation.x;
 
1349         // int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
 
1350         // int y = minLocation.y + text.getLineHeight() - 1;
 
1352         // GC gc = event.gc;
 
1353         // if (fColor != null && !fColor.isDisposed())
 
1354         // gc.setForeground(fColor);
 
1355         // gc.drawLine(x1, y, x2, y);
 
1358         // private boolean includes(IRegion region, IRegion position) {
 
1359         // return position.getOffset() >= region.getOffset()
 
1360         // && position.getOffset() + position.getLength() <= region.getOffset() +
 
1361         // region.getLength();
 
1364         // private Point getMinimumLocation(StyledText text, int offset, int length) {
 
1365         // Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
 
1367         // for (int i = 0; i <= length; i++) {
 
1368         // Point location = text.getLocationAtOffset(offset + i);
 
1370         // if (location.x < minLocation.x)
 
1371         // minLocation.x = location.x;
 
1372         // if (location.y < minLocation.y)
 
1373         // minLocation.y = location.y;
 
1376         // return minLocation;
 
1379         // private Point getMaximumLocation(StyledText text, int offset, int length) {
 
1380         // Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
 
1382         // for (int i = 0; i <= length; i++) {
 
1383         // Point location = text.getLocationAtOffset(offset + i);
 
1385         // if (location.x > maxLocation.x)
 
1386         // maxLocation.x = location.x;
 
1387         // if (location.y > maxLocation.y)
 
1388         // maxLocation.y = location.y;
 
1391         // return maxLocation;
 
1397         class MouseClickListener implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener,
 
1398                         IPropertyChangeListener, IDocumentListener, ITextInputListener, ITextPresentationListener {
 
1400                 /** The session is active. */
 
1401                 private boolean fActive;
 
1403                 /** The currently active style range. */
 
1404                 private IRegion fActiveRegion;
 
1406                 /** The currently active style range as position. */
 
1407                 private Position fRememberedPosition;
 
1409                 /** The hand cursor. */
 
1410                 private Cursor fCursor;
 
1412                 /** The link color. */
 
1413                 private Color fColor;
 
1415                 /** The key modifier mask. */
 
1416                 private int fKeyModifierMask;
 
1418                 public void deactivate() {
 
1422                 public void deactivate(boolean redrawAll) {
 
1426                         repairRepresentation(redrawAll);
 
1430                 public void install() {
 
1431                         ISourceViewer sourceViewer = getSourceViewer();
 
1432                         if (sourceViewer == null)
 
1435                         StyledText text = sourceViewer.getTextWidget();
 
1436                         if (text == null || text.isDisposed())
 
1439                         updateColor(sourceViewer);
 
1441                         sourceViewer.addTextInputListener(this);
 
1443                         IDocument document = sourceViewer.getDocument();
 
1444                         if (document != null)
 
1445                                 document.addDocumentListener(this);
 
1447                         text.addKeyListener(this);
 
1448                         text.addMouseListener(this);
 
1449                         text.addMouseMoveListener(this);
 
1450                         text.addFocusListener(this);
 
1451                         text.addPaintListener(this);
 
1453                         ((ITextViewerExtension4) sourceViewer).addTextPresentationListener(this);
 
1455                         updateKeyModifierMask();
 
1457                         IPreferenceStore preferenceStore = getPreferenceStore();
 
1458                         preferenceStore.addPropertyChangeListener(this);
 
1461                 private void updateKeyModifierMask() {
 
1462                         String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
 
1463                         fKeyModifierMask = computeStateMask(modifiers);
 
1464                         if (fKeyModifierMask == -1) {
 
1465                                 // Fall back to stored state mask
 
1466                                 fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
 
1470                 private int computeStateMask(String modifiers) {
 
1471                         if (modifiers == null)
 
1474                         if (modifiers.length() == 0)
 
1478                         StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
 
1479                         while (modifierTokenizer.hasMoreTokens()) {
 
1480                                 int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
 
1481                                 if (modifier == 0 || (stateMask & modifier) == modifier)
 
1483                                 stateMask = stateMask | modifier;
 
1488                 public void uninstall() {
 
1490                         if (fColor != null) {
 
1495                         if (fCursor != null) {
 
1500                         ISourceViewer sourceViewer = getSourceViewer();
 
1501                         if (sourceViewer != null)
 
1502                                 sourceViewer.removeTextInputListener(this);
 
1504                         IDocumentProvider documentProvider = getDocumentProvider();
 
1505                         if (documentProvider != null) {
 
1506                                 IDocument document = documentProvider.getDocument(getEditorInput());
 
1507                                 if (document != null)
 
1508                                         document.removeDocumentListener(this);
 
1511                         IPreferenceStore preferenceStore = getPreferenceStore();
 
1512                         if (preferenceStore != null)
 
1513                                 preferenceStore.removePropertyChangeListener(this);
 
1515                         if (sourceViewer == null)
 
1518                         StyledText text = sourceViewer.getTextWidget();
 
1519                         if (text == null || text.isDisposed())
 
1522                         text.removeKeyListener(this);
 
1523                         text.removeMouseListener(this);
 
1524                         text.removeMouseMoveListener(this);
 
1525                         text.removeFocusListener(this);
 
1526                         text.removePaintListener(this);
 
1528                         ((ITextViewerExtension4) sourceViewer).removeTextPresentationListener(this);
 
1532                  * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
 
1534                 public void propertyChange(PropertyChangeEvent event) {
 
1535                         if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
 
1536                                 ISourceViewer viewer = getSourceViewer();
 
1538                                         updateColor(viewer);
 
1539                         } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
 
1540                                 updateKeyModifierMask();
 
1544                 private void updateColor(ISourceViewer viewer) {
 
1548                         StyledText text = viewer.getTextWidget();
 
1549                         if (text == null || text.isDisposed())
 
1552                         Display display = text.getDisplay();
 
1553                         fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
 
1557                  * Creates a color from the information stored in the given preference
 
1561                  *          the preference store
 
1566                  * @return the color or <code>null</code> if there is no such information
 
1569                 private Color createColor(IPreferenceStore store, String key, Display display) {
 
1573                         if (store.contains(key)) {
 
1575                                 if (store.isDefault(key))
 
1576                                         rgb = PreferenceConverter.getDefaultColor(store, key);
 
1578                                         rgb = PreferenceConverter.getColor(store, key);
 
1581                                         return new Color(display, rgb);
 
1587                 private void repairRepresentation() {
 
1588                         repairRepresentation(false);
 
1591                 private void repairRepresentation(boolean redrawAll) {
 
1593                         if (fActiveRegion == null)
 
1596                         int offset = fActiveRegion.getOffset();
 
1597                         int length = fActiveRegion.getLength();
 
1598                         fActiveRegion = null;
 
1600                         ISourceViewer viewer = getSourceViewer();
 
1601                         if (viewer != null) {
 
1603                                 resetCursor(viewer);
 
1605                                 // Invalidate ==> remove applied text presentation
 
1606                                 if (!redrawAll && viewer instanceof ITextViewerExtension2)
 
1607                                         ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
 
1609                                         viewer.invalidateTextPresentation();
 
1612                                 if (viewer instanceof ITextViewerExtension5) {
 
1613                                         ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
 
1614                                         offset = extension.modelOffset2WidgetOffset(offset);
 
1616                                         offset -= viewer.getVisibleRegion().getOffset();
 
1619                                         StyledText text = viewer.getTextWidget();
 
1621                                         text.redrawRange(offset, length, false);
 
1622                                 } catch (IllegalArgumentException x) {
 
1623                                         // JavaPlugin.log(x);
 
1628                 // will eventually be replaced by a method provided by jdt.core
 
1629                 private IRegion selectWord(IDocument document, int anchor) {
 
1632                                 int offset = anchor;
 
1635                                 while (offset >= 0) {
 
1636                                         c = document.getChar(offset);
 
1637                                         if (!Scanner.isPHPIdentifierPart(c) && c != '$')
 
1645                                 int length = document.getLength();
 
1647                                 while (offset < length) {
 
1648                                         c = document.getChar(offset);
 
1649                                         if (!Scanner.isPHPIdentifierPart(c) && c != '$')
 
1657                                         return new Region(start, 0);
 
1659                                         return new Region(start + 1, end - start - 1);
 
1661                         } catch (BadLocationException x) {
 
1666                 IRegion getCurrentTextRegion(ISourceViewer viewer) {
 
1668                         int offset = getCurrentTextOffset(viewer);
 
1672                         IJavaElement input = SelectionConverter.getInput(PHPEditor.this);
 
1678                         // IJavaElement[] elements= null;
 
1679                         // synchronized (input) {
 
1680                         // elements= ((ICodeAssist) input).codeSelect(offset, 0);
 
1683                         // if (elements == null || elements.length == 0)
 
1686                         return selectWord(viewer.getDocument(), offset);
 
1688                         // } catch (JavaModelException e) {
 
1693                 private int getCurrentTextOffset(ISourceViewer viewer) {
 
1696                                 StyledText text = viewer.getTextWidget();
 
1697                                 if (text == null || text.isDisposed())
 
1700                                 Display display = text.getDisplay();
 
1701                                 Point absolutePosition = display.getCursorLocation();
 
1702                                 Point relativePosition = text.toControl(absolutePosition);
 
1704                                 int widgetOffset = text.getOffsetAtLocation(relativePosition);
 
1705                                 if (viewer instanceof ITextViewerExtension5) {
 
1706                                         ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
 
1707                                         return extension.widgetOffset2ModelOffset(widgetOffset);
 
1709                                         return widgetOffset + viewer.getVisibleRegion().getOffset();
 
1712                         } catch (IllegalArgumentException e) {
 
1717                 public void applyTextPresentation(TextPresentation textPresentation) {
 
1718                         if (fActiveRegion == null)
 
1720                         IRegion region = textPresentation.getExtent();
 
1721                         if (fActiveRegion.getOffset() + fActiveRegion.getLength() >= region.getOffset()
 
1722                                         && region.getOffset() + region.getLength() > fActiveRegion.getOffset())
 
1723                                 textPresentation.mergeStyleRange(new StyleRange(fActiveRegion.getOffset(), fActiveRegion.getLength(), fColor, null));
 
1726                 private void highlightRegion(ISourceViewer viewer, IRegion region) {
 
1728                         if (region.equals(fActiveRegion))
 
1731                         repairRepresentation();
 
1733                         StyledText text = viewer.getTextWidget();
 
1734                         if (text == null || text.isDisposed())
 
1740                         if (viewer instanceof ITextViewerExtension5) {
 
1741                                 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
 
1742                                 IRegion widgetRange = extension.modelRange2WidgetRange(region);
 
1743                                 if (widgetRange == null)
 
1746                                 offset = widgetRange.getOffset();
 
1747                                 length = widgetRange.getLength();
 
1750                                 offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
 
1751                                 length = region.getLength();
 
1753                         text.redrawRange(offset, length, false);
 
1755                         // Invalidate region ==> apply text presentation
 
1756                         fActiveRegion = region;
 
1757                         if (viewer instanceof ITextViewerExtension2)
 
1758                                 ((ITextViewerExtension2) viewer).invalidateTextPresentation(region.getOffset(), region.getLength());
 
1760                                 viewer.invalidateTextPresentation();
 
1763                 private void activateCursor(ISourceViewer viewer) {
 
1764                         StyledText text = viewer.getTextWidget();
 
1765                         if (text == null || text.isDisposed())
 
1767                         Display display = text.getDisplay();
 
1768                         if (fCursor == null)
 
1769                                 fCursor = new Cursor(display, SWT.CURSOR_HAND);
 
1770                         text.setCursor(fCursor);
 
1773                 private void resetCursor(ISourceViewer viewer) {
 
1774                         StyledText text = viewer.getTextWidget();
 
1775                         if (text != null && !text.isDisposed())
 
1776                                 text.setCursor(null);
 
1778                         if (fCursor != null) {
 
1785                  * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
 
1787                 public void keyPressed(KeyEvent event) {
 
1794                         if (event.keyCode != fKeyModifierMask) {
 
1801                         // removed for #25871
 
1803                         // ISourceViewer viewer= getSourceViewer();
 
1804                         // if (viewer == null)
 
1807                         // IRegion region= getCurrentTextRegion(viewer);
 
1808                         // if (region == null)
 
1811                         // highlightRegion(viewer, region);
 
1812                         // activateCursor(viewer);
 
1816                  * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
 
1818                 public void keyReleased(KeyEvent event) {
 
1827                  * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
 
1829                 public void mouseDoubleClick(MouseEvent e) {
 
1833                  * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
 
1835                 public void mouseDown(MouseEvent event) {
 
1840                         if (event.stateMask != fKeyModifierMask) {
 
1845                         if (event.button != 1) {
 
1852                  * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
 
1854                 public void mouseUp(MouseEvent e) {
 
1859                         if (e.button != 1) {
 
1864                         boolean wasActive = fCursor != null;
 
1869                                 IAction action = getAction("OpenEditor"); //$NON-NLS-1$
 
1876                  * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
 
1878                 public void mouseMove(MouseEvent event) {
 
1880                         if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
 
1886                                 if (event.stateMask != fKeyModifierMask)
 
1888                                 // modifier was already pressed
 
1892                         ISourceViewer viewer = getSourceViewer();
 
1893                         if (viewer == null) {
 
1898                         StyledText text = viewer.getTextWidget();
 
1899                         if (text == null || text.isDisposed()) {
 
1904                         if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
 
1909                         IRegion region = getCurrentTextRegion(viewer);
 
1910                         if (region == null || region.getLength() == 0) {
 
1911                                 repairRepresentation();
 
1915                         highlightRegion(viewer, region);
 
1916                         activateCursor(viewer);
 
1920                  * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
 
1922                 public void focusGained(FocusEvent e) {
 
1926                  * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
 
1928                 public void focusLost(FocusEvent event) {
 
1933                  * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
 
1935                 public void documentAboutToBeChanged(DocumentEvent event) {
 
1936                         if (fActive && fActiveRegion != null) {
 
1937                                 fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
 
1939                                         event.getDocument().addPosition(fRememberedPosition);
 
1940                                 } catch (BadLocationException x) {
 
1941                                         fRememberedPosition = null;
 
1947                  * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
 
1949                 public void documentChanged(DocumentEvent event) {
 
1950                         if (fRememberedPosition != null) {
 
1951                                 if (!fRememberedPosition.isDeleted()) {
 
1953                                         event.getDocument().removePosition(fRememberedPosition);
 
1954                                         fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
 
1955                                         fRememberedPosition = null;
 
1957                                         ISourceViewer viewer = getSourceViewer();
 
1958                                         if (viewer != null) {
 
1959                                                 StyledText widget = viewer.getTextWidget();
 
1960                                                 if (widget != null && !widget.isDisposed()) {
 
1961                                                         widget.getDisplay().asyncExec(new Runnable() {
 
1970                                         fActiveRegion = null;
 
1971                                         fRememberedPosition = null;
 
1978                  * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
 
1979                  *      org.eclipse.jface.text.IDocument)
 
1981                 public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
 
1982                         if (oldInput == null)
 
1985                         oldInput.removeDocumentListener(this);
 
1989                  * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
 
1990                  *      org.eclipse.jface.text.IDocument)
 
1992                 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
 
1993                         if (newInput == null)
 
1995                         newInput.addDocumentListener(this);
 
1999                  * @see PaintListener#paintControl(PaintEvent)
 
2001                 public void paintControl(PaintEvent event) {
 
2002                         if (fActiveRegion == null)
 
2005                         ISourceViewer viewer = getSourceViewer();
 
2009                         StyledText text = viewer.getTextWidget();
 
2010                         if (text == null || text.isDisposed())
 
2016                         if (viewer instanceof ITextViewerExtension5) {
 
2018                                 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
 
2019                                 IRegion widgetRange = extension.modelRange2WidgetRange(fActiveRegion);
 
2020                                 if (widgetRange == null)
 
2023                                 offset = widgetRange.getOffset();
 
2024                                 length = widgetRange.getLength();
 
2028                                 IRegion region = viewer.getVisibleRegion();
 
2029                                 if (!includes(region, fActiveRegion))
 
2032                                 offset = fActiveRegion.getOffset() - region.getOffset();
 
2033                                 length = fActiveRegion.getLength();
 
2037                         Point minLocation = getMinimumLocation(text, offset, length);
 
2038                         Point maxLocation = getMaximumLocation(text, offset, length);
 
2040                         int x1 = minLocation.x;
 
2041                         int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
 
2042                         int y = minLocation.y + text.getLineHeight() - 1;
 
2045                         if (fColor != null && !fColor.isDisposed())
 
2046                                 gc.setForeground(fColor);
 
2047                         gc.drawLine(x1, y, x2, y);
 
2050                 private boolean includes(IRegion region, IRegion position) {
 
2051                         return position.getOffset() >= region.getOffset()
 
2052                                         && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
 
2055                 private Point getMinimumLocation(StyledText text, int offset, int length) {
 
2056                         Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
 
2058                         for (int i = 0; i <= length; i++) {
 
2059                                 Point location = text.getLocationAtOffset(offset + i);
 
2061                                 if (location.x < minLocation.x)
 
2062                                         minLocation.x = location.x;
 
2063                                 if (location.y < minLocation.y)
 
2064                                         minLocation.y = location.y;
 
2070                 private Point getMaximumLocation(StyledText text, int offset, int length) {
 
2071                         Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
 
2073                         for (int i = 0; i <= length; i++) {
 
2074                                 Point location = text.getLocationAtOffset(offset + i);
 
2076                                 if (location.x > maxLocation.x)
 
2077                                         maxLocation.x = location.x;
 
2078                                 if (location.y > maxLocation.y)
 
2079                                         maxLocation.y = location.y;
 
2087          * This action dispatches into two behaviours: If there is no current text
 
2088          * hover, the javadoc is displayed using information presenter. If there is a
 
2089          * current text hover, it is converted into a information presenter in order
 
2090          * to make it sticky.
 
2092         class InformationDispatchAction extends TextEditorAction {
 
2094                 /** The wrapped text operation action. */
 
2095                 private final TextOperationAction fTextOperationAction;
 
2098                  * Creates a dispatch action.
 
2100                 public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
 
2101                         super(resourceBundle, prefix, PHPEditor.this);
 
2102                         if (textOperationAction == null)
 
2103                                 throw new IllegalArgumentException();
 
2104                         fTextOperationAction = textOperationAction;
 
2108                  * @see org.eclipse.jface.action.IAction#run()
 
2112                         ISourceViewer sourceViewer = getSourceViewer();
 
2113                         if (sourceViewer == null) {
 
2114                                 fTextOperationAction.run();
 
2118                         if (!(sourceViewer instanceof ITextViewerExtension2)) {
 
2119                                 fTextOperationAction.run();
 
2123                         ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
 
2125                         // does a text hover exist?
 
2126                         ITextHover textHover = textViewerExtension2.getCurrentTextHover();
 
2127                         if (textHover == null) {
 
2128                                 fTextOperationAction.run();
 
2132                         Point hoverEventLocation = textViewerExtension2.getHoverEventLocation();
 
2133                         int offset = computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
 
2135                                 fTextOperationAction.run();
 
2140                                 // get the text hover content
 
2141                                 IDocument document = sourceViewer.getDocument();
 
2142                                 String contentType = document.getContentType(offset);
 
2144                                 final IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
 
2145                                 if (hoverRegion == null)
 
2148                                 final String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);
 
2150                                 // with information provider
 
2151                                 IInformationProvider informationProvider = new IInformationProvider() {
 
2153                                          * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer,
 
2156                                         public IRegion getSubject(ITextViewer textViewer, int offset) {
 
2161                                          * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer,
 
2162                                          *      org.eclipse.jface.text.IRegion)
 
2164                                         public String getInformation(ITextViewer textViewer, IRegion subject) {
 
2169                                 fInformationPresenter.setOffset(offset);
 
2170                                 fInformationPresenter.setInformationProvider(informationProvider, contentType);
 
2171                                 fInformationPresenter.showInformation();
 
2173                         } catch (BadLocationException e) {
 
2177                 // modified version from TextViewer
 
2178                 private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
 
2180                         StyledText styledText = textViewer.getTextWidget();
 
2181                         IDocument document = textViewer.getDocument();
 
2183                         if (document == null)
 
2187                                 int widgetLocation = styledText.getOffsetAtLocation(new Point(x, y));
 
2188                                 if (textViewer instanceof ITextViewerExtension5) {
 
2189                                         ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer;
 
2190                                         return extension.widgetOffset2ModelOffset(widgetLocation);
 
2192                                         IRegion visibleRegion = textViewer.getVisibleRegion();
 
2193                                         return widgetLocation + visibleRegion.getOffset();
 
2195                         } catch (IllegalArgumentException e) {
 
2203          * This action implements smart home.
 
2205          * Instead of going to the start of a line it does the following: - if smart
 
2206          * home/end is enabled and the caret is after the line's first non-whitespace
 
2207          * then the caret is moved directly before it, taking JavaDoc and multi-line
 
2208          * comments into account. - if the caret is before the line's first
 
2209          * non-whitespace the caret is moved to the beginning of the line - if the
 
2210          * caret is at the beginning of the line see first case.
 
2214         protected class SmartLineStartAction extends LineStartAction {
 
2217                  * Creates a new smart line start action
 
2220                  *          the styled text widget
 
2222                  *          a boolean flag which tells if the text up to the beginning of
 
2223                  *          the line should be selected
 
2225                 public SmartLineStartAction(final StyledText textWidget, final boolean doSelect) {
 
2226                         super(textWidget, doSelect);
 
2230                  * @see org.eclipse.ui.texteditor.AbstractTextEditor.LineStartAction#getLineStartPosition(java.lang.String,
 
2231                  *      int, java.lang.String)
 
2233                 protected int getLineStartPosition(final IDocument document, final String line, final int length, final int offset) {
 
2235                         String type = IDocument.DEFAULT_CONTENT_TYPE;
 
2237                                 type = TextUtilities.getContentType(document, IPHPPartitions.PHP_PARTITIONING, offset, true);
 
2238                         } catch (BadLocationException exception) {
 
2239                                 // Should not happen
 
2242                         int index = super.getLineStartPosition(document, line, length, offset);
 
2243                         if (type.equals(IPHPPartitions.PHP_PHPDOC_COMMENT) || type.equals(IPHPPartitions.PHP_MULTILINE_COMMENT)) {
 
2244                                 if (index < length - 1 && line.charAt(index) == '*' && line.charAt(index + 1) != '/') {
 
2247                                         } while (index < length && Character.isWhitespace(line.charAt(index)));
 
2250                                 if (index < length - 1 && line.charAt(index) == '/' && line.charAt(index + 1) == '/') {
 
2254                                         } while (index < length && Character.isWhitespace(line.charAt(index)));
 
2262          * Text navigation action to navigate to the next sub-word.
 
2266         protected abstract class NextSubWordAction extends TextNavigationAction {
 
2268                 protected JavaWordIterator fIterator = new JavaWordIterator();
 
2271                  * Creates a new next sub-word action.
 
2274                  *          Action code for the default operation. Must be an action code
 
2276                  * @see org.eclipse.swt.custom.ST.
 
2278                 protected NextSubWordAction(int code) {
 
2279                         super(getSourceViewer().getTextWidget(), code);
 
2283                  * @see org.eclipse.jface.action.IAction#run()
 
2286                         // Check whether we are in a java code partition and the preference is
 
2288                         final IPreferenceStore store = getPreferenceStore();
 
2289                         if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
 
2294                         final ISourceViewer viewer = getSourceViewer();
 
2295                         final IDocument document = viewer.getDocument();
 
2296                         fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document));
 
2297                         int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
 
2301                         int next = findNextPosition(position);
 
2302                         if (next != BreakIterator.DONE) {
 
2303                                 setCaretPosition(next);
 
2304                                 getTextWidget().showSelection();
 
2305                                 fireSelectionChanged();
 
2311                  * Finds the next position after the given position.
 
2314                  *          the current position
 
2315                  * @return the next position
 
2317                 protected int findNextPosition(int position) {
 
2318                         ISourceViewer viewer = getSourceViewer();
 
2320                         while (position != BreakIterator.DONE && widget == -1) { // TODO:
 
2322                                 position = fIterator.following(position);
 
2323                                 if (position != BreakIterator.DONE)
 
2324                                         widget = modelOffset2WidgetOffset(viewer, position);
 
2330                  * Sets the caret position to the sub-word boundary given with
 
2331                  * <code>position</code>.
 
2334                  *          Position where the action should move the caret
 
2336                 protected abstract void setCaretPosition(int position);
 
2340          * Text navigation action to navigate to the next sub-word.
 
2344         protected class NavigateNextSubWordAction extends NextSubWordAction {
 
2347                  * Creates a new navigate next sub-word action.
 
2349                 public NavigateNextSubWordAction() {
 
2350                         super(ST.WORD_NEXT);
 
2354                  * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
 
2356                 protected void setCaretPosition(final int position) {
 
2357                         getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position));
 
2362          * Text operation action to delete the next sub-word.
 
2366         protected class DeleteNextSubWordAction extends NextSubWordAction implements IUpdate {
 
2369                  * Creates a new delete next sub-word action.
 
2371                 public DeleteNextSubWordAction() {
 
2372                         super(ST.DELETE_WORD_NEXT);
 
2376                  * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
 
2378                 protected void setCaretPosition(final int position) {
 
2379                         if (!validateEditorInputState())
 
2382                         final ISourceViewer viewer = getSourceViewer();
 
2383                         final int caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
 
2386                                 viewer.getDocument().replace(caret, position - caret, ""); //$NON-NLS-1$
 
2387                         } catch (BadLocationException exception) {
 
2388                                 // Should not happen
 
2393                  * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#findNextPosition(int)
 
2395                 protected int findNextPosition(int position) {
 
2396                         return fIterator.following(position);
 
2400                  * @see org.eclipse.ui.texteditor.IUpdate#update()
 
2402                 public void update() {
 
2403                         setEnabled(isEditorInputModifiable());
 
2408          * Text operation action to select the next sub-word.
 
2412         protected class SelectNextSubWordAction extends NextSubWordAction {
 
2415                  * Creates a new select next sub-word action.
 
2417                 public SelectNextSubWordAction() {
 
2418                         super(ST.SELECT_WORD_NEXT);
 
2422                  * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
 
2424                 protected void setCaretPosition(final int position) {
 
2425                         final ISourceViewer viewer = getSourceViewer();
 
2427                         final StyledText text = viewer.getTextWidget();
 
2428                         if (text != null && !text.isDisposed()) {
 
2430                                 final Point selection = text.getSelection();
 
2431                                 final int caret = text.getCaretOffset();
 
2432                                 final int offset = modelOffset2WidgetOffset(viewer, position);
 
2434                                 if (caret == selection.x)
 
2435                                         text.setSelectionRange(selection.y, offset - selection.y);
 
2437                                         text.setSelectionRange(selection.x, offset - selection.x);
 
2443          * Text navigation action to navigate to the previous sub-word.
 
2447         protected abstract class PreviousSubWordAction extends TextNavigationAction {
 
2449                 protected JavaWordIterator fIterator = new JavaWordIterator();
 
2452                  * Creates a new previous sub-word action.
 
2455                  *          Action code for the default operation. Must be an action code
 
2457                  * @see org.eclipse.swt.custom.ST.
 
2459                 protected PreviousSubWordAction(final int code) {
 
2460                         super(getSourceViewer().getTextWidget(), code);
 
2464                  * @see org.eclipse.jface.action.IAction#run()
 
2467                         // Check whether we are in a java code partition and the preference is
 
2469                         final IPreferenceStore store = getPreferenceStore();
 
2470                         if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
 
2475                         final ISourceViewer viewer = getSourceViewer();
 
2476                         final IDocument document = viewer.getDocument();
 
2477                         fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document));
 
2478                         int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
 
2482                         int previous = findPreviousPosition(position);
 
2483                         if (previous != BreakIterator.DONE) {
 
2484                                 setCaretPosition(previous);
 
2485                                 getTextWidget().showSelection();
 
2486                                 fireSelectionChanged();
 
2492                  * Finds the previous position before the given position.
 
2495                  *          the current position
 
2496                  * @return the previous position
 
2498                 protected int findPreviousPosition(int position) {
 
2499                         ISourceViewer viewer = getSourceViewer();
 
2501                         while (position != BreakIterator.DONE && widget == -1) { // TODO:
 
2503                                 position = fIterator.preceding(position);
 
2504                                 if (position != BreakIterator.DONE)
 
2505                                         widget = modelOffset2WidgetOffset(viewer, position);
 
2511                  * Sets the caret position to the sub-word boundary given with
 
2512                  * <code>position</code>.
 
2515                  *          Position where the action should move the caret
 
2517                 protected abstract void setCaretPosition(int position);
 
2521          * Text navigation action to navigate to the previous sub-word.
 
2525         protected class NavigatePreviousSubWordAction extends PreviousSubWordAction {
 
2528                  * Creates a new navigate previous sub-word action.
 
2530                 public NavigatePreviousSubWordAction() {
 
2531                         super(ST.WORD_PREVIOUS);
 
2535                  * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
 
2537                 protected void setCaretPosition(final int position) {
 
2538                         getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position));
 
2543          * Text operation action to delete the previous sub-word.
 
2547         protected class DeletePreviousSubWordAction extends PreviousSubWordAction implements IUpdate {
 
2550                  * Creates a new delete previous sub-word action.
 
2552                 public DeletePreviousSubWordAction() {
 
2553                         super(ST.DELETE_WORD_PREVIOUS);
 
2557                  * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
 
2559                 protected void setCaretPosition(final int position) {
 
2560                         if (!validateEditorInputState())
 
2563                         final ISourceViewer viewer = getSourceViewer();
 
2564                         final int caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
 
2567                                 viewer.getDocument().replace(position, caret - position, ""); //$NON-NLS-1$
 
2568                         } catch (BadLocationException exception) {
 
2569                                 // Should not happen
 
2574                  * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#findPreviousPosition(int)
 
2576                 protected int findPreviousPosition(int position) {
 
2577                         return fIterator.preceding(position);
 
2581                  * @see org.eclipse.ui.texteditor.IUpdate#update()
 
2583                 public void update() {
 
2584                         setEnabled(isEditorInputModifiable());
 
2589          * Text operation action to select the previous sub-word.
 
2593         protected class SelectPreviousSubWordAction extends PreviousSubWordAction {
 
2596                  * Creates a new select previous sub-word action.
 
2598                 public SelectPreviousSubWordAction() {
 
2599                         super(ST.SELECT_WORD_PREVIOUS);
 
2603                  * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
 
2605                 protected void setCaretPosition(final int position) {
 
2606                         final ISourceViewer viewer = getSourceViewer();
 
2608                         final StyledText text = viewer.getTextWidget();
 
2609                         if (text != null && !text.isDisposed()) {
 
2611                                 final Point selection = text.getSelection();
 
2612                                 final int caret = text.getCaretOffset();
 
2613                                 final int offset = modelOffset2WidgetOffset(viewer, position);
 
2615                                 if (caret == selection.x)
 
2616                                         text.setSelectionRange(selection.y, offset - selection.y);
 
2618                                         text.setSelectionRange(selection.x, offset - selection.x);
 
2623         // static protected class AnnotationAccess implements IAnnotationAccess {
 
2626         // org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
 
2628         // public Object getType(Annotation annotation) {
 
2629         // if (annotation instanceof IJavaAnnotation) {
 
2630         // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
 
2631         // // if (javaAnnotation.isRelevant())
 
2632         // // return javaAnnotation.getAnnotationType();
 
2639         // org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
 
2641         // public boolean isMultiLine(Annotation annotation) {
 
2647         // org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
 
2649         // public boolean isTemporary(Annotation annotation) {
 
2650         // if (annotation instanceof IJavaAnnotation) {
 
2651         // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
 
2652         // if (javaAnnotation.isRelevant())
 
2653         // return javaAnnotation.isTemporary();
 
2659         private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
 
2661                  * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
 
2663                 public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
 
2664                         handlePreferencePropertyChanged(event);
 
2669          * Finds and marks occurrence annotations.
 
2673         class OccurrencesFinderJob extends Job {
 
2675                 private IDocument fDocument;
 
2677                 private ISelection fSelection;
 
2679                 private ISelectionValidator fPostSelectionValidator;
 
2681                 private boolean fCanceled = false;
 
2683                 private IProgressMonitor fProgressMonitor;
 
2685                 private Position[] fPositions;
 
2687                 public OccurrencesFinderJob(IDocument document, Position[] positions, ISelection selection) {
 
2688                         super(PHPEditorMessages.JavaEditor_markOccurrences_job_name);
 
2689                         fDocument = document;
 
2690                         fSelection = selection;
 
2691                         fPositions = positions;
 
2693                         if (getSelectionProvider() instanceof ISelectionValidator)
 
2694                                 fPostSelectionValidator = (ISelectionValidator) getSelectionProvider();
 
2697                 // cannot use cancel() because it is declared final
 
2703                 private boolean isCanceled() {
 
2704                         return fCanceled || fProgressMonitor.isCanceled() || fPostSelectionValidator != null
 
2705                                         && !(fPostSelectionValidator.isValid(fSelection) || fForcedMarkOccurrencesSelection == fSelection)
 
2706                                         || LinkedModeModel.hasInstalledModel(fDocument);
 
2710                  * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
 
2712                 public IStatus run(IProgressMonitor progressMonitor) {
 
2714                         fProgressMonitor = progressMonitor;
 
2717                                 return Status.CANCEL_STATUS;
 
2719                         ITextViewer textViewer = getViewer();
 
2720                         if (textViewer == null)
 
2721                                 return Status.CANCEL_STATUS;
 
2723                         IDocument document = textViewer.getDocument();
 
2724                         if (document == null)
 
2725                                 return Status.CANCEL_STATUS;
 
2727                         IDocumentProvider documentProvider = getDocumentProvider();
 
2728                         if (documentProvider == null)
 
2729                                 return Status.CANCEL_STATUS;
 
2731                         IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
 
2732                         if (annotationModel == null)
 
2733                                 return Status.CANCEL_STATUS;
 
2735                         // Add occurrence annotations
 
2736                         int length = fPositions.length;
 
2737                         Map annotationMap = new HashMap(length);
 
2738                         for (int i = 0; i < length; i++) {
 
2741                                         return Status.CANCEL_STATUS;
 
2744                                 Position position = fPositions[i];
 
2746                                 // Create & add annotation
 
2748                                         message = document.get(position.offset, position.length);
 
2749                                 } catch (BadLocationException ex) {
 
2753                                 annotationMap.put(new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
 
2758                                 return Status.CANCEL_STATUS;
 
2760                         synchronized (getLockObject(annotationModel)) {
 
2761                                 if (annotationModel instanceof IAnnotationModelExtension) {
 
2762                                         ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
 
2764                                         removeOccurrenceAnnotations();
 
2765                                         Iterator iter = annotationMap.entrySet().iterator();
 
2766                                         while (iter.hasNext()) {
 
2767                                                 Map.Entry mapEntry = (Map.Entry) iter.next();
 
2768                                                 annotationModel.addAnnotation((Annotation) mapEntry.getKey(), (Position) mapEntry.getValue());
 
2771                                 fOccurrenceAnnotations = (Annotation[]) annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
 
2774                         return Status.OK_STATUS;
 
2779          * Cancels the occurrences finder job upon document changes.
 
2783         class OccurrencesFinderJobCanceler implements IDocumentListener, ITextInputListener {
 
2785                 public void install() {
 
2786                         ISourceViewer sourceViewer = getSourceViewer();
 
2787                         if (sourceViewer == null)
 
2790                         StyledText text = sourceViewer.getTextWidget();
 
2791                         if (text == null || text.isDisposed())
 
2794                         sourceViewer.addTextInputListener(this);
 
2796                         IDocument document = sourceViewer.getDocument();
 
2797                         if (document != null)
 
2798                                 document.addDocumentListener(this);
 
2801                 public void uninstall() {
 
2802                         ISourceViewer sourceViewer = getSourceViewer();
 
2803                         if (sourceViewer != null)
 
2804                                 sourceViewer.removeTextInputListener(this);
 
2806                         IDocumentProvider documentProvider = getDocumentProvider();
 
2807                         if (documentProvider != null) {
 
2808                                 IDocument document = documentProvider.getDocument(getEditorInput());
 
2809                                 if (document != null)
 
2810                                         document.removeDocumentListener(this);
 
2815                  * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
 
2817                 public void documentAboutToBeChanged(DocumentEvent event) {
 
2818                         if (fOccurrencesFinderJob != null)
 
2819                                 fOccurrencesFinderJob.doCancel();
 
2823                  * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
 
2825                 public void documentChanged(DocumentEvent event) {
 
2829                  * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
 
2830                  *      org.eclipse.jface.text.IDocument)
 
2832                 public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
 
2833                         if (oldInput == null)
 
2836                         oldInput.removeDocumentListener(this);
 
2840                  * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
 
2841                  *      org.eclipse.jface.text.IDocument)
 
2843                 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
 
2844                         if (newInput == null)
 
2846                         newInput.addDocumentListener(this);
 
2851          * Internal activation listener.
 
2855         private class ActivationListener implements IWindowListener {
 
2858                  * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
 
2861                 public void windowActivated(IWorkbenchWindow window) {
 
2862                         if (window == getEditorSite().getWorkbenchWindow() && fMarkOccurrenceAnnotations && isActivePart()) {
 
2863                                 fForcedMarkOccurrencesSelection = getSelectionProvider().getSelection();
 
2864                                 SelectionListenerWithASTManager.getDefault().forceSelectionChange(PHPEditor.this,
 
2865                                                 (ITextSelection) fForcedMarkOccurrencesSelection);
 
2870                  * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow)
 
2873                 public void windowDeactivated(IWorkbenchWindow window) {
 
2874                         if (window == getEditorSite().getWorkbenchWindow() && fMarkOccurrenceAnnotations && isActivePart())
 
2875                                 removeOccurrenceAnnotations();
 
2879                  * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow)
 
2882                 public void windowClosed(IWorkbenchWindow window) {
 
2886                  * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow)
 
2889                 public void windowOpened(IWorkbenchWindow window) {
 
2894          * Updates the selection in the editor's widget with the selection of the
 
2897         class OutlineSelectionChangedListener extends AbstractSelectionChangedListener {
 
2898                 public void selectionChanged(SelectionChangedEvent event) {
 
2899                         doSelectionChanged(event);
 
2904          * The internal shell activation listener for updating occurrences.
 
2908         private ActivationListener fActivationListener = new ActivationListener();
 
2910         private ISelectionListenerWithAST fPostSelectionListenerWithAST;
 
2912         private OccurrencesFinderJob fOccurrencesFinderJob;
 
2914         /** The occurrences finder job canceler */
 
2915         private OccurrencesFinderJobCanceler fOccurrencesFinderJobCanceler;
 
2918          * Holds the current occurrence annotations.
 
2922         private Annotation[] fOccurrenceAnnotations = null;
 
2925          * Tells whether all occurrences of the element at the current caret location
 
2926          * are automatically marked in this editor.
 
2930         private boolean fMarkOccurrenceAnnotations;
 
2933          * The selection used when forcing occurrence marking through code.
 
2937         private ISelection fForcedMarkOccurrencesSelection;
 
2940          * The document modification stamp at the time when the last occurrence
 
2941          * marking took place.
 
2945         private long fMarkOccurrenceModificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
 
2948          * The region of the word under the caret used to when computing the current
 
2949          * occurrence markings.
 
2953         private IRegion fMarkOccurrenceTargetRegion;
 
2956          * Tells whether the occurrence annotations are sticky i.e. whether they stay
 
2957          * even if there's no valid Java element at the current caret position. Only
 
2958          * valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>.
 
2962         private boolean fStickyOccurrenceAnnotations;
 
2964         /** Preference key for showing the line number ruler */
 
2965         // private final static String LINE_NUMBER_RULER =
 
2966         // PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
 
2967         /** Preference key for the foreground color of the line numbers */
 
2968         // private final static String LINE_NUMBER_COLOR =
 
2969         // PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
 
2970         /** Preference key for the link color */
 
2971         private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
 
2973         /** Preference key for compiler task tags */
 
2974         private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
 
2976         // protected PHPActionGroup fActionGroups;
 
2977         // /** The outline page */
 
2978         // private AbstractContentOutlinePage fOutlinePage;
 
2979         /** The outline page */
 
2980         protected JavaOutlinePage fOutlinePage;
 
2982         /** Outliner context menu Id */
 
2983         protected String fOutlinerContextMenuId;
 
2986          * Indicates whether this editor should react on outline page selection
 
2989         private int fIgnoreOutlinePageSelection;
 
2991         /** The outline page selection updater */
 
2992         // private OutlinePageSelectionUpdater fUpdater;
 
2993         // protected PHPSyntaxParserThread fValidationThread = null;
 
2994         // private IPreferenceStore fPHPPrefStore;
 
2995         /** The selection changed listener */
 
2996         // protected ISelectionChangedListener fSelectionChangedListener = new
 
2997         // SelectionChangedListener();
 
2999          * The editor selection changed listener.
 
3003         private EditorSelectionChangedListener fEditorSelectionChangedListener;
 
3005         /** The selection changed listener */
 
3006         protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener();
 
3008         /** The editor's bracket matcher */
 
3009         private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS);
 
3011         /** The line number ruler column */
 
3012         // private LineNumberRulerColumn fLineNumberRulerColumn;
 
3013         /** This editor's encoding support */
 
3014         private DefaultEncodingSupport fEncodingSupport;
 
3016         /** The mouse listener */
 
3017         private MouseClickListener fMouseListener;
 
3020          * Indicates whether this editor is about to update any annotation views.
 
3024         private boolean fIsUpdatingAnnotationViews = false;
 
3027          * The marker that served as last target for a goto marker request.
 
3031         private IMarker fLastMarkerTarget = null;
 
3033         protected CompositeActionGroup fActionGroups;
 
3035         protected CompositeActionGroup fContextMenuGroup;
 
3038          * This editor's projection support
 
3042         private ProjectionSupport fProjectionSupport;
 
3045          * This editor's projection model updater
 
3049         private IJavaFoldingStructureProvider fProjectionModelUpdater;
 
3052          * The override and implements indicator manager for this editor.
 
3056         // protected OverrideIndicatorManager fOverrideIndicatorManager;
 
3058          * The action group for folding.
 
3062         private FoldingActionGroup fFoldingGroup;
 
3064         /** The information presenter. */
 
3065         private InformationPresenter fInformationPresenter;
 
3067         /** The annotation access */
 
3068         // protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
 
3069         /** The overview ruler */
 
3070         protected OverviewRuler isOverviewRulerVisible;
 
3072         /** The source viewer decoration support */
 
3073         // protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
 
3074         /** The overview ruler */
 
3075         // protected OverviewRuler fOverviewRuler;
 
3076         /** The preference property change listener for java core. */
 
3077         private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
 
3080          * Returns the most narrow java element including the given offset
 
3083          *          the offset inside of the requested element
 
3085         abstract protected IJavaElement getElementAt(int offset);
 
3088          * Returns the java element of this editor's input corresponding to the given
 
3091         abstract protected IJavaElement getCorrespondingElement(IJavaElement element);
 
3094          * Sets the input of the editor's outline page.
 
3096         abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input);
 
3099          * Default constructor.
 
3101         public PHPEditor() {
 
3106          * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
 
3108         protected void initializeKeyBindingScopes() {
 
3109                 setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
 
3113          * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
 
3115         protected void initializeEditor() {
 
3117                 // JavaTextTools textTools =
 
3118                 // PHPeclipsePlugin.getDefault().getJavaTextTools();
 
3119                 // setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools,
 
3120                 // this, IPHPPartitions.PHP_PARTITIONING)); //,
 
3121                 // IJavaPartitions.JAVA_PARTITIONING));
 
3122                 IPreferenceStore store = createCombinedPreferenceStore(null);
 
3123                 setPreferenceStore(store);
 
3124                 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
 
3125                 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
 
3126                                 IPHPPartitions.PHP_PARTITIONING));
 
3128                 // TODO changed in 3.x ?
 
3129                 // setRangeIndicator(new DefaultRangeIndicator());
 
3131                 // (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
 
3132                 // fUpdater = new OutlinePageSelectionUpdater();
 
3135                 // IPreferenceStore store= createCombinedPreferenceStore(null);
 
3136                 // setPreferenceStore(store);
 
3137                 // JavaTextTools textTools=
 
3138                 // PHPeclipsePlugin.getDefault().getJavaTextTools();
 
3139                 // setSourceViewerConfiguration(new
 
3140                 // JavaSourceViewerConfiguration(textTools.getColorManager(), store,
 
3141                 // this, IJavaPartitions.JAVA_PARTITIONING));
 
3142                 fMarkOccurrenceAnnotations = store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
 
3143                 fStickyOccurrenceAnnotations = store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
 
3144                 // fMarkTypeOccurrences=
 
3145                 // store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
 
3146                 // fMarkMethodOccurrences=
 
3147                 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
 
3148                 // fMarkConstantOccurrences=
 
3149                 // store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
 
3150                 // fMarkFieldOccurrences=
 
3151                 // store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
 
3152                 // fMarkLocalVariableypeOccurrences=
 
3153                 // store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
 
3155                 // store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
 
3156                 // fMarkImplementors=
 
3157                 // store.getBoolean(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS);
 
3158                 // fMarkMethodExitPoints=
 
3159                 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
 
3164          * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
 
3166         protected void updatePropertyDependentActions() {
 
3167                 super.updatePropertyDependentActions();
 
3168                 if (fEncodingSupport != null)
 
3169                         fEncodingSupport.reset();
 
3173          * Update the hovering behavior depending on the preferences.
 
3175         private void updateHoverBehavior() {
 
3176                 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
 
3177                 String[] types = configuration.getConfiguredContentTypes(getSourceViewer());
 
3179                 for (int i = 0; i < types.length; i++) {
 
3181                         String t = types[i];
 
3183                         int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
 
3185                         ISourceViewer sourceViewer = getSourceViewer();
 
3186                         if (sourceViewer instanceof ITextViewerExtension2) {
 
3187                                 if (stateMasks != null) {
 
3188                                         for (int j = 0; j < stateMasks.length; j++) {
 
3189                                                 int stateMask = stateMasks[j];
 
3190                                                 ITextHover textHover = configuration.getTextHover(sourceViewer, t, stateMask);
 
3191                                                 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, stateMask);
 
3194                                         ITextHover textHover = configuration.getTextHover(sourceViewer, t);
 
3195                                         ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
 
3198                                 sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t);
 
3202         public void updatedTitleImage(Image image) {
 
3203                 setTitleImage(image);
 
3207          * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
 
3209         public Object getViewPartInput() {
 
3210                 return getEditorInput().getAdapter(IResource.class);
 
3214          * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
 
3216         protected void doSetSelection(ISelection selection) {
 
3217                 super.doSetSelection(selection);
 
3218                 synchronizeOutlinePageSelection();
 
3221         boolean isFoldingEnabled() {
 
3222                 return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
 
3226          * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.
 
3227          *      widgets.Composite)
 
3229         public void createPartControl(Composite parent) {
 
3230                 super.createPartControl(parent);
 
3232                 // fSourceViewerDecorationSupport.install(getPreferenceStore());
 
3234                 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
 
3236                 fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
 
3237                 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
 
3238                 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
 
3239                 fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() {
 
3240                         public IInformationControl createInformationControl(Shell shell) {
 
3241                                 return new CustomSourceInformationControl(shell, IDocument.DEFAULT_CONTENT_TYPE);
 
3244                 fProjectionSupport.install();
 
3246                 fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
 
3247                 if (fProjectionModelUpdater != null)
 
3248                         fProjectionModelUpdater.install(this, projectionViewer);
 
3250                 if (isFoldingEnabled())
 
3251                         projectionViewer.doOperation(ProjectionViewer.TOGGLE);
 
3252                 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
 
3253                 preferences.addPropertyChangeListener(fPropertyChangeListener);
 
3255                 IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
 
3256                         public IInformationControl createInformationControl(Shell parent) {
 
3257                                 boolean cutDown = false;
 
3258                                 int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
 
3259                                 return new DefaultInformationControl(parent, SWT.RESIZE, style, new HTMLTextPresenter(cutDown));
 
3263                 fInformationPresenter = new InformationPresenter(informationControlCreator);
 
3264                 fInformationPresenter.setSizeConstraints(60, 10, true, true);
 
3265                 fInformationPresenter.install(getSourceViewer());
 
3267                 fEditorSelectionChangedListener = new EditorSelectionChangedListener();
 
3268                 fEditorSelectionChangedListener.install(getSelectionProvider());
 
3270                 if (isBrowserLikeLinks())
 
3271                         enableBrowserLikeLinks();
 
3273                 if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE))
 
3274                         enableOverwriteMode(false);
 
3276                 if (fMarkOccurrenceAnnotations)
 
3277                         installOccurrencesFinder();
 
3279                 PlatformUI.getWorkbench().addWindowListener(fActivationListener);
 
3284         private void setWordWrap() {
 
3285                 if (getSourceViewer() != null) {
 
3286                         getSourceViewer().getTextWidget().setWordWrap(
 
3287                                         PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_WRAP_WORDS));
 
3291         protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
 
3293                 support.setCharacterPairMatcher(fBracketMatcher);
 
3294                 support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
 
3296                 super.configureSourceViewerDecorationSupport(support);
 
3300          * @see org.eclipse.ui.texteditor.AbstractTextEditor#gotoMarker(org.eclipse.core.resources.IMarker)
 
3302         public void gotoMarker(IMarker marker) {
 
3303                 fLastMarkerTarget = marker;
 
3304                 if (!fIsUpdatingAnnotationViews) {
 
3305                         super.gotoMarker(marker);
 
3310          * Jumps to the next enabled annotation according to the given direction. An
 
3311          * annotation type is enabled if it is configured to be in the Next/Previous
 
3312          * tool bar drop down menu and if it is checked.
 
3315          *          <code>true</code> if search direction is forward,
 
3316          *          <code>false</code> if backward
 
3318         public Annotation gotoAnnotation(boolean forward) {
 
3319                 ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
 
3320                 Position position = new Position(0, 0);
 
3321                 Annotation annotation=null;
 
3322                 if (false /* delayed - see bug 18316 */) {
 
3323                         annotation=getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
 
3324                         selectAndReveal(position.getOffset(), position.getLength());
 
3325                 } else /* no delay - see bug 18316 */{
 
3326                         annotation = getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
 
3327                         setStatusLineErrorMessage(null);
 
3328                         setStatusLineMessage(null);
 
3329                         if (annotation != null) {
 
3330                                 updateAnnotationViews(annotation);
 
3331                                 selectAndReveal(position.getOffset(), position.getLength());
 
3332                                 setStatusLineMessage(annotation.getText());
 
3339          * Returns the lock object for the given annotation model.
 
3341          * @param annotationModel
 
3342          *          the annotation model
 
3343          * @return the annotation model's lock object
 
3346         private Object getLockObject(IAnnotationModel annotationModel) {
 
3347                 if (annotationModel instanceof ISynchronizable)
 
3348                         return ((ISynchronizable) annotationModel).getLockObject();
 
3350                         return annotationModel;
 
3354          * Updates the annotation views that show the given annotation.
 
3359         private void updateAnnotationViews(Annotation annotation) {
 
3360                 IMarker marker = null;
 
3361                 if (annotation instanceof MarkerAnnotation)
 
3362                         marker = ((MarkerAnnotation) annotation).getMarker();
 
3363                 else if (annotation instanceof IJavaAnnotation) {
 
3364                         Iterator e = ((IJavaAnnotation) annotation).getOverlaidIterator();
 
3366                                 while (e.hasNext()) {
 
3367                                         Object o = e.next();
 
3368                                         if (o instanceof MarkerAnnotation) {
 
3369                                                 marker = ((MarkerAnnotation) o).getMarker();
 
3376                 if (marker != null && !marker.equals(fLastMarkerTarget)) {
 
3378                                 boolean isProblem = marker.isSubtypeOf(IMarker.PROBLEM);
 
3379                                 IWorkbenchPage page = getSite().getPage();
 
3380                                 IViewPart view = page.findView(isProblem ? IPageLayout.ID_PROBLEM_VIEW : IPageLayout.ID_TASK_LIST); //$NON-NLS-1$  //$NON-NLS-2$
 
3382                                         Method method = view.getClass().getMethod("setSelection", new Class[] { IStructuredSelection.class, boolean.class }); //$NON-NLS-1$
 
3383                                         method.invoke(view, new Object[] { new StructuredSelection(marker), Boolean.TRUE });
 
3385                         } catch (CoreException x) {
 
3386                         } catch (NoSuchMethodException x) {
 
3387                         } catch (IllegalAccessException x) {
 
3388                         } catch (InvocationTargetException x) {
 
3390                         // ignore exceptions, don't update any of the lists, just set status line
 
3395          * Returns this document's complete text.
 
3397          * @return the document's complete text
 
3399         public String get() {
 
3400                 IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
 
3405          * Sets the outliner's context menu ID.
 
3407         protected void setOutlinerContextMenuId(String menuId) {
 
3408                 fOutlinerContextMenuId = menuId;
 
3412          * Returns the standard action group of this editor.
 
3414         protected ActionGroup getActionGroup() {
 
3415                 return fActionGroups;
 
3418         // public JavaOutlinePage getfOutlinePage() {
 
3419         // return fOutlinePage;
 
3423          * The <code>PHPEditor</code> implementation of this
 
3424          * <code>AbstractTextEditor</code> method extend the actions to add those
 
3425          * specific to the receiver
 
3427         protected void createActions() {
 
3428                 super.createActions();
 
3430                 ActionGroup oeg, ovg, jsg, sg;
 
3431                 fActionGroups = new CompositeActionGroup(new ActionGroup[] { oeg = new OpenEditorActionGroup(this),
 
3432                 // sg= new ShowActionGroup(this),
 
3433                                 // ovg= new OpenViewActionGroup(this),
 
3434                                 // jsg= new JavaSearchActionGroup(this)
 
3436                 fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { oeg });
 
3437                 // , ovg, sg, jsg});
 
3439                 fFoldingGroup = new FoldingActionGroup(this, getViewer());
 
3441                 // ResourceAction resAction = new
 
3442                 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
 
3443                 // "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
 
3445                 // InformationDispatchAction(PHPEditorMessages.getResourceBundle(),
 
3446                 // "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
 
3447                 // resAction.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
 
3448                 // setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
 
3450                 // WorkbenchHelp.setHelp(resAction,
 
3451                 // IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
 
3453                 Action action = new GotoMatchingBracketAction(this);
 
3454                 action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
 
3455                 setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
 
3458                 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.",
 
3459                 // this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
 
3460                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
 
3461                 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action);
 
3462                 // // WorkbenchHelp.setHelp(action,
 
3463                 // IJavaHelpContextIds.SHOW_OUTLINE_ACTION);
 
3466                 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.",
 
3467                 // this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$
 
3468                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE);
 
3469                 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE,
 
3471                 // // WorkbenchHelp.setHelp(action,
 
3472                 // IJavaHelpContextIds.OPEN_STRUCTURE_ACTION);
 
3475                 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.",
 
3476                 // this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
 
3477                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY);
 
3478                 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY,
 
3480                 // // WorkbenchHelp.setHelp(action,
 
3481                 // IJavaHelpContextIds.OPEN_HIERARCHY_ACTION);
 
3483                 fEncodingSupport = new DefaultEncodingSupport();
 
3484                 fEncodingSupport.initialize(this);
 
3486                 // fSelectionHistory= new SelectionHistory(this);
 
3488                 // action= new StructureSelectEnclosingAction(this, fSelectionHistory);
 
3489                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
 
3490                 // setAction(StructureSelectionAction.ENCLOSING, action);
 
3492                 // action= new StructureSelectNextAction(this, fSelectionHistory);
 
3493                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
 
3494                 // setAction(StructureSelectionAction.NEXT, action);
 
3496                 // action= new StructureSelectPreviousAction(this, fSelectionHistory);
 
3497                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
 
3498                 // setAction(StructureSelectionAction.PREVIOUS, action);
 
3500                 // StructureSelectHistoryAction historyAction= new
 
3501                 // StructureSelectHistoryAction(this, fSelectionHistory);
 
3502                 // historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
 
3503                 // setAction(StructureSelectionAction.HISTORY, historyAction);
 
3504                 // fSelectionHistory.setHistoryAction(historyAction);
 
3506                 // action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this);
 
3507                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
 
3508                 // setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action);
 
3511                 // GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this);
 
3512                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
 
3513                 // setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
 
3515                 // action= new QuickFormatAction();
 
3516                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT);
 
3517                 // setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action);
 
3519                 // action= new RemoveOccurrenceAnnotations(this);
 
3520                 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
 
3521                 // setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$
 
3523                 // add annotation actions
 
3524                 action = new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
 
3525                 setAction("AnnotationAction", action); //$NON-NLS-1$
 
3528         private void internalDoSetInput(IEditorInput input) throws CoreException {
 
3529                 super.doSetInput(input);
 
3531                 if (getSourceViewer() instanceof JavaSourceViewer) {
 
3532                         JavaSourceViewer viewer = (JavaSourceViewer) getSourceViewer();
 
3533                         if (viewer.getReconciler() == null) {
 
3534                                 IReconciler reconciler = getSourceViewerConfiguration().getReconciler(viewer);
 
3535                                 if (reconciler != null) {
 
3536                                         reconciler.install(viewer);
 
3537                                         viewer.setReconciler(reconciler);
 
3542                 if (fEncodingSupport != null)
 
3543                         fEncodingSupport.reset();
 
3545                 setOutlinePageInput(fOutlinePage, input);
 
3547                 if (fProjectionModelUpdater != null)
 
3548                         fProjectionModelUpdater.initialize();
 
3550                 // if (isShowingOverrideIndicators())
 
3551                 // installOverrideIndicator(false);
 
3555          * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)
 
3558         protected void setPreferenceStore(IPreferenceStore store) {
 
3559                 super.setPreferenceStore(store);
 
3560                 if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) {
 
3561                         JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
 
3562                         setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
 
3563                                         IPHPPartitions.PHP_PARTITIONING));
 
3565                 if (getSourceViewer() instanceof JavaSourceViewer)
 
3566                         ((JavaSourceViewer) getSourceViewer()).setPreferenceStore(store);
 
3570          * The <code>PHPEditor</code> implementation of this
 
3571          * <code>AbstractTextEditor</code> method performs any extra disposal
 
3572          * actions required by the php editor.
 
3574         public void dispose() {
 
3575                 if (fProjectionModelUpdater != null) {
 
3576                         fProjectionModelUpdater.uninstall();
 
3577                         fProjectionModelUpdater = null;
 
3580                 if (fProjectionSupport != null) {
 
3581                         fProjectionSupport.dispose();
 
3582                         fProjectionSupport = null;
 
3584                 // PHPEditorEnvironment.disconnect(this);
 
3585                 if (fOutlinePage != null)
 
3586                         fOutlinePage.setInput(null);
 
3588                 if (fActionGroups != null)
 
3589                         fActionGroups.dispose();
 
3591                 if (isBrowserLikeLinks())
 
3592                         disableBrowserLikeLinks();
 
3594                 // cancel possible running computation
 
3595                 fMarkOccurrenceAnnotations = false;
 
3596                 uninstallOccurrencesFinder();
 
3598                 uninstallOverrideIndicator();
 
3600                 if (fActivationListener != null) {
 
3601                         PlatformUI.getWorkbench().removeWindowListener(fActivationListener);
 
3602                         fActivationListener = null;
 
3605                 if (fEncodingSupport != null) {
 
3606                         fEncodingSupport.dispose();
 
3607                         fEncodingSupport = null;
 
3610                 if (fPropertyChangeListener != null) {
 
3611                         Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
 
3612                         preferences.removePropertyChangeListener(fPropertyChangeListener);
 
3613                         fPropertyChangeListener = null;
 
3616                 // if (fSourceViewerDecorationSupport != null) {
 
3617                 // fSourceViewerDecorationSupport.dispose();
 
3618                 // fSourceViewerDecorationSupport = null;
 
3621                 if (fBracketMatcher != null) {
 
3622                         fBracketMatcher.dispose();
 
3623                         fBracketMatcher = null;
 
3626                 if (fEditorSelectionChangedListener != null) {
 
3627                         fEditorSelectionChangedListener.uninstall(getSelectionProvider());
 
3628                         fEditorSelectionChangedListener = null;
 
3635          * The <code>PHPEditor</code> implementation of this
 
3636          * <code>AbstractTextEditor</code> method performs any extra revert behavior
 
3637          * required by the php editor.
 
3639         // public void doRevertToSaved() {
 
3640         // super.doRevertToSaved();
 
3641         // if (fOutlinePage != null)
 
3642         // fOutlinePage.update();
 
3645          * The <code>PHPEditor</code> implementation of this
 
3646          * <code>AbstractTextEditor</code> method performs any extra save behavior
 
3647          * required by the php editor.
 
3649         // public void doSave(IProgressMonitor monitor) {
 
3650         // super.doSave(monitor);
 
3651         // compile or not, according to the user preferences
 
3652         // IPreferenceStore store = getPreferenceStore();
 
3653         // the parse on save was changed to the eclipse "builders" concept
 
3654         // if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
 
3655         // IAction a = PHPParserAction.getInstance();
 
3659         // if (SWT.getPlatform().equals("win32")) {
 
3660         // IAction a = ShowExternalPreviewAction.getInstance();
 
3664         // if (fOutlinePage != null)
 
3665         // fOutlinePage.update();
 
3668          * The <code>PHPEditor</code> implementation of this
 
3669          * <code>AbstractTextEditor</code> method performs any extra save as
 
3670          * behavior required by the php editor.
 
3672         // public void doSaveAs() {
 
3673         // super.doSaveAs();
 
3674         // if (fOutlinePage != null)
 
3675         // fOutlinePage.update();
 
3678          * @see StatusTextEditor#getStatusHeader(IStatus)
 
3680         protected String getStatusHeader(IStatus status) {
 
3681                 if (fEncodingSupport != null) {
 
3682                         String message = fEncodingSupport.getStatusHeader(status);
 
3683                         if (message != null)
 
3686                 return super.getStatusHeader(status);
 
3690          * @see StatusTextEditor#getStatusBanner(IStatus)
 
3692         protected String getStatusBanner(IStatus status) {
 
3693                 if (fEncodingSupport != null) {
 
3694                         String message = fEncodingSupport.getStatusBanner(status);
 
3695                         if (message != null)
 
3698                 return super.getStatusBanner(status);
 
3702          * @see StatusTextEditor#getStatusMessage(IStatus)
 
3704         protected String getStatusMessage(IStatus status) {
 
3705                 if (fEncodingSupport != null) {
 
3706                         String message = fEncodingSupport.getStatusMessage(status);
 
3707                         if (message != null)
 
3710                 return super.getStatusMessage(status);
 
3714          * The <code>PHPEditor</code> implementation of this
 
3715          * <code>AbstractTextEditor</code> method performs sets the input of the
 
3716          * outline page after AbstractTextEditor has set input.
 
3718         // protected void doSetInput(IEditorInput input) throws CoreException {
 
3719         // super.doSetInput(input);
 
3720         // if (fEncodingSupport != null)
 
3721         // fEncodingSupport.reset();
 
3722         // setOutlinePageInput(fOutlinePage, input);
 
3725          * @see AbstractTextEditor#doSetInput
 
3727         protected void doSetInput(IEditorInput input) throws CoreException {
 
3728                 ISourceViewer sourceViewer = getSourceViewer();
 
3729                 if (!(sourceViewer instanceof ISourceViewerExtension2)) {
 
3730                         setPreferenceStore(createCombinedPreferenceStore(input));
 
3731                         internalDoSetInput(input);
 
3735                 // uninstall & unregister preference store listener
 
3736                 if (isBrowserLikeLinks())
 
3737                         disableBrowserLikeLinks();
 
3738                 getSourceViewerDecorationSupport(sourceViewer).uninstall();
 
3739                 ((ISourceViewerExtension2) sourceViewer).unconfigure();
 
3741                 setPreferenceStore(createCombinedPreferenceStore(input));
 
3743                 // install & register preference store listener
 
3744                 sourceViewer.configure(getSourceViewerConfiguration());
 
3745                 getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
 
3746                 if (isBrowserLikeLinks())
 
3747                         enableBrowserLikeLinks();
 
3749                 internalDoSetInput(input);
 
3753          * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
 
3755         // public Object getViewPartInput() {
 
3756         // return getEditorInput().getAdapter(IFile.class);
 
3759          * The <code>PHPEditor</code> implementation of this
 
3760          * <code>AbstractTextEditor</code> method adds any PHPEditor specific
 
3763         public void editorContextMenuAboutToShow(MenuManager menu) {
 
3764                 super.editorContextMenuAboutToShow(menu);
 
3765                 menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, new Separator(IContextMenuConstants.GROUP_OPEN));
 
3766                 menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));
 
3768                 ActionContext context = new ActionContext(getSelectionProvider().getSelection());
 
3769                 fContextMenuGroup.setContext(context);
 
3770                 fContextMenuGroup.fillContextMenu(menu);
 
3771                 fContextMenuGroup.setContext(null);
 
3772                 // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format");
 
3775                 // ActionContext context =
 
3776                 // new ActionContext(getSelectionProvider().getSelection());
 
3777                 // fContextMenuGroup.setContext(context);
 
3778                 // fContextMenuGroup.fillContextMenu(menu);
 
3779                 // fContextMenuGroup.setContext(null);
 
3783          * Creates the outline page used with this editor.
 
3785         protected JavaOutlinePage createOutlinePage() {
 
3786                 JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this);
 
3787                 fOutlineSelectionChangedListener.install(page);
 
3788                 setOutlinePageInput(page, getEditorInput());
 
3793          * Informs the editor that its outliner has been closed.
 
3795         public void outlinePageClosed() {
 
3796                 if (fOutlinePage != null) {
 
3797                         fOutlineSelectionChangedListener.uninstall(fOutlinePage);
 
3798                         fOutlinePage = null;
 
3799                         resetHighlightRange();
 
3804          * Synchronizes the outliner selection with the given element position in the
 
3808          *          the java element to select
 
3810         protected void synchronizeOutlinePage(ISourceReference element) {
 
3811                 synchronizeOutlinePage(element, true);
 
3815          * Synchronizes the outliner selection with the given element position in the
 
3819          *          the java element to select
 
3820          * @param checkIfOutlinePageActive
 
3821          *          <code>true</code> if check for active outline page needs to be
 
3824         protected void synchronizeOutlinePage(ISourceReference element, boolean checkIfOutlinePageActive) {
 
3825                 if (fOutlinePage != null && element != null && !(checkIfOutlinePageActive && isJavaOutlinePageActive())) {
 
3826                         fOutlineSelectionChangedListener.uninstall(fOutlinePage);
 
3827                         fOutlinePage.select(element);
 
3828                         fOutlineSelectionChangedListener.install(fOutlinePage);
 
3833          * Synchronizes the outliner selection with the actual cursor position in the
 
3836         public void synchronizeOutlinePageSelection() {
 
3837                 synchronizeOutlinePage(computeHighlightRangeSourceReference());
 
3839                 // ISourceViewer sourceViewer = getSourceViewer();
 
3840                 // if (sourceViewer == null || fOutlinePage == null)
 
3843                 // StyledText styledText = sourceViewer.getTextWidget();
 
3844                 // if (styledText == null)
 
3848                 // if (sourceViewer instanceof ITextViewerExtension3) {
 
3849                 // ITextViewerExtension3 extension = (ITextViewerExtension3)
 
3852                 // extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
 
3854                 // int offset = sourceViewer.getVisibleRegion().getOffset();
 
3855                 // caret = offset + styledText.getCaretOffset();
 
3858                 // IJavaElement element = getElementAt(caret);
 
3859                 // if (element instanceof ISourceReference) {
 
3860                 // fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
 
3861                 // fOutlinePage.select((ISourceReference) element);
 
3862                 // fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
 
3866         protected void setSelection(ISourceReference reference, boolean moveCursor) {
 
3868                 ISelection selection = getSelectionProvider().getSelection();
 
3869                 if (selection instanceof TextSelection) {
 
3870                         TextSelection textSelection = (TextSelection) selection;
 
3871                         if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
 
3872                                 markInNavigationHistory();
 
3875                 if (reference != null) {
 
3877                         StyledText textWidget = null;
 
3879                         ISourceViewer sourceViewer = getSourceViewer();
 
3880                         if (sourceViewer != null)
 
3881                                 textWidget = sourceViewer.getTextWidget();
 
3883                         if (textWidget == null)
 
3888                                 ISourceRange range = reference.getSourceRange();
 
3892                                 int offset = range.getOffset();
 
3893                                 int length = range.getLength();
 
3895                                 if (offset < 0 || length < 0)
 
3898                                 textWidget.setRedraw(false);
 
3900                                 setHighlightRange(offset, length, moveCursor);
 
3908                                 if (reference instanceof IMember) {
 
3909                                         range = ((IMember) reference).getNameRange();
 
3910                                         if (range != null) {
 
3911                                                 offset = range.getOffset();
 
3912                                                 length = range.getLength();
 
3915                                 // else if (reference instanceof IImportDeclaration) {
 
3916                                 // String name= ((IImportDeclaration)
 
3917                                 // reference).getElementName();
 
3918                                 // if (name != null && name.length() > 0) {
 
3919                                 // String content= reference.getSource();
 
3920                                 // if (content != null) {
 
3921                                 // offset= range.getOffset() + content.indexOf(name);
 
3922                                 // length= name.length();
 
3925                                 // } else if (reference instanceof IPackageDeclaration) {
 
3926                                 // String name= ((IPackageDeclaration)
 
3927                                 // reference).getElementName();
 
3928                                 // if (name != null && name.length() > 0) {
 
3929                                 // String content= reference.getSource();
 
3930                                 // if (content != null) {
 
3931                                 // offset= range.getOffset() + content.indexOf(name);
 
3932                                 // length= name.length();
 
3937                                 if (offset > -1 && length > 0) {
 
3938                                         sourceViewer.revealRange(offset, length);
 
3939                                         sourceViewer.setSelectedRange(offset, length);
 
3942                         } catch (JavaModelException x) {
 
3943                         } catch (IllegalArgumentException x) {
 
3945                                 if (textWidget != null)
 
3946                                         textWidget.setRedraw(true);
 
3949                 } else if (moveCursor) {
 
3950                         resetHighlightRange();
 
3953                 markInNavigationHistory();
 
3956         public void setSelection(IJavaElement element) {
 
3957                 if (element == null || element instanceof ICompilationUnit) { // ||
 
3963                          * If the element is an ICompilationUnit this unit is either the input of
 
3964                          * this editor or not being displayed. In both cases, nothing should
 
3965                          * happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
 
3970                 IJavaElement corresponding = getCorrespondingElement(element);
 
3971                 if (corresponding instanceof ISourceReference) {
 
3972                         ISourceReference reference = (ISourceReference) corresponding;
 
3973                         // set highlight range
 
3974                         setSelection(reference, true);
 
3975                         // set outliner selection
 
3976                         if (fOutlinePage != null) {
 
3977                                 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
 
3978                                 fOutlinePage.select(reference);
 
3979                                 fOutlineSelectionChangedListener.install(fOutlinePage);
 
3984         public synchronized void editingScriptStarted() {
 
3985                 ++fIgnoreOutlinePageSelection;
 
3988         public synchronized void editingScriptEnded() {
 
3989                 --fIgnoreOutlinePageSelection;
 
3992         public synchronized boolean isEditingScriptRunning() {
 
3993                 return (fIgnoreOutlinePageSelection > 0);
 
3997          * The <code>PHPEditor</code> implementation of this
 
3998          * <code>AbstractTextEditor</code> method performs gets the java content
 
3999          * outline page if request is for a an outline page.
 
4001         public Object getAdapter(Class required) {
 
4003                 if (IContentOutlinePage.class.equals(required)) {
 
4004                         if (fOutlinePage == null)
 
4005                                 fOutlinePage = createOutlinePage();
 
4006                         return fOutlinePage;
 
4009                 if (IEncodingSupport.class.equals(required))
 
4010                         return fEncodingSupport;
 
4012                 if (required == IShowInTargetList.class) {
 
4013                         return new IShowInTargetList() {
 
4014                                 public String[] getShowInTargetIds() {
 
4015                                         return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
 
4020                 if (fProjectionSupport != null) {
 
4021                         Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
 
4022                         if (adapter != null)
 
4026                 return super.getAdapter(required);
 
4029         // public Object getAdapter(Class required) {
 
4030         // if (IContentOutlinePage.class.equals(required)) {
 
4031         // if (fOutlinePage == null) {
 
4032         // fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
 
4033         // if (getEditorInput() != null)
 
4034         // fOutlinePage.setInput(getEditorInput());
 
4036         // return fOutlinePage;
 
4039         // if (IEncodingSupport.class.equals(required))
 
4040         // return fEncodingSupport;
 
4042         // return super.getAdapter(required);
 
4045         protected void doSelectionChanged(SelectionChangedEvent event) {
 
4046                 ISourceReference reference = null;
 
4048                 ISelection selection = event.getSelection();
 
4049                 Iterator iter = ((IStructuredSelection) selection).iterator();
 
4050                 while (iter.hasNext()) {
 
4051                         Object o = iter.next();
 
4052                         if (o instanceof ISourceReference) {
 
4053                                 reference = (ISourceReference) o;
 
4058                 if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
 
4059                         PHPeclipsePlugin.getActivePage().bringToTop(this);
 
4062                         editingScriptStarted();
 
4063                         setSelection(reference, !isActivePart());
 
4065                         editingScriptEnded();
 
4070          * @see AbstractTextEditor#adjustHighlightRange(int, int)
 
4072         protected void adjustHighlightRange(int offset, int length) {
 
4076                         IJavaElement element = getElementAt(offset);
 
4077                         while (element instanceof ISourceReference) {
 
4078                                 ISourceRange range = ((ISourceReference) element).getSourceRange();
 
4079                                 if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) {
 
4081                                         ISourceViewer viewer = getSourceViewer();
 
4082                                         if (viewer instanceof ITextViewerExtension5) {
 
4083                                                 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
 
4084                                                 extension.exposeModelRange(new Region(range.getOffset(), range.getLength()));
 
4087                                         setHighlightRange(range.getOffset(), range.getLength(), true);
 
4088                                         if (fOutlinePage != null) {
 
4089                                                 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
 
4090                                                 fOutlinePage.select((ISourceReference) element);
 
4091                                                 fOutlineSelectionChangedListener.install(fOutlinePage);
 
4096                                 element = element.getParent();
 
4099                 } catch (JavaModelException x) {
 
4100                         PHPeclipsePlugin.log(x.getStatus());
 
4103                 ISourceViewer viewer = getSourceViewer();
 
4104                 if (viewer instanceof ITextViewerExtension5) {
 
4105                         ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
 
4106                         extension.exposeModelRange(new Region(offset, length));
 
4108                         resetHighlightRange();
 
4113         protected boolean isActivePart() {
 
4114                 IWorkbenchWindow window = getSite().getWorkbenchWindow();
 
4115                 IPartService service = window.getPartService();
 
4116                 IWorkbenchPart part = service.getActivePart();
 
4117                 return part != null && part.equals(this);
 
4120         // public void openContextHelp() {
 
4122         // this.getDocumentProvider().getDocument(this.getEditorInput());
 
4123         // ITextSelection selection = (ITextSelection)
 
4124         // this.getSelectionProvider().getSelection();
 
4125         // int pos = selection.getOffset();
 
4126         // String word = getFunctionName(doc, pos);
 
4127         // openContextHelp(word);
 
4130         // private void openContextHelp(String word) {
 
4134         // public static void open(String word) {
 
4135         // IHelp help = WorkbenchHelp.getHelpSupport();
 
4136         // if (help != null) {
 
4137         // IHelpResource helpResource = new PHPFunctionHelpResource(word);
 
4138         // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
 
4140         // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help
 
4141         // not available"), false); //$NON-NLS-1$
 
4145         // private String getFunctionName(IDocument doc, int pos) {
 
4146         // Point word = PHPWordExtractor.findWord(doc, pos);
 
4147         // if (word != null) {
 
4149         // return doc.get(word.x, word.y).replace('_', '-');
 
4150         // } catch (BadLocationException e) {
 
4157          * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
 
4159         protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
 
4163                         ISourceViewer sourceViewer = getSourceViewer();
 
4164                         if (sourceViewer == null)
 
4167                         String property = event.getProperty();
 
4169                         if (PreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
 
4170                                 Object value = event.getNewValue();
 
4171                                 if (value instanceof Integer) {
 
4172                                         sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
 
4173                                 } else if (value instanceof String) {
 
4175                                                 sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
 
4176                                         } catch (NumberFormatException e) {
 
4177                                                 // bug #1038071 - set default tab:
 
4178                                                 sourceViewer.getTextWidget().setTabs(80);
 
4184                         // if (OVERVIEW_RULER.equals(property)) {
 
4185                         // if (isOverviewRulerVisible())
 
4186                         // showOverviewRuler();
 
4188                         // hideOverviewRuler();
 
4192                         // if (LINE_NUMBER_RULER.equals(property)) {
 
4193                         // if (isLineNumberRulerVisible())
 
4194                         // showLineNumberRuler();
 
4196                         // hideLineNumberRuler();
 
4200                         // if (fLineNumberRulerColumn != null
 
4201                         // && (LINE_NUMBER_COLOR.equals(property) ||
 
4202                         // PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) ||
 
4203                         // PREFERENCE_COLOR_BACKGROUND.equals(property))) {
 
4205                         // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
 
4208                         if (isJavaEditorHoverProperty(property))
 
4209                                 updateHoverBehavior();
 
4211                         if (BROWSER_LIKE_LINKS.equals(property)) {
 
4212                                 if (isBrowserLikeLinks())
 
4213                                         enableBrowserLikeLinks();
 
4215                                         disableBrowserLikeLinks();
 
4219                         if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) {
 
4220                                 if (event.getNewValue() instanceof Boolean) {
 
4221                                         Boolean disable = (Boolean) event.getNewValue();
 
4222                                         enableOverwriteMode(!disable.booleanValue());
 
4227                         boolean newBooleanValue = false;
 
4228                         Object newValue = event.getNewValue();
 
4229                         if (newValue != null)
 
4230                                 newBooleanValue = Boolean.valueOf(newValue.toString()).booleanValue();
 
4232                         if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) {
 
4233                                 if (newBooleanValue)
 
4238                         if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) {
 
4239                                 if (newBooleanValue != fMarkOccurrenceAnnotations) {
 
4240                                         fMarkOccurrenceAnnotations = newBooleanValue;
 
4241                                         if (!fMarkOccurrenceAnnotations)
 
4242                                                 uninstallOccurrencesFinder();
 
4244                                                 installOccurrencesFinder();
 
4249                         if (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) {
 
4250                                 fStickyOccurrenceAnnotations = newBooleanValue;
 
4256                         // (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property))
 
4258                         // if (event.getNewValue() instanceof Boolean) {
 
4259                         // boolean stickyOccurrenceAnnotations=
 
4260                         // ((Boolean)event.getNewValue()).booleanValue();
 
4261                         // if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations)
 
4264                         ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
 
4266                         // if (affectsOverrideIndicatorAnnotations(event)) {
 
4267                         // if (isShowingOverrideIndicators()) {
 
4268                         // if (fOverrideIndicatorManager == null)
 
4269                         // installOverrideIndicator(true);
 
4271                         // if (fOverrideIndicatorManager != null)
 
4272                         // uninstallOverrideIndicator();
 
4277                         if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
 
4278                                 if (sourceViewer instanceof ProjectionViewer) {
 
4279                                         ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer;
 
4280                                         if (fProjectionModelUpdater != null)
 
4281                                                 fProjectionModelUpdater.uninstall();
 
4282                                         // either freshly enabled or provider changed
 
4283                                         fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
 
4284                                         if (fProjectionModelUpdater != null) {
 
4285                                                 fProjectionModelUpdater.install(this, projectionViewer);
 
4291                         super.handlePreferenceStoreChanged(event);
 
4297         // AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
 
4299         // protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
 
4303         // ISourceViewer sourceViewer = getSourceViewer();
 
4304         // if (sourceViewer == null)
 
4307         // String property = event.getProperty();
 
4310         // (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
 
4311         // // Object value= event.getNewValue();
 
4312         // // if (value instanceof Integer) {
 
4313         // // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
 
4314         // // } else if (value instanceof String) {
 
4315         // // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String)
 
4321         // if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
 
4322         // if (isLineNumberRulerVisible())
 
4323         // showLineNumberRuler();
 
4325         // hideLineNumberRuler();
 
4329         // if (fLineNumberRulerColumn != null
 
4330         // && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
 
4331         // || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
 
4332         // || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
 
4334         // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
 
4338         // super.handlePreferenceStoreChanged(event);
 
4342         // private boolean isJavaEditorHoverProperty(String property) {
 
4343         // return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
 
4344         // || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
 
4345         // || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
 
4346         // || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
 
4347         // || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
 
4348         // || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
 
4349         // || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
 
4350         // || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
 
4354          * Shows the line number ruler column.
 
4356         // private void showLineNumberRuler() {
 
4357         // IVerticalRuler v = getVerticalRuler();
 
4358         // if (v instanceof CompositeRuler) {
 
4359         // CompositeRuler c = (CompositeRuler) v;
 
4360         // c.addDecorator(1, createLineNumberRulerColumn());
 
4363         private boolean isJavaEditorHoverProperty(String property) {
 
4364                 return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property);
 
4368          * Return whether the browser like links should be enabled according to the
 
4369          * preference store settings.
 
4371          * @return <code>true</code> if the browser like links should be enabled
 
4373         private boolean isBrowserLikeLinks() {
 
4374                 IPreferenceStore store = getPreferenceStore();
 
4375                 return store.getBoolean(BROWSER_LIKE_LINKS);
 
4379          * Enables browser like links.
 
4381         private void enableBrowserLikeLinks() {
 
4382                 if (fMouseListener == null) {
 
4383                         fMouseListener = new MouseClickListener();
 
4384                         fMouseListener.install();
 
4389          * Disables browser like links.
 
4391         private void disableBrowserLikeLinks() {
 
4392                 if (fMouseListener != null) {
 
4393                         fMouseListener.uninstall();
 
4394                         fMouseListener = null;
 
4399          * Handles a property change event describing a change of the java core's
 
4400          * preferences and updates the preference related editor properties.
 
4403          *          the property change event
 
4405         protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
 
4406                 if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
 
4407                         ISourceViewer sourceViewer = getSourceViewer();
 
4408                         if (sourceViewer != null
 
4409                                         && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event
 
4411                                 sourceViewer.invalidateTextPresentation();
 
4413                 if (PreferenceConstants.EDITOR_WRAP_WORDS.equals(event.getProperty())) {
 
4419          * Return whether the line number ruler column should be visible according to
 
4420          * the preference store settings.
 
4422          * @return <code>true</code> if the line numbers should be visible
 
4424         // protected boolean isLineNumberRulerVisible() {
 
4425         // IPreferenceStore store = getPreferenceStore();
 
4426         // return store.getBoolean(LINE_NUMBER_RULER);
 
4429          * Hides the line number ruler column.
 
4431         // private void hideLineNumberRuler() {
 
4432         // IVerticalRuler v = getVerticalRuler();
 
4433         // if (v instanceof CompositeRuler) {
 
4434         // CompositeRuler c = (CompositeRuler) v;
 
4436         // c.removeDecorator(1);
 
4437         // } catch (Throwable e) {
 
4442          * @see AbstractTextEditor#handleCursorPositionChanged()
 
4444         // protected void handleCursorPositionChanged() {
 
4445         // super.handleCursorPositionChanged();
 
4446         // if (!isEditingScriptRunning() && fUpdater != null)
 
4450          * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced()
 
4452         protected void handleElementContentReplaced() {
 
4453                 super.handleElementContentReplaced();
 
4454                 if (fProjectionModelUpdater != null)
 
4455                         fProjectionModelUpdater.initialize();
 
4459          * Initializes the given line number ruler column from the preference store.
 
4461          * @param rulerColumn
 
4462          *          the ruler column to be initialized
 
4464         // protected void initializeLineNumberRulerColumn(LineNumberRulerColumn
 
4466         // JavaTextTools textTools =
 
4467         // PHPeclipsePlugin.getDefault().getJavaTextTools();
 
4468         // IColorManager manager = textTools.getColorManager();
 
4470         // IPreferenceStore store = getPreferenceStore();
 
4471         // if (store != null) {
 
4474         // // foreground color
 
4475         // if (store.contains(LINE_NUMBER_COLOR)) {
 
4476         // if (store.isDefault(LINE_NUMBER_COLOR))
 
4477         // rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
 
4479         // rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
 
4481         // rulerColumn.setForeground(manager.getColor(rgb));
 
4484         // // background color
 
4485         // if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
 
4486         // if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
 
4487         // if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
 
4488         // rgb = PreferenceConverter.getDefaultColor(store,
 
4489         // PREFERENCE_COLOR_BACKGROUND);
 
4491         // rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
 
4494         // rulerColumn.setBackground(manager.getColor(rgb));
 
4498          * Creates a new line number ruler column that is appropriately initialized.
 
4500         // protected IVerticalRulerColumn createLineNumberRulerColumn() {
 
4501         // fLineNumberRulerColumn = new LineNumberRulerColumn();
 
4502         // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
 
4503         // return fLineNumberRulerColumn;
 
4506          * @see AbstractTextEditor#createVerticalRuler()
 
4508         // protected IVerticalRuler createVerticalRuler() {
 
4509         // CompositeRuler ruler = new CompositeRuler();
 
4510         // ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
 
4511         // if (isLineNumberRulerVisible())
 
4512         // ruler.addDecorator(1, createLineNumberRulerColumn());
 
4515         // private static IRegion getSignedSelection(ITextViewer viewer) {
 
4517         // StyledText text = viewer.getTextWidget();
 
4518         // int caretOffset = text.getCaretOffset();
 
4519         // Point selection = text.getSelection();
 
4522         // int offset, length;
 
4523         // if (caretOffset == selection.x) {
 
4524         // offset = selection.y;
 
4525         // length = selection.x - selection.y;
 
4529         // offset = selection.x;
 
4530         // length = selection.y - selection.x;
 
4533         // return new Region(offset, length);
 
4535         protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
 
4536                 StyledText text = sourceViewer.getTextWidget();
 
4537                 Point selection = text.getSelectionRange();
 
4539                 if (text.getCaretOffset() == selection.x) {
 
4540                         selection.x = selection.x + selection.y;
 
4541                         selection.y = -selection.y;
 
4544                 selection.x = widgetOffset2ModelOffset(sourceViewer, selection.x);
 
4546                 return new Region(selection.x, selection.y);
 
4549         /** Preference key for matching brackets */
 
4550         protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
 
4552         /** Preference key for matching brackets color */
 
4553         protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
 
4555         /** Preference key for highlighting current line */
 
4556         // protected final static String CURRENT_LINE =
 
4557         // PreferenceConstants.EDITOR_CURRENT_LINE;
 
4558         /** Preference key for highlight color of current line */
 
4559         // protected final static String CURRENT_LINE_COLOR =
 
4560         // PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
 
4561         /** Preference key for showing print marging ruler */
 
4562         // protected final static String PRINT_MARGIN =
 
4563         // PreferenceConstants.EDITOR_PRINT_MARGIN;
 
4564         /** Preference key for print margin ruler color */
 
4565         // protected final static String PRINT_MARGIN_COLOR =
 
4566         // PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
 
4567         /** Preference key for print margin ruler column */
 
4568         // protected final static String PRINT_MARGIN_COLUMN =
 
4569         // PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
 
4570         /** Preference key for error indication */
 
4571         // protected final static String ERROR_INDICATION =
 
4572         // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
 
4573         /** Preference key for error color */
 
4574         // protected final static String ERROR_INDICATION_COLOR =
 
4575         // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
 
4576         /** Preference key for warning indication */
 
4577         // protected final static String WARNING_INDICATION =
 
4578         // PreferenceConstants.EDITOR_WARNING_INDICATION;
 
4579         /** Preference key for warning color */
 
4580         // protected final static String WARNING_INDICATION_COLOR =
 
4581         // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
 
4582         /** Preference key for task indication */
 
4583         protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
 
4585         /** Preference key for task color */
 
4586         protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
 
4588         /** Preference key for bookmark indication */
 
4589         protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
 
4591         /** Preference key for bookmark color */
 
4592         protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
 
4594         /** Preference key for search result indication */
 
4595         protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
 
4597         /** Preference key for search result color */
 
4598         protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
 
4600         /** Preference key for unknown annotation indication */
 
4601         protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
 
4603         /** Preference key for unknown annotation color */
 
4604         protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
 
4606         /** Preference key for shwoing the overview ruler */
 
4607         protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
 
4609         /** Preference key for error indication in overview ruler */
 
4610         protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
 
4612         /** Preference key for warning indication in overview ruler */
 
4613         protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
 
4615         /** Preference key for task indication in overview ruler */
 
4616         protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
 
4618         /** Preference key for bookmark indication in overview ruler */
 
4619         protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
 
4621         /** Preference key for search result indication in overview ruler */
 
4622         protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
 
4624         /** Preference key for unknown annotation indication in overview ruler */
 
4625         protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
 
4627         // /** Preference key for compiler task tags */
 
4628         // private final static String COMPILER_TASK_TAGS=
 
4629         // JavaCore.COMPILER_TASK_TAGS;
 
4630         /** Preference key for browser like links */
 
4631         private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS;
 
4633         /** Preference key for key modifier of browser like links */
 
4634         private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER;
 
4637          * Preference key for key modifier mask of browser like links. The value is
 
4638          * only used if the value of <code>EDITOR_BROWSER_LIKE_LINKS</code> cannot
 
4639          * be resolved to valid SWT modifier bits.
 
4643         private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
 
4645         private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
 
4647         private static boolean isBracket(char character) {
 
4648                 for (int i = 0; i != BRACKETS.length; ++i)
 
4649                         if (character == BRACKETS[i])
 
4654         private static boolean isSurroundedByBrackets(IDocument document, int offset) {
 
4655                 if (offset == 0 || offset == document.getLength())
 
4659                         return isBracket(document.getChar(offset - 1)) && isBracket(document.getChar(offset));
 
4661                 } catch (BadLocationException e) {
 
4666         // protected void configureSourceViewerDecorationSupport() {
 
4668         // fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
 
4670         // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
 
4671         // AnnotationType.UNKNOWN,
 
4672         // UNKNOWN_INDICATION_COLOR,
 
4673         // UNKNOWN_INDICATION,
 
4674         // UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
 
4676         // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
 
4677         // AnnotationType.BOOKMARK,
 
4678         // BOOKMARK_INDICATION_COLOR,
 
4679         // BOOKMARK_INDICATION,
 
4680         // BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
 
4682         // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
 
4683         // AnnotationType.TASK,
 
4684         // TASK_INDICATION_COLOR,
 
4686         // TASK_INDICATION_IN_OVERVIEW_RULER,
 
4688         // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
 
4689         // AnnotationType.SEARCH,
 
4690         // SEARCH_RESULT_INDICATION_COLOR,
 
4691         // SEARCH_RESULT_INDICATION,
 
4692         // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
 
4694         // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
 
4695         // AnnotationType.WARNING,
 
4696         // WARNING_INDICATION_COLOR,
 
4697         // WARNING_INDICATION,
 
4698         // WARNING_INDICATION_IN_OVERVIEW_RULER,
 
4700         // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
 
4701         // AnnotationType.ERROR,
 
4702         // ERROR_INDICATION_COLOR,
 
4703         // ERROR_INDICATION,
 
4704         // ERROR_INDICATION_IN_OVERVIEW_RULER,
 
4707         // fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE,
 
4708         // CURRENT_LINE_COLOR);
 
4709         // fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN,
 
4710         // PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
 
4711         // fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS,
 
4712         // MATCHING_BRACKETS_COLOR);
 
4714         // fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
 
4718          * Returns the Java element wrapped by this editors input.
 
4720          * @return the Java element wrapped by this editors input.
 
4723         abstract protected IJavaElement getInputJavaElement();
 
4725         protected void updateStatusLine() {
 
4726                 ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
 
4727                 Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength());
 
4728                 setStatusLineErrorMessage(null);
 
4729                 setStatusLineMessage(null);
 
4730                 if (annotation != null) {
 
4732                                 fIsUpdatingAnnotationViews = true;
 
4733                                 updateAnnotationViews(annotation);
 
4735                                 fIsUpdatingAnnotationViews = false;
 
4737                         if (annotation instanceof IJavaAnnotation && ((IJavaAnnotation) annotation).isProblem())
 
4738                                 setStatusLineMessage(annotation.getText());
 
4743          * Jumps to the matching bracket.
 
4745         public void gotoMatchingBracket() {
 
4747                 ISourceViewer sourceViewer = getSourceViewer();
 
4748                 IDocument document = sourceViewer.getDocument();
 
4749                 if (document == null)
 
4752                 IRegion selection = getSignedSelection(sourceViewer);
 
4754                 int selectionLength = Math.abs(selection.getLength());
 
4755                 if (selectionLength > 1) {
 
4756                         setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$
 
4757                         sourceViewer.getTextWidget().getDisplay().beep();
 
4762                 int sourceCaretOffset = selection.getOffset() + selection.getLength();
 
4763                 if (isSurroundedByBrackets(document, sourceCaretOffset))
 
4764                         sourceCaretOffset -= selection.getLength();
 
4766                 IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
 
4767                 if (region == null) {
 
4768                         setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$
 
4769                         sourceViewer.getTextWidget().getDisplay().beep();
 
4773                 int offset = region.getOffset();
 
4774                 int length = region.getLength();
 
4779                 int anchor = fBracketMatcher.getAnchor();
 
4780                 int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
 
4782                 boolean visible = false;
 
4783                 if (sourceViewer instanceof ITextViewerExtension5) {
 
4784                         ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
 
4785                         visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
 
4787                         IRegion visibleRegion = sourceViewer.getVisibleRegion();
 
4788                         visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength());
 
4792                         setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$
 
4793                         sourceViewer.getTextWidget().getDisplay().beep();
 
4797                 if (selection.getLength() < 0)
 
4798                         targetOffset -= selection.getLength();
 
4800                 sourceViewer.setSelectedRange(targetOffset, selection.getLength());
 
4801                 sourceViewer.revealRange(targetOffset, selection.getLength());
 
4805          * Ses the given message as error message to this editor's status line.
 
4810         protected void setStatusLineErrorMessage(String msg) {
 
4811                 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
 
4812                 if (statusLine != null)
 
4813                         statusLine.setMessage(true, msg, null);
 
4817          * Sets the given message as message to this editor's status line.
 
4823         protected void setStatusLineMessage(String msg) {
 
4824                 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
 
4825                 if (statusLine != null)
 
4826                         statusLine.setMessage(false, msg, null);
 
4830          * Returns the annotation closest to the given range respecting the given
 
4831          * direction. If an annotation is found, the annotations current position is
 
4832          * copied into the provided annotation position.
 
4839          *          <code>true</code> for forwards, <code>false</code> for
 
4841          * @param annotationPosition
 
4842          *          the position of the found annotation
 
4843          * @return the found annotation
 
4845         private Annotation getNextAnnotation(final int offset, final int length, boolean forward, Position annotationPosition) {
 
4847                 Annotation nextAnnotation = null;
 
4848                 Position nextAnnotationPosition = null;
 
4849                 Annotation containingAnnotation = null;
 
4850                 Position containingAnnotationPosition = null;
 
4851                 boolean currentAnnotation = false;
 
4853                 IDocument document = getDocumentProvider().getDocument(getEditorInput());
 
4854                 int endOfDocument = document.getLength();
 
4855                 int distance = Integer.MAX_VALUE;
 
4857                 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
 
4858                 Iterator e = new JavaAnnotationIterator(model, true, true);
 
4859                 while (e.hasNext()) {
 
4860                         Annotation a = (Annotation) e.next();
 
4861                         if ((a instanceof IJavaAnnotation) && ((IJavaAnnotation) a).hasOverlay() || !isNavigationTarget(a))
 
4864                         Position p = model.getPosition(a);
 
4868                         if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {// ||
 
4869                                 // p.includes(offset))
 
4871                                 if (containingAnnotation == null
 
4872                                                 || (forward && p.length >= containingAnnotationPosition.length || !forward
 
4873                                                                 && p.length >= containingAnnotationPosition.length)) {
 
4874                                         containingAnnotation = a;
 
4875                                         containingAnnotationPosition = p;
 
4876                                         currentAnnotation = p.length == length;
 
4879                                 int currentDistance = 0;
 
4882                                         currentDistance = p.getOffset() - offset;
 
4883                                         if (currentDistance < 0)
 
4884                                                 currentDistance = endOfDocument + currentDistance;
 
4886                                         if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
 
4887                                                 distance = currentDistance;
 
4889                                                 nextAnnotationPosition = p;
 
4892                                         currentDistance = offset + length - (p.getOffset() + p.length);
 
4893                                         if (currentDistance < 0)
 
4894                                                 currentDistance = endOfDocument + currentDistance;
 
4896                                         if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
 
4897                                                 distance = currentDistance;
 
4899                                                 nextAnnotationPosition = p;
 
4904                 if (containingAnnotationPosition != null && (!currentAnnotation || nextAnnotation == null)) {
 
4905                         annotationPosition.setOffset(containingAnnotationPosition.getOffset());
 
4906                         annotationPosition.setLength(containingAnnotationPosition.getLength());
 
4907                         return containingAnnotation;
 
4909                 if (nextAnnotationPosition != null) {
 
4910                         annotationPosition.setOffset(nextAnnotationPosition.getOffset());
 
4911                         annotationPosition.setLength(nextAnnotationPosition.getLength());
 
4914                 return nextAnnotation;
 
4918          * Returns the annotation overlapping with the given range or
 
4919          * <code>null</code>.
 
4925          * @return the found annotation or <code>null</code>
 
4928         private Annotation getAnnotation(int offset, int length) {
 
4929                 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
 
4930                 Iterator e = new JavaAnnotationIterator(model, true, true);
 
4931                 while (e.hasNext()) {
 
4932                         Annotation a = (Annotation) e.next();
 
4933                         if (!isNavigationTarget(a))
 
4936                         Position p = model.getPosition(a);
 
4937                         if (p != null && p.overlapsWith(offset, length))
 
4945          * Returns whether the given annotation is configured as a target for the "Go
 
4946          * to Next/Previous Annotation" actions
 
4950          * @return <code>true</code> if this is a target, <code>false</code>
 
4954         protected boolean isNavigationTarget(Annotation annotation) {
 
4955                 Preferences preferences = EditorsUI.getPluginPreferences();
 
4956                 AnnotationPreference preference = getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
 
4958                 // String key= forward ? preference.getIsGoToNextNavigationTargetKey() :
 
4959                 // preference.getIsGoToPreviousNavigationTargetKey();
 
4960                 String key = preference == null ? null : preference.getIsGoToNextNavigationTargetKey();
 
4961                 return (key != null && preferences.getBoolean(key));
 
4965          * Returns a segmentation of the line of the given document appropriate for
 
4966          * bidi rendering. The default implementation returns only the string literals
 
4967          * of a php code line as segments.
 
4972          *          the offset of the line
 
4973          * @return the line's bidi segmentation
 
4974          * @throws BadLocationException
 
4975          *           in case lineOffset is not valid in document
 
4977         public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException {
 
4979                 IRegion line = document.getLineInformationOfOffset(lineOffset);
 
4980                 ITypedRegion[] linePartitioning = document.computePartitioning(lineOffset, line.getLength());
 
4982                 List segmentation = new ArrayList();
 
4983                 for (int i = 0; i < linePartitioning.length; i++) {
 
4984                         if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType())) {
 
4985                                 segmentation.add(linePartitioning[i]);
 
4986                         } else if (IPHPPartitions.PHP_STRING_HEREDOC.equals(linePartitioning[i].getType())) {
 
4987                                 segmentation.add(linePartitioning[i]);
 
4991                 if (segmentation.size() == 0)
 
4994                 int size = segmentation.size();
 
4995                 int[] segments = new int[size * 2 + 1];
 
4998                 for (int i = 0; i < size; i++) {
 
4999                         ITypedRegion segment = (ITypedRegion) segmentation.get(i);
 
5004                         int offset = segment.getOffset() - lineOffset;
 
5005                         if (offset > segments[j - 1])
 
5006                                 segments[j++] = offset;
 
5008                         if (offset + segment.getLength() >= line.getLength())
 
5011                         segments[j++] = offset + segment.getLength();
 
5014                 if (j < segments.length) {
 
5015                         int[] result = new int[j];
 
5016                         System.arraycopy(segments, 0, result, 0, j);
 
5024          * Returns a segmentation of the given line appropriate for bidi rendering.
 
5025          * The default implementation returns only the string literals of a php code
 
5029          *          the offset of the line
 
5031          *          the content of the line
 
5032          * @return the line's bidi segmentation
 
5034         protected int[] getBidiLineSegments(int lineOffset, String line) {
 
5035                 IDocumentProvider provider = getDocumentProvider();
 
5036                 if (provider != null && line != null && line.length() > 0) {
 
5037                         IDocument document = provider.getDocument(getEditorInput());
 
5038                         if (document != null)
 
5040                                         return getBidiLineSegments(document, lineOffset);
 
5041                                 } catch (BadLocationException x) {
 
5049          * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
 
5051         // protected final ISourceViewer createSourceViewer(
 
5052         // Composite parent,
 
5053         // IVerticalRuler ruler,
 
5055         // ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
 
5056         // StyledText text = viewer.getTextWidget();
 
5057         // text.addBidiSegmentListener(new BidiSegmentListener() {
 
5058         // public void lineGetSegments(BidiSegmentEvent event) {
 
5059         // event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
 
5062         // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
 
5065         public final ISourceViewer getViewer() {
 
5066                 return getSourceViewer();
 
5069         // protected void showOverviewRuler() {
 
5070         // if (fOverviewRuler != null) {
 
5071         // if (getSourceViewer() instanceof ISourceViewerExtension) {
 
5072         // ((ISourceViewerExtension)
 
5073         // getSourceViewer()).showAnnotationsOverview(true);
 
5074         // fSourceViewerDecorationSupport.updateOverviewDecorations();
 
5079         // protected void hideOverviewRuler() {
 
5080         // if (getSourceViewer() instanceof ISourceViewerExtension) {
 
5081         // fSourceViewerDecorationSupport.hideAnnotationOverview();
 
5082         // ((ISourceViewerExtension)
 
5083         // getSourceViewer()).showAnnotationsOverview(false);
 
5087         // protected boolean isOverviewRulerVisible() {
 
5088         // IPreferenceStore store = getPreferenceStore();
 
5089         // return store.getBoolean(OVERVIEW_RULER);
 
5092          * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
 
5094         // protected ISourceViewer createJavaSourceViewer(
 
5095         // Composite parent,
 
5096         // IVerticalRuler ruler,
 
5097         // IOverviewRuler overviewRuler,
 
5098         // boolean isOverviewRulerVisible,
 
5100         // return new SourceViewer(parent, ruler, overviewRuler,
 
5101         // isOverviewRulerVisible(), styles);
 
5104          * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
 
5106         protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
 
5107                         boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
 
5108                 return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, store);
 
5112          * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
 
5114         protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {
 
5116                 ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles,
 
5117                                 getPreferenceStore());
 
5119                 StyledText text = viewer.getTextWidget();
 
5120                 text.addBidiSegmentListener(new BidiSegmentListener() {
 
5121                         public void lineGetSegments(BidiSegmentEvent event) {
 
5122                                 event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
 
5126                 // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
 
5128                 // ensure source viewer decoration support has been created and
 
5130                 getSourceViewerDecorationSupport(viewer);
 
5136          * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
 
5138         protected boolean affectsTextPresentation(PropertyChangeEvent event) {
 
5139                 return ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).affectsTextPresentation(event)
 
5140                                 || super.affectsTextPresentation(event);
 
5144         // protected boolean affectsTextPresentation(PropertyChangeEvent event) {
 
5145         // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
 
5146         // return textTools.affectsBehavior(event);
 
5149          * Creates and returns the preference store for this Java editor with the
 
5153          *          The editor input for which to create the preference store
 
5154          * @return the preference store for this editor
 
5158         private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
 
5159                 List stores = new ArrayList(3);
 
5161                 IJavaProject project = EditorUtility.getJavaProject(input);
 
5162                 if (project != null)
 
5163                         stores.add(new OptionsAdapter(project.getOptions(false), PHPeclipsePlugin.getDefault().getMockupPreferenceStore(),
 
5164                                         new OptionsAdapter.IPropertyChangeEventFilter() {
 
5166                                                 public boolean isFiltered(PropertyChangeEvent event) {
 
5167                                                         IJavaElement inputJavaElement = getInputJavaElement();
 
5168                                                         IJavaProject javaProject = inputJavaElement != null ? inputJavaElement.getJavaProject() : null;
 
5169                                                         if (javaProject == null)
 
5172                                                         return !javaProject.getProject().equals(event.getSource());
 
5177                 stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore());
 
5178                 stores.add(new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()));
 
5179                 stores.add(EditorsUI.getPreferenceStore());
 
5181                 return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
 
5185          * Jumps to the error next according to the given direction.
 
5187         public void gotoError(boolean forward) {
 
5189                 ISelectionProvider provider = getSelectionProvider();
 
5191                 ITextSelection s = (ITextSelection) provider.getSelection();
 
5192                 Position errorPosition = new Position(0, 0);
 
5193                 IJavaAnnotation nextError = getNextError(s.getOffset(), forward, errorPosition);
 
5195                 if (nextError != null) {
 
5197                         IMarker marker = null;
 
5198                         if (nextError instanceof MarkerAnnotation)
 
5199                                 marker = ((MarkerAnnotation) nextError).getMarker();
 
5201                                 Iterator e = nextError.getOverlaidIterator();
 
5203                                         while (e.hasNext()) {
 
5204                                                 Object o = e.next();
 
5205                                                 if (o instanceof MarkerAnnotation) {
 
5206                                                         marker = ((MarkerAnnotation) o).getMarker();
 
5213                         if (marker != null) {
 
5214                                 IWorkbenchPage page = getSite().getPage();
 
5215                                 IViewPart view = view = page.findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
 
5216                                 if (view instanceof TaskList) {
 
5217                                         StructuredSelection ss = new StructuredSelection(marker);
 
5218                                         ((TaskList) view).setSelection(ss, true);
 
5222                         selectAndReveal(errorPosition.getOffset(), errorPosition.getLength());
 
5223                         // setStatusLineErrorMessage(nextError.getMessage());
 
5227                         setStatusLineErrorMessage(null);
 
5232         private IJavaAnnotation getNextError(int offset, boolean forward, Position errorPosition) {
 
5234                 IJavaAnnotation nextError = null;
 
5235                 Position nextErrorPosition = null;
 
5237                 IDocument document = getDocumentProvider().getDocument(getEditorInput());
 
5238                 int endOfDocument = document.getLength();
 
5241                 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
 
5242                 Iterator e = new JavaAnnotationIterator(model, false);
 
5243                 while (e.hasNext()) {
 
5245                         IJavaAnnotation a = (IJavaAnnotation) e.next();
 
5246                         if (a.hasOverlay() || !a.isProblem())
 
5249                         Position p = model.getPosition((Annotation) a);
 
5250                         if (!p.includes(offset)) {
 
5252                                 int currentDistance = 0;
 
5255                                         currentDistance = p.getOffset() - offset;
 
5256                                         if (currentDistance < 0)
 
5257                                                 currentDistance = endOfDocument - offset + p.getOffset();
 
5259                                         currentDistance = offset - p.getOffset();
 
5260                                         if (currentDistance < 0)
 
5261                                                 currentDistance = offset + endOfDocument - p.getOffset();
 
5264                                 if (nextError == null || currentDistance < distance) {
 
5265                                         distance = currentDistance;
 
5267                                         nextErrorPosition = p;
 
5272                 if (nextErrorPosition != null) {
 
5273                         errorPosition.setOffset(nextErrorPosition.getOffset());
 
5274                         errorPosition.setLength(nextErrorPosition.getLength());
 
5280         protected void uninstallOverrideIndicator() {
 
5281                 // if (fOverrideIndicatorManager != null) {
 
5282                 // fOverrideIndicatorManager.removeAnnotations();
 
5283                 // fOverrideIndicatorManager= null;
 
5287         protected void installOverrideIndicator(boolean waitForReconcilation) {
 
5288                 uninstallOverrideIndicator();
 
5289                 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
 
5290                 final IJavaElement inputElement = getInputJavaElement();
 
5292                 if (model == null || inputElement == null)
 
5295                 // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
 
5296                 // inputElement, null);
 
5298                 // if (provideAST) {
 
5300                 // Job(JavaEditorMessages.getString("OverrideIndicatorManager.intallJob")) {
 
5304                 // org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
 
5307                 // protected IStatus run(IProgressMonitor monitor) {
 
5308                 // CompilationUnit ast=
 
5309                 // JavaPlugin.getDefault().getASTProvider().getAST(inputElement, true,
 
5311                 // if (fOverrideIndicatorManager != null) // editor might have been closed
 
5313                 // fOverrideIndicatorManager.reconciled(ast, true, monitor);
 
5314                 // return Status.OK_STATUS;
 
5317                 // job.setPriority(Job.DECORATE);
 
5318                 // job.setSystem(true);
 
5324          * Tells whether override indicators are shown.
 
5326          * @return <code>true</code> if the override indicators are shown
 
5329         // protected boolean isShowingOverrideIndicators() {
 
5330         // AnnotationPreference preference=
 
5331         // getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
 
5332         // IPreferenceStore store= getPreferenceStore();
 
5333         // return getBoolean(store, preference.getHighlightPreferenceKey())
 
5334         // || getBoolean(store, preference.getVerticalRulerPreferenceKey())
 
5335         // || getBoolean(store, preference.getOverviewRulerPreferenceKey())
 
5336         // || getBoolean(store, preference.getTextPreferenceKey());
 
5339          * Returns the boolean preference for the given key.
 
5342          *          the preference store
 
5344          *          the preference key
 
5345          * @return <code>true</code> if the key exists in the store and its value is
 
5349         private boolean getBoolean(IPreferenceStore store, String key) {
 
5350                 return key != null && store.getBoolean(key);
 
5353         protected boolean isPrefQuickDiffAlwaysOn() {
 
5354                 return false; // never show change ruler for the non-editable java editor.
 
5355                 // Overridden in subclasses like PHPUnitEditor
 
5359          * @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions()
 
5361         protected void createNavigationActions() {
 
5362                 super.createNavigationActions();
 
5364                 final StyledText textWidget = getSourceViewer().getTextWidget();
 
5366                 IAction action = new SmartLineStartAction(textWidget, false);
 
5367                 action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
 
5368                 setAction(ITextEditorActionDefinitionIds.LINE_START, action);
 
5370                 action = new SmartLineStartAction(textWidget, true);
 
5371                 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
 
5372                 setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);
 
5374                 action = new NavigatePreviousSubWordAction();
 
5375                 action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS);
 
5376                 setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action);
 
5377                 textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL);
 
5379                 action = new NavigateNextSubWordAction();
 
5380                 action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT);
 
5381                 setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action);
 
5382                 textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL);
 
5384                 action = new SelectPreviousSubWordAction();
 
5385                 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS);
 
5386                 setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action);
 
5387                 textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL);
 
5389                 action = new SelectNextSubWordAction();
 
5390                 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT);
 
5391                 setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action);
 
5392                 textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL);
 
5396          * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createCompositeRuler()
 
5398 //      protected CompositeRuler createCompositeRuler() {
 
5399 //              if (!getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
 
5400 //                      return super.createCompositeRuler();
 
5402 //              CompositeRuler ruler = new CompositeRuler();
 
5403 //              AnnotationRulerColumn column = new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess());
 
5404 //              column.setHover(new JavaExpandHover(ruler, getAnnotationAccess(), new IDoubleClickListener() {
 
5406 //                      public void doubleClick(DoubleClickEvent event) {
 
5407 //                              // for now: just invoke ruler double click action
 
5408 //                              triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK);
 
5411 //                      private void triggerAction(String actionID) {
 
5412 //                              IAction action = getAction(actionID);
 
5413 //                              if (action != null) {
 
5414 //                                      if (action instanceof IUpdate)
 
5415 //                                              ((IUpdate) action).update();
 
5416 //                                      // hack to propagate line change
 
5417 //                                      if (action instanceof ISelectionListener) {
 
5418 //                                              ((ISelectionListener) action).selectionChanged(null, null);
 
5420 //                                      if (action.isEnabled())
 
5426 //              ruler.addDecorator(0, column);
 
5428 //              if (isLineNumberRulerVisible())
 
5429 //                      ruler.addDecorator(1, createLineNumberRulerColumn());
 
5430 //              else if (isPrefQuickDiffAlwaysOn())
 
5431 //                      ruler.addDecorator(1, createChangeRulerColumn());
 
5437          * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createAnnotationRulerColumn(org.eclipse.jface.text.source.CompositeRuler)
 
5440         protected IVerticalRulerColumn createAnnotationRulerColumn(CompositeRuler ruler) {
 
5441                 if (!getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
 
5442                         return super.createAnnotationRulerColumn(ruler);
 
5444                 AnnotationRulerColumn column= new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess());
 
5445                 column.setHover(new JavaExpandHover(ruler, getAnnotationAccess(), new IDoubleClickListener() {
 
5447                         public void doubleClick(DoubleClickEvent event) {
 
5448                                 // for now: just invoke ruler double click action
 
5449                                 triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK);
 
5452                         private void triggerAction(String actionID) {
 
5453                                 IAction action= getAction(actionID);
 
5454                                 if (action != null) {
 
5455                                         if (action instanceof IUpdate)
 
5456                                                 ((IUpdate) action).update();
 
5457                                         // hack to propagate line change
 
5458                                         if (action instanceof ISelectionListener) {
 
5459                                                 ((ISelectionListener)action).selectionChanged(null, null);
 
5461                                         if (action.isEnabled())
 
5471          * Returns the folding action group, or <code>null</code> if there is none.
 
5473          * @return the folding action group, or <code>null</code> if there is none
 
5476         protected FoldingActionGroup getFoldingActionGroup() {
 
5477                 return fFoldingGroup;
 
5481          * @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert()
 
5483         protected void performRevert() {
 
5484                 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
 
5485                 projectionViewer.setRedraw(false);
 
5488                         boolean projectionMode = projectionViewer.isProjectionMode();
 
5489                         if (projectionMode) {
 
5490                                 projectionViewer.disableProjection();
 
5491                                 if (fProjectionModelUpdater != null)
 
5492                                         fProjectionModelUpdater.uninstall();
 
5495                         super.performRevert();
 
5497                         if (projectionMode) {
 
5498                                 if (fProjectionModelUpdater != null)
 
5499                                         fProjectionModelUpdater.install(this, projectionViewer);
 
5500                                 projectionViewer.enableProjection();
 
5504                         projectionViewer.setRedraw(true);
 
5509          * React to changed selection.
 
5513         protected void selectionChanged() {
 
5514                 if (getSelectionProvider() == null)
 
5516                 ISourceReference element = computeHighlightRangeSourceReference();
 
5517                 if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
 
5518                         synchronizeOutlinePage(element);
 
5519                 setSelection(element, false);
 
5523         private boolean isJavaOutlinePageActive() {
 
5524                 IWorkbenchPart part = getActivePart();
 
5525                 return part instanceof ContentOutline && ((ContentOutline) part).getCurrentPage() == fOutlinePage;
 
5528         private IWorkbenchPart getActivePart() {
 
5529                 IWorkbenchWindow window = getSite().getWorkbenchWindow();
 
5530                 IPartService service = window.getPartService();
 
5531                 IWorkbenchPart part = service.getActivePart();
 
5536          * Computes and returns the source reference that includes the caret and
 
5537          * serves as provider for the outline page selection and the editor range
 
5540          * @return the computed source reference
 
5543         protected ISourceReference computeHighlightRangeSourceReference() {
 
5544                 ISourceViewer sourceViewer = getSourceViewer();
 
5545                 if (sourceViewer == null)
 
5548                 StyledText styledText = sourceViewer.getTextWidget();
 
5549                 if (styledText == null)
 
5553                 if (sourceViewer instanceof ITextViewerExtension5) {
 
5554                         ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
 
5555                         caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
 
5557                         int offset = sourceViewer.getVisibleRegion().getOffset();
 
5558                         caret = offset + styledText.getCaretOffset();
 
5561                 IJavaElement element = getElementAt(caret, false);
 
5563                 if (!(element instanceof ISourceReference))
 
5566                 if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) {
 
5568                         IImportDeclaration declaration = (IImportDeclaration) element;
 
5569                         IImportContainer container = (IImportContainer) declaration.getParent();
 
5570                         ISourceRange srcRange = null;
 
5573                                 srcRange = container.getSourceRange();
 
5574                         } catch (JavaModelException e) {
 
5577                         if (srcRange != null && srcRange.getOffset() == caret)
 
5581                 return (ISourceReference) element;
 
5585          * Returns the most narrow java element including the given offset.
 
5588          *          the offset inside of the requested element
 
5590          *          <code>true</code> if editor input should be reconciled in
 
5592          * @return the most narrow java element
 
5595         protected IJavaElement getElementAt(int offset, boolean reconcile) {
 
5596                 return getElementAt(offset);
 
5599         public ShowInContext getShowInContext() {
 
5600                 FileEditorInput fei = (FileEditorInput) getEditorInput();
 
5601                 ShowInContext context = BrowserUtil.getShowInContext(fei.getFile(), false, "");
 
5602                 if (context != null) {
 
5605                 return new ShowInContext(fei.getFile(), null);
 
5608         public String[] getShowInTargetIds() {
 
5609                 return new String[] { BrowserView.ID_BROWSER };
 
5613          * Updates the occurrences annotations based on the current selection.
 
5616          *          the text selection
 
5618          *          the compilation unit AST
 
5621         protected void updateOccurrenceAnnotations(ITextSelection selection) {// ,
 
5626                 if (fOccurrencesFinderJob != null)
 
5627                         fOccurrencesFinderJob.cancel();
 
5629                 if (!fMarkOccurrenceAnnotations)
 
5632                 // if (astRoot == null || selection == null)
 
5633                 if (selection == null)
 
5636                 IDocument document = getSourceViewer().getDocument();
 
5637                 if (document == null)
 
5640                 fMarkOccurrenceTargetRegion = null;
 
5641                 if (document instanceof IDocumentExtension4) {
 
5642                         int offset = selection.getOffset();
 
5643                         long currentModificationStamp = ((IDocumentExtension4) document).getModificationStamp();
 
5644                         if (fMarkOccurrenceTargetRegion != null && currentModificationStamp == fMarkOccurrenceModificationStamp) {
 
5645                                 if (fMarkOccurrenceTargetRegion.getOffset() <= offset
 
5646                                                 && offset <= fMarkOccurrenceTargetRegion.getOffset() + fMarkOccurrenceTargetRegion.getLength())
 
5649                         fMarkOccurrenceTargetRegion = JavaWordFinder.findWord(document, offset);
 
5650                         fMarkOccurrenceModificationStamp = currentModificationStamp;
 
5653                 if (fMarkOccurrenceTargetRegion == null || fMarkOccurrenceTargetRegion.getLength() == 0) {
 
5657                 List matches = null;
 
5659                 if (matches == null) {
 
5661                                 matches = new ArrayList();
 
5663                                 Scanner fScanner = new Scanner();
 
5664                                 fScanner.setSource(document.get().toCharArray());
 
5665                                 fScanner.setPHPMode(false);
 
5669                                 wordStr = document.get(fMarkOccurrenceTargetRegion.getOffset(), fMarkOccurrenceTargetRegion.getLength());
 
5670                                 if (wordStr != null) {
 
5671                                         word = wordStr.toCharArray();
 
5672                                         int fToken = ITerminalSymbols.TokenNameEOF;
 
5674                                                 fToken = fScanner.getNextToken();
 
5675                                                 while (fToken != ITerminalSymbols.TokenNameEOF) { // && fToken !=
 
5676                                                         // TokenNameERROR) {
 
5677                                                         if (fToken == ITerminalSymbols.TokenNameVariable || fToken == ITerminalSymbols.TokenNameIdentifier) {
 
5679                                                                 if (fScanner.equalsCurrentTokenSource(word)) {
 
5680                                                                         matches.add(new Region(fScanner.getCurrentTokenStartPosition(), fScanner.getCurrentTokenEndPosition()
 
5681                                                                                         - fScanner.getCurrentTokenStartPosition() + 1));
 
5684                                                         fToken = fScanner.getNextToken();
 
5686                                         } catch (InvalidInputException e) {
 
5688                                         } catch (SyntaxError e) {
 
5692                         } catch (BadLocationException e1) {
 
5694                         } catch (Exception e) {
 
5695                                 e.printStackTrace();
 
5701                 if (matches == null || matches.size() == 0) {
 
5702                         if (!fStickyOccurrenceAnnotations)
 
5703                                 removeOccurrenceAnnotations();
 
5707                 Position[] positions = new Position[matches.size()];
 
5709                 for (Iterator each = matches.iterator(); each.hasNext();) {
 
5710                         IRegion currentNode = (IRegion) each.next();
 
5711                         positions[i++] = new Position(currentNode.getOffset(), currentNode.getLength());
 
5714                 fOccurrencesFinderJob = new OccurrencesFinderJob(document, positions, selection);
 
5715                 // fOccurrencesFinderJob.setPriority(Job.DECORATE);
 
5716                 // fOccurrencesFinderJob.setSystem(true);
 
5717                 // fOccurrencesFinderJob.schedule();
 
5718                 fOccurrencesFinderJob.run(new NullProgressMonitor());
 
5721         protected void installOccurrencesFinder() {
 
5722                 fMarkOccurrenceAnnotations = true;
 
5724                 fPostSelectionListenerWithAST = new ISelectionListenerWithAST() {
 
5725                         public void selectionChanged(IEditorPart part, ITextSelection selection) { // ,
 
5729                                 updateOccurrenceAnnotations(selection);// , astRoot);
 
5732                 SelectionListenerWithASTManager.getDefault().addListener(this, fPostSelectionListenerWithAST);
 
5733                 if (getSelectionProvider() != null) {
 
5734                         fForcedMarkOccurrencesSelection = getSelectionProvider().getSelection();
 
5735                         SelectionListenerWithASTManager.getDefault().forceSelectionChange(this, (ITextSelection) fForcedMarkOccurrencesSelection);
 
5738                 if (fOccurrencesFinderJobCanceler == null) {
 
5739                         fOccurrencesFinderJobCanceler = new OccurrencesFinderJobCanceler();
 
5740                         fOccurrencesFinderJobCanceler.install();
 
5744         protected void uninstallOccurrencesFinder() {
 
5745                 fMarkOccurrenceAnnotations = false;
 
5747                 if (fOccurrencesFinderJob != null) {
 
5748                         fOccurrencesFinderJob.cancel();
 
5749                         fOccurrencesFinderJob = null;
 
5752                 if (fOccurrencesFinderJobCanceler != null) {
 
5753                         fOccurrencesFinderJobCanceler.uninstall();
 
5754                         fOccurrencesFinderJobCanceler = null;
 
5757                 if (fPostSelectionListenerWithAST != null) {
 
5758                         SelectionListenerWithASTManager.getDefault().removeListener(this, fPostSelectionListenerWithAST);
 
5759                         fPostSelectionListenerWithAST = null;
 
5762                 removeOccurrenceAnnotations();
 
5765         protected boolean isMarkingOccurrences() {
 
5766                 return fMarkOccurrenceAnnotations;
 
5769         void removeOccurrenceAnnotations() {
 
5770                 fMarkOccurrenceModificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
 
5771                 fMarkOccurrenceTargetRegion = null;
 
5773                 IDocumentProvider documentProvider = getDocumentProvider();
 
5774                 if (documentProvider == null)
 
5777                 IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
 
5778                 if (annotationModel == null || fOccurrenceAnnotations == null)
 
5781                 synchronized (getLockObject(annotationModel)) {
 
5782                         if (annotationModel instanceof IAnnotationModelExtension) {
 
5783                                 ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
 
5785                                 for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++)
 
5786                                         annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
 
5788                         fOccurrenceAnnotations = null;