jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1752722 - in /jmeter/trunk: src/jorphan/org/apache/jorphan/gui/GuiUtils.java src/protocol/http/org/apache/jmeter/protocol/http/gui/HeaderPanel.java xdocs/changes.xml
Date Thu, 14 Jul 2016 18:44:55 GMT
Author: fschumacher
Date: Thu Jul 14 18:44:54 2016
New Revision: 1752722

URL: http://svn.apache.org/viewvc?rev=1752722&view=rev
Log:
Allow multiple selection and delete in HTTP Header Manager.
Based on a patch by Benoit Wiart (b.wiart at ubik-ingenierie.com)

Bugzilla Id: 59816
This closes #213 on github

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/gui/GuiUtils.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/HeaderPanel.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/gui/GuiUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/gui/GuiUtils.java?rev=1752722&r1=1752721&r2=1752722&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/gui/GuiUtils.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/gui/GuiUtils.java Thu Jul 14 18:44:54 2016
@@ -111,6 +111,20 @@ public final class GuiUtils {
             cellEditor.stopCellEditing();
         }
     }
+
+    /**
+     * cancel any editing that is currently being done on the table.
+     *
+     * @param table the table to cancel on editing
+     * @since 3.1
+     */
+    public static void cancelEditing(JTable table) {
+        // If a table cell is being edited, we must cancel the editing
+        if (table != null && table.isEditing()) {
+            TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), table.getEditingColumn());
+            cellEditor.cancelCellEditing();
+        }
+    }
     
     /**
      * Get pasted text from clipboard

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/HeaderPanel.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/HeaderPanel.java?rev=1752722&r1=1752721&r2=1752722&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/HeaderPanel.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/HeaderPanel.java Thu
Jul 14 18:44:54 2016
@@ -35,7 +35,6 @@ import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.ListSelectionModel;
 import javax.swing.table.AbstractTableModel;
-import javax.swing.table.TableCellEditor;
 
 import org.apache.jmeter.config.gui.AbstractConfigGui;
 import org.apache.jmeter.gui.util.FileDialoger;
@@ -125,7 +124,6 @@ public class HeaderPanel extends Abstrac
         boolean hasRows = tableModel.getRowCount() > 0;
         deleteButton.setEnabled(hasRows);
         saveButton.setEnabled(hasRows);
-
     }
 
     @Override
@@ -141,46 +139,52 @@ public class HeaderPanel extends Abstrac
         add(createHeaderTablePanel(), BorderLayout.CENTER);
     }
 
-    @Override
-    public void actionPerformed(ActionEvent e) {
-        String action = e.getActionCommand();
+    private void checkButtonsStatus() {
+        if (tableModel.getRowCount() == 0) {
+            deleteButton.setEnabled(false);
+            saveButton.setEnabled(false);
+        } else {
+            deleteButton.setEnabled(true);
+            saveButton.setEnabled(true);
+        }
+    }
 
-        if (action.equals(DELETE_COMMAND)) {
+    /**
+     * Remove the currently selected rows from the table.
+     */
+    protected void deleteRows() {
+        // If a table cell is being edited, we must cancel the editing
+        // before deleting the row.
+        GuiUtils.cancelEditing(headerTable);
+
+        int[] rowsSelected = headerTable.getSelectedRows();
+        int anchorSelection = headerTable.getSelectionModel().getAnchorSelectionIndex();
+        headerTable.clearSelection();
+        if (rowsSelected.length > 0) {
+            for (int i = rowsSelected.length - 1; i >= 0; i--) {
+                tableModel.removeRow(rowsSelected[i]);
+            }
+            tableModel.fireTableDataChanged();
+
+            // Table still contains one or more rows, so highlight (select)
+            // the appropriate one.
             if (tableModel.getRowCount() > 0) {
-                // If a table cell is being edited, we must cancel the editing
-                // before deleting the row.
-                if (headerTable.isEditing()) {
-                    TableCellEditor cellEditor = headerTable.getCellEditor(headerTable.getEditingRow(),
-                            headerTable.getEditingColumn());
-                    cellEditor.cancelCellEditing();
+                if (anchorSelection >= tableModel.getRowCount()) {
+                    anchorSelection = tableModel.getRowCount() - 1;
                 }
+                headerTable.setRowSelectionInterval(anchorSelection, anchorSelection);
+            }
 
-                int rowSelected = headerTable.getSelectedRow();
-
-                if (rowSelected != -1) {
-                    tableModel.removeRow(rowSelected);
-                    tableModel.fireTableDataChanged();
+            checkButtonsStatus();
+        }
+    }
 
-                    // Disable the DELETE and SAVE buttons if no rows remaining
-                    // after delete
-                    if (tableModel.getRowCount() == 0) {
-                        deleteButton.setEnabled(false);
-                        saveButton.setEnabled(false);
-                    }
-
-                    // Table still contains one or more rows, so highlight
-                    // (select) the appropriate one.
-                    else {
-                        int rowToSelect = rowSelected;
-
-                        if (rowSelected >= tableModel.getRowCount()) {
-                            rowToSelect = rowSelected - 1;
-                        }
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        String action = e.getActionCommand();
 
-                        headerTable.setRowSelectionInterval(rowToSelect, rowToSelect);
-                    }
-                }
-            }
+        if (action.equals(DELETE_COMMAND)) {
+            deleteRows();
         } else if (action.equals(ADD_COMMAND)) {
             // If a table cell is being edited, we should accept the current
             // value and stop the editing before adding a new row.
@@ -189,14 +193,8 @@ public class HeaderPanel extends Abstrac
             tableModel.addNewRow();
             tableModel.fireTableDataChanged();
 
-            // Enable the DELETE and SAVE buttons if they are currently
-            // disabled.
-            if (!deleteButton.isEnabled()) {
-                deleteButton.setEnabled(true);
-            }
-            if (!saveButton.isEnabled()) {
-                saveButton.setEnabled(true);
-            }
+            // Enable the DELETE and SAVE buttons if they are currently disabled.
+            checkButtonsStatus();
 
             // Highlight (select) the appropriate row.
             int rowToSelect = tableModel.getRowCount() - 1;
@@ -208,10 +206,7 @@ public class HeaderPanel extends Abstrac
                     headerManager.addFile(chooser.getSelectedFile().getAbsolutePath());
                     tableModel.fireTableDataChanged();
 
-                    if (tableModel.getRowCount() > 0) {
-                        deleteButton.setEnabled(true);
-                        saveButton.setEnabled(true);
-                    }
+                    checkButtonsStatus();
                 }
             } catch (IOException ex) {
                 log.error("Could not load headers", ex);
@@ -258,13 +253,12 @@ public class HeaderPanel extends Abstrac
             }
             tableModel.fireTableDataChanged();
             if (headerTable.getRowCount() > rowCount) {
-                deleteButton.setEnabled(true);
-                saveButton.setEnabled(true);
-
                 // Highlight (select) the appropriate rows.
                 int rowToSelect = tableModel.getRowCount() - 1;
                 headerTable.setRowSelectionInterval(rowCount, rowToSelect);
             }
