Delete IP implemented, ResultTable is created before the menu, so it can be used in initialization of menu actions

git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/ipscan@25 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
angryziber 2006-09-20 20:49:31 +00:00
parent f4b5777fd5
commit c20df50653
5 changed files with 44 additions and 9 deletions

View File

@ -92,4 +92,14 @@ public class ScanningResultList {
return (String) scanningResults.get(tableIndex);
}
/**
* @param indices
*/
public void remove(int[] indices) {
// this removal is probably O(n^2)...
for (int i = 0; i < indices.length; i++) {
scanningResults.remove(i);
}
}
}

View File

@ -102,7 +102,7 @@ public class MainMenu {
new Object[] {"menu.commands.details", null, new CommandsActions.Details(mainWindow.getResultTable())},
null,
new Object[] {"menu.commands.rescan", new Integer(SWT.CONTROL | 'R'), null},
new Object[] {"menu.commands.delete", new Integer(SWT.DEL), null},
new Object[] {"menu.commands.delete", new Integer(SWT.DEL), new CommandsActions.Delete(mainWindow.getResultTable())},
null,
new Object[] {"menu.commands.copy", new Integer(SWT.CONTROL | 'C'), null},
new Object[] {"menu.commands.copyDetails", null, null},

View File

@ -83,11 +83,12 @@ public class MainWindow {
// load and set icon
Image image = new Image(shell.getDisplay(), Labels.getInstance().getImageAsStream("icon"));
shell.setImage(image);
resultTable = new ResultTable(shell);
createMenu();
createControls();
createStatusBar();
createTable();
initTable();
shell.setBounds(Config.getDimensionsConfig().getWindowBounds());
shell.setMaximized(Config.getDimensionsConfig().isWindowMaximized);
@ -146,8 +147,8 @@ public class MainWindow {
/**
* This method initializes resultTable
*/
private void createTable() {
resultTable = new ResultTable(shell, mainMenu.getColumnsPopupMenu());
private void initTable() {
resultTable.setColumnsMenu(mainMenu.getColumnsPopupMenu());
FormData formData = new FormData();
formData.top = new FormAttachment(feederArea);
formData.left = new FormAttachment(0);

View File

@ -41,12 +41,15 @@ public class ResultTable extends Table {
private String feederInfo;
private Menu columnsMenu;
public ResultTable(Composite parent, Menu columnsMenu) {
public ResultTable(Composite parent) {
super(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
this.columnsMenu = columnsMenu;
initialize();
}
void setColumnsMenu(Menu columnsMenu) {
this.columnsMenu = columnsMenu;
}
private void initialize() {
setHeaderVisible(true);
setLinesVisible(true);
@ -147,6 +150,12 @@ public class ResultTable extends Table {
return scanningResults.getResultsAsString(selectedIndex);
}
public void remove(int[] indices) {
// we need to remove the elements from our real storage as well
scanningResults.remove(indices);
super.remove(indices);
}
/**
* Initializes a new scan.
* (clears all elments, etc)

View File

@ -30,10 +30,10 @@ import org.eclipse.swt.widgets.MenuItem;
public class CommandsActions {
public static class Details implements Listener {
ResultTable resultTable;
private ResultTable resultTable;
public Details(ResultTable table) {
resultTable = table;
public Details(ResultTable resultTable) {
this.resultTable = resultTable;
}
public void handleEvent(Event event) {
@ -42,6 +42,21 @@ public class CommandsActions {
}
}
public static class Delete implements Listener {
private ResultTable resultTable;
public Delete(ResultTable resultTable) {
this.resultTable = resultTable;
}
public void handleEvent(Event event) {
checkSelection(resultTable);
int firstSelection = resultTable.getSelectionIndex();
resultTable.remove(resultTable.getSelectionIndices());
resultTable.setSelection(firstSelection);
}
}
/**
* Checks that there is at least one item selected in the results list.
* @param mainWindow