1 20 21 package org.apache.directory.ldapstudio.browser.common.filtereditor; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.DialogContentAssistant; 25 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 26 import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser; 27 28 import org.eclipse.jface.text.IAutoIndentStrategy; 29 import org.eclipse.jface.text.IDocument; 30 import org.eclipse.jface.text.ITextHover; 31 import org.eclipse.jface.text.contentassist.IContentAssistant; 32 import org.eclipse.jface.text.formatter.ContentFormatter; 33 import org.eclipse.jface.text.formatter.IContentFormatter; 34 import org.eclipse.jface.text.presentation.IPresentationReconciler; 35 import org.eclipse.jface.text.presentation.PresentationReconciler; 36 import org.eclipse.jface.text.reconciler.IReconciler; 37 import org.eclipse.jface.text.reconciler.MonoReconciler; 38 import org.eclipse.jface.text.source.ISourceViewer; 39 import org.eclipse.jface.text.source.SourceViewer; 40 import org.eclipse.jface.text.source.SourceViewerConfiguration; 41 42 43 public class FilterSourceViewerConfiguration extends SourceViewerConfiguration 45 { 46 47 private IConnection connection; 48 49 private LdapFilterParser parser; 50 51 private SourceViewer sourceViewer; 52 53 private PresentationReconciler presentationReconciler; 55 56 private FilterDamagerRepairer damagerRepairer; 57 58 private MonoReconciler reconciler; 60 61 private FilterReconcilingStrategy reconcilingStrategy; 62 63 private FilterTextHover textHover; 65 66 private FilterAutoEditStrategy autoEditStrategy; 68 69 private ContentFormatter formatter; 70 71 private FilterFormattingStrategy formattingStrategy; 72 73 private DialogContentAssistant contentAssistant; 75 76 private FilterContentAssistProcessor contentAssistProcessor; 77 78 79 public FilterSourceViewerConfiguration( SourceViewer sourceViewer, LdapFilterParser parser, IConnection connection ) 80 { 81 super(); 82 this.sourceViewer = sourceViewer; 83 this.parser = parser; 84 this.connection = connection; 85 } 86 87 88 public void setConnection( IConnection connection ) 89 { 90 this.connection = connection; 91 this.contentAssistProcessor.setPossibleAttributeTypes( this.connection == null ? new String [0] 92 : this.connection.getSchema().getAttributeTypeDescriptionNames() ); 93 } 94 95 96 public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer ) 97 { 98 if ( this.damagerRepairer == null ) 99 { 100 this.damagerRepairer = new FilterDamagerRepairer( this.sourceViewer, this.parser ); 101 } 102 if ( this.presentationReconciler == null ) 103 { 104 this.presentationReconciler = new PresentationReconciler(); 105 this.presentationReconciler.setDamager( this.damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE ); 106 this.presentationReconciler.setRepairer( this.damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE ); 107 } 108 return this.presentationReconciler; 109 } 110 111 112 public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType ) 113 { 114 if ( this.textHover == null ) 115 { 116 this.textHover = new FilterTextHover( this.sourceViewer, this.parser ); 117 } 118 return this.textHover; 119 } 120 121 122 public IReconciler getReconciler( ISourceViewer sourceViewer ) 123 { 124 if ( this.reconcilingStrategy == null ) 125 { 126 this.reconcilingStrategy = new FilterReconcilingStrategy( this.sourceViewer, this.parser ); 127 } 128 if ( this.reconciler == null ) 129 { 130 this.reconciler = new MonoReconciler( this.reconcilingStrategy, false ); 131 } 132 return this.reconciler; 133 } 134 135 136 public IAutoIndentStrategy getAutoIndentStrategy( ISourceViewer sourceViewer, String contentType ) 137 { 138 if ( this.autoEditStrategy == null ) 139 { 140 this.autoEditStrategy = new FilterAutoEditStrategy( this.sourceViewer, this.parser ); 141 } 142 return this.autoEditStrategy; 143 } 144 145 146 public IContentFormatter getContentFormatter( ISourceViewer sourceViewer ) 147 { 148 if ( this.formattingStrategy == null ) 149 { 150 this.formattingStrategy = new FilterFormattingStrategy( this.sourceViewer, this.parser ); 151 } 152 if ( this.formatter == null ) 153 { 154 this.formatter = new ContentFormatter(); 155 this.formatter.enablePartitionAwareFormatting( false ); 156 this.formatter.setFormattingStrategy( this.formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE ); 157 } 158 return formatter; 159 } 160 161 162 public IContentAssistant getContentAssistant( ISourceViewer sourceViewer ) 163 { 164 165 if ( this.contentAssistProcessor == null ) 166 { 167 this.contentAssistProcessor = new FilterContentAssistProcessor( this.sourceViewer, this.parser ); 168 this.contentAssistProcessor.setPossibleAttributeTypes( this.connection == null ? new String [0] 169 : this.connection.getSchema().getAttributeTypeDescriptionNames() ); 170 } 171 if ( this.contentAssistant == null ) 172 { 173 this.contentAssistant = new DialogContentAssistant(); 174 this.contentAssistant.enableAutoInsert( true ); 175 this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor, 176 IDocument.DEFAULT_CONTENT_TYPE ); 177 this.contentAssistant.enableAutoActivation( true ); 178 this.contentAssistant.setAutoActivationDelay( 100 ); 179 } 180 return this.contentAssistant; 181 182 } 183 184 } 185 | Popular Tags |