3.x RC1 compatibility show and refresh browser preview
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPUnitEditor.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.text.MessageFormat;
5 import java.util.ArrayList;
6 import java.util.Iterator;
7 import java.util.List;
8
9 import net.sourceforge.phpdt.core.ICompilationUnit;
10 import net.sourceforge.phpdt.core.IJavaElement;
11 import net.sourceforge.phpdt.core.ISourceRange;
12 import net.sourceforge.phpdt.core.ISourceReference;
13 import net.sourceforge.phpdt.core.JavaCore;
14 import net.sourceforge.phpdt.core.JavaModelException;
15 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
16 import net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction;
17 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
18 import net.sourceforge.phpdt.internal.ui.actions.RemoveBlockCommentAction;
19 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
20 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
21 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
22 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
23 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
24 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags;
25 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
26 import net.sourceforge.phpdt.ui.PreferenceConstants;
27 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
28 import net.sourceforge.phpdt.ui.text.JavaTextTools;
29 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
30
31 import org.eclipse.core.resources.IFile;
32 import org.eclipse.core.resources.IWorkspace;
33 import org.eclipse.core.resources.IWorkspaceRoot;
34 import org.eclipse.core.resources.ResourcesPlugin;
35 import org.eclipse.core.runtime.CoreException;
36 import org.eclipse.core.runtime.IPath;
37 import org.eclipse.core.runtime.IProgressMonitor;
38 import org.eclipse.core.runtime.IStatus;
39 import org.eclipse.core.runtime.Preferences;
40
41 import net.sourceforge.phpdt.internal.ui.text.java.IJavaReconcilingListener;
42
43 import org.eclipse.jface.action.Action;
44 import org.eclipse.jface.action.IAction;
45 import org.eclipse.jface.action.IMenuManager;
46 import org.eclipse.jface.dialogs.Dialog;
47 import org.eclipse.jface.dialogs.ErrorDialog;
48 import org.eclipse.jface.dialogs.IMessageProvider;
49 import org.eclipse.jface.dialogs.MessageDialog;
50 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
51 import org.eclipse.jface.preference.IPreferenceStore;
52 import org.eclipse.jface.preference.PreferenceConverter;
53 import org.eclipse.jface.text.BadLocationException;
54 import org.eclipse.jface.text.DocumentCommand;
55 import org.eclipse.jface.text.IDocument;
56 import org.eclipse.jface.text.ILineTracker;
57 import org.eclipse.jface.text.IRegion;
58 import org.eclipse.jface.text.ITextOperationTarget;
59 import org.eclipse.jface.text.ITextSelection;
60 import org.eclipse.jface.text.ITextViewerExtension;
61 import org.eclipse.jface.text.ITypedRegion;
62 import org.eclipse.jface.text.IWidgetTokenKeeper;
63 import org.eclipse.jface.text.contentassist.ContentAssistant;
64 import org.eclipse.jface.text.contentassist.IContentAssistant;
65 import org.eclipse.jface.text.source.IAnnotationModel;
66 import org.eclipse.jface.text.source.IOverviewRuler;
67 import org.eclipse.jface.text.source.ISourceViewer;
68 import org.eclipse.jface.text.source.IVerticalRuler;
69 import org.eclipse.jface.text.source.SourceViewerConfiguration;
70 import org.eclipse.jface.util.PropertyChangeEvent;
71 import org.eclipse.jface.viewers.ISelectionProvider;
72 import org.eclipse.jface.window.Window;
73 import org.eclipse.swt.SWT;
74 import org.eclipse.swt.custom.VerifyKeyListener;
75 import org.eclipse.swt.events.VerifyEvent;
76 import org.eclipse.swt.graphics.Color;
77 import org.eclipse.swt.graphics.Point;
78 import org.eclipse.swt.graphics.RGB;
79 import org.eclipse.swt.widgets.Composite;
80 import org.eclipse.swt.widgets.Display;
81 import org.eclipse.swt.widgets.Shell;
82 import org.eclipse.ui.IEditorInput;
83 import org.eclipse.ui.IFileEditorInput;
84 import org.eclipse.ui.actions.ActionContext;
85 import org.eclipse.ui.actions.ActionGroup;
86 import org.eclipse.ui.actions.WorkspaceModifyOperation;
87 import org.eclipse.ui.dialogs.SaveAsDialog;
88 import org.eclipse.ui.editors.text.IStorageDocumentProvider;
89 import org.eclipse.ui.help.WorkbenchHelp;
90 import org.eclipse.ui.part.FileEditorInput;
91 import org.eclipse.ui.texteditor.ContentAssistAction;
92 import org.eclipse.ui.texteditor.IDocumentProvider;
93 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
94 import org.eclipse.ui.texteditor.TextOperationAction;
95 /*******************************************************************************
96  * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
97  * program and the accompanying materials are made available under the terms of
98  * the Common Public License v1.0 which accompanies this distribution, and is
99  * available at http://www.eclipse.org/legal/cpl-v10.html
100  * 
101  * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
102  * www.eclipseproject.de
103  ******************************************************************************/
104 /**
105  * PHP specific text editor.
106  */
107 public class PHPUnitEditor extends PHPEditor { //implements
108                                                                                            // IJavaReconcilingListener {
109         interface ITextConverter {
110                 void customizeDocumentCommand(IDocument document,
111                                 DocumentCommand command);
112         };
113         //  class AdaptedRulerLayout extends Layout {
114         //
115         //    protected int fGap;
116         //    protected AdaptedSourceViewer fAdaptedSourceViewer;
117         //
118         //    protected AdaptedRulerLayout(int gap, AdaptedSourceViewer asv) {
119         //      fGap = gap;
120         //      fAdaptedSourceViewer = asv;
121         //    }
122         //
123         //    protected Point computeSize(Composite composite, int wHint, int hHint,
124         // boolean flushCache) {
125         //      Control[] children = composite.getChildren();
126         //      Point s = children[children.length - 1].computeSize(SWT.DEFAULT,
127         // SWT.DEFAULT, flushCache);
128         //      if (fAdaptedSourceViewer.isVerticalRulerVisible())
129         //        s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap;
130         //      return s;
131         //    }
132         //
133         //    protected void layout(Composite composite, boolean flushCache) {
134         //      Rectangle clArea = composite.getClientArea();
135         //      if (fAdaptedSourceViewer.isVerticalRulerVisible()) {
136         //
137         //        StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
138         //        Rectangle trim = textWidget.computeTrim(0, 0, 0, 0);
139         //        int scrollbarHeight = trim.height;
140         //
141         //        IVerticalRuler vr = fAdaptedSourceViewer.getVerticalRuler();
142         //        int vrWidth = vr.getWidth();
143         //
144         //        int orWidth = 0;
145         //        if (fAdaptedSourceViewer.isOverviewRulerVisible()) {
146         //          OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler();
147         //          orWidth = or.getWidth();
148         //          or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight,
149         // orWidth, clArea.height - 3 * scrollbarHeight);
150         //        }
151         //
152         //        textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth
153         // -
154         // 2 * fGap, clArea.height);
155         //        vr.getControl().setBounds(0, 0, vrWidth, clArea.height -
156         // scrollbarHeight);
157         //
158         //      } else {
159         //        StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
160         //        textWidget.setBounds(0, 0, clArea.width, clArea.height);
161         //      }
162         //    }
163         //  };
164         //
165         //  class AdaptedSourceViewer extends SourceViewer { // extends
166         // JavaCorrectionSourceViewer {
167         //
168         //    private List fTextConverters;
169         //
170         //    private OverviewRuler fOverviewRuler;
171         //    private boolean fIsOverviewRulerVisible;
172         //    /** The viewer's overview ruler hovering controller */
173         //    private AbstractHoverInformationControlManager
174         // fOverviewRulerHoveringController;
175         //
176         //    private boolean fIgnoreTextConverters = false;
177         //
178         //    private IVerticalRuler fCachedVerticalRuler;
179         //    private boolean fCachedIsVerticalRulerVisible;
180         //
181         //    public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int
182         // styles) {
183         //      super(parent, ruler, styles); //, CompilationUnitEditor.this);
184         //
185         //      fCachedVerticalRuler = ruler;
186         //      fCachedIsVerticalRulerVisible = (ruler != null);
187         //      fOverviewRuler = new OverviewRuler(VERTICAL_RULER_WIDTH);
188         //
189         //      delayedCreateControl(parent, styles);
190         //    }
191         //
192         //    /*
193         //     * @see ISourceViewer#showAnnotations(boolean)
194         //     */
195         //    public void showAnnotations(boolean show) {
196         //      fCachedIsVerticalRulerVisible = (show && fCachedVerticalRuler != null);
197         //      // super.showAnnotations(show);
198         //    }
199         //
200         //    public IContentAssistant getContentAssistant() {
201         //      return fContentAssistant;
202         //    }
203         //
204         //    /*
205         //     * @see ITextOperationTarget#doOperation(int)
206         //     */
207         //    public void doOperation(int operation) {
208         //
209         //      if (getTextWidget() == null)
210         //        return;
211         //
212         //      switch (operation) {
213         //        case CONTENTASSIST_PROPOSALS :
214         //          String msg = fContentAssistant.showPossibleCompletions();
215         //          setStatusLineErrorMessage(msg);
216         //          return;
217         //        case UNDO :
218         //          fIgnoreTextConverters = true;
219         //          break;
220         //        case REDO :
221         //          fIgnoreTextConverters = true;
222         //          break;
223         //      }
224         //
225         //      super.doOperation(operation);
226         //    }
227         //
228         //    public void insertTextConverter(ITextConverter textConverter, int index)
229         // {
230         //      throw new UnsupportedOperationException();
231         //    }
232         //
233         //    public void addTextConverter(ITextConverter textConverter) {
234         //      if (fTextConverters == null) {
235         //        fTextConverters = new ArrayList(1);
236         //        fTextConverters.add(textConverter);
237         //      } else if (!fTextConverters.contains(textConverter))
238         //        fTextConverters.add(textConverter);
239         //    }
240         //
241         //    public void removeTextConverter(ITextConverter textConverter) {
242         //      if (fTextConverters != null) {
243         //        fTextConverters.remove(textConverter);
244         //        if (fTextConverters.size() == 0)
245         //          fTextConverters = null;
246         //      }
247         //    }
248         //
249         //    /*
250         //     * @see TextViewer#customizeDocumentCommand(DocumentCommand)
251         //     */
252         //    protected void customizeDocumentCommand(DocumentCommand command) {
253         //      super.customizeDocumentCommand(command);
254         //      if (!fIgnoreTextConverters && fTextConverters != null) {
255         //        for (Iterator e = fTextConverters.iterator(); e.hasNext();)
256         //           ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(),
257         // command);
258         //      }
259         //      fIgnoreTextConverters = false;
260         //    }
261         //
262         //    public IVerticalRuler getVerticalRuler() {
263         //      return fCachedVerticalRuler;
264         //    }
265         //
266         //    public boolean isVerticalRulerVisible() {
267         //      return fCachedIsVerticalRulerVisible;
268         //    }
269         //
270         //    public OverviewRuler getOverviewRuler() {
271         //      return fOverviewRuler;
272         //    }
273         //
274         //    /*
275         //     * @see TextViewer#createControl(Composite, int)
276         //     */
277         //    protected void createControl(Composite parent, int styles) {
278         //      // do nothing here
279         //    }
280         //
281         //    protected void delayedCreateControl(Composite parent, int styles) {
282         //      //create the viewer
283         //      super.createControl(parent, styles);
284         //
285         //      Control control = getControl();
286         //      if (control instanceof Composite) {
287         //        Composite composite = (Composite) control;
288         //        composite.setLayout(new AdaptedRulerLayout(GAP_SIZE, this));
289         //        fOverviewRuler.createControl(composite, this);
290         //      }
291         //    }
292         //    protected void ensureOverviewHoverManagerInstalled() {
293         //      if (fOverviewRulerHoveringController == null && fAnnotationHover != null
294         // && fHoverControlCreator != null) {
295         //        fOverviewRulerHoveringController =
296         //          new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover,
297         // fHoverControlCreator);
298         //        fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
299         //      }
300         //    }
301         //
302         //    public void hideOverviewRuler() {
303         //      fIsOverviewRulerVisible = false;
304         //      Control control = getControl();
305         //      if (control instanceof Composite) {
306         //        Composite composite = (Composite) control;
307         //        composite.layout();
308         //      }
309         //      if (fOverviewRulerHoveringController != null) {
310         //        fOverviewRulerHoveringController.dispose();
311         //        fOverviewRulerHoveringController = null;
312         //      }
313         //    }
314         //
315         //    public void showOverviewRuler() {
316         //      fIsOverviewRulerVisible = true;
317         //      Control control = getControl();
318         //      if (control instanceof Composite) {
319         //        Composite composite = (Composite) control;
320         //        composite.layout();
321         //      }
322         //      ensureOverviewHoverManagerInstalled();
323         //    }
324         //
325         //    public boolean isOverviewRulerVisible() {
326         //      return fIsOverviewRulerVisible;
327         //    }
328         //
329         //    /*
330         //     * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
331         //     */
332         //    public void setDocument(
333         //      IDocument document,
334         //      IAnnotationModel annotationModel,
335         //      int visibleRegionOffset,
336         //      int visibleRegionLength) {
337         //      super.setDocument(document, annotationModel, visibleRegionOffset,
338         // visibleRegionLength);
339         //      fOverviewRuler.setModel(annotationModel);
340         //    }
341         //
342         //    // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
343         //    public void updateIndentationPrefixes() {
344         //      SourceViewerConfiguration configuration = getSourceViewerConfiguration();
345         //      String[] types = configuration.getConfiguredContentTypes(this);
346         //      for (int i = 0; i < types.length; i++) {
347         //        String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
348         //        if (prefixes != null && prefixes.length > 0)
349         //          setIndentPrefixes(prefixes, types[i]);
350         //      }
351         //    }
352         //
353         //    /*
354         //     * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
355         //     */
356         //    public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
357         //      if (WorkbenchHelp.isContextHelpDisplayed())
358         //        return false;
359         //      return super.requestWidgetToken(requester);
360         //    }
361         //
362         //    /*
363         //     * @see
364         // org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
365         //     */
366         //    public void configure(SourceViewerConfiguration configuration) {
367         //      super.configure(configuration);
368         //      // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
369         // IDocument.DEFAULT_CONTENT_TYPE);
370         //    }
371         //
372         //    protected void handleDispose() {
373         //      fOverviewRuler = null;
374         //
375         //      if (fOverviewRulerHoveringController != null) {
376         //        fOverviewRulerHoveringController.dispose();
377         //        fOverviewRulerHoveringController = null;
378         //      }
379         //
380         //      super.handleDispose();
381         //    }
382         //
383         //  };
384         class AdaptedSourceViewer extends JavaSourceViewer {
385                 private List fTextConverters;
386                 private boolean fIgnoreTextConverters = false;
387                 //                      private JavaCorrectionAssistant fCorrectionAssistant;
388                 public AdaptedSourceViewer(Composite parent,
389                                 IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
390                                 boolean showAnnotationsOverview, int styles,
391                                 IPreferenceStore store) {
392                         super(parent, verticalRuler, overviewRuler,
393                                         showAnnotationsOverview, styles, store);
394                 }
395                 //              public AdaptedSourceViewer(Composite parent,
396                 //                              IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
397                 //                              boolean showAnnotationsOverview, int styles) {
398                 //                      super(parent, verticalRuler, overviewRuler,
399                 //                                      showAnnotationsOverview, styles);
400                 //              }
401                 public IContentAssistant getContentAssistant() {
402                         return fContentAssistant;
403                 }
404                 /*
405                  * @see ITextOperationTarget#doOperation(int)
406                  */
407                 public void doOperation(int operation) {
408                         if (getTextWidget() == null)
409                                 return;
410                         switch (operation) {
411                                 case CONTENTASSIST_PROPOSALS :
412                                         String msg = fContentAssistant.showPossibleCompletions();
413                                         setStatusLineErrorMessage(msg);
414                                         return;
415                                 //                                      case CORRECTIONASSIST_PROPOSALS:
416                                 //                                              fCorrectionAssistant.showPossibleCompletions();
417                                 //                                              return;
418                                 case UNDO :
419                                         fIgnoreTextConverters = true;
420                                         break;
421                                 case REDO :
422                                         fIgnoreTextConverters = true;
423                                         break;
424                         }
425                         super.doOperation(operation);
426                 }
427                 /*
428                  * @see ITextOperationTarget#canDoOperation(int)
429                  */
430                 public boolean canDoOperation(int operation) {
431                         //                              if (operation == CORRECTIONASSIST_PROPOSALS)
432                         //                                      return isEditable();
433                         return super.canDoOperation(operation);
434                 }
435                 /*
436                  * @see TextViewer#handleDispose()
437                  */
438                 protected void handleDispose() {
439                         //                              if (fCorrectionAssistant != null) {
440                         //                                      fCorrectionAssistant.uninstall();
441                         //                                      fCorrectionAssistant= null;
442                         //                              }
443                         super.handleDispose();
444                 }
445                 public void insertTextConverter(ITextConverter textConverter, int index) {
446                         throw new UnsupportedOperationException();
447                 }
448                 public void addTextConverter(ITextConverter textConverter) {
449                         if (fTextConverters == null) {
450                                 fTextConverters = new ArrayList(1);
451                                 fTextConverters.add(textConverter);
452                         } else if (!fTextConverters.contains(textConverter))
453                                 fTextConverters.add(textConverter);
454                 }
455                 public void removeTextConverter(ITextConverter textConverter) {
456                         if (fTextConverters != null) {
457                                 fTextConverters.remove(textConverter);
458                                 if (fTextConverters.size() == 0)
459                                         fTextConverters = null;
460                         }
461                 }
462                 /*
463                  * @see TextViewer#customizeDocumentCommand(DocumentCommand)
464                  */
465                 protected void customizeDocumentCommand(DocumentCommand command) {
466                         super.customizeDocumentCommand(command);
467                         if (!fIgnoreTextConverters && fTextConverters != null) {
468                                 for (Iterator e = fTextConverters.iterator(); e.hasNext();)
469                                         ((ITextConverter) e.next()).customizeDocumentCommand(
470                                                         getDocument(), command);
471                         }
472                         fIgnoreTextConverters = false;
473                 }
474                 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
475                 public void updateIndentationPrefixes() {
476                         SourceViewerConfiguration configuration = getSourceViewerConfiguration();
477                         String[] types = configuration.getConfiguredContentTypes(this);
478                         for (int i = 0; i < types.length; i++) {
479                                 String[] prefixes = configuration.getIndentPrefixes(this,
480                                                 types[i]);
481                                 if (prefixes != null && prefixes.length > 0)
482                                         setIndentPrefixes(prefixes, types[i]);
483                         }
484                 }
485                 /*
486                  * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
487                  */
488                 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
489                         if (WorkbenchHelp.isContextHelpDisplayed())
490                                 return false;
491                         return super.requestWidgetToken(requester);
492                 }
493                 /*
494                  * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
495                  */
496                 public void configure(SourceViewerConfiguration configuration) {
497                         super.configure(configuration);
498                         //                              fCorrectionAssistant= new
499                         // JavaCorrectionAssistant(CompilationUnitEditor.this);
500                         //                              fCorrectionAssistant.install(this);
501                         //TODO install SmartBracesAutoEditStrategy
502                         //                              prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
503                         // IDocument.DEFAULT_CONTENT_TYPE);
504                 }
505         };
506         static class TabConverter implements ITextConverter {
507                 private int fTabRatio;
508                 private ILineTracker fLineTracker;
509                 public TabConverter() {
510                 }
511                 public void setNumberOfSpacesPerTab(int ratio) {
512                         fTabRatio = ratio;
513                 }
514                 public void setLineTracker(ILineTracker lineTracker) {
515                         fLineTracker = lineTracker;
516                 }
517                 private int insertTabString(StringBuffer buffer, int offsetInLine) {
518                         if (fTabRatio == 0)
519                                 return 0;
520                         int remainder = offsetInLine % fTabRatio;
521                         remainder = fTabRatio - remainder;
522                         for (int i = 0; i < remainder; i++)
523                                 buffer.append(' ');
524                         return remainder;
525                 }
526                 public void customizeDocumentCommand(IDocument document,
527                                 DocumentCommand command) {
528                         String text = command.text;
529                         if (text == null)
530                                 return;
531                         int index = text.indexOf('\t');
532                         if (index > -1) {
533                                 StringBuffer buffer = new StringBuffer();
534                                 fLineTracker.set(command.text);
535                                 int lines = fLineTracker.getNumberOfLines();
536                                 try {
537                                         for (int i = 0; i < lines; i++) {
538                                                 int offset = fLineTracker.getLineOffset(i);
539                                                 int endOffset = offset + fLineTracker.getLineLength(i);
540                                                 String line = text.substring(offset, endOffset);
541                                                 int position = 0;
542                                                 if (i == 0) {
543                                                         IRegion firstLine = document
544                                                                         .getLineInformationOfOffset(command.offset);
545                                                         position = command.offset - firstLine.getOffset();
546                                                 }
547                                                 int length = line.length();
548                                                 for (int j = 0; j < length; j++) {
549                                                         char c = line.charAt(j);
550                                                         if (c == '\t') {
551                                                                 position += insertTabString(buffer, position);
552                                                         } else {
553                                                                 buffer.append(c);
554                                                                 ++position;
555                                                         }
556                                                 }
557                                         }
558                                         command.text = buffer.toString();
559                                 } catch (BadLocationException x) {
560                                 }
561                         }
562                 }
563         };
564         private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
565                 final char fExitCharacter;
566                 public ExitPolicy(char exitCharacter) {
567                         fExitCharacter = exitCharacter;
568                 }
569                 /*
570                  * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager,
571                  *      org.eclipse.swt.events.VerifyEvent, int, int)
572                  */
573                 public ExitFlags doExit(LinkedPositionManager manager,
574                                 VerifyEvent event, int offset, int length) {
575                         if (event.character == fExitCharacter) {
576                                 if (manager.anyPositionIncludes(offset, length))
577                                         return new ExitFlags(LinkedPositionUI.COMMIT
578                                                         | LinkedPositionUI.UPDATE_CARET, false);
579                                 else
580                                         return new ExitFlags(LinkedPositionUI.COMMIT, true);
581                         }
582                         switch (event.character) {
583                                 case '\b' :
584                                         if (manager.getFirstPosition().length == 0)
585                                                 return new ExitFlags(0, false);
586                                         else
587                                                 return null;
588                                 case '\n' :
589                                 case '\r' :
590                                         return new ExitFlags(LinkedPositionUI.COMMIT, true);
591                                 default :
592                                         return null;
593                         }
594                 }
595         }
596         private static class BracketLevel {
597                 int fOffset;
598                 int fLength;
599                 LinkedPositionManager fManager;
600                 LinkedPositionUI fEditor;
601         };
602         private class BracketInserter
603                         implements
604                                 VerifyKeyListener,
605                                 LinkedPositionUI.ExitListener {
606                 private boolean fCloseBracketsPHP = true;
607                 private boolean fCloseStringsPHP = true;
608                 private boolean fCloseBracketsHTML = true;
609                 private boolean fCloseStringsHTML = true;
610                 private int fOffset;
611                 private int fLength;
612                 public void setCloseBracketsPHPEnabled(boolean enabled) {
613                         fCloseBracketsPHP = enabled;
614                 }
615                 public void setCloseStringsPHPEnabled(boolean enabled) {
616                         fCloseStringsPHP = enabled;
617                 }
618                 public void setCloseBracketsHTMLEnabled(boolean enabled) {
619                         fCloseBracketsHTML = enabled;
620                 }
621                 public void setCloseStringsHTMLEnabled(boolean enabled) {
622                         fCloseStringsHTML = enabled;
623                 }
624                 private boolean hasIdentifierToTheRight(IDocument document, int offset) {
625                         try {
626                                 int end = offset;
627                                 IRegion endLine = document.getLineInformationOfOffset(end);
628                                 int maxEnd = endLine.getOffset() + endLine.getLength();
629                                 while (end != maxEnd
630                                                 && Character.isWhitespace(document.getChar(end)))
631                                         ++end;
632                                 return end != maxEnd
633                                                 && Scanner.isPHPIdentifierPart(document.getChar(end));
634                         } catch (BadLocationException e) {
635                                 // be conservative
636                                 return true;
637                         }
638                 }
639                 private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
640                         try {
641                                 int start = offset;
642                                 IRegion startLine = document.getLineInformationOfOffset(start);
643                                 int minStart = startLine.getOffset();
644                                 while (start != minStart
645                                                 && Character.isWhitespace(document.getChar(start - 1)))
646                                         --start;
647                                 return start != minStart
648                                                 && Scanner.isPHPIdentifierPart(document
649                                                                 .getChar(start - 1));
650                         } catch (BadLocationException e) {
651                                 return true;
652                         }
653                 }
654                 private boolean hasCharacterToTheRight(IDocument document, int offset,
655                                 char character) {
656                         try {
657                                 int end = offset;
658                                 IRegion endLine = document.getLineInformationOfOffset(end);
659                                 int maxEnd = endLine.getOffset() + endLine.getLength();
660                                 while (end != maxEnd
661                                                 && Character.isWhitespace(document.getChar(end)))
662                                         ++end;
663                                 return end != maxEnd && document.getChar(end) == character;
664                         } catch (BadLocationException e) {
665                                 // be conservative
666                                 return true;
667                         }
668                 }
669                 /*
670                  * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
671                  */
672                 public void verifyKey(VerifyEvent event) {
673                         if (!event.doit)
674                                 return;
675                         final ISourceViewer sourceViewer = getSourceViewer();
676                         IDocument document = sourceViewer.getDocument();
677                         final Point selection = sourceViewer.getSelectedRange();
678                         final int offset = selection.x;
679                         final int length = selection.y;
680                         try {
681                                 ITypedRegion partition = document.getPartition(offset);
682                                 String type = partition.getType();
683                                 if (type.equals(IPHPPartitions.PHP_PARTITIONING)) {
684                                         switch (event.character) {
685                                                 case '(' :
686                                                         if (hasCharacterToTheRight(document, offset
687                                                                         + length, '('))
688                                                                 return;
689                                                 // fall through
690                                                 case '[' :
691                                                         if (!fCloseBracketsPHP)
692                                                                 return;
693                                                         if (hasIdentifierToTheRight(document, offset
694                                                                         + length))
695                                                                 return;
696                                                 // fall through
697                                                 case '"' :
698                                                         if (event.character == '"') {
699                                                                 if (!fCloseStringsPHP)
700                                                                         return;
701                                                                 // changed for statements like echo "" print ""
702                                                                 //    if (hasIdentifierToTheLeft(document, offset)
703                                                                 // ||
704                                                                 // hasIdentifierToTheRight(document, offset +
705                                                                 // length))
706                                                                 if (hasIdentifierToTheRight(document, offset
707                                                                                 + length))
708                                                                         return;
709                                                         }
710                                                         //     ITypedRegion partition=
711                                                         // document.getPartition(offset);
712                                                         //       if (!
713                                                         // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
714                                                         // &&
715                                                         // (partition.getOffset() != offset))
716                                                         //         return;
717                                                         final char character = event.character;
718                                                         final char closingCharacter = getPeerCharacter(character);
719                                                         final StringBuffer buffer = new StringBuffer();
720                                                         buffer.append(character);
721                                                         buffer.append(closingCharacter);
722                                                         document.replace(offset, length, buffer.toString());
723                                                         LinkedPositionManager manager = new LinkedPositionManager(
724                                                                         document);
725                                                         manager.addPosition(offset + 1, 0);
726                                                         fOffset = offset;
727                                                         fLength = 2;
728                                                         LinkedPositionUI editor = new LinkedPositionUI(
729                                                                         sourceViewer, manager);
730                                                         editor.setCancelListener(this);
731                                                         editor.setExitPolicy(new ExitPolicy(
732                                                                         closingCharacter));
733                                                         editor.setFinalCaretOffset(offset + 2);
734                                                         editor.enter();
735                                                         IRegion newSelection = editor.getSelectedRegion();
736                                                         sourceViewer.setSelectedRange(newSelection
737                                                                         .getOffset(), newSelection.getLength());
738                                                         event.doit = false;
739                                         }
740                                 } else if (type.equals(IPHPPartitions.HTML)
741                                                 || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
742                                         switch (event.character) {
743                                                 case '(' :
744                                                         if (hasCharacterToTheRight(document, offset
745                                                                         + length, '('))
746                                                                 return;
747                                                 // fall through
748                                                 case '[' :
749                                                         if (!fCloseBracketsHTML)
750                                                                 return;
751                                                         if (hasIdentifierToTheRight(document, offset
752                                                                         + length))
753                                                                 return;
754                                                 // fall through
755                                                 case '"' :
756                                                         if (event.character == '"') {
757                                                                 if (!fCloseStringsHTML)
758                                                                         return;
759                                                                 if (hasIdentifierToTheLeft(document, offset)
760                                                                                 || hasIdentifierToTheRight(document,
761                                                                                                 offset + length))
762                                                                         return;
763                                                         }
764                                                         //     ITypedRegion partition=
765                                                         // document.getPartition(offset);
766                                                         //       if (!
767                                                         // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
768                                                         // &&
769                                                         // (partition.getOffset() != offset))
770                                                         //         return;
771                                                         final char character = event.character;
772                                                         final char closingCharacter = getPeerCharacter(character);
773                                                         final StringBuffer buffer = new StringBuffer();
774                                                         buffer.append(character);
775                                                         buffer.append(closingCharacter);
776                                                         document.replace(offset, length, buffer.toString());
777                                                         LinkedPositionManager manager = new LinkedPositionManager(
778                                                                         document);
779                                                         manager.addPosition(offset + 1, 0);
780                                                         fOffset = offset;
781                                                         fLength = 2;
782                                                         LinkedPositionUI editor = new LinkedPositionUI(
783                                                                         sourceViewer, manager);
784                                                         editor.setCancelListener(this);
785                                                         editor.setExitPolicy(new ExitPolicy(
786                                                                         closingCharacter));
787                                                         editor.setFinalCaretOffset(offset + 2);
788                                                         editor.enter();
789                                                         IRegion newSelection = editor.getSelectedRegion();
790                                                         sourceViewer.setSelectedRange(newSelection
791                                                                         .getOffset(), newSelection.getLength());
792                                                         event.doit = false;
793                                         }
794                                 }
795                         } catch (BadLocationException e) {
796                         }
797                 }
798                 /*
799                  * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean)
800                  */
801                 public void exit(boolean accept) {
802                         if (accept)
803                                 return;
804                         // remove brackets
805                         try {
806                                 final ISourceViewer sourceViewer = getSourceViewer();
807                                 IDocument document = sourceViewer.getDocument();
808                                 document.replace(fOffset, fLength, null);
809                         } catch (BadLocationException e) {
810                         }
811                 }
812         }
813         /** The editor's save policy */
814         protected ISavePolicy fSavePolicy;
815         /**
816          * Listener to annotation model changes that updates the error tick in the
817          * tab image
818          */
819         private JavaEditorErrorTickUpdater fJavaEditorErrorTickUpdater;
820         /** The editor's paint manager */
821         //  private PaintManager fPaintManager;
822         /** The editor's bracket painter */
823         private BracketPainter fBracketPainter;
824         /** The editor's bracket matcher */
825         private PHPPairMatcher fBracketMatcher;
826         /** The editor's line painter */
827         private LinePainter fLinePainter;
828         /** The editor's print margin ruler painter */
829         private PrintMarginPainter fPrintMarginPainter;
830         /** The editor's problem painter */
831         //  private ProblemPainter fProblemPainter;
832         /** The editor's tab converter */
833         private TabConverter fTabConverter;
834         /** History for structure select action */
835         //private SelectionHistory fSelectionHistory;
836         /** The preference property change listener for php core. */
837         //  private IPropertyChangeListener fPropertyChangeListener = new
838         // PropertyChangeListener();
839         /** The remembered java element */
840         private IJavaElement fRememberedElement;
841         /** The remembered selection */
842         private ITextSelection fRememberedSelection;
843         /** The remembered php element offset */
844         private int fRememberedElementOffset;
845         /** The bracket inserter. */
846         private BracketInserter fBracketInserter = new BracketInserter();
847
848         /** The standard action groups added to the menu */
849         private GenerateActionGroup fGenerateActionGroup;
850         private CompositeActionGroup fContextMenuGroup;
851         //  private class PropertyChangeListener implements IPropertyChangeListener {
852         //    /*
853         //     * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
854         //     */
855         //    public void
856         // propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
857         // event) {
858         //      handlePreferencePropertyChanged(event);
859         //    }
860         //  }
861         /* Preference key for code formatter tab size */
862         private final static String CODE_FORMATTER_TAB_SIZE = JavaCore.FORMATTER_TAB_SIZE;
863         /** Preference key for matching brackets */
864         private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
865         /** Preference key for matching brackets color */
866         private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
867         /** Preference key for highlighting current line */
868         private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
869         /** Preference key for highlight color of current line */
870         private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
871         /** Preference key for showing print marging ruler */
872         private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
873         /** Preference key for print margin ruler color */
874         private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
875         /** Preference key for print margin ruler column */
876         private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
877         /** Preference key for inserting spaces rather than tabs */
878         private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
879         /** Preference key for error indication */
880         //  private final static String ERROR_INDICATION =
881         // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
882         /** Preference key for error color */
883         //  private final static String ERROR_INDICATION_COLOR =
884         // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
885         /** Preference key for warning indication */
886         //  private final static String WARNING_INDICATION =
887         // PreferenceConstants.EDITOR_WARNING_INDICATION;
888         /** Preference key for warning color */
889         //  private final static String WARNING_INDICATION_COLOR =
890         // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
891         /** Preference key for task indication */
892         private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
893         /** Preference key for task color */
894         private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
895         /** Preference key for bookmark indication */
896         private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
897         /** Preference key for bookmark color */
898         private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
899         /** Preference key for search result indication */
900         private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
901         /** Preference key for search result color */
902         private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
903         /** Preference key for unknown annotation indication */
904         private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
905         /** Preference key for unknown annotation color */
906         private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
907         /** Preference key for linked position color */
908         private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
909         /** Preference key for shwoing the overview ruler */
910         private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
911         /** Preference key for error indication in overview ruler */
912         private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
913         /** Preference key for warning indication in overview ruler */
914         private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
915         /** Preference key for task indication in overview ruler */
916         private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
917         /** Preference key for bookmark indication in overview ruler */
918         private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
919         /** Preference key for search result indication in overview ruler */
920         private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
921         /** Preference key for unknown annotation indication in overview ruler */
922         private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
923         /** Preference key for automatically closing strings */
924         private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP;
925         /** Preference key for automatically wrapping Java strings */
926         private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS;
927         /** Preference key for automatically closing brackets and parenthesis */
928         private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
929         /** Preference key for automatically closing phpdocs and comments */
930         private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
931         /** Preference key for automatically adding phpdoc tags */
932         private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
933         /** Preference key for automatically formatting phpdocs */
934         private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
935         /** Preference key for automatically closing strings */
936         private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
937         /** Preference key for automatically closing brackets and parenthesis */
938         private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
939         /** Preference key for smart paste */
940         private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
941         //  private final static class AnnotationInfo {
942         //    public String fColorPreference;
943         //    public String fOverviewRulerPreference;
944         //    public String fEditorPreference;
945         //  };
946         //  private final static Map ANNOTATION_MAP;
947         //  static {
948         //
949         //    AnnotationInfo info;
950         //    ANNOTATION_MAP = new HashMap();
951         //
952         //    info = new AnnotationInfo();
953         //    info.fColorPreference = TASK_INDICATION_COLOR;
954         //    info.fOverviewRulerPreference = TASK_INDICATION_IN_OVERVIEW_RULER;
955         //    info.fEditorPreference = TASK_INDICATION;
956         //    ANNOTATION_MAP.put(AnnotationType.TASK, info);
957         //
958         //    info = new AnnotationInfo();
959         //    info.fColorPreference = ERROR_INDICATION_COLOR;
960         //    info.fOverviewRulerPreference = ERROR_INDICATION_IN_OVERVIEW_RULER;
961         //    info.fEditorPreference = ERROR_INDICATION;
962         //    ANNOTATION_MAP.put(AnnotationType.ERROR, info);
963         //
964         //    info = new AnnotationInfo();
965         //    info.fColorPreference = WARNING_INDICATION_COLOR;
966         //    info.fOverviewRulerPreference = WARNING_INDICATION_IN_OVERVIEW_RULER;
967         //    info.fEditorPreference = WARNING_INDICATION;
968         //    ANNOTATION_MAP.put(AnnotationType.WARNING, info);
969         //
970         //    info = new AnnotationInfo();
971         //    info.fColorPreference = BOOKMARK_INDICATION_COLOR;
972         //    info.fOverviewRulerPreference = BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
973         //    info.fEditorPreference = BOOKMARK_INDICATION;
974         //    ANNOTATION_MAP.put(AnnotationType.BOOKMARK, info);
975         //
976         //    info = new AnnotationInfo();
977         //    info.fColorPreference = SEARCH_RESULT_INDICATION_COLOR;
978         //    info.fOverviewRulerPreference =
979         // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
980         //    info.fEditorPreference = SEARCH_RESULT_INDICATION;
981         //    ANNOTATION_MAP.put(AnnotationType.SEARCH, info);
982         //
983         //    info = new AnnotationInfo();
984         //    info.fColorPreference = UNKNOWN_INDICATION_COLOR;
985         //    info.fOverviewRulerPreference = UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
986         //    info.fEditorPreference = UNKNOWN_INDICATION;
987         //    ANNOTATION_MAP.put(AnnotationType.UNKNOWN, info);
988         //  };
989         //
990         //  private final static AnnotationType[] ANNOTATION_LAYERS =
991         //    new AnnotationType[] {
992         //      AnnotationType.UNKNOWN,
993         //      AnnotationType.BOOKMARK,
994         //      AnnotationType.TASK,
995         //      AnnotationType.SEARCH,
996         //      AnnotationType.WARNING,
997         //      AnnotationType.ERROR };
998         /**
999          * Creates a new php unit editor.
1000          */
1001         public PHPUnitEditor() {
1002                 super();
1003                 setDocumentProvider(PHPeclipsePlugin.getDefault()
1004                                 .getCompilationUnitDocumentProvider());
1005                 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
1006                 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
1007                 setOutlinerContextMenuId("#PHPOutlinerContext"); //$NON-NLS-1$
1008                 // don't set help contextId, we install our own help context
1009                 fSavePolicy = null;
1010                 fJavaEditorErrorTickUpdater = new JavaEditorErrorTickUpdater(this);
1011         }
1012         /*
1013          * @see AbstractTextEditor#createActions()
1014          */
1015         protected void createActions() {
1016                 super.createActions();
1017                 Action action;
1018                 //              Action action= new
1019                 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1020                 // "CorrectionAssistProposal.", this, CORRECTIONASSIST_PROPOSALS);
1021                 // //$NON-NLS-1$
1022                 //              action.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
1023                 //              setAction("CorrectionAssistProposal", action); //$NON-NLS-1$
1024                 //              markAsStateDependentAction("CorrectionAssistProposal", true);
1025                 // //$NON-NLS-1$
1026                 //// WorkbenchHelp.setHelp(action,
1027                 // IJavaHelpContextIds.QUICK_FIX_ACTION);
1028                 action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(),
1029                                 "ContentAssistProposal.", this); //$NON-NLS-1$
1030                 action
1031                                 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
1032                 setAction("ContentAssistProposal", action); //$NON-NLS-1$
1033                 markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
1034                 //              WorkbenchHelp.setHelp(action,
1035                 // IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
1036                 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1037                                 "ContentAssistContextInformation.", this,
1038                                 ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$
1039                 action
1040                                 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
1041                 setAction("ContentAssistContextInformation", action); //$NON-NLS-1$
1042                 markAsStateDependentAction("ContentAssistContextInformation", true); //$NON-NLS-1$
1043                 //              WorkbenchHelp.setHelp(action,
1044                 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1045                 //              action= new
1046                 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1047                 // "ContentAssistCompletePrefix.", this, CONTENTASSIST_COMPLETE_PREFIX);
1048                 // //$NON-NLS-1$
1049                 //              action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_COMPLETE_PREFIX);
1050                 //              setAction("ContentAssistCompletePrefix", action); //$NON-NLS-1$
1051                 //              markAsStateDependentAction("ContentAssistCompletePrefix", true);
1052                 // //$NON-NLS-1$
1053                 //// WorkbenchHelp.setHelp(action,
1054                 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1055                 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1056                                 "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
1057                 action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
1058                 setAction("Comment", action); //$NON-NLS-1$
1059                 markAsStateDependentAction("Comment", true); //$NON-NLS-1$
1060                 //              WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
1061                 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1062                                 "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
1063                 action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
1064                 setAction("Uncomment", action); //$NON-NLS-1$
1065                 markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
1066                 //              WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
1067
1068                 action = new ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1069                                 "ToggleComment.", this); //$NON-NLS-1$
1070                 action
1071                                 .setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1072                 setAction("ToggleComment", action); //$NON-NLS-1$
1073                 markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1074                 //WorkbenchHelp.setHelp(action,
1075                 // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1076                 configureToggleCommentAction();
1077
1078                 //    action = new
1079                 // ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1080                 //        "ToggleComment.", this, getSourceViewerConfiguration()
1081                 //            .getDefaultPrefixes(getSourceViewer(), "")); //$NON-NLS-1$
1082                 // //$NON-NLS-2$
1083                 //    action.setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1084                 //    setAction("ToggleComment", action); //$NON-NLS-1$
1085                 //    markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1086                 //    // WorkbenchHelp.setHelp(action,
1087                 //    // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1088
1089                 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1090                                 "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
1091                 action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
1092                 setAction("Format", action); //$NON-NLS-1$
1093                 markAsStateDependentAction("Format", true); //$NON-NLS-1$
1094                 markAsSelectionDependentAction("Format", true); //$NON-NLS-1$           
1095                 //              WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
1096
1097                 action = new AddBlockCommentAction(PHPEditorMessages
1098                                 .getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$
1099                 action
1100                                 .setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
1101                 setAction("AddBlockComment", action); //$NON-NLS-1$
1102                 markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
1103                 markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$          
1104                 //              WorkbenchHelp.setHelp(action,
1105                 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1106                 action = new RemoveBlockCommentAction(PHPEditorMessages
1107                                 .getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
1108                 action
1109                                 .setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
1110                 setAction("RemoveBlockComment", action); //$NON-NLS-1$
1111                 markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1112                 markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$               
1113                 //              WorkbenchHelp.setHelp(action,
1114                 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1115                 //              action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1116                 // "Indent.", this, false); //$NON-NLS-1$
1117                 //              action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT);
1118                 //              setAction("Indent", action); //$NON-NLS-1$
1119                 //              markAsStateDependentAction("Indent", true); //$NON-NLS-1$
1120                 //              markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
1121                 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION);
1122                 //              
1123                 //              action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1124                 // "Indent.", this, true); //$NON-NLS-1$
1125                 //              setAction("IndentOnTab", action); //$NON-NLS-1$
1126                 //              markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
1127                 //              markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$
1128                 //              
1129                 if (getPreferenceStore().getBoolean(
1130                                 PreferenceConstants.EDITOR_SMART_TAB)) {
1131                         // don't replace Shift Right - have to make sure their enablement is
1132                         // mutually exclusive
1133                         //                      removeActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT);
1134                         setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$
1135                 }
1136                 fGenerateActionGroup = new GenerateActionGroup(this,
1137                                 ITextEditorActionConstants.GROUP_EDIT);
1138                 fActionGroups = new CompositeActionGroup(
1139                                 new ActionGroup[]{fGenerateActionGroup});
1140                 //        We have to keep the context menu group separate to have better
1141                 // control
1142                 // over positioning
1143                 fContextMenuGroup = new CompositeActionGroup(
1144                                 new ActionGroup[]{fGenerateActionGroup});
1145                 //      rg,
1146                 //      new LocalHistoryActionGroup(this,
1147                 // ITextEditorActionConstants.GROUP_EDIT)});
1148
1149         }
1150         /*
1151          * @see JavaEditor#getElementAt(int)
1152          */
1153         protected IJavaElement getElementAt(int offset) {
1154                 return getElementAt(offset, true);
1155         }
1156         /**
1157          * Returns the most narrow element including the given offset. If
1158          * <code>reconcile</code> is <code>true</code> the editor's input
1159          * element is reconciled in advance. If it is <code>false</code> this
1160          * method only returns a result if the editor's input element does not need
1161          * to be reconciled.
1162          * 
1163          * @param offset
1164          *            the offset included by the retrieved element
1165          * @param reconcile
1166          *            <code>true</code> if working copy should be reconciled
1167          */
1168         protected IJavaElement getElementAt(int offset, boolean reconcile) {
1169                 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1170                                 .getWorkingCopyManager();
1171                 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1172                 if (unit != null) {
1173                         try {
1174                                 if (reconcile) {
1175                                         synchronized (unit) {
1176                                                 unit.reconcile();
1177                                         }
1178                                         return unit.getElementAt(offset);
1179                                 } else if (unit.isConsistent())
1180                                         return unit.getElementAt(offset);
1181                         } catch (JavaModelException x) {
1182                                 PHPeclipsePlugin.log(x.getStatus());
1183                                 // nothing found, be tolerant and go on
1184                         }
1185                 }
1186                 return null;
1187         }
1188         /*
1189          * @see JavaEditor#getCorrespondingElement(IJavaElement)
1190          */
1191         protected IJavaElement getCorrespondingElement(IJavaElement element) {
1192                 try {
1193                         return EditorUtility.getWorkingCopy(element, true);
1194                 } catch (JavaModelException x) {
1195                         PHPeclipsePlugin.log(x.getStatus());
1196                         // nothing found, be tolerant and go on
1197                 }
1198                 return null;
1199         }
1200         public void createPartControl(Composite parent) {
1201                 super.createPartControl(parent);
1202                 //    fPaintManager = new PaintManager(getSourceViewer());
1203                 LinePainter linePainter;
1204                 linePainter = new LinePainter(getSourceViewer());
1205                 linePainter.setHighlightColor(new Color(Display.getCurrent(), 225, 235,
1206                                 224));
1207                 //    fPaintManager.addPainter(linePainter);
1208                 if (isBracketHighlightingEnabled())
1209                         startBracketHighlighting();
1210                 if (isLineHighlightingEnabled())
1211                         startLineHighlighting();
1212                 if (isPrintMarginVisible())
1213                         showPrintMargin();
1214                 //    Iterator e = ANNOTATION_MAP.keySet().iterator();
1215                 //    while (e.hasNext()) {
1216                 //      AnnotationType type = (AnnotationType) e.next();
1217                 //      if (isAnnotationIndicationEnabled(type))
1218                 //        startAnnotationIndication(type);
1219                 //    }
1220                 if (isTabConversionEnabled())
1221                         startTabConversion();
1222                 //    if (isOverviewRulerVisible())
1223                 //      showOverviewRuler();
1224                 //
1225                 //    Preferences preferences =
1226                 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1227                 //    preferences.addPropertyChangeListener(fPropertyChangeListener);
1228                 IPreferenceStore preferenceStore = getPreferenceStore();
1229                 boolean closeBracketsPHP = preferenceStore
1230                                 .getBoolean(CLOSE_BRACKETS_PHP);
1231                 boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP);
1232                 boolean closeBracketsHTML = preferenceStore
1233                                 .getBoolean(CLOSE_BRACKETS_HTML);
1234                 boolean closeStringsHTML = preferenceStore
1235                                 .getBoolean(CLOSE_STRINGS_HTML);
1236                 fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
1237                 fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP);
1238                 fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
1239                 fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
1240                 ISourceViewer sourceViewer = getSourceViewer();
1241                 if (sourceViewer instanceof ITextViewerExtension)
1242                         ((ITextViewerExtension) sourceViewer)
1243                                         .prependVerifyKeyListener(fBracketInserter);
1244         }
1245         private static char getPeerCharacter(char character) {
1246                 switch (character) {
1247                         case '(' :
1248                                 return ')';
1249                         case ')' :
1250                                 return '(';
1251                         case '[' :
1252                                 return ']';
1253                         case ']' :
1254                                 return '[';
1255                         case '"' :
1256                                 return character;
1257                         default :
1258                                 throw new IllegalArgumentException();
1259                 }
1260         }
1261
1262         private void startBracketHighlighting() {
1263                 if (fBracketPainter == null) {
1264                         ISourceViewer sourceViewer = getSourceViewer();
1265                         fBracketPainter = new BracketPainter(sourceViewer);
1266                         fBracketPainter
1267                                         .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1268                         //      fPaintManager.addPainter(fBracketPainter);
1269                 }
1270         }
1271         private void stopBracketHighlighting() {
1272                 if (fBracketPainter != null) {
1273                         //      fPaintManager.removePainter(fBracketPainter);
1274                         fBracketPainter.deactivate(true);
1275                         fBracketPainter.dispose();
1276                         fBracketPainter = null;
1277                 }
1278         }
1279         private boolean isBracketHighlightingEnabled() {
1280                 IPreferenceStore store = getPreferenceStore();
1281                 return store.getBoolean(MATCHING_BRACKETS);
1282         }
1283         private void startLineHighlighting() {
1284                 if (fLinePainter == null) {
1285                         ISourceViewer sourceViewer = getSourceViewer();
1286                         fLinePainter = new LinePainter(sourceViewer);
1287                         fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR));
1288                         //      fPaintManager.addPainter(fLinePainter);
1289                 }
1290         }
1291         private void stopLineHighlighting() {
1292                 if (fLinePainter != null) {
1293                         //      fPaintManager.removePainter(fLinePainter);
1294                         fLinePainter.deactivate(true);
1295                         fLinePainter.dispose();
1296                         fLinePainter = null;
1297                 }
1298         }
1299         private boolean isLineHighlightingEnabled() {
1300                 IPreferenceStore store = getPreferenceStore();
1301                 return store.getBoolean(CURRENT_LINE);
1302         }
1303         private void showPrintMargin() {
1304                 if (fPrintMarginPainter == null) {
1305                         fPrintMarginPainter = new PrintMarginPainter(getSourceViewer());
1306                         fPrintMarginPainter
1307                                         .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1308                         fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore()
1309                                         .getInt(PRINT_MARGIN_COLUMN));
1310                         //      fPaintManager.addPainter(fPrintMarginPainter);
1311                 }
1312         }
1313         private void hidePrintMargin() {
1314                 if (fPrintMarginPainter != null) {
1315                         //      fPaintManager.removePainter(fPrintMarginPainter);
1316                         fPrintMarginPainter.deactivate(true);
1317                         fPrintMarginPainter.dispose();
1318                         fPrintMarginPainter = null;
1319                 }
1320         }
1321         private boolean isPrintMarginVisible() {
1322                 IPreferenceStore store = getPreferenceStore();
1323                 return store.getBoolean(PRINT_MARGIN);
1324         }
1325         //  private void startAnnotationIndication(AnnotationType annotationType) {
1326         //    if (fProblemPainter == null) {
1327         //      fProblemPainter = new ProblemPainter(this, getSourceViewer());
1328         //// fPaintManager.addPainter(fProblemPainter);
1329         //    }
1330         //    fProblemPainter.setColor(annotationType, getColor(annotationType));
1331         //    fProblemPainter.paintAnnotations(annotationType, true);
1332         //    fProblemPainter.paint(IPainter.CONFIGURATION);
1333         //  }
1334         //
1335         //  private void shutdownAnnotationIndication() {
1336         //    if (fProblemPainter != null) {
1337         //
1338         //      if (!fProblemPainter.isPaintingAnnotations()) {
1339         //// fPaintManager.removePainter(fProblemPainter);
1340         //        fProblemPainter.deactivate(true);
1341         //        fProblemPainter.dispose();
1342         //        fProblemPainter = null;
1343         //      } else {
1344         //        fProblemPainter.paint(IPainter.CONFIGURATION);
1345         //      }
1346         //    }
1347         //  }
1348         //
1349         //  private void stopAnnotationIndication(AnnotationType annotationType) {
1350         //    if (fProblemPainter != null) {
1351         //      fProblemPainter.paintAnnotations(annotationType, false);
1352         //      shutdownAnnotationIndication();
1353         //    }
1354         //  }
1355         //
1356         //  private boolean isAnnotationIndicationEnabled(AnnotationType
1357         // annotationType) {
1358         //    IPreferenceStore store = getPreferenceStore();
1359         //    AnnotationInfo info = (AnnotationInfo)
1360         // ANNOTATION_MAP.get(annotationType);
1361         //    if (info != null)
1362         //      return store.getBoolean(info.fEditorPreference);
1363         //    return false;
1364         //  }
1365         //
1366         //  private boolean
1367         // isAnnotationIndicationInOverviewRulerEnabled(AnnotationType
1368         // annotationType) {
1369         //    IPreferenceStore store = getPreferenceStore();
1370         //    AnnotationInfo info = (AnnotationInfo)
1371         // ANNOTATION_MAP.get(annotationType);
1372         //    if (info != null)
1373         //      return store.getBoolean(info.fOverviewRulerPreference);
1374         //    return false;
1375         //  }
1376         //
1377         //  private void showAnnotationIndicationInOverviewRuler(AnnotationType
1378         // annotationType, boolean show) {
1379         //    AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1380         //    OverviewRuler ruler = asv.getOverviewRuler();
1381         //    if (ruler != null) {
1382         //      ruler.setColor(annotationType, getColor(annotationType));
1383         //      ruler.showAnnotation(annotationType, show);
1384         //      ruler.update();
1385         //    }
1386         //  }
1387         //
1388         //  private void setColorInOverviewRuler(AnnotationType annotationType, Color
1389         // color) {
1390         //    AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1391         //    OverviewRuler ruler = asv.getOverviewRuler();
1392         //    if (ruler != null) {
1393         //      ruler.setColor(annotationType, color);
1394         //      ruler.update();
1395         //    }
1396         //  }
1397
1398         private int getTabSize() {
1399                 Preferences preferences = PHPeclipsePlugin.getDefault()
1400                                 .getPluginPreferences();
1401                 return preferences.getInt(CODE_FORMATTER_TAB_SIZE);
1402         }
1403
1404         private boolean isTabConversionEnabled() {
1405                 IPreferenceStore store = getPreferenceStore();
1406                 return store.getBoolean(SPACES_FOR_TABS);
1407         }
1408         //  private void showOverviewRuler() {
1409         //    AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1410         //    asv.showOverviewRuler();
1411         //
1412         //    OverviewRuler overviewRuler = asv.getOverviewRuler();
1413         //    if (overviewRuler != null) {
1414         //      for (int i = 0; i < ANNOTATION_LAYERS.length; i++) {
1415         //        AnnotationType type = ANNOTATION_LAYERS[i];
1416         //        overviewRuler.setLayer(type, i);
1417         //        if (isAnnotationIndicationInOverviewRulerEnabled(type))
1418         //          showAnnotationIndicationInOverviewRuler(type, true);
1419         //      }
1420         //    }
1421         //  }
1422         //
1423         //  private void hideOverviewRuler() {
1424         //    AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1425         //    asv.hideOverviewRuler();
1426         //  }
1427         //
1428         //  private boolean isOverviewRulerVisible() {
1429         //    IPreferenceStore store = getPreferenceStore();
1430         //    return store.getBoolean(OVERVIEW_RULER);
1431         //  }
1432         private Color getColor(String key) {
1433                 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
1434                 return getColor(rgb);
1435         }
1436         private Color getColor(RGB rgb) {
1437                 JavaTextTools textTools = PHPeclipsePlugin.getDefault()
1438                                 .getJavaTextTools();
1439                 return textTools.getColorManager().getColor(rgb);
1440         }
1441         //  private Color getColor(AnnotationType annotationType) {
1442         //    AnnotationInfo info = (AnnotationInfo)
1443         // ANNOTATION_MAP.get(annotationType);
1444         //    if (info != null)
1445         //      return getColor(info.fColorPreference);
1446         //    return null;
1447         //  }
1448         public void dispose() {
1449                 ISourceViewer sourceViewer = getSourceViewer();
1450                 if (sourceViewer instanceof ITextViewerExtension)
1451                         ((ITextViewerExtension) sourceViewer)
1452                                         .removeVerifyKeyListener(fBracketInserter);
1453                 //    if (fPropertyChangeListener != null) {
1454                 //      Preferences preferences =
1455                 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1456                 //      preferences.removePropertyChangeListener(fPropertyChangeListener);
1457                 //      fPropertyChangeListener = null;
1458                 //    }
1459                 if (fJavaEditorErrorTickUpdater != null) {
1460                         fJavaEditorErrorTickUpdater.dispose();
1461                         fJavaEditorErrorTickUpdater = null;
1462                 }
1463                 //    if (fSelectionHistory != null)
1464                 //      fSelectionHistory.dispose();
1465                 //    if (fPaintManager != null) {
1466                 //      fPaintManager.dispose();
1467                 //      fPaintManager = null;
1468                 //    }
1469                 if (fActionGroups != null) {
1470                         fActionGroups.dispose();
1471                         fActionGroups = null;
1472                 }
1473                 super.dispose();
1474         }
1475         //  protected AnnotationType getAnnotationType(String preferenceKey) {
1476         //    Iterator e = ANNOTATION_MAP.keySet().iterator();
1477         //    while (e.hasNext()) {
1478         //      AnnotationType type = (AnnotationType) e.next();
1479         //      AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1480         //      if (info != null) {
1481         //        if (preferenceKey.equals(info.fColorPreference)
1482         //          || preferenceKey.equals(info.fEditorPreference)
1483         //          || preferenceKey.equals(info.fOverviewRulerPreference))
1484         //          return type;
1485         //      }
1486         //    }
1487         //    return null;
1488         //  }
1489         /*
1490          * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1491          */
1492         protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1493                 try {
1494                         AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1495                         if (asv != null) {
1496                                 String p = event.getProperty();
1497                                 if (CLOSE_BRACKETS_PHP.equals(p)) {
1498                                         fBracketInserter
1499                                                         .setCloseBracketsPHPEnabled(getPreferenceStore()
1500                                                                         .getBoolean(p));
1501                                         return;
1502                                 }
1503                                 if (CLOSE_STRINGS_PHP.equals(p)) {
1504                                         fBracketInserter
1505                                                         .setCloseStringsPHPEnabled(getPreferenceStore()
1506                                                                         .getBoolean(p));
1507                                         return;
1508                                 }
1509                                 if (CLOSE_BRACKETS_HTML.equals(p)) {
1510                                         fBracketInserter
1511                                                         .setCloseBracketsHTMLEnabled(getPreferenceStore()
1512                                                                         .getBoolean(p));
1513                                         return;
1514                                 }
1515                                 if (CLOSE_STRINGS_HTML.equals(p)) {
1516                                         fBracketInserter
1517                                                         .setCloseStringsHTMLEnabled(getPreferenceStore()
1518                                                                         .getBoolean(p));
1519                                         return;
1520                                 }
1521                                 if (SPACES_FOR_TABS.equals(p)) {
1522                                         if (isTabConversionEnabled())
1523                                                 startTabConversion();
1524                                         else
1525                                                 stopTabConversion();
1526                                         return;
1527                                 }
1528                                 if (MATCHING_BRACKETS.equals(p)) {
1529                                         if (isBracketHighlightingEnabled())
1530                                                 startBracketHighlighting();
1531                                         else
1532                                                 stopBracketHighlighting();
1533                                         return;
1534                                 }
1535                                 if (MATCHING_BRACKETS_COLOR.equals(p)) {
1536                                         if (fBracketPainter != null)
1537                                                 fBracketPainter
1538                                                                 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1539                                         return;
1540                                 }
1541                                 if (CURRENT_LINE.equals(p)) {
1542                                         if (isLineHighlightingEnabled())
1543                                                 startLineHighlighting();
1544                                         else
1545                                                 stopLineHighlighting();
1546                                         return;
1547                                 }
1548                                 if (CURRENT_LINE_COLOR.equals(p)) {
1549                                         if (fLinePainter != null) {
1550                                                 stopLineHighlighting();
1551                                                 startLineHighlighting();
1552                                         }
1553                                         return;
1554                                 }
1555                                 if (PRINT_MARGIN.equals(p)) {
1556                                         if (isPrintMarginVisible())
1557                                                 showPrintMargin();
1558                                         else
1559                                                 hidePrintMargin();
1560                                         return;
1561                                 }
1562                                 if (PRINT_MARGIN_COLOR.equals(p)) {
1563                                         if (fPrintMarginPainter != null)
1564                                                 fPrintMarginPainter
1565                                                                 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1566                                         return;
1567                                 }
1568                                 if (PRINT_MARGIN_COLUMN.equals(p)) {
1569                                         if (fPrintMarginPainter != null)
1570                                                 fPrintMarginPainter
1571                                                                 .setMarginRulerColumn(getPreferenceStore()
1572                                                                                 .getInt(PRINT_MARGIN_COLUMN));
1573                                         return;
1574                                 }
1575                                 //        if (OVERVIEW_RULER.equals(p)) {
1576                                 //          if (isOverviewRulerVisible())
1577                                 //            showOverviewRuler();
1578                                 //          else
1579                                 //            hideOverviewRuler();
1580                                 //          return;
1581                                 //        }
1582                                 //        AnnotationType type = getAnnotationType(p);
1583                                 //        if (type != null) {
1584                                 //
1585                                 //          AnnotationInfo info = (AnnotationInfo)
1586                                 // ANNOTATION_MAP.get(type);
1587                                 //          if (info.fColorPreference.equals(p)) {
1588                                 //            Color color = getColor(type);
1589                                 //            if (fProblemPainter != null) {
1590                                 //              fProblemPainter.setColor(type, color);
1591                                 //              fProblemPainter.paint(IPainter.CONFIGURATION);
1592                                 //            }
1593                                 //            setColorInOverviewRuler(type, color);
1594                                 //            return;
1595                                 //          }
1596                                 //
1597                                 //          if (info.fEditorPreference.equals(p)) {
1598                                 //            if (isAnnotationIndicationEnabled(type))
1599                                 //              startAnnotationIndication(type);
1600                                 //            else
1601                                 //              stopAnnotationIndication(type);
1602                                 //            return;
1603                                 //          }
1604                                 //
1605                                 //          if (info.fOverviewRulerPreference.equals(p)) {
1606                                 //            if (isAnnotationIndicationInOverviewRulerEnabled(type))
1607                                 //              showAnnotationIndicationInOverviewRuler(type, true);
1608                                 //            else
1609                                 //              showAnnotationIndicationInOverviewRuler(type, false);
1610                                 //            return;
1611                                 //          }
1612                                 //        }
1613                                 IContentAssistant c = asv.getContentAssistant();
1614                                 if (c instanceof ContentAssistant)
1615                                         ContentAssistPreference.changeConfiguration(
1616                                                         (ContentAssistant) c, getPreferenceStore(), event);
1617                         }
1618                 } finally {
1619                         super.handlePreferenceStoreChanged(event);
1620                 }
1621         }
1622         /*
1623          * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
1624          */
1625         protected void handlePreferencePropertyChanged(
1626                         org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1627                 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1628                 if (asv != null) {
1629                         String p = event.getProperty();
1630                         if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1631                                 asv.updateIndentationPrefixes();
1632                                 if (fTabConverter != null)
1633                                         fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1634                         }
1635                 }
1636                 super.handlePreferencePropertyChanged(event);
1637         }
1638         /**
1639          * Handles a property change event describing a change of the php core's
1640          * preferences and updates the preference related editor properties.
1641          * 
1642          * @param event
1643          *            the property change event
1644          */
1645         //  protected void
1646         // handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
1647         // event) {
1648         //    AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1649         //    if (asv != null) {
1650         //      String p = event.getProperty();
1651         //      if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1652         //        asv.updateIndentationPrefixes();
1653         //        if (fTabConverter != null)
1654         //          fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1655         //      }
1656         //    }
1657         //  }
1658         /*
1659          * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#createJavaSourceViewer(org.eclipse.swt.widgets.Composite,
1660          *      org.eclipse.jface.text.source.IVerticalRuler,
1661          *      org.eclipse.jface.text.source.IOverviewRuler, boolean, int)
1662          */
1663         protected ISourceViewer createJavaSourceViewer(Composite parent,
1664                         IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
1665                         boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
1666                 return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler,
1667                                 isOverviewRulerVisible, styles, store);
1668         }
1669         //  protected ISourceViewer createJavaSourceViewer(Composite parent,
1670         // IVerticalRuler ruler, int styles) {
1671         //    return new AdaptedSourceViewer(parent, ruler, styles);
1672         //  }
1673         private boolean isValidSelection(int offset, int length) {
1674                 IDocumentProvider provider = getDocumentProvider();
1675                 if (provider != null) {
1676                         IDocument document = provider.getDocument(getEditorInput());
1677                         if (document != null) {
1678                                 int end = offset + length;
1679                                 int documentLength = document.getLength();
1680                                 return 0 <= offset && offset <= documentLength && 0 <= end
1681                                                 && end <= documentLength;
1682                         }
1683                 }
1684                 return false;
1685         }
1686         /*
1687          * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput)
1688          */
1689         protected boolean canHandleMove(IEditorInput originalElement,
1690                         IEditorInput movedElement) {
1691                 String oldExtension = ""; //$NON-NLS-1$
1692                 if (originalElement instanceof IFileEditorInput) {
1693                         IFile file = ((IFileEditorInput) originalElement).getFile();
1694                         if (file != null) {
1695                                 String ext = file.getFileExtension();
1696                                 if (ext != null)
1697                                         oldExtension = ext;
1698                         }
1699                 }
1700                 String newExtension = ""; //$NON-NLS-1$
1701                 if (movedElement instanceof IFileEditorInput) {
1702                         IFile file = ((IFileEditorInput) movedElement).getFile();
1703                         if (file != null)
1704                                 newExtension = file.getFileExtension();
1705                 }
1706                 return oldExtension.equals(newExtension);
1707         }
1708         /*
1709          * @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager)
1710          */
1711         public void editorContextMenuAboutToShow(IMenuManager menu) {
1712                 super.editorContextMenuAboutToShow(menu);
1713                 ActionContext context = new ActionContext(getSelectionProvider()
1714                                 .getSelection());
1715                 fContextMenuGroup.setContext(context);
1716                 fContextMenuGroup.fillContextMenu(menu);
1717                 fContextMenuGroup.setContext(null);
1718         }
1719         /*
1720          * @see JavaEditor#setOutlinePageInput(JavaOutlinePage, IEditorInput)
1721          */
1722         protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input) {
1723                 if (page != null) {
1724                         IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1725                                         .getWorkingCopyManager();
1726                         page.setInput(manager.getWorkingCopy(input));
1727                 }
1728         }
1729         /*
1730          * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation,
1731          *      IProgressMonitor)
1732          */
1733         //  protected void performSaveOperation(WorkspaceModifyOperation operation,
1734         // IProgressMonitor progressMonitor) {
1735         //    IDocumentProvider p = getDocumentProvider();
1736         //    if (p instanceof PHPDocumentProvider) {
1737         //      PHPDocumentProvider cp = (PHPDocumentProvider) p;
1738         //      cp.setSavePolicy(fSavePolicy);
1739         //    }
1740         //
1741         //    try {
1742         //      super.performSaveOperation(operation, progressMonitor);
1743         //    } finally {
1744         //      if (p instanceof PHPDocumentProvider) {
1745         //        PHPDocumentProvider cp = (PHPDocumentProvider) p;
1746         //        cp.setSavePolicy(null);
1747         //      }
1748         //    }
1749         //  }
1750         /*
1751          * @see AbstractTextEditor#doSave(IProgressMonitor)
1752          */
1753         public void doSave(IProgressMonitor progressMonitor) {
1754
1755                 IDocumentProvider p = getDocumentProvider();
1756                 if (p == null) {
1757                         // editor has been closed
1758                         return;
1759                 }
1760
1761                 if (p.isDeleted(getEditorInput())) {
1762
1763                         if (isSaveAsAllowed()) {
1764
1765                                 /*
1766                                  * 1GEUSSR: ITPUI:ALL - User should never loose changes made in
1767                                  * the editors. Changed Behavior to make sure that if called
1768                                  * inside a regular save (because of deletion of input element)
1769                                  * there is a way to report back to the caller.
1770                                  */
1771                                 performSaveAs(progressMonitor);
1772
1773                         } else {
1774
1775                                 /*
1776                                  * 1GF5YOX: ITPJUI:ALL - Save of delete file claims it's still
1777                                  * there Missing resources.
1778                                  */
1779                                 Shell shell = getSite().getShell();
1780                                 MessageDialog
1781                                                 .openError(
1782                                                                 shell,
1783                                                                 PHPEditorMessages
1784                                                                                 .getString("PHPUnitEditor.error.saving.title1"), PHPEditorMessages.getString("PHPUnitEditor.error.saving.message1")); //$NON-NLS-1$ //$NON-NLS-2$
1785                         }
1786
1787                 } else {
1788
1789                         setStatusLineErrorMessage(null);
1790
1791                         IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1792                                         .getWorkingCopyManager();
1793                         ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1794
1795                         if (unit != null) {
1796                                 synchronized (unit) {
1797                                         performSave(false, progressMonitor);
1798                                 }
1799                         } else
1800                                 performSave(false, progressMonitor);
1801                 }
1802                 ShowExternalPreviewAction a = ShowExternalPreviewAction.getInstance();
1803                 if (a != null) {
1804                         a.refresh();
1805                 }
1806         }
1807
1808         public boolean isSaveAsAllowed() {
1809                 return true;
1810         }
1811
1812         /**
1813          * The compilation unit editor implementation of this
1814          * <code>AbstractTextEditor</code> method asks the user for the workspace
1815          * path of a file resource and saves the document there. See
1816          * http://dev.eclipse.org/bugs/show_bug.cgi?id=6295
1817          * 
1818          * @param progressMonitor
1819          *            the progress monitor
1820          */
1821         protected void performSaveAs(IProgressMonitor progressMonitor) {
1822
1823                 Shell shell = getSite().getShell();
1824                 IEditorInput input = getEditorInput();
1825
1826                 SaveAsDialog dialog = new SaveAsDialog(shell);
1827
1828                 IFile original = (input instanceof IFileEditorInput)
1829                                 ? ((IFileEditorInput) input).getFile()
1830                                 : null;
1831                 if (original != null)
1832                         dialog.setOriginalFile(original);
1833
1834                 dialog.create();
1835
1836                 IDocumentProvider provider = getDocumentProvider();
1837                 if (provider == null) {
1838                         // editor has been programmatically closed while the dialog was open
1839                         return;
1840                 }
1841
1842                 if (provider.isDeleted(input) && original != null) {
1843                         String message = PHPEditorMessages
1844                                         .getFormattedString(
1845                                                         "CompilationUnitEditor.warning.save.delete", new Object[]{original.getName()}); //$NON-NLS-1$
1846                         dialog.setErrorMessage(null);
1847                         dialog.setMessage(message, IMessageProvider.WARNING);
1848                 }
1849
1850                 if (dialog.open() == Window.CANCEL) {
1851                         if (progressMonitor != null)
1852                                 progressMonitor.setCanceled(true);
1853                         return;
1854                 }
1855
1856                 IPath filePath = dialog.getResult();
1857                 if (filePath == null) {
1858                         if (progressMonitor != null)
1859                                 progressMonitor.setCanceled(true);
1860                         return;
1861                 }
1862
1863                 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1864                 IFile file = workspaceRoot.getFile(filePath);
1865                 final IEditorInput newInput = new FileEditorInput(file);
1866
1867                 boolean success = false;
1868                 try {
1869
1870                         provider.aboutToChange(newInput);
1871                         getDocumentProvider().saveDocument(progressMonitor, newInput,
1872                                         getDocumentProvider().getDocument(getEditorInput()), true);
1873                         success = true;
1874
1875                 } catch (CoreException x) {
1876                         IStatus status = x.getStatus();
1877                         if (status == null || status.getSeverity() != IStatus.CANCEL)
1878                                 ErrorDialog
1879                                                 .openError(
1880                                                                 shell,
1881                                                                 PHPEditorMessages
1882                                                                                 .getString("CompilationUnitEditor.error.saving.title2"), PHPEditorMessages.getString("CompilationUnitEditor.error.saving.message2"), x.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
1883                 } finally {
1884                         provider.changed(newInput);
1885                         if (success)
1886                                 setInput(newInput);
1887                 }
1888
1889                 if (progressMonitor != null)
1890                         progressMonitor.setCanceled(!success);
1891         }
1892
1893         /*
1894          * @see AbstractTextEditor#doSetInput(IEditorInput)
1895          */
1896         protected void doSetInput(IEditorInput input) throws CoreException {
1897                 super.doSetInput(input);
1898                 configureTabConverter();
1899                 configureToggleCommentAction();
1900         }
1901
1902         //      /*
1903         //       * @see
1904         // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#installOverrideIndicator(boolean)
1905         //       * @since 3.0
1906         //       */
1907         //      protected void installOverrideIndicator(boolean waitForReconcilation) {
1908         //              IAnnotationModel model=
1909         // getDocumentProvider().getAnnotationModel(getEditorInput());
1910         //              if (!waitForReconcilation)
1911         //                      super.installOverrideIndicator(false);
1912         //              else {
1913         //                      uninstallOverrideIndicator();
1914         //                      IJavaElement inputElement= getInputJavaElement();
1915         //                      if (model == null || inputElement == null)
1916         //                              return;
1917         //                      
1918         //                      fOverrideIndicatorManager= new OverrideIndicatorManager(model,
1919         // inputElement, null);
1920         //                      addReconcileListener(fOverrideIndicatorManager);
1921         //              }
1922         //      }
1923         //      
1924         //      /*
1925         //       * @see
1926         // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#uninstallOverrideIndicator()
1927         //       * @since 3.0
1928         //       */
1929         //      protected void uninstallOverrideIndicator() {
1930         //              if (fOverrideIndicatorManager != null)
1931         //                      removeReconcileListener(fOverrideIndicatorManager);
1932         //              super.uninstallOverrideIndicator();
1933         //      }
1934
1935         /**
1936          * Configures the toggle comment action
1937          * 
1938          * @since 3.0
1939          */
1940         private void configureToggleCommentAction() {
1941                 IAction action = getAction("ToggleComment"); //$NON-NLS-1$
1942                 if (action instanceof ToggleCommentAction) {
1943                         ISourceViewer sourceViewer = getSourceViewer();
1944                         SourceViewerConfiguration configuration = getSourceViewerConfiguration();
1945                         ((ToggleCommentAction) action).configure(sourceViewer,
1946                                         configuration);
1947                 }
1948         }
1949
1950         private void configureTabConverter() {
1951                 if (fTabConverter != null) {
1952                         IDocumentProvider provider = getDocumentProvider();
1953                         if (provider instanceof PHPDocumentProvider) {
1954                                 PHPDocumentProvider cup = (PHPDocumentProvider) provider;
1955                                 fTabConverter.setLineTracker(cup
1956                                                 .createLineTracker(getEditorInput()));
1957                         }
1958                 }
1959         }
1960
1961         private void startTabConversion() {
1962                 if (fTabConverter == null) {
1963                         fTabConverter = new TabConverter();
1964                         configureTabConverter();
1965                         fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1966                         AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1967                         asv.addTextConverter(fTabConverter);
1968                         // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1969                         asv.updateIndentationPrefixes();
1970                 }
1971         }
1972
1973         private void stopTabConversion() {
1974                 if (fTabConverter != null) {
1975                         AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1976                         asv.removeTextConverter(fTabConverter);
1977                         // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1978                         asv.updateIndentationPrefixes();
1979                         fTabConverter = null;
1980                 }
1981         }
1982
1983         /*
1984          * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean,
1985          *      org.eclipse.core.runtime.IProgressMonitor)
1986          */
1987         protected void performSave(boolean overwrite,
1988                         IProgressMonitor progressMonitor) {
1989                 IDocumentProvider p = getDocumentProvider();
1990                 if (p instanceof PHPDocumentProvider) {
1991                         PHPDocumentProvider cp = (PHPDocumentProvider) p;
1992                         cp.setSavePolicy(fSavePolicy);
1993                 }
1994                 try {
1995                         super.performSave(overwrite, progressMonitor);
1996                 } finally {
1997                         if (p instanceof PHPDocumentProvider) {
1998                                 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1999                                 cp.setSavePolicy(null);
2000                         }
2001                 }
2002         }
2003         /*
2004          * @see AbstractTextEditor#doSaveAs
2005          */
2006         public void doSaveAs() {
2007                 if (askIfNonWorkbenchEncodingIsOk()) {
2008                         super.doSaveAs();
2009                 }
2010         }
2011
2012         /**
2013          * Asks the user if it is ok to store in non-workbench encoding.
2014          * 
2015          * @return <true>if the user wants to continue
2016          */
2017         private boolean askIfNonWorkbenchEncodingIsOk() {
2018                 IDocumentProvider provider = getDocumentProvider();
2019                 if (provider instanceof IStorageDocumentProvider) {
2020                         IEditorInput input = getEditorInput();
2021                         IStorageDocumentProvider storageProvider = (IStorageDocumentProvider) provider;
2022                         String encoding = storageProvider.getEncoding(input);
2023                         String defaultEncoding = storageProvider.getDefaultEncoding();
2024                         if (encoding != null && !encoding.equals(defaultEncoding)) {
2025                                 Shell shell = getSite().getShell();
2026                                 String title = PHPEditorMessages
2027                                                 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$
2028                                 String msg;
2029                                 if (input != null)
2030                                         msg = MessageFormat
2031                                                         .format(
2032                                                                         PHPEditorMessages
2033                                                                                         .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"),
2034                                                                         new String[]{input.getName(), encoding}); //$NON-NLS-1$
2035                                 else
2036                                         msg = MessageFormat
2037                                                         .format(
2038                                                                         PHPEditorMessages
2039                                                                                         .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message2"),
2040                                                                         new String[]{encoding}); //$NON-NLS-1$
2041                                 return MessageDialog.openQuestion(shell, title, msg);
2042                         }
2043                 }
2044                 return true;
2045         }
2046         /*
2047          * @see IReconcilingParticipant#reconciled()
2048          */
2049         public void reconciled() {
2050                 if (synchronizeOutlineOnCursorMove()) {
2051                         Shell shell = getSite().getShell();
2052                         if (shell != null && !shell.isDisposed()) {
2053                                 shell.getDisplay().asyncExec(new Runnable() {
2054                                         public void run() {
2055                                                 synchronizeOutlinePageSelection();
2056                                         }
2057                                 });
2058                         }
2059                 }
2060         }
2061
2062         protected void updateStateDependentActions() {
2063                 super.updateStateDependentActions();
2064                 fGenerateActionGroup.editorStateChanged();
2065         }
2066
2067         private boolean synchronizeOutlineOnCursorMove() {
2068                 return PreferenceConstants.getPreferenceStore().getBoolean(
2069                                 PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE);
2070         }
2071
2072         /**
2073          * Returns the updated java element for the old java element.
2074          */
2075         private IJavaElement findElement(IJavaElement element) {
2076                 if (element == null)
2077                         return null;
2078                 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
2079                                 .getWorkingCopyManager();
2080                 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
2081                 if (unit != null) {
2082                         try {
2083                                 synchronized (unit) {
2084                                         unit.reconcile();
2085                                 }
2086                                 IJavaElement[] findings = unit.findElements(element);
2087                                 if (findings != null && findings.length > 0)
2088                                         return findings[0];
2089                         } catch (JavaModelException x) {
2090                                 PHPeclipsePlugin.log(x.getStatus());
2091                                 // nothing found, be tolerant and go on
2092                         }
2093                 }
2094                 return null;
2095         }
2096         /**
2097          * Returns the offset of the given Java element.
2098          */
2099         private int getOffset(IJavaElement element) {
2100                 if (element instanceof ISourceReference) {
2101                         ISourceReference sr = (ISourceReference) element;
2102                         try {
2103                                 ISourceRange srcRange = sr.getSourceRange();
2104                                 if (srcRange != null)
2105                                         return srcRange.getOffset();
2106                         } catch (JavaModelException e) {
2107                         }
2108                 }
2109                 return -1;
2110         }
2111         /*
2112          * @see AbstractTextEditor#rememberSelection()
2113          */
2114         protected void rememberSelection() {
2115                 ISelectionProvider sp = getSelectionProvider();
2116                 fRememberedSelection = (sp == null ? null : (ITextSelection) sp
2117                                 .getSelection());
2118                 if (fRememberedSelection != null) {
2119                         fRememberedElement = getElementAt(fRememberedSelection.getOffset(),
2120                                         true);
2121                         fRememberedElementOffset = getOffset(fRememberedElement);
2122                 }
2123         }
2124         /*
2125          * @see AbstractTextEditor#restoreSelection()
2126          */
2127         protected void restoreSelection() {
2128                 try {
2129                         if (getSourceViewer() == null || fRememberedSelection == null)
2130                                 return;
2131                         IJavaElement newElement = findElement(fRememberedElement);
2132                         int newOffset = getOffset(newElement);
2133                         int delta = (newOffset > -1 && fRememberedElementOffset > -1)
2134                                         ? newOffset - fRememberedElementOffset
2135                                         : 0;
2136                         if (isValidSelection(delta + fRememberedSelection.getOffset(),
2137                                         fRememberedSelection.getLength()))
2138                                 selectAndReveal(delta + fRememberedSelection.getOffset(),
2139                                                 fRememberedSelection.getLength());
2140                 } finally {
2141                         fRememberedSelection = null;
2142                         fRememberedElement = null;
2143                         fRememberedElementOffset = -1;
2144                 }
2145         }
2146
2147         //      /*
2148         //       * @see
2149         // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
2150         //       * @since 3.0
2151         //       */
2152         //      public void aboutToBeReconciled() {
2153         //
2154         //              // Notify AST provider
2155         //              PHPeclipsePlugin.getDefault().getASTProvider().aboutToBeReconciled(getInputJavaElement());
2156         //              
2157         //              // Notify listeners
2158         //              Object[] listeners = fReconcilingListeners.getListeners();
2159         //              for (int i = 0, length= listeners.length; i < length; ++i)
2160         //                      ((IJavaReconcilingListener)listeners[i]).aboutToBeReconciled();
2161         //      }
2162         //      
2163         //      /*
2164         //       * @see
2165         // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit,
2166         // boolean, IProgressMonitor)
2167         //       * @since 3.0
2168         //       */
2169         //      public void reconciled(net.sourceforge.phpdt.core.dom.CompilationUnit
2170         // ast, boolean forced, IProgressMonitor progressMonitor) {
2171         //
2172         //              // Always notify AST provider
2173         //              PHPeclipsePlugin.getDefault().getASTProvider().reconciled(ast,
2174         // getInputJavaElement());
2175         //              
2176         //              // Notify listeners
2177         //              Object[] listeners = fReconcilingListeners.getListeners();
2178         //              for (int i = 0, length= listeners.length; i < length; ++i)
2179         //                      ((IJavaReconcilingListener)listeners[i]).reconciled(ast, forced,
2180         // progressMonitor);
2181         //
2182         //              // Update Java Outline page selection
2183         //              if (!forced && !progressMonitor.isCanceled()) {
2184         //                      Shell shell= getSite().getShell();
2185         //                      if (shell != null && !shell.isDisposed()) {
2186         //                              shell.getDisplay().asyncExec(new Runnable() {
2187         //                                      public void run() {
2188         //                                              selectionChanged();
2189         //                                      }
2190         //                              });
2191         //                      }
2192         //              }
2193         //      }
2194 }