directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r581723 - in /directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions: CopyAction.java PasteAction.java
Date Wed, 03 Oct 2007 20:59:25 GMT
Author: seelmann
Date: Wed Oct  3 13:59:24 2007
New Revision: 581723

URL: http://svn.apache.org/viewvc?rev=581723&view=rev
Log:
DIRSTUDIO-187: copy/paste for connection folders

Modified:
    directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
    directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java

Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java?rev=581723&r1=581722&r2=581723&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
(original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
Wed Oct  3 13:59:24 2007
@@ -21,7 +21,12 @@
 package org.apache.directory.studio.connection.ui.actions;
 
 
+import java.util.ArrayList;
+import java.util.Arrays;
+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.jface.resource.ImageDescriptor;
 import org.eclipse.swt.dnd.Clipboard;
@@ -61,15 +66,20 @@
      */
     public String getText()
     {
-
-        // connection
-        Connection[] connections = getConnections();
-        if ( connections != null )
+        Connection[] connections = getSelectedConnections();
+        ConnectionFolder[] connectionFolders = getSelectedConnectionFolders();
+        if ( connections.length > 0 && connectionFolders.length == 0 )
         {
             return connections.length > 1 ? "Copy Connections" : "Copy Connection";
         }
-
-        return "Copy";
+        else if ( connectionFolders.length > 0 && connections.length == 0 )
+        {
+            return connectionFolders.length > 1 ? "Copy Connection Folders" : "Copy Connection
Folder";
+        }
+        else
+        {
+            return "Copy";
+        }
     }
 
 
@@ -96,13 +106,17 @@
      */
     public void run()
     {
-        Connection[] connections = getConnections();
+        Connection[] connections = getSelectedConnections();
+        ConnectionFolder[] connectionFolders = getSelectedConnectionFolders();
+        List<Object> objects = new ArrayList<Object>();
+        objects.addAll( Arrays.asList( connections ) );
+        objects.addAll( Arrays.asList( connectionFolders ) );
 
         // connection
-        if ( connections != null )
+        if ( objects != null )
         {
             copyToClipboard( new Object[]
-                { connections }, new Transfer[]
+                { objects.toArray() }, new Transfer[]
                 { ConnectionTransfer.getInstance() } );
         }
 
@@ -144,37 +158,7 @@
      */
     public boolean isEnabled()
     {
-
-        // connection
-        if ( getConnections() != null )
-        {
-            return true;
-        }
-
-        else
-        {
-            return false;
-        }
-    }
-
-
-    /**
-     * Get the Connections
-     *
-     * @return
-     *      the Connections
-     */
-    private Connection[] getConnections()
-    {
-
-        if ( getSelectedConnections().length > 0 )
-        {
-            return getSelectedConnections();
-        }
-        else
-        {
-            return null;
-        }
+        return getSelectedConnections().length + getSelectedConnectionFolders().length >
0;
     }
 
 }

Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java?rev=581723&r1=581722&r2=581723&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
(original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
Wed Oct  3 13:59:24 2007
@@ -21,9 +21,14 @@
 package org.apache.directory.studio.connection.ui.actions;
 
 
+import java.util.ArrayList;
+import java.util.List;
+
 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.jface.resource.ImageDescriptor;
 import org.eclipse.swt.dnd.Clipboard;
@@ -56,14 +61,20 @@
      */
     public String getText()
     {
-        // connection
-        Connection[] connections = getConnectionsToPaste();
-        if ( connections != null )
+        List<Connection> connections = getConnectionsToPaste();
+        List<ConnectionFolder> connectionFolders = getConnectionFoldersToPaste();
+        if ( connections.size() > 0 && connectionFolders.size() == 0 )
         {
-            return connections.length > 1 ? "Paste Connections" : "Paste Connection";
+            return connections.size() > 1 ? "Paste Connections" : "Paste Connection";
+        }
+        else if ( connectionFolders.size() > 0 && connections.size() == 0 )
+        {
+            return connectionFolders.size() > 1 ? "Paste Connection Folders" : "Paste
Connection Folder";
+        }
+        else
+        {
+            return "Paste";
         }
-
-        return "Paste";
     }
 
 
@@ -90,60 +101,104 @@
      */
     public boolean isEnabled()
     {
-        // connection
-        if ( getConnectionsToPaste() != null )
+        return this.getFromClipboard( ConnectionTransfer.getInstance() ) != null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault()
+            .getConnectionFolderManager();
+        ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+
+        ConnectionFolder[] selectedFolders = getSelectedConnectionFolders();
+        Connection[] selectedConnections = getSelectedConnections();
+        ConnectionFolder targetFolder = null;
+        if ( selectedFolders.length > 0 )
+        {
+            targetFolder = selectedFolders[0];
+        }
+        else if ( selectedConnections.length > 0 )
+        {
+            targetFolder = connectionFolderManager.getParentConnectionFolder( selectedConnections[0]
);
+        }
+        if ( targetFolder == null )
+        {
+            targetFolder = connectionFolderManager.getRootConnectionFolder();
+        }
+
+        // connections
+        List<Connection> connections = getConnectionsToPaste();
+        for ( Connection connection : connections )
         {
-            return true;
+            Connection newConnection = ( Connection ) connection.clone();
+            connectionManager.addConnection( newConnection );
+            targetFolder.addConnectionId( newConnection.getId() );
         }
 
-        return false;
+        // connection folders
+        List<ConnectionFolder> connectionFolders = getConnectionFoldersToPaste();
+        for ( ConnectionFolder connectionFolder : connectionFolders )
+        {
+            ConnectionFolder newConnectionFolder = ( ConnectionFolder ) connectionFolder.clone();
+            connectionFolderManager.addConnectionFolder( newConnectionFolder );
+            targetFolder.addSubFolderId( newConnectionFolder.getId() );
+        }
     }
 
 
     /**
-     * {@inheritDoc}
+     * Condition: there are connections in clipboard
+     * 
+     * @return the connections to paste
      */
-    public void run()
+    private List<Connection> getConnectionsToPaste()
     {
-        // connection
-        Connection[] connections = getConnectionsToPaste();
-        if ( connections != null )
+        List<Connection> connections = new ArrayList<Connection>();
+
+        Object content = this.getFromClipboard( ConnectionTransfer.getInstance() );
+        if ( content != null && content instanceof Object[] )
         {
-            for ( int i = 0; i < connections.length; i++ )
+            Object[] objects = ( Object[] ) content;
+            for ( Object object : objects )
             {
-                Connection newConnection = ( Connection ) connections[i].clone();
-                ConnectionCorePlugin.getDefault().getConnectionManager().addConnection( newConnection
);
-                ConnectionFolder[] folders = getSelectedConnectionFolders();
-                if(folders != null && folders.length > 0)
+                if ( object instanceof Connection )
                 {
-                    folders[0].addConnectionId( newConnection.getId() );
-                }
-                else
-                {
-                    ConnectionCorePlugin.getDefault().getConnectionFolderManager().getRootConnectionFolder()
-                        .addConnectionId( newConnection.getId() );
+                    connections.add( ( Connection ) object );
                 }
             }
-            return;
         }
+
+        return connections;
     }
 
 
     /**
-     * Condition: there are connections in clipboard
+     * Condition: there are connection folders in clipboard
      * 
-     * @return the connections to paste
+     * @return the connection folders to paste
      */
-    private Connection[] getConnectionsToPaste()
+    private List<ConnectionFolder> getConnectionFoldersToPaste()
     {
+        List<ConnectionFolder> folders = new ArrayList<ConnectionFolder>();
+
         Object content = this.getFromClipboard( ConnectionTransfer.getInstance() );
-        if ( content != null && content instanceof Connection[] )
+        if ( content != null && content instanceof Object[] )
         {
-            Connection[] connections = ( Connection[] ) content;
-            return connections;
+            Object[] objects = ( Object[] ) content;
+            for ( Object object : objects )
+            {
+                if ( object instanceof ConnectionFolder )
+                {
+                    folders.add( ( ConnectionFolder ) object );
+                }
+            }
         }
 
-        return null;
+        return folders;
     }
 
 



Mime
View raw message