View | Details | Raw Unified | Return to bug 52116
Collapse All | Expand All

(-)src/core/org/apache/jmeter/config/gui/ArgumentsPanel.java (-1 / +65 lines)
Lines 22-29 Link Here
22
import java.awt.Color;
22
import java.awt.Color;
23
import java.awt.Component;
23
import java.awt.Component;
24
import java.awt.FlowLayout;
24
import java.awt.FlowLayout;
25
import java.awt.Toolkit;
26
import java.awt.datatransfer.Clipboard;
27
import java.awt.datatransfer.DataFlavor;
28
import java.awt.datatransfer.Transferable;
29
import java.awt.datatransfer.UnsupportedFlavorException;
25
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
31
import java.awt.event.ActionListener;
32
import java.io.IOException;
27
import java.util.Collection;
33
import java.util.Collection;
28
import java.util.Iterator;
34
import java.util.Iterator;
29
35
Lines 43-49 Link Here
43
import org.apache.jmeter.testelement.property.PropertyIterator;
49
import org.apache.jmeter.testelement.property.PropertyIterator;
44
import org.apache.jmeter.util.JMeterUtils;
50
import org.apache.jmeter.util.JMeterUtils;
45
import org.apache.jorphan.gui.ObjectTableModel;
51
import org.apache.jorphan.gui.ObjectTableModel;
52
import org.apache.jorphan.logging.LoggingManager;
46
import org.apache.jorphan.reflect.Functor;
53
import org.apache.jorphan.reflect.Functor;
54
import org.apache.log.Logger;
47
55
48
/**
56
/**
49
 * A GUI panel allowing the user to enter name-value argument pairs. These
57
 * A GUI panel allowing the user to enter name-value argument pairs. These
Lines 55-60 Link Here
55
63
56
    private static final long serialVersionUID = 240L;
64
    private static final long serialVersionUID = 240L;
57
65
66
    private static final Logger log = LoggingManager.getLoggerForClass();
67
58
    /** The title label for this component. */
68
    /** The title label for this component. */
59
    private JLabel tableLabel;
69
    private JLabel tableLabel;
60
70
Lines 67-72 Link Here
67
    /** A button for adding new arguments to the table. */
77
    /** A button for adding new arguments to the table. */
68
    private JButton add;
78
    private JButton add;
69
79
80
    /** A button for adding new arguments to the table from the clipboard. */
81
    private JButton addFromClipboard;
82
70
    /** A button for removing arguments from the table. */
83
    /** A button for removing arguments from the table. */
71
    private JButton delete;
84
    private JButton delete;
72
85
Lines 92-97 Link Here
92
    /** Command for adding a row to the table. */
105
    /** Command for adding a row to the table. */
93
    private static final String ADD = "add"; // $NON-NLS-1$
106
    private static final String ADD = "add"; // $NON-NLS-1$
94
107
108
    /** Command for adding rows from the clipboard */
109
    private static final String ADD_FROM_CLIPBOARD = "addFromClipboard"; // $NON-NLS-1$
110
95
    /** Command for removing a row from the table. */
111
    /** Command for removing a row from the table. */
96
    private static final String DELETE = "delete"; // $NON-NLS-1$
112
    private static final String DELETE = "delete"; // $NON-NLS-1$
97
113
Lines 309-314 Link Here
309
            deleteArgument();
325
            deleteArgument();
310
        } else if (action.equals(ADD)) {
326
        } else if (action.equals(ADD)) {
311
            addArgument();
327
            addArgument();
328
        } else if (action.equals(ADD_FROM_CLIPBOARD)) {
329
            addFromClipboard();
312
        } else if (action.equals(UP)) {
330
        } else if (action.equals(UP)) {
313
            moveUp();
331
            moveUp();
314
        } else if (action.equals(DOWN)) {
332
        } else if (action.equals(DOWN)) {
Lines 421-428 Link Here
421
    }
439
    }
422
440
423
    /**
441
    /**
442
     * Add values from the clipboard
443
     */
444
    protected void addFromClipboard() {
445
        stopTableEditing();
446
        int rowCount = table.getRowCount();
447
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
448
        Transferable trans = clipboard.getContents(null);
449
        try {
450
            String clipboardContent = (String) trans.getTransferData(DataFlavor.stringFlavor);
451
            String[] clipboardLines = clipboardContent.split("\n");
452
            for (String clipboardLine : clipboardLines) {
453
                String[] clipboardCols = clipboardLine.split("\t");
454
                if (clipboardCols.length > 0) {
455
                    Argument argument = makeNewArgument();
456
                    argument.setName(clipboardCols[0]);
457
                    if (clipboardCols.length > 1) {
458
                        argument.setValue(clipboardCols[1]);
459
                        if (clipboardCols.length > 2) {
460
                            argument.setDescription(clipboardCols[2]);
461
                        }
462
                    }
463
                    tableModel.addRow(argument);
464
                }
465
            }
466
        } catch (IOException ioe) {
467
            log.warn("Failed to paste arguments from clipboard.", ioe);
468
        } catch (UnsupportedFlavorException ufe) {
469
            log.warn("Failed to paste arguments from clipboard.", ufe);
470
        }
471
        if (table.getRowCount() > rowCount) {
472
            // Enable DELETE (which may already be enabled, but it won't hurt)
473
            delete.setEnabled(true);
474
475
            // Highlight (select) the appropriate rows.
476
            int rowToSelect = tableModel.getRowCount() - 1;
477
            table.setRowSelectionInterval(rowCount, rowToSelect);
478
        }
479
    }
480
481
    /**
424
     * Create a new Argument object.
482
     * Create a new Argument object.
425
     *
483
     * 
426
     * @return a new Argument object
484
     * @return a new Argument object
427
     */
485
     */
428
    protected Argument makeNewArgument() {
486
    protected Argument makeNewArgument() {
Lines 524-529 Link Here
524
        add.setActionCommand(ADD);
582
        add.setActionCommand(ADD);
525
        add.setEnabled(true);
583
        add.setEnabled(true);
526
584
585
        addFromClipboard = new JButton(JMeterUtils.getResString("add_from_clipboard")); // $NON-NLS-1$
586
        addFromClipboard.setActionCommand(ADD_FROM_CLIPBOARD);
587
        addFromClipboard.setEnabled(true);
588
527
        delete = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$
589
        delete = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$
528
        delete.setActionCommand(DELETE);
590
        delete.setActionCommand(DELETE);
529
591
Lines 542-549 Link Here
542
            buttonPanel.setBackground(this.background);
604
            buttonPanel.setBackground(this.background);
543
        }
605
        }
544
        add.addActionListener(this);
606
        add.addActionListener(this);
607
        addFromClipboard.addActionListener(this);
545
        delete.addActionListener(this);
608
        delete.addActionListener(this);
546
        buttonPanel.add(add);
609
        buttonPanel.add(add);
610
        buttonPanel.add(addFromClipboard);
547
        buttonPanel.add(delete);
611
        buttonPanel.add(delete);
548
        if(enableUpDown) {
612
        if(enableUpDown) {
549
            up.addActionListener(this);
613
            up.addActionListener(this);
(-)src/core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 22-27 Link Here
22
22
23
about=About Apache JMeter
23
about=About Apache JMeter
24
add=Add
24
add=Add
25
add_from_clipboard=Add from Clipboard
25
add_as_child=Add as Child
26
add_as_child=Add as Child
26
add_parameter=Add Variable
27
add_parameter=Add Variable
27
add_pattern=Add Pattern\:
28
add_pattern=Add Pattern\:

Return to bug 52116