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
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpdt.ui.text;
14 import java.util.Vector;
16 import net.sourceforge.phpdt.core.JavaCore;
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.PreferencesAdapter;
27 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
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.java.hover.JavaInformationProvider;
32 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
33 import net.sourceforge.phpdt.ui.PreferenceConstants;
34 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
35 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
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.PHPDocumentPartitioner;
41 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
42 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
43 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
44 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
45 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
46 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
47 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
49 import org.eclipse.core.runtime.NullProgressMonitor;
50 import org.eclipse.jface.preference.IPreferenceStore;
51 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
52 import org.eclipse.jface.text.DefaultInformationControl;
53 import org.eclipse.jface.text.IAutoIndentStrategy;
54 import org.eclipse.jface.text.IDocument;
55 import org.eclipse.jface.text.IInformationControl;
56 import org.eclipse.jface.text.IInformationControlCreator;
57 import org.eclipse.jface.text.ITextDoubleClickStrategy;
58 import org.eclipse.jface.text.ITextHover;
59 import org.eclipse.jface.text.ITextViewerExtension2;
60 import org.eclipse.jface.text.TextAttribute;
61 import org.eclipse.jface.text.contentassist.ContentAssistant;
62 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
63 import org.eclipse.jface.text.contentassist.IContentAssistant;
64 import org.eclipse.jface.text.formatter.ContentFormatter;
65 import org.eclipse.jface.text.formatter.IContentFormatter;
66 import org.eclipse.jface.text.formatter.IFormattingStrategy;
67 import org.eclipse.jface.text.information.IInformationPresenter;
68 import org.eclipse.jface.text.information.IInformationProvider;
69 import org.eclipse.jface.text.information.InformationPresenter;
70 import org.eclipse.jface.text.presentation.IPresentationDamager;
71 import org.eclipse.jface.text.presentation.IPresentationReconciler;
72 import org.eclipse.jface.text.presentation.IPresentationRepairer;
73 import org.eclipse.jface.text.presentation.PresentationReconciler;
74 import org.eclipse.jface.text.reconciler.IReconciler;
75 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
76 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
77 import org.eclipse.jface.text.rules.DefaultPartitioner;
78 import org.eclipse.jface.text.rules.RuleBasedScanner;
79 import org.eclipse.jface.text.rules.Token;
80 import org.eclipse.jface.text.source.IAnnotationHover;
81 import org.eclipse.jface.text.source.ISourceViewer;
82 import org.eclipse.jface.text.source.SourceViewerConfiguration;
83 import org.eclipse.jface.util.Assert;
84 import org.eclipse.jface.util.PropertyChangeEvent;
85 import org.eclipse.swt.SWT;
86 import org.eclipse.swt.widgets.Shell;
87 import org.eclipse.ui.editors.text.EditorsUI;
88 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
89 import org.eclipse.ui.texteditor.ITextEditor;
92 * Configuration for an <code>SourceViewer</code> which shows PHP code.
94 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
96 * Preference key used to look up display tab width.
100 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
103 * Preference key for inserting spaces rather than tabs.
107 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
109 // public static final String HTML_DEFAULT =
110 // IPHPPartitionScannerConstants.HTML;
111 //IDocument.DEFAULT_CONTENT_TYPE;
112 private JavaTextTools fJavaTextTools;
114 private ITextEditor fTextEditor;
116 * The document partitioning.
119 private String fDocumentPartitioning;
121 private ContentFormatter fFormatter;
123 private HTMLFormattingStrategy fFormattingStrategy;
126 * Single token scanner.
128 static class SingleTokenScanner extends BufferedRuleBasedScanner {
129 public SingleTokenScanner(TextAttribute attribute) {
130 setDefaultReturnToken(new Token(attribute));
135 * The document partitioning.
139 // private String fDocumentPartitioning;
142 // * The Java source code scanner
146 // private AbstractJavaScanner fCodeScanner;
149 // * The Java multi-line comment scanner
153 // private AbstractJavaScanner fMultilineCommentScanner;
156 // * The Java single-line comment scanner
160 // private AbstractJavaScanner fSinglelineCommentScanner;
163 // * The Java string scanner
167 // private AbstractJavaScanner fStringScanner;
170 // * The Javadoc scanner
174 // private AbstractJavaScanner fJavaDocScanner;
177 * The preference store, can be read-only
181 private IPreferenceStore fPreferenceStore;
188 private IColorManager fColorManager;
190 private XMLTextTools fXMLTextTools;
191 private XMLConfiguration xmlConfiguration;
193 * Creates a new Java source viewer configuration for viewers in the given editor using the given preference store, the color
194 * manager and the specified document partitioning.
196 * Creates a Java source viewer configuration in the new setup without text tools. Clients are allowed to call
197 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and disallowed to call
198 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the resulting Java source viewer configuration.
201 * @param colorManager
203 * @param preferenceStore
204 * the preference store, can be read-only
206 * the editor in which the configured viewer(s) will reside
207 * @param partitioning
208 * the document partitioning for this configuration
211 public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor,
212 String partitioning) {
213 fColorManager = colorManager;
214 fPreferenceStore = preferenceStore;
215 fTextEditor = editor;
216 fDocumentPartitioning = partitioning;
217 fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
218 fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
219 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
221 // initializeScanners();
225 * Default constructor.
227 public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor editor, String partitioning) {
228 fJavaTextTools= tools;
229 fColorManager= tools.getColorManager();
230 fPreferenceStore= createPreferenceStore();
231 fDocumentPartitioning = partitioning;
232 // fCodeScanner= (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
233 // fMultilineCommentScanner= (AbstractJavaScanner) fJavaTextTools.getMultilineCommentScanner();
234 // fSinglelineCommentScanner= (AbstractJavaScanner) fJavaTextTools.getSinglelineCommentScanner();
235 // fStringScanner= (AbstractJavaScanner) fJavaTextTools.getStringScanner();
236 // fJavaDocScanner= (AbstractJavaScanner) fJavaTextTools.getJavaDocScanner();
238 fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
239 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
243 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
245 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
246 // if (fFormatter == null) {
247 // fFormatter = new ContentFormatter();
248 // fFormattingStrategy = new HTMLFormattingStrategy(this,
250 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
251 // fFormatter.enablePartitionAwareFormatting(false);
252 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
254 // return fFormatter;
255 if (fFormatter == null) {
257 fFormatter = new ContentFormatter();
258 IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer);
259 fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
260 fFormatter.enablePartitionAwareFormatting(false);
261 fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
267 * Returns the names of the document position categories used by the document partitioners created by this object to manage their
268 * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
270 * @return the partition managing position categories or <code>null</code> if there is none
272 public String[] getPartitionManagingPositionCategories() {
273 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
277 // * Returns the names of the document position categories used by the
279 // * partitioners created by this object to manage their partition
281 // * If the partitioners don't use document position categories, the
283 // * result is <code>null</code>.
285 // * @return the partition managing position categories or
287 // * if there is none
289 // private String[] getPartitionManagingPositionCategories() {
290 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
292 public ITextEditor getEditor() {
297 * Returns the preference store used by this configuration to initialize the individual bits and pieces.
299 * @return the preference store used to initialize this configuration
303 protected IPreferenceStore getPreferenceStore() {
304 return PHPeclipsePlugin.getDefault().getPreferenceStore();
308 // * Method declared on SourceViewerConfiguration
310 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
311 // return new PHPAnnotationHover();
314 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
316 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
317 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
321 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
324 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
325 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
329 * (non-Javadoc) Method declared on SourceViewerConfiguration
331 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
332 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
333 return new JavaStringAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
335 return (IPHPPartitions.PHP_PARTITIONING.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy());
339 * Returns the PHP source code scanner for this configuration.
341 * @return the PHP source code scanner
343 protected RuleBasedScanner getCodeScanner() {
344 return fJavaTextTools.getCodeScanner();
348 * Returns the HTML source code scanner for this configuration.
350 * @return the HTML source code scanner
352 // protected RuleBasedScanner getHTMLScanner() {
353 // return fJavaTextTools.getHTMLScanner();
357 * Returns the Smarty source code scanner for this configuration.
359 * @return the Smarty source code scanner
361 protected RuleBasedScanner getSmartyScanner() {
362 return fJavaTextTools.getSmartyScanner();
366 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
369 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
371 public IReconciler getReconciler(ISourceViewer sourceViewer) {
373 final ITextEditor editor = getEditor();
374 if (editor != null && editor.isEditable()) {
376 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(editor,
377 getConfiguredDocumentPartitioning(sourceViewer));
378 JavaReconciler reconciler = new JavaReconciler(editor, strategy, false);
379 reconciler.setIsIncrementalReconciler(false);
380 reconciler.setProgressMonitor(new NullProgressMonitor());
381 reconciler.setDelay(500);
388 // public IReconciler getReconciler(ISourceViewer sourceViewer) {
389 // if (getEditor() != null && getEditor().isEditable()) {
390 // JavaReconciler reconciler = new JavaReconciler(getEditor(),
391 // new JavaReconcilingStrategy(getEditor()), false);
392 // reconciler.setProgressMonitor(new NullProgressMonitor());
393 // reconciler.setDelay(500);
394 // return reconciler;
399 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String)
402 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
403 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
404 int stateMasks[] = new int[hoverDescs.length];
405 int stateMasksLength = 0;
406 for (int i = 0; i < hoverDescs.length; i++) {
407 if (hoverDescs[i].isEnabled()) {
409 int stateMask = hoverDescs[i].getStateMask();
410 while (j < stateMasksLength) {
411 if (stateMasks[j] == stateMask)
415 if (j == stateMasksLength)
416 stateMasks[stateMasksLength++] = stateMask;
419 if (stateMasksLength == hoverDescs.length)
421 int[] shortenedStateMasks = new int[stateMasksLength];
422 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, stateMasksLength);
423 return shortenedStateMasks;
427 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
430 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
431 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
433 while (i < hoverDescs.length) {
434 if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask)
435 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
439 // if (fEditor != null) {
440 // IEditorInput editorInput = fEditor.getEditorInput();
441 // if (editorInput instanceof IFileEditorInput) {
443 // IFile f = ((IFileEditorInput) editorInput).getFile();
444 // return new PHPTextHover(f.getProject());
445 // } catch (NullPointerException e) {
446 // // this exception occurs, if getTextHover is called by
447 // // preference pages !
451 // return new PHPTextHover(null);
455 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
457 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
458 return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
462 * Returns the SmartyDoc source code scanner for this configuration.
464 * @return the SmartyDoc source code scanner
466 protected RuleBasedScanner getSmartyDocScanner() {
467 return fJavaTextTools.getSmartyDocScanner();
471 * Returns the PHPDoc source code scanner for this configuration.
473 * @return the PHPDoc source code scanner
475 protected RuleBasedScanner getPHPDocScanner() {
476 return fJavaTextTools.getJavaDocScanner();
480 * (non-Javadoc) Method declared on SourceViewerConfiguration
482 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
483 return new String[] {
484 IDocument.DEFAULT_CONTENT_TYPE,
485 PHPPartitionScanner.PHP_SCRIPTING_AREA,
488 IPHPPartitions.HTML_MULTILINE_COMMENT,
489 IPHPPartitions.PHP_PARTITIONING,
490 IPHPPartitions.PHP_SINGLELINE_COMMENT,
491 IPHPPartitions.PHP_MULTILINE_COMMENT,
492 IPHPPartitions.PHP_PHPDOC_COMMENT,
493 IPHPPartitions.PHP_STRING_DQ,
494 IPHPPartitions.PHP_STRING_SQ,
496 IPHPPartitions.CSS_MULTILINE_COMMENT,
497 IPHPPartitions.JAVASCRIPT,
498 IPHPPartitions.JS_MULTILINE_COMMENT,
499 IPHPPartitions.SMARTY,
500 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
502 XMLPartitionScanner.XML_PI,
503 XMLPartitionScanner.XML_COMMENT,
504 XMLPartitionScanner.XML_DECL,
505 XMLPartitionScanner.XML_TAG,
506 XMLPartitionScanner.XML_ATTRIBUTE,
507 XMLPartitionScanner.XML_CDATA,
509 XMLPartitionScanner.DTD_INTERNAL,
510 XMLPartitionScanner.DTD_INTERNAL_PI,
511 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
512 XMLPartitionScanner.DTD_INTERNAL_DECL,
514 PHPDocumentPartitioner.PHP_TEMPLATE_DATA,
515 PHPDocumentPartitioner.PHP_SCRIPT_CODE
519 public String[] getConfiguredHTMLContentTypes() {
520 return new String[] {
521 XMLPartitionScanner.XML_PI,
522 XMLPartitionScanner.XML_COMMENT,
523 XMLPartitionScanner.XML_DECL,
524 XMLPartitionScanner.XML_TAG,
525 XMLPartitionScanner.XML_ATTRIBUTE,
526 XMLPartitionScanner.XML_CDATA,
528 XMLPartitionScanner.DTD_INTERNAL,
529 XMLPartitionScanner.DTD_INTERNAL_PI,
530 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
531 XMLPartitionScanner.DTD_INTERNAL_DECL,
534 public String[] getConfiguredPHPContentTypes() {
535 return new String[] {
536 IDocument.DEFAULT_CONTENT_TYPE,
537 IPHPPartitions.PHP_PARTITIONING,
538 IPHPPartitions.PHP_SINGLELINE_COMMENT,
539 IPHPPartitions.PHP_MULTILINE_COMMENT,
540 IPHPPartitions.PHP_PHPDOC_COMMENT,
541 IPHPPartitions.PHP_STRING_DQ,
542 IPHPPartitions.PHP_STRING_SQ,
544 IPHPPartitions.CSS_MULTILINE_COMMENT,
545 IPHPPartitions.JAVASCRIPT,
546 IPHPPartitions.JS_MULTILINE_COMMENT,
547 IPHPPartitions.SMARTY,
548 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
552 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
555 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
556 if (fDocumentPartitioning != null)
557 return fDocumentPartitioning;
558 return super.getConfiguredDocumentPartitioning(sourceViewer);
561 * (non-Javadoc) Method declared on SourceViewerConfiguration
563 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
564 ContentAssistant assistant = new ContentAssistant();
565 IContentAssistProcessor processor = new HTMLCompletionProcessor();
566 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
567 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
568 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
570 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
571 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
572 assistant.setContentAssistProcessor(processor, IPHPPartitions.JAVASCRIPT);
573 assistant.setContentAssistProcessor(processor, IPHPPartitions.JS_MULTILINE_COMMENT);
574 // TODO define special smarty partition content assist
575 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
576 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
578 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
579 String[] htmlTypes = getConfiguredHTMLContentTypes();
580 for (int i = 0; i < htmlTypes.length; i++) {
581 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
583 processor = new PHPCompletionProcessor(getEditor());
585 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
586 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
587 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
588 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
590 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(), IPHPPartitions.PHP_PHPDOC_COMMENT);
591 // assistant.enableAutoActivation(true);
592 // assistant.setAutoActivationDelay(500);
593 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
594 // ContentAssistPreference.configure(assistant, getPreferenceStore());
595 // assistant.setContextInformationPopupOrientation(
596 // ContentAssistant.CONTEXT_INFO_ABOVE);
597 // assistant.setContextInformationPopupBackground(
598 // PHPEditorEnvironment.getPHPColorProvider().getColor(
599 // new RGB(150, 150, 0)));
600 ContentAssistPreference.configure(assistant, getPreferenceStore());
601 assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
602 assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
607 * (non-Javadoc) Method declared on SourceViewerConfiguration
609 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
611 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
613 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
614 // null); //$NON-NLS-1$
617 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
620 public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
621 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
625 * (non-Javadoc) Method declared on SourceViewerConfiguration
627 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
628 return new PHPDoubleClickSelector();
632 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
634 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
635 Vector vector = new Vector();
636 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
637 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault().getPreferenceStore();
638 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
639 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
640 for (int i = 0; i <= tabWidth; i++) {
641 StringBuffer prefix = new StringBuffer();
643 for (int j = 0; j + i < tabWidth; j++)
648 for (int j = 0; j < i; j++)
653 vector.add(prefix.toString());
655 vector.add(""); //$NON-NLS-1$
656 return (String[]) vector.toArray(new String[vector.size()]);
659 * @return <code>true</code> iff the new setup without text tools is in use.
663 private boolean isNewSetup() {
664 return fJavaTextTools == null;
667 * Creates and returns a preference store which combines the preference
668 * stores from the text tools and which is read-only.
670 * @return the read-only preference store
673 private IPreferenceStore createPreferenceStore() {
674 Assert.isTrue(!isNewSetup());
675 IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore();
676 if (fJavaTextTools.getCorePreferenceStore() == null)
677 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(), generalTextStore});
679 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(), new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()), generalTextStore });
682 * (non-Javadoc) Method declared on SourceViewerConfiguration
684 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
685 // PHPColorProvider provider =
686 // PHPEditorEnvironment.getPHPColorProvider();
687 // JavaColorManager provider =
688 // PHPEditorEnvironment.getPHPColorProvider();
689 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
690 phpReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
692 // DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
693 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
694 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
695 // dr = new DefaultDamagerRepairer(getHTMLScanner());
696 // reconciler.setDamager(dr, IPHPPartitions.HTML);
697 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
698 // dr = new DefaultDamagerRepairer(getHTMLScanner());
699 // reconciler.setDamager(dr, IPHPPartitions.CSS);
700 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
701 // dr = new DefaultDamagerRepairer(getHTMLScanner());
702 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
703 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
704 // dr = new DefaultDamagerRepairer(getHTMLScanner());
705 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
706 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
707 // dr = new DefaultDamagerRepairer(getHTMLScanner());
708 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
709 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
710 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getSmartyScanner());
711 phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
712 phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
713 phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
714 phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
715 phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
716 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
717 // PHPColorProvider.MULTI_LINE_COMMENT))));
718 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
719 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
721 phpDR = new DefaultDamagerRepairer(getCodeScanner());
722 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
723 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
725 phpDR = new DefaultDamagerRepairer(getCodeScanner());
726 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
727 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
729 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
730 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
731 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
733 phpDR = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
734 PHPColorProvider.STRING))));
735 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
736 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
737 phpDR = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
738 PHPColorProvider.STRING))));
739 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
740 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
741 phpDR = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
742 PHPColorProvider.SINGLE_LINE_COMMENT))));
743 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
744 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
745 phpDR = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
746 PHPColorProvider.MULTI_LINE_COMMENT))));
747 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
748 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
750 PresentationReconciler reconciler = new PresentationReconciler();
751 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
753 JavaTextTools jspTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
754 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
755 PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPTextScanner());
756 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
757 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
759 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
760 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
761 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
762 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
765 configureEmbeddedPresentationReconciler(reconciler,
766 xmlConfiguration.getPresentationReconciler(sourceViewer),
767 xmlConfiguration.getConfiguredContentTypes(sourceViewer),
768 PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
771 configureEmbeddedPresentationReconciler(reconciler,
773 getConfiguredPHPContentTypes(),
774 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
779 private void configureEmbeddedPresentationReconciler(
780 PresentationReconciler reconciler,
781 IPresentationReconciler embedded,
785 for (int i = 0; i < types.length; i++) {
786 String type = types[i];
788 IPresentationDamager damager = embedded.getDamager(type);
789 IPresentationRepairer repairer = embedded.getRepairer(type);
791 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
795 reconciler.setDamager(damager, type);
796 reconciler.setRepairer(repairer, type);
801 * (non-Javadoc) Method declared on SourceViewerConfiguration
803 public int getTabWidth(ISourceViewer sourceViewer) {
804 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
808 * (non-Javadoc) Method declared on SourceViewerConfiguration
810 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
812 // if (fEditor != null) {
813 // IEditorInput editorInput = fEditor.getEditorInput();
814 // if (editorInput instanceof IFileEditorInput) {
816 // IFile f = ((IFileEditorInput) editorInput).getFile();
817 // return new PHPTextHover(f.getProject());
818 // } catch (NullPointerException e) {
819 // // this exception occurs, if getTextHover is called by preference pages
824 // return new PHPTextHover(null);
827 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
830 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
831 return new IInformationControlCreator() {
832 public IInformationControl createInformationControl(Shell parent) {
833 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
834 // return new HoverBrowserControl(parent);
840 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
843 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
844 InformationPresenter presenter= new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
845 presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
846 IInformationProvider provider= new JavaInformationProvider(getEditor());
847 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
848 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
849 // presenter.setInformationProvider(provider, IPHPPartitions.JAVA_CHARACTER);
850 presenter.setSizeConstraints(60, 10, true, true);
854 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
857 // public IInformationPresenter getInformationPresenter(ISourceViewer
859 // InformationPresenter presenter= new
860 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
861 // IInformationProvider provider= new JavaInformationProvider(getEditor());
862 // presenter.setInformationProvider(provider,
863 // IDocument.DEFAULT_CONTENT_TYPE);
864 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
865 // presenter.setSizeConstraints(60, 10, true, true);
869 * Returns the information presenter control creator. The creator is a factory creating the presenter controls for the given
870 * source viewer. This implementation always returns a creator for <code>DefaultInformationControl</code> instances.
872 * @param sourceViewer
873 * the source viewer to be configured by this configuration
874 * @return an information control creator
877 private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
878 return new IInformationControlCreator() {
879 public IInformationControl createInformationControl(Shell parent) {
880 int shellStyle = SWT.RESIZE;
881 int style = SWT.V_SCROLL | SWT.H_SCROLL;
882 return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
883 // return new HoverBrowserControl(parent);
889 * Returns the outline presenter control creator. The creator is a factory creating outline presenter controls for the given
890 * source viewer. This implementation always returns a creator for <code>JavaOutlineInformationControl</code> instances.
892 * @param sourceViewer
893 * the source viewer to be configured by this configuration
894 * @return an information control creator
897 private IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer) {
898 return new IInformationControlCreator() {
899 public IInformationControl createInformationControl(Shell parent) {
900 int shellStyle = SWT.RESIZE;
901 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
902 return new JavaOutlineInformationControl(parent, shellStyle, treeStyle);
908 * Returns the outline presenter which will determine and shown information requested for the current cursor position.
910 * @param sourceViewer
911 * the source viewer to be configured by this configuration
912 * @param doCodeResolve
913 * a boolean which specifies whether code resolve should be used to compute the Java element
914 * @return an information presenter
917 public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {
918 InformationPresenter presenter = new InformationPresenter(getOutlinePresenterControlCreator(sourceViewer));
919 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
920 IInformationProvider provider = new JavaElementProvider(getEditor(), doCodeResolve);
921 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
922 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PARTITIONING);
923 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
924 presenter.setInformationProvider(provider, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
925 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
926 presenter.setInformationProvider(provider, IPHPPartitions.HTML_MULTILINE_COMMENT);
927 presenter.setSizeConstraints(40, 20, true, false);