KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > ldifeditor > editor > LdifSourceViewerConfiguration


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

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 /**
55  * This class enables the features of the editor (Syntax coloring, code completion, etc.)
56  *
57  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
58  * @version $Rev$, $Date$
59  */

60 public class LdifSourceViewerConfiguration extends SourceViewerConfiguration
61 {
62     private ILdifEditor editor;
63
64     // Error hover and annotations
65
private LdifAnnotationHover annotationHover;
66
67     private LdifTextHover textHover;
68
69     // Presentation Reconciler (syntax highlight)
70
private PresentationReconciler presentationReconciler;
71
72     private LdifDamagerRepairer damagerRepairer;
73
74     // Content Assistent
75
private boolean contentAssistEnabled;
76
77     private ContentAssistant contentAssistant;
78
79     private IContentAssistProcessor contentAssistProcessor;
80
81     private LdifDoubleClickStrategy doubleClickStrategy;
82
83     // Asynchronous Reconciler (annotations)
84
private MonoReconciler reconciler;
85
86     private LdifReconcilingStrategy reconcilingStrategy;
87
88     private IAutoEditStrategy[] autoEditStrategies;
89
90
91     /**
92      * Creates a new instance of LdifSourceViewerConfiguration.
93      *
94      * @param editor
95      * @param contentAssistEnabled
96      */

97     public LdifSourceViewerConfiguration( ILdifEditor editor, boolean contentAssistEnabled )
98     {
99         super();
100         this.editor = editor;
101
102         this.contentAssistEnabled = contentAssistEnabled;
103     }
104
105
106     /**
107      * Overwrites the style set in preference store
108      *
109      * @param key
110      * the key
111      * @param rgb
112      * the color
113      * @param style
114      * the stule
115      */

116     public void setTextAttribute( String JavaDoc key, RGB rgb, int style )
117     {
118         damagerRepairer.setTextAttribute( key, rgb, style );
119     }
120
121
122     /**
123      * {@inheritDoc}
124      */

125     public String JavaDoc getConfiguredDocumentPartitioning( ISourceViewer sourceViewer )
126     {
127         return LdifDocumentSetupParticipant.LDIF_PARTITIONING;
128     }
129
130
131     /**
132      * {@inheritDoc}
133      */

134     public String JavaDoc[] getConfiguredContentTypes( ISourceViewer sourceViewer )
135     {
136         return new String JavaDoc[]
137             { IDocument.DEFAULT_CONTENT_TYPE, LdifPartitionScanner.LDIF_RECORD };
138     }
139
140
141     /**
142      * {@inheritDoc}
143      */

144     public ITextDoubleClickStrategy getDoubleClickStrategy( ISourceViewer sourceViewer, String JavaDoc contentType )
145     {
146         if ( this.doubleClickStrategy == null )
147         {
148             this.doubleClickStrategy = new LdifDoubleClickStrategy();
149         }
150         return this.doubleClickStrategy;
151     }
152
153
154     /**
155      * {@inheritDoc}
156      */

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     /**
179      * {@inheritDoc}
180      */

181     public IReconciler getReconciler( ISourceViewer sourceViewer )
182     {
183         if ( this.reconciler == null )
184         {
185             this.reconcilingStrategy = new LdifReconcilingStrategy( editor );
186
187             // Reconciler reconciler = new Reconciler();
188
// reconciler.setIsIncrementalReconciler(true);
189
// reconciler.setReconcilingStrategy(strategy,
190
// LdifPartitionScanner.LDIF_RECORD);
191
// reconciler.setReconcilingStrategy(strategy,
192
// IDocument.DEFAULT_CONTENT_TYPE);
193
// reconciler.setProgressMonitor(new NullProgressMonitor());
194
// reconciler.setDelay(500);
195
// return reconciler;
196

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     /**
207      * {@inheritDoc}
208      */

209     public IContentAssistant getContentAssistant( ISourceViewer sourceViewer )
210     {
211         if ( this.contentAssistEnabled )
212         {
213             if ( this.contentAssistant == null )
214             {
215                 // this.contentAssistant = new ContentAssistant();
216
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                 // this.contentAssistant.enableAutoInsert(true);
236
// this.contentAssistant.enableAutoActivation(true);
237
// this.contentAssistant.setAutoActivationDelay(100);
238
}
239             return this.contentAssistant;
240         }
241         else
242         {
243             return null;
244         }
245     }
246
247
248     /**
249      * {@inheritDoc}
250      */

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     /**
262      * {@inheritDoc}
263      */

264     public ITextHover getTextHover( ISourceViewer sourceViewer, String JavaDoc contentType )
265     {
266         if ( this.textHover == null )
267         {
268             this.textHover = new LdifTextHover( this.editor );
269         }
270         return this.textHover;
271     }
272
273
274     /**
275      * {@inheritDoc}
276      */

277     public IAutoEditStrategy[] getAutoEditStrategies( ISourceViewer sourceViewer, String JavaDoc 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