* Tools->Select in list menu implemented

* Deletion of items is no longer allowed during the scanning

git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@235 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
angryziber 2007-11-09 20:44:20 +00:00
parent 90b9741fd4
commit 403dc52aea
7 changed files with 156 additions and 30 deletions

1
TODO
View File

@ -5,7 +5,6 @@ Before 3.0 beta:
Before 3.0:
* command-line scanning start
* tools->delete menus (maybe tools->select?)
* fetcher-specific options
* multiple port support web-detect
* add new fetchers by configuration of PortTextFetcher

View File

@ -27,8 +27,12 @@ menu.favorites.add=Ad&d current...
menu.favorites.edit=&Manage favorites...
menu.tools=&Tools
menu.tools.preferences=&Preferences...
menu.tools.fetchers=Select &fetchers...
menu.tools.delete=Delete from list
menu.tools.fetchers=&Fetchers...
menu.tools.select=Se&lect in list
menu.tools.select.alive=&Alive hosts
menu.tools.select.dead=&Dead hosts
menu.tools.select.withPorts=With &open ports
menu.tools.select.withoutPorts=Without o&pen ports
menu.tools.scanInfo=Show scan &info
menu.help=&Help
menu.help.gettingStarted=Getting &Started
@ -75,6 +79,7 @@ text.threads=Threads:
text.display.ALL=Display: All
text.display.ALIVE=Display: Alive only
text.display.PORTS=Display: Open ports
text.hostsSelected= hosts selected
text.favorite.add=Enter the name of the new favorite
text.favorite.edit=Below you can rearrange or delete favorites
text.find=Enter the text to search for

View File

