1 20 21 package org.apache.directory.ldapstudio.ldifeditor.editor; 22 23 24 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants; 25 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator; 26 import org.apache.directory.ldapstudio.ldifeditor.editor.reconciler.LdifReconcilingStrategy; 27 import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifAnnotationHover; 28 import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifAutoEditStrategy; 29 import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifCompletionProcessor; 30 import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifDamagerRepairer; 31 import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifDoubleClickStrategy; 32 import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifPartitionScanner; 33 import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifTextHover; 34 import org.apache.directory.ldapstudio.browser.common.widgets.DialogContentAssistant; 35 import org.eclipse.core.runtime.NullProgressMonitor; 36 import org.eclipse.jface.preference.IPreferenceStore; 37 import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy; 38 import org.eclipse.jface.text.IAutoEditStrategy; 39 import org.eclipse.jface.text.IDocument; 40 import org.eclipse.jface.text.ITextDoubleClickStrategy; 41 import org.eclipse.jface.text.ITextHover; 42 import org.eclipse.jface.text.contentassist.ContentAssistant; 43 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 44 import org.eclipse.jface.text.contentassist.IContentAssistant; 45 import org.eclipse.jface.text.presentation.IPresentationReconciler; 46 import org.eclipse.jface.text.presentation.PresentationReconciler; 47 import org.eclipse.jface.text.reconciler.IReconciler; 48 import org.eclipse.jface.text.reconciler.MonoReconciler; 49 import org.eclipse.jface.text.source.IAnnotationHover; 50 import org.eclipse.jface.text.source.ISourceViewer; 51 import org.eclipse.jface.text.source.SourceViewerConfiguration; 52 import org.eclipse.swt.graphics.RGB; 53 54 60 public class LdifSourceViewerConfiguration extends SourceViewerConfiguration 61 { 62 private ILdifEditor editor; 63 64 private LdifAnnotationHover annotationHover; 66 67 private LdifTextHover textHover; 68 69 private PresentationReconciler presentationReconciler; 71 72 private LdifDamagerRepairer damagerRepairer; 73 74 private boolean contentAssistEnabled; 76 77 private ContentAssistant contentAssistant; 78 79 private IContentAssistProcessor contentAssistProcessor; 80 81 private LdifDoubleClickStrategy doubleClickStrategy; 82 83 private MonoReconciler reconciler; 85 86 private LdifReconcilingStrategy reconcilingStrategy; 87 88 private IAutoEditStrategy[] autoEditStrategies; 89 90 91 97 public LdifSourceViewerConfiguration( ILdifEditor editor, boolean contentAssistEnabled ) 98 { 99 super(); 100 this.editor = editor; 101 102 this.contentAssistEnabled = contentAssistEnabled; 103 } 104 105 106 116 public void setTextAttribute( String key, RGB rgb, int style ) 117 { 118 damagerRepairer.setTextAttribute( key, rgb, style ); 119 } 120 121 122 125 public String getConfiguredDocumentPartitioning( ISourceViewer sourceViewer ) 126 { 127 return LdifDocumentSetupParticipant.LDIF_PARTITIONING; 128 } 129 130 131 134 public String [] getConfiguredContentTypes( ISourceViewer sourceViewer ) 135 { 136 return new String [] 137 { IDocument.DEFAULT_CONTENT_TYPE, LdifPartitionScanner.LDIF_RECORD }; 138 } 139 140 141 144 public ITextDoubleClickStrategy getDoubleClickStrategy( ISourceViewer sourceViewer, String contentType ) 145 { 146 if ( this.doubleClickStrategy == null ) 147 { 148 this.doubleClickStrategy = new LdifDoubleClickStrategy(); 149 } 150 return this.doubleClickStrategy; 151 } 152 153 154 157 public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer ) 158 { 159 160 if ( this.presentationReconciler == null ) 161 { 162 this.presentationReconciler = new PresentationReconciler(); 163 this.presentationReconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer ) ); 164 165 damagerRepairer = new LdifDamagerRepairer( this.editor ); 166 167 this.presentationReconciler.setDamager( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE ); 168 this.presentationReconciler.setRepairer( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE ); 169 170 this.presentationReconciler.setDamager( damagerRepairer, LdifPartitionScanner.LDIF_RECORD ); 171 this.presentationReconciler.setRepairer( damagerRepairer, LdifPartitionScanner.LDIF_RECORD ); 172 } 173 174 return this.presentationReconciler; 175 } 176 177 178 181 public IReconciler getReconciler( ISourceViewer sourceViewer ) 182 { 183 if ( this.reconciler == null ) 184 { 185 this.reconcilingStrategy = new LdifReconcilingStrategy( editor ); 186 187 197 this.reconciler = new MonoReconciler( this.reconcilingStrategy, true ); 198 this.reconciler.setProgressMonitor( new NullProgressMonitor() ); 199 this.reconciler.setDelay( 500 ); 200 } 201 202 return this.reconciler; 203 } 204 205 206 209 public IContentAssistant getContentAssistant( ISourceViewer sourceViewer ) 210 { 211 if ( this.contentAssistEnabled ) 212 { 213 if ( this.contentAssistant == null ) 214 { 215 this.contentAssistant = new DialogContentAssistant(); 217 218 this.contentAssistProcessor = new LdifCompletionProcessor( editor, contentAssistant ); 219 this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor, 220 LdifPartitionScanner.LDIF_RECORD ); 221 this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor, 222 IDocument.DEFAULT_CONTENT_TYPE ); 223 this.contentAssistant.setDocumentPartitioning( LdifDocumentSetupParticipant.LDIF_PARTITIONING ); 224 225 this.contentAssistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE ); 226 this.contentAssistant.setInformationControlCreator( getInformationControlCreator( sourceViewer ) ); 227 228 IPreferenceStore store = LdifEditorActivator.getDefault().getPreferenceStore(); 229 this.contentAssistant.enableAutoInsert( store 230 .getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) ); 231 this.contentAssistant.enableAutoActivation( store 232 .getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) ); 233 this.contentAssistant.setAutoActivationDelay( store 234 .getInt( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) ); 235 } 239 return this.contentAssistant; 240 } 241 else 242 { 243 return null; 244 } 245 } 246 247 248 251 public IAnnotationHover getAnnotationHover( ISourceViewer sourceViewer ) 252 { 253 if ( this.annotationHover == null ) 254 { 255 this.annotationHover = new LdifAnnotationHover( this.editor ); 256 } 257 return this.annotationHover; 258 } 259 260 261 264 public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType ) 265 { 266 if ( this.textHover == null ) 267 { 268 this.textHover = new LdifTextHover( this.editor ); 269 } 270 return this.textHover; 271 } 272 273 274 277 public IAutoEditStrategy[] getAutoEditStrategies( ISourceViewer sourceViewer, String contentType ) 278 { 279 if ( autoEditStrategies == null ) 280 { 281 this.autoEditStrategies = new IAutoEditStrategy[2]; 282 this.autoEditStrategies[0] = new DefaultIndentLineAutoEditStrategy(); 283 this.autoEditStrategies[1] = new LdifAutoEditStrategy( this.editor ); 284 } 285 286 return autoEditStrategies; 287 } 288 } 289 | Popular Tags |