misc changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPSourceViewerConfiguration.java
1 /**********************************************************************
2  Copyright (c) 2000, 2002 IBM Corp. and others.
3  All rights reserved. This program and the accompanying materials
4  are made available under the terms of the Common Public License v1.0
5  which accompanies this distribution, and is available at
6  http://www.eclipse.org/legal/cpl-v10.html
7
8  Contributors:
9  IBM Corporation - Initial implementation
10  Klaus Hartlage - www.eclipseproject.de
11  **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
13 import java.util.Vector;
14
15 import net.sourceforge.phpdt.core.JavaCore;
16 import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
17 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
18 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
19 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
20 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
21 import net.sourceforge.phpdt.internal.ui.text.JavaCompositeReconcilingStrategy;
22 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
23 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
24 import net.sourceforge.phpdt.internal.ui.text.JavaPresentationReconciler;
25 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
26 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
27 import net.sourceforge.phpdt.internal.ui.text.java.JavaReconcilingStrategy;
28 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategy;
29 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
30 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
31 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
32 import net.sourceforge.phpdt.ui.PreferenceConstants;
33 import net.sourceforge.phpdt.ui.text.IColorManager;
34 import net.sourceforge.phpdt.ui.text.JavaTextTools;
35 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
36 import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
37 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
38 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
39 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
40 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
41 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
42
43 import org.eclipse.core.runtime.NullProgressMonitor;
44 import org.eclipse.jface.preference.IPreferenceStore;
45 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
46 import org.eclipse.jface.text.DefaultInformationControl;
47 import org.eclipse.jface.text.IAutoIndentStrategy;
48 import org.eclipse.jface.text.IDocument;
49 import org.eclipse.jface.text.IInformationControl;
50 import org.eclipse.jface.text.IInformationControlCreator;
51 import org.eclipse.jface.text.ITextDoubleClickStrategy;
52 import org.eclipse.jface.text.ITextHover;
53 import org.eclipse.jface.text.ITextViewerExtension2;
54 import org.eclipse.jface.text.TextAttribute;
55 import org.eclipse.jface.text.contentassist.ContentAssistant;
56 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
57 import org.eclipse.jface.text.contentassist.IContentAssistant;
58 import org.eclipse.jface.text.formatter.ContentFormatter;
59 import org.eclipse.jface.text.formatter.IContentFormatter;
60 import org.eclipse.jface.text.formatter.IFormattingStrategy;
61 import org.eclipse.jface.text.information.IInformationPresenter;
62 import org.eclipse.jface.text.information.IInformationProvider;
63 import org.eclipse.jface.text.information.InformationPresenter;
64 import org.eclipse.jface.text.presentation.IPresentationReconciler;
65 import org.eclipse.jface.text.presentation.PresentationReconciler;
66 import org.eclipse.jface.text.reconciler.IReconciler;
67 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
68 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
69 import org.eclipse.jface.text.rules.DefaultPartitioner;
70 import org.eclipse.jface.text.rules.RuleBasedScanner;
71 import org.eclipse.jface.text.rules.Token;
72 import org.eclipse.jface.text.source.IAnnotationHover;
73 import org.eclipse.jface.text.source.ISourceViewer;
74 import org.eclipse.jface.text.source.SourceViewerConfiguration;
75 import org.eclipse.jface.util.PropertyChangeEvent;
76 import org.eclipse.swt.SWT;
77 import org.eclipse.swt.widgets.Shell;
78 import org.eclipse.ui.texteditor.ITextEditor;
79 /**
80  * Configuration for an <code>SourceViewer</code> which shows PHP code.
81  */
82 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
83         /**
84          * Preference key used to look up display tab width.
85          * 
86          * @since 2.0
87          */
88         public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
89         /**
90          * Preference key for inserting spaces rather than tabs.
91          * 
92          * @since 2.0
93          */
94         public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
95         //  public static final String HTML_DEFAULT =
96         // IPHPPartitionScannerConstants.HTML;
97         //IDocument.DEFAULT_CONTENT_TYPE;
98         private JavaTextTools fJavaTextTools;
99         private ITextEditor fTextEditor;
100         private ContentFormatter fFormatter;
101         private HTMLFormattingStrategy fFormattingStrategy;
102         /**
103          * Single token scanner.
104          */
105         static class SingleTokenScanner extends BufferedRuleBasedScanner {
106                 public SingleTokenScanner(TextAttribute attribute) {
107                         setDefaultReturnToken(new Token(attribute));
108                 }
109         };
110         /**
111          * The document partitioning.
112          * @since 3.0
113          */
114         private String fDocumentPartitioning;
115         /**
116          * The Java source code scanner
117          * @since 3.0
118          */
119         private AbstractJavaScanner fCodeScanner;
120         /** 
121          * The Java multi-line comment scanner 
122          * @since 3.0
123          */
124         private AbstractJavaScanner fMultilineCommentScanner;
125         /**
126          * The Java single-line comment scanner
127          * @since 3.0
128          */
129         private AbstractJavaScanner fSinglelineCommentScanner;
130         /**
131          * The Java string scanner
132          * @since 3.0
133          */
134         private AbstractJavaScanner fStringScanner;
135         /**
136          * The Javadoc scanner
137          * @since 3.0
138          */
139         private AbstractJavaScanner fJavaDocScanner;
140         /**
141          * The preference store, can be read-only
142          * @since 3.0
143          */
144         private IPreferenceStore fPreferenceStore;
145         /**
146          * The color manager
147          * @since 3.0
148          */
149         private IColorManager fColorManager;
150         
151         /**
152          * Creates a new Java source viewer configuration for viewers in the given editor 
153          * using the given preference store, the color manager and the specified document partitioning.
154          * <p>
155          * Creates a Java source viewer configuration in the new setup without text tools. Clients are
156          * allowed to call {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}
157          * and disallowed to call {@link JavaSourceViewerConfiguration#getPreferenceStore()} on the resulting
158          * Java source viewer configuration.
159          * </p>
160          *
161          * @param colorManager the color manager
162          * @param preferenceStore the preference store, can be read-only
163          * @param editor the editor in which the configured viewer(s) will reside
164          * @param partitioning the document partitioning for this configuration
165          * @since 3.0
166          */
167         public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
168                 fColorManager= colorManager;
169                 fPreferenceStore= preferenceStore;
170                 fTextEditor= editor;
171                 fDocumentPartitioning= partitioning;
172                 fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
173 //              initializeScanners();
174         }
175
176         /**
177          * Default constructor.
178          */
179         public PHPSourceViewerConfiguration(JavaTextTools textTools,
180                         PHPEditor editor) {
181                 fJavaTextTools = textTools;
182                 fTextEditor = editor;
183         }
184         /*
185          * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
186          */
187         public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
188                 //    if (fFormatter == null) {
189                 //      fFormatter = new ContentFormatter();
190                 //      fFormattingStrategy = new HTMLFormattingStrategy(this,
191                 // sourceViewer);
192                 //      fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
193                 //      fFormatter.enablePartitionAwareFormatting(false);
194                 //      fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
195                 //    }
196                 //    return fFormatter;
197                 if (fFormatter == null) {
198                         //ContentFormatter
199                         fFormatter = new ContentFormatter();
200                         IFormattingStrategy strategy = new JavaFormattingStrategy(
201                                         sourceViewer);
202                         fFormatter.setFormattingStrategy(strategy,
203                                         IDocument.DEFAULT_CONTENT_TYPE);
204                         fFormatter.enablePartitionAwareFormatting(false);
205                         fFormatter
206                                         .setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
207                 }
208                 return fFormatter;
209         }
210         /**
211          * Returns the names of the document position categories used by the
212          * document partitioners created by this object to manage their partition
213          * information. If the partitioners don't use document position categories,
214          * the returned result is <code>null</code>.
215          * 
216          * @return the partition managing position categories or <code>null</code>
217          *         if there is none
218          */
219         public String[] getPartitionManagingPositionCategories() {
220                 return new String[]{DefaultPartitioner.CONTENT_TYPES_CATEGORY};
221         }
222         //  /**
223         //   * Returns the names of the document position categories used by the
224         // document
225         //   * partitioners created by this object to manage their partition
226         // information.
227         //   * If the partitioners don't use document position categories, the
228         // returned
229         //   * result is <code>null</code>.
230         //   *
231         //   * @return the partition managing position categories or
232         // <code>null</code>
233         //   * if there is none
234         //   */
235         //  private String[] getPartitionManagingPositionCategories() {
236         //    return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
237         //  }
238         public ITextEditor getEditor() {
239                 return fTextEditor;
240         }
241         /**
242          * Returns the preference store used by this configuration to initialize
243          * the individual bits and pieces.
244          * 
245          * @return the preference store used to initialize this configuration
246          * 
247          * @since 2.0
248          */
249         protected IPreferenceStore getPreferenceStore() {
250                 return PHPeclipsePlugin.getDefault().getPreferenceStore();
251         }
252         //  /* (non-Javadoc)
253         //   * Method declared on SourceViewerConfiguration
254         //   */
255         //  public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
256         //    return new PHPAnnotationHover();
257         //  }
258         /*
259          * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
260          */
261         public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
262                 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
263         }
264         /*
265          * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
266          * @since 3.0
267          */
268         public IAnnotationHover getOverviewRulerAnnotationHover(
269                         ISourceViewer sourceViewer) {
270                 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
271         }
272         /*
273          * (non-Javadoc) Method declared on SourceViewerConfiguration
274          */
275         public IAutoIndentStrategy getAutoIndentStrategy(
276                         ISourceViewer sourceViewer, String contentType) {
277                 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
278                         return new JavaStringAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
279
280                 return (IPHPPartitions.PHP_PARTITIONING.equals(contentType)
281                                 ? new PHPAutoIndentStrategy()
282                                 : new DefaultAutoIndentStrategy());
283         }
284         /**
285          * Returns the PHP source code scanner for this configuration.
286          * 
287          * @return the PHP source code scanner
288          */
289         protected RuleBasedScanner getCodeScanner() {
290                 return fJavaTextTools.getCodeScanner();
291         }
292         /**
293          * Returns the HTML source code scanner for this configuration.
294          * 
295          * @return the HTML source code scanner
296          */
297         protected RuleBasedScanner getHTMLScanner() {
298                 return fJavaTextTools.getHTMLScanner();
299         }
300         /**
301          * Returns the Smarty source code scanner for this configuration.
302          * 
303          * @return the Smarty source code scanner
304          */
305         protected RuleBasedScanner getSmartyScanner() {
306                 return fJavaTextTools.getSmartyScanner();
307         }
308         /*
309          * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
310          */
311         /*
312          * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
313          */
314         public IReconciler getReconciler(ISourceViewer sourceViewer) {
315
316                 final ITextEditor editor= getEditor();
317                 if (editor != null && editor.isEditable()) {
318                         
319                         JavaCompositeReconcilingStrategy strategy= new JavaCompositeReconcilingStrategy(editor, getConfiguredDocumentPartitioning(sourceViewer));
320                         JavaReconciler reconciler= new JavaReconciler(editor, strategy, false);
321                         reconciler.setIsIncrementalReconciler(false);
322                         reconciler.setProgressMonitor(new NullProgressMonitor());
323                         reconciler.setDelay(500);
324
325                         return reconciler;
326                 }
327                 return null;
328         }
329 //      public IReconciler getReconciler(ISourceViewer sourceViewer) {
330 //              if (getEditor() != null && getEditor().isEditable()) {
331 //                      JavaReconciler reconciler = new JavaReconciler(getEditor(),
332 //                                      new JavaReconcilingStrategy(getEditor()), false);
333 //                      reconciler.setProgressMonitor(new NullProgressMonitor());
334 //                      reconciler.setDelay(500);
335 //                      return reconciler;
336 //              }
337 //              return null;
338 //      }
339         /*
340          * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer,
341          *      String)
342          * @since 2.1
343          */
344         public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer,
345                         String contentType) {
346                 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
347                                 .getDefault().getJavaEditorTextHoverDescriptors();
348                 int stateMasks[] = new int[hoverDescs.length];
349                 int stateMasksLength = 0;
350                 for (int i = 0; i < hoverDescs.length; i++) {
351                         if (hoverDescs[i].isEnabled()) {
352                                 int j = 0;
353                                 int stateMask = hoverDescs[i].getStateMask();
354                                 while (j < stateMasksLength) {
355                                         if (stateMasks[j] == stateMask)
356                                                 break;
357                                         j++;
358                                 }
359                                 if (j == stateMasksLength)
360                                         stateMasks[stateMasksLength++] = stateMask;
361                         }
362                 }
363                 if (stateMasksLength == hoverDescs.length)
364                         return stateMasks;
365                 int[] shortenedStateMasks = new int[stateMasksLength];
366                 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0,
367                                 stateMasksLength);
368                 return shortenedStateMasks;
369         }
370         /*
371          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
372          * @since 2.1
373          */
374         public ITextHover getTextHover(ISourceViewer sourceViewer,
375                         String contentType, int stateMask) {
376                 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
377                                 .getDefault().getJavaEditorTextHoverDescriptors();
378                 int i = 0;
379                 while (i < hoverDescs.length) {
380                         if (hoverDescs[i].isEnabled()
381                                         && hoverDescs[i].getStateMask() == stateMask)
382                                 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
383                         i++;
384                 }
385                 return null;
386 //              if (fEditor != null) {
387 //                      IEditorInput editorInput = fEditor.getEditorInput();
388 //                      if (editorInput instanceof IFileEditorInput) {
389 //                              try {
390 //                                      IFile f = ((IFileEditorInput) editorInput).getFile();
391 //                                      return new PHPTextHover(f.getProject());
392 //                              } catch (NullPointerException e) {
393 //                                      // this exception occurs, if getTextHover is called by
394 //                                      // preference pages !
395 //                              }
396 //                      }
397 //              }
398 //              return new PHPTextHover(null);
399         }
400         /*
401          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
402          */
403         public ITextHover getTextHover(ISourceViewer sourceViewer,
404                         String contentType) {
405                 return getTextHover(sourceViewer, contentType,
406                                 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
407         }
408         /**
409          * Returns the SmartyDoc source code scanner for this configuration.
410          * 
411          * @return the SmartyDoc source code scanner
412          */
413         protected RuleBasedScanner getSmartyDocScanner() {
414                 return fJavaTextTools.getSmartyDocScanner();
415         }
416         /**
417          * Returns the PHPDoc source code scanner for this configuration.
418          * 
419          * @return the PHPDoc source code scanner
420          */
421         protected RuleBasedScanner getPHPDocScanner() {
422                 return fJavaTextTools.getJavaDocScanner();
423         }
424         /*
425          * (non-Javadoc) Method declared on SourceViewerConfiguration
426          */
427         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
428                 return new String[]{IPHPPartitions.HTML,
429                                 IPHPPartitions.HTML_MULTILINE_COMMENT,
430                                 IPHPPartitions.PHP_PARTITIONING,
431                                 IPHPPartitions.PHP_PHPDOC_COMMENT,
432                                 IPHPPartitions.CSS,
433                                 IPHPPartitions.CSS_MULTILINE_COMMENT,
434                                 IPHPPartitions.JAVASCRIPT,
435                                 IPHPPartitions.JS_MULTILINE_COMMENT,
436                                 IPHPPartitions.SMARTY,
437                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
438                                 IDocument.DEFAULT_CONTENT_TYPE};
439         }
440         /*
441          * (non-Javadoc) Method declared on SourceViewerConfiguration
442          */
443         public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
444                 ContentAssistant assistant = new ContentAssistant();
445                 IContentAssistProcessor processor = new HTMLCompletionProcessor();
446                 assistant.setContentAssistProcessor(processor,
447                                 IPHPPartitions.HTML);
448                 assistant.setContentAssistProcessor(processor,
449                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
450                 assistant.setContentAssistProcessor(processor,
451                                 IDocument.DEFAULT_CONTENT_TYPE);
452                 assistant.setContentAssistProcessor(processor,
453                                 IPHPPartitions.CSS);
454                 assistant.setContentAssistProcessor(processor,
455                                 IPHPPartitions.CSS_MULTILINE_COMMENT);
456                 assistant.setContentAssistProcessor(processor,
457                                 IPHPPartitions.JAVASCRIPT);
458                 assistant.setContentAssistProcessor(processor,
459                                 IPHPPartitions.JS_MULTILINE_COMMENT);
460                 // TODO define special smarty partition content assist
461                 assistant.setContentAssistProcessor(processor,
462                                 IPHPPartitions.SMARTY);
463                 assistant.setContentAssistProcessor(processor,
464                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
465                 assistant.setContentAssistProcessor(new PHPCompletionProcessor(getEditor()),
466                                 IPHPPartitions.PHP_PARTITIONING);
467                 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(),
468                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
469                 //    assistant.enableAutoActivation(true);
470                 //    assistant.setAutoActivationDelay(500);
471                 //    assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
472                 //    ContentAssistPreference.configure(assistant, getPreferenceStore());
473                 //    assistant.setContextInformationPopupOrientation(
474                 //      ContentAssistant.CONTEXT_INFO_ABOVE);
475                 //    assistant.setContextInformationPopupBackground(
476                 //      PHPEditorEnvironment.getPHPColorProvider().getColor(
477                 //        new RGB(150, 150, 0)));
478                 ContentAssistPreference.configure(assistant, getPreferenceStore());
479                 assistant
480                                 .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
481                 assistant
482                                 .setInformationControlCreator(getInformationControlCreator(sourceViewer));
483                 return assistant;
484         }
485         /*
486          * (non-Javadoc) Method declared on SourceViewerConfiguration
487          */
488         //  public String getDefaultPrefix(ISourceViewer sourceViewer, String
489         // contentType) {
490         //    return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
491         // //$NON-NLS-1$
492         //    // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
493         // null); //$NON-NLS-1$
494         //  }
495         /*
496          * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
497          * @since 2.0
498          */
499         public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
500                         String contentType) {
501                 return new String[]{"//", ""}; //$NON-NLS-1$ //$NON-NLS-2$
502         }
503         /*
504          * (non-Javadoc) Method declared on SourceViewerConfiguration
505          */
506         public ITextDoubleClickStrategy getDoubleClickStrategy(
507                         ISourceViewer sourceViewer, String contentType) {
508                 return new PHPDoubleClickSelector();
509         }
510         /*
511          * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
512          */
513         public String[] getIndentPrefixes(ISourceViewer sourceViewer,
514                         String contentType) {
515                 Vector vector = new Vector();
516                 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
517                 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault()
518                                 .getPreferenceStore();
519                 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
520                 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
521                 for (int i = 0; i <= tabWidth; i++) {
522                         StringBuffer prefix = new StringBuffer();
523                         if (useSpaces) {
524                                 for (int j = 0; j + i < tabWidth; j++)
525                                         prefix.append(' ');
526                                 if (i != 0)
527                                         prefix.append('\t');
528                         } else {
529                                 for (int j = 0; j < i; j++)
530                                         prefix.append(' ');
531                                 if (i != tabWidth)
532                                         prefix.append('\t');
533                         }
534                         vector.add(prefix.toString());
535                 }
536                 vector.add(""); //$NON-NLS-1$
537                 return (String[]) vector.toArray(new String[vector.size()]);
538         }
539         /*
540          * (non-Javadoc) Method declared on SourceViewerConfiguration
541          */
542         public IPresentationReconciler getPresentationReconciler(
543                         ISourceViewer sourceViewer) {
544                 //  PHPColorProvider provider =
545                 // PHPEditorEnvironment.getPHPColorProvider();
546                 //    JavaColorManager provider =
547                 // PHPEditorEnvironment.getPHPColorProvider();
548                 PresentationReconciler reconciler= new JavaPresentationReconciler();
549                 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
550
551                 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
552                 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
553                 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
554                 dr = new DefaultDamagerRepairer(getHTMLScanner());
555                 reconciler.setDamager(dr, IPHPPartitions.HTML);
556                 reconciler.setRepairer(dr, IPHPPartitions.HTML);
557                 dr = new DefaultDamagerRepairer(getHTMLScanner());
558                 reconciler.setDamager(dr, IPHPPartitions.CSS);
559                 reconciler.setRepairer(dr, IPHPPartitions.CSS);
560                 dr = new DefaultDamagerRepairer(getHTMLScanner());
561                 reconciler.setDamager(dr,
562                                 IPHPPartitions.CSS_MULTILINE_COMMENT);
563                 reconciler.setRepairer(dr,
564                                 IPHPPartitions.CSS_MULTILINE_COMMENT);
565                 dr = new DefaultDamagerRepairer(getHTMLScanner());
566                 reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
567                 reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
568                 dr = new DefaultDamagerRepairer(getHTMLScanner());
569                 reconciler.setDamager(dr,
570                                 IPHPPartitions.JS_MULTILINE_COMMENT);
571                 reconciler.setRepairer(dr,
572                                 IPHPPartitions.JS_MULTILINE_COMMENT);
573                 dr = new DefaultDamagerRepairer(getSmartyScanner());
574                 reconciler.setDamager(dr, IPHPPartitions.SMARTY);
575                 reconciler.setRepairer(dr, IPHPPartitions.SMARTY);
576                 dr = new DefaultDamagerRepairer(getSmartyDocScanner());
577                 reconciler.setDamager(dr,
578                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
579                 reconciler.setRepairer(dr,
580                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
581                 dr = new DefaultDamagerRepairer(new SingleTokenScanner(
582                                 new TextAttribute(fJavaTextTools.getColorManager().getColor(
583                                                 PHPColorProvider.MULTI_LINE_COMMENT))));
584                 reconciler.setDamager(dr,
585                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
586                 reconciler.setRepairer(dr,
587                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
588                 dr = new DefaultDamagerRepairer(getCodeScanner());
589                 reconciler.setDamager(dr, IPHPPartitions.PHP_PARTITIONING);
590                 reconciler.setRepairer(dr, IPHPPartitions.PHP_PARTITIONING);
591                 dr = new DefaultDamagerRepairer(getPHPDocScanner());
592                 reconciler.setDamager(dr,
593                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
594                 reconciler.setRepairer(dr,
595                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
596                 return reconciler;
597         }
598         /*
599          * (non-Javadoc) Method declared on SourceViewerConfiguration
600          */
601         public int getTabWidth(ISourceViewer sourceViewer) {
602                 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
603         }
604         /*
605          * (non-Javadoc) Method declared on SourceViewerConfiguration
606          */
607         //  public ITextHover getTextHover(ISourceViewer sourceViewer, String
608         // contentType) {
609         //    if (fEditor != null) {
610         //      IEditorInput editorInput = fEditor.getEditorInput();
611         //      if (editorInput instanceof IFileEditorInput) {
612         //        try {
613         //          IFile f = ((IFileEditorInput) editorInput).getFile();
614         //          return new PHPTextHover(f.getProject());
615         //        } catch (NullPointerException e) {
616         //          // this exception occurs, if getTextHover is called by preference pages
617         // !
618         //        }
619         //      }
620         //    }
621         //    return new PHPTextHover(null);
622         //  }
623         /*
624          * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
625          * @since 2.0
626          */
627         public IInformationControlCreator getInformationControlCreator(
628                         ISourceViewer sourceViewer) {
629                 return new IInformationControlCreator() {
630                         public IInformationControl createInformationControl(Shell parent) {
631                                 return new DefaultInformationControl(parent, SWT.NONE,
632                                                 new HTMLTextPresenter(true));
633                                 // return new HoverBrowserControl(parent);
634                         }
635                 };
636         }
637         /*
638          * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
639          * @since 2.0
640          */
641         //      public IInformationPresenter getInformationPresenter(ISourceViewer
642         // sourceViewer) {
643         //              InformationPresenter presenter= new
644         // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
645         //              IInformationProvider provider= new JavaInformationProvider(getEditor());
646         //              presenter.setInformationProvider(provider,
647         // IDocument.DEFAULT_CONTENT_TYPE);
648         //              presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
649         //              presenter.setSizeConstraints(60, 10, true, true);
650         //              return presenter;
651         //      }
652         /**
653          * Returns the information presenter control creator. The creator is a
654          * factory creating the presenter controls for the given source viewer.
655          * This implementation always returns a creator for <code>DefaultInformationControl</code>
656          * instances.
657          * 
658          * @param sourceViewer
659          *            the source viewer to be configured by this configuration
660          * @return an information control creator
661          * @since 2.1
662          */
663         private IInformationControlCreator getInformationPresenterControlCreator(
664                         ISourceViewer sourceViewer) {
665                 return new IInformationControlCreator() {
666                         public IInformationControl createInformationControl(Shell parent) {
667                                 int shellStyle = SWT.RESIZE;
668                                 int style = SWT.V_SCROLL | SWT.H_SCROLL;
669                                 return new DefaultInformationControl(parent, shellStyle, style,
670                                                 new HTMLTextPresenter(false));
671                                 // return new HoverBrowserControl(parent);
672                         }
673                 };
674         }
675         /**
676          * Returns the outline presenter control creator. The creator is a factory
677          * creating outline presenter controls for the given source viewer. This
678          * implementation always returns a creator for <code>JavaOutlineInformationControl</code>
679          * instances.
680          * 
681          * @param sourceViewer
682          *            the source viewer to be configured by this configuration
683          * @return an information control creator
684          * @since 2.1
685          */
686         private IInformationControlCreator getOutlinePresenterControlCreator(
687                         ISourceViewer sourceViewer) {
688                 return new IInformationControlCreator() {
689                         public IInformationControl createInformationControl(Shell parent) {
690                                 int shellStyle = SWT.RESIZE;
691                                 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
692                                 return new JavaOutlineInformationControl(parent, shellStyle,
693                                                 treeStyle);
694                         }
695                 };
696         }
697         /**
698          * Returns the outline presenter which will determine and shown information
699          * requested for the current cursor position.
700          * 
701          * @param sourceViewer
702          *            the source viewer to be configured by this configuration
703          * @param doCodeResolve
704          *            a boolean which specifies whether code resolve should be used
705          *            to compute the Java element
706          * @return an information presenter
707          * @since 2.1
708          */
709         public IInformationPresenter getOutlinePresenter(
710                         ISourceViewer sourceViewer, boolean doCodeResolve) {
711                 InformationPresenter presenter = new InformationPresenter(
712                                 getOutlinePresenterControlCreator(sourceViewer));
713                 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
714                 IInformationProvider provider = new JavaElementProvider(getEditor(),
715                                 doCodeResolve);
716                 presenter.setInformationProvider(provider,
717                                 IDocument.DEFAULT_CONTENT_TYPE);
718                 presenter.setInformationProvider(provider,
719                                 IPHPPartitions.PHP_PARTITIONING);
720                 presenter.setInformationProvider(provider,
721                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
722                 presenter.setInformationProvider(provider,
723                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
724                 presenter.setInformationProvider(provider,
725                                 IPHPPartitions.HTML);
726                 presenter.setInformationProvider(provider,
727                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
728                 presenter.setSizeConstraints(40, 20, true, false);
729                 return presenter;
730         }
731 }