KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > dnd > listeners > ControllerTransferListener


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.dnd.listeners;
26
27 import java.awt.datatransfer.DataFlavor JavaDoc;
28 import java.awt.datatransfer.Transferable JavaDoc;
29 import java.awt.dnd.DnDConstants JavaDoc;
30 import java.awt.dnd.DropTarget JavaDoc;
31 import java.awt.dnd.DropTargetDropEvent JavaDoc;
32
33 import javax.swing.JButton JavaDoc;
34
35 import org.objectweb.cjdbc.console.gui.CjdbcGui;
36
37 /**
38  * This class defines a ControllerTransferListener.
39  * Listens for DnD on configuration files and on transfered backends from the backend panel
40  *
41  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk</a>
42  * @version 1.0
43  */

44 public class ControllerTransferListener extends AbstractGuiDropListener
45 {
46   
47   /**
48    *
49    * Creates a new <code>ControllerTransferListener</code> object
50    *
51    * @param gui link to the main gui
52    */

53   public ControllerTransferListener(CjdbcGui gui)
54   {
55     super(gui);
56   }
57   
58   
59   /**
60    * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
61    */

62   public void drop(DropTargetDropEvent JavaDoc dtde)
63   {
64     dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
65     DropTarget JavaDoc target = ((DropTarget JavaDoc) dtde.getSource());
66     Transferable JavaDoc transfer = dtde.getTransferable();
67     
68     JButton JavaDoc bo = (JButton JavaDoc) target.getComponent();
69     try
70     {
71       // This is the flavor for backends
72
Object JavaDoc data = transfer.getTransferData(DataFlavor.plainTextFlavor);
73       if(data==null)
74       {
75         // We have to transfer a configuration file
76
data = transfer.getTransferData(DataFlavor.stringFlavor);
77         gui.publicActionExecuteControllerDrop(data.toString(), bo.getText());
78       }
79       else
80       {
81         // we transfer a backend from one controller to another one
82
gui.publicActionExecuteTransfer(data.toString(),bo.getText());
83       }
84       dtde.dropComplete(true);
85     }
86     catch (Exception JavaDoc e)
87     {
88       dtde.dropComplete(true);
89       gui.appendDebugText("Failed to execute Drag and drop for targer:"
90           + bo.getText());
91     }
92     finally
93     {
94       dtde.dropComplete(true);
95       gui.publicActionRefreshCursorShape();
96     }
97   }
98 }
99
Popular Tags