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