Lines 22-36
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; |
33 |
import java.util.ArrayList; |
27 |
import java.util.Collection; |
34 |
import java.util.Collection; |
|
|
35 |
import java.util.Collections; |
28 |
import java.util.Iterator; |
36 |
import java.util.Iterator; |
29 |
|
37 |
|
30 |
import javax.swing.BorderFactory; |
38 |
import javax.swing.BorderFactory; |
31 |
import javax.swing.Box; |
39 |
import javax.swing.Box; |
32 |
import javax.swing.JButton; |
40 |
import javax.swing.JButton; |
33 |
import javax.swing.JLabel; |
41 |
import javax.swing.JLabel; |
|
|
42 |
import javax.swing.JOptionPane; |
34 |
import javax.swing.JPanel; |
43 |
import javax.swing.JPanel; |
35 |
import javax.swing.JTable; |
44 |
import javax.swing.JTable; |
36 |
import javax.swing.ListSelectionModel; |
45 |
import javax.swing.ListSelectionModel; |
Lines 43-49
Link Here
|
43 |
import org.apache.jmeter.testelement.property.PropertyIterator; |
52 |
import org.apache.jmeter.testelement.property.PropertyIterator; |
44 |
import org.apache.jmeter.util.JMeterUtils; |
53 |
import org.apache.jmeter.util.JMeterUtils; |
45 |
import org.apache.jorphan.gui.ObjectTableModel; |
54 |
import org.apache.jorphan.gui.ObjectTableModel; |
|
|
55 |
import org.apache.jorphan.logging.LoggingManager; |
46 |
import org.apache.jorphan.reflect.Functor; |
56 |
import org.apache.jorphan.reflect.Functor; |
|
|
57 |
import org.apache.log.Logger; |
47 |
|
58 |
|
48 |
/** |
59 |
/** |
49 |
* A GUI panel allowing the user to enter name-value argument pairs. These |
60 |
* A GUI panel allowing the user to enter name-value argument pairs. These |
Lines 55-60
Link Here
|
55 |
|
66 |
|
56 |
private static final long serialVersionUID = 240L; |
67 |
private static final long serialVersionUID = 240L; |
57 |
|
68 |
|
|
|
69 |
private static final Logger log = LoggingManager.getLoggerForClass(); |
70 |
|
58 |
/** The title label for this component. */ |
71 |
/** The title label for this component. */ |
59 |
private JLabel tableLabel; |
72 |
private JLabel tableLabel; |
60 |
|
73 |
|
Lines 67-72
Link Here
|
67 |
/** A button for adding new arguments to the table. */ |
80 |
/** A button for adding new arguments to the table. */ |
68 |
private JButton add; |
81 |
private JButton add; |
69 |
|
82 |
|
|
|
83 |
/** A button for adding new arguments to the table from the clipboard. */ |
84 |
private JButton addFromClipboard; |
85 |
|
70 |
/** A button for removing arguments from the table. */ |
86 |
/** A button for removing arguments from the table. */ |
71 |
private JButton delete; |
87 |
private JButton delete; |
72 |
|
88 |
|
Lines 92-97
Link Here
|
92 |
/** Command for adding a row to the table. */ |
108 |
/** Command for adding a row to the table. */ |
93 |
private static final String ADD = "add"; // $NON-NLS-1$ |
109 |
private static final String ADD = "add"; // $NON-NLS-1$ |
94 |
|
110 |
|
|
|
111 |
/** Command for adding rows from the clipboard */ |
112 |
private static final String ADD_FROM_CLIPBOARD = "addFromClipboard"; // $NON-NLS-1$ |
113 |
|
95 |
/** Command for removing a row from the table. */ |
114 |
/** Command for removing a row from the table. */ |
96 |
private static final String DELETE = "delete"; // $NON-NLS-1$ |
115 |
private static final String DELETE = "delete"; // $NON-NLS-1$ |
97 |
|
116 |
|
Lines 309-314
Link Here
|
309 |
deleteArgument(); |
328 |
deleteArgument(); |
310 |
} else if (action.equals(ADD)) { |
329 |
} else if (action.equals(ADD)) { |
311 |
addArgument(); |
330 |
addArgument(); |
|
|
331 |
} else if (action.equals(ADD_FROM_CLIPBOARD)) { |
332 |
addFromClipboard(); |
312 |
} else if (action.equals(UP)) { |
333 |
} else if (action.equals(UP)) { |
313 |
moveUp(); |
334 |
moveUp(); |
314 |
} else if (action.equals(DOWN)) { |
335 |
} else if (action.equals(DOWN)) { |
Lines 421-428
Link Here
|
421 |
} |
442 |
} |
422 |
|
443 |
|
423 |
/** |
444 |
/** |
|
|
445 |
* Add values from the clipboard |
446 |
*/ |
447 |
protected void addFromClipboard() { |
448 |
stopTableEditing(); |
449 |
int rowCount = table.getRowCount(); |
450 |
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); |
451 |
Transferable trans = clipboard.getContents(null); |
452 |
DataFlavor[] flavourList = trans.getTransferDataFlavors(); |
453 |
Collection<DataFlavor> flavours = new ArrayList<DataFlavor>(flavourList.length); |
454 |
if (Collections.addAll(flavours, flavourList) && flavours.contains(DataFlavor.stringFlavor)) { |
455 |
try { |
456 |
String clipboardContent = (String) trans.getTransferData(DataFlavor.stringFlavor); |
457 |
String[] clipboardLines = clipboardContent.split("\n"); |
458 |
for (String clipboardLine : clipboardLines) { |
459 |
String[] clipboardCols = clipboardLine.split("\t"); |
460 |
if (clipboardCols.length > 0) { |
461 |
Argument argument = makeNewArgument(); |
462 |
argument.setName(clipboardCols[0]); |
463 |
if (clipboardCols.length > 1) { |
464 |
argument.setValue(clipboardCols[1]); |
465 |
if (clipboardCols.length > 2) { |
466 |
argument.setDescription(clipboardCols[2]); |
467 |
} |
468 |
} |
469 |
tableModel.addRow(argument); |
470 |
} |
471 |
} |
472 |
} catch (IOException ioe) { |
473 |
JOptionPane.showMessageDialog(this, |
474 |
"Could not add read arguments from clipboard:\n" + ioe.getLocalizedMessage(), "Error", |
475 |
JOptionPane.ERROR_MESSAGE); |
476 |
log.warn("Failed to add arguments from clipboard.", ioe); |
477 |
} catch (UnsupportedFlavorException ufe) { |
478 |
JOptionPane.showMessageDialog(this, |
479 |
"Could not add retrieve " + DataFlavor.stringFlavor.getHumanPresentableName() |
480 |
+ " from clipboard" + ufe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
481 |
log.warn("Failed to paste arguments from clipboard.", ufe); |
482 |
} |
483 |
if (table.getRowCount() > rowCount) { |
484 |
// Enable DELETE (which may already be enabled, but it won't hurt) |
485 |
delete.setEnabled(true); |
486 |
|
487 |
// Highlight (select) the appropriate rows. |
488 |
int rowToSelect = tableModel.getRowCount() - 1; |
489 |
table.setRowSelectionInterval(rowCount, rowToSelect); |
490 |
} |
491 |
} |
492 |
} |
493 |
|
494 |
/** |
424 |
* Create a new Argument object. |
495 |
* Create a new Argument object. |
425 |
* |
496 |
* |
426 |
* @return a new Argument object |
497 |
* @return a new Argument object |
427 |
*/ |
498 |
*/ |
428 |
protected Argument makeNewArgument() { |
499 |
protected Argument makeNewArgument() { |
Lines 524-529
Link Here
|
524 |
add.setActionCommand(ADD); |
595 |
add.setActionCommand(ADD); |
525 |
add.setEnabled(true); |
596 |
add.setEnabled(true); |
526 |
|
597 |
|
|
|
598 |
addFromClipboard = new JButton(JMeterUtils.getResString("add_from_clipboard")); // $NON-NLS-1$ |
599 |
addFromClipboard.setActionCommand(ADD_FROM_CLIPBOARD); |
600 |
addFromClipboard.setEnabled(true); |
601 |
|
527 |
delete = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$ |
602 |
delete = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$ |
528 |
delete.setActionCommand(DELETE); |
603 |
delete.setActionCommand(DELETE); |
529 |
|
604 |
|
Lines 542-549
Link Here
|
542 |
buttonPanel.setBackground(this.background); |
617 |
buttonPanel.setBackground(this.background); |
543 |
} |
618 |
} |
544 |
add.addActionListener(this); |
619 |
add.addActionListener(this); |
|
|
620 |
addFromClipboard.addActionListener(this); |
545 |
delete.addActionListener(this); |
621 |
delete.addActionListener(this); |
546 |
buttonPanel.add(add); |
622 |
buttonPanel.add(add); |
|
|
623 |
buttonPanel.add(addFromClipboard); |
547 |
buttonPanel.add(delete); |
624 |
buttonPanel.add(delete); |
548 |
if(enableUpDown) { |
625 |
if(enableUpDown) { |
549 |
up.addActionListener(this); |
626 |
up.addActionListener(this); |