directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r757480 - /directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditorOutlinePage.java
Date Mon, 23 Mar 2009 18:14:40 GMT
Author: seelmann
Date: Mon Mar 23 18:14:40 2009
New Revision: 757480

URL: http://svn.apache.org/viewvc?rev=757480&view=rev
Log:
DIRSTUDIO-423: simplified outline page

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

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditorOutlinePage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditorOutlinePage.java?rev=757480&r1=757479&r2=757480&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditorOutlinePage.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditorOutlinePage.java
Mon Mar 23 18:14:40 2009
@@ -23,28 +23,14 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IValue;
 import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
-import org.apache.directory.studio.ldapbrowser.ui.actions.CopyEntryAsLdifAction;
 import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
 import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
-import org.apache.directory.studio.ldifparser.model.LdifFile;
-import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
-import org.apache.directory.studio.ldifparser.model.container.LdifChangeDeleteRecord;
-import org.apache.directory.studio.ldifparser.model.container.LdifChangeModDnRecord;
-import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord;
-import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
-import org.apache.directory.studio.ldifparser.model.container.LdifModSpec;
-import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
-import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
-import org.apache.directory.studio.ldifparser.parser.LdifParser;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -93,9 +79,8 @@
         super.createControl( parent );
 
         final TreeViewer treeViewer = getTreeViewer();
