Added mapped path field
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPEditor.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
9
10 Contributors:
11     IBM Corporation - Initial implementation
12     Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.ResourceBundle;
20 import java.util.StringTokenizer;
21
22 import net.sourceforge.phpdt.core.ICompilationUnit;
23 import net.sourceforge.phpdt.core.IJavaElement;
24 import net.sourceforge.phpdt.core.IMember;
25 import net.sourceforge.phpdt.core.ISourceRange;
26 import net.sourceforge.phpdt.core.ISourceReference;
27 import net.sourceforge.phpdt.core.JavaModelException;
28 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
29 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
30 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
31 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
32 import net.sourceforge.phpdt.ui.IContextMenuConstants;
33 import net.sourceforge.phpdt.ui.JavaUI;
34 import net.sourceforge.phpdt.ui.PreferenceConstants;
35 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
36 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
37 import net.sourceforge.phpdt.ui.text.JavaTextTools;
38 import net.sourceforge.phpeclipse.PHPCore;
39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
40 import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
41
42 import org.eclipse.core.resources.IMarker;
43 import org.eclipse.core.resources.IResource;
44 import org.eclipse.core.runtime.CoreException;
45 import org.eclipse.core.runtime.IProgressMonitor;
46 import org.eclipse.core.runtime.IStatus;
47 import org.eclipse.core.runtime.Preferences;
48 import org.eclipse.core.runtime.Status;
49 import org.eclipse.core.runtime.jobs.Job;
50 import org.eclipse.jface.action.Action;
51 import org.eclipse.jface.action.GroupMarker;
52 import org.eclipse.jface.action.IAction;
53 import org.eclipse.jface.action.MenuManager;
54 import org.eclipse.jface.action.Separator;
55 import org.eclipse.jface.preference.IPreferenceStore;
56 import org.eclipse.jface.preference.PreferenceConverter;
57 import org.eclipse.jface.text.BadLocationException;
58 import org.eclipse.jface.text.DefaultInformationControl;
59 import org.eclipse.jface.text.DocumentEvent;
60 import org.eclipse.jface.text.IDocument;
61 import org.eclipse.jface.text.IDocumentListener;
62 import org.eclipse.jface.text.IInformationControl;
63 import org.eclipse.jface.text.IInformationControlCreator;
64 import org.eclipse.jface.text.IRegion;
65 import org.eclipse.jface.text.ITextHover;
66 import org.eclipse.jface.text.ITextInputListener;
67 import org.eclipse.jface.text.ITextOperationTarget;
68 import org.eclipse.jface.text.ITextSelection;
69 import org.eclipse.jface.text.ITextViewer;
70 import org.eclipse.jface.text.ITextViewerExtension2;
71 import org.eclipse.jface.text.ITextViewerExtension3;
72 import org.eclipse.jface.text.ITypedRegion;
73 import org.eclipse.jface.text.Position;
74 import org.eclipse.jface.text.Region;
75 import org.eclipse.jface.text.TextSelection;
76 import org.eclipse.jface.text.information.IInformationProvider;
77 import org.eclipse.jface.text.information.InformationPresenter;
78 import org.eclipse.jface.text.source.Annotation;
79 import org.eclipse.jface.text.source.IAnnotationModel;
80 import org.eclipse.jface.text.source.IAnnotationModelExtension;
81 import org.eclipse.jface.text.source.IOverviewRuler;
82 import org.eclipse.jface.text.source.ISourceViewer;
83 import org.eclipse.jface.text.source.IVerticalRuler;
84 import org.eclipse.jface.text.source.OverviewRuler;
85 import org.eclipse.jface.text.source.SourceViewerConfiguration;
86 import org.eclipse.jface.util.IPropertyChangeListener;
87 import org.eclipse.jface.util.PropertyChangeEvent;
88 import org.eclipse.jface.viewers.ISelection;
89 import org.eclipse.jface.viewers.ISelectionChangedListener;
90 import org.eclipse.jface.viewers.ISelectionProvider;
91 import org.eclipse.jface.viewers.IStructuredSelection;
92 import org.eclipse.jface.viewers.SelectionChangedEvent;
93 import org.eclipse.jface.viewers.StructuredSelection;
94 import org.eclipse.swt.SWT;
95 import org.eclipse.swt.custom.BidiSegmentEvent;
96 import org.eclipse.swt.custom.BidiSegmentListener;
97 import org.eclipse.swt.custom.StyleRange;
98 import org.eclipse.swt.custom.StyledText;
99 import org.eclipse.swt.events.FocusEvent;
100 import org.eclipse.swt.events.FocusListener;
101 import org.eclipse.swt.events.KeyEvent;
102 import org.eclipse.swt.events.KeyListener;
103 import org.eclipse.swt.events.MouseEvent;
104 import org.eclipse.swt.events.MouseListener;
105 import org.eclipse.swt.events.MouseMoveListener;
106 import org.eclipse.swt.events.PaintEvent;
107 import org.eclipse.swt.events.PaintListener;
108 import org.eclipse.swt.graphics.Color;
109 import org.eclipse.swt.graphics.Cursor;
110 import org.eclipse.swt.graphics.GC;
111 import org.eclipse.swt.graphics.Image;
112 import org.eclipse.swt.graphics.Point;
113 import org.eclipse.swt.graphics.RGB;
114 import org.eclipse.swt.widgets.Composite;
115 import org.eclipse.swt.widgets.Control;
116 import org.eclipse.swt.widgets.Display;
117 import org.eclipse.swt.widgets.Shell;
118 import org.eclipse.ui.IEditorInput;
119 import org.eclipse.ui.IPageLayout;
120 import org.eclipse.ui.IPartService;
121 import org.eclipse.ui.IViewPart;
122 import org.eclipse.ui.IWorkbenchPage;
123 import org.eclipse.ui.IWorkbenchPart;
124 import org.eclipse.ui.IWorkbenchWindow;
125 import org.eclipse.ui.actions.ActionContext;
126 import org.eclipse.ui.actions.ActionGroup;
127 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
128 import org.eclipse.ui.editors.text.IEncodingSupport;
129 import org.eclipse.ui.part.IShowInTargetList;
130 import org.eclipse.ui.texteditor.ContentAssistAction;
131 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
132 import org.eclipse.ui.texteditor.ExtendedTextEditor;
133 import org.eclipse.ui.texteditor.IDocumentProvider;
134 import org.eclipse.ui.texteditor.IEditorStatusLine;
135 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
136 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
137 import org.eclipse.ui.texteditor.MarkerAnnotation;
138 import org.eclipse.ui.texteditor.ResourceAction;
139 import org.eclipse.ui.texteditor.TextEditorAction;
140 import org.eclipse.ui.texteditor.TextOperationAction;
141 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
142 import org.eclipse.ui.views.tasklist.TaskList;
143
144 /**
145  * PHP specific text editor.
146  */
147 public abstract class PHPEditor  extends ExtendedTextEditor implements IViewPartInputProvider {
148 //extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor {
149   /**
150          * "Smart" runnable for updating the outline page's selection.
151          */
152   class OutlinePageSelectionUpdater implements Runnable {
153
154     /** Has the runnable already been posted? */
155     private boolean fPosted = false;
156
157     public OutlinePageSelectionUpdater() {
158     }
159
160     /*
161      * @see Runnable#run()
162      */
163     public void run() {
164       synchronizeOutlinePageSelection();
165       fPosted = false;
166     }
167
168     /**
169      * Posts this runnable into the event queue.
170      */
171     public void post() {
172       if (fPosted)
173         return;
174
175       Shell shell = getSite().getShell();
176       if (shell != null & !shell.isDisposed()) {
177         fPosted = true;
178         shell.getDisplay().asyncExec(this);
179       }
180     }
181   };
182   class SelectionChangedListener implements ISelectionChangedListener {
183     public void selectionChanged(SelectionChangedEvent event) {
184       doSelectionChanged(event);
185     }
186   };
187
188   /*
189   * Link mode.  
190   */
191   class MouseClickListener
192     implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener, IPropertyChangeListener, IDocumentListener, ITextInputListener {
193
194     /** The session is active. */
195     private boolean fActive;
196
197     /** The currently active style range. */
198     private IRegion fActiveRegion;
199     /** The currently active style range as position. */
200     private Position fRememberedPosition;
201     /** The hand cursor. */
202     private Cursor fCursor;
203
204     /** The link color. */
205     private Color fColor;
206     /** The key modifier mask. */
207     private int fKeyModifierMask;
208
209     public void deactivate() {
210       deactivate(false);
211     }
212
213     public void deactivate(boolean redrawAll) {
214       if (!fActive)
215         return;
216
217       repairRepresentation(redrawAll);
218       fActive = false;
219     }
220
221     public void install() {
222
223       ISourceViewer sourceViewer = getSourceViewer();
224       if (sourceViewer == null)
225         return;
226
227       StyledText text = sourceViewer.getTextWidget();
228       if (text == null || text.isDisposed())
229         return;
230
231       updateColor(sourceViewer);
232
233       sourceViewer.addTextInputListener(this);
234
235       IDocument document = sourceViewer.getDocument();
236       if (document != null)
237         document.addDocumentListener(this);
238
239       text.addKeyListener(this);
240       text.addMouseListener(this);
241       text.addMouseMoveListener(this);
242       text.addFocusListener(this);
243       text.addPaintListener(this);
244
245       updateKeyModifierMask();
246
247       IPreferenceStore preferenceStore = getPreferenceStore();
248       preferenceStore.addPropertyChangeListener(this);
249     }
250
251     private void updateKeyModifierMask() {
252       String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
253       fKeyModifierMask = computeStateMask(modifiers);
254       if (fKeyModifierMask == -1) {
255         // Fallback to stored state mask
256         fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
257       };
258     }
259
260     private int computeStateMask(String modifiers) {
261       if (modifiers == null)
262         return -1;
263
264       if (modifiers.length() == 0)
265         return SWT.NONE;
266
267       int stateMask = 0;
268       StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
269       while (modifierTokenizer.hasMoreTokens()) {
270         int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
271         if (modifier == 0 || (stateMask & modifier) == modifier)
272           return -1;
273         stateMask = stateMask | modifier;
274       }
275       return stateMask;
276     }
277
278     public void uninstall() {
279
280       if (fColor != null) {
281         fColor.dispose();
282         fColor = null;
283       }
284
285       if (fCursor != null) {
286         fCursor.dispose();
287         fCursor = null;
288       }
289
290       ISourceViewer sourceViewer = getSourceViewer();
291       if (sourceViewer == null)
292         return;
293
294       sourceViewer.removeTextInputListener(this);
295
296       IDocument document = sourceViewer.getDocument();
297       if (document != null)
298         document.removeDocumentListener(this);
299
300       IPreferenceStore preferenceStore = getPreferenceStore();
301       if (preferenceStore != null)
302         preferenceStore.removePropertyChangeListener(this);
303
304       StyledText text = sourceViewer.getTextWidget();
305       if (text == null || text.isDisposed())
306         return;
307
308       text.removeKeyListener(this);
309       text.removeMouseListener(this);
310       text.removeMouseMoveListener(this);
311       text.removeFocusListener(this);
312       text.removePaintListener(this);
313     }
314
315     /*
316      * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
317      */
318     public void propertyChange(PropertyChangeEvent event) {
319       if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
320         ISourceViewer viewer = getSourceViewer();
321         if (viewer != null)
322           updateColor(viewer);
323       } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
324         updateKeyModifierMask();
325       }
326     }
327
328     private void updateColor(ISourceViewer viewer) {
329       if (fColor != null)
330         fColor.dispose();
331
332       StyledText text = viewer.getTextWidget();
333       if (text == null || text.isDisposed())
334         return;
335
336       Display display = text.getDisplay();
337       fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
338     }
339
340     /**
341      * Creates a color from the information stored in the given preference store.
342      * Returns <code>null</code> if there is no such information available.
343      */
344     private Color createColor(IPreferenceStore store, String key, Display display) {
345
346       RGB rgb = null;
347
348       if (store.contains(key)) {
349
350         if (store.isDefault(key))
351           rgb = PreferenceConverter.getDefaultColor(store, key);
352         else
353           rgb = PreferenceConverter.getColor(store, key);
354
355         if (rgb != null)
356           return new Color(display, rgb);
357       }
358
359       return null;
360     }
361
362     private void repairRepresentation() {
363       repairRepresentation(false);
364     }
365
366     private void repairRepresentation(boolean redrawAll) {
367
368       if (fActiveRegion == null)
369         return;
370
371       ISourceViewer viewer = getSourceViewer();
372       if (viewer != null) {
373         resetCursor(viewer);
374
375         int offset = fActiveRegion.getOffset();
376         int length = fActiveRegion.getLength();
377
378         // remove style
379         if (!redrawAll && viewer instanceof ITextViewerExtension2)
380            ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
381         else
382           viewer.invalidateTextPresentation();
383
384         // remove underline                             
385         if (viewer instanceof ITextViewerExtension3) {
386           ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
387           offset = extension.modelOffset2WidgetOffset(offset);
388         } else {
389           offset -= viewer.getVisibleRegion().getOffset();
390         }
391
392         StyledText text = viewer.getTextWidget();
393         try {
394           text.redrawRange(offset, length, true);
395         } catch (IllegalArgumentException x) {
396           PHPeclipsePlugin.log(x);
397         }
398       }
399
400       fActiveRegion = null;
401     }
402
403     // will eventually be replaced by a method provided by jdt.core             
404     private IRegion selectWord(IDocument document, int anchor) {
405
406       try {
407         int offset = anchor;
408         char c;
409
410         while (offset >= 0) {
411           c = document.getChar(offset);
412           if (!Character.isJavaIdentifierPart(c))
413             break;
414           --offset;
415         }
416
417         int start = offset;
418
419         offset = anchor;
420         int length = document.getLength();
421
422         while (offset < length) {
423           c = document.getChar(offset);
424           if (!Character.isJavaIdentifierPart(c))
425             break;
426           ++offset;
427         }
428
429         int end = offset;
430
431         if (start == end)
432           return new Region(start, 0);
433         else
434           return new Region(start + 1, end - start - 1);
435
436       } catch (BadLocationException x) {
437         return null;
438       }
439     }
440
441     IRegion getCurrentTextRegion(ISourceViewer viewer) {
442
443       int offset = getCurrentTextOffset(viewer);
444       if (offset == -1)
445         return null;
446
447       return null;
448       //                                IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
449       //                                if (input == null)
450       //                                        return null;
451       //      
452       //                                try {
453       //                                
454       //                                        IJavaElement[] elements= null;
455       //                                        synchronized (input) {
456       //                                                elements= ((ICodeAssist) input).codeSelect(offset, 0);
457       //                                        }
458       //                                
459       //                                        if (elements == null || elements.length == 0)
460       //                                                return null;
461       //                                        
462       //                                        return selectWord(viewer.getDocument(), offset);
463       //                                        
464       //                                } catch (JavaModelException e) {
465       //                                        return null;    
466       //                                }
467     }
468
469     private int getCurrentTextOffset(ISourceViewer viewer) {
470
471       try {
472         StyledText text = viewer.getTextWidget();
473         if (text == null || text.isDisposed())
474           return -1;
475
476         Display display = text.getDisplay();
477         Point absolutePosition = display.getCursorLocation();
478         Point relativePosition = text.toControl(absolutePosition);
479
480         int widgetOffset = text.getOffsetAtLocation(relativePosition);
481         if (viewer instanceof ITextViewerExtension3) {
482           ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
483           return extension.widgetOffset2ModelOffset(widgetOffset);
484         } else {
485           return widgetOffset + viewer.getVisibleRegion().getOffset();
486         }
487
488       } catch (IllegalArgumentException e) {
489         return -1;
490       }
491     }
492
493     private void highlightRegion(ISourceViewer viewer, IRegion region) {
494
495       if (region.equals(fActiveRegion))
496         return;
497
498       repairRepresentation();
499
500       StyledText text = viewer.getTextWidget();
501       if (text == null || text.isDisposed())
502         return;
503
504       // highlight region
505       int offset = 0;
506       int length = 0;
507
508       if (viewer instanceof ITextViewerExtension3) {
509         ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
510         IRegion widgetRange = extension.modelRange2WidgetRange(region);
511         if (widgetRange == null)
512           return;
513
514         offset = widgetRange.getOffset();
515         length = widgetRange.getLength();
516
517       } else {
518         offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
519         length = region.getLength();
520       }
521
522       StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
523       Color foregroundColor = fColor;
524       Color backgroundColor = oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
525       StyleRange styleRange = new StyleRange(offset, length, foregroundColor, backgroundColor);
526       text.setStyleRange(styleRange);
527
528       // underline
529       text.redrawRange(offset, length, true);
530
531       fActiveRegion = region;
532     }
533
534     private void activateCursor(ISourceViewer viewer) {
535       StyledText text = viewer.getTextWidget();
536       if (text == null || text.isDisposed())
537         return;
538       Display display = text.getDisplay();
539       if (fCursor == null)
540         fCursor = new Cursor(display, SWT.CURSOR_HAND);
541       text.setCursor(fCursor);
542     }
543
544     private void resetCursor(ISourceViewer viewer) {
545       StyledText text = viewer.getTextWidget();
546       if (text != null && !text.isDisposed())
547         text.setCursor(null);
548
549       if (fCursor != null) {
550         fCursor.dispose();
551         fCursor = null;
552       }
553     }
554
555     /*
556      * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
557      */
558     public void keyPressed(KeyEvent event) {
559
560       if (fActive) {
561         deactivate();
562         return;
563       }
564
565       if (event.keyCode != fKeyModifierMask) {
566         deactivate();
567         return;
568       }
569
570       fActive = true;
571
572       //                                removed for #25871                      
573       //
574       //                                ISourceViewer viewer= getSourceViewer();
575       //                                if (viewer == null)
576       //                                        return;
577       //                        
578       //                                IRegion region= getCurrentTextRegion(viewer);
579       //                                if (region == null)
580       //                                        return;
581       //                        
582       //                                highlightRegion(viewer, region);
583       //                                activateCursor(viewer);                                                                                         
584     }
585
586     /*
587      * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
588      */
589     public void keyReleased(KeyEvent event) {
590
591       if (!fActive)
592         return;
593
594       deactivate();
595     }
596
597     /*
598      * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
599      */
600     public void mouseDoubleClick(MouseEvent e) {
601     }
602     /*
603      * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
604      */
605     public void mouseDown(MouseEvent event) {
606
607       if (!fActive)
608         return;
609
610       if (event.stateMask != fKeyModifierMask) {
611         deactivate();
612         return;
613       }
614
615       if (event.button != 1) {
616         deactivate();
617         return;
618       }
619     }
620
621     /*
622      * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
623      */
624     public void mouseUp(MouseEvent e) {
625
626       if (!fActive)
627         return;
628
629       if (e.button != 1) {
630         deactivate();
631         return;
632       }
633
634       boolean wasActive = fCursor != null;
635
636       deactivate();
637
638       if (wasActive) {
639         IAction action = getAction("OpenEditor"); //$NON-NLS-1$
640         if (action != null)
641           action.run();
642       }
643     }
644
645     /*
646      * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
647      */
648     public void mouseMove(MouseEvent event) {
649
650       if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
651         deactivate();
652         return;
653       }
654
655       if (!fActive) {
656         if (event.stateMask != fKeyModifierMask)
657           return;
658         // modifier was already pressed
659         fActive = true;
660       }
661
662       ISourceViewer viewer = getSourceViewer();
663       if (viewer == null) {
664         deactivate();
665         return;
666       }
667
668       StyledText text = viewer.getTextWidget();
669       if (text == null || text.isDisposed()) {
670         deactivate();
671         return;
672       }
673
674       if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
675         deactivate();
676         return;
677       }
678
679       IRegion region = getCurrentTextRegion(viewer);
680       if (region == null || region.getLength() == 0) {
681         repairRepresentation();
682         return;
683       }
684
685       highlightRegion(viewer, region);
686       activateCursor(viewer);
687     }
688
689     /*
690      * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
691      */
692     public void focusGained(FocusEvent e) {
693     }
694
695     /*
696      * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
697      */
698     public void focusLost(FocusEvent event) {
699       deactivate();
700     }
701
702     /*
703      * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
704      */
705     public void documentAboutToBeChanged(DocumentEvent event) {
706       if (fActive && fActiveRegion != null) {
707         fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
708         try {
709           event.getDocument().addPosition(fRememberedPosition);
710         } catch (BadLocationException x) {
711           fRememberedPosition = null;
712         }
713       }
714     }
715
716     /*
717      * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
718      */
719     public void documentChanged(DocumentEvent event) {
720       if (fRememberedPosition != null && !fRememberedPosition.isDeleted()) {
721         event.getDocument().removePosition(fRememberedPosition);
722         fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
723       }
724       fRememberedPosition = null;
725
726       ISourceViewer viewer = getSourceViewer();
727       if (viewer != null) {
728         StyledText widget = viewer.getTextWidget();
729         if (widget != null && !widget.isDisposed()) {
730           widget.getDisplay().asyncExec(new Runnable() {
731             public void run() {
732               deactivate();
733             }
734           });
735         }
736       }
737     }
738
739     /*
740      * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
741      */
742     public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
743       if (oldInput == null)
744         return;
745       deactivate();
746       oldInput.removeDocumentListener(this);
747     }
748
749     /*
750      * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
751      */
752     public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
753       if (newInput == null)
754         return;
755       newInput.addDocumentListener(this);
756     }
757
758     /*
759      * @see PaintListener#paintControl(PaintEvent)
760      */
761     public void paintControl(PaintEvent event) {
762       if (fActiveRegion == null)
763         return;
764
765       ISourceViewer viewer = getSourceViewer();
766       if (viewer == null)
767         return;
768
769       StyledText text = viewer.getTextWidget();
770       if (text == null || text.isDisposed())
771         return;
772
773       int offset = 0;
774       int length = 0;
775
776       if (viewer instanceof ITextViewerExtension3) {
777
778         ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
779         IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
780         if (widgetRange == null)
781           return;
782
783         offset = widgetRange.getOffset();
784         length = widgetRange.getLength();
785
786       } else {
787
788         IRegion region = viewer.getVisibleRegion();
789         if (!includes(region, fActiveRegion))
790           return;
791
792         offset = fActiveRegion.getOffset() - region.getOffset();
793         length = fActiveRegion.getLength();
794       }
795
796       // support for bidi
797       Point minLocation = getMinimumLocation(text, offset, length);
798       Point maxLocation = getMaximumLocation(text, offset, length);
799
800       int x1 = minLocation.x;
801       int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
802       int y = minLocation.y + text.getLineHeight() - 1;
803
804       GC gc = event.gc;
805       if (fColor != null && !fColor.isDisposed())
806         gc.setForeground(fColor);
807       gc.drawLine(x1, y, x2, y);
808     }
809
810     private boolean includes(IRegion region, IRegion position) {
811       return position.getOffset() >= region.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
812     }
813
814     private Point getMinimumLocation(StyledText text, int offset, int length) {
815       Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
816
817       for (int i = 0; i <= length; i++) {
818         Point location = text.getLocationAtOffset(offset + i);
819
820         if (location.x < minLocation.x)
821           minLocation.x = location.x;
822         if (location.y < minLocation.y)
823           minLocation.y = location.y;
824       }
825
826       return minLocation;
827     }
828
829     private Point getMaximumLocation(StyledText text, int offset, int length) {
830       Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
831
832       for (int i = 0; i <= length; i++) {
833         Point location = text.getLocationAtOffset(offset + i);
834
835         if (location.x > maxLocation.x)
836           maxLocation.x = location.x;
837         if (location.y > maxLocation.y)
838           maxLocation.y = location.y;
839       }
840
841       return maxLocation;
842     }
843   };
844
845   /**
846    * This action dispatches into two behaviours: If there is no current text
847    * hover, the javadoc is displayed using information presenter. If there is
848    * a current text hover, it is converted into a information presenter in
849    * order to make it sticky.
850    */
851   class InformationDispatchAction extends TextEditorAction {
852
853     /** The wrapped text operation action. */
854     private final TextOperationAction fTextOperationAction;
855
856     /**
857      * Creates a dispatch action.
858      */
859     public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
860       super(resourceBundle, prefix, PHPEditor.this);
861       if (textOperationAction == null)
862         throw new IllegalArgumentException();
863       fTextOperationAction = textOperationAction;
864     }
865
866     /*
867      * @see org.eclipse.jface.action.IAction#run()
868      */
869     public void run() {
870
871       ISourceViewer sourceViewer = getSourceViewer();
872       if (sourceViewer == null) {
873         fTextOperationAction.run();
874         return;
875       }
876
877       if (!(sourceViewer instanceof ITextViewerExtension2)) {
878         fTextOperationAction.run();
879         return;
880       }
881
882       ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
883
884       // does a text hover exist?
885       ITextHover textHover = textViewerExtension2.getCurrentTextHover();
886       if (textHover == null) {
887         fTextOperationAction.run();
888         return;
889       }
890
891       Point hoverEventLocation = textViewerExtension2.getHoverEventLocation();
892       int offset = computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
893       if (offset == -1) {
894         fTextOperationAction.run();
895         return;
896       }
897
898       try {
899         // get the text hover content
900         IDocument document = sourceViewer.getDocument();
901         String contentType = document.getContentType(offset);
902
903         final IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
904         if (hoverRegion == null)
905           return;
906
907         final String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);
908
909         // with information provider
910         IInformationProvider informationProvider = new IInformationProvider() {
911           /*
912            * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
913            */
914           public IRegion getSubject(ITextViewer textViewer, int offset) {
915             return hoverRegion;
916           }
917           /*
918            * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
919            */
920           public String getInformation(ITextViewer textViewer, IRegion subject) {
921             return hoverInfo;
922           }
923         };
924
925         fInformationPresenter.setOffset(offset);
926         fInformationPresenter.setInformationProvider(informationProvider, contentType);
927         fInformationPresenter.showInformation();
928
929       } catch (BadLocationException e) {
930       }
931     }
932
933     // modified version from TextViewer
934     private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
935
936       StyledText styledText = textViewer.getTextWidget();
937       IDocument document = textViewer.getDocument();
938
939       if (document == null)
940         return -1;
941
942       try {
943         int widgetLocation = styledText.getOffsetAtLocation(new Point(x, y));
944         if (textViewer instanceof ITextViewerExtension3) {
945           ITextViewerExtension3 extension = (ITextViewerExtension3) textViewer;
946           return extension.widgetOffset2ModelOffset(widgetLocation);
947         } else {
948           IRegion visibleRegion = textViewer.getVisibleRegion();
949           return widgetLocation + visibleRegion.getOffset();
950         }
951       } catch (IllegalArgumentException e) {
952         return -1;
953       }
954
955     }
956   };
957
958 //  static protected class AnnotationAccess implements IAnnotationAccess {
959 //    /*
960 //     * @see org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
961 //     */
962 //    public Object getType(Annotation annotation) {
963 //      if (annotation instanceof IJavaAnnotation) {
964 //        IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
965 //   //     if (javaAnnotation.isRelevant())
966 //   //       return javaAnnotation.getAnnotationType();
967 //      }
968 //      return null;
969 //    }
970 //
971 //    /*
972 //     * @see org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
973 //     */
974 //    public boolean isMultiLine(Annotation annotation) {
975 //      return true;
976 //    }
977 //
978 //    /*
979 //     * @see org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
980 //     */
981 //    public boolean isTemporary(Annotation annotation) {
982 //      if (annotation instanceof IJavaAnnotation) {
983 //        IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
984 //        if (javaAnnotation.isRelevant())
985 //          return javaAnnotation.isTemporary();
986 //      }
987 //      return false;
988 //    }
989 //  };
990
991   private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
992     /*
993      * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
994      */
995     public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
996       handlePreferencePropertyChanged(event);
997     }
998   };
999   
1000   /**
1001          * Finds and marks occurrence annotations.
1002          * 
1003          * @since 3.0
1004          */
1005         class OccurrencesFinderJob extends Job implements IDocumentListener {
1006                 
1007                 private IDocument fDocument;
1008                 private boolean fCancelled= false;
1009                 private IProgressMonitor fProgressMonitor;
1010                 private Position[] fPositions;
1011                 
1012                 public OccurrencesFinderJob(IDocument document, Position[] positions) {
1013                         super("Occurrences Marker"); //$NON-NLS-1$
1014                         fDocument= document;
1015                         fPositions= positions;
1016                         fDocument.addDocumentListener(this);
1017                 }
1018                 
1019                 private boolean isCancelled() {
1020                         return fCancelled || fProgressMonitor.isCanceled();
1021                 }
1022                 
1023                 /*
1024                  * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
1025                  */
1026                 public IStatus run(IProgressMonitor progressMonitor) {
1027                         
1028                         fProgressMonitor= progressMonitor;
1029                         
1030                         try {
1031                                 
1032                                 if (isCancelled())
1033                                         return Status.CANCEL_STATUS;
1034                                 
1035                                 ITextViewer textViewer= getViewer(); 
1036                                 if (textViewer == null)
1037                                         return Status.CANCEL_STATUS;
1038                                 
1039                                 IDocument document= textViewer.getDocument();
1040                                 if (document == null)
1041                                         return Status.CANCEL_STATUS;
1042                                 
1043                                 IDocumentProvider documentProvider= getDocumentProvider();
1044                                 if (documentProvider == null)
1045                                         return Status.CANCEL_STATUS;
1046                         
1047                                 IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput());
1048                                 if (annotationModel == null)
1049                                         return Status.CANCEL_STATUS;
1050                                 
1051                                 // Add occurrence annotations
1052                                 int length= fPositions.length;
1053                                 Map annotationMap= new HashMap(length);
1054                                 for (int i= 0; i < length; i++) {
1055                                         
1056                                         if (isCancelled())
1057                                                 return Status.CANCEL_STATUS; 
1058                                         
1059                                         String message;
1060                                         Position position= fPositions[i];
1061                                         
1062                                         // Create & add annotation
1063                                         try {
1064                                                 message= document.get(position.offset, position.length);
1065                                         } catch (BadLocationException ex) {
1066                                                 // Skip this match
1067                                                 continue;
1068                                         }
1069                                         annotationMap.put(
1070                                                         new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
1071                                                         position);
1072                                 }
1073                                 
1074                                 if (isCancelled())
1075                                         return Status.CANCEL_STATUS;
1076                                 
1077                                 synchronized (annotationModel) {
1078                                         if (annotationModel instanceof IAnnotationModelExtension) {
1079                                                 ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
1080                                         } else {
1081                                                 removeOccurrenceAnnotations();
1082                                                 Iterator iter= annotationMap.entrySet().iterator();
1083                                                 while (iter.hasNext()) {
1084                                                         Map.Entry mapEntry= (Map.Entry)iter.next(); 
1085                                                         annotationModel.addAnnotation((Annotation)mapEntry.getKey(), (Position)mapEntry.getValue());
1086                                                 }
1087                                         }
1088                                         fOccurrenceAnnotations= (Annotation[])annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
1089                                 }
1090                         } finally {
1091                                 fDocument.removeDocumentListener(this);
1092                         }
1093                         return Status.OK_STATUS;
1094                 }
1095
1096                 /*
1097                  * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1098                  */
1099                 public void documentAboutToBeChanged(DocumentEvent event) {
1100                         fCancelled= true;
1101                 }
1102
1103                 /*
1104                  * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1105                  */
1106                 public void documentChanged(DocumentEvent event) {
1107                 }
1108         }
1109         
1110         
1111         /**
1112          * Holds the current occurrence annotations.
1113          * @since 3.0
1114          */
1115   private Annotation[] fOccurrenceAnnotations= null;
1116   
1117   private Job fOccurrencesFinderJob;
1118         
1119   /** Preference key for showing the line number ruler */
1120 //  private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
1121   /** Preference key for the foreground color of the line numbers */
1122  // private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
1123   /** Preference key for the link color */
1124   private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
1125   /** Preference key for compiler task tags */
1126   private final static String COMPILER_TASK_TAGS = PHPCore.COMPILER_TASK_TAGS;
1127
1128   // protected PHPActionGroup fActionGroups;
1129   //  /** The outline page */
1130   //  private AbstractContentOutlinePage fOutlinePage;
1131   /** The outline page */
1132   protected JavaOutlinePage fOutlinePage;
1133   /** Outliner context menu Id */
1134   protected String fOutlinerContextMenuId;
1135   /** Indicates whether this editor should react on outline page selection changes */
1136   private int fIgnoreOutlinePageSelection;
1137   
1138         /** The outline page selection updater */
1139         private OutlinePageSelectionUpdater fUpdater;
1140   //  protected PHPSyntaxParserThread fValidationThread = null;
1141
1142   // private IPreferenceStore fPHPPrefStore;
1143   /** The selection changed listener */
1144   protected ISelectionChangedListener fSelectionChangedListener = new SelectionChangedListener();
1145
1146   /** The editor's bracket matcher */
1147   private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS);
1148
1149
1150   /** The line number ruler column */
1151 //  private LineNumberRulerColumn fLineNumberRulerColumn;
1152   /** This editor's encoding support */
1153   private DefaultEncodingSupport fEncodingSupport;
1154   /** The mouse listener */
1155   private MouseClickListener fMouseListener;
1156
1157   protected CompositeActionGroup fActionGroups;
1158   /** The standard action groups added to the menu */
1159   protected GenerateActionGroup fGenerateActionGroup;
1160   protected CompositeActionGroup fContextMenuGroup;
1161
1162   /** The information presenter. */
1163   private InformationPresenter fInformationPresenter;
1164   /** The annotation access */
1165 //  protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
1166   /** The overview ruler */
1167   protected OverviewRuler isOverviewRulerVisible;
1168   /** The source viewer decoration support */
1169   //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
1170   /** The overview ruler */
1171   //protected OverviewRuler fOverviewRuler;
1172
1173   /** The preference property change listener for java core. */
1174   private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
1175   /**
1176    * Returns the most narrow java element including the given offset
1177    * 
1178    * @param offset the offset inside of the requested element
1179    */
1180   abstract protected IJavaElement getElementAt(int offset);
1181
1182   /**
1183    * Returns the java element of this editor's input corresponding to the given IJavaElement
1184    */
1185   abstract protected IJavaElement getCorrespondingElement(IJavaElement element);
1186   /**
1187          * Sets the input of the editor's outline page.
1188          */
1189   abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input);
1190
1191   /**
1192    * Default constructor.
1193    */
1194   public PHPEditor() {
1195     super();
1196     JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1197     setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this));
1198     setRangeIndicator(new DefaultRangeIndicator());
1199     setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
1200
1201     // don't activate this scope without synchronizing plugin.xml !!!
1202     //    setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
1203
1204         if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
1205           fUpdater= new OutlinePageSelectionUpdater();
1206   }
1207   //
1208   //    /**
1209   //     * @see IMember#getCompilationUnit()
1210   //     */
1211   //    public ICompilationUnit getCompilationUnit() {
1212   //            return this; 
1213   //    }
1214   //    /**
1215   //     * @see org.phpeclipse.phpdt.internal.compiler.env.ICompilationUnit#getContents()
1216   //     */
1217   //    public char[] getContents() {
1218   //            IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
1219   //    
1220   //            return doc.get().toCharArray();
1221   //    }
1222   /*
1223    * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
1224    */
1225   protected void updatePropertyDependentActions() {
1226     super.updatePropertyDependentActions();
1227     if (fEncodingSupport != null)
1228       fEncodingSupport.reset();
1229   }
1230
1231   /*
1232    * Update the hovering behavior depending on the preferences.
1233    */
1234   private void updateHoverBehavior() {
1235     SourceViewerConfiguration configuration = getSourceViewerConfiguration();
1236     String[] types = configuration.getConfiguredContentTypes(getSourceViewer());
1237
1238     for (int i = 0; i < types.length; i++) {
1239
1240       String t = types[i];
1241
1242       int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
1243
1244       ISourceViewer sourceViewer = getSourceViewer();
1245       if (sourceViewer instanceof ITextViewerExtension2) {
1246         if (stateMasks != null) {
1247           for (int j = 0; j < stateMasks.length; j++) {
1248             int stateMask = stateMasks[j];
1249             ITextHover textHover = configuration.getTextHover(sourceViewer, t, stateMask);
1250             ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, stateMask);
1251           }
1252         } else {
1253           ITextHover textHover = configuration.getTextHover(sourceViewer, t);
1254           ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
1255         }
1256       } else
1257         sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t);
1258     }
1259   }
1260
1261   public void updatedTitleImage(Image image) {
1262     setTitleImage(image);
1263   }
1264   /*
1265    * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
1266    */
1267   public Object getViewPartInput() {
1268     return getEditorInput().getAdapter(IResource.class);
1269   }
1270   /*
1271    * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
1272    */
1273   protected void doSetSelection(ISelection selection) {
1274     super.doSetSelection(selection);
1275     synchronizeOutlinePageSelection();
1276   }
1277   /*
1278    * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.
1279    * widgets.Composite)
1280    */
1281   public void createPartControl(Composite parent) {
1282     super.createPartControl(parent);
1283
1284     //fSourceViewerDecorationSupport.install(getPreferenceStore());
1285
1286     Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
1287     preferences.addPropertyChangeListener(fPropertyChangeListener);
1288
1289     IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
1290       public IInformationControl createInformationControl(Shell parent) {
1291         boolean cutDown = false;
1292         int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
1293         return new DefaultInformationControl(parent, SWT.RESIZE, style, new HTMLTextPresenter(cutDown));
1294       }
1295     };
1296
1297     fInformationPresenter = new InformationPresenter(informationControlCreator);
1298     fInformationPresenter.setSizeConstraints(60, 10, true, true);
1299     fInformationPresenter.install(getSourceViewer());
1300
1301   }
1302
1303   /**
1304    * Returns this document's complete text.
1305    *
1306    * @return the document's complete text
1307    */
1308   public String get() {
1309     IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
1310     return doc.get();
1311   }
1312
1313   /**
1314          * Sets the outliner's context menu ID.
1315          */
1316   protected void setOutlinerContextMenuId(String menuId) {
1317     fOutlinerContextMenuId = menuId;
1318   }
1319
1320   /**
1321    *  Returns the standard action group of this editor.
1322    */
1323   protected ActionGroup getActionGroup() {
1324     return fActionGroups;
1325   }
1326
1327   //  public JavaOutlinePage getfOutlinePage() {
1328   //    return fOutlinePage;
1329   //  }
1330
1331   /** The <code>PHPEditor</code> implementation of this 
1332    * <code>AbstractTextEditor</code> method extend the 
1333    * actions to add those specific to the receiver
1334    */
1335   protected void createActions() {
1336     super.createActions();
1337
1338     ResourceAction resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
1339     resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
1340     resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
1341     setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
1342     //                                          WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
1343
1344     Action action;
1345
1346     setAction(
1347       "ContentAssistTip",
1348       new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
1349
1350     action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$
1351     action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
1352     setAction("ContentAssistProposal", action); //$NON-NLS-1$
1353     markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
1354     //  WorkbenchHelp.setHelp(action, IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
1355
1356     fEncodingSupport = new DefaultEncodingSupport();
1357     fEncodingSupport.initialize(this);
1358
1359     action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
1360     action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
1361     setAction("Comment", action); //$NON-NLS-1$
1362     markAsStateDependentAction("Comment", true); //$NON-NLS-1$
1363     //          WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
1364
1365     action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
1366     action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
1367     setAction("Uncomment", action); //$NON-NLS-1$
1368     markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
1369     //          WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
1370
1371     action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
1372     action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
1373     setAction("Format", action); //$NON-NLS-1$
1374     markAsStateDependentAction("Format", true); //$NON-NLS-1$
1375     markAsSelectionDependentAction("Format", true); //$NON-NLS-1$               
1376     //  WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
1377
1378     action = new GotoMatchingBracketAction(this);
1379     action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
1380     setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
1381
1382     fGenerateActionGroup = new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
1383
1384     fActionGroups = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
1385
1386     // We have to keep the context menu group separate to have better control over positioning
1387     fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
1388     //      rg, 
1389     //      new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)});
1390
1391         // add annotation actions
1392         action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
1393         setAction("AnnotationAction", action); //$NON-NLS-1$
1394   }
1395
1396   /** The <code>PHPEditor</code> implementation of this 
1397    * <code>AbstractTextEditor</code> method performs any extra 
1398    * disposal actions required by the php editor.
1399    */
1400   public void dispose() {
1401     //   PHPEditorEnvironment.disconnect(this);
1402     if (fOutlinePage != null)
1403       fOutlinePage.setInput(null);
1404
1405     if (fActionGroups != null)
1406       fActionGroups.dispose();
1407
1408     if (isBrowserLikeLinks())
1409       disableBrowserLikeLinks();
1410
1411     if (fEncodingSupport != null) {
1412       fEncodingSupport.dispose();
1413       fEncodingSupport = null;
1414     }
1415
1416     if (fPropertyChangeListener != null) {
1417       Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
1418       preferences.removePropertyChangeListener(fPropertyChangeListener);
1419       fPropertyChangeListener = null;
1420     }
1421
1422 //    if (fSourceViewerDecorationSupport != null) {
1423 //      fSourceViewerDecorationSupport.dispose();
1424 //      fSourceViewerDecorationSupport = null;
1425 //    }
1426
1427     if (fBracketMatcher != null) {
1428       fBracketMatcher.dispose();
1429       fBracketMatcher = null;
1430     }
1431     super.dispose();
1432   }
1433
1434   /** The <code>PHPEditor</code> implementation of this 
1435    * <code>AbstractTextEditor</code> method performs any extra 
1436    * revert behavior required by the php editor.
1437    */
1438   //  public void doRevertToSaved() {
1439   //    super.doRevertToSaved();
1440   //    if (fOutlinePage != null)
1441   //      fOutlinePage.update();
1442   //  }
1443
1444   /** The <code>PHPEditor</code> implementation of this 
1445    * <code>AbstractTextEditor</code> method performs any extra 
1446    * save behavior required by the php editor.
1447    */
1448   //  public void doSave(IProgressMonitor monitor) {
1449   //    super.doSave(monitor);
1450   // compile or not, according to the user preferences
1451   // IPreferenceStore store = getPreferenceStore(); 
1452
1453   // the parse on save was changed to the eclipse "builders" concept
1454   //    if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
1455   //      IAction a = PHPParserAction.getInstance();
1456   //      if (a != null)
1457   //        a.run();
1458   //    }
1459
1460   //    if (SWT.getPlatform().equals("win32")) {
1461   //      IAction a = ShowExternalPreviewAction.getInstance();
1462   //      if (a != null)
1463   //        a.run();
1464   //    }
1465   //    if (fOutlinePage != null)
1466   //      fOutlinePage.update();
1467   //  }
1468
1469   /** The <code>PHPEditor</code> implementation of this 
1470    * <code>AbstractTextEditor</code> method performs any extra 
1471    * save as behavior required by the php editor.
1472    */
1473   //  public void doSaveAs() {
1474   //    super.doSaveAs();
1475   //    if (fOutlinePage != null)
1476   //      fOutlinePage.update();
1477   //  }
1478   /*
1479          * @see StatusTextEditor#getStatusHeader(IStatus)
1480          */
1481   protected String getStatusHeader(IStatus status) {
1482     if (fEncodingSupport != null) {
1483       String message = fEncodingSupport.getStatusHeader(status);
1484       if (message != null)
1485         return message;
1486     }
1487     return super.getStatusHeader(status);
1488   }
1489
1490   /*
1491    * @see StatusTextEditor#getStatusBanner(IStatus)
1492    */
1493   protected String getStatusBanner(IStatus status) {
1494     if (fEncodingSupport != null) {
1495       String message = fEncodingSupport.getStatusBanner(status);
1496       if (message != null)
1497         return message;
1498     }
1499     return super.getStatusBanner(status);
1500   }
1501
1502   /*
1503    * @see StatusTextEditor#getStatusMessage(IStatus)
1504    */
1505   protected String getStatusMessage(IStatus status) {
1506     if (fEncodingSupport != null) {
1507       String message = fEncodingSupport.getStatusMessage(status);
1508       if (message != null)
1509         return message;
1510     }
1511     return super.getStatusMessage(status);
1512   }
1513   /** The <code>PHPEditor</code> implementation of this 
1514    * <code>AbstractTextEditor</code> method performs sets the 
1515    * input of the outline page after AbstractTextEditor has set input.
1516    */
1517   //  protected void doSetInput(IEditorInput input) throws CoreException {
1518   //    super.doSetInput(input);
1519   //
1520   //    if (fEncodingSupport != null)
1521   //      fEncodingSupport.reset();
1522   //    if (fOutlinePage != null)
1523   //      fOutlinePage.setInput(input);
1524   //    //              setOutlinePageInput(fOutlinePage, input);
1525   //  } 
1526   protected void doSetInput(IEditorInput input) throws CoreException {
1527     super.doSetInput(input);
1528     if (fEncodingSupport != null)
1529       fEncodingSupport.reset();
1530     setOutlinePageInput(fOutlinePage, input);
1531   }
1532   /*
1533    * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
1534    */
1535   //  public Object getViewPartInput() {
1536   //    return getEditorInput().getAdapter(IFile.class);
1537   //  }
1538
1539   /** The <code>PHPEditor</code> implementation of this 
1540    * <code>AbstractTextEditor</code> method adds any 
1541    * PHPEditor specific entries.
1542    */
1543   public void editorContextMenuAboutToShow(MenuManager menu) {
1544     super.editorContextMenuAboutToShow(menu);
1545     menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, new Separator(IContextMenuConstants.GROUP_OPEN));
1546     menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));
1547
1548     ActionContext context = new ActionContext(getSelectionProvider().getSelection());
1549     fContextMenuGroup.setContext(context);
1550     fContextMenuGroup.fillContextMenu(menu);
1551     fContextMenuGroup.setContext(null);
1552     //    addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$
1553     //
1554     //    ActionContext context =
1555     //      new ActionContext(getSelectionProvider().getSelection());
1556     //    fContextMenuGroup.setContext(context);
1557     //    fContextMenuGroup.fillContextMenu(menu);
1558     //    fContextMenuGroup.setContext(null);
1559   }
1560
1561   /**
1562    * Creates the outline page used with this editor.
1563    */
1564   protected JavaOutlinePage createOutlinePage() {
1565
1566     //    AbstractContentOutlinePage page = new PHPContentOutlinePage(getDocumentProvider(), this);
1567     //
1568     //    page.addSelectionChangedListener(fSelectionChangedListener);
1569     //    //    setOutlinePageInput(page, getEditorInput());
1570     //    if (getEditorInput() != null)
1571     //      fOutlinePage.setInput(getEditorInput());
1572     //
1573     //    return page;
1574     JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this);
1575
1576     page.addSelectionChangedListener(fSelectionChangedListener);
1577     setOutlinePageInput(page, getEditorInput());
1578
1579     return page;
1580   }
1581
1582   /**
1583    * Informs the editor that its outliner has been closed.
1584    */
1585   public void outlinePageClosed() {
1586     if (fOutlinePage != null) {
1587       fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
1588       fOutlinePage = null;
1589       resetHighlightRange();
1590     }
1591   }
1592   /**
1593    * Synchronizes the outliner selection with the actual cursor
1594    * position in the editor.
1595    */
1596   public void synchronizeOutlinePageSelection() {
1597
1598     //          if (isEditingScriptRunning())
1599     //                  return;
1600
1601     ISourceViewer sourceViewer = getSourceViewer();
1602     if (sourceViewer == null || fOutlinePage == null)
1603       return;
1604
1605     StyledText styledText = sourceViewer.getTextWidget();
1606     if (styledText == null)
1607       return;
1608
1609     int caret = 0;
1610     if (sourceViewer instanceof ITextViewerExtension3) {
1611       ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
1612       caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
1613     } else {
1614       int offset = sourceViewer.getVisibleRegion().getOffset();
1615       caret = offset + styledText.getCaretOffset();
1616     }
1617
1618     IJavaElement element = getElementAt(caret);
1619     if (element instanceof ISourceReference) {
1620       fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
1621       fOutlinePage.select((ISourceReference) element);
1622       fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
1623     }
1624   }
1625   protected void updateStateDependentActions() {
1626     super.updateStateDependentActions();
1627     fGenerateActionGroup.editorStateChanged();
1628   }
1629
1630   protected void setSelection(ISourceReference reference, boolean moveCursor) {
1631
1632     ISelection selection = getSelectionProvider().getSelection();
1633     if (selection instanceof TextSelection) {
1634       TextSelection textSelection = (TextSelection) selection;
1635       if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
1636         markInNavigationHistory();
1637     }
1638
1639     if (reference != null) {
1640
1641       StyledText textWidget = null;
1642
1643       ISourceViewer sourceViewer = getSourceViewer();
1644       if (sourceViewer != null)
1645         textWidget = sourceViewer.getTextWidget();
1646
1647       if (textWidget == null)
1648         return;
1649
1650       try {
1651
1652         ISourceRange range = reference.getSourceRange();
1653         if (range == null)
1654           return;
1655
1656         int offset = range.getOffset();
1657         int length = range.getLength();
1658
1659         if (offset < 0 || length < 0)
1660           return;
1661
1662         textWidget.setRedraw(false);
1663
1664         setHighlightRange(offset, length, moveCursor);
1665
1666         if (!moveCursor)
1667           return;
1668
1669         offset = -1;
1670         length = -1;
1671
1672         if (reference instanceof IMember) {
1673           range = ((IMember) reference).getNameRange();
1674           if (range != null) {
1675             offset = range.getOffset();
1676             length = range.getLength();
1677           }
1678         }
1679         //                                      else if (reference instanceof IImportDeclaration) {
1680         //                                              String name= ((IImportDeclaration) reference).getElementName();
1681         //                                              if (name != null && name.length() > 0) {
1682         //                                                      String content= reference.getSource();
1683         //                                                      if (content != null) {
1684         //                                                              offset= range.getOffset() + content.indexOf(name);
1685         //                                                              length= name.length();
1686         //                                                      }
1687         //                                              }
1688         //                                      } else if (reference instanceof IPackageDeclaration) {
1689         //                                              String name= ((IPackageDeclaration) reference).getElementName();
1690         //                                              if (name != null && name.length() > 0) {
1691         //                                                      String content= reference.getSource();
1692         //                                                      if (content != null) {
1693         //                                                              offset= range.getOffset() + content.indexOf(name);
1694         //                                                              length= name.length();
1695         //                                                      }
1696         //                                              }
1697         //                                      }
1698
1699         if (offset > -1 && length > 0) {
1700           sourceViewer.revealRange(offset, length);
1701           sourceViewer.setSelectedRange(offset, length);
1702         }
1703
1704       } catch (JavaModelException x) {
1705       } catch (IllegalArgumentException x) {
1706       } finally {
1707         if (textWidget != null)
1708           textWidget.setRedraw(true);
1709       }
1710
1711     } else if (moveCursor) {
1712       resetHighlightRange();
1713     }
1714
1715     markInNavigationHistory();
1716   }
1717
1718   public void setSelection(IJavaElement element) {
1719
1720     if (element == null || element instanceof ICompilationUnit) { // || element instanceof IClassFile) {
1721       /*
1722        * If the element is an ICompilationUnit this unit is either the input
1723        * of this editor or not being displayed. In both cases, nothing should
1724        * happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
1725        */
1726       return;
1727     }
1728
1729     IJavaElement corresponding = getCorrespondingElement(element);
1730     if (corresponding instanceof ISourceReference) {
1731       ISourceReference reference = (ISourceReference) corresponding;
1732       // set hightlight range
1733       setSelection(reference, true);
1734       // set outliner selection
1735       if (fOutlinePage != null) {
1736         fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
1737         fOutlinePage.select(reference);
1738         fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
1739       }
1740     }
1741   }
1742
1743         public synchronized void editingScriptStarted() {
1744                 ++ fIgnoreOutlinePageSelection;
1745         }
1746         
1747         public synchronized void editingScriptEnded() {
1748                 -- fIgnoreOutlinePageSelection;
1749         }
1750         
1751         public synchronized boolean isEditingScriptRunning() {
1752                 return (fIgnoreOutlinePageSelection > 0);
1753         }
1754         
1755   /** The <code>PHPEditor</code> implementation of this 
1756    * <code>AbstractTextEditor</code> method performs gets
1757    * the java content outline page if request is for a an 
1758    * outline page.
1759    */
1760   public Object getAdapter(Class required) {
1761
1762     if (IContentOutlinePage.class.equals(required)) {
1763       if (fOutlinePage == null)
1764         fOutlinePage = createOutlinePage();
1765       return fOutlinePage;
1766     }
1767
1768     if (IEncodingSupport.class.equals(required))
1769       return fEncodingSupport;
1770
1771     if (required == IShowInTargetList.class) {
1772       return new IShowInTargetList() {
1773         public String[] getShowInTargetIds() {
1774           return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
1775         }
1776
1777       };
1778     }
1779
1780     return super.getAdapter(required);
1781   }
1782   //  public Object getAdapter(Class required) {
1783   //    if (IContentOutlinePage.class.equals(required)) {
1784   //      if (fOutlinePage == null) {
1785   //        fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
1786   //        if (getEditorInput() != null)
1787   //          fOutlinePage.setInput(getEditorInput());
1788   //      }
1789   //      return fOutlinePage;
1790   //    }
1791   //
1792   //    if (IEncodingSupport.class.equals(required))
1793   //      return fEncodingSupport;
1794   //
1795   //    return super.getAdapter(required);
1796   //  }
1797
1798   protected void doSelectionChanged(SelectionChangedEvent event) {
1799     ISourceReference reference = null;
1800
1801     ISelection selection = event.getSelection();
1802     Iterator iter = ((IStructuredSelection) selection).iterator();
1803     while (iter.hasNext()) {
1804       Object o = iter.next();
1805       if (o instanceof ISourceReference) {
1806         reference = (ISourceReference) o;
1807         break;
1808       }
1809     }
1810
1811     if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
1812       PHPeclipsePlugin.getActivePage().bringToTop(this);
1813
1814     try {
1815       editingScriptStarted();
1816       setSelection(reference, !isActivePart());
1817     } finally {
1818       editingScriptEnded();
1819     }
1820   }
1821   /*
1822          * @see AbstractTextEditor#adjustHighlightRange(int, int)
1823          */
1824   protected void adjustHighlightRange(int offset, int length) {
1825
1826     try {
1827
1828       IJavaElement element = getElementAt(offset);
1829       while (element instanceof ISourceReference) {
1830         ISourceRange range = ((ISourceReference) element).getSourceRange();
1831         if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) {
1832           setHighlightRange(range.getOffset(), range.getLength(), true);
1833           if (fOutlinePage != null) {
1834             fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
1835             fOutlinePage.select((ISourceReference) element);
1836             fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
1837           }
1838           return;
1839         }
1840         element = element.getParent();
1841       }
1842
1843     } catch (JavaModelException x) {
1844       PHPeclipsePlugin.log(x.getStatus());
1845     }
1846
1847     resetHighlightRange();
1848   }
1849   protected boolean isActivePart() {
1850     IWorkbenchWindow window = getSite().getWorkbenchWindow();
1851     IPartService service = window.getPartService();
1852     IWorkbenchPart part = service.getActivePart();
1853     return part != null && part.equals(this);
1854   }
1855
1856
1857   //  public void openContextHelp() {
1858   //    IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
1859   //    ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
1860   //    int pos = selection.getOffset();
1861   //    String word = getFunctionName(doc, pos);
1862   //    openContextHelp(word);
1863   //  }
1864   //
1865   //  private void openContextHelp(String word) {
1866   //    open(word);
1867   //  }
1868   //
1869   //  public static void open(String word) {
1870   //    IHelp help = WorkbenchHelp.getHelpSupport();
1871   //    if (help != null) {
1872   //      IHelpResource helpResource = new PHPFunctionHelpResource(word);
1873   //      WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
1874   //    } else {
1875   //      //   showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
1876   //    }
1877   //  }
1878
1879   //    private String getFunctionName(IDocument doc, int pos) {
1880   //            Point word = PHPWordExtractor.findWord(doc, pos);
1881   //            if (word != null) {
1882   //                    try {
1883   //                            return doc.get(word.x, word.y).replace('_', '-');
1884   //                    } catch (BadLocationException e) {
1885   //                    }
1886   //            }
1887   //            return "";
1888   //    }
1889
1890   /*
1891    * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1892    */
1893   protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1894
1895     try {
1896
1897       ISourceViewer sourceViewer = getSourceViewer();
1898       if (sourceViewer == null)
1899         return;
1900
1901       String property = event.getProperty();
1902
1903       if (PreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
1904         Object value = event.getNewValue();
1905         if (value instanceof Integer) {
1906           sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
1907         } else if (value instanceof String) {
1908           sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
1909         }
1910         return;
1911       }
1912       
1913 //      if (OVERVIEW_RULER.equals(property)) {
1914 //        if (isOverviewRulerVisible())
1915 //          showOverviewRuler();
1916 //        else
1917 //          hideOverviewRuler();
1918 //        return;
1919 //      }
1920
1921 //      if (LINE_NUMBER_RULER.equals(property)) {
1922 //        if (isLineNumberRulerVisible())
1923 //          showLineNumberRuler();
1924 //        else
1925 //          hideLineNumberRuler();
1926 //        return;
1927 //      }
1928
1929 //      if (fLineNumberRulerColumn != null
1930 //        && (LINE_NUMBER_COLOR.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
1931 //
1932 //        initializeLineNumberRulerColumn(fLineNumberRulerColumn);
1933 //      }
1934
1935       if (isJavaEditorHoverProperty(property))
1936         updateHoverBehavior();
1937
1938       if (BROWSER_LIKE_LINKS.equals(property)) {
1939         if (isBrowserLikeLinks())
1940           enableBrowserLikeLinks();
1941         else
1942           disableBrowserLikeLinks();
1943         return;
1944       }
1945
1946     } finally {
1947       super.handlePreferenceStoreChanged(event);
1948     }
1949   }
1950
1951   //  /*
1952   //     * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1953   //     */
1954   //  protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1955   //
1956   //    try {
1957   //
1958   //      ISourceViewer sourceViewer = getSourceViewer();
1959   //      if (sourceViewer == null)
1960   //        return;
1961   //
1962   //      String property = event.getProperty();
1963   //
1964   //      //      if (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
1965   //      //        Object value= event.getNewValue();
1966   //      //        if (value instanceof Integer) {
1967   //      //          sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
1968   //      //        } else if (value instanceof String) {
1969   //      //          sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
1970   //      //        }
1971   //      //        return;
1972   //      //      }
1973   //
1974   //      if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
1975   //        if (isLineNumberRulerVisible())
1976   //          showLineNumberRuler();
1977   //        else
1978   //          hideLineNumberRuler();
1979   //        return;
1980   //      }
1981   //
1982   //      if (fLineNumberRulerColumn != null
1983   //        && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
1984   //          || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
1985   //          || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
1986   //
1987   //        initializeLineNumberRulerColumn(fLineNumberRulerColumn);
1988   //      }
1989   //
1990   //    } finally {
1991   //      super.handlePreferenceStoreChanged(event);
1992   //    }
1993   //  }
1994
1995   //  private boolean isJavaEditorHoverProperty(String property) {
1996   //    return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
1997   //      || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
1998   //      || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
1999   //      || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
2000   //      || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
2001   //      || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
2002   //      || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
2003   //      || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
2004   //  }
2005
2006   /**
2007    * Shows the line number ruler column.
2008    */
2009 //  private void showLineNumberRuler() {
2010 //    IVerticalRuler v = getVerticalRuler();
2011 //    if (v instanceof CompositeRuler) {
2012 //      CompositeRuler c = (CompositeRuler) v;
2013 //      c.addDecorator(1, createLineNumberRulerColumn());
2014 //    }
2015 //  }
2016   private boolean isJavaEditorHoverProperty(String property) {
2017     return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property);
2018   }
2019
2020   /**
2021          * Return whether the browser like links should be enabled
2022          * according to the preference store settings.
2023          * @return <code>true</code> if the browser like links should be enabled
2024          */
2025   private boolean isBrowserLikeLinks() {
2026     IPreferenceStore store = getPreferenceStore();
2027     return store.getBoolean(BROWSER_LIKE_LINKS);
2028   }
2029
2030   /**
2031    * Enables browser like links.
2032    */
2033   private void enableBrowserLikeLinks() {
2034     if (fMouseListener == null) {
2035       fMouseListener = new MouseClickListener();
2036       fMouseListener.install();
2037     }
2038   }
2039
2040   /**
2041    * Disables browser like links.
2042    */
2043   private void disableBrowserLikeLinks() {
2044     if (fMouseListener != null) {
2045       fMouseListener.uninstall();
2046       fMouseListener = null;
2047     }
2048   }
2049   /**
2050    * Handles a property change event describing a change
2051    * of the java core's preferences and updates the preference
2052    * related editor properties.
2053    * 
2054    * @param event the property change event
2055    */
2056   protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
2057     if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
2058       ISourceViewer sourceViewer = getSourceViewer();
2059       if (sourceViewer != null
2060         && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue())))
2061         sourceViewer.invalidateTextPresentation();
2062     }
2063   }
2064
2065   /**
2066    * Return whether the line number ruler column should be 
2067    * visible according to the preference store settings.
2068    * @return <code>true</code> if the line numbers should be visible
2069    */
2070 //  protected boolean isLineNumberRulerVisible() {
2071 //    IPreferenceStore store = getPreferenceStore();
2072 //    return store.getBoolean(LINE_NUMBER_RULER);
2073 //  }
2074   /**
2075    * Hides the line number ruler column.
2076    */
2077 //  private void hideLineNumberRuler() {
2078 //    IVerticalRuler v = getVerticalRuler();
2079 //    if (v instanceof CompositeRuler) {
2080 //      CompositeRuler c = (CompositeRuler) v;
2081 //      try {
2082 //        c.removeDecorator(1);
2083 //      } catch (Throwable e) {
2084 //      }
2085 //    }
2086 //  }
2087
2088         /*
2089          * @see AbstractTextEditor#handleCursorPositionChanged()
2090          */
2091         protected void handleCursorPositionChanged() {
2092                 super.handleCursorPositionChanged();
2093                 if (!isEditingScriptRunning() && fUpdater != null)
2094                         fUpdater.post();
2095         }
2096         
2097   /**
2098    * Initializes the given line number ruler column from the preference store.
2099    * @param rulerColumn the ruler column to be initialized
2100    */
2101 //  protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) {
2102 //    JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2103 //    IColorManager manager = textTools.getColorManager();
2104 //
2105 //    IPreferenceStore store = getPreferenceStore();
2106 //    if (store != null) {
2107 //
2108 //      RGB rgb = null;
2109 //      // foreground color
2110 //      if (store.contains(LINE_NUMBER_COLOR)) {
2111 //        if (store.isDefault(LINE_NUMBER_COLOR))
2112 //          rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
2113 //        else
2114 //          rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
2115 //      }
2116 //      rulerColumn.setForeground(manager.getColor(rgb));
2117 //
2118 //      rgb = null;
2119 //      // background color
2120 //      if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
2121 //        if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
2122 //          if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
2123 //            rgb = PreferenceConverter.getDefaultColor(store, PREFERENCE_COLOR_BACKGROUND);
2124 //          else
2125 //            rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
2126 //        }
2127 //      }
2128 //      rulerColumn.setBackground(manager.getColor(rgb));
2129 //    }
2130 //  }
2131
2132   /**
2133    * Creates a new line number ruler column that is appropriately initialized.
2134    */
2135 //  protected IVerticalRulerColumn createLineNumberRulerColumn() {
2136 //    fLineNumberRulerColumn = new LineNumberRulerColumn();
2137 //    initializeLineNumberRulerColumn(fLineNumberRulerColumn);
2138 //    return fLineNumberRulerColumn;
2139 //  }
2140
2141   /*
2142    * @see AbstractTextEditor#createVerticalRuler()
2143    */
2144 //  protected IVerticalRuler createVerticalRuler() {
2145 //    CompositeRuler ruler = new CompositeRuler();
2146 //    ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
2147 //    if (isLineNumberRulerVisible())
2148 //      ruler.addDecorator(1, createLineNumberRulerColumn());
2149 //    return ruler;
2150 //  }
2151
2152   private static IRegion getSignedSelection(ITextViewer viewer) {
2153
2154     StyledText text = viewer.getTextWidget();
2155     int caretOffset = text.getCaretOffset();
2156     Point selection = text.getSelection();
2157
2158     // caret left
2159     int offset, length;
2160     if (caretOffset == selection.x) {
2161       offset = selection.y;
2162       length = selection.x - selection.y;
2163
2164       // caret right
2165     } else {
2166       offset = selection.x;
2167       length = selection.y - selection.x;
2168     }
2169
2170     return new Region(offset, length);
2171   }
2172
2173   /** Preference key for matching brackets */
2174   protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
2175   /** Preference key for matching brackets color */
2176   protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
2177   /** Preference key for highlighting current line */
2178   protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
2179   /** Preference key for highlight color of current line */
2180   protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
2181   /** Preference key for showing print marging ruler */
2182   protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
2183   /** Preference key for print margin ruler color */
2184   protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
2185   /** Preference key for print margin ruler column */
2186   protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
2187   /** Preference key for error indication */
2188   protected final static String ERROR_INDICATION = PreferenceConstants.EDITOR_PROBLEM_INDICATION;
2189   /** Preference key for error color */
2190   protected final static String ERROR_INDICATION_COLOR = PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
2191   /** Preference key for warning indication */
2192   protected final static String WARNING_INDICATION = PreferenceConstants.EDITOR_WARNING_INDICATION;
2193   /** Preference key for warning color */
2194   protected final static String WARNING_INDICATION_COLOR = PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
2195   /** Preference key for task indication */
2196   protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
2197   /** Preference key for task color */
2198   protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
2199   /** Preference key for bookmark indication */
2200   protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
2201   /** Preference key for bookmark color */
2202   protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
2203   /** Preference key for search result indication */
2204   protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
2205   /** Preference key for search result color */
2206   protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
2207   /** Preference key for unknown annotation indication */
2208   protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
2209   /** Preference key for unknown annotation color */
2210   protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
2211   /** Preference key for shwoing the overview ruler */
2212   protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
2213   /** Preference key for error indication in overview ruler */
2214   protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
2215   /** Preference key for warning indication in overview ruler */
2216   protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
2217   /** Preference key for task indication in overview ruler */
2218   protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
2219   /** Preference key for bookmark indication in overview ruler */
2220   protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
2221   /** Preference key for search result indication in overview ruler */
2222   protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
2223   /** Preference key for unknown annotation indication in overview ruler */
2224   protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
2225   //            /** Preference key for compiler task tags */
2226   //            private final static String COMPILER_TASK_TAGS= JavaCore.COMPILER_TASK_TAGS;
2227   /** Preference key for browser like links */
2228   private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS;
2229   /** Preference key for key modifier of browser like links */
2230   private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER;
2231   /**
2232    * Preference key for key modifier mask of browser like links.
2233    * The value is only used if the value of <code>EDITOR_BROWSER_LIKE_LINKS</code>
2234    * cannot be resolved to valid SWT modifier bits.
2235    * 
2236    * @since 2.1.1
2237    */
2238   private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
2239
2240   private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
2241
2242   private static boolean isBracket(char character) {
2243     for (int i = 0; i != BRACKETS.length; ++i)
2244       if (character == BRACKETS[i])
2245         return true;
2246     return false;
2247   }
2248
2249   private static boolean isSurroundedByBrackets(IDocument document, int offset) {
2250     if (offset == 0 || offset == document.getLength())
2251       return false;
2252
2253     try {
2254       return isBracket(document.getChar(offset - 1)) && isBracket(document.getChar(offset));
2255
2256     } catch (BadLocationException e) {
2257       return false;
2258     }
2259   }
2260
2261 //  protected void configureSourceViewerDecorationSupport() {
2262 //
2263 //    fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
2264 //
2265 //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2266 //      AnnotationType.UNKNOWN,
2267 //      UNKNOWN_INDICATION_COLOR,
2268 //      UNKNOWN_INDICATION,
2269 //      UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
2270 //      0);
2271 //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2272 //      AnnotationType.BOOKMARK,
2273 //      BOOKMARK_INDICATION_COLOR,
2274 //      BOOKMARK_INDICATION,
2275 //      BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
2276 //      1);
2277 //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2278 //      AnnotationType.TASK,
2279 //      TASK_INDICATION_COLOR,
2280 //      TASK_INDICATION,
2281 //      TASK_INDICATION_IN_OVERVIEW_RULER, 
2282 //      2);
2283 //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2284 //      AnnotationType.SEARCH,
2285 //      SEARCH_RESULT_INDICATION_COLOR,
2286 //      SEARCH_RESULT_INDICATION,
2287 //      SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
2288 //      3);
2289 //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2290 //      AnnotationType.WARNING,
2291 //      WARNING_INDICATION_COLOR,
2292 //      WARNING_INDICATION,
2293 //      WARNING_INDICATION_IN_OVERVIEW_RULER,
2294 //      4);
2295 //    fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2296 //      AnnotationType.ERROR,
2297 //      ERROR_INDICATION_COLOR,
2298 //      ERROR_INDICATION,
2299 //      ERROR_INDICATION_IN_OVERVIEW_RULER,
2300 //      5);
2301 //
2302 //    fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR);
2303 //    fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
2304 //    fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
2305 //
2306 //    fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
2307 //
2308 //  }
2309   /**
2310     * Jumps to the matching bracket.
2311     */
2312   public void gotoMatchingBracket() {
2313
2314     ISourceViewer sourceViewer = getSourceViewer();
2315     IDocument document = sourceViewer.getDocument();
2316     if (document == null)
2317       return;
2318
2319     IRegion selection = getSignedSelection(sourceViewer);
2320
2321     int selectionLength = Math.abs(selection.getLength());
2322     if (selectionLength > 1) {
2323       setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$               
2324       sourceViewer.getTextWidget().getDisplay().beep();
2325       return;
2326     }
2327
2328     // #26314
2329     int sourceCaretOffset = selection.getOffset() + selection.getLength();
2330     if (isSurroundedByBrackets(document, sourceCaretOffset))
2331       sourceCaretOffset -= selection.getLength();
2332
2333     IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
2334     if (region == null) {
2335       setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$              
2336       sourceViewer.getTextWidget().getDisplay().beep();
2337       return;
2338     }
2339
2340     int offset = region.getOffset();
2341     int length = region.getLength();
2342
2343     if (length < 1)
2344       return;
2345
2346     int anchor = fBracketMatcher.getAnchor();
2347     int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
2348
2349     boolean visible = false;
2350     if (sourceViewer instanceof ITextViewerExtension3) {
2351       ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
2352       visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
2353     } else {
2354       IRegion visibleRegion = sourceViewer.getVisibleRegion();
2355       visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength());
2356     }
2357
2358     if (!visible) {
2359       setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$          
2360       sourceViewer.getTextWidget().getDisplay().beep();
2361       return;
2362     }
2363
2364     if (selection.getLength() < 0)
2365       targetOffset -= selection.getLength();
2366
2367     sourceViewer.setSelectedRange(targetOffset, selection.getLength());
2368     sourceViewer.revealRange(targetOffset, selection.getLength());
2369   }
2370   /**
2371      * Ses the given message as error message to this editor's status line.
2372      * @param msg message to be set
2373      */
2374   protected void setStatusLineErrorMessage(String msg) {
2375     IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
2376     if (statusLine != null)
2377       statusLine.setMessage(true, msg, null);
2378   }
2379
2380   /**
2381      * Returns a segmentation of the line of the given document appropriate for bidi rendering.
2382      * The default implementation returns only the string literals of a php code line as segments.
2383      * 
2384      * @param document the document
2385      * @param lineOffset the offset of the line
2386      * @return the line's bidi segmentation
2387      * @throws BadLocationException in case lineOffset is not valid in document
2388      */
2389   public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException {
2390
2391     IRegion line = document.getLineInformationOfOffset(lineOffset);
2392     ITypedRegion[] linePartitioning = document.computePartitioning(lineOffset, line.getLength());
2393
2394     List segmentation = new ArrayList();
2395     for (int i = 0; i < linePartitioning.length; i++) {
2396       if (IPHPPartitionScannerConstants.PHP_STRING.equals(linePartitioning[i].getType()))
2397         segmentation.add(linePartitioning[i]);
2398     }
2399
2400     if (segmentation.size() == 0)
2401       return null;
2402
2403     int size = segmentation.size();
2404     int[] segments = new int[size * 2 + 1];
2405
2406     int j = 0;
2407     for (int i = 0; i < size; i++) {
2408       ITypedRegion segment = (ITypedRegion) segmentation.get(i);
2409
2410       if (i == 0)
2411         segments[j++] = 0;
2412
2413       int offset = segment.getOffset() - lineOffset;
2414       if (offset > segments[j - 1])
2415         segments[j++] = offset;
2416
2417       if (offset + segment.getLength() >= line.getLength())
2418         break;
2419
2420       segments[j++] = offset + segment.getLength();
2421     }
2422
2423     if (j < segments.length) {
2424       int[] result = new int[j];
2425       System.arraycopy(segments, 0, result, 0, j);
2426       segments = result;
2427     }
2428
2429     return segments;
2430   }
2431   /**
2432      * Returns a segmentation of the given line appropriate for bidi rendering. The default
2433      * implementation returns only the string literals of a php code line as segments.
2434      * 
2435      * @param lineOffset the offset of the line
2436      * @param line the content of the line
2437      * @return the line's bidi segmentation
2438      */
2439   protected int[] getBidiLineSegments(int lineOffset, String line) {
2440     IDocumentProvider provider = getDocumentProvider();
2441     if (provider != null && line != null && line.length() > 0) {
2442       IDocument document = provider.getDocument(getEditorInput());
2443       if (document != null)
2444         try {
2445           return getBidiLineSegments(document, lineOffset);
2446         } catch (BadLocationException x) {
2447           // ignore
2448         }
2449     }
2450     return null;
2451   }
2452
2453   /*
2454    * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
2455    */
2456   //  protected final ISourceViewer createSourceViewer(
2457   //    Composite parent,
2458   //    IVerticalRuler ruler,
2459   //    int styles) {
2460   //    ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
2461   //    StyledText text = viewer.getTextWidget();
2462   //    text.addBidiSegmentListener(new BidiSegmentListener() {
2463   //      public void lineGetSegments(BidiSegmentEvent event) {
2464   //        event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
2465   //      }
2466   //    });
2467   //    //   JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
2468   //    return viewer;
2469   //  }
2470   
2471   public final ISourceViewer getViewer() {
2472         return getSourceViewer();
2473   }
2474   
2475   protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {
2476         ISourceViewer viewer= createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles);
2477         
2478         StyledText text= viewer.getTextWidget();
2479         text.addBidiSegmentListener(new  BidiSegmentListener() {
2480                 public void lineGetSegments(BidiSegmentEvent event) {
2481                         event.segments= getBidiLineSegments(event.lineOffset, event.lineText);
2482                 }
2483         });
2484         
2485 //      JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
2486
2487         // ensure source viewer decoration support has been created and configured
2488         getSourceViewerDecorationSupport(viewer);                               
2489         
2490         return viewer;
2491         
2492 //    ISharedTextColors sharedColors = PHPeclipsePlugin.getDefault().getJavaTextTools().getColorManager();
2493 //
2494 //    fOverviewRuler = new OverviewRuler(fAnnotationAccess, VERTICAL_RULER_WIDTH, sharedColors);
2495 //    fOverviewRuler.addHeaderAnnotationType(AnnotationType.WARNING);
2496 //    fOverviewRuler.addHeaderAnnotationType(AnnotationType.ERROR);
2497 //
2498 //    ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, fOverviewRuler, isOverviewRulerVisible(), styles);
2499 //
2500 //    StyledText text = viewer.getTextWidget();
2501 //    text.addBidiSegmentListener(new BidiSegmentListener() {
2502 //      public void lineGetSegments(BidiSegmentEvent event) {
2503 //        event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
2504 //      }
2505 //    });
2506 //
2507 //    //                JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
2508 //
2509 //    fSourceViewerDecorationSupport = new SourceViewerDecorationSupport(viewer, fOverviewRuler, fAnnotationAccess, sharedColors);
2510 //    configureSourceViewerDecorationSupport();
2511 //
2512 //    return viewer;
2513   }
2514
2515 //  protected void showOverviewRuler() {
2516 //    if (fOverviewRuler != null) {
2517 //      if (getSourceViewer() instanceof ISourceViewerExtension) {
2518 //        ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(true);
2519 //        fSourceViewerDecorationSupport.updateOverviewDecorations();
2520 //      }
2521 //    }
2522 //  }
2523 //
2524 //  protected void hideOverviewRuler() {
2525 //    if (getSourceViewer() instanceof ISourceViewerExtension) {
2526 //      fSourceViewerDecorationSupport.hideAnnotationOverview();
2527 //      ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(false);
2528 //    }
2529 //  }
2530
2531 //  protected boolean isOverviewRulerVisible() {
2532 //    IPreferenceStore store = getPreferenceStore();
2533 //    return store.getBoolean(OVERVIEW_RULER);
2534 //  }
2535   /*
2536    * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
2537    */
2538 //  protected ISourceViewer createJavaSourceViewer(
2539 //    Composite parent,
2540 //    IVerticalRuler ruler,
2541 //    IOverviewRuler overviewRuler,
2542 //    boolean isOverviewRulerVisible,
2543 //    int styles) {
2544 //    return new SourceViewer(parent, ruler, overviewRuler, isOverviewRulerVisible(), styles);
2545 //  }
2546   
2547   /*
2548          * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
2549          */
2550         protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles) {
2551                 return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles);
2552         }
2553   /*
2554    * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
2555    */
2556   protected boolean affectsTextPresentation(PropertyChangeEvent event) {
2557     JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2558     return textTools.affectsBehavior(event);
2559   }
2560
2561   /**
2562    * Jumps to the error next according to the given direction.
2563    */
2564   public void gotoError(boolean forward) {
2565
2566     ISelectionProvider provider = getSelectionProvider();
2567
2568     ITextSelection s = (ITextSelection) provider.getSelection();
2569     Position errorPosition = new Position(0, 0);
2570     IJavaAnnotation nextError = getNextError(s.getOffset(), forward, errorPosition);
2571
2572     if (nextError != null) {
2573
2574       IMarker marker = null;
2575       if (nextError instanceof MarkerAnnotation)
2576         marker = ((MarkerAnnotation) nextError).getMarker();
2577       else {
2578         Iterator e = nextError.getOverlaidIterator();
2579         if (e != null) {
2580           while (e.hasNext()) {
2581             Object o = e.next();
2582             if (o instanceof MarkerAnnotation) {
2583               marker = ((MarkerAnnotation) o).getMarker();
2584               break;
2585             }
2586           }
2587         }
2588       }
2589
2590       if (marker != null) {
2591         IWorkbenchPage page = getSite().getPage();
2592         IViewPart view = view = page.findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
2593         if (view instanceof TaskList) {
2594           StructuredSelection ss = new StructuredSelection(marker);
2595           ((TaskList) view).setSelection(ss, true);
2596         }
2597       }
2598
2599       selectAndReveal(errorPosition.getOffset(), errorPosition.getLength());
2600 //      setStatusLineErrorMessage(nextError.getMessage());
2601
2602     } else {
2603
2604       setStatusLineErrorMessage(null);
2605
2606     }
2607   }
2608
2609   private IJavaAnnotation getNextError(int offset, boolean forward, Position errorPosition) {
2610
2611     IJavaAnnotation nextError = null;
2612     Position nextErrorPosition = null;
2613
2614     IDocument document = getDocumentProvider().getDocument(getEditorInput());
2615     int endOfDocument = document.getLength();
2616     int distance = 0;
2617
2618     IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
2619     Iterator e = new JavaAnnotationIterator(model, false);
2620     while (e.hasNext()) {
2621
2622       IJavaAnnotation a = (IJavaAnnotation) e.next();
2623       if (a.hasOverlay() || !a.isProblem())
2624         continue;
2625
2626       Position p = model.getPosition((Annotation) a);
2627       if (!p.includes(offset)) {
2628
2629         int currentDistance = 0;
2630
2631         if (forward) {
2632           currentDistance = p.getOffset() - offset;
2633           if (currentDistance < 0)
2634             currentDistance = endOfDocument - offset + p.getOffset();
2635         } else {
2636           currentDistance = offset - p.getOffset();
2637           if (currentDistance < 0)
2638             currentDistance = offset + endOfDocument - p.getOffset();
2639         }
2640
2641         if (nextError == null || currentDistance < distance) {
2642           distance = currentDistance;
2643           nextError = a;
2644           nextErrorPosition = p;
2645         }
2646       }
2647     }
2648
2649     if (nextErrorPosition != null) {
2650       errorPosition.setOffset(nextErrorPosition.getOffset());
2651       errorPosition.setLength(nextErrorPosition.getLength());
2652     }
2653
2654     return nextError;
2655   }
2656   void removeOccurrenceAnnotations() {
2657         IDocumentProvider documentProvider= getDocumentProvider();
2658         if (documentProvider == null)
2659                 return;
2660         
2661         IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput());
2662         if (annotationModel == null || fOccurrenceAnnotations == null)
2663                 return;
2664
2665         synchronized (annotationModel) {
2666                 if (annotationModel instanceof IAnnotationModelExtension) {
2667                         ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
2668                 } else {
2669                         for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++)
2670                                 annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
2671                 }
2672                 fOccurrenceAnnotations= null;
2673         }
2674 }
2675 }