added domain object listener for function remove events

This commit is contained in:
adamopolous 2019-11-21 14:55:29 -05:00
parent 02df944b0e
commit a682ef31ea
52 changed files with 4184 additions and 2210 deletions

View file

@ -18,6 +18,7 @@ package docking.widgets;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
@ -30,6 +31,7 @@ public class ListSelectionTableDialog<T> extends DialogComponentProvider {
private GTable gTable;
private T selectedValue;
private List<T> selectedValues = new ArrayList<>();
private GTableFilterPanel<T> filterPanel;
private RowObjectTableModel<T> model;
@ -55,10 +57,15 @@ public class ListSelectionTableDialog<T> extends DialogComponentProvider {
@Override
protected void okCallback() {
int selectedRow = gTable.getSelectedRow();
if (selectedRow >= 0) {
int modelRow = filterPanel.getModelRow(selectedRow);
selectedValue = model.getRowObject(modelRow);
int[] selectedRows = gTable.getSelectedRows();
if (selectedRows.length > 0) {
selectedValues.clear();
for (int selectedRow : selectedRows) {
int modelRow = filterPanel.getModelRow(selectedRow);
T rowObject = model.getRowObject(modelRow);
selectedValues.add(rowObject);
}
selectedValue = selectedValues.isEmpty() ? null : selectedValues.get(0);
close();
}
}
@ -101,15 +108,26 @@ public class ListSelectionTableDialog<T> extends DialogComponentProvider {
return selectedValue;
}
public List<T> getSelectedItems() {
return selectedValues;
}
public T show(Component parent) {
setMultiSelectionMode(false);
DockingWindowManager.showDialog(parent, this);
return getSelectedItem();
}
public List<T> showSelectMultiple(Component parent) {
setMultiSelectionMode(true);
DockingWindowManager.showDialog(parent, this);
return getSelectedItems();
}
public void setMultiSelectionMode(boolean enable) {
if (enable) {
gTable.getSelectionModel().setSelectionMode(
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
gTable.getSelectionModel()
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}
else {
gTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

View file

@ -0,0 +1,128 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package docking.widgets.dialogs;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.List;
import javax.swing.*;
import docking.DialogComponentProvider;
import docking.widgets.table.*;
/**
* Dialog for displaying table data in a dialog for the purpose of the user selecting one or
* more items from the table.
*
* @param <T> The type of row object in the table.
*/
public class TableChooserDialog<T> extends DialogComponentProvider {
private RowObjectTableModel<T> model;
private GFilterTable<T> gFilterTable;
private List<T> selectedItems;
/**
* Create a new Dialog for displaying and choosing table row items
*
* @param title The title for the dialog
* @param model a {@link RowObjectTableModel} that has the tRable data
* @param allowMultipleSelection if true, the dialog allows the user to select more
* than one row; otherwise, only single selection is allowed
*/
public TableChooserDialog(String title, RowObjectTableModel<T> model,
boolean allowMultipleSelection) {
super(title);
this.model = model;
addWorkPanel(buildTable(allowMultipleSelection));
addOKButton();
addCancelButton();
}
/**
* Returns the list of selected items or null if the dialog was cancelled.
* @return the list of selected items or null if the dialog was cancelled.
*/
public List<T> getSelectionItems() {
return selectedItems;
}
private void initializeTable(boolean allowMultipleSelection) {
GTable table = gFilterTable.getTable();
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
int selectionMode = allowMultipleSelection ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
: ListSelectionModel.SINGLE_SELECTION;
table.getSelectionModel().setSelectionMode(selectionMode);
}
protected void processMouseClicked(MouseEvent e) {
if (e.getClickCount() != 2) {
return;
}
int rowAtPoint = gFilterTable.getTable().rowAtPoint(e.getPoint());
if (rowAtPoint < 0) {
return;
}
T selectedRowObject = gFilterTable.getSelectedRowObject();
selectedItems = Arrays.asList(selectedRowObject);
close();
}
@Override
protected void okCallback() {
selectedItems = gFilterTable.getSelectedRowObjects();
close();
}
@Override
protected void cancelCallback() {
selectedItems = null;
close();
}
@Override
protected void dialogShown() {
gFilterTable.focusFilter();
}
private JComponent buildTable(boolean allowMultipleSelection) {
gFilterTable = new GFilterTable<>(model);
initializeTable(allowMultipleSelection);
gFilterTable.getTable().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (!e.isShiftDown()) {
processMouseClicked(e);
}
updateOkEnabled();
}
});
setOkEnabled(false);
return gFilterTable;
}
protected void updateOkEnabled() {
setOkEnabled(gFilterTable.getSelectedRowObject() != null);
}
}

View file

@ -15,13 +15,12 @@
*/
package docking.widgets.fieldpanel.internal;
import ghidra.util.exception.AssertException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import docking.widgets.fieldpanel.FieldPanel;
import ghidra.util.exception.AssertException;
/**
* A LineLockedFieldPanelCoordinator coordinates the scrolling of a set of field panels by sharing
@ -63,12 +62,12 @@ public class LineLockedFieldPanelCoordinator extends FieldPanelCoordinator {
public void setLockedLines(BigInteger[] lockedLineNumbers) {
if (lockedLineNumbers.length != this.lockedLineNumbers.length) {
throw new AssertException("The number of lines(" + lockedLineNumbers.length +
") must exactly match the number of panels(" + this.lockedLineNumbers.length + ").");
") must exactly match the number of panels(" + this.lockedLineNumbers.length +
").");
}
for (int i = 0; i < lockedLineNumbers.length; i++) {
if (lockedLineNumbers[i] == null) {
throw new AssertException("lockedLineNumber for field panel [" + i +
"] was unexpectedly null.");
lockedLineNumbers[i] = BigInteger.ZERO;
}
}
for (int i = 0; i < lockedLineNumbers.length; i++) {
@ -99,7 +98,7 @@ public class LineLockedFieldPanelCoordinator extends FieldPanelCoordinator {
*/
@Override
public void remove(FieldPanel fp) {
List<BigInteger> lineNumberList = new ArrayList<BigInteger>(panels.length);
List<BigInteger> lineNumberList = new ArrayList<>(panels.length);
// Adjust our locked line number array.
int length = panels.length;
for (int i = 0; i < length; i++) {