-        treeViewer.setLabelProvider( new LdifLabelProvider() );
-        treeViewer.setContentProvider( new LdifContentProvider() );
-        // treeViewer.setAutoExpandLevel(1);
+        treeViewer.setLabelProvider( new EntryEditorOutlineLabelProvider() );
+        treeViewer.setContentProvider( new EntryEditorOutlineContentProvider() );
 
         treeViewer.addSelectionChangedListener( new ISelectionChangedListener()
         {
@@ -103,58 +88,31 @@
             {
                 if ( !event.getSelection().isEmpty() && event.getSelection() instanceof
IStructuredSelection )
                 {
-
                     Object o = entryEditor.getMainWidget().getViewer().getInput();
                     if ( o != null && o instanceof IEntry )
                     {
-                        IEntry entry = ( IEntry ) o;
-                        IAttribute[] attributes = entry.getAttributes();
-
                         List<Object> selectionList = new ArrayList<Object>();
 
-                        Iterator<?> it = ( ( IStructuredSelection ) event.getSelection()
).iterator();
-                        while ( it.hasNext() )
+                        for ( Object element : ( ( IStructuredSelection ) event.getSelection()
).toArray() )
                         {
-                            Object element = it.next();
-
-                            if ( element instanceof LdifAttrValLine )
+                            if ( element instanceof IValue )
                             {
                                 // select the value
-                                LdifAttrValLine line = ( LdifAttrValLine ) element;
-                                for ( IAttribute attribute : attributes )
-                                {
-                                    if ( attribute.getDescription().equals( line.getUnfoldedAttributeDescription()
) )
-                                    {
-                                        for ( IValue value : attribute.getValues() )
-                                        {
-                                            if ( value.getStringValue().equals( line.getValueAsString()
) )
-                                            {
-                                                selectionList.add( value );
-                                            }
-                                        }
-                                    }
-                                }
+                                IValue value = ( IValue ) element;
+                                selectionList.add( value );
                             }
-                            else if ( element instanceof List )
+                            else if ( element instanceof IAttribute )
                             {
                                 // select attribute and all values
-                                List<?> list = ( List<?> ) element;
-                                if ( !list.isEmpty() && list.get( 0 ) instanceof
LdifAttrValLine )
-                                {
-                                    LdifAttrValLine line = ( LdifAttrValLine ) list.get(
0 );
-                                    for ( IAttribute attribute : attributes )
-                                    {
-                                        if ( attribute.getDescription().equals( line.getUnfoldedAttributeDescription()
) )
-                                        {
-                                            selectionList.add( attribute );
-                                            selectionList.addAll( Arrays.asList( attribute.getValues()
) );
-                                        }
-                                    }
-                                }
+                                IAttribute attribute = ( IAttribute ) element;
+                                selectionList.add( attribute );
+                                selectionList.addAll( Arrays.asList( attribute.getValues()
) );
                             }
-                            else if ( element instanceof LdifRecord )
+                            else if ( element instanceof EntryWrapper )
                             {
-                                for ( IAttribute attribute : attributes )
+                                // select all attributes and values
+                                IEntry entry = ( ( EntryWrapper ) element ).entry;
+                                for ( IAttribute attribute : entry.getAttributes() )
                                 {
                                     selectionList.add( attribute );
                                     selectionList.addAll( Arrays.asList( attribute.getValues()
) );
@@ -177,9 +135,13 @@
                 {
                     Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
                     if ( treeViewer.getExpandedState( obj ) )
+                    {
                         treeViewer.collapseToLevel( obj, 1 );
+                    }
                     else if ( ( ( ITreeContentProvider ) treeViewer.getContentProvider()
).hasChildren( obj ) )
+                    {
                         treeViewer.expandToLevel( obj, 1 );
+                    }
                 }
             }
         } );
@@ -199,6 +161,7 @@
         final TreeViewer treeViewer = getTreeViewer();
         if ( treeViewer != null && treeViewer.getTree() != null && !treeViewer.getTree().isDisposed()
)
         {
+            treeViewer.setFilters( entryEditor.getMainWidget().getViewer().getFilters() );
             treeViewer.refresh( element );
         }
     }
@@ -213,9 +176,7 @@
 
         if ( treeViewer != null && treeViewer.getTree() != null && !treeViewer.getTree().isDisposed()
)
         {
-            // ISelection selection = treeViewer.getSelection();
-            // Object[] expandedElements = treeViewer.getExpandedElements();
-
+            treeViewer.setFilters( entryEditor.getMainWidget().getViewer().getFilters() );
             if ( !treeViewer.getTree().isEnabled() )
             {
                 treeViewer.getTree().setEnabled( true );
@@ -230,25 +191,14 @@
                     treeViewer.setInput( null );
                     treeViewer.getTree().setEnabled( false );
                 }
-                else
+                else if ( o instanceof IEntry )
                 {
-                    if ( o instanceof IEntry )
-                    {
-                        StringBuffer sb = new StringBuffer();
-                        new CopyEntryAsLdifAction( CopyEntryAsLdifAction.MODE_INCLUDE_OPERATIONAL_ATTRIBUTES
)
-                            .serialializeEntries( new IEntry[]
-                                { ( IEntry ) o }, sb );
-                        LdifFile model = new LdifParser().parse( sb.toString() );
-                        treeViewer.setInput( model );
-                        treeViewer.expandToLevel( 2 );
-                    }
+                    treeViewer.setInput( o );
+                    treeViewer.expandToLevel( 2 );
                 }
             }
 
             treeViewer.refresh();
-
-            // treeViewer.setSelection(selection);
-            // treeViewer.setExpandedElements(expandedElements);
         }
     }
 
@@ -266,60 +216,40 @@
     }
 
     /**
-     * This class implements the ContentProvider used for the LDIF Outline View
+     * This class implements the ContentProvider used for the Entry Editor Outline View.
      *
      * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
      * @version $Rev$, $Date$
      */
-    private static class LdifContentProvider implements ITreeContentProvider
+    private static class EntryEditorOutlineContentProvider implements ITreeContentProvider
     {
-        /* (non-Javadoc)
-         * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+        /**
+         * {@inheritDoc}
          */
         public Object[] getChildren( Object element )
         {
-            // file --> records
-            if ( element instanceof LdifFile )
+            // entry -> entry wrapper
+            // the entry is the input and is not visible, 
+            // so we use an wrapper around to make it visible as root element 
+            if ( element instanceof IEntry )
             {
-                LdifFile ldifFile = ( LdifFile ) element;
-                return ldifFile.getRecords();
+                IEntry entry = ( IEntry ) element;
+                return new EntryWrapper[]
+                    { new EntryWrapper( entry ) };
             }
 
-            // record --> Array of List of AttrValLine
-            else if ( element instanceof LdifContentRecord )
-            {
-                LdifContentRecord record = ( LdifContentRecord ) element;
-                return getUniqueAttrValLineArray( record.getAttrVals() );
-            }
-            else if ( element instanceof LdifChangeAddRecord )
+            // entry wrapper -> attribute
+            if ( element instanceof EntryWrapper )
             {
-                LdifChangeAddRecord record = ( LdifChangeAddRecord ) element;
-                return getUniqueAttrValLineArray( record.getAttrVals() );
-            }
-            else if ( element instanceof LdifChangeModifyRecord )
-            {
-                LdifChangeModifyRecord record = ( LdifChangeModifyRecord ) element;
-                return record.getModSpecs();
-            }
-            else if ( element instanceof LdifChangeModDnRecord )
-            {
-                return new Object[0];
-            }
-            else if ( element instanceof LdifChangeDeleteRecord )
-            {
-                return new Object[0];
+                EntryWrapper entryWrapper = ( EntryWrapper ) element;
+                return entryWrapper.entry.getAttributes();
             }
 
-            // List of AttrValLine --> Array of AttrValLine
-            else if ( element instanceof List && ( ( List<?> ) element ).get(
0 ) instanceof LdifAttrValLine )
-            {
-                List<?> list = ( List<?> ) element;
-                return list.toArray();
-            }
-            else if ( element instanceof LdifModSpec )
+            // attribute -> values
+            else if ( element instanceof IAttribute )
             {
-                LdifModSpec modSpec = ( LdifModSpec ) element;
-                return modSpec.getAttrVals();
+                IAttribute attribute = ( IAttribute ) element;
+                return attribute.getValues();
             }
 
             else
@@ -330,29 +260,6 @@
 
 
         /**
-         * Returns a unique line of attribute values from an array of attribute value lines
-         *
-         * @param lines
-         *      the attribute value lines
-         * @return 
-         *      a unique line of attribute values from an array of attribute values lines
-         */
-        private Object[] getUniqueAttrValLineArray( LdifAttrValLine[] lines )
-        {
-            Map<String, List<LdifAttrValLine>> uniqueAttrMap = new LinkedHashMap<String,
List<LdifAttrValLine>>();
-            for ( int i = 0; i < lines.length; i++ )
-            {
-                if ( !uniqueAttrMap.containsKey( lines[i].getUnfoldedAttributeDescription()
) )
-                {
-                    uniqueAttrMap.put( lines[i].getUnfoldedAttributeDescription(), new ArrayList<LdifAttrValLine>()
);
-                }
-                ( uniqueAttrMap.get( lines[i].getUnfoldedAttributeDescription() ) ).add(
lines[i] );
-            }
-            return uniqueAttrMap.values().toArray();
-        }
-
-
-        /**
          * {@inheritDoc}
          */
         public Object getParent( Object element )
@@ -396,44 +303,37 @@
     }
 
     /**
-     * This class implements the LabelProvider used for the LDIF Outline View
+     * This class implements the LabelProvider used for the Entry Editor Outline View
      *
      * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
      * @version $Rev$, $Date$
      */
-    private static class LdifLabelProvider extends LabelProvider
+    private static class EntryEditorOutlineLabelProvider extends LabelProvider
     {
         /**
          * {@inheritDoc}
          */
         public String getText( Object element )
         {
-            // Record
-            if ( element instanceof LdifRecord )
+            // Entry
+            if ( element instanceof EntryWrapper )
             {
-                LdifRecord ldifRecord = ( LdifRecord ) element;
-                return ldifRecord.getDnLine().getValueAsString();
+                EntryWrapper entryWrapper = ( EntryWrapper ) element;
+                return entryWrapper.entry.getDn().getUpName();
             }
 
-            // List of AttrValLine
-            else if ( element instanceof List && ( ( List<?> ) element ).get(
0 ) instanceof LdifAttrValLine )
-            {
-                List<?> list = ( List<?> ) element;
-                return ( ( LdifAttrValLine ) list.get( 0 ) ).getUnfoldedAttributeDescription()
+ " (" + list.size() //$NON-NLS-1$
-                    + ")"; //$NON-NLS-1$
-            }
-            else if ( element instanceof LdifModSpec )
+            // Attribute
+            else if ( element instanceof IAttribute )
             {
-                LdifModSpec modSpec = ( LdifModSpec ) element;
-                return modSpec.getModSpecType().getUnfoldedAttributeDescription() + " ("
+ modSpec.getAttrVals().length //$NON-NLS-1$
-                    + ")"; //$NON-NLS-1$
+                IAttribute attribute = ( IAttribute ) element;
+                return attribute.getDescription() + " (" + attribute.getValueSize() + ")";
//$NON-NLS-1$  //$NON-NLS-2$
             }
 
-            // AttrValLine
-            else if ( element instanceof LdifAttrValLine )
+            // Value
+            else if ( element instanceof IValue )
             {
-                LdifAttrValLine line = ( LdifAttrValLine ) element;
-                return Utils.getShortenedString( line.getValueAsString(), 20 );
+                IValue value = ( IValue ) element;
+                return Utils.getShortenedString( value.getStringValue(), 20 );
             }
 
             else
@@ -448,48 +348,20 @@
          */
         public Image getImage( Object element )
         {
-            // Record
-            if ( element instanceof LdifContentRecord )
+            // Entry
+            if ( element instanceof EntryWrapper )
             {
                 return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_ENTRY
);
             }
-            else if ( element instanceof LdifChangeAddRecord )
-            {
-                return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ADD
);
-            }
-            else if ( element instanceof LdifChangeModifyRecord )
-            {
-                return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MODIFY
);
-            }
-            else if ( element instanceof LdifChangeDeleteRecord )
-            {
-                return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_DELETE
);
-            }
-            else if ( element instanceof LdifChangeModDnRecord )
-            {
-                return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_RENAME
);
-            }
 
