You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/10/03 20:29:18 UTC

svn commit: r581678 - in /directory/studio/trunk: studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ studio-connection-ui/src/main/java/...

Author: seelmann
Date: Wed Oct  3 11:29:17 2007
New Revision: 581678

URL: http://svn.apache.org/viewvc?rev=581678&view=rev
Log:
DIRSTUDIO-187: drag and drop support for connection folders

Modified:
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
    directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java
    directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DragConnectionListener.java
    directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DropConnectionListener.java

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java?rev=581678&r1=581677&r2=581678&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java Wed Oct  3 11:29:17 2007
@@ -23,7 +23,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Random;
+import java.util.UUID;
 
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
 
@@ -34,7 +34,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ConnectionFolder
+public class ConnectionFolder implements Cloneable
 {
     private String id;
 
@@ -69,25 +69,62 @@
 
 
     /**
+     * @see java.lang.Object#clone()
+     */
+    public Object clone()
+    {
+        ConnectionFolder folder = new ConnectionFolder( getName() );
+
+        // clone connections
+        ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+        for ( String id : connectionIds )
+        {
+            Connection connection = connectionManager.getConnectionById( id );
+            if ( connection != null )
+            {
+                Connection newConnection = ( Connection ) connection.clone();
+                connectionManager.addConnection( newConnection );
+                folder.addConnectionId( newConnection.getId() );
+            }
+        }
+        
+        // clone subfolders
+        ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault().getConnectionFolderManager();
+        for ( String id : subFolderIds )
+        {
+            ConnectionFolder subFolder = connectionFolderManager.getConnectionFolderById( id );
+            if ( subFolder != null )
+            {
+                ConnectionFolder newFolder = ( ConnectionFolder ) subFolder.clone();
+                connectionFolderManager.addConnectionFolder( newFolder );
+                folder.addSubFolderId( newFolder.getId() );
+            }
+        }
+
+        return folder;
+    }
+
+
+    /**
      * Adds the connection id to the end of the connection list.
      * 
      * @param connectionId the connection id
      */
     public void addConnectionId( String connectionId )
     {
-        addConnectionId( connectionIds.size(), connectionId );
+        connectionIds.add( connectionId );
+        ConnectionEventRegistry.fireConnectonFolderModified( this, this );
     }
 
 
     /**
-     * Adds the connection id at the specified position of the connection list.
+     * Removes the connection id from the connection list.
      * 
-     * @param index the index
      * @param connectionId the connection id
      */
-    public void addConnectionId( int index, String connectionId )
+    public void removeConnectionId( String connectionId )
     {
-        connectionIds.add( index, connectionId );
+        connectionIds.remove( connectionId );
         ConnectionEventRegistry.fireConnectonFolderModified( this, this );
     }
 
@@ -99,19 +136,19 @@
      */
     public void addSubFolderId( String folderId )
     {
-        addSubFolderId( subFolderIds.size(), folderId );
+        subFolderIds.add( folderId );
+        ConnectionEventRegistry.fireConnectonFolderModified( this, this );
     }
 
 
     /**
-     * Adds the folder id to the end of the sub-folder list.
+     * Removes the connection folder from the sub-folder list.
      * 
-     * @param index the index
      * @param folderId the folder id
      */
-    public void addSubFolderId( int index, String folderId )
+    public void removeSubFolderId( String folderId )
     {
-        subFolderIds.add( index, folderId );
+        subFolderIds.remove( folderId );
         ConnectionEventRegistry.fireConnectonFolderModified( this, this );
     }
 
@@ -123,6 +160,10 @@
      */
     public String getId()
     {
+        if ( id == null )
+        {
+            id = createId();
+        }
         return id;
     }
 
@@ -230,8 +271,30 @@
      */
     private String createId()
     {
-        long id = new Random( System.currentTimeMillis() ).nextLong();
-        return Long.valueOf( id ).toString();
+        return UUID.randomUUID().toString();
+    }
+
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        return getId().hashCode();
+    }
+
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals( Object obj )
+    {
+        if ( obj instanceof ConnectionFolder )
+        {
+            ConnectionFolder other = ( ConnectionFolder ) obj;
+            return getId().equals( other.getId() );
+        }
+        return false;
     }
 
 }

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java?rev=581678&r1=581677&r2=581678&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java Wed Oct  3 11:29:17 2007
@@ -27,7 +27,9 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
@@ -49,7 +51,7 @@
     private ConnectionFolder root;
 
     /** The list of folders. */
