Skip to content

Commit

Permalink
Merge branch 'master' into update-license
Browse files Browse the repository at this point in the history
  • Loading branch information
beryxz authored Mar 27, 2024
2 parents ac8408a + 8a88707 commit cf921b9
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public LogsTable(LogsTableModel logsTableModel, List<LogEntity> logEntries, Http
super(logsTableModel);

this.setAutoCreateRowSorter(false);
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.logEntries = logEntries;
this.requestViewer = requestViewer;
this.responseViewer = responseViewer;
Expand Down
136 changes: 107 additions & 29 deletions src/main/java/com/cys4/sensitivediscoverer/ui/RegexListViewer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cys4.sensitivediscoverer.ui;

import com.cys4.sensitivediscoverer.MainUI;
import com.cys4.sensitivediscoverer.model.LogEntity;
import com.cys4.sensitivediscoverer.model.RegexEntity;
import com.cys4.sensitivediscoverer.model.RegexListContext;
import com.cys4.sensitivediscoverer.model.RegexListViewerTableModel;
Expand All @@ -10,6 +11,10 @@
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
Expand Down Expand Up @@ -136,6 +141,9 @@ private JPanel createRegexListViewerBody(List<RegexEntity> regexEntities, Suppli
gbc.fill = GridBagConstraints.BOTH;
containerCenter.add(scrollPane, gbc);

//Add Regex Popup Menu
regexTable.addMouseListener(createRegexPopupMenu(ctx, regexTable, containerCenter, tableModel));

// buttons
JButton enableAllButton = createSetEnabledButton(ctx, true, containerCenter, tableModel);
containerRight.add(enableAllButton, createButtonGridConstraints(0, 0));
Expand All @@ -160,33 +168,54 @@ private JPanel createRegexListViewerBody(List<RegexEntity> regexEntities, Suppli
return container;
}

/**
* Create a popup menu over the selected regexTable entry and show edit and delete buttons.
*
* @param ctx
* @param regexTable
* @param tabPaneOptions
* @param tableModel
*/
private MouseListener createRegexPopupMenu(RegexListContext ctx, JTable regexTable, JPanel tabPaneOptions, RegexListViewerTableModel tableModel) {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
onMouseEvent(e);
}

private void onMouseEvent(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
int row = regexTable.getSelectedRow();
if (row == -1) return;
if (e.getComponent() instanceof JTable) {
JPopupMenu regexMenu = new JPopupMenu();
regexMenu.add(new JMenuItem(new AbstractAction(getLocaleString("options-list-edit")) {
@Override
public void actionPerformed(final ActionEvent e) {
editSelectedRegex(ctx, regexTable, tabPaneOptions, tableModel);
}
}));
regexMenu.add(new JMenuItem(new AbstractAction(getLocaleString("options-list-delete")) {
@Override
public void actionPerformed(final ActionEvent e) {
deleteSelectedRegex(ctx, regexTable, tabPaneOptions, tableModel);
}
}));
regexMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
}
};
}

private JMenuItem createEditRegexMenuItem(RegexListContext ctx,
JTable optionsRegexTable,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
JMenuItem btnEditRegex = new JMenuItem(getLocaleString("options-list-edit"));
btnEditRegex.setEnabled(false);
btnEditRegex.addActionListener(actionEvent -> {
int rowIndex;
int realRow;

rowIndex = optionsRegexTable.getSelectedRow();
if (rowIndex == -1) return;
realRow = optionsRegexTable.convertRowIndexToModel(rowIndex);

RegexEntity previousRegex = ctx.regexEntities().get(realRow);
RegexEditDialog dialog = new RegexEditDialog(previousRegex);
if (!dialog.showDialog(tabPaneOptions, getLocaleString("options-list-edit-dialogTitle"))) return;

RegexEntity newRegex = dialog.getRegexEntity();
if (newRegex.getRegex().isEmpty() && newRegex.getDescription().isEmpty()) return;
if (previousRegex.equals(newRegex)) return;

ctx.regexEntities().set(realRow, newRegex);

tableModel.fireTableRowsUpdated(realRow, realRow);
tabPaneOptions.validate();
tabPaneOptions.repaint();
editSelectedRegex(ctx, optionsRegexTable, tabPaneOptions, tableModel);
});
optionsRegexTable.getSelectionModel().addListSelectionListener(event -> {
int viewRow = optionsRegexTable.getSelectedRow();
Expand All @@ -195,22 +224,48 @@ private JMenuItem createEditRegexMenuItem(RegexListContext ctx,
return btnEditRegex;
}

/**
* Open the edit regex dialog of the selected regex.
*
* @param ctx
* @param optionsRegexTable
* @param tabPaneOptions
* @param tableModel
*/
private void editSelectedRegex(RegexListContext ctx,
JTable optionsRegexTable,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
int rowIndex;
int realRow;

rowIndex = optionsRegexTable.getSelectedRow();
if (rowIndex == -1) return;
realRow = optionsRegexTable.convertRowIndexToModel(rowIndex);

RegexEntity previousRegex = ctx.regexEntities().get(realRow);
RegexEditDialog dialog = new RegexEditDialog(previousRegex);
if (!dialog.showDialog(tabPaneOptions, getLocaleString("options-list-edit-dialogTitle"))) return;

RegexEntity newRegex = dialog.getRegexEntity();
if (newRegex.getRegex().isEmpty() && newRegex.getDescription().isEmpty()) return;
if (previousRegex.equals(newRegex)) return;

ctx.regexEntities().set(realRow, newRegex);

tableModel.fireTableRowsUpdated(realRow, realRow);
tabPaneOptions.validate();
tabPaneOptions.repaint();
}

private JMenuItem createDeleteRegexMenuItem(RegexListContext ctx,
JTable optionsRegexTable,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
JMenuItem btnDeleteRegex = new JMenuItem(getLocaleString("options-list-delete"));
btnDeleteRegex.setEnabled(false);
btnDeleteRegex.addActionListener(actionEvent -> {
int rowIndex = optionsRegexTable.getSelectedRow();
if (rowIndex == -1) return;
int realRow = optionsRegexTable.convertRowIndexToModel(rowIndex);
ctx.regexEntities().remove(realRow);

tableModel.fireTableRowsDeleted(realRow, realRow);

tabPaneOptions.validate();
tabPaneOptions.repaint();
deleteSelectedRegex(ctx, optionsRegexTable, tabPaneOptions, tableModel);
});
optionsRegexTable.getSelectionModel().addListSelectionListener(event -> {
int viewRow = optionsRegexTable.getSelectedRow();
Expand All @@ -219,6 +274,29 @@ private JMenuItem createDeleteRegexMenuItem(RegexListContext ctx,
return btnDeleteRegex;
}

/**
* Delete the selected regex from the table.
*
* @param ctx
* @param optionsRegexTable
* @param tabPaneOptions
* @param tableModel
*/
private void deleteSelectedRegex(RegexListContext ctx,
JTable optionsRegexTable,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
int rowIndex = optionsRegexTable.getSelectedRow();
if (rowIndex == -1) return;
int realRow = optionsRegexTable.convertRowIndexToModel(rowIndex);
ctx.regexEntities().remove(realRow);

tableModel.fireTableRowsDeleted(realRow, realRow);

tabPaneOptions.validate();
tabPaneOptions.repaint();
}

private JMenuItem createNewRegexMenuItem(RegexListContext ctx,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/com/cys4/sensitivediscoverer/ui/tab/LoggerTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,12 @@ private void onMouseEvent(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
int row = logsTable.getSelectedRow();
if (row == -1) return;
logsTable.setRowSelectionInterval(row, row);
if (logsTable.getSelectedRowCount() == 1) {
int realRow = logsTable.convertRowIndexToModel(row);
LogEntity logEntry = logEntries.get(realRow);

if (e.getComponent() instanceof LogsTable) {
new LogsTableContextMenu(logEntry, logEntries, originalRequestViewer, originalResponseViewer, logsTableModel, logsTable, mainUI.getBurpApi(), isAnalysisRunning)
.show(e.getComponent(), e.getX(), e.getY());
}
int realRow = logsTable.convertRowIndexToModel(row);
LogEntity logEntry = logEntries.get(realRow);

if (e.getComponent() instanceof LogsTable) {
new LogsTableContextMenu(logEntry, logEntries, originalRequestViewer, originalResponseViewer, logsTableModel, logsTable, mainUI.getBurpApi(), isAnalysisRunning)
.show(e.getComponent(), e.getX(), e.getY());
}
}
}
Expand Down

0 comments on commit cf921b9

Please sign in to comment.