+
+            checkButtonsStatus();
         } catch (IOException ioe) {
             JOptionPane.showMessageDialog(this,
                     "Could not add read headers from clipboard:\n" + ioe.getLocalizedMessage(),
"Error",
@@ -275,13 +269,13 @@ public class HeaderPanel extends Abstrac
                             + " from clipboard" + ufe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
         }
     }
-    
+
     public JPanel createHeaderTablePanel() {
         // create the JTable that holds header per row
         headerTable = new JTable(tableModel);
         JMeterUtils.applyHiDPI(headerTable);
         headerTable.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
-        headerTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        headerTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
         headerTable.setPreferredScrollableViewportSize(new Dimension(100, 70));
 
         JPanel panel = new JPanel(new BorderLayout(0, 5));

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1752722&r1=1752721&r2=1752722&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Thu Jul 14 18:44:54 2016
@@ -102,6 +102,8 @@ Summary
     <li><bug>59609</bug>Format extracted JSON Objects in JSON Post Processor
correctly as JSON.</li>
     <li><bug>59845</bug>Log messages about JSON Path mismatches at <code>debug</code>
level instead of <code>error</code>.</li>
     <li><pr>212</pr>Allow multiple selection and delete in HTTP Authorization
Manager. Based on a patch by Benoit Wiart (b.wiart at ubik-ingenierie.com)</li>
+    <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>
 </ul>
 
 <h3>Functions</h3>



Mime
View raw message