From commits-return-15698-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Wed Oct 03 18:29:50 2007 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 25894 invoked from network); 3 Oct 2007 18:29:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Oct 2007 18:29:47 -0000 Received: (qmail 12418 invoked by uid 500); 3 Oct 2007 18:29:32 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 12378 invoked by uid 500); 3 Oct 2007 18:29:32 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 12351 invoked by uid 99); 3 Oct 2007 18:29:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Oct 2007 11:29:31 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Oct 2007 18:29:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 272F51A9832; Wed, 3 Oct 2007 11:29:21 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/... Date: Wed, 03 Oct 2007 18:29:18 -0000 To: commits@directory.apache.org From: seelmann@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071003182921.272F51A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Apache Directory Project * @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 folderList; + private Set folderList; /** @@ -59,7 +61,7 @@ { this.root = new ConnectionFolder( "" ); this.root.setId( "0" ); //$NON-NLS-1$s - this.folderList = new ArrayList(); + this.folderList = new HashSet(); 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 getAllSubFolders( ConnectionFolder folder ) + { + Set allSubFolders = new HashSet(); + + List ids = new ArrayList(); + 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 getAllParentFolders( ConnectionFolder folder ) + { + Set allParentFolders = new HashSet(); + + 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 connectionList; + private Set connectionList; /** @@ -54,7 +54,7 @@ */ public ConnectionManager() { - this.connectionList = new ArrayList(); + this.connectionList = new HashSet(); 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 connectionParameters = new ArrayList(); + Set connectionParameters = new HashSet(); for ( Connection connection : connectionList ) { connectionParameters.add( connection.getConnectionParameter() ); @@ -304,7 +276,7 @@ */ private synchronized void loadConnections() { - List connectionParameters = null; + Set 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 load( FileInputStream stream ) throws ConnectionIOException + public static Set load( FileInputStream stream ) throws ConnectionIOException { - List connections = new ArrayList(); + Set connections = new HashSet(); SAXReader saxReader = new SAXReader(); Document document = null; @@ -242,7 +242,7 @@ * @throws IOException * if an I/O error occurs */ - public static void save( List connections, FileOutputStream stream ) throws IOException + public static void save( Set 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 loadConnectionFolders( FileInputStream stream ) throws ConnectionIOException + public static Set loadConnectionFolders( FileInputStream stream ) throws ConnectionIOException { - List connectionFolders = new ArrayList(); + Set connectionFolders = new HashSet(); SAXReader saxReader = new SAXReader(); Document document = null; @@ -438,7 +438,7 @@ * @throws IOException * if an I/O error occurs */ - public static void saveConnectionFolders( List connectionFolders, FileOutputStream stream ) throws IOException + public static void saveConnectionFolders( Set 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 connectionList = new ArrayList(); + List objectList = new ArrayList(); 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 connectionList = new ArrayList(); + Tree tree = ( Tree ) dragSource.getControl(); + TreeItem[] items = tree.getSelection(); + List objectList = new ArrayList(); 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 allParentFolders = connectionFolderManager + .getAllParentFolders( overFolder ); + + if ( event.widget instanceof DropTarget ) { - Table table = ( Table ) dropTarget.getControl(); - TableItem[] items = table.getSelection(); - List connectionList = new ArrayList(); - 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 + } } } }