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

(-)src/components/org/apache/jmeter/assertions/gui/AssertionGui.java (-2 / +62 lines)
Lines 20-40 Link Here
20
20
21
import java.awt.BorderLayout;
21
import java.awt.BorderLayout;
22
import java.awt.Dimension;
22
import java.awt.Dimension;
23
import java.awt.datatransfer.DataFlavor;
24
import java.awt.datatransfer.UnsupportedFlavorException;
23
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
26
import java.awt.event.ActionListener;
27
import java.io.IOException;
25
28
26
import javax.swing.BorderFactory;
29
import javax.swing.BorderFactory;
27
import javax.swing.Box;
30
import javax.swing.Box;
28
import javax.swing.ButtonGroup;
31
import javax.swing.ButtonGroup;
29
import javax.swing.JButton;
32
import javax.swing.JButton;
30
import javax.swing.JCheckBox;
33
import javax.swing.JCheckBox;
34
import javax.swing.JOptionPane;
31
import javax.swing.JPanel;
35
import javax.swing.JPanel;
32
import javax.swing.JRadioButton;
36
import javax.swing.JRadioButton;
33
import javax.swing.JScrollPane;
37
import javax.swing.JScrollPane;
34
import javax.swing.JTable;
38
import javax.swing.JTable;
35
import javax.swing.table.TableCellEditor;
39
import javax.swing.ListSelectionModel;
36
40
37
import org.apache.jmeter.assertions.ResponseAssertion;
41
import org.apache.jmeter.assertions.ResponseAssertion;
42
import org.apache.jmeter.gui.GuiPackage;
38
import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
43
import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
39
import org.apache.jmeter.gui.util.PowerTableModel;
44
import org.apache.jmeter.gui.util.PowerTableModel;
40
import org.apache.jmeter.gui.util.TextAreaCellRenderer;
45
import org.apache.jmeter.gui.util.TextAreaCellRenderer;
Lines 365-370 Link Here
365
        tableModel = new PowerTableModel(new String[] { COL_RESOURCE_NAME }, new Class[] { String.class });
370
        tableModel = new PowerTableModel(new String[] { COL_RESOURCE_NAME }, new Class[] { String.class });
366
        stringTable = new JTable(tableModel);
371
        stringTable = new JTable(tableModel);
367
        stringTable.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
372
        stringTable.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
373
        stringTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
374
        JMeterUtils.applyHiDPI(stringTable);
375
368
376
369
        TextAreaCellRenderer renderer = new TextAreaCellRenderer();
377
        TextAreaCellRenderer renderer = new TextAreaCellRenderer();
370
        stringTable.setRowHeight(renderer.getPreferredHeight());
378
        stringTable.setRowHeight(renderer.getPreferredHeight());
Lines 390-395 Link Here
390
    private JPanel createButtonPanel() {
398
    private JPanel createButtonPanel() {
391
        JButton addPattern = new JButton(JMeterUtils.getResString("add")); //$NON-NLS-1$
399
        JButton addPattern = new JButton(JMeterUtils.getResString("add")); //$NON-NLS-1$
392
        addPattern.addActionListener(new AddPatternListener());
400
        addPattern.addActionListener(new AddPatternListener());
401
        
402
        JButton addFromClipboardPattern = new JButton(JMeterUtils.getResString("add_from_clipboard")); //$NON-NLS-1$
403
        addFromClipboardPattern.addActionListener(new AddFromClipboardListener());
393
404
394
        deletePattern = new JButton(JMeterUtils.getResString("delete")); //$NON-NLS-1$
405
        deletePattern = new JButton(JMeterUtils.getResString("delete")); //$NON-NLS-1$
395
        deletePattern.addActionListener(new ClearPatternsListener());
406
        deletePattern.addActionListener(new ClearPatternsListener());
Lines 397-402 Link Here
397
408
398
        JPanel buttonPanel = new JPanel();
409
        JPanel buttonPanel = new JPanel();
399
        buttonPanel.add(addPattern);
410
        buttonPanel.add(addPattern);
411
        buttonPanel.add(addFromClipboardPattern);
400
        buttonPanel.add(deletePattern);
412
        buttonPanel.add(deletePattern);
401
        return buttonPanel;
413
        return buttonPanel;
402
    }
414
    }
Lines 427-440 Link Here
427
439
428
    /**
440
    /**
429
     * An ActionListener for adding a pattern.
441
     * An ActionListener for adding a pattern.
430
     *
431
     */
442
     */
432
    private class AddPatternListener implements ActionListener {
443
    private class AddPatternListener implements ActionListener {
433
        @Override
444
        @Override
434
        public void actionPerformed(ActionEvent e) {
445
        public void actionPerformed(ActionEvent e) {
446
            GuiUtils.stopTableEditing(stringTable);
435
            tableModel.addNewRow();
447
            tableModel.addNewRow();
448
            checkButtonsStatus();
449
            tableModel.fireTableDataChanged();
450
        }
451
    }
452
    
453
    /**
454
     * An ActionListener for pasting from clipboard
455
     */
456
    private class AddFromClipboardListener implements ActionListener {
457
        @Override
458
        public void actionPerformed(ActionEvent e) {
436
            deletePattern.setEnabled(true);
459
            deletePattern.setEnabled(true);
460
            GuiUtils.stopTableEditing(stringTable);
461
            int rowCount = stringTable.getRowCount();
462
            try {
463
                String clipboardContent = GuiUtils.getPastedText();
464
                if(clipboardContent == null) {
465
                    return;
466
                }
467
                String[] clipboardLines = clipboardContent.split("\n");
468
                for (String clipboardLine : clipboardLines) {
469
                    tableModel.addRow(new Object[] { clipboardLine.trim() });
470
                }
471
                if (stringTable.getRowCount() > rowCount) {
472
                    checkButtonsStatus();
473
474
                    // Highlight (select) and scroll to the appropriate rows.
475
                    int rowToSelect = tableModel.getRowCount() - 1;
476
                    stringTable.setRowSelectionInterval(rowCount, rowToSelect);
477
                    stringTable.scrollRectToVisible(stringTable.getCellRect(rowCount, 0, true));
478
                }
479
            } catch (IOException ioe) {
480
                JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(),
481
                        "Could not add data from clipboard:\n" + ioe.getLocalizedMessage(), "Error",
482
                        JOptionPane.ERROR_MESSAGE);
483
            } catch (UnsupportedFlavorException ufe) {
484
                JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(),
485
                        "Could not add retrieve " + DataFlavor.stringFlavor.getHumanPresentableName()
486
                                + " from clipboard" + ufe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
487
            }
437
            tableModel.fireTableDataChanged();
488
            tableModel.fireTableDataChanged();
438
        }
489
        }
439
    }
490
    }
491
    
492
    protected void checkButtonsStatus() {
493
        // Disable DELETE if there are no rows in the table to delete.
494
        if (tableModel.getRowCount() == 0) {
495
            deletePattern.setEnabled(false);
496
        } else {
497
            deletePattern.setEnabled(true);
498
        }
499
    }
440
}
500
}

Return to bug 59974