Skip to content

Commit

Permalink
Databoard 数据看板新增 “删除选中项” 菜单项;调整菜单项的顺序,防止误操作
Browse files Browse the repository at this point in the history
  • Loading branch information
vaycore committed Oct 27, 2023
1 parent 89d6763 commit 4a3e7f1
Showing 1 changed file with 47 additions and 23 deletions.
70 changes: 47 additions & 23 deletions src/main/java/burp/vaycore/onescan/ui/widget/TaskTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
* 任务列表
Expand All @@ -43,23 +45,6 @@ public void mousePressed(MouseEvent e) {
String action = item.getActionCommand();
int[] selectedRows = getSelectedRows();
switch (action) {
case "clean-all":
mTaskTableModel.clearAll();
if (mOnTaskTableEventListener != null) {
mOnTaskTableEventListener.onChangeSelection(null);
}
mLastSelectedRow = -1;
break;
case "send-to-repeater":
ArrayList<TaskData> newData = new ArrayList<>(selectedRows.length);
for (int index : selectedRows) {
TaskData data = getTaskData(index);
newData.add(data);
}
if (mOnTaskTableEventListener != null) {
mOnTaskTableEventListener.onSendToRepeater(newData);
}
break;
case "fetch-body-md5":
case "fetch-body-hash":
if (mOnTaskTableEventListener == null) {
Expand All @@ -82,6 +67,16 @@ public void mousePressed(MouseEvent e) {
}
showTextAreaDialog(item.getText(), result.toString());
break;
case "send-to-repeater":
ArrayList<TaskData> newData = new ArrayList<>(selectedRows.length);
for (int index : selectedRows) {
TaskData data = getTaskData(index);
newData.add(data);
}
if (mOnTaskTableEventListener != null) {
mOnTaskTableEventListener.onSendToRepeater(newData);
}
break;
case "add-to-black-host":
if (mOnTaskTableEventListener == null) {
break;
Expand All @@ -100,6 +95,21 @@ public void mousePressed(MouseEvent e) {
}
mOnTaskTableEventListener.addToBlackHost(hosts);
break;
case "remove-items":
ArrayList<TaskData> removeList = new ArrayList<>();
for (int index : selectedRows) {
TaskData data = getTaskData(index);
removeList.add(data);
}
mTaskTableModel.removeItems(removeList);
break;
case "clean-all":
mTaskTableModel.clearAll();
if (mOnTaskTableEventListener != null) {
mOnTaskTableEventListener.onChangeSelection(null);
}
mLastSelectedRow = -1;
break;
}
}
};
Expand Down Expand Up @@ -243,11 +253,12 @@ public Component prepareRenderer(TableCellRenderer renderer, int row, int column

private void showPopupMenu(int x, int y) {
JPopupMenu menu = new JPopupMenu();
addPopupMenuItem(menu, "清空所有记录", "clean-all");
addPopupMenuItem(menu, "发送选中项到Repeater", "send-to-repeater");
addPopupMenuItem(menu, "获取bodyMd5值", "fetch-body-md5");
addPopupMenuItem(menu, "获取bodyHash值", "fetch-body-hash");
addPopupMenuItem(menu, "发送选中项到Repeater", "send-to-repeater");
addPopupMenuItem(menu, "添加Host到黑名单", "add-to-black-host");
addPopupMenuItem(menu, "删除选中项", "remove-items");
addPopupMenuItem(menu, "清空所有记录", "clean-all");
menu.setLightWeightPopupEnabled(true);
// 显示菜单
menu.show(this, x, y);
Expand Down Expand Up @@ -399,28 +410,41 @@ public static class TaskTableModel extends AbstractTableModel {
public static final String[] COLUMN_NAMES = new String[]{
"#", "From", "Method", "Host", "Url", "Title", "IP", "Status", "Length", "Fingerprint", "Comment", "Color-level"};
private final ArrayList<TaskData> mData;
private final AtomicInteger mCounter;

public TaskTableModel() {
mData = new ArrayList<>();
mCounter = new AtomicInteger();
}

public void add(TaskData data) {
if (data == null || data.getReqResp() == null) {
return;
}
synchronized (this.mData) {
int id = this.mData.size();
int index = mData.size();
int id = mCounter.getAndIncrement();
data.setId(id);
this.mData.add(data);
fireTableRowsInserted(id, id);
fireTableRowsInserted(index, index);
}
}

public void removeItems(List<TaskData> list) {
if (list == null || list.isEmpty()) {
return;
}
synchronized (this.mData) {
this.mData.removeAll(list);
fireTableDataChanged();
}
}

public void clearAll() {
synchronized (this.mData) {
int size = this.mData.size();
mData.clear();
fireTableRowsDeleted(0, size - 1);
mCounter.set(0);
fireTableDataChanged();
}
}

Expand Down

0 comments on commit 4a3e7f1

Please sign in to comment.