directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592089 [4/5] - in /directory/sandbox/felixk/studio-ldifeditor: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ src/main/...
Date Mon, 05 Nov 2007 17:04:59 GMT
Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifAnnotationUpdater.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifAnnotationUpdater.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifAnnotationUpdater.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifAnnotationUpdater.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,144 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.reconciler;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IAnnotationModelExtension;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+class LdifAnnotationUpdater
+{
+
+    private static final String ERROR_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.error";
+
+    private ILdifEditor editor;
+
+
+    public LdifAnnotationUpdater( ILdifEditor editor )
+    {
+        this.editor = editor;
+    }
+
+
+    public void dispose()
+    {
+    }
+
+
+    public void updateAnnotations( LdifContainer[] containers )
+    {
+
+    }
+
+
+    public void updateAnnotations()
+    {
+
+        LdifFile model = editor.getLdifModel();
+        ISourceViewer viewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+        if ( viewer == null )
+            return;
+
+        IDocument document = viewer.getDocument();
+        IAnnotationModel annotationModel = viewer.getAnnotationModel();
+        if ( document == null || annotationModel == null || model == null )
+            return;
+
+        if ( annotationModel instanceof IAnnotationModelExtension )
+        {
+            ( ( IAnnotationModelExtension ) annotationModel ).removeAllAnnotations();
+
+            List positionList = new ArrayList();
+
+            LdifContainer[] containers = model.getContainers();
+            for ( int i = 0; i < containers.length; i++ )
+            {
+                LdifContainer container = containers[i];
+
+                // LdifPart errorPart = null;
+                int errorOffset = -1;
+                int errorLength = -1;
+                StringBuffer errorText = null;
+
+                LdifPart[] parts = container.getParts();
+                for ( int k = 0; k < parts.length; k++ )
+                {
+                    LdifPart part = parts[k];
+                    if ( !part.isValid() )
+                    {
+                        if ( errorOffset == -1 )
+                        {
+                            // errorPart = part;
+                            errorOffset = part.getOffset();
+                            errorLength = part.getLength();
+                            errorText = new StringBuffer();
+                            errorText.append( part.toRawString() );
+                        }
+                        else
+                        {
+                            errorLength += part.getLength();
+                            errorText.append( part.toRawString() );
+                        }
+                    }
+                }
+
+                if ( errorOffset == -1 && !container.isValid() )
+                {
+                    errorOffset = container.getOffset();
+                    errorLength = container.getLength();
+                    errorText = new StringBuffer();
+                    errorText.append( container.toRawString() );
+                }
+
+                if ( errorOffset > -1 )
+                {
+                    // Annotation annotation = new Annotation("DEFAULT",
+                    // true,
+                    // invalidFilters[i].toString());
+                    // if(errorPart instanceof LdifUnknownPart) {
+                    // errorOffset = container.getOffset();
+                    // errorLength = container.getLength();
+                    // errorText = new StringBuffer(container.toString());
+                    // }
+                    Annotation annotation = new Annotation( ERROR_ANNOTATION_TYPE, true, errorText.toString() );
+                    Position position = new Position( errorOffset, errorLength );
+                    positionList.add( position );
+                    viewer.getAnnotationModel().addAnnotation( annotation, position );
+                }
+
+            }
+        }
+    }
+
+}
\ No newline at end of file

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifAnnotationUpdater.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifFoldingRegionUpdater.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifFoldingRegionUpdater.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifFoldingRegionUpdater.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifFoldingRegionUpdater.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,224 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.reconciler;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifCommentContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifNonEmptyLineBase;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifSepLine;
+import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
+import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
+import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+
+public class LdifFoldingRegionUpdater implements IPropertyChangeListener
+{
+
+    private ILdifEditor editor;
+
+
+    public LdifFoldingRegionUpdater( ILdifEditor editor )
+    {
+        this.editor = editor;
+
+        LdifEditorActivator.getDefault().getPreferenceStore().addPropertyChangeListener( this );
+    }
+
+
+    public void dispose()
+    {
+        LdifEditorActivator.getDefault().getPreferenceStore().removePropertyChangeListener( this );
+    }
+
+
+    public void propertyChange( PropertyChangeEvent event )
+    {
+        if ( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE.equals( event.getProperty() )
+            || LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS.equals( event.getProperty() )
+            || LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS.equals( event.getProperty() )
+            || LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES.equals( event.getProperty() ) )
+        {
+            this.updateFoldingRegions();
+        }
+    }
+
+
+    public void updateFoldingRegions()
+    {
+
+        ISourceViewer viewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+        if ( viewer == null )
+            return;
+
+        IDocument document = viewer.getDocument();
+
+        try
+        {
+            ProjectionAnnotationModel projectionAnnotationModel = ( ProjectionAnnotationModel ) editor
+                .getAdapter( ProjectionAnnotationModel.class );
+            if ( projectionAnnotationModel == null )
+                return;
+
+            // create folding regions of current LDIF model; mark comments
+            // and
+            // folded lines as collapsed
+            Map positionToAnnotationMap = createFoldingRegions( editor.getLdifModel(), document );
+
+            // compare with current annotation model (--> toAdd, toDelete)
+            List annotationsToDeleteList = new ArrayList();
+            Map annotationsToAddMap = new HashMap();
+            this.computeDifferences( projectionAnnotationModel, positionToAnnotationMap, annotationsToDeleteList,
+                annotationsToAddMap );
+            Annotation[] annotationsToDelete = ( Annotation[] ) annotationsToDeleteList
+                .toArray( new Annotation[annotationsToDeleteList.size()] );
+
+            // update annotation model
+            if ( !annotationsToDeleteList.isEmpty() || !annotationsToAddMap.isEmpty() )
+            {
+                projectionAnnotationModel.modifyAnnotations( annotationsToDelete, annotationsToAddMap,
+                    new Annotation[0] );
+            }
+
+        }
+        catch ( BadLocationException e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+
+    private void computeDifferences( ProjectionAnnotationModel model, Map positionToAnnotationMap,
+        List annotationsToDeleteList, Map annotationsToAddMap )
+    {
+
+        for ( Iterator iter = model.getAnnotationIterator(); iter.hasNext(); )
+        {
+            Object annotation = iter.next();
+            if ( annotation instanceof ProjectionAnnotation )
+            {
+                Position position = model.getPosition( ( Annotation ) annotation );
+                if ( positionToAnnotationMap.containsKey( position ) )
+                    positionToAnnotationMap.remove( position );
+                else
+                    annotationsToDeleteList.add( annotation );
+            }
+        }
+
+        for ( Iterator iter = positionToAnnotationMap.keySet().iterator(); iter.hasNext(); )
+        {
+            Position position = ( Position ) iter.next();
+            ProjectionAnnotation annotation = ( ProjectionAnnotation ) positionToAnnotationMap.get( position );
+            annotationsToAddMap.put( annotation, position );
+        }
+    }
+
+
+    /**
+     * Creates all folding region of the given LDIF model.
+     * LdifCommentContainers and wrapped lines are marked as collapsed.
+     * 
+     * @param model
+     * @param document
+     * @return a map with positions as keys to annotations as values
+     * @throws BadLocationException
+     */
+    private Map createFoldingRegions( LdifFile model, IDocument document ) throws BadLocationException
+    {
+        Map positionToAnnotationMap = new HashMap();
+        LdifContainer[] containers = model.getContainers();
+
+        boolean ENABLE_FOLDING = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
+            LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE );
+        boolean FOLD_COMMENTS = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
+            LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS );
+        boolean FOLD_RECORDS = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
+            LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS );
+        boolean FOLD_WRAPPEDLINES = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
+            LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES );
+
+        if ( ENABLE_FOLDING )
+        {
+            for ( int i = 0; i < containers.length; i++ )
+            {
+                LdifContainer container = containers[i];
+                int containerStartLine = document.getLineOfOffset( container.getOffset() );
+                int containerEndLine = -1;
+                LdifPart[] parts = container.getParts();
+                for ( int j = parts.length - 1; j >= 0; j-- )
+                {
+                    if ( containerEndLine == -1
+                        && ( !( parts[j] instanceof LdifSepLine ) || ( container instanceof LdifCommentContainer && j < parts.length - 1 ) ) )
+                    {
+                        containerEndLine = document.getLineOfOffset( parts[j].getOffset() + parts[j].getLength() - 1 );
+                        // break;
+                    }
+                    if ( parts[j] instanceof LdifNonEmptyLineBase )
+                    {
+                        LdifNonEmptyLineBase line = ( LdifNonEmptyLineBase ) parts[j];
+                        if ( line.isFolded() )
+                        {
+                            Position position = new Position( line.getOffset(), line.getLength() );
+                            // ProjectionAnnotation annotation = new
+                            // ProjectionAnnotation(true);
+                            ProjectionAnnotation annotation = new ProjectionAnnotation( FOLD_WRAPPEDLINES );
+                            positionToAnnotationMap.put( position, annotation );
+                        }
+                    }
+                }
+
+                if ( containerStartLine < containerEndLine )
+                {
+                    int start = document.getLineOffset( containerStartLine );
+                    int end = document.getLineOffset( containerEndLine ) + document.getLineLength( containerEndLine );
+                    Position position = new Position( start, end - start );
+                    // ProjectionAnnotation annotation = new
+                    // ProjectionAnnotation(container instanceof
+                    // LdifCommentContainer);
+                    ProjectionAnnotation annotation = new ProjectionAnnotation( FOLD_RECORDS
+                        || ( FOLD_COMMENTS && container instanceof LdifCommentContainer ) );
+                    positionToAnnotationMap.put( position, annotation );
+                }
+            }
+        }
+
+        return positionToAnnotationMap;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifFoldingRegionUpdater.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifReconcilingStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifReconcilingStrategy.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifReconcilingStrategy.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifReconcilingStrategy.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,127 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.reconciler;
+
+
+import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
+import org.apache.directory.studio.ldifeditor.editor.LdifOutlinePage;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+
+
+public class LdifReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension
+{
+
+    private ILdifEditor editor;
+
+    // private IDocument document;
+    // private IProgressMonitor progressMonitor;
+
+    private LdifFoldingRegionUpdater foldingUpdater;
+
+    private LdifAnnotationUpdater annotationUpdater;
+
+
+    public LdifReconcilingStrategy( ILdifEditor editor )
+    {
+        this.editor = editor;
+
+        this.annotationUpdater = new LdifAnnotationUpdater( this.editor );
+        this.foldingUpdater = new LdifFoldingRegionUpdater( this.editor );
+
+    }
+
+
+    public void dispose()
+    {
+        this.annotationUpdater.dispose();
+        this.foldingUpdater.dispose();
+    }
+
+
+    public void setDocument( IDocument document )
+    {
+        // this.document = document;
+    }
+
+
+    public void setProgressMonitor( IProgressMonitor monitor )
+    {
+        // this.progressMonitor = monitor;
+    }
+
+
+    public void reconcile( DirtyRegion dirtyRegion, IRegion subRegion )
+    {
+        reconcile();
+    }
+
+
+    public void reconcile( IRegion partition )
+    {
+        reconcile();
+    }
+
+
+    public void initialReconcile()
+    {
+        reconcile();
+    }
+
+
+    private void reconcile()
+    {
+        notifyEnvironment();
+    }
+
+
+    private void notifyEnvironment()
+    {
+
+        Display.getDefault().asyncExec( new Runnable()
+        {
+            public void run()
+            {
+
+                // notify outline
+                IContentOutlinePage outline = ( IContentOutlinePage ) editor.getAdapter( IContentOutlinePage.class );
+                if ( outline != null && outline instanceof LdifOutlinePage )
+                {
+                    ( ( LdifOutlinePage ) outline ).refresh();
+                }
+
+                // notify annotation updater
+                annotationUpdater.updateAnnotations();
+
+                // notify folding updater
+                foldingUpdater.updateFoldingRegions();
+
+            }
+        } );
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifReconcilingStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAnnotationHover.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAnnotationHover.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAnnotationHover.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAnnotationHover.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,75 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.text;
+
+
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+public class LdifAnnotationHover implements IAnnotationHover
+{
+
+    private ILdifEditor editor;
+
+
+    public LdifAnnotationHover( ILdifEditor editor )
+    {
+        this.editor = editor;
+    }
+
+
+    public String getHoverInfo( ISourceViewer sourceViewer, int lineNumber )
+    {
+
+        try
+        {
+            if ( this.editor != null )
+            {
+
+                int offset = sourceViewer.getDocument().getLineOffset( lineNumber );
+                LdifContainer container = LdifFile.getContainer( this.editor.getLdifModel(), offset );
+                if ( container != null )
+                {
+                    LdifPart part = LdifFile.getContainerContent( container, offset );
+                    if ( part != null )
+                    {
+                        // return container.getClass().getName() + " - " +
+                        // part.getClass().getName();
+                        return container.getInvalidString() + " - " + part.getInvalidString();
+                    }
+                }
+            }
+        }
+        catch ( BadLocationException e )
+        {
+        }
+
+        return null;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAnnotationHover.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAutoEditStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAutoEditStrategy.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAutoEditStrategy.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAutoEditStrategy.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.text;
+
+
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifModSpecTypeLine;
+import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
+import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
+import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
+
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextUtilities;
+
+
+public class LdifAutoEditStrategy implements IAutoEditStrategy
+{
+
+    private ILdifEditor editor;
+
+
+    public LdifAutoEditStrategy( ILdifEditor editor )
+    {
+        this.editor = editor;
+    }
+
+
+    public void customizeDocumentCommand( IDocument d, DocumentCommand c )
+    {
+
+        LdifFile model = editor.getLdifModel();
+        LdifContainer container = LdifFile.getContainer( model, c.offset );
+        LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, c.offset ) : null;
+        LdifPart part = container != null ? LdifFile.getContainerContent( container, c.offset ) : null;
+
+        boolean smartInsertAttributeInModSpec = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
+            LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC );
+        if ( smartInsertAttributeInModSpec )
+        {
+            if ( c.length == 0 && c.text != null && TextUtilities.endsWith( d.getLegalLineDelimiters(), c.text ) != -1 )
+            {
+
+                if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec
+                    && ( part instanceof LdifAttrValLine || part instanceof LdifModSpecTypeLine ) )
+                {
+                    LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
+                    String att = modSpec.getModSpecType().getUnfoldedAttributeDescription();
+                    c.text += att + ": ";
+                }
+            }
+        }
+
+        boolean autoWrap = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
+            LdifEditorConstants.PREFERENCE_LDIFEDITOR_FORMATTER_AUTOWRAP );
+        
+        if ( autoWrap )
+        {
+
+        }
+
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAutoEditStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifCompletionProcessor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifCompletionProcessor.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifCompletionProcessor.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifCompletionProcessor.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,460 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.text;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifInvalidPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModDnRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifInvalidContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifSepContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifChangeTypeLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifSepLine;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
+import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
+import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.swt.graphics.Image;
+
+
+public class LdifCompletionProcessor extends TemplateCompletionProcessor
+{
+
+    // private final static String DN = "dn: ";
+    private final static String CT_ADD = "changetype: add" + BrowserCoreConstants.LINE_SEPARATOR;
+
+    private final static String CT_MODIFY = "changetype: modify" + BrowserCoreConstants.LINE_SEPARATOR;
+
+    private final static String CT_DELETE = "changetype: delete" + BrowserCoreConstants.LINE_SEPARATOR;
+
+    private final static String CT_MODDN = "changetype: moddn" + BrowserCoreConstants.LINE_SEPARATOR;
+
+    private final static String MD_NEWRDN = "newrdn: ";
+
+    private final static String MD_DELETEOLDRDN_TRUE = "deleteoldrdn: 1";
+
+    // private final static String MD_DELETEOLDRDN_FALSE = "deleteoldrdn:
+    // 0";
+    private final static String MD_NEWSUPERIOR = "newsuperior: ";
+
+    private final ILdifEditor editor;
+
+    private final ContentAssistant contentAssistant;
+
+
+    public LdifCompletionProcessor( ILdifEditor editor, ContentAssistant contentAssistant )
+    {
+        this.editor = editor;
+        this.contentAssistant = contentAssistant;
+    }
+
+
+    public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset )
+    {
+
+        IPreferenceStore store = LdifEditorActivator.getDefault().getPreferenceStore();
+        contentAssistant.enableAutoInsert( store
+            .getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) );
+        contentAssistant.enableAutoActivation( store
+            .getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) );
+        contentAssistant.setAutoActivationDelay( store
+            .getInt( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) );
+
+        List proposalList = new ArrayList();
+
+        LdifFile model = editor.getLdifModel();
+        LdifContainer container = LdifFile.getContainer( model, offset );
+        LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, offset ) : null;
+        LdifPart part = container != null ? LdifFile.getContainerContent( container, offset ) : null;
+        int documentLine = -1;
+        int documentLineOffset = -1;
+        String prefix = "";
+        try
+        {
+            documentLine = viewer.getDocument().getLineOfOffset( offset );
+            documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
+            prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
+        }
+        catch ( BadLocationException e )
+        {
+        }
+        // TemplateContextType contextType = getContextType(viewer, new
+        // Region(offset, 0));
+
+        // Add context dependend template proposals
+        ICompletionProposal[] templateProposals = super.computeCompletionProposals( viewer, offset );
+        if ( templateProposals != null )
+        {
+            proposalList.addAll( Arrays.asList( templateProposals ) );
+        }
+
+        // changetype: xxx
+        if ( container instanceof LdifRecord )
+        {
+            LdifRecord record = ( LdifRecord ) container;
+            LdifPart[] parts = record.getParts();
+            if ( parts.length > 1 && ( !( parts[1] instanceof LdifChangeTypeLine ) || !parts[1].isValid() ) )
+            {
+                if ( CT_ADD.startsWith( prefix ) )
+                    proposalList.add( new CompletionProposal( CT_ADD, offset - prefix.length(), prefix.length(), CT_ADD
+                        .length(), LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ADD ), CT_ADD
+                        .substring( 0, CT_ADD.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ), null, null ) );
+                if ( CT_MODIFY.startsWith( prefix ) )
+                    proposalList.add( new CompletionProposal( CT_MODIFY, offset - prefix.length(), prefix.length(),
+                        CT_MODIFY.length(),
+                        LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MODIFY ), CT_MODIFY
+                            .substring( 0, CT_MODIFY.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ), null,
+                        null ) );
+                if ( CT_DELETE.startsWith( prefix ) )
+                    proposalList.add( new CompletionProposal( CT_DELETE, offset - prefix.length(), prefix.length(),
+                        CT_DELETE.length(),
+                        LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_DELETE ), CT_DELETE
+                            .substring( 0, CT_DELETE.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ), null,
+                        null ) );
+                if ( CT_MODDN.startsWith( prefix ) )
+                    proposalList.add( new CompletionProposal( CT_MODDN, offset - prefix.length(), prefix.length(),
+                        CT_MODDN.length(), LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_RENAME ),
+                        CT_MODDN.substring( 0, CT_MODDN.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ),
+                        null, null ) );
+            }
+
+        }
+
+        // changetype: modify
+        if ( container instanceof LdifChangeModDnRecord )
+        {
+            LdifChangeModDnRecord record = ( LdifChangeModDnRecord ) container;
+            if ( ( record.getNewrdnLine() == null || !record.getNewrdnLine().isValid() )
+                && MD_NEWRDN.startsWith( prefix ) )
+            {
+                proposalList.add( new CompletionProposal( MD_NEWRDN, offset - prefix.length(), prefix.length(),
+                    MD_NEWRDN.length(), null, null, null, null ) );
+            }
+            if ( ( record.getDeloldrdnLine() == null || !record.getDeloldrdnLine().isValid() )
+                && MD_DELETEOLDRDN_TRUE.startsWith( prefix ) )
+            {
+                proposalList.add( new CompletionProposal( MD_DELETEOLDRDN_TRUE, offset - prefix.length(), prefix
+                    .length(), MD_DELETEOLDRDN_TRUE.length(), null, null, null, null ) );
+            }
+            if ( ( record.getNewsuperiorLine() == null || !record.getNewsuperiorLine().isValid() )
+                && MD_NEWSUPERIOR.startsWith( prefix ) )
+            {
+                proposalList.add( new CompletionProposal( MD_NEWSUPERIOR, offset - prefix.length(), prefix.length(),
+                    MD_NEWSUPERIOR.length(), null, null, null, null ) );
+            }
+        }
+
+        // modspecs
+        if ( innerContainer instanceof LdifModSpec )
+        {
+            LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
+            String att = modSpec.getModSpecType().getRawAttributeDescription();
+            if ( att != null && att.startsWith( prefix ) )
+            {
+                proposalList.add( new CompletionProposal( att, offset - prefix.length(), prefix.length(), att.length(),
+                    null, null, null, null ) );
+            }
+        }
+
+        // attribute descriptions
+        if ( container instanceof LdifContentRecord || container instanceof LdifChangeAddRecord )
+        {
+
+            if ( part instanceof LdifInvalidPart
+                || part instanceof LdifAttrValLine
+                || ( part instanceof LdifSepLine && ( container instanceof LdifContentRecord || container instanceof LdifChangeAddRecord ) ) )
+            {
+
+                String rawAttributeDescription = prefix;
+                String rawValueType = "";
+
+                if ( part instanceof LdifAttrValLine )
+                {
+                    LdifAttrValLine line = ( LdifAttrValLine ) part;
+                    rawAttributeDescription = line.getRawAttributeDescription();
+                    rawValueType = line.getRawValueType();
+                }
+
+                if ( offset <= part.getOffset() + rawAttributeDescription.length() )
+                {
+                    Schema schema = editor.getConnection() != null ? editor.getConnection().getSchema()
+                        : Schema.DEFAULT_SCHEMA;
+                    String[] attributeNames = schema.getAttributeTypeDescriptionNames();
+                    Arrays.sort( attributeNames );
+                    for ( int a = 0; a < attributeNames.length; a++ )
+                    {
+                        if ( rawAttributeDescription.length() == 0
+                            || attributeNames[a].startsWith( rawAttributeDescription ) )
+                        {
+
+                            String proposal = attributeNames[a];
+
+                            if ( rawValueType.length() == 0 )
+                            {
+                                if ( schema.getAttributeTypeDescription( proposal ).isBinary() )
+                                {
+                                    proposal += ":: ";
+                                }
+                                else
+                                {
+                                    proposal += ": ";
+                                }
+                            }
+
+                            proposalList
+                                .add( new CompletionProposal( proposal, offset - rawAttributeDescription.length(),
+                                    rawAttributeDescription.length(), proposal.length() ) );
+                        }
+                    }
+                }
+            }
+        }
+
+        // comment
+        boolean commentOnly = false;
+        if ( documentLineOffset == offset )
+        {
+            commentOnly = proposalList.isEmpty();
+            proposalList.add( new CompletionProposal( "# ", offset, 0, 2, LdifEditorActivator.getDefault().getImage(
+                LdifEditorConstants.IMG_LDIF_COMMENT ), "# - Comment", null, null ) );
+        }
+
+        // adjust auto-insert
+        this.contentAssistant.enableAutoInsert( !commentOnly );
+
+        ICompletionProposal[] proposals = ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] );
+        return proposals;
+
+    }
+
+
+    protected String extractPrefix( ITextViewer viewer, int offset )
+    {
+
+        IDocument document = viewer.getDocument();
+        if ( offset > document.getLength() )
+            return ""; //$NON-NLS-1$
+
+        try
+        {
+            int documentLine = viewer.getDocument().getLineOfOffset( offset );
+            int documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
+            String prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
+            return prefix;
+        }
+        catch ( BadLocationException e )
+        {
+            return ""; //$NON-NLS-1$
+        }
+    }
+
+
+    public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset )
+    {
+        return null;
+    }
+
+
+    public char[] getCompletionProposalAutoActivationCharacters()
+    {
+
+        char[] chars = new char[53];
+        for ( int i = 0; i < 26; i++ )
+            chars[i] = ( char ) ( 'a' + i );
+        for ( int i = 0; i < 26; i++ )
+            chars[i + 26] = ( char ) ( 'A' + i );
+        chars[52] = ':';
+
+        return chars;
+    }
+
+
+    public char[] getContextInformationAutoActivationCharacters()
+    {
+        return null;
+    }
+
+
+    public String getErrorMessage()
+    {
+        return null;
+    }
+
+
+    public IContextInformationValidator getContextInformationValidator()
+    {
+        return null;
+    }
+
+
+    protected Template[] getTemplates( String contextTypeId )
+    {
+        Template[] templates = LdifEditorActivator.getDefault().getLdifTemplateStore().getTemplates( contextTypeId );
+        return templates;
+    }
+
+
+    protected TemplateContextType getContextType( ITextViewer viewer, IRegion region )
+    {
+
+        int offset = region.getOffset();
+
+        LdifFile model = editor.getLdifModel();
+        LdifContainer container = LdifFile.getContainer( model, offset );
+        LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, offset ) : null;
+        LdifPart part = container != null ? LdifFile.getContainerContent( container, offset ) : null;
+        int documentLine = -1;
+        int documentLineOffset = -1;
+        String prefix = "";
+        try
+        {
+            documentLine = viewer.getDocument().getLineOfOffset( offset );
+            documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
+            prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
+        }
+        catch ( BadLocationException e )
+        {
+        }
+
+        // FILE
+        if ( container == null && innerContainer == null && part == null )
+        {
+            return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+                LdifEditorConstants.LDIF_FILE_TEMPLATE_ID );
+        }
+        if ( container instanceof LdifSepContainer && innerContainer == null && part instanceof LdifSepLine )
+        {
+            return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+                LdifEditorConstants.LDIF_FILE_TEMPLATE_ID );
+        }
+        if ( ( container instanceof LdifInvalidContainer && part instanceof LdifInvalidPart && "d".equals( prefix ) )
+            || ( container instanceof LdifContentRecord && part instanceof LdifInvalidPart && "dn".equals( prefix ) )
+            || ( container instanceof LdifContentRecord && part instanceof LdifInvalidPart && "dn:".equals( prefix ) ) )
+        {
+            return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+                LdifEditorConstants.LDIF_FILE_TEMPLATE_ID );
+        }
+
+        // MODIFICATION RECORD
+        if ( container instanceof LdifChangeModifyRecord && innerContainer == null
+            && ( part instanceof LdifSepLine || part instanceof LdifInvalidPart ) )
+        {
+            return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+                LdifEditorConstants.LDIF_MODIFICATION_RECORD_TEMPLATE_ID );
+        }
+
+        // MODIFICATION ITEM
+        if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec )
+        {
+            return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+                LdifEditorConstants.LDIF_MODIFICATION_ITEM_TEMPLATE_ID );
+        }
+
+        // MODDN RECORD
+        if ( container instanceof LdifChangeModDnRecord && innerContainer == null
+            && ( part instanceof LdifSepLine || part instanceof LdifInvalidPart ) )
+        {
+            return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+                LdifEditorConstants.LDIF_MODDN_RECORD_TEMPLATE_ID );
+        }
+
+        // TemplateContextType contextType =
+        // Activator.getDefault().getContextTypeRegistry().getContextType(LdifEditorConstants.LDIF_FILE_TEMPLATE_ID);
+        // TemplateContextType contextType =
+        // Activator.getDefault().getContextTypeRegistry().getContextType(LdifEditorConstants.LDIF_MODIFICATION_RECORD_TEMPLATE_ID);
+
+        return null;
+
+    }
+
+
+    protected Image getImage( Template template )
+    {
+
+        if ( template.getPattern().indexOf( "add: " ) > -1 )
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_ADD );
+        }
+        else if ( template.getPattern().indexOf( "replace: " ) > -1 )
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_REPLACE );
+        }
+        else if ( template.getPattern().indexOf( "delete: " ) > -1 )
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_DELETE );
+        }
+
+        else if ( template.getPattern().indexOf( "changetype: add" ) > -1 )
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ADD );
+        }
+        else if ( template.getPattern().indexOf( "changetype: modify" ) > -1 )
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MODIFY );
+        }
+        else if ( template.getPattern().indexOf( "changetype: delete" ) > -1 )
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_DELETE );
+        }
+        else if ( template.getPattern().indexOf( "changetype: moddn" ) > -1 )
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_RENAME );
+        }
+        else if ( template.getPattern().indexOf( "dn: " ) > -1 )
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_ENTRY );
+        }
+
+        else
+        {
+            return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_TEMPLATE );
+        }
+
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifCompletionProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDamagerRepairer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDamagerRepairer.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDamagerRepairer.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDamagerRepairer.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,420 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.text;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEOFPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifInvalidPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeDeleteRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModDnRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifChangeTypeLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifCommentLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifControlLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifDeloldrdnLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifDnLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifLineBase;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifModSpecSepLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifModSpecTypeLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifNewrdnLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifNewsuperiorLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifVersionLine;
+import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
+import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
+import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.presentation.IPresentationDamager;
+import org.eclipse.jface.text.presentation.IPresentationRepairer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+
+public class LdifDamagerRepairer implements IPresentationDamager, IPresentationRepairer
+{
+
+    private ILdifEditor editor;
+
+
+    // private IDocument document;
+
+    public LdifDamagerRepairer( ILdifEditor editor )
+    {
+        super();
+        this.editor = editor;
+        // this.document = null;
+    }
+
+
+    public void setDocument( IDocument document )
+    {
+        // this.document = document;
+    }
+
+
+    public IRegion getDamageRegion( ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged )
+    {
+        return partition;
+    }
+
+
+    public void createPresentation( TextPresentation presentation, ITypedRegion damage )
+    {
+
+        LdifFile ldifModel = this.editor.getLdifModel();
+        LdifContainer[] allContainers = ldifModel.getContainers();
+        List containerList = new ArrayList();
+        for ( int i = 0; i < allContainers.length; i++ )
+        {
+            LdifContainer container = allContainers[i];
+            Region containerRegion = new Region( container.getOffset(), container.getLength() );
+            if ( TextUtilities.overlaps( containerRegion, damage ) )
+            {
+                containerList.add( container );
+            }
+        }
+        LdifContainer[] containers = ( LdifContainer[] ) containerList
+            .toArray( new LdifContainer[containerList.size()] );
+        this.highlight( containers, presentation, damage );
+
+        // LdifFile ldifModel = this.editor.getLdifModel();
+        // System.out.println(ldifModel.toRawString());
+        // LdifContainer[] allContainers = ldifModel.getContainers();
+        // this.highlight(allContainers, presentation, null);
+
+    }
+
+    private Map textAttributeKeyToValueMap;
+
+
+    private TextAttribute geTextAttribute( String key )
+    {
+        IPreferenceStore store = LdifEditorActivator.getDefault().getPreferenceStore();
+
+        RGB rgb = PreferenceConverter
+            .getColor( store, key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX );
+        int style = store.getInt( key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX );
+
+        if ( textAttributeKeyToValueMap != null )
+        {
+            if ( textAttributeKeyToValueMap.containsKey( key
+                + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX ) )
+            {
+                rgb = ( RGB ) textAttributeKeyToValueMap.get( key
+                    + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX );
+            }
+            if ( textAttributeKeyToValueMap.containsKey( key
+                + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX ) )
+            {
+                style = ( ( Integer ) textAttributeKeyToValueMap.get( key
+                    + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX ) ).intValue();
+            }
+        }
+
+        Color color = LdifEditorActivator.getDefault().getColor( rgb );
+        TextAttribute textAttribute = new TextAttribute( color, null, style );
+        return textAttribute;
+    }
+
+
+    /**
+     * Overwrites the style set in preference store
+     * 
+     * @param key
+     *                the key
+     *                LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_xxx +
+     *                LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX
+     *                ore
+     *                LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX
+     * @param newValue
+     *                RGB object or Integer object
+     */
+    public void setTextAttribute( String key, RGB rgb, int style )
+    {
+        if ( textAttributeKeyToValueMap == null )
+        {
+            textAttributeKeyToValueMap = new HashMap();
+        }
+        textAttributeKeyToValueMap.put( key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, rgb );
+        textAttributeKeyToValueMap.put( key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX,
+            new Integer( style ) );
+    }
+
+
+    private void highlight( LdifContainer[] containers, TextPresentation presentation, ITypedRegion damage )
+    {
+
+        // TextAttribute DEFAULT_TEXT_ATTRIBUTE = new
+        // TextAttribute(Activator.getDefault().getColor(new RGB(0, 0,
+        // 0)));
+
+        TextAttribute COMMENT_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_COMMENT );
+        TextAttribute KEYWORD_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_KEYWORD );
+        TextAttribute DN_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_DN );
+        TextAttribute ATTRIBUTE_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_ATTRIBUTE );
+        TextAttribute VALUETYPE_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUETYPE );
+        TextAttribute VALUE_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUE );
+        TextAttribute ADD_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEADD );
+        TextAttribute MODIFY_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODIFY );
+        TextAttribute DELETE_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEDELETE );
+        TextAttribute MODDN_TEXT_ATTRIBUTE = geTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODDN );
+
+        for ( int z = 0; z < containers.length; z++ )
+        {
+
+            LdifContainer container = containers[z];
+
+            LdifPart[] parts = container.getParts();
+
+            for ( int i = 0; i < parts.length; i++ )
+            {
+
+                // int offset = damage.getOffset() + parts[i].getOffset();
+                int offset = parts[i].getOffset();
+
+                if ( parts[i] instanceof LdifLineBase )
+                {
+                    LdifLineBase line = ( LdifLineBase ) parts[i];
+
+                    // String debug = line.getClass().getName() +
+                    // "("+line.getOffset()+","+line.getLength()+"):
+                    // "+line.toString();
+                    // debug = debug.replaceAll("\n", "\\\\n");
+                    // debug = debug.replaceAll("\r", "\\\\r");
+                    // System.out.println(debug);
+
+                    if ( line instanceof LdifVersionLine )
+                    {
+                        this.addStyleRange( presentation, offset, line.getLength(), KEYWORD_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifCommentLine )
+                    {
+                        this.addStyleRange( presentation, offset, line.getLength(), COMMENT_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifDnLine )
+                    {
+                        LdifDnLine dnLine = ( LdifDnLine ) line;
+                        int dnSpecLength = dnLine.getRawDnSpec().length();
+                        int valueTypeLength = dnLine.getRawValueType().length();
+                        int dnLength = dnLine.getRawDn().length();
+                        this.addStyleRange( presentation, offset, dnSpecLength, DN_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + dnSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + dnSpecLength + valueTypeLength, dnLength,
+                            DN_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifAttrValLine )
+                    {
+                        LdifAttrValLine attrValLine = ( LdifAttrValLine ) line;
+                        int attributeNameLength = attrValLine.getRawAttributeDescription().length();
+                        int valueTypeLength = attrValLine.getRawValueType().length();
+                        int valueLength = attrValLine.getRawValue().length();
+                        this.addStyleRange( presentation, offset, attributeNameLength, ATTRIBUTE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + attributeNameLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + attributeNameLength + valueTypeLength, valueLength,
+                            VALUE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifChangeTypeLine )
+                    {
+                        LdifChangeTypeLine changeTypeLine = ( LdifChangeTypeLine ) line;
+                        int changeTypeSpecLength = changeTypeLine.getRawChangeTypeSpec().length();
+                        int valueTypeLength = changeTypeLine.getRawValueType().length();
+                        int changeTypeLength = changeTypeLine.getRawChangeType().length();
+                        this.addStyleRange( presentation, offset, changeTypeSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + changeTypeSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+
+                        if ( container instanceof LdifChangeAddRecord )
+                        {
+                            this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
+                                changeTypeLength, ADD_TEXT_ATTRIBUTE );
+                        }
+                        else if ( container instanceof LdifChangeModifyRecord )
+                        {
+                            this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
+                                changeTypeLength, MODIFY_TEXT_ATTRIBUTE );
+                        }
+                        else if ( container instanceof LdifChangeModDnRecord )
+                        {
+                            this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
+                                changeTypeLength, MODDN_TEXT_ATTRIBUTE );
+                        }
+                        else if ( container instanceof LdifChangeDeleteRecord )
+                        {
+                            this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
+                                changeTypeLength, DELETE_TEXT_ATTRIBUTE );
+                        }
+                    }
+                    else if ( line instanceof LdifNewrdnLine )
+                    {
+                        LdifNewrdnLine newrdnLine = ( LdifNewrdnLine ) line;
+                        int newrdnSpecLength = newrdnLine.getRawNewrdnSpec().length();
+                        int valueTypeLength = newrdnLine.getRawValueType().length();
+                        int newrdnLength = newrdnLine.getRawNewrdn().length();
+                        this.addStyleRange( presentation, offset, newrdnSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + newrdnSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + newrdnSpecLength + valueTypeLength, newrdnLength,
+                            VALUE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifDeloldrdnLine )
+                    {
+                        LdifDeloldrdnLine deleteoldrdnLine = ( LdifDeloldrdnLine ) line;
+                        int deleteoldrdnSpecLength = deleteoldrdnLine.getRawDeleteOldrdnSpec().length();
+                        int valueTypeLength = deleteoldrdnLine.getRawValueType().length();
+                        int deleteoldrdnLength = deleteoldrdnLine.getRawDeleteOldrdn().length();
+                        this.addStyleRange( presentation, offset, deleteoldrdnSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + deleteoldrdnSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + deleteoldrdnSpecLength + valueTypeLength,
+                            deleteoldrdnLength, VALUE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifNewsuperiorLine )
+                    {
+                        LdifNewsuperiorLine newsuperiorLine = ( LdifNewsuperiorLine ) line;
+                        int newsuperiorSpecLength = newsuperiorLine.getRawNewSuperiorSpec().length();
+                        int valueTypeLength = newsuperiorLine.getRawValueType().length();
+                        int newsuperiorLength = newsuperiorLine.getRawNewSuperiorDn().length();
+                        this.addStyleRange( presentation, offset, newsuperiorSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + newsuperiorSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + newsuperiorSpecLength + valueTypeLength,
+                            newsuperiorLength, VALUE_TEXT_ATTRIBUTE );
+                    }
+                    // else if(line instanceof LdifDeloldrdnLine) {
+                    // this.addStyleRange(presentation, offset,
+                    // line.getLength(), MODTYPE_TEXT_ATTRIBUTE);
+                    // }
+                    // else if(line instanceof LdifNewsuperiorLine) {
+                    // this.addStyleRange(presentation, offset,
+                    // line.getLength(), MODTYPE_TEXT_ATTRIBUTE);
+                    // }
+                    else if ( line instanceof LdifModSpecTypeLine )
+                    {
+                        LdifModSpecTypeLine modSpecTypeLine = ( LdifModSpecTypeLine ) line;
+                        int modTypeLength = modSpecTypeLine.getRawModType().length();
+                        int valueTypeLength = modSpecTypeLine.getRawValueType().length();
+                        int attributeDescriptionLength = modSpecTypeLine.getRawAttributeDescription().length();
+                        this.addStyleRange( presentation, offset, modTypeLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + modTypeLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + modTypeLength + valueTypeLength,
+                            attributeDescriptionLength, ATTRIBUTE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifModSpecSepLine )
+                    {
+                        this.addStyleRange( presentation, offset, line.getLength(), VALUETYPE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifControlLine )
+                    {
+                        LdifControlLine controlLine = ( LdifControlLine ) line;
+                        int controlSpecLength = controlLine.getRawControlSpec().length();
+                        int controlTypeLength = controlLine.getRawControlType().length();
+                        int oidLength = controlLine.getRawOid().length();
+                        int critLength = controlLine.getRawCriticality().length();
+                        int valueTypeLength = controlLine.getRawControlValueType().length();
+                        int valueLength = controlLine.getRawControlValue().length();
+                        this.addStyleRange( presentation, offset, controlSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength, controlTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength, oidLength,
+                            ATTRIBUTE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength,
+                            critLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength
+                            + critLength, valueTypeLength, VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength
+                            + critLength + valueTypeLength, valueLength, VALUE_TEXT_ATTRIBUTE );
+                    }
+                    else
+                    {
+                        // this.addStyleRange(presentation, offset,
+                        // line.getLength(), DEFAULT_TEXT_ATTRIBUTE);
+                    }
+                }
+                else if ( parts[i] instanceof LdifModSpec )
+                {
+                    LdifModSpec modSpec = ( LdifModSpec ) parts[i];
+                    this.highlight( new LdifContainer[]
+                        { modSpec }, presentation, damage );
+
+                }
+                else if ( parts[i] instanceof LdifInvalidPart )
+                {
+                    // LdifUnknownPart unknownPart =
+                    // (LdifUnknownPart)parts[i];
+                    // this.addStyleRange(presentation, offset,
+                    // unknownPart.getLength(), UNKNOWN_TEXT_ATTRIBUTE);
+                    // this.addStyleRange(presentation, offset,
+                    // parts[i].getLength(), DEFAULT_TEXT_ATTRIBUTE);
+                }
+                else if ( parts[i] instanceof LdifEOFPart )
+                {
+                    // ignore
+                }
+                else
+                {
+                    // TODO
+                    System.out.println( "LdifDamagerRepairer: Unspecified Token: " + parts[i].getClass() );
+                }
+
+            }
+        }
+
+    }
+
+
+    private void addStyleRange( TextPresentation presentation, int offset, int length, TextAttribute textAttribute )
+    {
+        if ( offset >= 0 && length > 0 )
+        {
+            StyleRange range = new StyleRange( offset, length, textAttribute.getForeground(), textAttribute
+                .getBackground(), textAttribute.getStyle() & ( SWT.BOLD | SWT.ITALIC ) );
+            range.underline = ( textAttribute.getStyle() & TextAttribute.UNDERLINE ) != 0;
+            range.strikeout = ( textAttribute.getStyle() & TextAttribute.STRIKETHROUGH ) != 0;
+            presentation.addStyleRange( range );
+        }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDamagerRepairer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDoubleClickStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDoubleClickStrategy.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDoubleClickStrategy.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDoubleClickStrategy.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,157 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.text;
+
+
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEOFPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifInvalidPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifLineBase;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifSepLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifValueLineBase;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.parser.LdifParser;
+import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
+import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultTextDoubleClickStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.ITypedRegion;
+
+
+public class LdifDoubleClickStrategy implements ITextDoubleClickStrategy
+{
+
+    private static final int OFFSET = 0;
+
+    private static final int LENGTH = 1;
+
+    /**
+     * Default double click strategy
+     */
+    private DefaultTextDoubleClickStrategy delegateDoubleClickStrategy;
+
+
+    public LdifDoubleClickStrategy()
+    {
+        this.delegateDoubleClickStrategy = new DefaultTextDoubleClickStrategy();
+    }
+
+
+    public void doubleClicked( ITextViewer viewer )
+    {
+
+        if ( !LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
+            LdifEditorConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK ) )
+        {
+            delegateDoubleClickStrategy.doubleClicked( viewer );
+        }
+        else
+        {
+
+            int cursorPos = viewer.getSelectedRange().x;
+            if ( cursorPos < 0 )
+            {
+                return;
+            }
+
+            try
+            {
+                LdifParser parser = new LdifParser();
+                IDocument document = viewer.getDocument();
+                ITypedRegion partition = document.getPartition( cursorPos );
+
+                // now use position relative to partition
+                int offset = partition.getOffset();
+                int relativePos = cursorPos - offset;
+
+                // parse partition
+                String s = document.get( partition.getOffset(), partition.getLength() );
+                LdifFile model = parser.parse( s );
+                LdifContainer container = LdifFile.getContainer( model, relativePos );
+                if ( container != null )
+                {
+                    LdifPart part = LdifFile.getContainerContent( container, relativePos );
+
+                    if ( part != null && !( part instanceof LdifSepLine ) && !( part instanceof LdifInvalidPart )
+                        && !( part instanceof LdifEOFPart ) )
+                    {
+
+                        // calculate selected range
+                        int[] range = null;
+                        if ( part instanceof LdifValueLineBase )
+                        {
+                            LdifValueLineBase line = ( LdifValueLineBase ) part;
+                            range = getRange( relativePos, part.getOffset(), new String[]
+                                { line.getRawLineStart(), line.getRawValueType(), line.getRawValue() } );
+                        }
+                        else if ( part instanceof LdifLineBase )
+                        {
+                            LdifLineBase line = ( LdifLineBase ) part;
+                            range = new int[]
+                                { part.getOffset(), part.getLength() - line.getRawNewLine().length() };
+                        }
+
+                        // set range on viewer, add global offset
+                        int start = range != null ? range[OFFSET] : part.getOffset();
+                        start += offset;
+                        int length = range != null ? range[LENGTH] : part.getLength();
+                        viewer.setSelectedRange( start, length );
+                    }
+                    else
+                    {
+                        // use default double click strategy
+                        delegateDoubleClickStrategy.doubleClicked( viewer );
+                    }
+                }
+
+            }
+            catch ( BadLocationException e )
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+
+
+    private int[] getRange( int pos, int offset, String[] parts )
+    {
+
+        for ( int i = 0; i < parts.length; i++ )
+        {
+            if ( parts[i] != null )
+            {
+                if ( pos < offset + parts[i].length() )
+                {
+                    return new int[]
+                        { offset, parts[i].length() };
+                }
+                offset += parts[i].length();
+            }
+        }
+        return null;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDoubleClickStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifExternalAnnotationModel.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifExternalAnnotationModel.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifExternalAnnotationModel.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifExternalAnnotationModel.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,30 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.text;
+
+
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+
+
+public class LdifExternalAnnotationModel extends ProjectionAnnotationModel
+{
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifExternalAnnotationModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifPartitionScanner.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifPartitionScanner.java?rev=592089&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifPartitionScanner.java (added)
+++ directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifPartitionScanner.java Mon Nov  5 09:04:52 2007
@@ -0,0 +1,57 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifeditor.editor.text;
+
+
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
+import org.eclipse.jface.text.rules.Token;
+
+
+public class LdifPartitionScanner extends RuleBasedPartitionScanner
+{
+
+    public final static String LDIF_RECORD = "__ldif_record";
+
+
+    public LdifPartitionScanner()
+    {
+        IToken record = new Token( LDIF_RECORD );
+
+        IPredicateRule[] rules = new IPredicateRule[1];
+        rules[0] = new LdifRecordRule( record );
+
+        setPredicateRules( rules );
+    }
+
+
+    public int read()
+    {
+        return super.read();
+        // try {
+        // return super.read();
+        // } finally {
+        // fColumn = UNDEFINED;
+        // }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifPartitionScanner.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message