1 11 package org.eclipse.jdt.internal.ui.propertiesfileeditor; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.runtime.NullProgressMonitor; 16 import org.eclipse.core.runtime.Platform; 17 import org.eclipse.core.runtime.content.IContentType; 18 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.widgets.Shell; 21 22 import org.eclipse.jface.internal.text.html.HTMLTextPresenter; 23 import org.eclipse.jface.preference.IPreferenceStore; 24 import org.eclipse.jface.util.PropertyChangeEvent; 25 26 import org.eclipse.jface.text.DefaultInformationControl; 27 import org.eclipse.jface.text.IDocument; 28 import org.eclipse.jface.text.IInformationControl; 29 import org.eclipse.jface.text.IInformationControlCreator; 30 import org.eclipse.jface.text.ITextDoubleClickStrategy; 31 import org.eclipse.jface.text.presentation.IPresentationReconciler; 32 import org.eclipse.jface.text.presentation.PresentationReconciler; 33 import org.eclipse.jface.text.reconciler.IReconciler; 34 import org.eclipse.jface.text.reconciler.IReconcilingStrategy; 35 import org.eclipse.jface.text.reconciler.MonoReconciler; 36 import org.eclipse.jface.text.rules.DefaultDamagerRepairer; 37 import org.eclipse.jface.text.rules.RuleBasedScanner; 38 import org.eclipse.jface.text.source.Annotation; 39 import org.eclipse.jface.text.source.IAnnotationHover; 40 import org.eclipse.jface.text.source.ISourceViewer; 41 42 import org.eclipse.ui.texteditor.ITextEditor; 43 import org.eclipse.ui.texteditor.spelling.SpellingReconcileStrategy; 44 import org.eclipse.ui.texteditor.spelling.SpellingService; 45 46 import org.eclipse.ui.editors.text.EditorsUI; 47 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; 48 49 import org.eclipse.jdt.ui.PreferenceConstants; 50 import org.eclipse.jdt.ui.text.IColorManager; 51 52 import org.eclipse.jdt.internal.ui.text.AbstractJavaScanner; 53 import org.eclipse.jdt.internal.ui.text.HTMLAnnotationHover; 54 import org.eclipse.jdt.internal.ui.text.JavaPresentationReconciler; 55 import org.eclipse.jdt.internal.ui.text.SingleTokenJavaScanner; 56 import org.eclipse.jdt.internal.ui.text.java.JavaStringDoubleClickSelector; 57 58 66 public class PropertiesFileSourceViewerConfiguration extends TextSourceViewerConfiguration { 67 68 69 private static final IContentType PROPERTIES_CONTENT_TYPE= Platform.getContentTypeManager().getContentType("org.eclipse.jdt.core.javaProperties"); 71 74 private ITextEditor fTextEditor; 75 78 private String fDocumentPartitioning; 79 82 private AbstractJavaScanner fPropertyKeyScanner; 83 86 private AbstractJavaScanner fCommentScanner; 87 90 private AbstractJavaScanner fPropertyValueScanner; 91 94 private IColorManager fColorManager; 95 96 97 106 public PropertiesFileSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) { 107 super(preferenceStore); 108 fColorManager= colorManager; 109 fTextEditor= editor; 110 fDocumentPartitioning= partitioning; 111 initializeScanners(); 112 } 113 114 119 protected RuleBasedScanner getPropertyKeyScanner() { 120 return fPropertyKeyScanner; 121 } 122 123 128 protected RuleBasedScanner getCommentScanner() { 129 return fCommentScanner; 130 } 131 132 137 protected RuleBasedScanner getPropertyValueScanner() { 138 return fPropertyValueScanner; 139 } 140 141 146 protected IColorManager getColorManager() { 147 return fColorManager; 148 } 149 150 155 protected ITextEditor getEditor() { 156 return fTextEditor; 157 } 158 159 162 private void initializeScanners() { 163 fPropertyKeyScanner= new SingleTokenJavaScanner(getColorManager(), fPreferenceStore, PreferenceConstants.PROPERTIES_FILE_COLORING_KEY); 164 fPropertyValueScanner= new PropertyValueScanner(getColorManager(), fPreferenceStore); 165 fCommentScanner= new SingleTokenJavaScanner(getColorManager(), fPreferenceStore, PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT); 166 } 167 168 171 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { 172 173 PresentationReconciler reconciler= new JavaPresentationReconciler(); 174 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); 175 176 DefaultDamagerRepairer dr= new DefaultDamagerRepairer(getPropertyKeyScanner()); 177 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); 178 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); 179 180 dr= new DefaultDamagerRepairer(getCommentScanner()); 181 reconciler.setDamager(dr, IPropertiesFilePartitions.COMMENT); 182 reconciler.setRepairer(dr, IPropertiesFilePartitions.COMMENT); 183 184 dr= new DefaultDamagerRepairer(getPropertyValueScanner()); 185 reconciler.setDamager(dr, IPropertiesFilePartitions.PROPERTY_VALUE); 186 reconciler.setRepairer(dr, IPropertiesFilePartitions.PROPERTY_VALUE); 187 188 return reconciler; 189 } 190 191 194 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) { 195 if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) 196 return new JavaStringDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer)); 197 198 return super.getDoubleClickStrategy(sourceViewer, contentType); 199 } 200 201 204 public String [] getConfiguredContentTypes(ISourceViewer sourceViewer) { 205 int length= IPropertiesFilePartitions.PARTITIONS.length; 206 String [] contentTypes= new String [length + 1]; 207 contentTypes[0]= IDocument.DEFAULT_CONTENT_TYPE; 208 for (int i= 0; i < length; i++) 209 contentTypes[i+1]= IPropertiesFilePartitions.PARTITIONS[i]; 210 211 return contentTypes; 212 } 213 214 217 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) { 218 if (fDocumentPartitioning != null) 219 return fDocumentPartitioning; 220 return super.getConfiguredDocumentPartitioning(sourceViewer); 221 } 222 223 230 public boolean affectsTextPresentation(PropertyChangeEvent event) { 231 return fPropertyKeyScanner.affectsBehavior(event) 232 || fCommentScanner.affectsBehavior(event) 233 || fPropertyValueScanner.affectsBehavior(event); 234 } 235 236 243 public void handlePropertyChangeEvent(PropertyChangeEvent event) { 244 if (fPropertyKeyScanner.affectsBehavior(event)) 245 fPropertyKeyScanner.adaptToPreferenceChange(event); 246 if (fCommentScanner.affectsBehavior(event)) 247 fCommentScanner.adaptToPreferenceChange(event); 248 if (fPropertyValueScanner.affectsBehavior(event)) 249 fPropertyValueScanner.adaptToPreferenceChange(event); 250 } 251 252 256 protected Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) { 257 Map targets= super.getHyperlinkDetectorTargets(sourceViewer); 258 targets.put("org.eclipse.jdt.ui.PropertiesFileEditor", fTextEditor); return targets; 260 } 261 262 265 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { 266 return new HTMLAnnotationHover() { 267 protected boolean isIncluded(Annotation annotation) { 268 return isShowInVerticalRuler(annotation); 269 } 270 }; 271 } 272 273 276 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) { 277 return new HTMLAnnotationHover() { 278 protected boolean isIncluded(Annotation annotation) { 279 return isShowInOverviewRuler(annotation); 280 } 281 }; 282 } 283 284 287 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) { 288 return new IInformationControlCreator() { 289 public IInformationControl createInformationControl(Shell parent) { 290 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true)); 291 } 292 }; 293 } 294 295 298 public IReconciler getReconciler(ISourceViewer sourceViewer) { 299 if (!EditorsUI.getPreferenceStore().getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) 300 return null; 301 302 IReconcilingStrategy strategy= new SpellingReconcileStrategy(sourceViewer, EditorsUI.getSpellingService()) { 303 protected IContentType getContentType() { 304 return PROPERTIES_CONTENT_TYPE; 305 } 306 }; 307 308 MonoReconciler reconciler= new MonoReconciler(strategy, false); 309 reconciler.setIsIncrementalReconciler(false); 310 reconciler.setProgressMonitor(new NullProgressMonitor()); 311 reconciler.setDelay(500); 312 return reconciler; 313 } 314 315 } 316 | Popular Tags |