1) Fixed issue #852: Correct matching of closing brace with the according opening...
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / ui / text / 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  www.phpeclipse.de
11  **********************************************************************/
12 package net.sourceforge.phpdt.ui.text;
13
14 import java.util.Vector;
15
16 import net.sourceforge.phpdt.core.JavaCore;
17 //import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
18 import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
19 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
20 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
21 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
22 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
23 import net.sourceforge.phpdt.internal.ui.text.JavaCompositeReconcilingStrategy;
24 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
25 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
26 import net.sourceforge.phpdt.internal.ui.text.JavaPresentationReconciler;
27 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
28 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
29 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategyDQ;
30 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategySQ;
31 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
32 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
33 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaInformationProvider;
34 import net.sourceforge.phpdt.internal.ui.text.phpdoc.JavaDocAutoIndentStrategy;
35 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
36 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
37 import net.sourceforge.phpdt.ui.PreferenceConstants;
38 import net.sourceforge.phpeclipse.IPreferenceConstants;
39 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
40 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
41 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
42 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
43 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
44 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
45 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
46 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
47 import net.sourceforge.phpeclipse.ui.WebUI;
48 //import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
49 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
50 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
51 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
52
53 import org.eclipse.core.runtime.NullProgressMonitor;
54 import org.eclipse.jface.preference.IPreferenceStore;
55 import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
56 import org.eclipse.jface.text.DefaultInformationControl;
57 import org.eclipse.jface.text.IAutoEditStrategy;
58 import org.eclipse.jface.text.IDocument;
59 import org.eclipse.jface.text.IInformationControl;
60 import org.eclipse.jface.text.IInformationControlCreator;
61 import org.eclipse.jface.text.ITextDoubleClickStrategy;
62 import org.eclipse.jface.text.ITextHover;
63 import org.eclipse.jface.text.ITextViewerExtension2;
64 import org.eclipse.jface.text.TextAttribute;
65 import org.eclipse.jface.text.contentassist.ContentAssistant;
66 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
67 import org.eclipse.jface.text.contentassist.IContentAssistant;
68 import org.eclipse.jface.text.formatter.ContentFormatter;
69 import org.eclipse.jface.text.formatter.IContentFormatter;
70 import org.eclipse.jface.text.formatter.IFormattingStrategy;
71 import org.eclipse.jface.text.information.IInformationPresenter;
72 import org.eclipse.jface.text.information.IInformationProvider;
73 import org.eclipse.jface.text.information.InformationPresenter;
74 import org.eclipse.jface.text.presentation.IPresentationDamager;
75 import org.eclipse.jface.text.presentation.IPresentationReconciler;
76 import org.eclipse.jface.text.presentation.IPresentationRepairer;
77 import org.eclipse.jface.text.presentation.PresentationReconciler;
78 import org.eclipse.jface.text.reconciler.IReconciler;
79 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
80 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
81 import org.eclipse.jface.text.rules.DefaultPartitioner;
82 import org.eclipse.jface.text.rules.RuleBasedScanner;
83 import org.eclipse.jface.text.rules.Token;
84 import org.eclipse.jface.text.source.IAnnotationHover;
85 import org.eclipse.jface.text.source.ISourceViewer;
86 import org.eclipse.jface.text.source.SourceViewerConfiguration;
87 import org.eclipse.jface.util.PropertyChangeEvent;
88 import org.eclipse.swt.SWT;
89 import org.eclipse.swt.widgets.Shell;
90 import org.eclipse.ui.texteditor.ITextEditor;
91
92 /**
93  * Configuration for an <code>SourceViewer</code> which shows PHP code.
94  */
95 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
96         /**
97          * Preference key used to look up display tab width.
98          * 
99          * @since 2.0
100          */
101         public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
102
103         /**
104          * Preference key for inserting spaces rather than tabs.
105          * 
106          * @since 2.0
107          */
108         public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
109
110         // public static final String HTML_DEFAULT =
111         // IPHPPartitionScannerConstants.HTML;
112         // IDocument.DEFAULT_CONTENT_TYPE;
113         // private JavaTextTools fJavaTextTools;
114
115         private ITextEditor fTextEditor;
116
117         /**
118          * The document partitioning.
119          * 
120          * @since 3.0
121          */
122         private String fDocumentPartitioning;
123
124         private ContentFormatter fFormatter;
125
126         /**
127          * Single token scanner.
128          */
129         static class SingleTokenScanner extends BufferedRuleBasedScanner {
130                 public SingleTokenScanner(TextAttribute attribute) {
131                         setDefaultReturnToken(new Token(attribute));
132                 }
133         };
134
135         /**
136          * The document partitioning.
137          * 
138          * @since 3.0
139          */
140         // private String fDocumentPartitioning;
141         /**
142          * The Java source code scanner
143          * 
144          * @since 3.0
145          */
146         private AbstractJavaScanner fCodeScanner;
147
148         /**
149          * The Java multi-line comment scanner
150          * 
151          * @since 3.0
152          */
153         private AbstractJavaScanner fMultilineCommentScanner;
154
155         /**
156          * The Java single-line comment scanner
157          * 
158          * @since 3.0
159          */
160         private AbstractJavaScanner fSinglelineCommentScanner;
161
162         /**
163          * The PHP double quoted string scanner
164          */
165         private AbstractJavaScanner fStringDQScanner;
166
167         /**
168          * The PHP single quoted string scanner
169          */
170         private AbstractJavaScanner fStringSQScanner;
171
172         /**
173          * The Javadoc scanner
174          * 
175          * @since 3.0
176          */
177         private AbstractJavaScanner fJavaDocScanner;
178
179         /**
180          * The preference store, can be read-only
181          * 
182          * @since 3.0
183          */
184         private IPreferenceStore fPreferenceStore;
185
186         /**
187          * The color manager
188          * 
189          * @since 3.0
190          */
191         private IColorManager fColorManager;
192
193         private XMLTextTools fXMLTextTools;
194
195         private XMLConfiguration xmlConfiguration;
196
197         /**
198          * Creates a new Java source viewer configuration for viewers in the given
199          * editor using the given preference store, the color manager and the
200          * specified document partitioning.
201          * <p>
202          * Creates a Java source viewer configuration in the new setup without text
203          * tools. Clients are allowed to call
204          * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and
205          * disallowed to call
206          * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the
207          * resulting Java source viewer configuration.
208          * </p>
209          * 
210          * @param colorManager
211          *            the color manager
212          * @param preferenceStore
213          *            the preference store, can be read-only
214          * @param editor
215          *            the editor in which the configured viewer(s) will reside
216          * @param partitioning
217          *            the document partitioning for this configuration
218          * @since 3.0
219          */
220         public PHPSourceViewerConfiguration(IColorManager colorManager,
221                         IPreferenceStore preferenceStore, ITextEditor editor,
222                         String partitioning) {
223                 fColorManager = colorManager;
224                 fPreferenceStore = preferenceStore;
225                 fTextEditor = editor;
226                 fDocumentPartitioning = partitioning;
227                 // fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
228                 fXMLTextTools = new XMLTextTools(getPreferenceStore());
229                 //XMLPlugin.getDefault().getXMLTextTools();
230                 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
231                 fColorManager = colorManager;
232                 fPreferenceStore = preferenceStore;
233                 fTextEditor = editor;
234                 fDocumentPartitioning = partitioning;
235
236                 initializeScanners();
237         }
238
239         /**
240          * Creates a new Java source viewer configuration for viewers in the given
241          * editor using the given Java tools.
242          * 
243          * @param tools
244          *            the Java text tools to be used
245          * @param editor
246          *            the editor in which the configured viewer(s) will reside
247          * @see JavaTextTools
248          * @deprecated As of 3.0, replaced by
249          *             {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
250          */
251         // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor
252         // editor, String partitioning) {
253         // fJavaTextTools = tools;
254         // fColorManager = tools.getColorManager();
255         // fPreferenceStore = createPreferenceStore();
256         // fDocumentPartitioning = partitioning;
257         // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
258         // fMultilineCommentScanner = (AbstractJavaScanner)
259         // fJavaTextTools.getMultilineCommentScanner();
260         // fSinglelineCommentScanner = (AbstractJavaScanner)
261         // fJavaTextTools.getSinglelineCommentScanner();
262         // fStringDQScanner = (AbstractJavaScanner)
263         // fJavaTextTools.getStringScanner();
264         // fJavaDocScanner = (AbstractJavaScanner)
265         // fJavaTextTools.getJavaDocScanner();
266         // fTextEditor = editor;
267         // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
268         // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
269         // }
270         /**
271          * Returns the color manager for this configuration.
272          * 
273          * @return the color manager
274          */
275         protected IColorManager getColorManager() {
276                 return fColorManager;
277         }
278
279         /**
280          * Initializes the scanners.
281          * 
282          * @since 3.0
283          */
284         private void initializeScanners() {
285                 // Assert.isTrue(isNewSetup());
286                 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
287                 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(),
288                                 fPreferenceStore, IPreferenceConstants.PHP_MULTILINE_COMMENT);
289                 fSinglelineCommentScanner = new SingleTokenPHPScanner(
290                                 getColorManager(), fPreferenceStore,
291                                 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
292                 // fStringDQScanner = new SingleTokenPHPScanner(getColorManager(),
293                 // fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ);
294                 fStringDQScanner = new PHPStringDQCodeScanner(getColorManager(),
295                                 fPreferenceStore);
296                 fStringSQScanner = new SingleTokenPHPScanner(getColorManager(),
297                                 fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
298                 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(),
299                                 fPreferenceStore);
300         }
301
302         /**
303          * Determines whether the preference change encoded by the given event
304          * changes the behavior of one of its contained components.
305          * 
306          * @param event
307          *            the event to be investigated
308          * @return <code>true</code> if event causes a behavioral change
309          * @since 3.0
310          */
311         public boolean affectsTextPresentation(PropertyChangeEvent event) {
312                 return fCodeScanner.affectsBehavior(event)
313                                 || fMultilineCommentScanner.affectsBehavior(event)
314                                 || fSinglelineCommentScanner.affectsBehavior(event)
315                                 || fStringDQScanner.affectsBehavior(event)
316                                 || fStringSQScanner.affectsBehavior(event)
317                                 || fJavaDocScanner.affectsBehavior(event);
318         }
319
320         /**
321          * Adapts the behavior of the contained components to the change encoded in
322          * the given event.
323          * <p>
324          * Clients are not allowed to call this method if the old setup with text
325          * tools is in use.
326          * </p>
327          * 
328          * @param event
329          *            the event to which to adapt
330          * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager,
331          *      IPreferenceStore, ITextEditor, String)
332          * @since 3.0
333          */
334         public void handlePropertyChangeEvent(PropertyChangeEvent event) {
335                 // Assert.isTrue(isNewSetup());
336                 if (fCodeScanner.affectsBehavior(event))
337                         fCodeScanner.adaptToPreferenceChange(event);
338                 if (fMultilineCommentScanner.affectsBehavior(event))
339                         fMultilineCommentScanner.adaptToPreferenceChange(event);
340                 if (fSinglelineCommentScanner.affectsBehavior(event))
341                         fSinglelineCommentScanner.adaptToPreferenceChange(event);
342                 if (fStringDQScanner.affectsBehavior(event))
343                         fStringDQScanner.adaptToPreferenceChange(event);
344                 if (fStringSQScanner.affectsBehavior(event))
345                         fStringSQScanner.adaptToPreferenceChange(event);
346                 if (fJavaDocScanner.affectsBehavior(event))
347                         fJavaDocScanner.adaptToPreferenceChange(event);
348         }
349
350         /*
351          * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
352          */
353         public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
354                 // if (fFormatter == null) {
355                 // fFormatter = new ContentFormatter();
356                 // fFormattingStrategy = new HTMLFormattingStrategy(this,
357                 // sourceViewer);
358                 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
359                 // fFormatter.enablePartitionAwareFormatting(false);
360                 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
361                 // }
362                 // return fFormatter;
363                 if (fFormatter == null) {
364                         // ContentFormatter
365                         fFormatter = new ContentFormatter();
366                         IFormattingStrategy strategy = new JavaFormattingStrategy(
367                                         sourceViewer);
368                         fFormatter.setFormattingStrategy(strategy,
369                                         IDocument.DEFAULT_CONTENT_TYPE);
370                         fFormatter.enablePartitionAwareFormatting(false);
371                         fFormatter
372                                         .setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
373                 }
374                 return fFormatter;
375         }
376
377         /**
378          * Returns the names of the document position categories used by the
379          * document partitioners created by this object to manage their partition
380          * information. If the partitioners don't use document position categories,
381          * the returned result is <code>null</code>.
382          * 
383          * @return the partition managing position categories or <code>null</code>
384          *         if there is none
385          */
386         public String[] getPartitionManagingPositionCategories() {
387                 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
388         }
389
390         // /**
391         // * Returns the names of the document position categories used by the
392         // document
393         // * partitioners created by this object to manage their partition
394         // information.
395         // * If the partitioners don't use document position categories, the
396         // returned
397         // * result is <code>null</code>.
398         // *
399         // * @return the partition managing position categories or
400         // <code>null</code>
401         // * if there is none
402         // */
403         // private String[] getPartitionManagingPositionCategories() {
404         // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
405         // }
406         public ITextEditor getEditor() {
407                 return fTextEditor;
408         }
409
410         /**
411          * Returns the preference store used by this configuration to initialize the
412          * individual bits and pieces.
413          * 
414          * @return the preference store used to initialize this configuration
415          * 
416          * @since 2.0
417          */
418         protected IPreferenceStore getPreferenceStore() {
419                 return WebUI.getDefault().getPreferenceStore();
420         }
421
422         // /* (non-Javadoc)
423         // * Method declared on SourceViewerConfiguration
424         // */
425         // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
426         // return new PHPAnnotationHover();
427         // }
428         /*
429          * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
430          */
431         public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
432                 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
433         }
434
435         /*
436          * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
437          * @since 3.0
438          */
439         public IAnnotationHover getOverviewRulerAnnotationHover(
440                         ISourceViewer sourceViewer) {
441                 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
442         }
443
444         public IAutoEditStrategy[] getAutoEditStrategies(
445                         ISourceViewer sourceViewer, String contentType) {
446                 IAutoEditStrategy strategy = new DefaultIndentLineAutoEditStrategy();
447                 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
448                                 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
449                         strategy = new JavaDocAutoIndentStrategy(
450                                         getConfiguredDocumentPartitioning(sourceViewer));
451                 else if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
452                         strategy = new JavaStringAutoIndentStrategyDQ(
453                                         getConfiguredDocumentPartitioning(sourceViewer));
454                 else if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
455                         strategy = new JavaStringAutoIndentStrategySQ(
456                                         getConfiguredDocumentPartitioning(sourceViewer));
457                 else
458                         strategy = (PHPDocumentPartitioner.PHP_TEMPLATE_DATA
459                                         .equals(contentType)
460                                         || PHPDocumentPartitioner.PHP_SCRIPT_CODE
461                                                         .equals(contentType)
462                                         || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
463                                         || IPHPPartitions.PHP_PARTITIONING.equals(contentType)
464                                         || PHPPartitionScanner.PHP_SCRIPTING_AREA
465                                                         .equals(contentType) ? new PHPAutoIndentStrategy()
466                                         : new DefaultIndentLineAutoEditStrategy());
467                 IAutoEditStrategy[] result = new IAutoEditStrategy[1];
468                 result[0] = strategy;
469                 return result;
470         }
471
472         /**
473          * Returns the PHP source code scanner for this configuration.
474          * 
475          * @return the PHP source code scanner
476          */
477         protected RuleBasedScanner getCodeScanner() {
478                 return fCodeScanner; // fJavaTextTools.getCodeScanner();
479         }
480
481         /**
482          * Returns the Java multi-line comment scanner for this configuration.
483          * 
484          * @return the Java multi-line comment scanner
485          * @since 2.0
486          */
487         protected RuleBasedScanner getMultilineCommentScanner() {
488                 return fMultilineCommentScanner;
489         }
490
491         /**
492          * Returns the Java single-line comment scanner for this configuration.
493          * 
494          * @return the Java single-line comment scanner
495          * @since 2.0
496          */
497         protected RuleBasedScanner getSinglelineCommentScanner() {
498                 return fSinglelineCommentScanner;
499         }
500
501         /**
502          * Returns the PHP double quoted string scanner for this configuration.
503          * 
504          * @return the PHP double quoted string scanner
505          */
506         protected RuleBasedScanner getStringDQScanner() {
507                 return fStringDQScanner;
508         }
509
510         /**
511          * Returns the PHP single quoted string scanner for this configuration.
512          * 
513          * @return the PHP single quoted string scanner
514          */
515         protected RuleBasedScanner getStringSQScanner() {
516                 return fStringSQScanner;
517         }
518
519         /**
520          * Returns the HTML source code scanner for this configuration.
521          * 
522          * @return the HTML source code scanner
523          */
524         // protected RuleBasedScanner getHTMLScanner() {
525         // return fJavaTextTools.getHTMLScanner();
526         // }
527         /**
528          * Returns the Smarty source code scanner for this configuration.
529          * 
530          * @return the Smarty source code scanner
531          */
532         // protected RuleBasedScanner getSmartyScanner() {
533         // return fJavaTextTools.getSmartyScanner();
534         // }
535         /*
536          * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
537          */
538         /*
539          * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
540          */
541         public IReconciler getReconciler(ISourceViewer sourceViewer) {
542
543                 final ITextEditor editor = getEditor();
544                 if (editor != null && editor.isEditable()) {
545
546                         JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(
547                                         editor, getConfiguredDocumentPartitioning(sourceViewer));
548                         JavaReconciler reconciler = new JavaReconciler(editor, strategy,
549                                         false);
550                         reconciler.setIsIncrementalReconciler(false);
551                         reconciler.setProgressMonitor(new NullProgressMonitor());
552                         reconciler.setDelay(500);
553
554                         return reconciler;
555                 }
556                 return null;
557         }
558
559         /*
560          * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer,
561          *      String)
562          * @since 2.1
563          */
564         public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer,
565                         String contentType) {
566                 JavaEditorTextHoverDescriptor[] hoverDescs = WebUI
567                                 .getDefault().getJavaEditorTextHoverDescriptors();
568                 int stateMasks[] = new int[hoverDescs.length];
569                 int stateMasksLength = 0;
570                 for (int i = 0; i < hoverDescs.length; i++) {
571                         if (hoverDescs[i].isEnabled()) {
572                                 int j = 0;
573                                 int stateMask = hoverDescs[i].getStateMask();
574                                 while (j < stateMasksLength) {
575                                         if (stateMasks[j] == stateMask)
576                                                 break;
577                                         j++;
578                                 }
579                                 if (j == stateMasksLength)
580                                         stateMasks[stateMasksLength++] = stateMask;
581                         }
582                 }
583                 if (stateMasksLength == hoverDescs.length)
584                         return stateMasks;
585                 int[] shortenedStateMasks = new int[stateMasksLength];
586                 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0,
587                                 stateMasksLength);
588                 return shortenedStateMasks;
589         }
590
591         /*
592          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
593          * @since 2.1
594          */
595         public ITextHover getTextHover(ISourceViewer sourceViewer,
596                         String contentType, int stateMask) {
597                 JavaEditorTextHoverDescriptor[] hoverDescs = WebUI
598                                 .getDefault().getJavaEditorTextHoverDescriptors();
599                 int i = 0;
600                 while (i < hoverDescs.length) {
601                         if (hoverDescs[i].isEnabled()
602                                         && hoverDescs[i].getStateMask() == stateMask)
603                                 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
604                         i++;
605                 }
606                 return null;
607                 // if (fEditor != null) {
608                 // IEditorInput editorInput = fEditor.getEditorInput();
609                 // if (editorInput instanceof IFileEditorInput) {
610                 // try {
611                 // IFile f = ((IFileEditorInput) editorInput).getFile();
612                 // return new PHPTextHover(f.getProject());
613                 // } catch (NullPointerException e) {
614                 // // this exception occurs, if getTextHover is called by
615                 // // preference pages !
616                 // }
617                 // }
618                 // }
619                 // return new PHPTextHover(null);
620         }
621
622         /*
623          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
624          */
625         public ITextHover getTextHover(ISourceViewer sourceViewer,
626                         String contentType) {
627                 return getTextHover(sourceViewer, contentType,
628                                 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
629         }
630
631         /**
632          * Returns the SmartyDoc source code scanner for this configuration.
633          * 
634          * @return the SmartyDoc source code scanner
635          */
636         // protected RuleBasedScanner getSmartyDocScanner() {
637         // return fJavaTextTools.getSmartyDocScanner();
638         // }
639         /**
640          * Returns the PHPDoc source code scanner for this configuration.
641          * 
642          * @return the PHPDoc source code scanner
643          */
644         protected RuleBasedScanner getPHPDocScanner() {
645                 return fJavaDocScanner; // fJavaTextTools.getJavaDocScanner();
646         }
647
648         /*
649          * (non-Javadoc) Method declared on SourceViewerConfiguration
650          */
651         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
652                 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
653                                 PHPPartitionScanner.PHP_SCRIPTING_AREA,
654
655                                 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT,
656                                 IPHPPartitions.PHP_PARTITIONING,
657                                 IPHPPartitions.PHP_SINGLELINE_COMMENT,
658                                 IPHPPartitions.PHP_MULTILINE_COMMENT,
659                                 IPHPPartitions.PHP_PHPDOC_COMMENT,
660                                 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ,
661                                 IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS,
662                                 IPHPPartitions.CSS_MULTILINE_COMMENT,
663                                 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT,
664                                 IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT,
665
666                                 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT,
667                                 XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
668                                 XMLPartitionScanner.XML_ATTRIBUTE,
669                                 XMLPartitionScanner.XML_CDATA,
670
671                                 XMLPartitionScanner.DTD_INTERNAL,
672                                 XMLPartitionScanner.DTD_INTERNAL_PI,
673                                 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
674                                 XMLPartitionScanner.DTD_INTERNAL_DECL,
675
676                                 PHPDocumentPartitioner.PHP_TEMPLATE_DATA,
677                                 PHPDocumentPartitioner.PHP_SCRIPT_CODE };
678         }
679
680         public String[] getConfiguredHTMLContentTypes() {
681                 return new String[] { XMLPartitionScanner.XML_PI,
682                                 XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
683                                 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE,
684                                 XMLPartitionScanner.XML_CDATA,
685
686                                 XMLPartitionScanner.DTD_INTERNAL,
687                                 XMLPartitionScanner.DTD_INTERNAL_PI,
688                                 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
689                                 XMLPartitionScanner.DTD_INTERNAL_DECL, };
690         }
691
692         public String[] getConfiguredPHPContentTypes() {
693                 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
694                                 IPHPPartitions.PHP_PARTITIONING,
695                                 IPHPPartitions.PHP_SINGLELINE_COMMENT,
696                                 IPHPPartitions.PHP_MULTILINE_COMMENT,
697                                 IPHPPartitions.PHP_PHPDOC_COMMENT,
698                                 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ,
699                                 IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS,
700                                 IPHPPartitions.CSS_MULTILINE_COMMENT,
701                                 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT,
702                                 IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
703         }
704
705         /*
706          * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
707          * @since 3.0
708          */
709         public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
710                 if (fDocumentPartitioning != null)
711                         return fDocumentPartitioning;
712                 return super.getConfiguredDocumentPartitioning(sourceViewer);
713         }
714
715         /*
716          * (non-Javadoc) Method declared on SourceViewerConfiguration
717          */
718         public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
719                 ContentAssistant assistant = new ContentAssistant();
720                 IContentAssistProcessor processor = new HTMLCompletionProcessor(
721                                 getEditor());
722                 assistant
723                                 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
724                 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
725                 assistant.setContentAssistProcessor(processor,
726                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
727
728                 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
729                 assistant.setContentAssistProcessor(processor,
730                                 IPHPPartitions.CSS_MULTILINE_COMMENT);
731                 assistant.setContentAssistProcessor(processor,
732                                 IPHPPartitions.JAVASCRIPT);
733                 assistant.setContentAssistProcessor(processor,
734                                 IPHPPartitions.JS_MULTILINE_COMMENT);
735                 // TODO define special smarty partition content assist
736                 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
737                 assistant.setContentAssistProcessor(processor,
738                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
739
740                 assistant.setContentAssistProcessor(processor,
741                                 PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
742                 String[] htmlTypes = getConfiguredHTMLContentTypes();
743                 for (int i = 0; i < htmlTypes.length; i++) {
744                         assistant.setContentAssistProcessor(processor, htmlTypes[i]);
745                 }
746                 processor = new PHPCompletionProcessor(getEditor());
747
748                 assistant.setContentAssistProcessor(processor,
749                                 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
750                 assistant.setContentAssistProcessor(processor,
751                                 IPHPPartitions.PHP_PARTITIONING);
752                 assistant.setContentAssistProcessor(processor,
753                                 IPHPPartitions.PHP_STRING_DQ);
754                 assistant.setContentAssistProcessor(processor,
755                                 IPHPPartitions.PHP_STRING_SQ);
756                 assistant.setContentAssistProcessor(processor,
757                                 IPHPPartitions.PHP_STRING_HEREDOC);
758
759                 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(
760                                 getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
761                 // assistant.enableAutoActivation(true);
762                 // assistant.setAutoActivationDelay(500);
763                 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
764                 // ContentAssistPreference.configure(assistant, getPreferenceStore());
765                 // assistant.setContextInformationPopupOrientation(
766                 // ContentAssistant.CONTEXT_INFO_ABOVE);
767                 // assistant.setContextInformationPopupBackground(
768                 // PHPEditorEnvironment.getPHPColorProvider().getColor(
769                 // new RGB(150, 150, 0)));
770                 ContentAssistPreference.configure(assistant, getPreferenceStore());
771                 assistant
772                                 .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
773                 assistant
774                                 .setInformationControlCreator(getInformationControlCreator(sourceViewer));
775                 return assistant;
776         }
777
778         /*
779          * (non-Javadoc) Method declared on SourceViewerConfiguration
780          */
781         // public String getDefaultPrefix(ISourceViewer sourceViewer, String
782         // contentType) {
783         // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
784         // //$NON-NLS-1$
785         // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
786         // null); //$NON-NLS-1$
787         // }
788         /*
789          * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
790          * @since 2.0
791          */
792         public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
793                         String contentType) {
794                 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
795         }
796
797         /*
798          * (non-Javadoc) Method declared on SourceViewerConfiguration
799          */
800         public ITextDoubleClickStrategy getDoubleClickStrategy(
801                         ISourceViewer sourceViewer, String contentType) {
802                 return new PHPDoubleClickSelector();
803         }
804
805         /*
806          * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
807          */
808         public String[] getIndentPrefixes(ISourceViewer sourceViewer,
809                         String contentType) {
810                 Vector vector = new Vector();
811                 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
812                 final IPreferenceStore preferences = WebUI.getDefault()
813                                 .getPreferenceStore();
814                 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
815                 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
816                 for (int i = 0; i <= tabWidth; i++) {
817                         StringBuffer prefix = new StringBuffer();
818                         if (useSpaces) {
819                                 for (int j = 0; j + i < tabWidth; j++)
820                                         prefix.append(' ');
821                                 if (i != 0)
822                                         prefix.append('\t');
823                         } else {
824                                 for (int j = 0; j < i; j++)
825                                         prefix.append(' ');
826                                 if (i != tabWidth)
827                                         prefix.append('\t');
828                         }
829                         vector.add(prefix.toString());
830                 }
831                 vector.add(""); //$NON-NLS-1$
832                 return (String[]) vector.toArray(new String[vector.size()]);
833         }
834
835         /**
836          * @return <code>true</code> iff the new setup without text tools is in
837          *         use.
838          * 
839          * @since 3.0
840          */
841         // private boolean isNewSetup() {
842         // return fJavaTextTools == null;
843         // }
844         /**
845          * Creates and returns a preference store which combines the preference
846          * stores from the text tools and which is read-only.
847          * 
848          * @return the read-only preference store
849          * @since 3.0
850          */
851         // private IPreferenceStore createPreferenceStore() {
852         // Assert.isTrue(!isNewSetup());
853         // IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
854         // if (fJavaTextTools.getCorePreferenceStore() == null)
855         // return new ChainedPreferenceStore(new IPreferenceStore[] {
856         // fJavaTextTools.getPreferenceStore(), generalTextStore });
857         //
858         // return new ChainedPreferenceStore(new IPreferenceStore[] {
859         // fJavaTextTools.getPreferenceStore(),
860         // new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()),
861         // generalTextStore });
862         // }
863         /*
864          * (non-Javadoc) Method declared on SourceViewerConfiguration
865          */
866         public IPresentationReconciler getPresentationReconciler(
867                         ISourceViewer sourceViewer) {
868                 // PHPColorProvider provider =
869                 // PHPEditorEnvironment.getPHPColorProvider();
870                 // JavaColorManager provider =
871                 // PHPEditorEnvironment.getPHPColorProvider();
872                 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
873                 phpReconciler
874                                 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
875
876                 // DefaultDamagerRepairer dr = new
877                 // DefaultDamagerRepairer(getHTMLScanner());
878                 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
879                 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
880                 // dr = new DefaultDamagerRepairer(getHTMLScanner());
881                 // reconciler.setDamager(dr, IPHPPartitions.HTML);
882                 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
883                 // dr = new DefaultDamagerRepairer(getHTMLScanner());
884                 // reconciler.setDamager(dr, IPHPPartitions.CSS);
885                 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
886                 // dr = new DefaultDamagerRepairer(getHTMLScanner());
887                 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
888                 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
889                 // dr = new DefaultDamagerRepairer(getHTMLScanner());
890                 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
891                 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
892                 // dr = new DefaultDamagerRepairer(getHTMLScanner());
893                 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
894                 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
895                 // DefaultDamagerRepairer phpDR = new
896                 // DefaultDamagerRepairer(getSmartyScanner());
897                 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
898                 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
899                 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
900                 // phpReconciler.setDamager(phpDR,
901                 // IPHPPartitions.SMARTY_MULTILINE_COMMENT);
902                 // phpReconciler.setRepairer(phpDR,
903                 // IPHPPartitions.SMARTY_MULTILINE_COMMENT);
904                 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new
905                 // TextAttribute(fJavaTextTools.getColorManager().getColor(
906                 // PHPColorProvider.MULTI_LINE_COMMENT))));
907                 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
908                 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
909
910                 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(
911                                 getCodeScanner());
912                 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
913                 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
914
915                 phpDR = new DefaultDamagerRepairer(getCodeScanner());
916                 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
917                 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
918
919                 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
920                 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
921                 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
922
923                 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
924                 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
925                 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
926                 phpDR = new DefaultDamagerRepairer(getStringSQScanner());
927                 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
928                 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
929                 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
930                 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
931                 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
932                 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
933                 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
934                 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
935                 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
936                 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
937                 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
938
939                 PresentationReconciler reconciler = new PresentationReconciler();
940                 reconciler
941                                 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
942                 //
943                 // JavaTextTools jspTextTools =
944                 // PHPeclipsePlugin.getDefault().getJavaTextTools();
945                 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
946                                 getPHPDocScanner());// jspTextTools.getJSPTextScanner());
947                 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
948                 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
949
950                 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new
951                 // TextAttribute(fJavaTextTools.getColorManager().getColor(
952                 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
953                 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
954                 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
955
956                 // xml partitions
957                 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration
958                                 .getPresentationReconciler(sourceViewer), xmlConfiguration
959                                 .getConfiguredContentTypes(sourceViewer),
960                                 PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
961
962                 // java partitions
963                 configureEmbeddedPresentationReconciler(reconciler, phpReconciler,
964                                 getConfiguredPHPContentTypes(),
965                                 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
966
967                 return reconciler;
968         }
969
970         private void configureEmbeddedPresentationReconciler(
971                         PresentationReconciler reconciler,
972                         IPresentationReconciler embedded, String[] types, String defaultType) {
973                 for (int i = 0; i < types.length; i++) {
974                         String type = types[i];
975
976                         IPresentationDamager damager = embedded.getDamager(type);
977                         IPresentationRepairer repairer = embedded.getRepairer(type);
978
979                         if (type == IDocument.DEFAULT_CONTENT_TYPE) {
980                                 type = defaultType;
981                         }
982
983                         reconciler.setDamager(damager, type);
984                         reconciler.setRepairer(repairer, type);
985                 }
986         }
987
988         /*
989          * (non-Javadoc) Method declared on SourceViewerConfiguration
990          */
991         public int getTabWidth(ISourceViewer sourceViewer) {
992                 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
993         }
994
995         /*
996          * (non-Javadoc) Method declared on SourceViewerConfiguration
997          */
998         // public ITextHover getTextHover(ISourceViewer sourceViewer, String
999         // contentType) {
1000         // if (fEditor != null) {
1001         // IEditorInput editorInput = fEditor.getEditorInput();
1002         // if (editorInput instanceof IFileEditorInput) {
1003         // try {
1004         // IFile f = ((IFileEditorInput) editorInput).getFile();
1005         // return new PHPTextHover(f.getProject());
1006         // } catch (NullPointerException e) {
1007         // // this exception occurs, if getTextHover is called by preference pages
1008         // !
1009         // }
1010         // }
1011         // }
1012         // return new PHPTextHover(null);
1013         // }
1014         /*
1015          * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
1016          * @since 2.0
1017          */
1018         public IInformationControlCreator getInformationControlCreator(
1019                         ISourceViewer sourceViewer) {
1020                 return new IInformationControlCreator() {
1021                         public IInformationControl createInformationControl(Shell parent) {
1022 //incastrix
1023                                 //                              return new DefaultInformationControl(parent, SWT.NONE,
1024 //                                              new HTMLTextPresenter(true));
1025                                 return new DefaultInformationControl(parent,
1026                                                 new HTMLTextPresenter(true));
1027                                 // return new HoverBrowserControl(parent);
1028                         }
1029                 };
1030         }
1031
1032         /*
1033          * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
1034          * @since 2.0
1035          */
1036         public IInformationPresenter getInformationPresenter(
1037                         ISourceViewer sourceViewer) {
1038                 InformationPresenter presenter = new InformationPresenter(
1039                                 getInformationPresenterControlCreator(sourceViewer));
1040                 presenter
1041                                 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
1042                 IInformationProvider provider = new JavaInformationProvider(getEditor());
1043                 presenter.setInformationProvider(provider,
1044                                 IDocument.DEFAULT_CONTENT_TYPE);
1045                 presenter.setInformationProvider(provider,
1046                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
1047                 // presenter.setInformationProvider(provider,
1048                 // IPHPPartitions.JAVA_CHARACTER);
1049                 presenter.setSizeConstraints(60, 10, true, true);
1050                 return presenter;
1051         }
1052
1053         /*
1054          * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
1055          * @since 2.0
1056          */
1057         // public IInformationPresenter getInformationPresenter(ISourceViewer
1058         // sourceViewer) {
1059         // InformationPresenter presenter= new
1060         // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
1061         // IInformationProvider provider= new JavaInformationProvider(getEditor());
1062         // presenter.setInformationProvider(provider,
1063         // IDocument.DEFAULT_CONTENT_TYPE);
1064         // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
1065         // presenter.setSizeConstraints(60, 10, true, true);
1066         // return presenter;
1067         // }
1068         /**
1069          * Returns the information presenter control creator. The creator is a
1070          * factory creating the presenter controls for the given source viewer. This
1071          * implementation always returns a creator for
1072          * <code>DefaultInformationControl</code> instances.
1073          * 
1074          * @param sourceViewer
1075          *            the source viewer to be configured by this configuration
1076          * @return an information control creator
1077          * @since 2.1
1078          */
1079         private IInformationControlCreator getInformationPresenterControlCreator(
1080                         ISourceViewer sourceViewer) {
1081                 return new IInformationControlCreator() {
1082                         public IInformationControl createInformationControl(Shell parent) {
1083                                 int shellStyle = SWT.RESIZE;
1084                                 int style = SWT.V_SCROLL | SWT.H_SCROLL;
1085                                 return new DefaultInformationControl(parent, shellStyle, style,
1086                                                 new HTMLTextPresenter(false));
1087                                 // return new HoverBrowserControl(parent);
1088                         }
1089                 };
1090         }
1091
1092         /**
1093          * Returns the outline presenter control creator. The creator is a factory
1094          * creating outline presenter controls for the given source viewer. This
1095          * implementation always returns a creator for
1096          * <code>JavaOutlineInformationControl</code> instances.
1097          * 
1098          * @param sourceViewer
1099          *            the source viewer to be configured by this configuration
1100          * @return an information control creator
1101          * @since 2.1
1102          */
1103         private IInformationControlCreator getOutlinePresenterControlCreator(
1104                         ISourceViewer sourceViewer) {
1105                 return new IInformationControlCreator() {
1106                         public IInformationControl createInformationControl(Shell parent) {
1107                                 int shellStyle = SWT.RESIZE;
1108                                 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
1109                                 return new JavaOutlineInformationControl(parent, shellStyle,
1110                                                 treeStyle);
1111                         }
1112                 };
1113         }
1114
1115         /**
1116          * Returns the outline presenter which will determine and shown information
1117          * requested for the current cursor position.
1118          * 
1119          * @param sourceViewer
1120          *            the source viewer to be configured by this configuration
1121          * @param doCodeResolve
1122          *            a boolean which specifies whether code resolve should be used
1123          *            to compute the Java element
1124          * @return an information presenter
1125          * @since 2.1
1126          */
1127         public IInformationPresenter getOutlinePresenter(
1128                         ISourceViewer sourceViewer, boolean doCodeResolve) {
1129                 InformationPresenter presenter = new InformationPresenter(
1130                                 getOutlinePresenterControlCreator(sourceViewer));
1131                 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
1132                 IInformationProvider provider = new JavaElementProvider(getEditor(),
1133                                 doCodeResolve);
1134                 presenter.setInformationProvider(provider,
1135                                 IDocument.DEFAULT_CONTENT_TYPE);
1136                 presenter.setInformationProvider(provider,
1137                                 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
1138                 presenter.setInformationProvider(provider,
1139                                 IPHPPartitions.PHP_PARTITIONING);
1140                 presenter.setInformationProvider(provider,
1141                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
1142                 presenter.setInformationProvider(provider,
1143                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
1144                 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
1145                 presenter.setInformationProvider(provider,
1146                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
1147                 presenter.setSizeConstraints(40, 20, true, false);
1148                 return presenter;
1149         }
1150 }