XMLConfiguration.java
上传用户:fanxing
上传日期:2017-01-19
资源大小:36k
文件大小:4k
源码类别:

PlugIns编程

开发平台:

Java

  1. /*******************************************************************************
  2.  * Copyright (c) 2005 Prashant Deva.
  3.  
  4.  * All rights reserved. This program and the accompanying materials 
  5.  * are made available under the terms of the Eclipse Public License - v 1.0
  6.  * which is available at http://www.eclipse.org/legal/epl-v10.html
  7. *******************************************************************************/
  8. package projection_test.editors;
  9. import org.eclipse.jface.text.IDocument;
  10. import org.eclipse.jface.text.ITextDoubleClickStrategy;
  11. import org.eclipse.jface.text.TextAttribute;
  12. import org.eclipse.jface.text.contentassist.ContentAssistant;
  13. import org.eclipse.jface.text.contentassist.IContentAssistant;
  14. import org.eclipse.jface.text.presentation.IPresentationReconciler;
  15. import org.eclipse.jface.text.presentation.PresentationReconciler;
  16. import org.eclipse.jface.text.reconciler.IReconciler;
  17. import org.eclipse.jface.text.reconciler.MonoReconciler;
  18. import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
  19. import org.eclipse.jface.text.rules.Token;
  20. import org.eclipse.jface.text.source.ISourceViewer;
  21. import org.eclipse.jface.text.source.SourceViewerConfiguration;
  22. public class XMLConfiguration extends SourceViewerConfiguration {
  23. private XMLDoubleClickStrategy doubleClickStrategy;
  24. private XMLTagScanner tagScanner;
  25. private XMLScanner scanner;
  26. private ColorManager colorManager;
  27. private XMLEditor editor;
  28. public XMLConfiguration(ColorManager colorManager,XMLEditor editor) {
  29. this.colorManager = colorManager;
  30. this.editor = editor;
  31. }
  32. public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
  33. return new String[] {
  34. IDocument.DEFAULT_CONTENT_TYPE,
  35. XMLPartitionScanner.XML_COMMENT,
  36. XMLPartitionScanner.XML_TAG };
  37. }
  38. public ITextDoubleClickStrategy getDoubleClickStrategy(
  39. ISourceViewer sourceViewer,
  40. String contentType) {
  41. if (doubleClickStrategy == null)
  42. doubleClickStrategy = new XMLDoubleClickStrategy();
  43. return doubleClickStrategy;
  44. }
  45. protected XMLScanner getXMLScanner() {
  46. if (scanner == null) {
  47. scanner = new XMLScanner(colorManager);
  48. scanner.setDefaultReturnToken(
  49. new Token(
  50. new TextAttribute(
  51. colorManager.getColor(IXMLColorConstants.DEFAULT))));
  52. }
  53. return scanner;
  54. }
  55. protected XMLTagScanner getXMLTagScanner() {
  56. if (tagScanner == null) {
  57. tagScanner = new XMLTagScanner(colorManager);
  58. tagScanner.setDefaultReturnToken(
  59. new Token(
  60. new TextAttribute(
  61. colorManager.getColor(IXMLColorConstants.TAG))));
  62. }
  63. return tagScanner;
  64. }
  65. public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
  66. PresentationReconciler reconciler = new PresentationReconciler();
  67. DefaultDamagerRepairer dr =
  68. new DefaultDamagerRepairer(getXMLTagScanner());
  69. reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
  70. reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
  71. dr = new DefaultDamagerRepairer(getXMLScanner());
  72. reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
  73. reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
  74. NonRuleBasedDamagerRepairer ndr =
  75. new NonRuleBasedDamagerRepairer(
  76. new TextAttribute(
  77. colorManager.getColor(IXMLColorConstants.XML_COMMENT)));
  78. reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
  79. reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
  80. return reconciler;
  81. }
  82.     /* (non-Javadoc)
  83.      * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
  84.      */
  85.     public IContentAssistant getContentAssistant(ISourceViewer sourceViewer)
  86.     {
  87.         ContentAssistant assistant = new ContentAssistant();
  88.         assistant.setContentAssistProcessor(new XMLContentAssistantProcessor(),IDocument.DEFAULT_CONTENT_TYPE);
  89.         assistant.enableAutoActivation(true);
  90.         
  91.         return assistant;
  92.     }
  93.     /* (non-Javadoc)
  94.      * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
  95.      */
  96.     public IReconciler getReconciler(ISourceViewer sourceViewer)
  97.     {
  98.         XmlReconcilingStrategy strategy = new XmlReconcilingStrategy();
  99.         strategy.setEditor(editor);
  100.         
  101.         MonoReconciler reconciler = new MonoReconciler(strategy,false);
  102.         
  103.         return reconciler;
  104.     }
  105. }