-            // List of AttrValLine
-            else if ( element instanceof List && ( ( List<?> ) element ).get(
0 ) instanceof LdifAttrValLine )
+            // Attribute
+            else if ( element instanceof IAttribute )
             {
                 return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ATTRIBUTE
);
             }
-            else if ( element instanceof LdifModSpec )
-            {
-                LdifModSpec modSpec = ( LdifModSpec ) element;
-                if ( modSpec.isAdd() )
-                    return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_ADD
);
-                else if ( modSpec.isReplace() )
-                    return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_REPLACE
);
-                else if ( modSpec.isDelete() )
-                    return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_DELETE
);
-                else
-                    return null;
-            }
 
-            // AttrValLine
-            else if ( element instanceof LdifAttrValLine )
+            // Value
+            else if ( element instanceof IValue )
             {
                 return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_VALUE
);
             }
@@ -500,4 +372,55 @@
             }
         }
     }
+
+    /**
+     * Wrapper around an entry.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    private static class EntryWrapper
+    {
+        IEntry entry;
+
+
+        public EntryWrapper( IEntry entry )
+        {
+            super();
+            this.entry = entry;
+        }
+
+
+        @Override
+        public int hashCode()
+        {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ( ( entry == null ) ? 0 : entry.hashCode() );
+            return result;
+        }
+
+
+        @Override
+        public boolean equals( Object obj )
+        {
+            if ( this == obj )
+                return true;
+            if ( obj == null )
+                return false;
+            if ( getClass() != obj.getClass() )
+                return false;
+            EntryWrapper other = ( EntryWrapper ) obj;
+            if ( entry == null )
+            {
+                if ( other.entry != null )
+                    return false;
+            }
+            else if ( !entry.equals( other.entry ) )
+                return false;
+            return true;
+        }
+
+    }
+
 }



Mime
View raw message