directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r820979 - /directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java
Date Fri, 02 Oct 2009 11:54:27 GMT
Author: seelmann
Date: Fri Oct  2 11:54:27 2009
New Revision: 820979

URL: http://svn.apache.org/viewvc?rev=820979&view=rev
Log:
DIRSTUDIO-519: sort attributes in LDIF entry editor (OC, must, may, operational)

Modified:
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java?rev=820979&r1=820978&r2=820979&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java
Fri Oct  2 11:54:27 2009
@@ -21,12 +21,15 @@
 package org.apache.directory.studio.ldapbrowser.ui.editors.entry;
 
 
+import java.util.Arrays;
+
 import javax.naming.InvalidNameException;
 
 import org.apache.directory.studio.entryeditors.EntryEditorInput;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry;
+import org.apache.directory.studio.ldapbrowser.core.utils.AttributeComparator;
 import org.apache.directory.studio.ldapbrowser.core.utils.CompoundModification;
 import org.apache.directory.studio.ldapbrowser.core.utils.ModelConverter;
 import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
@@ -34,6 +37,7 @@
 import org.apache.directory.studio.ldifeditor.editor.LdifDocumentProvider;
 import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
 import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
+import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -144,12 +148,8 @@
             try
             {
                 inSetContent = true;
-
-                // set content
                 IEntry sharedWorkingCopy = input.getSharedWorkingCopy( editor );
-                LdifContentRecord record = ModelConverter.entryToLdifContentRecord( sharedWorkingCopy
);
-                String newContent = record.toFormattedString( Utils.getLdifFormatParameters()
);
-                document.set( newContent );
+                setDocumentInput( document, sharedWorkingCopy );
 
                 // reset dirty state
                 if ( !input.isSharedWorkingCopyDirty( editor ) )
@@ -169,6 +169,29 @@
     }
 
 
+    private void setDocumentInput( IDocument document, IEntry entry )
+    {
+        LdifContentRecord record = ModelConverter.entryToLdifContentRecord( entry );
+
+        // sort attribute-value lines
+        AttributeComparator comparator = new AttributeComparator( entry );
+        LdifAttrValLine[] attrValLines = record.getAttrVals();
+        Arrays.sort( attrValLines, comparator );
+        LdifContentRecord newRecord = new LdifContentRecord( record.getDnLine() );
+        for ( LdifAttrValLine attrValLine : attrValLines )
+        {
+            newRecord.addAttrVal( attrValLine );
+        }
+        newRecord.finish( record.getSepLine() );
+
+        // format
+        String newContent = newRecord.toFormattedString( Utils.getLdifFormatParameters()
);
+
+        // set content
+        document.set( newContent );
+    }
+
+
     public IDocument getDocument( Object element )
     {
         if ( element instanceof EntryEditorInput )
@@ -189,13 +212,9 @@
     protected IDocument createDocument( Object element ) throws CoreException
     {
         input = getEntryEditorInput( element );
-
         IEntry entry = getEntryEditorInput( element ).getSharedWorkingCopy( editor );
-        LdifContentRecord record = ModelConverter.entryToLdifContentRecord( entry );
-        String content = record.toFormattedString( Utils.getLdifFormatParameters() );
-
         IDocument document = new Document();
-        document.set( content );
+        setDocumentInput( document, entry );
         setupDocument( document );
         return document;
     }



Mime
View raw message