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