public static void setCopiedNodes(JMeterTreeNode[] nodes) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); try { JMeterTreeNodeTransferable transferable = new JMeterTreeNodeTransferable(); transferable.setTransferData(nodes); clipboard.setContents(transferable, null); } catch (Exception ex) { log.error("Clipboard node read error: {}", ex.getMessage(), ex); JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("clipboard_node_read_error")+":\n" + ex.getLocalizedMessage(), //$NON-NLS-1$ //$NON-NLS-2$ JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ } }
@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; }