@ -39,6 +39,7 @@ import net.azib.ipscan.gui.MainMenu.CommandsMenu;
import net.azib.ipscan.gui.actions.ColumnsActions;
import net.azib.ipscan.gui.actions.OpenerLauncher;
import net.azib.ipscan.gui.actions.StartStopScanningAction;
import net.azib.ipscan.gui.actions.ToolsActions;
import net.azib.ipscan.gui.feeders.FeederGUIRegistry;
import net.azib.ipscan.gui.feeders.FileFeederGUI;
import net.azib.ipscan.gui.feeders.RandomFeederGUI;
@ -154,6 +155,8 @@ public class ComponentRegistry {
anyComponentParameter,
anyComponentParameter,
anyComponentParameter,
anyComponentParameter,
anyComponentParameter,
anyComponentParameter});
container.registerComponentImplementation(StatusBar.class, StatusBar.class, new Parameter[] {
new ComponentParameter("mainShell"),
@ -183,6 +186,7 @@ public class ComponentRegistry {
container.registerComponentImplementation(ColumnsActions.AboutFetcher.class);
container.registerComponentImplementation(ColumnsActions.ColumnClick.class);
container.registerComponentImplementation(ColumnsActions.ColumnResize.class);
container.registerComponentImplementation(ToolsActions.TableSelection.class);
}
public MainWindow createMainWindow() {

View File

@ -95,10 +95,15 @@ public class MainMenu {
subMenu = initMenu(menu, "menu.tools");
initMenuItem(subMenu, "menu.tools.preferences", "Ctrl+O", new Integer(SWT.MOD1 | (Platform.MAC_OS ? ',' : 'O')), initListener(ToolsActions.Preferences.class), true);
initMenuItem(subMenu, "menu.tools.fetchers", "Ctrl+Shift+O", new Integer(SWT.MOD1 | SWT.MOD2 | (Platform.MAC_OS ? ',' : 'O')), initListener(ToolsActions.SelectFetchers.class), true);
initMenuItem(subMenu, "menu.tools.fetchers", "Ctrl+Shift+O", new Integer(SWT.MOD1 | SWT.MOD2 | (Platform.MAC_OS ? ',' : 'O')), initListener(ToolsActions.ChooseFetchers.class), true);
initMenuItem(subMenu, null, null, null, null);
initMenuItem(subMenu, "menu.tools.delete", null, null, null);
Menu selectMenu = initMenu(subMenu, "menu.tools.select");
initMenuItem(subMenu, "menu.tools.scanInfo", "Ctrl+I", new Integer(SWT.MOD1 | 'I'), initListener(ToolsActions.ScanInfo.class));
initMenuItem(selectMenu, "menu.tools.select.alive", null, null, initListener(ToolsActions.SelectAlive.class), true);
initMenuItem(selectMenu, "menu.tools.select.dead", null, null, initListener(ToolsActions.SelectDead.class), true);
initMenuItem(selectMenu, "menu.tools.select.withPorts", null, null, initListener(ToolsActions.SelectWithPorts.class), true);
initMenuItem(selectMenu, "menu.tools.select.withoutPorts", null, null, initListener(ToolsActions.SelectWithoutPorts.class), true);
subMenu = initMenu(menu, "menu.help");
initMenuItem(subMenu, "menu.help.gettingStarted", !Platform.MAC_OS ? "F1" : null, new Integer(Platform.MAC_OS ? SWT.HELP : SWT.F1), initListener(HelpActions.GettingStarted.class));
@ -129,9 +134,9 @@ public class MainMenu {
// initMenuItem(subMenu, "menu.commands.show", null, initListener());
}
private void createOpenersMenu(Menu subMenu) {
private void createOpenersMenu(Menu parentMenu) {
OpenersMenu openersMenu = (OpenersMenu) container.getComponentInstance(OpenersMenu.class);
MenuItem openersMenuItem = new MenuItem(subMenu, SWT.CASCADE);
MenuItem openersMenuItem = new MenuItem(parentMenu, SWT.CASCADE);
openersMenuItem.setText(Labels.getLabel("menu.commands.open"));
openersMenuItem.setMenu(openersMenu);
}

View File

@ -12,11 +12,13 @@ import net.azib.ipscan.config.Labels;
import net.azib.ipscan.core.ScanningResult;
import net.azib.ipscan.core.ScanningResultList;
import net.azib.ipscan.core.ScanningResult.ResultType;
import net.azib.ipscan.core.state.StateMachine;
import net.azib.ipscan.fetchers.Fetcher;
import net.azib.ipscan.fetchers.FetcherRegistry;
import net.azib.ipscan.fetchers.FetcherRegistryUpdateListener;
import net.azib.ipscan.gui.actions.ColumnsActions;
import net.azib.ipscan.gui.actions.CommandsActions;
import net.azib.ipscan.gui.actions.ToolsActions;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
@ -42,7 +44,7 @@ public class ResultTable extends Table implements FetcherRegistryUpdateListener
private Listener columnResizeListener;
public ResultTable(Composite parent, FetcherRegistry fetcherRegistry, ScanningResultList scanningResultList, ColumnsActions.ColumnClick columnClickListener, ColumnsActions.ColumnResize columnResizeListener) {
public ResultTable(Composite parent, FetcherRegistry fetcherRegistry, ScanningResultList scanningResultList, StateMachine stateMachine, ColumnsActions.ColumnClick columnClickListener, ColumnsActions.ColumnResize columnResizeListener, ToolsActions.TableSelection selectionListener) {
super(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
this.scanningResults = scanningResultList;
@ -54,25 +56,17 @@ public class ResultTable extends Table implements FetcherRegistryUpdateListener
fetcherRegistry.addListener(this);
handleUpdateOfSelectedFetchers(fetcherRegistry);
// pre-load button images
// load button images
listImages[ResultType.UNKNOWN.ordinal()] = new Image(null, Labels.getInstance().getImageAsStream("list.unknown.img"));
listImages[ResultType.DEAD.ordinal()] = new Image(null, Labels.getInstance().getImageAsStream("list.dead.img"));
listImages[ResultType.ALIVE.ordinal()] = new Image(null, Labels.getInstance().getImageAsStream("list.alive.img"));
listImages[ResultType.WITH_PORTS.ordinal()] = new Image(null, Labels.getInstance().getImageAsStream("list.addinfo.img"));
Listener detailsListener = new Listener() {
CommandsActions.Details detailsListener = new CommandsActions.Details(ResultTable.this);
public void handleEvent(Event e) {
// activate only if something is selected
if (getSelectionIndex() >= 0 && (e.type == SWT.MouseDoubleClick || e.detail == SWT.TRAVERSE_RETURN)) {
e.doit = false;
detailsListener.handleEvent(e);
}
}
};
Listener detailsListener = new DetailsListener();
addListener(SWT.Traverse, detailsListener);
addListener(SWT.MouseDoubleClick, detailsListener);
addListener(SWT.KeyDown, new CommandsActions.Delete(this));
addListener(SWT.Selection, selectionListener);
addListener(SWT.KeyDown, new CommandsActions.Delete(this, stateMachine));
addListener(SWT.KeyDown, new CommandsActions.CopyIP(this));
// this one populates table dynamically, taking data from ScanningResultList
@ -189,10 +183,28 @@ public class ResultTable extends Table implements FetcherRegistryUpdateListener
return scanningResults;
}
/**
* This listener shows the details window
*/
final class DetailsListener extends CommandsActions.Details {
public DetailsListener() {
super(ResultTable.this);
}
public void handleEvent(Event e) {
// activate only if something is selected
if (getSelectionIndex() >= 0 && (e.type == SWT.MouseDoubleClick || e.detail == SWT.TRAVERSE_RETURN)) {
e.doit = false;
super.handleEvent(e);
}
}
}
/**
* This listener is used for displaying the real results in the table, on demand.
*/
class SetDataListener implements Listener {
final class SetDataListener implements Listener {
public void handleEvent(Event event) {
TableItem item = (TableItem)event.item;

View File

@ -15,6 +15,7 @@ import net.azib.ipscan.config.Labels;
import net.azib.ipscan.config.OpenersConfig.Opener;
import net.azib.ipscan.core.ScanningResultList;
import net.azib.ipscan.core.UserErrorException;
import net.azib.ipscan.core.state.ScanningState;
import net.azib.ipscan.core.state.StateMachine;
import net.azib.ipscan.fetchers.CommentFetcher;
import net.azib.ipscan.fetchers.FetcherRegistry;
@ -69,17 +70,23 @@ public class CommandsActions {
}
public static class Delete implements Listener {
private ResultTable resultTable;
private final ResultTable resultTable;
private final StateMachine stateMachine;
public Delete(ResultTable resultTable) {
public Delete(ResultTable resultTable, StateMachine stateMachine) {
this.resultTable = resultTable;
this.stateMachine = stateMachine;
}
public void handleEvent(Event event) {
// ignore other keys if this is a KeyDown event -
// the same listener is used for several events
if (event.type == SWT.KeyDown && event.keyCode != SWT.DEL)
return;
return;
// deletion now allowed when scanning
if (!stateMachine.inState(ScanningState.IDLE))
return;
checkSelection(resultTable);
int firstSelection = resultTable.getSelectionIndex();
resultTable.remove(resultTable.getSelectionIndices());

View File

@ -5,11 +5,10 @@
*/
package net.azib.ipscan.gui.actions;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import net.azib.ipscan.config.GlobalConfig;
import net.azib.ipscan.config.Labels;
import net.azib.ipscan.core.ScanningResultList;
import net.azib.ipscan.core.ScanningResult.ResultType;
import net.azib.ipscan.core.state.ScanningState;
import net.azib.ipscan.core.state.StateMachine;
import net.azib.ipscan.core.state.StateTransitionListener;
@ -19,6 +18,11 @@ import net.azib.ipscan.gui.SelectFetchersDialog;
import net.azib.ipscan.gui.StatisticsDialog;
import net.azib.ipscan.gui.StatusBar;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
/**
* ToolsActions
*
@ -48,11 +52,11 @@ public class ToolsActions {
}
}
public static class SelectFetchers implements Listener {
public static class ChooseFetchers implements Listener {
private SelectFetchersDialog selectFetchersDialog;
public SelectFetchers(SelectFetchersDialog selectFetchersDialog) {
public ChooseFetchers(SelectFetchersDialog selectFetchersDialog) {
this.selectFetchersDialog = selectFetchersDialog;
}
@ -88,6 +92,96 @@ public class ToolsActions {
});
}
}
}
/**
* This listener updates the status bar when user selects many items in the result table
*/
public static final class TableSelection implements Listener {
private final StatusBar statusBar;
private final StateMachine stateMachine;
public TableSelection(StatusBar statusBar, StateMachine stateMachine) {
this.statusBar = statusBar;
this.stateMachine = stateMachine;
}
public void handleEvent(Event event) {
if (stateMachine.inState(ScanningState.IDLE)) {
Table resultTable = (Table) event.widget;
int selectionCount = resultTable.getSelectionCount();
if (selectionCount > 1)
statusBar.setStatusText(selectionCount + Labels.getLabel("text.hostsSelected"));
else
statusBar.setStatusText(null);
}
}
}
abstract static class SelectDesired implements Listener {
private final ResultTable resultTable;
private final ScanningResultList results;
private final TableSelection tableSelectionListener;
public SelectDesired(ResultTable resultTable, ScanningResultList results, TableSelection tableSelectionListener) {
this.resultTable = resultTable;
this.results = results;
this.tableSelectionListener = tableSelectionListener;
}
public void handleEvent(Event event) {
int count = resultTable.getItemCount();
resultTable.deselectAll();
for (int i = 0; i < count; i++) {
if (isDesired(results.getResult(i).getType())) {
resultTable.select(i);
}
}
event.widget = resultTable;
tableSelectionListener.handleEvent(event);
}
abstract boolean isDesired(ResultType type);
}
public static class SelectAlive extends SelectDesired {
public SelectAlive(ResultTable resultTable, ScanningResultList results, TableSelection tableSelectionListener) {
super(resultTable, results, tableSelectionListener);
}
boolean isDesired(ResultType type) {
return type.ordinal() >= ResultType.ALIVE.ordinal();
}
}
public static class SelectDead extends SelectDesired {
public SelectDead(ResultTable resultTable, ScanningResultList results, TableSelection tableSelectionListener) {
super(resultTable, results, tableSelectionListener);
}
boolean isDesired(ResultType type) {
return type == ResultType.DEAD;
}
}
public static class SelectWithPorts extends SelectDesired {
public SelectWithPorts(ResultTable resultTable, ScanningResultList results, TableSelection tableSelectionListener) {
super(resultTable, results, tableSelectionListener);
}
boolean isDesired(ResultType type) {
return type == ResultType.WITH_PORTS;
}
}
public static class SelectWithoutPorts extends SelectDesired {
public SelectWithoutPorts(ResultTable resultTable, ScanningResultList results, TableSelection tableSelectionListener) {
super(resultTable, results, tableSelectionListener);
}
boolean isDesired(ResultType type) {
return type == ResultType.ALIVE;
}
}
}