misc parser changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPSourceViewerConfiguration.java
1 /**********************************************************************
2  Copyright (c) 2000, 2002 IBM Corp. and others.
3  All rights reserved. This program and the accompanying materials
4  are made available under the terms of the Common Public License v1.0
5  which accompanies this distribution, and is available at
6  http://www.eclipse.org/legal/cpl-v10.html
7
8  Contributors:
9  IBM Corporation - Initial implementation
10  Klaus Hartlage - www.eclipseproject.de
11  **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
13 import java.util.Vector;
14 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
15 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
16 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
17 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
18 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
19 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
20 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
21 import net.sourceforge.phpdt.internal.ui.text.java.JavaReconcilingStrategy;
22 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
23 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
24 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
25 import net.sourceforge.phpdt.ui.PreferenceConstants;
26 import net.sourceforge.phpdt.ui.text.JavaTextTools;
27 import net.sourceforge.phpeclipse.PHPCore;
28 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
29 import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
30 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
31 import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
32 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
33 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
34 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
35 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
36 import org.eclipse.core.resources.IFile;
37 import org.eclipse.core.runtime.NullProgressMonitor;
38 import org.eclipse.jface.preference.IPreferenceStore;
39 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
40 import org.eclipse.jface.text.DefaultInformationControl;
41 import org.eclipse.jface.text.IAutoIndentStrategy;
42 import org.eclipse.jface.text.IDocument;
43 import org.eclipse.jface.text.IInformationControl;
44 import org.eclipse.jface.text.IInformationControlCreator;
45 import org.eclipse.jface.text.ITextDoubleClickStrategy;
46 import org.eclipse.jface.text.ITextHover;
47 import org.eclipse.jface.text.ITextViewerExtension2;
48 import org.eclipse.jface.text.TextAttribute;
49 import org.eclipse.jface.text.contentassist.ContentAssistant;
50 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
51 import org.eclipse.jface.text.contentassist.IContentAssistant;
52 import org.eclipse.jface.text.formatter.ContentFormatter;
53 import org.eclipse.jface.text.formatter.IContentFormatter;
54 import org.eclipse.jface.text.formatter.IFormattingStrategy;
55 import org.eclipse.jface.text.information.IInformationPresenter;
56 import org.eclipse.jface.text.information.IInformationProvider;
57 import org.eclipse.jface.text.information.InformationPresenter;
58 import org.eclipse.jface.text.presentation.IPresentationReconciler;
59 import org.eclipse.jface.text.presentation.PresentationReconciler;
60 import org.eclipse.jface.text.reconciler.IReconciler;
61 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
62 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
63 import org.eclipse.jface.text.rules.DefaultPartitioner;
64 import org.eclipse.jface.text.rules.RuleBasedScanner;
65 import org.eclipse.jface.text.rules.Token;
66 import org.eclipse.jface.text.source.IAnnotationHover;
67 import org.eclipse.jface.text.source.ISourceViewer;
68 import org.eclipse.jface.text.source.SourceViewerConfiguration;
69 import org.eclipse.swt.SWT;
70 import org.eclipse.swt.widgets.Shell;
71 import org.eclipse.ui.IEditorInput;
72 import org.eclipse.ui.IFileEditorInput;
73 /**
74  * Configuration for an <code>SourceViewer</code> which shows PHP code.
75  */
76 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
77         /**
78          * Preference key used to look up display tab width.
79          * 
80          * @since 2.0
81          */
82         public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
83         /**
84          * Preference key for inserting spaces rather than tabs.
85          * 
86          * @since 2.0
87          */
88         public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
89         //  public static final String HTML_DEFAULT =
90         // IPHPPartitionScannerConstants.HTML;
91         //IDocument.DEFAULT_CONTENT_TYPE;
92         private JavaTextTools fJavaTextTools;
93         private PHPEditor fEditor;
94         private ContentFormatter fFormatter;
95         private HTMLFormattingStrategy fFormattingStrategy;
96         /**
97          * Single token scanner.
98          */
99         static class SingleTokenScanner extends BufferedRuleBasedScanner {
100                 public SingleTokenScanner(TextAttribute attribute) {
101                         setDefaultReturnToken(new Token(attribute));
102                 }
103         };
104         /**
105          * Default constructor.
106          */
107         public PHPSourceViewerConfiguration(JavaTextTools textTools,
108                         PHPEditor editor) {
109                 fJavaTextTools = textTools;
110                 fEditor = editor;
111         }
112         /*
113          * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
114          */
115         public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
116                 //    if (fFormatter == null) {
117                 //      fFormatter = new ContentFormatter();
118                 //      fFormattingStrategy = new HTMLFormattingStrategy(this,
119                 // sourceViewer);
120                 //      fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
121                 //      fFormatter.enablePartitionAwareFormatting(false);
122                 //      fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
123                 //    }
124                 //    return fFormatter;
125                 if (fFormatter == null) {
126                         //ContentFormatter
127                         fFormatter = new ContentFormatter();
128                         IFormattingStrategy strategy = new JavaFormattingStrategy(
129                                         sourceViewer);
130                         fFormatter.setFormattingStrategy(strategy,
131                                         IDocument.DEFAULT_CONTENT_TYPE);
132                         fFormatter.enablePartitionAwareFormatting(false);
133                         fFormatter
134                                         .setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
135                 }
136                 return fFormatter;
137         }
138         /**
139          * Returns the names of the document position categories used by the
140          * document partitioners created by this object to manage their partition
141          * information. If the partitioners don't use document position categories,
142          * the returned result is <code>null</code>.
143          * 
144          * @return the partition managing position categories or <code>null</code>
145          *         if there is none
146          */
147         public String[] getPartitionManagingPositionCategories() {
148                 return new String[]{DefaultPartitioner.CONTENT_TYPES_CATEGORY};
149         }
150         //  /**
151         //   * Returns the names of the document position categories used by the
152         // document
153         //   * partitioners created by this object to manage their partition
154         // information.
155         //   * If the partitioners don't use document position categories, the
156         // returned
157         //   * result is <code>null</code>.
158         //   *
159         //   * @return the partition managing position categories or
160         // <code>null</code>
161         //   * if there is none
162         //   */
163         //  private String[] getPartitionManagingPositionCategories() {
164         //    return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
165         //  }
166         public PHPEditor getEditor() {
167                 return fEditor;
168         }
169         /**
170          * Returns the preference store used by this configuration to initialize
171          * the individual bits and pieces.
172          * 
173          * @return the preference store used to initialize this configuration
174          * 
175          * @since 2.0
176          */
177         protected IPreferenceStore getPreferenceStore() {
178                 return PHPeclipsePlugin.getDefault().getPreferenceStore();
179         }
180         //  /* (non-Javadoc)
181         //   * Method declared on SourceViewerConfiguration
182         //   */
183         //  public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
184         //    return new PHPAnnotationHover();
185         //  }
186         /*
187          * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
188          */
189         public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
190                 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
191         }
192         /*
193          * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
194          * @since 3.0
195          */
196         public IAnnotationHover getOverviewRulerAnnotationHover(
197                         ISourceViewer sourceViewer) {
198                 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
199         }
200         /*
201          * (non-Javadoc) Method declared on SourceViewerConfiguration
202          */
203         public IAutoIndentStrategy getAutoIndentStrategy(
204                         ISourceViewer sourceViewer, String contentType) {
205                 return (IPHPPartitionScannerConstants.PHP.equals(contentType)
206                                 ? new PHPAutoIndentStrategy()
207                                 : new DefaultAutoIndentStrategy());
208         }
209         /**
210          * Returns the PHP source code scanner for this configuration.
211          * 
212          * @return the PHP source code scanner
213          */
214         protected RuleBasedScanner getCodeScanner() {
215                 return fJavaTextTools.getCodeScanner();
216         }
217         /**
218          * Returns the HTML source code scanner for this configuration.
219          * 
220          * @return the HTML source code scanner
221          */
222         protected RuleBasedScanner getHTMLScanner() {
223                 return fJavaTextTools.getHTMLScanner();
224         }
225         /**
226          * Returns the Smarty source code scanner for this configuration.
227          * 
228          * @return the Smarty source code scanner
229          */
230         protected RuleBasedScanner getSmartyScanner() {
231                 return fJavaTextTools.getSmartyScanner();
232         }
233         /*
234          * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
235          */
236         public IReconciler getReconciler(ISourceViewer sourceViewer) {
237                 if (getEditor() != null && getEditor().isEditable()) {
238                         JavaReconciler reconciler = new JavaReconciler(getEditor(),
239                                         new JavaReconcilingStrategy(getEditor()), false);
240                         reconciler.setProgressMonitor(new NullProgressMonitor());
241                         reconciler.setDelay(500);
242                         return reconciler;
243                 }
244                 return null;
245         }
246         /*
247          * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer,
248          *      String)
249          * @since 2.1
250          */
251         public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer,
252                         String contentType) {
253                 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
254                                 .getDefault().getJavaEditorTextHoverDescriptors();
255                 int stateMasks[] = new int[hoverDescs.length];
256                 int stateMasksLength = 0;
257                 for (int i = 0; i < hoverDescs.length; i++) {
258                         if (hoverDescs[i].isEnabled()) {
259                                 int j = 0;
260                                 int stateMask = hoverDescs[i].getStateMask();
261                                 while (j < stateMasksLength) {
262                                         if (stateMasks[j] == stateMask)
263                                                 break;
264                                         j++;
265                                 }
266                                 if (j == stateMasksLength)
267                                         stateMasks[stateMasksLength++] = stateMask;
268                         }
269                 }
270                 if (stateMasksLength == hoverDescs.length)
271                         return stateMasks;
272                 int[] shortenedStateMasks = new int[stateMasksLength];
273                 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0,
274                                 stateMasksLength);
275                 return shortenedStateMasks;
276         }
277         /*
278          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
279          * @since 2.1
280          */
281         public ITextHover getTextHover(ISourceViewer sourceViewer,
282                         String contentType, int stateMask) {
283                 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
284                                 .getDefault().getJavaEditorTextHoverDescriptors();
285                 int i = 0;
286                 while (i < hoverDescs.length) {
287                         if (hoverDescs[i].isEnabled()
288                                         && hoverDescs[i].getStateMask() == stateMask)
289                                 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
290                         i++;
291                 }
292                 return null;
293 //              if (fEditor != null) {
294 //                      IEditorInput editorInput = fEditor.getEditorInput();
295 //                      if (editorInput instanceof IFileEditorInput) {
296 //                              try {
297 //                                      IFile f = ((IFileEditorInput) editorInput).getFile();
298 //                                      return new PHPTextHover(f.getProject());
299 //                              } catch (NullPointerException e) {
300 //                                      // this exception occurs, if getTextHover is called by
301 //                                      // preference pages !
302 //                              }
303 //                      }
304 //              }
305 //              return new PHPTextHover(null);
306         }
307         /*
308          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
309          */
310         public ITextHover getTextHover(ISourceViewer sourceViewer,
311                         String contentType) {
312                 return getTextHover(sourceViewer, contentType,
313                                 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
314         }
315         /**
316          * Returns the SmartyDoc source code scanner for this configuration.
317          * 
318          * @return the SmartyDoc source code scanner
319          */
320         protected RuleBasedScanner getSmartyDocScanner() {
321                 return fJavaTextTools.getSmartyDocScanner();
322         }
323         /**
324          * Returns the PHPDoc source code scanner for this configuration.
325          * 
326          * @return the PHPDoc source code scanner
327          */
328         protected RuleBasedScanner getPHPDocScanner() {
329                 return fJavaTextTools.getJavaDocScanner();
330         }
331         /*
332          * (non-Javadoc) Method declared on SourceViewerConfiguration
333          */
334         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
335                 return new String[]{IPHPPartitionScannerConstants.HTML,
336                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
337                                 IPHPPartitionScannerConstants.PHP,
338                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
339                                 IPHPPartitionScannerConstants.CSS,
340                                 IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT,
341                                 IPHPPartitionScannerConstants.JAVASCRIPT,
342                                 IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT,
343                                 IPHPPartitionScannerConstants.SMARTY,
344                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT,
345                                 IDocument.DEFAULT_CONTENT_TYPE};
346         }
347         /*
348          * (non-Javadoc) Method declared on SourceViewerConfiguration
349          */
350         public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
351                 ContentAssistant assistant = new ContentAssistant();
352                 IContentAssistProcessor processor = new HTMLCompletionProcessor();
353                 assistant.setContentAssistProcessor(processor,
354                                 IPHPPartitionScannerConstants.HTML);
355                 assistant.setContentAssistProcessor(processor,
356                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
357                 assistant.setContentAssistProcessor(processor,
358                                 IDocument.DEFAULT_CONTENT_TYPE);
359                 assistant.setContentAssistProcessor(processor,
360                                 IPHPPartitionScannerConstants.CSS);
361                 assistant.setContentAssistProcessor(processor,
362                                 IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT);
363                 assistant.setContentAssistProcessor(processor,
364                                 IPHPPartitionScannerConstants.JAVASCRIPT);
365                 assistant.setContentAssistProcessor(processor,
366                                 IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT);
367                 // TODO define special smarty partition content assist
368                 assistant.setContentAssistProcessor(processor,
369                                 IPHPPartitionScannerConstants.SMARTY);
370                 assistant.setContentAssistProcessor(processor,
371                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
372                 assistant.setContentAssistProcessor(new PHPCompletionProcessor(),
373                                 IPHPPartitionScannerConstants.PHP);
374                 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(),
375                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
376                 //    assistant.enableAutoActivation(true);
377                 //    assistant.setAutoActivationDelay(500);
378                 //    assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
379                 //    ContentAssistPreference.configure(assistant, getPreferenceStore());
380                 //    assistant.setContextInformationPopupOrientation(
381                 //      ContentAssistant.CONTEXT_INFO_ABOVE);
382                 //    assistant.setContextInformationPopupBackground(
383                 //      PHPEditorEnvironment.getPHPColorProvider().getColor(
384                 //        new RGB(150, 150, 0)));
385                 ContentAssistPreference.configure(assistant, getPreferenceStore());
386                 assistant
387                                 .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
388                 assistant
389                                 .setInformationControlCreator(getInformationControlCreator(sourceViewer));
390                 return assistant;
391         }
392         /*
393          * (non-Javadoc) Method declared on SourceViewerConfiguration
394          */
395         //  public String getDefaultPrefix(ISourceViewer sourceViewer, String
396         // contentType) {
397         //    return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
398         // //$NON-NLS-1$
399         //    // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
400         // null); //$NON-NLS-1$
401         //  }
402         /*
403          * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
404          * @since 2.0
405          */
406         public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
407                         String contentType) {
408                 return new String[]{"//", ""}; //$NON-NLS-1$ //$NON-NLS-2$
409         }
410         /*
411          * (non-Javadoc) Method declared on SourceViewerConfiguration
412          */
413         public ITextDoubleClickStrategy getDoubleClickStrategy(
414                         ISourceViewer sourceViewer, String contentType) {
415                 return new PHPDoubleClickSelector();
416         }
417         /*
418          * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
419          */
420         public String[] getIndentPrefixes(ISourceViewer sourceViewer,
421                         String contentType) {
422                 Vector vector = new Vector();
423                 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
424                 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault()
425                                 .getPreferenceStore();
426                 int tabWidth = preferences.getInt(PHPCore.FORMATTER_TAB_SIZE);
427                 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
428                 for (int i = 0; i <= tabWidth; i++) {
429                         StringBuffer prefix = new StringBuffer();
430                         if (useSpaces) {
431                                 for (int j = 0; j + i < tabWidth; j++)
432                                         prefix.append(' ');
433                                 if (i != 0)
434                                         prefix.append('\t');
435                         } else {
436                                 for (int j = 0; j < i; j++)
437                                         prefix.append(' ');
438                                 if (i != tabWidth)
439                                         prefix.append('\t');
440                         }
441                         vector.add(prefix.toString());
442                 }
443                 vector.add(""); //$NON-NLS-1$
444                 return (String[]) vector.toArray(new String[vector.size()]);
445         }
446         /*
447          * (non-Javadoc) Method declared on SourceViewerConfiguration
448          */
449         public IPresentationReconciler getPresentationReconciler(
450                         ISourceViewer sourceViewer) {
451                 //  PHPColorProvider provider =
452                 // PHPEditorEnvironment.getPHPColorProvider();
453                 //    JavaColorManager provider =
454                 // PHPEditorEnvironment.getPHPColorProvider();
455                 PresentationReconciler reconciler = new PresentationReconciler();
456                 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
457                 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
458                 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
459                 dr = new DefaultDamagerRepairer(getHTMLScanner());
460                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML);
461                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML);
462                 dr = new DefaultDamagerRepairer(getHTMLScanner());
463                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.CSS);
464                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.CSS);
465                 dr = new DefaultDamagerRepairer(getHTMLScanner());
466                 reconciler.setDamager(dr,
467                                 IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT);
468                 reconciler.setRepairer(dr,
469                                 IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT);
470                 dr = new DefaultDamagerRepairer(getHTMLScanner());
471                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.JAVASCRIPT);
472                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.JAVASCRIPT);
473                 dr = new DefaultDamagerRepairer(getHTMLScanner());
474                 reconciler.setDamager(dr,
475                                 IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT);
476                 reconciler.setRepairer(dr,
477                                 IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT);
478                 dr = new DefaultDamagerRepairer(getSmartyScanner());
479                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.SMARTY);
480                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.SMARTY);
481                 dr = new DefaultDamagerRepairer(getSmartyDocScanner());
482                 reconciler.setDamager(dr,
483                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
484                 reconciler.setRepairer(dr,
485                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
486                 dr = new DefaultDamagerRepairer(new SingleTokenScanner(
487                                 new TextAttribute(fJavaTextTools.getColorManager().getColor(
488                                                 PHPColorProvider.MULTI_LINE_COMMENT))));
489                 reconciler.setDamager(dr,
490                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
491                 reconciler.setRepairer(dr,
492                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
493                 dr = new DefaultDamagerRepairer(getCodeScanner());
494                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP);
495                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP);
496                 dr = new DefaultDamagerRepairer(getPHPDocScanner());
497                 reconciler.setDamager(dr,
498                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
499                 reconciler.setRepairer(dr,
500                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
501                 return reconciler;
502         }
503         /*
504          * (non-Javadoc) Method declared on SourceViewerConfiguration
505          */
506         public int getTabWidth(ISourceViewer sourceViewer) {
507                 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
508         }
509         /*
510          * (non-Javadoc) Method declared on SourceViewerConfiguration
511          */
512         //  public ITextHover getTextHover(ISourceViewer sourceViewer, String
513         // contentType) {
514         //    if (fEditor != null) {
515         //      IEditorInput editorInput = fEditor.getEditorInput();
516         //      if (editorInput instanceof IFileEditorInput) {
517         //        try {
518         //          IFile f = ((IFileEditorInput) editorInput).getFile();
519         //          return new PHPTextHover(f.getProject());
520         //        } catch (NullPointerException e) {
521         //          // this exception occurs, if getTextHover is called by preference pages
522         // !
523         //        }
524         //      }
525         //    }
526         //    return new PHPTextHover(null);
527         //  }
528         /*
529          * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
530          * @since 2.0
531          */
532         public IInformationControlCreator getInformationControlCreator(
533                         ISourceViewer sourceViewer) {
534                 return new IInformationControlCreator() {
535                         public IInformationControl createInformationControl(Shell parent) {
536                                 return new DefaultInformationControl(parent, SWT.NONE,
537                                                 new HTMLTextPresenter(true));
538                                 // return new HoverBrowserControl(parent);
539                         }
540                 };
541         }
542         /*
543          * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
544          * @since 2.0
545          */
546         //      public IInformationPresenter getInformationPresenter(ISourceViewer
547         // sourceViewer) {
548         //              InformationPresenter presenter= new
549         // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
550         //              IInformationProvider provider= new JavaInformationProvider(getEditor());
551         //              presenter.setInformationProvider(provider,
552         // IDocument.DEFAULT_CONTENT_TYPE);
553         //              presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
554         //              presenter.setSizeConstraints(60, 10, true, true);
555         //              return presenter;
556         //      }
557         /**
558          * Returns the information presenter control creator. The creator is a
559          * factory creating the presenter controls for the given source viewer.
560          * This implementation always returns a creator for <code>DefaultInformationControl</code>
561          * instances.
562          * 
563          * @param sourceViewer
564          *            the source viewer to be configured by this configuration
565          * @return an information control creator
566          * @since 2.1
567          */
568         private IInformationControlCreator getInformationPresenterControlCreator(
569                         ISourceViewer sourceViewer) {
570                 return new IInformationControlCreator() {
571                         public IInformationControl createInformationControl(Shell parent) {
572                                 int shellStyle = SWT.RESIZE;
573                                 int style = SWT.V_SCROLL | SWT.H_SCROLL;
574                                 return new DefaultInformationControl(parent, shellStyle, style,
575                                                 new HTMLTextPresenter(false));
576                                 // return new HoverBrowserControl(parent);
577                         }
578                 };
579         }
580         /**
581          * Returns the outline presenter control creator. The creator is a factory
582          * creating outline presenter controls for the given source viewer. This
583          * implementation always returns a creator for <code>JavaOutlineInformationControl</code>
584          * instances.
585          * 
586          * @param sourceViewer
587          *            the source viewer to be configured by this configuration
588          * @return an information control creator
589          * @since 2.1
590          */
591         private IInformationControlCreator getOutlinePresenterControlCreator(
592                         ISourceViewer sourceViewer) {
593                 return new IInformationControlCreator() {
594                         public IInformationControl createInformationControl(Shell parent) {
595                                 int shellStyle = SWT.RESIZE;
596                                 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
597                                 return new JavaOutlineInformationControl(parent, shellStyle,
598                                                 treeStyle);
599                         }
600                 };
601         }
602         /**
603          * Returns the outline presenter which will determine and shown information
604          * requested for the current cursor position.
605          * 
606          * @param sourceViewer
607          *            the source viewer to be configured by this configuration
608          * @param doCodeResolve
609          *            a boolean which specifies whether code resolve should be used
610          *            to compute the Java element
611          * @return an information presenter
612          * @since 2.1
613          */
614         public IInformationPresenter getOutlinePresenter(
615                         ISourceViewer sourceViewer, boolean doCodeResolve) {
616                 InformationPresenter presenter = new InformationPresenter(
617                                 getOutlinePresenterControlCreator(sourceViewer));
618                 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
619                 IInformationProvider provider = new JavaElementProvider(getEditor(),
620                                 doCodeResolve);
621                 presenter.setInformationProvider(provider,
622                                 IDocument.DEFAULT_CONTENT_TYPE);
623                 presenter.setInformationProvider(provider,
624                                 IPHPPartitionScannerConstants.PHP);
625                 presenter.setInformationProvider(provider,
626                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
627                 presenter.setInformationProvider(provider,
628                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
629                 presenter.setInformationProvider(provider,
630                                 IPHPPartitionScannerConstants.HTML);
631                 presenter.setInformationProvider(provider,
632                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
633                 presenter.setSizeConstraints(40, 20, true, false);
634                 return presenter;
635         }
636 }