cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r900096 - in /cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor: AbstractCallbackMethodsTab.java StringTransferHandler.java
Date Sun, 17 Jan 2010 11:06:27 GMT
Author: aadamchik
Date: Sun Jan 17 11:06:27 2010
New Revision: 900096

URL: http://svn.apache.org/viewvc?rev=900096&view=rev
Log:
replacing a file that seems to be originally lifted from Sun swing tutorial

Removed:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/StringTransferHandler.java
Modified:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java?rev=900096&r1=900095&r2=900096&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
Sun Jan 17 11:06:27 2010
@@ -21,6 +21,9 @@
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.util.ArrayList;
@@ -33,6 +36,7 @@
 import javax.swing.JPopupMenu;
 import javax.swing.JTable;
 import javax.swing.JToolBar;
+import javax.swing.TransferHandler;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
 import javax.swing.table.DefaultTableCellRenderer;
@@ -54,6 +58,8 @@
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
 import org.apache.cayenne.modeler.util.PanelFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import com.jgoodies.forms.builder.DefaultFormBuilder;
 import com.jgoodies.forms.layout.FormLayout;
@@ -65,6 +71,8 @@
  */
 public abstract class AbstractCallbackMethodsTab extends JPanel {
 
+    private static Log logger = LogFactory.getLog(AbstractCallbackMethodsTab.class);
+
     /**
      * mediator instance
      */
@@ -166,38 +174,66 @@
 
         // drag-and-drop initialization
         table.setDragEnabled(true);
-        table.setTransferHandler(new StringTransferHandler() {
+        table.setTransferHandler(new TransferHandler() {
+
 
             @Override
-            protected String exportString(JComponent c) {
-                JTable table = (JTable) c;
+            protected Transferable createTransferable(JComponent c) {
                 int rowIndex = table.getSelectedRow();
 
                 String result = null;
                 if (rowIndex >= 0 && rowIndex < table.getModel().getRowCount())
{
-                    result = String.valueOf(table.getModel().getValueAt(rowIndex, 0));
+                    result = String.valueOf(table.getModel().getValueAt(
+                            rowIndex,
+                            CallbackDescriptorTableModel.METHOD_NAME));
                 }
 
-                return result;
+                return new StringSelection(result);
             }
 
             @Override
-            protected void importString(JComponent c, String callbackMethod) {
-                JTable table = (JTable) c;
-                int rowIndex = table.getSelectedRow();
+            public int getSourceActions(JComponent c) {
+                return COPY_OR_MOVE;
+            }
+
+            @Override
+            public boolean importData(JComponent comp, Transferable t) {
+                if (canImport(comp, t.getTransferDataFlavors())) {
+                    String callbackMethod;
+                    try {
+                        callbackMethod = (String) t
+                                .getTransferData(DataFlavor.stringFlavor);
+                    }
+                    catch (Exception e) {
+                        logger.warn("Error transferring", e);
+                        return false;
+                    }
+
+                    int rowIndex = table.getSelectedRow();
 
-                // move callback method inside of model
-                CallbackDescriptor callbackDescriptor = getCallbackMap()
-                        .getCallbackDescriptor(
-                                ((CallbackType) callbackTypeCombo.getSelectedItem())
-                                        .getType());
-                mediator
-                        .setDirty(callbackDescriptor.moveMethod(callbackMethod, rowIndex));
-                rebuildTable();
+                    // move callback method inside of model
+                    CallbackDescriptor callbackDescriptor = getCallbackMap()
+                            .getCallbackDescriptor(
+                                    ((CallbackType) callbackTypeCombo.getSelectedItem())
+                                            .getType());
+                    mediator.setDirty(callbackDescriptor.moveMethod(
+                            callbackMethod,
+                            rowIndex));
+                    rebuildTable();
+                    return true;
+                }
+
+                return false;
             }
 
             @Override
-            protected void cleanup(JComponent c, boolean remove) {
+            public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
+                for (DataFlavor flavor : transferFlavors) {
+                    if (DataFlavor.stringFlavor.equals(flavor)) {
+                        return true;
+                    }
+                }
+                return false;
             }
         });
 
@@ -263,20 +299,21 @@
             public void valueChanged(ListSelectionEvent e) {
                 if (!e.getValueIsAdjusting()) {
                     String[] methods = new String[0];
-                    
+
                     if (table.getSelectedRow() != -1) {
                         int[] sel = table.getSelectedRows();
                         methods = new String[sel.length];
-                        
+
                         for (int i = 0; i < sel.length; i++) {
                             methods[i] = (String) table.getValueAt(sel[i], 0);
                         }
                     }
-                        
+
                     mediator.setCurrentCallbackMethods(methods);
                     getRemoveCallbackMethodAction().setEnabled(methods.length > 0);
-                    getRemoveCallbackMethodAction().setName(getRemoveCallbackMethodAction().
-                            getActionName(methods.length > 1));
+                    getRemoveCallbackMethodAction().setName(
+                            getRemoveCallbackMethodAction().getActionName(
+                                    methods.length > 1));
                 }
             }
         });



Mime
View raw message