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