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