-    private List<ConnectionFolder> folderList;
+    private Set<ConnectionFolder> folderList;
 
 
     /**
@@ -59,7 +61,7 @@
     {
         this.root = new ConnectionFolder( "" );
         this.root.setId( "0" ); //$NON-NLS-1$s
-        this.folderList = new ArrayList<ConnectionFolder>();
+        this.folderList = new HashSet<ConnectionFolder>();
 
         loadConnectionFolders();
         ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner() );
@@ -160,6 +162,98 @@
     }
 
 
+    /**
+     * Gets the parent connection folder of the given connection.
+     *
+     * @param connection
+     *      the connection used to search the parent
+     * @return
+     *      the parent connection folder of the given connection
+     */
+    public ConnectionFolder getParentConnectionFolder( Connection connection )
+    {
+        for ( ConnectionFolder folder : folderList )
+        {
+            if ( folder.getConnectionIds().contains( connection.getId() ) )
+            {
+                return folder;
+            }
+        }
+        return getRootConnectionFolder();
+    }
+    
+    
+    /**
+     * Gets the parent connection folder of the given connection folder 
+     * or null if the folder doesn't have a parent folder.
+     *
+     * @param connectionFolder
+     *      the connection folder used to search the parent
+     * @return
+     *      the parent connection folder of the given connection folder
+     *      or null if the folder doesn't have a parent folder
+     */
+    public ConnectionFolder getParentConnectionFolder( ConnectionFolder connectionFolder )
+    {
+        for ( ConnectionFolder folder : folderList )
+        {
+            if ( folder.getSubFolderIds().contains( connectionFolder.getId() ) )
+            {
+                return folder;
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * Gets the all sub-folders of the given folder including the given folder.
+     * 
+     * @param folder the folder
+     * 
+     * @return all sub-folders
+     */
+    public Set<ConnectionFolder> getAllSubFolders( ConnectionFolder folder )
+    {
+        Set<ConnectionFolder> allSubFolders = new HashSet<ConnectionFolder>();
+        
+        List<String> ids = new ArrayList<String>();
+        ids.add( folder.getId() );
+        while ( !ids.isEmpty() )
+        {
+            String id = ids.remove( 0 );
+            ConnectionFolder subFolder = getConnectionFolderById( id );
+            allSubFolders.add( subFolder );
+            
+            ids.addAll( subFolder.getSubFolderIds() );
+        }
+        
+        return allSubFolders;
+    }
+
+
+    /**
+     * Gets the all parent folders of the given folder including the given folder.
+     * 
+     * @param folder the folder
+     * 
+     * @return all parent folders
+     */
+    public Set<ConnectionFolder> getAllParentFolders( ConnectionFolder folder )
+    {
+        Set<ConnectionFolder> allParentFolders = new HashSet<ConnectionFolder>();
+        
+        do
+        {
+            allParentFolders.add( folder );
+            folder = getParentConnectionFolder( folder );
+        }
+        while ( folder != null );
+        
+        return allParentFolders;
+    }
+    
+    
     /**
      * Gets the root connection folder.
      * 

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java?rev=581678&r1=581677&r2=581678&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java Wed Oct  3 11:29:17 2007
@@ -26,8 +26,8 @@
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
@@ -46,7 +46,7 @@
 {
 
     /** The list of connections. */
-    private List<Connection> connectionList;
+    private Set<Connection> connectionList;
 
 
     /**
@@ -54,7 +54,7 @@
      */
     public ConnectionManager()
     {
-        this.connectionList = new ArrayList<Connection>();
+        this.connectionList = new HashSet<Connection>();
         loadConnections();
         ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner() );
     }
@@ -77,24 +77,10 @@
      * Adds the connection to the end of the connection list. If there is
      * already a connection with this name, the new connection is renamed.
      *
-     * @param connection
+     * @param connection the connection to add
      */
     public void addConnection( Connection connection )
     {
-        addConnection( connectionList.size(), connection );
-    }
-
-
-    /**
-     * Adds the connection at the specified position of the connection list.
-     * If there is already a connection with this name the new connection is
-     * renamed.
-     *
-     * @param index
-     * @param connection
-     */
-    public void addConnection( int index, Connection connection )
-    {
         if ( getConnectionByName( connection.getConnectionParameter().getName() ) != null )
         {
             String newConnectionName = Messages.bind( Messages.copy_n_of_s,
@@ -107,7 +93,7 @@
             connection.getConnectionParameter().setName( newConnectionName );
         }
 
-        connectionList.add( index, connection );
+        connectionList.add( connection );
         ConnectionEventRegistry.fireConnectionAdded( connection, this );
     }
 
@@ -155,20 +141,6 @@
 
 
     /**
-     * Gets the index in the Connection list of the first occurrence of the specified Connection.
-     *
-     * @param connection
-     *      the Connection to search for
-     * @return
-     *      the index in the Connection list of the first occurrence of the specified Connection
-     */
-    public int indexOf( Connection connection )
-    {
-        return connectionList.indexOf( connection );
-    }
-
-
-    /**
      * Removes the given Connection from the Connection list.
      *
      * @param connection
@@ -261,7 +233,7 @@
      */
     private synchronized void saveConnections()
     {
-        List<ConnectionParameter> connectionParameters = new ArrayList<ConnectionParameter>();
+        Set<ConnectionParameter> connectionParameters = new HashSet<ConnectionParameter>();
         for ( Connection connection : connectionList )
         {
             connectionParameters.add( connection.getConnectionParameter() );
@@ -304,7 +276,7 @@
      */
     private synchronized void loadConnections()
     {
-        List<ConnectionParameter> connectionParameters = null;
+        Set<ConnectionParameter> connectionParameters = null;
 
         try
         {

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java?rev=581678&r1=581677&r2=581678&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java Wed Oct  3 11:29:17 2007
@@ -23,7 +23,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Random;
+import java.util.UUID;
 
 
 /**
@@ -451,8 +451,30 @@
      */
     private String createId()
     {
-        long id = new Random( System.currentTimeMillis() ).nextLong();
-        return Long.valueOf( id ).toString();
+        return UUID.randomUUID().toString();
+    }
+
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        return getId().hashCode();
+    }
+
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals( Object obj )
+    {
+        if ( obj instanceof ConnectionParameter )
+        {
+            ConnectionParameter other = ( ConnectionParameter ) obj;
+            return getId().equals( other.getId() );
+        }
+        return false;
     }
 
 }

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java?rev=581678&r1=581677&r2=581678&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java Wed Oct  3 11:29:17 2007
@@ -23,10 +23,10 @@
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.Map.Entry;
 
 import org.apache.directory.studio.connection.core.ConnectionFolder;
@@ -82,9 +82,9 @@
      * @throws ConnectionIOException 
      *      if an error occurs when converting the document
      */
-    public static List<ConnectionParameter> load( FileInputStream stream ) throws ConnectionIOException
+    public static Set<ConnectionParameter> load( FileInputStream stream ) throws ConnectionIOException
     {
-        List<ConnectionParameter> connections = new ArrayList<ConnectionParameter>();
+        Set<ConnectionParameter> connections = new HashSet<ConnectionParameter>();
 
         SAXReader saxReader = new SAXReader();
         Document document = null;
@@ -242,7 +242,7 @@
      * @throws IOException
      *      if an I/O error occurs
      */
-    public static void save( List<ConnectionParameter> connections, FileOutputStream stream ) throws IOException
+    public static void save( Set<ConnectionParameter> connections, FileOutputStream stream ) throws IOException
     {
         // Creating the Document
         Document document = DocumentHelper.createDocument();
@@ -330,9 +330,9 @@
      * @throws ConnectionIOException 
      *      if an error occurs when converting the document
      */
-    public static List<ConnectionFolder> loadConnectionFolders( FileInputStream stream ) throws ConnectionIOException
+    public static Set<ConnectionFolder> loadConnectionFolders( FileInputStream stream ) throws ConnectionIOException
     {
-        List<ConnectionFolder> connectionFolders = new ArrayList<ConnectionFolder>();
+        Set<ConnectionFolder> connectionFolders = new HashSet<ConnectionFolder>();
 
         SAXReader saxReader = new SAXReader();
         Document document = null;
@@ -438,7 +438,7 @@
      * @throws IOException
      *      if an I/O error occurs
      */
-    public static void saveConnectionFolders( List<ConnectionFolder> connectionFolders, FileOutputStream stream ) throws IOException
+    public static void saveConnectionFolders( Set<ConnectionFolder> connectionFolders, FileOutputStream stream ) throws IOException
     {
         // Creating the Document
         Document document = DocumentHelper.createDocument();

Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java?rev=581678&r1=581677&r2=581678&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java Wed Oct  3 11:29:17 2007
@@ -31,6 +31,8 @@
 
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.ConnectionFolderManager;
 import org.apache.directory.studio.connection.core.ConnectionManager;
 import org.eclipse.swt.dnd.ByteArrayTransfer;
 import org.eclipse.swt.dnd.Transfer;
@@ -81,37 +83,45 @@
     /**
      * {@inheritDoc}
      * 
-     * This implementation only accepts {@link Connection} objects. 
-     * It just converts the id of the connection to the platform 
+     * This implementation only accepts {@link Connection} and {@link ConnectionFolder} objects. 
+     * It just converts the id of the connection or connection folder to the platform 
      * specific representation.
      */
     public void javaToNative( Object object, TransferData transferData )
     {
-        if ( object == null || !( object instanceof Connection[] ) )
+        if ( object == null || !( object instanceof Object[] ) )
         {
             return;
         }
 
         if ( isSupportedType( transferData ) )
         {
-            Connection[] connections = ( Connection[] ) object;
+            Object[] objects = ( Object[] ) object;
             try
             {
                 ByteArrayOutputStream out = new ByteArrayOutputStream();
                 DataOutputStream writeOut = new DataOutputStream( out );
 
-                for ( int i = 0; i < connections.length; i++ )
+                for ( int i = 0; i < objects.length; i++ )
                 {
-                    byte[] id = connections[i].getConnectionParameter().getId().getBytes();
-                    writeOut.writeInt( id.length );
-                    writeOut.write( id );
+                    if ( objects[i] instanceof Connection )
+                    {
+                        byte[] id = ( ( Connection ) objects[i] ).getConnectionParameter().getId().getBytes();
+                        writeOut.writeInt( id.length );
+                        writeOut.write( id );
+                    }
+                    else if ( objects[i] instanceof ConnectionFolder )
+                    {
+                        byte[] id = ( ( ConnectionFolder ) objects[i] ).getId().getBytes();
+                        writeOut.writeInt( id.length );
+                        writeOut.write( id );
+                    }
                 }
 
                 byte[] buffer = out.toByteArray();
                 writeOut.close();
 
                 super.javaToNative( buffer, transferData );
-
             }
             catch ( IOException e )
             {
@@ -124,9 +134,10 @@
      * {@inheritDoc}
      * 
      * This implementation just converts the platform specific representation
-     * to the connection id and invokes 
+     * to the connection id or connection folder id and invokes 
      * {@link ConnectionManager#getConnectionById(String)} to get the
-     * {@link Connection} object.
+     * {@link Connection} object or {@link ConnectionFolderManager#getConnectionFolderById(String)}
+     * to get the {@link ConnectionFolder} object.
      */
     public Object nativeToJava( TransferData transferData )
     {
@@ -138,7 +149,7 @@
                 return null;
             }
 
-            List<Connection> connectionList = new ArrayList<Connection>();
+            List<Object> objectList = new ArrayList<Object>();
             try
             {
                 ByteArrayInputStream in = new ByteArrayInputStream( buffer );
@@ -151,9 +162,21 @@
                         int size = readIn.readInt();
                         byte[] id = new byte[size];
                         readIn.read( id );
-                        Connection connection = ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionById(
-                            new String( id ) );
-                        connectionList.add( connection );
+                        Connection connection = ConnectionCorePlugin.getDefault().getConnectionManager()
+                            .getConnectionById( new String( id ) );
+                        if ( connection != null )
+                        {
+                            objectList.add( connection );
+                        }
+                        else
+                        {
+                            ConnectionFolder folder = ConnectionCorePlugin.getDefault().getConnectionFolderManager()
+                                .getConnectionFolderById( new String( id ) );
+                            if ( folder != null )
+                            {
+                                objectList.add( folder );
+                            }
+                        }
                     }
                 }
                 while ( readIn.available() > 1 );
@@ -165,7 +188,7 @@
                 return null;
             }
 
-            return connectionList.toArray( new Connection[0] );
+            return objectList.toArray();
         }
 
         return null;

Modified: directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DragConnectionListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DragConnectionListener.java?rev=581678&r1=581677&r2=581678&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DragConnectionListener.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DragConnectionListener.java Wed Oct  3 11:29:17 2007
@@ -25,13 +25,13 @@
 import java.util.List;
 
 import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
 import org.apache.directory.studio.connection.ui.dnd.ConnectionTransfer;
-import org.eclipse.swt.dnd.DND;
 import org.eclipse.swt.dnd.DragSource;
 import org.eclipse.swt.dnd.DragSourceEvent;
 import org.eclipse.swt.dnd.DragSourceListener;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
 
 
 /**
@@ -65,7 +65,7 @@
     /**
      * {@inheritDoc}
      * 
-     * This implementation adds the dragged connections to the 
+     * This implementation adds the dragged connections and connection folders to the 
      * given event data.
      */
     public void dragSetData( DragSourceEvent event )
@@ -75,19 +75,19 @@
             if ( event.widget instanceof DragSource )
             {
                 DragSource dragSource = ( DragSource ) event.widget;
-                if ( dragSource.getControl() instanceof Table )
+                if ( dragSource.getControl() instanceof Tree )
                 {
-                    Table table = ( Table ) dragSource.getControl();
-                    TableItem[] items = table.getSelection();
-                    List<Connection> connectionList = new ArrayList<Connection>();
+                    Tree tree = ( Tree ) dragSource.getControl();
+                    TreeItem[] items = tree.getSelection();
+                    List<Object> objectList = new ArrayList<Object>();
                     for ( int i = 0; i < items.length; i++ )
                     {
-                        if ( items[i].getData() instanceof Connection )
+                        if ( items[i].getData() instanceof Connection || items[i].getData() instanceof ConnectionFolder )
                         {
-                            connectionList.add( ( Connection ) items[i].getData() );
+                            objectList.add( items[i].getData() );
                         }
                     }
-                    event.data = connectionList.toArray( new Connection[connectionList.size()] );
+                    event.data = objectList.toArray();
                 }
             }
         }
@@ -101,10 +101,6 @@
      */
     public void dragFinished( DragSourceEvent event )
     {
-        if ( event.detail == DND.DROP_MOVE && event.doit )
-        {
-            // this.connectionManager.removeConnection(this.dragConnection);
-        }
     }
 
 }

Modified: directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DropConnectionListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DropConnectionListener.java?rev=581678&r1=581677&r2=581678&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DropConnectionListener.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DropConnectionListener.java Wed Oct  3 11:29:17 2007
@@ -21,19 +21,20 @@
 package org.apache.directory.studio.ldapbrowser.ui.views.connection;
 
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Set;
 
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.ConnectionFolderManager;
 import org.apache.directory.studio.connection.core.ConnectionManager;
 import org.apache.directory.studio.connection.ui.dnd.ConnectionTransfer;
 import org.eclipse.swt.dnd.DND;
 import org.eclipse.swt.dnd.DropTarget;
 import org.eclipse.swt.dnd.DropTargetEvent;
 import org.eclipse.swt.dnd.DropTargetListener;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
 
 
 /**
@@ -98,58 +99,68 @@
      */
     public void dragOver( DropTargetEvent event )
     {
-        boolean isOverSelection = false;
-        if ( event.detail == DND.DROP_MOVE || event.detail == DND.DROP_NONE )
+        try
         {
-            if ( ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
+            // move connection folder: check that the new connection folder is not the same or a parent folder
+            boolean isMoveConnectionFolderForbidden = false;
+            if ( event.detail == DND.DROP_MOVE || event.detail == DND.DROP_NONE )
             {
-                if ( event.item != null && event.item.getData() instanceof Connection )
+                if ( ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
                 {
-                    Connection overConn = ( Connection ) event.item.getData();
-                    if ( event.widget instanceof DropTarget )
+                    if ( event.item != null && event.item.getData() instanceof ConnectionFolder )
                     {
-                        DropTarget dropTarget = ( DropTarget ) event.widget;
-                        if ( dropTarget.getControl() instanceof Table )
+                        ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault()
+                            .getConnectionFolderManager();
+                        ConnectionFolder overFolder = ( ConnectionFolder ) event.item.getData();
+                        Set<ConnectionFolder> allParentFolders = connectionFolderManager
+                            .getAllParentFolders( overFolder );
+
+                        if ( event.widget instanceof DropTarget )
                         {
-                            Table table = ( Table ) dropTarget.getControl();
-                            TableItem[] items = table.getSelection();
-                            List<Connection> connectionList = new ArrayList<Connection>();
-                            for ( int i = 0; i < items.length; i++ )
+                            DropTarget dropTarget = ( DropTarget ) event.widget;
+                            if ( dropTarget.getControl() instanceof Tree )
                             {
-                                if ( items[i].getData() instanceof Connection )
+                                Tree tree = ( Tree ) dropTarget.getControl();
+                                TreeItem[] items = tree.getSelection();
+                                for ( int i = 0; i < items.length; i++ )
                                 {
-                                    connectionList.add( ( Connection ) items[i].getData() );
+                                    if ( items[i].getData() instanceof ConnectionFolder )
+                                    {
+                                        ConnectionFolder folder = ( ConnectionFolder ) items[i].getData();
+                                        if ( allParentFolders.contains( folder ) )
+                                        {
+                                            isMoveConnectionFolderForbidden = true;
+                                            break;
+                                        }
+                                    }
                                 }
                             }
-                            if ( connectionList.contains( overConn ) )
-                            {
-                                isOverSelection = true;
-                            }
                         }
                     }
                 }
             }
-        }
 
-        if ( !ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
-        {
-            event.detail = DND.DROP_NONE;
-        }
-        else if ( event.item == null )
-        {
-            event.detail = DND.DROP_NONE;
-        }
-        else if ( isOverSelection )
-        {
-            event.detail = DND.DROP_NONE;
+            if ( !ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
+            {
+                event.detail = DND.DROP_NONE;
+            }
+            else if ( isMoveConnectionFolderForbidden )
+            {
+                event.detail = DND.DROP_NONE;
+            }
+            else if ( event.detail == DND.DROP_LINK )
+            {
+                event.detail = DND.DROP_NONE;
+            }
+            else if ( event.detail == DND.DROP_NONE )
+            {
+                event.detail = DND.DROP_DEFAULT;
+            }
         }
-        else if ( event.detail == DND.DROP_LINK )
+        catch ( Exception e )
         {
             event.detail = DND.DROP_NONE;
-        }
-        else if ( event.detail == DND.DROP_NONE )
-        {
-            event.detail = DND.DROP_DEFAULT;
+            e.printStackTrace();
         }
     }
 
@@ -173,44 +184,66 @@
     public void drop( DropTargetEvent event )
     {
         ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+        ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault()
+            .getConnectionFolderManager();
 
         try
         {
             if ( ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
             {
-                // get connection to handle
-                Connection[] connections = ( Connection[] ) event.data;
-                Connection targetConnection = ( Connection ) event.item.getData();
+                // get connection and folders to handle
+                Object[] objects = ( Object[] ) event.data;
+                Object target = event.item != null ? event.item.getData() : connectionFolderManager
+                    .getRootConnectionFolder();
 
-                if ( event.detail == DND.DROP_MOVE )
+                ConnectionFolder targetFolder = null;
+                if ( target instanceof ConnectionFolder )
                 {
-                    boolean fromTop = connectionManager.indexOf( connections[0] ) < connectionManager
-                        .indexOf( targetConnection );
-                    for ( int i = 0; i < connections.length; i++ )
-                    {
-                        connectionManager.removeConnection( connections[i] );
-                    }
-                    for ( int i = 0; i < connections.length; i++ )
+                    targetFolder = ( ConnectionFolder ) target;
+                }
+                else if ( target instanceof Connection )
+                {
+                    Connection connection = ( Connection ) target;
+                    targetFolder = connectionFolderManager.getParentConnectionFolder( connection );
+                }
+
+                for ( Object object : objects )
+                {
+                    if ( object instanceof Connection )
                     {
-                        int index = connectionManager.indexOf( targetConnection );
-                        if ( fromTop )
+                        Connection connection = ( Connection ) object;
+                        if ( event.detail == DND.DROP_MOVE )
                         {
-                            index++;
-                            connectionManager.addConnection( index + i, connections[i] );
+                            ConnectionFolder parentConnectionFolder = connectionFolderManager
+                                .getParentConnectionFolder( connection );
+                            parentConnectionFolder.removeConnectionId( connection.getId() );
+                            targetFolder.addConnectionId( connection.getId() );
                         }
-                        else
+                        else if ( event.detail == DND.DROP_COPY )
                         {
-                            connectionManager.addConnection( index, connections[i] );
+                            Connection newConnection = ( Connection ) connection.clone();
+                            connectionManager.addConnection( newConnection );
+                            targetFolder.addConnectionId( newConnection.getId() );
                         }
                     }
-                }
-                else if ( event.detail == DND.DROP_COPY )
-                {
-                    for ( int i = 0; i < connections.length; i++ )
+                    else if ( object instanceof ConnectionFolder )
                     {
-                        Connection newConnection = ( Connection ) connections[i].clone();
-                        int index = connectionManager.indexOf( targetConnection );
-                        connectionManager.addConnection( index + i + 1, newConnection );
+                        ConnectionFolder folder = ( ConnectionFolder ) object;
+                        if ( event.detail == DND.DROP_MOVE )
+                        {
+                            ConnectionFolder parentConnectionFolder = connectionFolderManager
+                                .getParentConnectionFolder( folder );
+                            parentConnectionFolder.removeSubFolderId( folder.getId() );
+                            targetFolder.addSubFolderId( folder.getId() );
+                            // TODO: expand target folder
+                        }
+                        else if ( event.detail == DND.DROP_COPY )
+                        {
+                            ConnectionFolder newFolder = ( ConnectionFolder ) folder.clone();
+                            connectionFolderManager.addConnectionFolder( newFolder );
+                            targetFolder.addSubFolderId( newFolder.getId() );
+                            // TODO: expand target folder
+                        }
                     }
                 }
             }