changes for new Action
[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                 if (fEditor != null) {
293                         IEditorInput editorInput = fEditor.getEditorInput();
294                         if (editorInput instanceof IFileEditorInput) {
295                                 try {
296                                         IFile f = ((IFileEditorInput) editorInput).getFile();
297                                         return new PHPTextHover(f.getProject());
298                                 } catch (NullPointerException e) {
299                                         // this exception occurs, if getTextHover is called by
300                                         // preference pages !
301                                 }
302                         }
303                 }
304                 return new PHPTextHover(null);
305         }
306         /*
307          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
308          */
309         public ITextHover getTextHover(ISourceViewer sourceViewer,
310                         String contentType) {
311                 return getTextHover(sourceViewer, contentType,
312                                 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
313         }
314         /**
315          * Returns the SmartyDoc source code scanner for this configuration.
316          * 
317          * @return the SmartyDoc source code scanner
318          */
319         protected RuleBasedScanner getSmartyDocScanner() {
320                 return fJavaTextTools.getSmartyDocScanner();
321         }
322         /**
323          * Returns the PHPDoc source code scanner for this configuration.
324          * 
325          * @return the PHPDoc source code scanner
326          */
327         protected RuleBasedScanner getPHPDocScanner() {
328                 return fJavaTextTools.getJavaDocScanner();
329         }
330         /*
331          * (non-Javadoc) Method declared on SourceViewerConfiguration
332          */
333         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
334                 return new String[]{IPHPPartitionScannerConstants.HTML,
335                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
336                                 IPHPPartitionScannerConstants.PHP,
337                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
338                                 IPHPPartitionScannerConstants.CSS,
339                                 IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT,
340                                 IPHPPartitionScannerConstants.JAVASCRIPT,
341                                 IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT,
342                                 IPHPPartitionScannerConstants.SMARTY,
343                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT,
344                                 IDocument.DEFAULT_CONTENT_TYPE};
345         }
346         /*
347          * (non-Javadoc) Method declared on SourceViewerConfiguration
348          */
349         public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
350                 ContentAssistant assistant = new ContentAssistant();
351                 IContentAssistProcessor processor = new HTMLCompletionProcessor();
352                 assistant.setContentAssistProcessor(processor,
353                                 IPHPPartitionScannerConstants.HTML);
354                 assistant.setContentAssistProcessor(processor,
355                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
356                 assistant.setContentAssistProcessor(processor,
357                                 IDocument.DEFAULT_CONTENT_TYPE);
358                 assistant.setContentAssistProcessor(processor,
359                                 IPHPPartitionScannerConstants.CSS);
360                 assistant.setContentAssistProcessor(processor,
361                                 IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT);
362                 assistant.setContentAssistProcessor(processor,
363                                 IPHPPartitionScannerConstants.JAVASCRIPT);
364                 assistant.setContentAssistProcessor(processor,
365                                 IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT);
366                 // TODO define special smarty partition content assist
367                 assistant.setContentAssistProcessor(processor,
368                                 IPHPPartitionScannerConstants.SMARTY);
369                 assistant.setContentAssistProcessor(processor,
370                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
371                 assistant.setContentAssistProcessor(new PHPCompletionProcessor(),
372                                 IPHPPartitionScannerConstants.PHP);
373                 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(),
374                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
375                 //    assistant.enableAutoActivation(true);
376                 //    assistant.setAutoActivationDelay(500);
377                 //    assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
378                 //    ContentAssistPreference.configure(assistant, getPreferenceStore());
379                 //    assistant.setContextInformationPopupOrientation(
380                 //      ContentAssistant.CONTEXT_INFO_ABOVE);
381                 //    assistant.setContextInformationPopupBackground(
382                 //      PHPEditorEnvironment.getPHPColorProvider().getColor(
383                 //        new RGB(150, 150, 0)));
384                 ContentAssistPreference.configure(assistant, getPreferenceStore());
385                 assistant
386                                 .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
387                 assistant
388                                 .setInformationControlCreator(getInformationControlCreator(sourceViewer));
389                 return assistant;
390         }
391         /*
392          * (non-Javadoc) Method declared on SourceViewerConfiguration
393          */
394         //  public String getDefaultPrefix(ISourceViewer sourceViewer, String
395         // contentType) {
396         //    return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
397         // //$NON-NLS-1$
398         //    // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
399         // null); //$NON-NLS-1$
400         //  }
401         /*
402          * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
403          * @since 2.0
404          */
405         public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
406                         String contentType) {
407                 return new String[]{"//", ""}; //$NON-NLS-1$ //$NON-NLS-2$
408         }
409         /*
410          * (non-Javadoc) Method declared on SourceViewerConfiguration
411          */
412         public ITextDoubleClickStrategy getDoubleClickStrategy(
413                         ISourceViewer sourceViewer, String contentType) {
414                 return new PHPDoubleClickSelector();
415         }
416         /*
417          * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
418          */
419         public String[] getIndentPrefixes(ISourceViewer sourceViewer,
420                         String contentType) {
421                 Vector vector = new Vector();
422                 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
423                 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault()
424                                 .getPreferenceStore();
425                 int tabWidth = preferences.getInt(PHPCore.FORMATTER_TAB_SIZE);
426                 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
427                 for (int i = 0; i <= tabWidth; i++) {
428                         StringBuffer prefix = new StringBuffer();
429                         if (useSpaces) {
430                                 for (int j = 0; j + i < tabWidth; j++)
431                                         prefix.append(' ');
432                                 if (i != 0)
433                                         prefix.append('\t');
434                         } else {
435                                 for (int j = 0; j < i; j++)
436                                         prefix.append(' ');
437                                 if (i != tabWidth)
438                                         prefix.append('\t');
439                         }
440                         vector.add(prefix.toString());
441                 }
442                 vector.add(""); //$NON-NLS-1$
443                 return (String[]) vector.toArray(new String[vector.size()]);
444         }
445         /*
446          * (non-Javadoc) Method declared on SourceViewerConfiguration
447          */
448         public IPresentationReconciler getPresentationReconciler(
449                         ISourceViewer sourceViewer) {
450                 //  PHPColorProvider provider =
451                 // PHPEditorEnvironment.getPHPColorProvider();
452                 //    JavaColorManager provider =
453                 // PHPEditorEnvironment.getPHPColorProvider();
454                 PresentationReconciler reconciler = new PresentationReconciler();
455                 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
456                 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
457                 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
458                 dr = new DefaultDamagerRepairer(getHTMLScanner());
459                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML);
460                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML);
461                 dr = new DefaultDamagerRepairer(getHTMLScanner());
462                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.CSS);
463                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.CSS);
464                 dr = new DefaultDamagerRepairer(getHTMLScanner());
465                 reconciler.setDamager(dr,
466                                 IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT);
467                 reconciler.setRepairer(dr,
468                                 IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT);
469                 dr = new DefaultDamagerRepairer(getHTMLScanner());
470                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.JAVASCRIPT);
471                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.JAVASCRIPT);
472                 dr = new DefaultDamagerRepairer(getHTMLScanner());
473                 reconciler.setDamager(dr,
474                                 IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT);
475                 reconciler.setRepairer(dr,
476                                 IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT);
477                 dr = new DefaultDamagerRepairer(getSmartyScanner());
478                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.SMARTY);
479                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.SMARTY);
480                 dr = new DefaultDamagerRepairer(getSmartyDocScanner());
481                 reconciler.setDamager(dr,
482                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
483                 reconciler.setRepairer(dr,
484                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
485                 dr = new DefaultDamagerRepairer(new SingleTokenScanner(
486                                 new TextAttribute(fJavaTextTools.getColorManager().getColor(
487                                                 PHPColorProvider.MULTI_LINE_COMMENT))));
488                 reconciler.setDamager(dr,
489                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
490                 reconciler.setRepairer(dr,
491                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
492                 dr = new DefaultDamagerRepairer(getCodeScanner());
493                 reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP);
494                 reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP);
495                 dr = new DefaultDamagerRepairer(getPHPDocScanner());
496                 reconciler.setDamager(dr,
497                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
498                 reconciler.setRepairer(dr,
499                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
500                 return reconciler;
501         }
502         /*
503          * (non-Javadoc) Method declared on SourceViewerConfiguration
504          */
505         public int getTabWidth(ISourceViewer sourceViewer) {
506                 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
507         }
508         /*
509          * (non-Javadoc) Method declared on SourceViewerConfiguration
510          */
511         //  public ITextHover getTextHover(ISourceViewer sourceViewer, String
512         // contentType) {
513         //    if (fEditor != null) {
514         //      IEditorInput editorInput = fEditor.getEditorInput();
515         //      if (editorInput instanceof IFileEditorInput) {
516         //        try {
517         //          IFile f = ((IFileEditorInput) editorInput).getFile();
518         //          return new PHPTextHover(f.getProject());
519         //        } catch (NullPointerException e) {
520         //          // this exception occurs, if getTextHover is called by preference pages
521         // !
522         //        }
523         //      }
524         //    }
525         //    return new PHPTextHover(null);
526         //  }
527         /*
528          * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
529          * @since 2.0
530          */
531         public IInformationControlCreator getInformationControlCreator(
532                         ISourceViewer sourceViewer) {
533                 return new IInformationControlCreator() {
534                         public IInformationControl createInformationControl(Shell parent) {
535                                 return new DefaultInformationControl(parent, SWT.NONE,
536                                                 new HTMLTextPresenter(true));
537                                 // return new HoverBrowserControl(parent);
538                         }
539                 };
540         }
541         /*
542          * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
543          * @since 2.0
544          */
545         //      public IInformationPresenter getInformationPresenter(ISourceViewer
546         // sourceViewer) {
547         //              InformationPresenter presenter= new
548         // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
549         //              IInformationProvider provider= new JavaInformationProvider(getEditor());
550         //              presenter.setInformationProvider(provider,
551         // IDocument.DEFAULT_CONTENT_TYPE);
552         //              presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
553         //              presenter.setSizeConstraints(60, 10, true, true);
554         //              return presenter;
555         //      }
556         /**
557          * Returns the information presenter control creator. The creator is a
558          * factory creating the presenter controls for the given source viewer.
559          * This implementation always returns a creator for <code>DefaultInformationControl</code>
560          * instances.
561          * 
562          * @param sourceViewer
563          *            the source viewer to be configured by this configuration
564          * @return an information control creator
565          * @since 2.1
566          */
567         private IInformationControlCreator getInformationPresenterControlCreator(
568                         ISourceViewer sourceViewer) {
569                 return new IInformationControlCreator() {
570                         public IInformationControl createInformationControl(Shell parent) {
571                                 int shellStyle = SWT.RESIZE;
572                                 int style = SWT.V_SCROLL | SWT.H_SCROLL;
573                                 return new DefaultInformationControl(parent, shellStyle, style,
574                                                 new HTMLTextPresenter(false));
575                                 // return new HoverBrowserControl(parent);
576                         }
577                 };
578         }
579         /**
580          * Returns the outline presenter control creator. The creator is a factory
581          * creating outline presenter controls for the given source viewer. This
582          * implementation always returns a creator for <code>JavaOutlineInformationControl</code>
583          * instances.
584          * 
585          * @param sourceViewer
586          *            the source viewer to be configured by this configuration
587          * @return an information control creator
588          * @since 2.1
589          */
590         private IInformationControlCreator getOutlinePresenterControlCreator(
591                         ISourceViewer sourceViewer) {
592                 return new IInformationControlCreator() {
593                         public IInformationControl createInformationControl(Shell parent) {
594                                 int shellStyle = SWT.RESIZE;
595                                 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
596                                 return new JavaOutlineInformationControl(parent, shellStyle,
597                                                 treeStyle);
598                         }
599                 };
600         }
601         /**
602          * Returns the outline presenter which will determine and shown information
603          * requested for the current cursor position.
604          * 
605          * @param sourceViewer
606          *            the source viewer to be configured by this configuration
607          * @param doCodeResolve
608          *            a boolean which specifies whether code resolve should be used
609          *            to compute the Java element
610          * @return an information presenter
611          * @since 2.1
612          */
613         public IInformationPresenter getOutlinePresenter(
614                         ISourceViewer sourceViewer, boolean doCodeResolve) {
615                 InformationPresenter presenter = new InformationPresenter(
616                                 getOutlinePresenterControlCreator(sourceViewer));
617                 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
618                 IInformationProvider provider = new JavaElementProvider(getEditor(),
619                                 doCodeResolve);
620                 presenter.setInformationProvider(provider,
621                                 IDocument.DEFAULT_CONTENT_TYPE);
622                 presenter.setInformationProvider(provider,
623                                 IPHPPartitionScannerConstants.PHP);
624                 presenter.setInformationProvider(provider,
625                                 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
626                 presenter.setInformationProvider(provider,
627                                 IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
628                 presenter.setInformationProvider(provider,
629                                 IPHPPartitionScannerConstants.HTML);
630                 presenter.setInformationProvider(provider,
631                                 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
632                 presenter.setSizeConstraints(40, 20, true, false);
633                 return presenter;
634         }
635 }