KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > ldifeditor > editor > text > LdifAutoEditStrategy


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.text;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
25 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
26 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModifyRecord;
27 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
28 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
29 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
30 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecTypeLine;
31 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants;
32 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator;
33 import org.apache.directory.ldapstudio.ldifeditor.editor.ILdifEditor;
34
35 import org.eclipse.jface.text.DocumentCommand;
36 import org.eclipse.jface.text.IAutoEditStrategy;
37 import org.eclipse.jface.text.IDocument;
38 import org.eclipse.jface.text.TextUtilities;
39
40
41 public class LdifAutoEditStrategy implements IAutoEditStrategy
42 {
43
44     private ILdifEditor editor;
45
46
47     public LdifAutoEditStrategy( ILdifEditor editor )
48     {
49         this.editor = editor;
50     }
51
52
53     public void customizeDocumentCommand( IDocument d, DocumentCommand c )
54     {
55
56         LdifFile model = editor.getLdifModel();
57         LdifContainer container = LdifFile.getContainer( model, c.offset );
58         LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, c.offset ) : null;
59         LdifPart part = container != null ? LdifFile.getContainerContent( container, c.offset ) : null;
60
61         boolean smartInsertAttributeInModSpec = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
62             LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC );
63         if ( smartInsertAttributeInModSpec )
64         {
65             if ( c.length == 0 && c.text != null && TextUtilities.endsWith( d.getLegalLineDelimiters(), c.text ) != -1 )
66             {
67
68                 if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec
69                     && ( part instanceof LdifAttrValLine || part instanceof LdifModSpecTypeLine ) )
70                 {
71                     LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
72                     String JavaDoc att = modSpec.getModSpecType().getUnfoldedAttributeDescription();
73                     c.text += att + ": ";
74                 }
75             }
76         }
77
78         boolean autoWrap = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
79             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FORMATTER_AUTOWRAP );
80         
81         if ( autoWrap )
82         {
83
84         }
85
86     }
87
88 }
89
Popular Tags