1 11 package org.eclipse.pde.internal.ui.editor.text; 12 13 import org.eclipse.jface.text.*; 14 import org.eclipse.jface.text.presentation.*; 15 import org.eclipse.jface.text.reconciler.*; 16 import org.eclipse.jface.text.rules.*; 17 import org.eclipse.jface.text.source.*; 18 import org.eclipse.jface.util.*; 19 import org.eclipse.pde.core.*; 20 import org.eclipse.pde.internal.ui.editor.*; 21 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; 22 23 24 public class XMLSourceViewerConfiguration extends TextSourceViewerConfiguration { 25 private AnnotationHover fAnnotationHover; 26 private XMLDoubleClickStrategy fDoubleClickStrategy; 27 private XMLTagScanner fTagScanner; 28 private XMLScanner fPdeScanner; 29 private IColorManager fColorManager; 30 private XMLSourcePage fSourcePage; 31 private MonoReconciler fReconciler; 32 private NonRuleBasedDamagerRepairer fNdr; 33 34 private TextAttribute fXMLCommentAttr; 35 36 public XMLSourceViewerConfiguration(XMLSourcePage page, IColorManager colorManager) { 37 fSourcePage = page; 38 setColorManager(colorManager); 39 } 40 41 public void setColorManager(IColorManager colorManager) { 42 fColorManager = colorManager; 43 } 44 45 public String [] getConfiguredContentTypes(ISourceViewer sourceViewer) { 46 return new String [] { 47 IDocument.DEFAULT_CONTENT_TYPE, 48 XMLPartitionScanner.XML_COMMENT, 49 XMLPartitionScanner.XML_TAG }; 50 } 51 52 public ITextDoubleClickStrategy getDoubleClickStrategy( 53 ISourceViewer sourceViewer, 54 String contentType) { 55 if (fDoubleClickStrategy == null) 56 fDoubleClickStrategy = new XMLDoubleClickStrategy(); 57 return fDoubleClickStrategy; 58 } 59 60 protected XMLScanner getPDEScanner() { 61 if (fPdeScanner == null) { 62 fPdeScanner = new XMLScanner(fColorManager); 63 fPdeScanner.setDefaultReturnToken( 64 new Token( 65 new TextAttribute(fColorManager.getColor(IPDEColorConstants.P_DEFAULT)))); 66 } 67 return fPdeScanner; 68 } 69 70 public void applyColorPreferenceChange(){ 71 fPdeScanner = new XMLScanner(fColorManager); 72 fPdeScanner.setDefaultReturnToken( 73 new Token( 74 new TextAttribute(fColorManager.getColor(IPDEColorConstants.P_DEFAULT)))); 75 fTagScanner = new XMLTagScanner(fColorManager); 76 fTagScanner.setDefaultReturnToken( 77 new Token(new TextAttribute(fColorManager.getColor(IPDEColorConstants.P_TAG)))); 78 79 } 80 protected XMLTagScanner getPDETagScanner() { 81 if (fTagScanner == null) { 82 fTagScanner = new XMLTagScanner(fColorManager); 83 fTagScanner.setDefaultReturnToken( 84 new Token(new TextAttribute(fColorManager.getColor(IPDEColorConstants.P_TAG)))); 85 } 86 return fTagScanner; 87 } 88 89 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { 90 PresentationReconciler reconciler = new PresentationReconciler(); 91 92 DefaultDamagerRepairer fDr = new DefaultDamagerRepairer(getPDEScanner()); 93 reconciler.setDamager(fDr, IDocument.DEFAULT_CONTENT_TYPE); 94 reconciler.setRepairer(fDr, IDocument.DEFAULT_CONTENT_TYPE); 95 96 fDr = new DefaultDamagerRepairer(getPDETagScanner()); 97 reconciler.setDamager(fDr, XMLPartitionScanner.XML_TAG); 98 reconciler.setRepairer(fDr, XMLPartitionScanner.XML_TAG); 99 100 fXMLCommentAttr = new TextAttribute(fColorManager.getColor(IPDEColorConstants.P_XML_COMMENT)); 101 fNdr = 102 new NonRuleBasedDamagerRepairer(fXMLCommentAttr); 103 reconciler.setDamager(fNdr, XMLPartitionScanner.XML_COMMENT); 104 reconciler.setRepairer(fNdr, XMLPartitionScanner.XML_COMMENT); 105 106 return reconciler; 107 } 108 109 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { 110 if (fAnnotationHover == null) 111 fAnnotationHover = new AnnotationHover(); 112 return fAnnotationHover; 113 } 114 115 public IReconciler getReconciler(ISourceViewer sourceViewer) { 116 if (fReconciler == null) { 117 IBaseModel model = fSourcePage.getInputContext().getModel(); 118 if (model instanceof IReconcilingParticipant) { 119 ReconcilingStrategy strategy = new ReconcilingStrategy(); 120 strategy.addParticipant((IReconcilingParticipant)model); 121 if (fSourcePage.getContentOutline() instanceof IReconcilingParticipant) 122 strategy.addParticipant((IReconcilingParticipant)fSourcePage.getContentOutline()); 123 fReconciler = new MonoReconciler(strategy, false); 124 fReconciler.setDelay(500); 125 } 126 } 127 return fReconciler; 128 } 129 130 public IColorManager getColorManager(){ 131 return fColorManager; 132 } 133 134 138 public void adaptToPreferenceChange(PropertyChangeEvent event) { 139 if (fTagScanner == null) { 140 return; } 142 fTagScanner.adaptToPreferenceChange((ColorManager)fColorManager, event); 143 fPdeScanner.adaptToPreferenceChange((ColorManager)fColorManager, event); 144 String property= event.getProperty(); 145 if (property.startsWith(IPDEColorConstants.P_XML_COMMENT)) { 146 adaptToColorChange(event); 147 fNdr.setDefaultTextAttribute(fXMLCommentAttr); 148 } 149 } 150 151 154 private void adaptToColorChange(PropertyChangeEvent event) { 155 ((ColorManager)fColorManager).updateProperty(event.getProperty()); 156 fXMLCommentAttr= new TextAttribute(((ColorManager)fColorManager).getColor(event.getProperty()), fXMLCommentAttr.getBackground(), fXMLCommentAttr.getStyle()); 157 } 158 159 160 161 } 162 | Popular Tags |