jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1413259 - in /jmeter/trunk: src/components/org/apache/jmeter/control/ModuleController.java src/core/org/apache/jmeter/gui/action/Copy.java src/core/org/apache/jmeter/util/JMeterTreeNodeTransferable.java xdocs/changes.xml
Date Sat, 24 Nov 2012 20:34:42 GMT
Author: pmouawad
Date: Sat Nov 24 20:34:40 2012
New Revision: 1413259

URL: http://svn.apache.org/viewvc?rev=1413259&view=rev
Log:
Bug 46677 - Copying Test Elements between test plans
Bugzilla Id: 46677

Added:
    jmeter/trunk/src/core/org/apache/jmeter/util/JMeterTreeNodeTransferable.java   (with props)
Modified:
    jmeter/trunk/src/components/org/apache/jmeter/control/ModuleController.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/Copy.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/control/ModuleController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/control/ModuleController.java?rev=1413259&r1=1413258&r2=1413259&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/control/ModuleController.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/control/ModuleController.java Sat Nov 24
20:34:40 2012
@@ -52,7 +52,7 @@ public class ModuleController extends Ge
 
     private static final String NODE_PATH = "ModuleController.node_path";// $NON-NLS-1$
 
-    private JMeterTreeNode selectedNode = null;
+    private transient JMeterTreeNode selectedNode = null;
 
     /**
      * No-arg constructor

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/Copy.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/Copy.java?rev=1413259&r1=1413258&r2=1413259&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/Copy.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/Copy.java Sat Nov 24 20:34:40 2012
@@ -15,32 +15,29 @@
  * limitations under the License.
  *
  */
-
-/*
- * Created on Apr 9, 2003
- *
- * Clones a JMeterTreeNode
- */
 package org.apache.jmeter.gui.action;
 
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
 import java.awt.event.ActionEvent;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.swing.JOptionPane;
+
 import org.apache.jmeter.gui.GuiPackage;
 import org.apache.jmeter.gui.tree.JMeterTreeListener;
 import org.apache.jmeter.gui.tree.JMeterTreeNode;
 import org.apache.jmeter.testelement.TestElement;
