jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1755946 - in /jmeter/trunk: src/components/org/apache/jmeter/assertions/gui/AssertionGui.java xdocs/changes.xml
Date Thu, 11 Aug 2016 11:29:40 GMT
Author: pmouawad
Date: Thu Aug 11 11:29:40 2016
New Revision: 1755946

URL: http://svn.apache.org/viewvc?rev=1755946&view=rev
Log:
Bug 59974 - Response Assertion : Add button "Add from clipboard"
Patch by UbikLoadPack
Bugzilla Id: 59974

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java?rev=1755946&r1=1755945&r2=1755946&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java Thu Aug
11 11:29:40 2016
@@ -20,21 +20,26 @@ package org.apache.jmeter.assertions.gui
 
 import java.awt.BorderLayout;
 import java.awt.Dimension;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.io.IOException;
 
 import javax.swing.BorderFactory;
 import javax.swing.Box;
 import javax.swing.ButtonGroup;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
-import javax.swing.table.TableCellEditor;
+import javax.swing.ListSelectionModel;
 
 import org.apache.jmeter.assertions.ResponseAssertion;
+import org.apache.jmeter.gui.GuiPackage;
 import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
 import org.apache.jmeter.gui.util.PowerTableModel;
 import org.apache.jmeter.gui.util.TextAreaCellRenderer;
@@ -365,6 +370,9 @@ public class AssertionGui extends Abstra
         tableModel = new PowerTableModel(new String[] { COL_RESOURCE_NAME }, new Class[]
{ String.class });
         stringTable = new JTable(tableModel);
         stringTable.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
+        stringTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+        JMeterUtils.applyHiDPI(stringTable);
+
 
         TextAreaCellRenderer renderer = new TextAreaCellRenderer();
         stringTable.setRowHeight(renderer.getPreferredHeight());
@@ -390,6 +398,9 @@ public class AssertionGui extends Abstra
     private JPanel createButtonPanel() {
         JButton addPattern = new JButton(JMeterUtils.getResString("add")); //$NON-NLS-1$
         addPattern.addActionListener(new AddPatternListener());
+        
+        JButton addFromClipboardPattern = new JButton(JMeterUtils.getResString("add_from_clipboard"));
//$NON-NLS-1$
+        addFromClipboardPattern.addActionListener(new AddFromClipboardListener());
 
         deletePattern = new JButton(JMeterUtils.getResString("delete")); //$NON-NLS-1$
         deletePattern.addActionListener(new ClearPatternsListener());
@@ -397,6 +408,7 @@ public class AssertionGui extends Abstra
 
         JPanel buttonPanel = new JPanel();
         buttonPanel.add(addPattern);
+        buttonPanel.add(addFromClipboardPattern);
         buttonPanel.add(deletePattern);
         return buttonPanel;
     }
@@ -427,14 +439,62 @@ public class AssertionGui extends Abstra
 
     /**
      * An ActionListener for adding a pattern.
-     *
      */
     private class AddPatternListener implements ActionListener {
         @Override
         public void actionPerformed(ActionEvent e) {
+            GuiUtils.stopTableEditing(stringTable);
             tableModel.addNewRow();
+            checkButtonsStatus();
+            tableModel.fireTableDataChanged();
+        }
+    }
+    
+    /**
+     * An ActionListener for pasting from clipboard
+     */
+    private class AddFromClipboardListener implements ActionListener {
+        @Override
+        public void actionPerformed(ActionEvent e) {
             deletePattern.setEnabled(true);
+            GuiUtils.stopTableEditing(stringTable);
+            int rowCount = stringTable.getRowCount();
+            try {
+                String clipboardContent = GuiUtils.getPastedText();
+                if(clipboardContent == null) {
+                    return;
+                }
+                String[] clipboardLines = clipboardContent.split("\n");
+                for (String clipboardLine : clipboardLines) {
+                    tableModel.addRow(new Object[] { clipboardLine.trim() });
+                }
+                if (stringTable.getRowCount() > rowCount) {
+                    checkButtonsStatus();
+
+                    // Highlight (select) and scroll to the appropriate rows.
+                    int rowToSelect = tableModel.getRowCount() - 1;
+                    stringTable.setRowSelectionInterval(rowCount, rowToSelect);
+                    stringTable.scrollRectToVisible(stringTable.getCellRect(rowCount, 0,
true));
+                }
+            } catch (IOException ioe) {
+                JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(),
+                        "Could not add data from clipboard:\n" + ioe.getLocalizedMessage(),
"Error",
+                        JOptionPane.ERROR_MESSAGE);
+            } catch (UnsupportedFlavorException ufe) {
+                JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(),
+                        "Could not add retrieve " + DataFlavor.stringFlavor.getHumanPresentableName()
+                                + " from clipboard" + ufe.getLocalizedMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
+            }
             tableModel.fireTableDataChanged();
         }
     }
+    
+    protected void checkButtonsStatus() {
+        // Disable DELETE if there are no rows in the table to delete.
+        if (tableModel.getRowCount() == 0) {
+            deletePattern.setEnabled(false);
+        } else {
+            deletePattern.setEnabled(true);
+        }
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1755946&r1=1755945&r2=1755946&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Thu Aug 11 11:29:40 2016
@@ -107,6 +107,7 @@ Summary
     <li><bug>59816</bug><pr>213</pr>Allow multiple selection
and delete in HTTP Header Manager.
     Based on a patch by Benoit Wiart (b.wiart at ubik-ingenierie.com)</li>
     <li><bug>59967</bug>CSS/JQuery Extractor : Allow empty default value.
Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
+    <li><bug>59974</bug>Response Assertion : Add button "Add from clipboard".
Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
 </ul>
 
 <h3>Functions</h3>



Mime
View raw message