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