+import org.apache.jmeter.util.JMeterTreeNodeTransferable;
+import org.apache.jmeter.util.JMeterUtils;
 
 /**
  * Implements the Copy menu command
  */
 public class Copy extends AbstractAction {
-    private static JMeterTreeNode copiedNode = null;
-
-    private static JMeterTreeNode copiedNodes[] = null;
-
+    
     private static final HashSet<String> commands = new HashSet<String>();
 
     static {
@@ -59,30 +56,20 @@ public class Copy extends AbstractAction
     public void doAction(ActionEvent e) {
         JMeterTreeListener treeListener = GuiPackage.getInstance().getTreeListener();
         JMeterTreeNode[] nodes = treeListener.getSelectedNodes();
+        nodes = cloneTreeNodes(nodes);
         setCopiedNodes(nodes);
     }
 
     public static JMeterTreeNode[] getCopiedNodes() {
-        if (copiedNodes == null) { // can be null if Copy has yet to be used
-            return null;
-        }
-        for (int i = 0; i < copiedNodes.length; i++) {
-            if (copiedNodes[i] == null) {
-                return null;
+        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+        if (clipboard.isDataFlavorAvailable(JMeterTreeNodeTransferable.JMETER_TREE_NODE_ARRAY_DATA_FLAVOR))
{
+            try {
+                return (JMeterTreeNode[]) clipboard.getData(JMeterTreeNodeTransferable.JMETER_TREE_NODE_ARRAY_DATA_FLAVOR);
+            } catch (Exception ex) {
+                JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("clipboard_node_read_error")+":\n"
+ ex.getLocalizedMessage(), JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
             }
         }
-        return cloneTreeNodes(copiedNodes);
-    }
-
-    public static JMeterTreeNode getCopiedNode() {
-        if (copiedNode == null) {
-            return null;
-        }
-        return cloneTreeNode(copiedNode);
-    }
-
-    public static void setCopiedNode(JMeterTreeNode node) {
-        copiedNode = cloneTreeNode(node);
+        return null;
     }
 
     public static JMeterTreeNode cloneTreeNode(JMeterTreeNode node) {
@@ -93,9 +80,13 @@ public class Copy extends AbstractAction
     }
 
     public static void setCopiedNodes(JMeterTreeNode nodes[]) {
-        copiedNodes = new JMeterTreeNode[nodes.length];
-        for (int i = 0; i < nodes.length; i++) {
-            copiedNodes[i] = cloneTreeNode(nodes[i]);
+        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+        try {
+            JMeterTreeNodeTransferable transferable = new JMeterTreeNodeTransferable();
+            transferable.setTransferData(nodes);
+            clipboard.setContents(transferable, null);
+        } catch (Exception ex) {
+            JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("clipboard_node_read_error")+":\n"
+ ex.getLocalizedMessage(), JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
         }
     }
 

Added: jmeter/trunk/src/core/org/apache/jmeter/util/JMeterTreeNodeTransferable.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterTreeNodeTransferable.java?rev=1413259&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/JMeterTreeNodeTransferable.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/JMeterTreeNodeTransferable.java Sat Nov 24
20:34:40 2012
@@ -0,0 +1,97 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.jmeter.util;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+
+/**
+ * Simple implementation of a transferable for {@link JMeterTreeNode} arrays based on serialization.
+ * @since 2.9
+ */
+public class JMeterTreeNodeTransferable implements Transferable {
+    
+    public final static DataFlavor JMETER_TREE_NODE_ARRAY_DATA_FLAVOR = new DataFlavor(JMeterTreeNode[].class,
JMeterTreeNode[].class.getName());
+    
+    private final static DataFlavor[] DATA_FLAVORS = new DataFlavor[]{JMETER_TREE_NODE_ARRAY_DATA_FLAVOR};
+    
+    private byte[] data = null;
+
+    @Override
+    public DataFlavor[] getTransferDataFlavors() {
+        return DATA_FLAVORS;
+    }
+
+    @Override
+    public boolean isDataFlavorSupported(DataFlavor flavor) {
+        return flavor.match(JMETER_TREE_NODE_ARRAY_DATA_FLAVOR);
+    }
+
+    @Override
+    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
{
+        if(!isDataFlavorSupported(flavor)) {
+            throw new UnsupportedFlavorException(flavor);
+        }
+        if(data != null) {
+            ObjectInput ois = null;
+            try {
+                ois = new ObjectInputStream(new ByteArrayInputStream(data));
+                JMeterTreeNode[] nodes = (JMeterTreeNode[]) ois.readObject();
+                return nodes;
+            } catch (ClassNotFoundException cnfe) {
+                throw new IOException("Failed to read object stream.", cnfe);
+            } finally {
+                if(ois != null) {
+                    try {
+                        ois.close();
+                    } catch (Exception e) {
+                        // NOOP
+                    }
+                }
+            }
+        }
+        return null;
+    }
+    
+    public void setTransferData(JMeterTreeNode[] nodes) throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = null;
+        try {
+            oos = new ObjectOutputStream(bos);
+            oos.writeObject(nodes);
+            data = bos.toByteArray();
+        } finally {
+            if(oos != null) {
+                try {
+                    oos.close();
+                } catch (Exception e) {
+                    // NOOP
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: jmeter/trunk/src/core/org/apache/jmeter/util/JMeterTreeNodeTransferable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1413259&r1=1413258&r2=1413259&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Nov 24 20:34:40 2012
@@ -205,6 +205,7 @@ to the elements View Results Tree, Asser
 <li><bugzilla>54161</bugzilla> - Proxy : be able to create binary sampler
for x-www-form-urlencoded POST request</li>
 <li><bugzilla>54154</bugzilla> - HTTP Proxy Server should not force user
to select the type of Sampler in HTTP Sampler Settings</li>
 <li><bugzilla>54165</bugzilla> - Proxy Server: Improve rendering of target
controller</li>
+<li><bugzilla>46677</bugzilla> - Copying Test Elements between test plans</li>
 </ul>
 
 <h2>Non-functional changes</h2>



Mime
View raw message