directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r678715 - in /directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui: dnd/DragConnectionListener.java widgets/ConnectionActionGroup.java
Date Tue, 22 Jul 2008 11:14:03 GMT
Author: pamarcelot
Date: Tue Jul 22 04:14:03 2008
New Revision: 678715

URL: http://svn.apache.org/viewvc?rev=678715&view=rev
Log:
Fix for DIRSTUDIO-298 (NullPointerException raised when drag'n'dropping a connection to a
folder (on Mac OS X only)).

Modified:
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java

Modified: directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java?rev=678715&r1=678714&r2=678715&view=diff
==============================================================================
--- directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java
(original)
+++ directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java
Tue Jul 22 04:14:03 2008
@@ -22,15 +22,17 @@
 
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.swt.dnd.DragSource;
 import org.eclipse.swt.dnd.DragSourceEvent;
 import org.eclipse.swt.dnd.DragSourceListener;
 import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
 
 
 /**
@@ -42,22 +44,31 @@
  */
 public class DragConnectionListener implements DragSourceListener
 {
+    /** The associated viewer */
+    private TreeViewer treeViewer;
+
+    /** The selection (used for drag and drop) */
+    private StructuredSelection selection = null;
+
 
     /**
      * Creates a new instance of DragConnectionListener.
      */
-    public DragConnectionListener()
+    public DragConnectionListener( TreeViewer viewer )
     {
+        treeViewer = viewer;
     }
 
 
     /**
      * {@inheritDoc}
      * 
-     * This implementation does nothing.
+     * This implementation saves the selection.
      */
     public void dragStart( DragSourceEvent event )
     {
+        selection = ( StructuredSelection ) treeViewer.getSelection();
+        event.doit = !selection.isEmpty();
     }
 
 
@@ -76,14 +87,16 @@
                 DragSource dragSource = ( DragSource ) event.widget;
                 if ( dragSource.getControl() instanceof Tree )
                 {
-                    Tree tree = ( Tree ) dragSource.getControl();
-                    TreeItem[] items = tree.getSelection();
                     List<Object> objectList = new ArrayList<Object>();
-                    for ( int i = 0; i < items.length; i++ )
+                    if ( selection != null )
                     {
-                        if ( items[i].getData() instanceof Connection || items[i].getData()
instanceof ConnectionFolder )
+                        for ( Iterator<?> iterator = selection.iterator(); iterator.hasNext();
)
                         {
-                            objectList.add( items[i].getData() );
+                            Object item = iterator.next();
+                            if ( item instanceof Connection || item instanceof ConnectionFolder
)
+                            {
+                                objectList.add( item );
+                            }
                         }
                     }
                     event.data = objectList.toArray();
@@ -101,5 +114,4 @@
     public void dragFinished( DragSourceEvent event )
     {
     }
-
 }

Modified: directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java?rev=678715&r1=678714&r2=678715&view=diff
==============================================================================
--- directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
(original)
+++ directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
Tue Jul 22 04:14:03 2008
@@ -68,7 +68,7 @@
 
     /** The Constant newConnectionFolderAction. */
     protected static final String newConnectionFolderAction = "newConnectionFolderAction";
-    
+
     /** The Constant openConnectionAction. */
     protected static final String openConnectionAction = "openConnectionAction";
 
@@ -139,7 +139,7 @@
 
         // DND support
         dropConnectionListener = new DropConnectionListener();
-        dragConnectionListener = new DragConnectionListener();
+        dragConnectionListener = new DragConnectionListener( viewer );
         int ops = DND.DROP_COPY | DND.DROP_MOVE;
         Transfer[] transfers = new Transfer[]
             { ConnectionTransfer.getInstance() };
@@ -168,7 +168,7 @@
 
             actionBars = null;
             mainWidget = null;
-            
+
             dragConnectionListener = null;
             dropConnectionListener = null;
         }



Mime
View raw message