0001: /*
0002: * GNetWatch
0003: * Copyright 2006, 2007 Alexandre Fenyo
0004: * gnetwatch@fenyo.net
0005: *
0006: * This file is part of GNetWatch.
0007: *
0008: * GNetWatch is free software; you can redistribute it and/or modify
0009: * it under the terms of the GNU General Public License as published by
0010: * the Free Software Foundation; either version 2 of the License, or
0011: * (at your option) any later version.
0012: *
0013: * GNetWatch is distributed in the hope that it will be useful,
0014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0016: * GNU General Public License for more details.
0017: *
0018: * You should have received a copy of the GNU General Public License
0019: * along with GNetWatch; if not, write to the Free Software
0020: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0021: */
0022:
0023: // icones :
0024: // http://www.kde-look.org/content/show.php?content=8341
0025: // http://www.oxygen-icons.org/?cat=3
0026: // http://icon-king.com/?p=34
0027: // http://www.kde-artists.org/
0028: // http://www.kde-look.org/content/show.php?content=8341
0029: package net.fenyo.gnetwatch.GUI;
0030:
0031: import java.io.*;
0032: import java.util.*;
0033: import java.net.*;
0034:
0035: import javax.swing.*;
0036:
0037: import net.fenyo.gnetwatch.*;
0038: import net.fenyo.gnetwatch.actions.*;
0039: import net.fenyo.gnetwatch.activities.*;
0040: import net.fenyo.gnetwatch.targets.*;
0041: import net.fenyo.gnetwatch.data.*;
0042:
0043: import org.apache.commons.logging.Log;
0044: import org.apache.commons.logging.LogFactory;
0045:
0046: import org.apache.commons.configuration.*;
0047: import org.apache.commons.configuration.tree.xpath.*;
0048:
0049: import org.eclipse.swt.*;
0050: import org.eclipse.swt.widgets.*;
0051: import org.eclipse.swt.layout.*;
0052: import org.eclipse.swt.custom.*;
0053: import org.eclipse.swt.events.*;
0054: import org.eclipse.swt.graphics.*;
0055: import org.eclipse.swt.browser.*;
0056: import org.snmp4j.security.SecurityLevel;
0057: import org.snmp4j.util.TableEvent;
0058:
0059: /**
0060: * Manages the main GUI.
0061: * @author Alexandre Fenyo
0062: * @version $Id: GUI.java,v 1.86 2007/03/12 05:04:15 fenyo Exp $
0063: */
0064:
0065: public class GUI implements Runnable {
0066: private static Log log = LogFactory.getLog(GUI.class);
0067:
0068: private Config config;
0069: private Background background;
0070: private Main main;
0071: private SNMPManager snmp_manager;
0072: private Views views;
0073:
0074: private AwtGUI awtGUI = null;
0075:
0076: // GUI/SWT/AWT objects
0077: private Display display = null;
0078:
0079: // main Shell
0080: private Shell shell = null;
0081: private GridLayout layout = null;
0082:
0083: // Menu
0084: private Menu menu_bar = null, menu_file = null;
0085: private MenuItem menu_item_file = null;
0086: private MenuItem menu_item_exit = null;
0087:
0088: // Toolbar
0089: private ToolBar toolbar = null;
0090: private GridData toolbar_grid_data = null;
0091:
0092: // vertical Sash for horizontal Composite and text console
0093: private SashForm vertical_sash = null;
0094: private GridData vertical_sash_grid_data = null;
0095:
0096: // horizontal Composite
0097: private Composite horizontal_composite = null;
0098: private GridLayout horizontal_composite_layout = null;
0099:
0100: // text console
0101: private Browser text_console = null;
0102: private StringBuffer text_console_content = new StringBuffer();
0103:
0104: // groups composite, groups and childs
0105: private Composite groups_composite = null;
0106: private RowLayout groups_composite_layout = null;
0107: private GridData groups_composite_grid_data = null;
0108: private Group group_target_subnet = null,
0109: group_target_range = null, group_target_host = null,
0110: group_target_group = null, group_target_host6 = null;
0111: // private Group group_data = null;
0112: private GridLayout group_target_subnet_layout = null,
0113: group_target_range_layout = null,
0114: group_target_host_layout = null,
0115: group_target_group_layout = null,
0116: group_target_host6_layout = null;
0117: // private GridLayout group_data_layout = null;
0118: private Text target_subnet_address = null,
0119: target_subnet_mask = null;
0120: private Text target_range_begin = null, target_range_end = null;
0121: private Button target_subnet_push = null, target_range_push = null;
0122: private Text target_host_value = null;
0123: private Text target_group_value = null;
0124: private Text target_host6_value = null;
0125: private Button target_host_push = null, target_group_push = null,
0126: target_host6_push = null;
0127: private TargetGroup user_defined = null;
0128: private final int bglevel = 100;
0129:
0130: // horizontal Sash for Tree and Label
0131: private SashForm horizontal_sash = null;
0132: private GridData horizontal_sash_grid_data = null;
0133:
0134: // Tree
0135: private Tree tree = null;
0136: private TreeColumn tree_column1 = null, tree_column2 = null,
0137: tree_column3 = null;
0138:
0139: // bottom status
0140: private StyledText status = null;
0141: private GridData status_grid_data = null;
0142:
0143: // progress bar
0144: private ProgressBar progress_bar = null;
0145: private GridData progress_bar_grid_data = null;
0146: private CTabFolder tab_folder = null;
0147:
0148: // General variables
0149: private Thread thread = null;
0150: private final boolean GUI_created[] = { false };
0151:
0152: // images
0153: private Image image_folder = null, image_oscillo = null,
0154: image_exec = null, image_watch = null, image_host = null,
0155: image_host6 = null, image_host_snmp = null,
0156: image_host6_snmp = null, image_interface = null,
0157: image_queue = null, image_network = null,
0158: image_multirow = null;
0159:
0160: // visuals
0161: private VisualElement visual_root = null;
0162: private VisualElement visual_queues = null;
0163: private VisualElement visual_transient = null;
0164: private TargetGroup visual_this host = null;
0165: // private VisualElement visual_persistent = null;
0166: private TargetGroup visual_transient_all = null;
0167: private TargetGroup visual_transient_networks = null;
0168: // private VisualElement visual_persistent_all = null;
0169:
0170: private Label label1 = null, label2 = null, label3 = null,
0171: label4 = null, label5 = null, label6 = null, label7 = null;
0172:
0173: private MenuItem menu_item_add_host = null,
0174: menu_item_add_host6 = null, menu_item_add_range = null,
0175: menu_item_add_network = null, menu_item_add_group = null;
0176:
0177: private ToolItem item_add_host = null, item_add_network = null,
0178: item_discover_start = null, item_discover_stop = null;
0179:
0180: private MenuItem menu_item_credentials = null,
0181: menu_item_ip_options = null, menu_item_http_options = null;
0182:
0183: private MenuItem menu_item_add_ping = null,
0184: menu_item_add_flood = null, menu_item_add_http = null,
0185: menu_item_explore_snmp = null,
0186: menu_item_remove_action = null,
0187: menu_item_remove_action_ping = null,
0188: menu_item_remove_action_flood = null,
0189: menu_item_remove_action_explore = null,
0190: menu_item_remove_view = null,
0191: menu_item_remove_view_ping = null,
0192: menu_item_remove_view_flood = null,
0193: menu_item_remove_view_explore = null;
0194:
0195: VisualElement previous_selection = null;
0196:
0197: // synchronization object for access and modifications to the tree of visual elements
0198: public Object sync_tree = new Object();
0199:
0200: private final Map<Target, Target> target_map = new HashMap<Target, Target>();
0201:
0202: private CTabItem tab_item1, tab_item2;
0203:
0204: private int text_console_do_not_go_on_top = 0;
0205:
0206: /**
0207: * Return the configuration.
0208: * @param none.
0209: * @return Config configuration.
0210: */
0211: public Config getConfig() {
0212: return config;
0213: }
0214:
0215: /**
0216: * Return the root shell.
0217: * @param none.
0218: * @return Shell shell.
0219: */
0220: public Shell getShell() {
0221: return shell;
0222: }
0223:
0224: /**
0225: * Computes the desired background color.
0226: * @param none.
0227: * @return background color.
0228: */
0229: public Color getBackgroundColor() {
0230: return new Color(display, (int) Math.min((int) shell
0231: .getBackground().getRed() * 1.05, 255), (int) Math.min(
0232: (int) shell.getBackground().getGreen() * 1.05, 255),
0233: (int) Math.min(
0234: (int) shell.getBackground().getBlue() * 1.05,
0235: 255));
0236: }
0237:
0238: /**
0239: * Returns the SNMPManager instance.
0240: * @param none.
0241: * @return SNMPManager instance.
0242: */
0243: public SNMPManager getSNMPManager() {
0244: return snmp_manager;
0245: }
0246:
0247: /**
0248: * Returns the multithreaded synchronization lock for GUI creation.
0249: * @param none.
0250: * @return lock.
0251: */
0252: public boolean[] getGUICreated() {
0253: return GUI_created;
0254: }
0255:
0256: /**
0257: * Gets the tree node acting as the visual transient root.
0258: * @param none.
0259: * @return VisualElement visual transient element.
0260: */
0261: public VisualElement getVisualTransient() {
0262: return visual_transient;
0263: }
0264:
0265: /**
0266: * Gets the tree node acting as the "local host" root.
0267: * @param none.
0268: * @return TargetGroup visual transient node.
0269: */
0270: public TargetGroup getVisualThisHost() {
0271: return visual_this host;
0272: }
0273:
0274: /**
0275: * Gets the tree node acting as the "every host" root.
0276: * @param none.
0277: * @return TargetGroup "every host" node.
0278: */
0279: public TargetGroup getVisualTransientAll() {
0280: return visual_transient_all;
0281: }
0282:
0283: /**
0284: * Gets the tree node acting as the "every network" root.
0285: * @param none.
0286: * @return TargetGroup "every network" node.
0287: */
0288: public TargetGroup getVisualTransientNetworks() {
0289: return visual_transient_networks;
0290: }
0291:
0292: /**
0293: * Returns the AwtGUI instance used to build AWT frames that host Java2D-drawn components.
0294: * @param none.
0295: * @return AwtGUI AWT gui.
0296: */
0297: // GUI thread
0298: public AwtGUI getAwtGUI() {
0299: return awtGUI;
0300: }
0301:
0302: /**
0303: * Removes a target.
0304: * @param target target to remove.
0305: * @return void.
0306: */
0307: // GUI thread
0308: public void dropTargetInstance(final VisualElement target) {
0309: target_map.remove(target);
0310: }
0311:
0312: /**
0313: * Returns the canonical instance of a target.
0314: * The canonical instance is an instance that equals to this one
0315: * and that was the first created.
0316: * @param target instance.
0317: * @return Target canonical instance.
0318: */
0319: // GUI thread
0320: public Target getCanonicalInstance(final Target target) {
0321: final Target canonic_instance = target_map.get(target);
0322: if (canonic_instance == null) {
0323: target_map.put(target, target);
0324: return target;
0325: } else
0326: return canonic_instance;
0327: }
0328:
0329: /**
0330: * Checks that this instance has already been created.
0331: * @param target checks against this instance.
0332: * @return true if this instance has already been created.
0333: */
0334: // Capture thread
0335: public boolean containsCanonicalInstance(final Target target) {
0336: return target_map.get(target) != null;
0337: }
0338:
0339: /**
0340: * Execute this operation in the future in the SWT thread.
0341: * @param r operation to execute.
0342: * @return void.
0343: */
0344: // any thread
0345: public void asyncExecIfNeeded(final Runnable r) {
0346: // If thread is null, the thread GUI is not started.
0347: if (thread == null || Thread.currentThread().equals(thread))
0348: r.run();
0349: else
0350: display.asyncExec(r);
0351: }
0352:
0353: /**
0354: * Returns the tab folder.
0355: * @param none.
0356: * @return CTabFolder tab folder.
0357: */
0358: // GUI thread
0359: public CTabFolder getTabFolder() {
0360: return tab_folder;
0361: }
0362:
0363: /**
0364: * Returns the picture "image folder".
0365: * @param none.
0366: * @return Image picture.
0367: */
0368: // GUI thread
0369: public Image getImageFolder() {
0370: return image_folder;
0371: }
0372:
0373: /**
0374: * Returns the picture "exec".
0375: * @param none.
0376: * @return Image picture.
0377: */
0378: // GUI thread
0379: public Image getImageExec() {
0380: return image_exec;
0381: }
0382:
0383: /**
0384: * Returns the picture "oscilloscope".
0385: * @param none.
0386: * @return Image picture.
0387: */
0388: // GUI thread
0389: public Image getImageOscillo() {
0390: return image_oscillo;
0391: }
0392:
0393: /**
0394: * Returns the picture "multirow".
0395: * @param none.
0396: * @return Image picture.
0397: */
0398: // GUI thread
0399: public Image getImageMultiRow() {
0400: return image_multirow;
0401: }
0402:
0403: /**
0404: * Returns the picture "watch".
0405: * @param none.
0406: * @return Image picture.
0407: */
0408: // GUI thread
0409: public Image getImageWatch() {
0410: return image_watch;
0411: }
0412:
0413: /**
0414: * Returns the picture "IPv4 host".
0415: * @param none.
0416: * @return Image picture.
0417: */
0418: // GUI thread
0419: public Image getImageHost() {
0420: return image_host;
0421: }
0422:
0423: /**
0424: * Returns the picture "IPv6 host".
0425: * @param none.
0426: * @return Image picture.
0427: */
0428: // GUI thread
0429: public Image getImageHost6() {
0430: return image_host6;
0431: }
0432:
0433: /**
0434: * Returns the picture "interface".
0435: * @param none.
0436: * @return Image picture.
0437: */
0438: // GUI thread
0439: public Image getImageInterface() {
0440: return image_interface;
0441: }
0442:
0443: /**
0444: * Returns the picture "queue".
0445: * @param none.
0446: * @return Image picture.
0447: */
0448: // GUI thread
0449: public Image getImageQueue() {
0450: return image_queue;
0451: }
0452:
0453: /**
0454: * Returns the picture "network".
0455: * @param none.
0456: * @return Image picture.
0457: */
0458: // GUI thread
0459: public Image getImageNetwork() {
0460: return image_network;
0461: }
0462:
0463: /**
0464: * Returns the picture "IPv4 SNMP host".
0465: * @param none.
0466: * @return Image picture.
0467: */
0468: // GUI thread
0469: public Image getImageHostSNMP() {
0470: return image_host_snmp;
0471: }
0472:
0473: /**
0474: * Returns the picture "IPv6 SNMP host".
0475: * @param none.
0476: * @return Image picture.
0477: */
0478: // GUI thread
0479: public Image getImageHost6SNMP() {
0480: return image_host6_snmp;
0481: }
0482:
0483: /**
0484: * Resets the status string.
0485: * May be called from any thread.
0486: * @param none.
0487: * @return void.
0488: */
0489: public void setStatus(final String str) {
0490: asyncExecIfNeeded(new Runnable() {
0491: public void run() {
0492: status.setText(" " + str);
0493: }
0494: });
0495: }
0496:
0497: /**
0498: * Sets the progress bar position.
0499: * @param position position.
0500: * @return void.
0501: */
0502: public void setProgress(final int position) {
0503: asyncExecIfNeeded(new Runnable() {
0504: public void run() {
0505: progress_bar.setSelection(position);
0506: }
0507: });
0508: }
0509:
0510: /**
0511: * Encapsulates an html part into a face definition.
0512: * @param html html source part.
0513: * @return embeded html part.
0514: */
0515: public String htmlFace(final String html) {
0516: return "<FONT FACE='Verdana' size='-2'>" + html + "</FONT>";
0517: }
0518:
0519: /**
0520: * Adds a string to the console.
0521: * May be called from any thread.
0522: * @param none.
0523: * @return void.
0524: */
0525: public void appendConsole(final String str) {
0526: asyncExecIfNeeded(new Runnable() {
0527: public void run() {
0528: text_console_content.append(str);
0529: text_console.setText("<html><body bgcolor='#"
0530: + String.format("%2x%2x%2x",
0531: getBackgroundColor().getRed(),
0532: getBackgroundColor().getGreen(),
0533: getBackgroundColor().getBlue()) + "'>"
0534: + htmlFace(text_console_content.toString())
0535: + "</body></html>");
0536: }
0537: });
0538: }
0539:
0540: /**
0541: * Check that the selection is under the transient node.
0542: * @param none.
0543: * @return true if the selection is under the transient node.
0544: */
0545: // GUI thread
0546: private boolean isSelectionTransient() {
0547: if (tree.getSelectionCount() == 1) {
0548: TreeItem current_item = tree.getSelection()[0];
0549: while (current_item != null
0550: && visual_transient.isThisOurTreeItem(current_item) == false /* &&
0551: visual_persistent.isThisOurTreeItem(current_item) == false */)
0552: current_item = current_item.getParentItem();
0553: if (visual_transient.isThisOurTreeItem(current_item))
0554: return true;
0555: }
0556: return false;
0557: }
0558:
0559: // GUI thread
0560: /*
0561: private boolean isSelectionPersistent() {
0562: if (tree.getSelectionCount() == 1) {
0563: TreeItem current_item = tree.getSelection()[0];
0564: while (current_item != null &&
0565: visual_transient.isThisOurTreeItem(current_item) == false &&
0566: visual_persistent.isThisOurTreeItem(current_item) == false)
0567: current_item = current_item.getParentItem();
0568: if (visual_persistent.isThisOurTreeItem(current_item)) return true;
0569: }
0570: return false;
0571: }
0572: */
0573:
0574: /**
0575: * Expands every nodes under a specified root node.
0576: * @param item root node.
0577: * @return void.
0578: */
0579: // GUI thread
0580: private void expandAll(final TreeItem item) {
0581: synchronized (sync_tree) {
0582: item.setExpanded(true);
0583: for (final TreeItem it : item.getItems())
0584: expandAll(it);
0585: }
0586: }
0587:
0588: /**
0589: * Merges every nodes under a specified root node.
0590: * @param item root node.
0591: * @return void.
0592: */
0593: // GUI thread
0594: private void mergeAll(final TreeItem item) {
0595: synchronized (sync_tree) {
0596: item.setExpanded(false);
0597: for (final TreeItem it : item.getItems())
0598: mergeAll(it);
0599: }
0600: }
0601:
0602: /**
0603: * Adds an action on every nodes under a specified root node.
0604: * @param item root node.
0605: * @param clazz action class.
0606: * @return void.
0607: */
0608: // GUI thread
0609: private void addActionAll(final TreeItem item, Class clazz) {
0610: synchronized (sync_tree) {
0611: for (final VisualElement elt : VisualElement
0612: .getSubElements(item, Target.class)) {
0613: final Target target = (Target) elt;
0614:
0615: boolean already_has_action = false;
0616: for (final VisualElement child : target.getChildren())
0617: if (clazz.isInstance(child)) {
0618: already_has_action = true;
0619: break;
0620: }
0621:
0622: if (already_has_action == false) {
0623: net.fenyo.gnetwatch.actions.Action action;
0624: try {
0625: action = (net.fenyo.gnetwatch.actions.Action) clazz
0626: .newInstance();
0627: } catch (final IllegalAccessException ex) {
0628: log.error("Exception", ex);
0629: return;
0630: } catch (final InstantiationException ex) {
0631: log.error("Exception", ex);
0632: return;
0633: }
0634: action.setTarget(target);
0635: action.setBackground(background);
0636: if (target.canManageThisChild(action))
0637: try {
0638: background.addActionQueue(action);
0639: action.setParent(this , target);
0640: } catch (final GeneralException ex) {
0641: log.error("Exception", ex);
0642: }
0643: }
0644: }
0645: }
0646: }
0647:
0648: /**
0649: * Adds a ping action on every nodes under a specified root node.
0650: * @param item root node.
0651: * @return void.
0652: */
0653: // GUI thread
0654: private void addPingAll(final TreeItem item) {
0655: addActionAll(item, ActionPing.class);
0656: }
0657:
0658: /**
0659: * Adds a flood action on every nodes under a specified root node.
0660: * @param item root node.
0661: * @return void.
0662: */
0663: // GUI thread
0664: private void addFloodAll(final TreeItem item) {
0665: addActionAll(item, ActionFlood.class);
0666: }
0667:
0668: /**
0669: * Adds a flood action on every nodes under a specified root node.
0670: * @param item root node.
0671: * @return void.
0672: */
0673: // GUI thread
0674: private void addHTTPAll(final TreeItem item) {
0675: addActionAll(item, ActionHTTP.class);
0676: }
0677:
0678: /**
0679: * Adds an "SNMP explore" action on every nodes under a specified root node.
0680: * @param item root node.
0681: * @return void.
0682: */
0683: // GUI thread
0684: private void exploreSNMP(final TreeItem item) {
0685: addActionAll(item, ActionSNMP.class);
0686: }
0687:
0688: /**
0689: * Adds an "nmap explore" action on every nodes under a specified root node.
0690: * @param item root node.
0691: * @return void.
0692: */
0693: // GUI thread
0694: private void exploreNmap(final TreeItem item) {
0695: addActionAll(item, ActionNmap.class);
0696: }
0697:
0698: /**
0699: * Synchronously get system descriptions via SNMP on every nodes under a specified root node.
0700: * @param item item root node.
0701: * @return void.
0702: */
0703: // GUI thread
0704: private void getSysdescr(final TreeItem item) {
0705: synchronized (sync_tree) {
0706: for (final VisualElement elt : VisualElement
0707: .getSubElements(item, TargetIPv4.class)) {
0708: final TargetIPv4 target = (TargetIPv4) elt;
0709: appendConsole("description[" + target.getAddress()
0710: + "]=\""
0711: + target.getSNMPQuerier().getSysDescr()
0712: + "\"<BR/>");
0713:
0714: if (target.getSNMPQuerier().isSNMPCapable())
0715: target.setImageHostSNMP();
0716: if (target.getSNMPQuerier().getLastSysdescr() != null)
0717: target.setType(target.getSNMPQuerier()
0718: .getLastSysdescr());
0719: }
0720: }
0721: }
0722:
0723: /**
0724: * Detaches every nodes under a specified root node.
0725: * @param item item root node.
0726: * @return void.
0727: */
0728: private void removeVisualElements(final TreeItem item) {
0729: synchronized (sync_tree) {
0730: final VisualElement visual_element = (VisualElement) item
0731: .getData(VisualElement.class.toString());
0732: if (item.getParentItem() == null)
0733: return;
0734: final VisualElement visual_parent = (VisualElement) item
0735: .getParentItem().getData(
0736: VisualElement.class.toString());
0737:
0738: visual_element.removeVisualElements(visual_parent);
0739: }
0740: }
0741:
0742: /**
0743: * Detaches action or view nodes under a specified root node.
0744: * @param item item root node.
0745: * @return void.
0746: */
0747: private void removeActionOrView(final TreeItem item,
0748: final Class clazz) {
0749: synchronized (sync_tree) {
0750: for (final VisualElement action : VisualElement
0751: .getSubElements(item, clazz))
0752: if (action.getParents().size() == 1)
0753: action.removeVisualElements(action.getParents()
0754: .get(0));
0755: }
0756: }
0757:
0758: /**
0759: * Detaches action nodes under a specified root node.
0760: * @param item item root node.
0761: * @return void.
0762: */
0763: private void removeActions(final TreeItem item) {
0764: removeActionOrView(item,
0765: net.fenyo.gnetwatch.actions.Action.class);
0766: }
0767:
0768: /**
0769: * Detaches ping actions under a specified root node.
0770: * @param item item root node.
0771: * @return void.
0772: */
0773: private void removeActionsPing(final TreeItem item) {
0774: removeActionOrView(item, ActionPing.class);
0775: }
0776:
0777: /**
0778: * Detaches flood actions under a specified root node.
0779: * @param item item root node.
0780: * @return void.
0781: */
0782: private void removeActionsFlood(final TreeItem item) {
0783: removeActionOrView(item, ActionFlood.class);
0784: }
0785:
0786: /**
0787: * Detaches "SNMP explore" actions under a specified root node.
0788: * @param item item root node.
0789: * @return void.
0790: */
0791: private void removeActionsExplore(final TreeItem item) {
0792: removeActionOrView(item, ActionSNMP.class);
0793: }
0794:
0795: /**
0796: * Detaches every views under a specified root node.
0797: * @param item item root node.
0798: * @return void.
0799: */
0800: private void removeViews(final TreeItem item) {
0801: removeActionOrView(item, DataView.class);
0802: }
0803:
0804: /**
0805: * Detaches ping views under a specified root node.
0806: * @param item item root node.
0807: * @return void.
0808: */
0809: private void removeViewsPing(final TreeItem item) {
0810: removeActionOrView(item, ReachableView.class);
0811: }
0812:
0813: /**
0814: * Detaches flood views under a specified root node.
0815: * @param item item root node.
0816: * @return void.
0817: */
0818: private void removeViewsFlood(final TreeItem item) {
0819: removeActionOrView(item, FloodView.class);
0820: }
0821:
0822: /**
0823: * Detaches "SNMP explore" views under a specified root node.
0824: * @param item item root node.
0825: * @return void.
0826: */
0827: private void removeViewsExplore(final TreeItem item) {
0828: removeActionOrView(item, BytesReceivedView.class);
0829: removeActionOrView(item, BytesSentView.class);
0830: }
0831:
0832: /**
0833: * Creates a new target or attach an existing one to the current position.
0834: * @param target target.
0835: * @return boolean true if the target has been created or attached.
0836: */
0837: // GUI thread
0838: // appelé par boutons sur la gauche pour ts types de targets
0839: // utilise la selection courante
0840: private boolean addTargetAtCurrentPosition(final Target target) {
0841: synchronized (sync_tree) {
0842: if (tree.getSelectionCount() == 1
0843: && (/* isSelectionPersistent() || */isSelectionTransient())) {
0844: final VisualElement parent = (VisualElement) tree
0845: .getSelection()[0].getData(VisualElement.class
0846: .toString());
0847: if (parent != null)
0848: return target.addTarget(this , parent);
0849: }
0850: // no target added
0851: }
0852: return false;
0853: }
0854:
0855: /**
0856: * Terminates the application.
0857: * @param none.
0858: * @return void.
0859: */
0860: // only called in the SWT thread
0861: private void exitApplication() {
0862: shell.close();
0863: }
0864:
0865: private void appendNetworkInterfaces() {
0866: try {
0867: String str = "<HR/><B>Local network interfaces</B>";
0868: str += "<TABLE BORDER='0' BGCOLOR='black' cellspacing='1' cellpadding='1'>";
0869: for (final Enumeration nifs = NetworkInterface
0870: .getNetworkInterfaces(); nifs.hasMoreElements();) {
0871: final NetworkInterface nif = (NetworkInterface) nifs
0872: .nextElement();
0873: str += "<TR><TD bgcolor='lightyellow' align='right'><B>"
0874: + htmlFace("interface name")
0875: + "</B></TD><TD bgcolor='lightyellow'><B>"
0876: + htmlFace(nif.getName()) + "</B></TD></TR>";
0877: str += "<TR><TD bgcolor='lightyellow' align='right'>"
0878: + htmlFace("display name")
0879: + "</TD><TD bgcolor='lightyellow'>"
0880: + htmlFace(nif.getDisplayName()) + "</TD></TR>";
0881: for (final Enumeration addrs = nif.getInetAddresses(); addrs
0882: .hasMoreElements();) {
0883: final InetAddress addr = (InetAddress) addrs
0884: .nextElement();
0885: if (Inet4Address.class.isInstance(addr))
0886: str += "<TR><TD bgcolor='lightyellow' align='right'>"
0887: + htmlFace("IPv4 address")
0888: + "</TD><TD bgcolor='lightyellow'>"
0889: + htmlFace(addr.getHostAddress())
0890: + "</TD></TR>";
0891: if (Inet6Address.class.isInstance(addr))
0892: str += "<TR><TD bgcolor='lightyellow' align='right'>"
0893: + htmlFace("IPv6 address")
0894: + "</TD><TD bgcolor='lightyellow'>"
0895: + htmlFace(addr.getHostAddress())
0896: + "</TD></TR>";
0897: }
0898: }
0899: str += "</TABLE>";
0900: appendConsole(str);
0901: } catch (final SocketException ex) {
0902: log.error("Exception", ex);
0903: }
0904: }
0905:
0906: /**
0907: * Instanciates the GUI objects.
0908: * GUI thread.
0909: * @param none.
0910: * @return void.
0911: */
0912: private void createGUI() throws UnknownHostException,
0913: SocketException, AlgorithmException {
0914: final GUI gui = this ;
0915:
0916: synchronized (sync_tree) {
0917:
0918: display = new Display();
0919: shell = new Shell(display);
0920: shell.setText(getConfig().getString("version"));
0921:
0922: // Shell Layout
0923: layout = new GridLayout();
0924: layout.numColumns = 1;
0925: layout.marginHeight = 2;
0926: layout.marginWidth = 2;
0927: layout.verticalSpacing = 1;
0928: shell.setLayout(layout);
0929: // shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
0930:
0931: // Menu
0932: menu_bar = new Menu(shell, SWT.BAR);
0933: shell.setMenuBar(menu_bar);
0934:
0935: // Menu "File"
0936: menu_file = new Menu(shell, SWT.DROP_DOWN);
0937: menu_item_file = new MenuItem(menu_bar, SWT.CASCADE);
0938: menu_item_file.setText(getConfig().getString("menu_file"));
0939: menu_item_file.setMenu(menu_file);
0940:
0941: // Menu "file": MenuItem "Exit"
0942: menu_item_exit = new MenuItem(menu_file, SWT.PUSH);
0943: menu_item_exit.setText(getConfig().getString("menu_exit"));
0944: menu_item_exit.addListener(SWT.Selection, new Listener() {
0945: public void handleEvent(final Event e) {
0946: gui.exitApplication();
0947: }
0948: });
0949: menu_item_exit.setImage(new Image(display,
0950: "pictures/exit.png"));
0951:
0952: // Menu "Discover"
0953: final Menu menu_discover = new Menu(shell, SWT.DROP_DOWN);
0954: final MenuItem menu_item_discover = new MenuItem(menu_bar,
0955: SWT.CASCADE);
0956: menu_item_discover.setText(getConfig().getString(
0957: "menu_discover"));
0958: menu_item_discover.setMenu(menu_discover);
0959:
0960: // Menu "Discover": MenuItem "Start" and "Stop"
0961: final MenuItem menu_item_discover_start = new MenuItem(
0962: menu_discover, SWT.PUSH);
0963: final MenuItem menu_item_discover_stop = new MenuItem(
0964: menu_discover, SWT.PUSH);
0965: menu_item_discover_start.setText(getConfig().getString(
0966: "menu_start"));
0967: menu_item_discover_start.setImage(new Image(display,
0968: "pictures/exec.png"));
0969: menu_item_discover_stop.setText(getConfig().getString(
0970: "menu_stop"));
0971: menu_item_discover_stop.setImage(new Image(display,
0972: "pictures/fileclose.png"));
0973: menu_item_discover_stop.setEnabled(false);
0974: menu_item_discover_start.addListener(SWT.Selection,
0975: new Listener() {
0976: public void handleEvent(final Event e) {
0977: menu_item_discover_start.setEnabled(false);
0978: item_discover_start.setEnabled(false);
0979: main.startDiscover();
0980: menu_item_discover_stop.setEnabled(true);
0981: item_discover_stop.setEnabled(true);
0982: }
0983: });
0984: menu_item_discover_stop.addListener(SWT.Selection,
0985: new Listener() {
0986: public void handleEvent(final Event e) {
0987: menu_item_discover_start.setEnabled(true);
0988: item_discover_start.setEnabled(true);
0989: main.stopDiscover();
0990: menu_item_discover_stop.setEnabled(false);
0991: item_discover_stop.setEnabled(false);
0992: }
0993: });
0994:
0995: // Menu "Tree"
0996: final Menu menu_tree = new Menu(shell, SWT.DROP_DOWN);
0997: final MenuItem menu_item_tree = new MenuItem(menu_bar,
0998: SWT.CASCADE);
0999: menu_item_tree.setText(getConfig().getString("menu_tree"));
1000: menu_item_tree.setMenu(menu_tree);
1001:
1002: // Menu "Tree": MenuItem "Expand"
1003: final MenuItem menu_item_expand = new MenuItem(menu_tree,
1004: SWT.PUSH);
1005: menu_item_expand.setText(getConfig().getString("expand"));
1006: menu_item_expand.addListener(SWT.Selection, new Listener() {
1007: public void handleEvent(final Event e) {
1008: if (tree.getSelectionCount() == 1)
1009: tree.getSelection()[0].setExpanded(true);
1010: }
1011: });
1012:
1013: // Menu "Tree": MenuItem "Merge"
1014: final MenuItem menu_item_merge = new MenuItem(menu_tree,
1015: SWT.PUSH);
1016: menu_item_merge.setText(getConfig().getString("collapse"));
1017: menu_item_merge.addListener(SWT.Selection, new Listener() {
1018: public void handleEvent(final Event e) {
1019: if (tree.getSelectionCount() == 1)
1020: tree.getSelection()[0].setExpanded(false);
1021: }
1022: });
1023:
1024: new MenuItem(menu_tree, SWT.SEPARATOR);
1025:
1026: // Menu "Tree": MenuItem "Expand All"
1027: final MenuItem menu_item_expand_all = new MenuItem(
1028: menu_tree, SWT.PUSH);
1029: menu_item_expand_all.setText(getConfig().getString(
1030: "menu_expand_all"));
1031: menu_item_expand_all.setImage(new Image(display,
1032: "pictures/show_table_column.png"));
1033: menu_item_expand_all.addListener(SWT.Selection,
1034: new Listener() {
1035: public void handleEvent(final Event e) {
1036: if (tree.getSelectionCount() == 1)
1037: expandAll(tree.getSelection()[0]);
1038: }
1039: });
1040:
1041: // Menu "Tree": MenuItem "Merge All"
1042: final MenuItem menu_item_merge_all = new MenuItem(
1043: menu_tree, SWT.PUSH);
1044: menu_item_merge_all.setText(getConfig().getString(
1045: "menu_collapse_all"));
1046: menu_item_merge_all.setImage(new Image(display,
1047: "pictures/hide_table_column.png"));
1048: menu_item_merge_all.addListener(SWT.Selection,
1049: new Listener() {
1050: public void handleEvent(final Event e) {
1051: if (tree.getSelectionCount() == 1)
1052: mergeAll(tree.getSelection()[0]);
1053: }
1054: });
1055:
1056: // Menu "Target"
1057: final Menu menu_target = new Menu(shell, SWT.DROP_DOWN);
1058: final MenuItem menu_item_target = new MenuItem(menu_bar,
1059: SWT.CASCADE);
1060: menu_item_target.setText(getConfig().getString(
1061: "menu_target"));
1062: menu_item_target.setMenu(menu_target);
1063:
1064: // Menu "Target": MenuItem "Set Credentials"
1065: menu_item_credentials = new MenuItem(menu_target, SWT.PUSH);
1066: menu_item_credentials.setText(getConfig().getString(
1067: "menu_set_credentials"));
1068: menu_item_credentials.addListener(SWT.Selection,
1069: new Listener() {
1070: public void handleEvent(final Event e) {
1071: final SNMPQuerier querier;
1072:
1073: synchronized (sync_tree) {
1074: if (tree.getSelectionCount() == 1
1075: && (/* isSelectionPersistent() || */isSelectionTransient())) {
1076: final VisualElement target = (VisualElement) tree
1077: .getSelection()[0]
1078: .getData(VisualElement.class
1079: .toString());
1080:
1081: if (target != null
1082: && (TargetIPv4.class
1083: .isInstance(target) || TargetIPv6.class
1084: .isInstance(target))) {
1085: if (TargetIPv4.class
1086: .isInstance(target))
1087: querier = ((TargetIPv4) target)
1088: .getSNMPQuerier();
1089: else
1090: querier = ((TargetIPv6) target)
1091: .getSNMPQuerier();
1092: } else
1093: return;
1094: } else
1095: return;
1096: }
1097:
1098: final int version = querier.getVersion();
1099: final int sec = querier.getSec();
1100: final int port_src = querier.getRetries();
1101: final int timeout = querier.getTimeout();
1102: final int port = querier.getPort();
1103: final String community = querier
1104: .getCommunity();
1105: final String username = querier
1106: .getUsername();
1107: final String password_auth = querier
1108: .getPasswordAuth();
1109: final String password_priv = querier
1110: .getPasswordPriv();
1111: final int pdu_max_size = querier
1112: .getPDUMaxSize();
1113:
1114: final DialogCredentials dialog = new DialogCredentials(
1115: gui, shell);
1116: dialog.setVersion(version);
1117: dialog.setSec(sec);
1118: dialog.setRetries(port_src);
1119: dialog.setTimeout(timeout);
1120: dialog.setPort(port);
1121: dialog.setCommunity(community);
1122: dialog.setUsername(username);
1123: dialog.setPasswordAuth(password_auth);
1124: dialog.setPasswordPriv(password_priv);
1125: dialog.setPDUMaxSize(pdu_max_size);
1126:
1127: dialog.open();
1128:
1129: synchronized (sync_tree) {
1130: if (dialog.getVersion() != version)
1131: querier.setVersion(dialog
1132: .getVersion());
1133: if (dialog.getSec() != sec)
1134: querier.setSec(dialog.getSec());
1135: if (dialog.getRetries() != port_src)
1136: querier.setRetries(dialog
1137: .getRetries());
1138: if (dialog.getTimeout() != timeout)
1139: querier.setTimeout(dialog
1140: .getTimeout());
1141: if (dialog.getPort() != port)
1142: querier.setPort(dialog.getPort());
1143: if (dialog.getCommunity() != community)
1144: querier.setCommunity(dialog
1145: .getCommunity());
1146: if (dialog.getUsername() != username)
1147: querier.setUsername(dialog
1148: .getUsername());
1149: if (dialog.getPasswordAuth() != password_auth)
1150: querier.setPasswordAuth(dialog
1151: .getPasswordAuth());
1152: if (dialog.getPasswordPriv() != password_priv)
1153: querier.setPasswordPriv(dialog
1154: .getPasswordPriv());
1155: if (dialog.getPDUMaxSize() != pdu_max_size)
1156: querier.setPDUMaxSize(dialog
1157: .getPDUMaxSize());
1158: querier.update();
1159: }
1160: }
1161: });
1162:
1163: // Menu "Target": MenuItem "Set IP options"
1164: menu_item_ip_options = new MenuItem(menu_target, SWT.PUSH);
1165: menu_item_ip_options.setText(getConfig().getString(
1166: "menu_set_ip_options"));
1167: menu_item_ip_options.addListener(SWT.Selection,
1168: new Listener() {
1169: public void handleEvent(final Event e) {
1170: final IPQuerier querier;
1171:
1172: synchronized (sync_tree) {
1173: if (tree.getSelectionCount() == 1
1174: && (/* isSelectionPersistent() || */isSelectionTransient())) {
1175: final VisualElement target = (VisualElement) tree
1176: .getSelection()[0]
1177: .getData(VisualElement.class
1178: .toString());
1179:
1180: if (target != null
1181: && (TargetIPv4.class
1182: .isInstance(target) || TargetIPv6.class
1183: .isInstance(target))) {
1184: if (TargetIPv4.class
1185: .isInstance(target))
1186: querier = ((TargetIPv4) target)
1187: .getIPQuerier();
1188: else
1189: querier = ((TargetIPv6) target)
1190: .getIPQuerier();
1191: } else
1192: return;
1193: } else
1194: return;
1195: }
1196:
1197: final int tos = querier.getTOS();
1198: final int port_src = querier.getPortSrc();
1199: final int port_dst = querier.getPortDst();
1200: final int pdu_max_size = querier
1201: .getPDUMaxSize();
1202:
1203: final DialogIPOptions dialog = new DialogIPOptions(
1204: gui, shell);
1205:
1206: dialog.setTOS(tos);
1207: dialog.setPortSrc(port_src);
1208: dialog.setPortDst(port_dst);
1209: dialog.setPDUMaxSize(pdu_max_size);
1210:
1211: dialog.open();
1212:
1213: synchronized (sync_tree) {
1214: if (dialog.getTOS() != tos)
1215: querier.setTOS(dialog.getTOS());
1216: if (dialog.getPortSrc() != port_src)
1217: querier.setPortSrc(dialog
1218: .getPortSrc());
1219: if (dialog.getPortDst() != port_dst)
1220: querier.setPortDst(dialog
1221: .getPortDst());
1222: if (dialog.getPDUMaxSize() != pdu_max_size)
1223: querier.setPDUMaxSize(dialog
1224: .getPDUMaxSize());
1225:
1226: querier.update();
1227: }
1228: }
1229: });
1230:
1231: // Menu "Target": MenuItem "Set HTTP/FTP options"
1232: menu_item_http_options = new MenuItem(menu_target, SWT.PUSH);
1233: menu_item_http_options.setText(getConfig().getString(
1234: "menu_set_http_options"));
1235: menu_item_http_options.addListener(SWT.Selection,
1236: new Listener() {
1237: public void handleEvent(final Event e) {
1238: final IPQuerier querier;
1239:
1240: synchronized (sync_tree) {
1241: if (tree.getSelectionCount() == 1
1242: && (/* isSelectionPersistent() || */isSelectionTransient())) {
1243: final VisualElement target = (VisualElement) tree
1244: .getSelection()[0]
1245: .getData(VisualElement.class
1246: .toString());
1247:
1248: if (target != null
1249: && (TargetIPv4.class
1250: .isInstance(target) || TargetIPv6.class
1251: .isInstance(target))) {
1252: if (TargetIPv4.class
1253: .isInstance(target))
1254: querier = ((TargetIPv4) target)
1255: .getIPQuerier();
1256: else
1257: querier = ((TargetIPv6) target)
1258: .getIPQuerier();
1259: } else
1260: return;
1261: } else
1262: return;
1263: }
1264:
1265: final int nparallel = querier
1266: .getNParallel();
1267: final String proxy_host = querier
1268: .getProxyHost();
1269: final int proxy_port = querier
1270: .getProxyPort();
1271: final String URL = querier.getURL();
1272: // final boolean reconnect = querier.getReconnect();
1273: final boolean use_proxy = querier
1274: .getUseProxy();
1275:
1276: final DialogHTTPOptions dialog = new DialogHTTPOptions(
1277: gui, shell);
1278:
1279: dialog.setNParallel(nparallel);
1280: dialog.setProxyHost(proxy_host);
1281: dialog.setProxyPort(proxy_port);
1282: dialog.setURL(URL);
1283: // dialog.setReconnect(reconnect);
1284: dialog.setUseProxy(use_proxy);
1285:
1286: dialog.open();
1287:
1288: synchronized (sync_tree) {
1289: if (dialog.getNParallel() != nparallel)
1290: querier.setNParallel(dialog
1291: .getNParallel());
1292: if (dialog.getProxyHost() != proxy_host)
1293: querier.setProxyHost(dialog
1294: .getProxyHost());
1295: if (dialog.getProxyPort() != proxy_port)
1296: querier.setProxyPort(dialog
1297: .getProxyPort());
1298: if (dialog.getURL() != URL)
1299: querier.setURL(dialog.getURL());
1300: // if (dialog.getReconnect() != reconnect) querier.setReconnect(dialog.getReconnect());
1301: if (dialog.getUseProxy() != use_proxy)
1302: querier.setUseProxy(dialog
1303: .getUseProxy());
1304:
1305: querier.update();
1306: }
1307: }
1308: });
1309:
1310: new MenuItem(menu_target, SWT.SEPARATOR);
1311:
1312: // Menu "Target": MenuItem "Add IPv4 Host"
1313: menu_item_add_host = new MenuItem(menu_target, SWT.PUSH);
1314: menu_item_add_host.setText(getConfig().getString(
1315: "menu_add_ipv4"));
1316: menu_item_add_host.setImage(new Image(display,
1317: "pictures/network_local.png"));
1318: menu_item_add_host.addListener(SWT.Selection,
1319: new Listener() {
1320: public void handleEvent(final Event e) {
1321: target_host_push.notifyListeners(
1322: SWT.Selection, e);
1323: }
1324: });
1325:
1326: // Menu "Target": MenuItem "Add IPv6 Host"
1327: menu_item_add_host6 = new MenuItem(menu_target, SWT.PUSH);
1328: menu_item_add_host6.setText(getConfig().getString(
1329: "menu_add_ipv6"));
1330: menu_item_add_host6.addListener(SWT.Selection,
1331: new Listener() {
1332: public void handleEvent(final Event e) {
1333: target_host6_push.notifyListeners(
1334: SWT.Selection, e);
1335: }
1336: });
1337:
1338: // Menu "Target": MenuItem "Add Range"
1339: menu_item_add_range = new MenuItem(menu_target, SWT.PUSH);
1340: menu_item_add_range.setText(getConfig().getString(
1341: "menu_add_range"));
1342: menu_item_add_range.addListener(SWT.Selection,
1343: new Listener() {
1344: public void handleEvent(final Event e) {
1345: target_range_push.notifyListeners(
1346: SWT.Selection, e);
1347: }
1348: });
1349:
1350: // Menu "Target": MenuItem "Add Network"
1351: menu_item_add_network = new MenuItem(menu_target, SWT.PUSH);
1352: menu_item_add_network.setText(getConfig().getString(
1353: "menu_add_network"));
1354: menu_item_add_network.setImage(new Image(display,
1355: "pictures/network.png"));
1356: menu_item_add_network.addListener(SWT.Selection,
1357: new Listener() {
1358: public void handleEvent(final Event e) {
1359: target_subnet_push.notifyListeners(
1360: SWT.Selection, e);
1361: }
1362: });
1363:
1364: // Menu "Target": MenuItem "Add Group"
1365: menu_item_add_group = new MenuItem(menu_target, SWT.PUSH);
1366: menu_item_add_group.setText(getConfig().getString(
1367: "menu_add_group"));
1368: menu_item_add_group.addListener(SWT.Selection,
1369: new Listener() {
1370: public void handleEvent(final Event e) {
1371: target_group_push.notifyListeners(
1372: SWT.Selection, e);
1373: }
1374: });
1375:
1376: new MenuItem(menu_target, SWT.SEPARATOR);
1377:
1378: // Menu "Target": MenuItem "Remove Target"
1379: final MenuItem menu_item_remove_target = new MenuItem(
1380: menu_target, SWT.PUSH);
1381: menu_item_remove_target.setText(getConfig().getString(
1382: "menu_remove_element"));
1383: menu_item_remove_target.setImage(new Image(display,
1384: "pictures/nomailappt.png"));
1385: menu_item_remove_target.addListener(SWT.Selection,
1386: new Listener() {
1387: public void handleEvent(final Event e) {
1388: if (tree.getSelectionCount() == 1)
1389: removeVisualElements(tree
1390: .getSelection()[0]);
1391: }
1392: });
1393:
1394: // Menu "Action"
1395: final Menu menu_action = new Menu(shell, SWT.DROP_DOWN);
1396: final MenuItem menu_item_action = new MenuItem(menu_bar,
1397: SWT.CASCADE);
1398: menu_item_action.setText(getConfig().getString(
1399: "menu_action"));
1400: menu_item_action.setMenu(menu_action);
1401:
1402: /*
1403: // Menu "Action": MenuItem "Sysdescr"
1404: final MenuItem menu_item_sysdescr = new MenuItem(menu_action, SWT.PUSH);
1405: menu_item_sysdescr.setText(getConfig().getString("menu_get_system_description"));
1406: menu_item_sysdescr.setImage(new Image(display, "pictures/yahoo_idle-af.png"));
1407: menu_item_sysdescr.addSelectionListener(new SelectionListener() {
1408: public void widgetDefaultSelected(SelectionEvent e) {
1409: widgetSelected(e);
1410: }
1411:
1412: public void widgetSelected(SelectionEvent e) {
1413: if (tree.getSelectionCount() == 1) getSysdescr(tree.getSelection()[0]);
1414: }
1415: });
1416: */
1417:
1418: // Menu "Action": MenuItem "Add Ping"
1419: menu_item_add_ping = new MenuItem(menu_action, SWT.PUSH);
1420: menu_item_add_ping.setText(getConfig().getString(
1421: "menu_ping_target"));
1422: menu_item_add_ping.setImage(new Image(display,
1423: "pictures/yahoo_idle-af.png"));
1424: menu_item_add_ping
1425: .addSelectionListener(new SelectionListener() {
1426: public void widgetDefaultSelected(
1427: SelectionEvent e) {
1428: widgetSelected(e);
1429: }
1430:
1431: public void widgetSelected(SelectionEvent e) {
1432: if (tree.getSelectionCount() == 1)
1433: addPingAll(tree.getSelection()[0]);
1434: }
1435: });
1436:
1437: // Menu "Action": MenuItem "Add Flood"
1438: menu_item_add_flood = new MenuItem(menu_action, SWT.PUSH);
1439: menu_item_add_flood.setText(getConfig().getString(
1440: "menu_flood_target"));
1441: menu_item_add_flood
1442: .addSelectionListener(new SelectionListener() {
1443: public void widgetDefaultSelected(
1444: SelectionEvent e) {
1445: widgetSelected(e);
1446: }
1447:
1448: public void widgetSelected(SelectionEvent e) {
1449: if (tree.getSelectionCount() == 1)
1450: addFloodAll(tree.getSelection()[0]);
1451: }
1452: });
1453:
1454: // Menu "Action": MenuItem "Add Flood"
1455: menu_item_add_http = new MenuItem(menu_action, SWT.PUSH);
1456: menu_item_add_http.setText(getConfig().getString(
1457: "menu_http_target"));
1458: menu_item_add_http
1459: .addSelectionListener(new SelectionListener() {
1460: public void widgetDefaultSelected(
1461: SelectionEvent e) {
1462: widgetSelected(e);
1463: }
1464:
1465: public void widgetSelected(SelectionEvent e) {
1466: if (tree.getSelectionCount() == 1)
1467: addHTTPAll(tree.getSelection()[0]);
1468: }
1469: });
1470:
1471: // Menu "Action": MenuItem "Explore via SNMP"
1472: menu_item_explore_snmp = new MenuItem(menu_action, SWT.PUSH);
1473: menu_item_explore_snmp.setText(getConfig().getString(
1474: "menu_explore_via_snmp"));
1475: menu_item_explore_snmp
1476: .addSelectionListener(new SelectionListener() {
1477: public void widgetDefaultSelected(
1478: SelectionEvent e) {
1479: widgetSelected(e);
1480: }
1481:
1482: public void widgetSelected(SelectionEvent e) {
1483: if (tree.getSelectionCount() == 1)
1484: exploreSNMP(tree.getSelection()[0]);
1485: }
1486: });
1487:
1488: // Menu "Action": MenuItem "Explore via Nmap"
1489: menu_item_explore_snmp = new MenuItem(menu_action, SWT.PUSH);
1490: menu_item_explore_snmp.setText(getConfig().getString(
1491: "menu_explore_via_nmap"));
1492: menu_item_explore_snmp
1493: .addSelectionListener(new SelectionListener() {
1494: public void widgetDefaultSelected(
1495: SelectionEvent e) {
1496: widgetSelected(e);
1497: }
1498:
1499: public void widgetSelected(SelectionEvent e) {
1500: if (tree.getSelectionCount() == 1)
1501: exploreNmap(tree.getSelection()[0]);
1502: }
1503: });
1504:
1505: new MenuItem(menu_action, SWT.SEPARATOR);
1506:
1507: // Menu "Action": MenuItem "Drop Action"
1508: menu_item_remove_action = new MenuItem(menu_action,
1509: SWT.PUSH);
1510: menu_item_remove_action.setText(getConfig().getString(
1511: "menu_drop_action"));
1512: menu_item_remove_action.setImage(new Image(display,
1513: "pictures/button_cancel-af.png"));
1514: menu_item_remove_action.addListener(SWT.Selection,
1515: new Listener() {
1516: public void handleEvent(final Event e) {
1517: if (tree.getSelectionCount() == 1)
1518: removeActions(tree.getSelection()[0]);
1519: }
1520: });
1521:
1522: // Menu "Action": MenuItem "Drop Action Ping"
1523: menu_item_remove_action_ping = new MenuItem(menu_action,
1524: SWT.PUSH);
1525: menu_item_remove_action_ping.setText(getConfig().getString(
1526: "menu_drop_action_ping"));
1527: menu_item_remove_action_ping.addListener(SWT.Selection,
1528: new Listener() {
1529: public void handleEvent(final Event e) {
1530: if (tree.getSelectionCount() == 1)
1531: removeActionsPing(tree.getSelection()[0]);
1532: }
1533: });
1534:
1535: // Menu "Action": MenuItem "Drop Action Flood"
1536: menu_item_remove_action_flood = new MenuItem(menu_action,
1537: SWT.PUSH);
1538: menu_item_remove_action_flood.setText(getConfig()
1539: .getString("menu_drop_action_flood"));
1540: menu_item_remove_action_flood.addListener(SWT.Selection,
1541: new Listener() {
1542: public void handleEvent(final Event e) {
1543: if (tree.getSelectionCount() == 1)
1544: removeActionsFlood(tree.getSelection()[0]);
1545: }
1546: });
1547:
1548: // Menu "Action": MenuItem "Drop Action Explore"
1549: menu_item_remove_action_explore = new MenuItem(menu_action,
1550: SWT.PUSH);
1551: menu_item_remove_action_explore.setText(getConfig()
1552: .getString("menu_drop_action_explore"));
1553: menu_item_remove_action_explore.addListener(SWT.Selection,
1554: new Listener() {
1555: public void handleEvent(final Event e) {
1556: if (tree.getSelectionCount() == 1)
1557: removeActionsExplore(tree
1558: .getSelection()[0]);
1559: }
1560: });
1561:
1562: new MenuItem(menu_action, SWT.SEPARATOR);
1563:
1564: // Menu "Action": MenuItem "Drop View"
1565: menu_item_remove_view = new MenuItem(menu_action, SWT.PUSH);
1566: menu_item_remove_view.setText(getConfig().getString(
1567: "menu_drop_view"));
1568: menu_item_remove_view.addListener(SWT.Selection,
1569: new Listener() {
1570: public void handleEvent(final Event e) {
1571: if (tree.getSelectionCount() == 1)
1572: removeViews(tree.getSelection()[0]);
1573: }
1574: });
1575:
1576: // Menu "Action": MenuItem "Drop View Ping"
1577: menu_item_remove_view_ping = new MenuItem(menu_action,
1578: SWT.PUSH);
1579: menu_item_remove_view_ping.setText(getConfig().getString(
1580: "menu_drop_view_ping"));
1581: menu_item_remove_view_ping.addListener(SWT.Selection,
1582: new Listener() {
1583: public void handleEvent(final Event e) {
1584: if (tree.getSelectionCount() == 1)
1585: removeViewsPing(tree.getSelection()[0]);
1586: }
1587: });
1588:
1589: // Menu "Action": MenuItem "Drop View Flood"
1590: menu_item_remove_view_flood = new MenuItem(menu_action,
1591: SWT.PUSH);
1592: menu_item_remove_view_flood.setText(getConfig().getString(
1593: "menu_drop_view_flood"));
1594: menu_item_remove_view_flood.addListener(SWT.Selection,
1595: new Listener() {
1596: public void handleEvent(final Event e) {
1597: if (tree.getSelectionCount() == 1)
1598: removeViewsFlood(tree.getSelection()[0]);
1599: }
1600: });
1601:
1602: // Menu "Action": MenuItem "Drop View Explore"
1603: menu_item_remove_view_explore = new MenuItem(menu_action,
1604: SWT.PUSH);
1605: menu_item_remove_view_explore.setText(getConfig()
1606: .getString("menu_drop_view_explore"));
1607: menu_item_remove_view_explore.addListener(SWT.Selection,
1608: new Listener() {
1609: public void handleEvent(final Event e) {
1610: if (tree.getSelectionCount() == 1)
1611: removeViewsExplore(tree.getSelection()[0]);
1612: }
1613: });
1614:
1615: // Menu "View"
1616: final Menu menu_view = new Menu(shell, SWT.DROP_DOWN);
1617: final MenuItem menu_item_view = new MenuItem(menu_bar,
1618: SWT.CASCADE);
1619: menu_item_view.setText(getConfig().getString(
1620: "menu_snmp_info"));
1621: menu_item_view.setMenu(menu_view);
1622:
1623: // Menu "View": MenuItem "Get SysDescr"
1624: final MenuItem menu_item_open_view = new MenuItem(
1625: menu_view, SWT.PUSH);
1626: menu_item_open_view.setText(getConfig().getString(
1627: "menu_get_system_description"));
1628: menu_item_open_view.setImage(new Image(display,
1629: "pictures/multirow.png"));
1630: menu_item_open_view
1631: .addSelectionListener(new SelectionListener() {
1632: public void widgetDefaultSelected(
1633: SelectionEvent e) {
1634: widgetSelected(e);
1635: }
1636:
1637: public void widgetSelected(SelectionEvent e) {
1638: if (tree.getSelectionCount() == 1)
1639: getSysdescr(tree.getSelection()[0]);
1640: }
1641: });
1642:
1643: /*
1644: // Menu "View": MenuItem getConfig().getString("menu_open_graph")
1645: final MenuItem menu_item_open_graph = new MenuItem(menu_view, SWT.PUSH);
1646: menu_item_open_graph.setText(getConfig().getString("menu_open_graph"));
1647: menu_item_open_graph.setImage(new Image(display, "pictures/oscilloscope-af.png"));
1648: menu_item_open_graph.addListener(SWT.Selection, new Listener() {
1649: public void handleEvent(final Event e) {
1650: log.debug("open graph");
1651: }
1652: });
1653:
1654: // Menu "View": MenuItem getConfig().getString("menu_close_view")
1655: final MenuItem menu_item_close_view = new MenuItem(menu_view, SWT.PUSH);
1656: menu_item_close_view.setText(getConfig().getString("menu_close_view"));
1657: menu_item_close_view.setImage(new Image(display, "pictures/multirow-af-cross.png"));
1658: menu_item_close_view.addListener(SWT.Selection, new Listener() {
1659: public void handleEvent(final Event e) {
1660: log.debug("close view");
1661: }
1662: });
1663: */
1664:
1665: // Menu "Status"
1666: final Menu menu_status = new Menu(shell, SWT.DROP_DOWN);
1667: final MenuItem menu_item_status = new MenuItem(menu_bar,
1668: SWT.CASCADE);
1669: menu_item_status.setText(getConfig().getString(
1670: "menu_status"));
1671: menu_item_status.setMenu(menu_status);
1672:
1673: // Menu "Status": MenuItem "Local interfaces"
1674: final MenuItem menu_item_local_interfaces = new MenuItem(
1675: menu_status, SWT.PUSH);
1676: menu_item_local_interfaces.setText(getConfig().getString(
1677: "menu_local_interfaces"));
1678: menu_item_local_interfaces.addListener(SWT.Selection,
1679: new Listener() {
1680: public void handleEvent(final Event e) {
1681: appendNetworkInterfaces();
1682: }
1683: });
1684:
1685: // Menu "Help"
1686: final Menu menu_help = new Menu(shell, SWT.DROP_DOWN);
1687: final MenuItem menu_item_help = new MenuItem(menu_bar,
1688: SWT.CASCADE);
1689: menu_item_help.setText(getConfig().getString("menu_help"));
1690: menu_item_help.setMenu(menu_help);
1691:
1692: // Menu "Help": MenuItem "Welcome"
1693: final MenuItem menu_item_welcome = new MenuItem(menu_help,
1694: SWT.PUSH);
1695: menu_item_welcome.setText(getConfig().getString(
1696: "menu_welcome"));
1697: menu_item_welcome.addListener(SWT.Selection,
1698: new Listener() {
1699: public void handleEvent(final Event e) {
1700: tab_folder.setSelection(tab_item1);
1701: }
1702: });
1703:
1704: // Menu "Help": MenuItem "Help Contents"
1705: final MenuItem menu_item_help_contents = new MenuItem(
1706: menu_help, SWT.PUSH);
1707: menu_item_help_contents.setText(getConfig().getString(
1708: "menu_help_contents"));
1709: menu_item_help_contents.addListener(SWT.Selection,
1710: new Listener() {
1711: public void handleEvent(final Event e) {
1712: tab_folder.setSelection(tab_item2);
1713: }
1714: });
1715:
1716: new MenuItem(menu_help, SWT.SEPARATOR);
1717:
1718: // Menu "Help": MenuItem "About"
1719: final MenuItem menu_item_about = new MenuItem(menu_help,
1720: SWT.PUSH);
1721: menu_item_about
1722: .setText(getConfig().getString("menu_about"));
1723: menu_item_about.setImage(new Image(display,
1724: "pictures/info.png"));
1725: menu_item_about.addListener(SWT.Selection, new Listener() {
1726: public void handleEvent(final Event e) {
1727: final DialogAbout dialog = new DialogAbout(gui,
1728: shell);
1729: dialog.open();
1730: }
1731: });
1732:
1733: /*
1734: new MenuItem(menu_help, SWT.SEPARATOR);
1735:
1736: // Menu "Help": MenuItem "Software Update"
1737: final MenuItem menu_item_new_version = new MenuItem(menu_help, SWT.PUSH);
1738: menu_item_new_version.setText(getConfig().getString("menu_software_update"));
1739: menu_item_new_version.addListener(SWT.Selection, new Listener() {
1740: public void handleEvent(final Event e) {
1741: log.debug("new version");
1742: }
1743: });
1744: */
1745:
1746: /*
1747: * ToolBar
1748: */
1749: toolbar = new ToolBar(shell, SWT.FLAT);
1750: final ToolItem item_exit = new ToolItem(toolbar, SWT.PUSH);
1751: item_exit.setImage(new Image(display, "pictures/exit.png"));
1752: item_exit.setToolTipText(getConfig().getString("exit"));
1753: item_exit.addListener(SWT.Selection, new Listener() {
1754: public void handleEvent(final Event e) {
1755: menu_item_exit.notifyListeners(SWT.Selection, e);
1756: }
1757: });
1758:
1759: new ToolItem(toolbar, SWT.SEPARATOR);
1760:
1761: item_discover_start = new ToolItem(toolbar, SWT.PUSH);
1762: item_discover_start.setImage(new Image(display,
1763: "pictures/exec.png"));
1764: item_discover_start.setToolTipText(getConfig().getString(
1765: "start_sniffer"));
1766: item_discover_start.addListener(SWT.Selection,
1767: new Listener() {
1768: public void handleEvent(final Event e) {
1769: menu_item_discover_start.notifyListeners(
1770: SWT.Selection, e);
1771: }
1772: });
1773:
1774: item_discover_stop = new ToolItem(toolbar, SWT.PUSH);
1775: item_discover_stop.setImage(new Image(display,
1776: "pictures/fileclose.png"));
1777: item_discover_stop.setToolTipText(getConfig().getString(
1778: "stop_sniffer"));
1779: item_discover_stop.setEnabled(false);
1780: item_discover_stop.addListener(SWT.Selection,
1781: new Listener() {
1782: public void handleEvent(final Event e) {
1783: menu_item_discover_stop.notifyListeners(
1784: SWT.Selection, e);
1785: }
1786: });
1787:
1788: new ToolItem(toolbar, SWT.SEPARATOR);
1789:
1790: final ToolItem item_expand_all = new ToolItem(toolbar,
1791: SWT.PUSH);
1792: item_expand_all.setImage(new Image(display,
1793: "pictures/show_table_column.png"));
1794: item_expand_all.setToolTipText(getConfig().getString(
1795: "expand_all"));
1796: item_expand_all.addListener(SWT.Selection, new Listener() {
1797: public void handleEvent(final Event e) {
1798: menu_item_expand_all.notifyListeners(SWT.Selection,
1799: e);
1800: }
1801: });
1802:
1803: final ToolItem item_merge_all = new ToolItem(toolbar,
1804: SWT.PUSH);
1805: item_merge_all.setImage(new Image(display,
1806: "pictures/hide_table_column.png"));
1807: item_merge_all.setToolTipText(getConfig().getString(
1808: "collapse_all"));
1809: item_merge_all.addListener(SWT.Selection, new Listener() {
1810: public void handleEvent(final Event e) {
1811: menu_item_merge_all.notifyListeners(SWT.Selection,
1812: e);
1813: }
1814: });
1815:
1816: new ToolItem(toolbar, SWT.SEPARATOR);
1817:
1818: item_add_host = new ToolItem(toolbar, SWT.PUSH);
1819: item_add_host.setImage(new Image(display,
1820: "pictures/network_local.png"));
1821: item_add_host.setToolTipText(getConfig().getString(
1822: "add_ipv4_host"));
1823: item_add_host.addListener(SWT.Selection, new Listener() {
1824: public void handleEvent(final Event e) {
1825: menu_item_add_host
1826: .notifyListeners(SWT.Selection, e);
1827: }
1828: });
1829:
1830: item_add_network = new ToolItem(toolbar, SWT.PUSH);
1831: item_add_network.setImage(new Image(display,
1832: "pictures/network.png"));
1833: item_add_network.setToolTipText(getConfig().getString(
1834: "add_network"));
1835: item_add_network.addListener(SWT.Selection, new Listener() {
1836: public void handleEvent(final Event e) {
1837: menu_item_add_network.notifyListeners(
1838: SWT.Selection, e);
1839: }
1840: });
1841:
1842: final ToolItem item_remove_target = new ToolItem(toolbar,
1843: SWT.PUSH);
1844: item_remove_target.setImage(new Image(display,
1845: "pictures/nomailappt.png"));
1846: item_remove_target.setToolTipText(getConfig().getString(
1847: "remove_element"));
1848: item_remove_target.addListener(SWT.Selection,
1849: new Listener() {
1850: public void handleEvent(final Event e) {
1851: menu_item_remove_target.notifyListeners(
1852: SWT.Selection, e);
1853: }
1854: });
1855:
1856: new ToolItem(toolbar, SWT.SEPARATOR);
1857:
1858: final ToolItem item_add_ping = new ToolItem(toolbar,
1859: SWT.PUSH);
1860: item_add_ping.setImage(new Image(display,
1861: "pictures/yahoo_idle-af.png"));
1862: item_add_ping.setToolTipText("ping");
1863: item_add_ping.addListener(SWT.Selection, new Listener() {
1864: public void handleEvent(final Event e) {
1865: menu_item_add_ping
1866: .notifyListeners(SWT.Selection, e);
1867: }
1868: });
1869:
1870: final ToolItem item_remove_action = new ToolItem(toolbar,
1871: SWT.PUSH);
1872: item_remove_action.setImage(new Image(display,
1873: "pictures/button_cancel-af.png"));
1874: item_remove_action.setToolTipText(getConfig().getString(
1875: "drop_action"));
1876: item_remove_action.addListener(SWT.Selection,
1877: new Listener() {
1878: public void handleEvent(final Event e) {
1879: menu_item_remove_action.notifyListeners(
1880: SWT.Selection, e);
1881: }
1882: });
1883:
1884: /*
1885: new ToolItem(toolbar, SWT.SEPARATOR);
1886:
1887: final ToolItem item_open_view = new ToolItem(toolbar, SWT.PUSH);
1888: item_open_view.setImage(new Image(display, "pictures/multirow.png"));
1889: item_open_view.setToolTipText("open view");
1890: item_open_view.addListener(SWT.Selection, new Listener() {
1891: public void handleEvent(final Event e) {
1892: menu_item_open_view.notifyListeners(SWT.Selection, e);
1893: }
1894: });
1895: */
1896:
1897: /*
1898: final ToolItem item_open_graph = new ToolItem(toolbar, SWT.PUSH);
1899: item_open_graph.setImage(new Image(display, "pictures/oscilloscope-af.png"));
1900: item_open_graph.setToolTipText("open graph");
1901: item_open_graph.addListener(SWT.Selection, new Listener() {
1902: public void handleEvent(final Event e) {
1903: menu_item_open_graph.notifyListeners(SWT.Selection, e);
1904: }
1905: });
1906:
1907: final ToolItem item_close_view = new ToolItem(toolbar, SWT.PUSH);
1908: item_close_view.setImage(new Image(display, "pictures/multirow-af-cross.png"));
1909: item_close_view.setToolTipText("close view");
1910: item_close_view.addListener(SWT.Selection, new Listener() {
1911: public void handleEvent(final Event e) {
1912: menu_item_close_view.notifyListeners(SWT.Selection, e);
1913: }
1914: });
1915: */
1916:
1917: new ToolItem(toolbar, SWT.SEPARATOR);
1918:
1919: ToolItem item_about = new ToolItem(toolbar, SWT.PUSH);
1920: item_about
1921: .setImage(new Image(display, "pictures/info.png"));
1922: item_about.setToolTipText(getConfig().getString("help"));
1923: item_about.addListener(SWT.Selection, new Listener() {
1924: public void handleEvent(final Event e) {
1925: menu_item_about.notifyListeners(SWT.Selection, e);
1926: }
1927: });
1928:
1929: // GridData
1930: toolbar_grid_data = new GridData(GridData.FILL_HORIZONTAL);
1931: toolbar.setLayoutData(toolbar_grid_data);
1932:
1933: // vertical Sash for Composite and text console
1934: vertical_sash = new SashForm(shell, SWT.VERTICAL);
1935: vertical_sash_grid_data = new GridData(GridData.FILL_BOTH);
1936: vertical_sash.setLayoutData(vertical_sash_grid_data);
1937: // vertical_sash.setBackground(display.getSystemColor(SWT.COLOR_RED));
1938:
1939: // horizontal Composite
1940: horizontal_composite = new Composite(vertical_sash,
1941: SWT.FLAT);
1942: // composite.setBackground(display.getSystemColor(SWT.COLOR_RED));
1943: horizontal_composite_layout = new GridLayout();
1944: horizontal_composite_layout.numColumns = 2;
1945: horizontal_composite_layout.marginHeight = 0;
1946: horizontal_composite_layout.marginWidth = 0;
1947: horizontal_composite.setLayout(horizontal_composite_layout);
1948:
1949: // text console
1950: text_console = new Browser(vertical_sash, SWT.BORDER
1951: | SWT.FILL);
1952: appendConsole(htmlFace("GNetWatch - © 2006, 2007<BR/>"));
1953: text_console.addProgressListener(new ProgressListener() {
1954: public void changed(ProgressEvent e) {
1955: }
1956:
1957: public void completed(ProgressEvent e) {
1958: // il faudrait mettre une valeur max plutôt que ça...
1959: if (text_console_do_not_go_on_top > 0)
1960: text_console_do_not_go_on_top--;
1961: else
1962: text_console
1963: .execute("window.scroll(0,1000000);");
1964: }
1965: });
1966:
1967: // set vertical_sash relative weights
1968: vertical_sash.setWeights(new int[] { 4, 1 });
1969:
1970: // Composite for groups at left
1971: groups_composite = new Composite(horizontal_composite,
1972: SWT.FLAT);
1973: groups_composite_layout = new RowLayout(SWT.VERTICAL);
1974: groups_composite_layout.fill = true;
1975: groups_composite_layout.marginTop = 0;
1976: groups_composite_layout.marginBottom = 0;
1977: groups_composite.setLayout(groups_composite_layout);
1978: groups_composite_grid_data = new GridData(
1979: GridData.FILL_VERTICAL);
1980: groups_composite.setLayoutData(groups_composite_grid_data);
1981:
1982: // Group for subnet targets
1983:
1984: group_target_subnet = new Group(groups_composite,
1985: SWT.SHADOW_ETCHED_IN);
1986: group_target_subnet_layout = new GridLayout();
1987: group_target_subnet_layout.numColumns = 2;
1988: group_target_subnet.setLayout(group_target_subnet_layout);
1989: group_target_subnet.setText(getConfig().getString(
1990: "create_network_target"));
1991:
1992: label1 = new Label(group_target_subnet, SWT.SHADOW_IN);
1993: label1.setText(getConfig().getString("address"));
1994: label1
1995: .setLayoutData(new GridData(
1996: GridData.FILL_HORIZONTAL));
1997: target_subnet_address = new Text(group_target_subnet,
1998: SWT.READ_ONLY | SWT.SINGLE);
1999: target_subnet_address.setLayoutData(new GridData(
2000: GridData.HORIZONTAL_ALIGN_END /*| GridData.GRAB_HORIZONTAL*/
2001: | GridData.FILL_VERTICAL));
2002: target_subnet_address.setBackground(new Color(display,
2003: bglevel, bglevel, bglevel));
2004: target_subnet_address.setForeground(display
2005: .getSystemColor(SWT.COLOR_WHITE));
2006: new IpAddressEditor(getConfig(), target_subnet_address);
2007:
2008: label2 = new Label(group_target_subnet, SWT.SHADOW_IN);
2009: label2.setText(getConfig().getString("netmask"));
2010: label2
2011: .setLayoutData(new GridData(
2012: GridData.FILL_HORIZONTAL));
2013: target_subnet_mask = new Text(group_target_subnet,
2014: SWT.READ_ONLY | SWT.SINGLE);
2015: target_subnet_mask.setLayoutData(new GridData(
2016: GridData.HORIZONTAL_ALIGN_END /*| GridData.GRAB_HORIZONTAL*/
2017: | GridData.FILL_VERTICAL));
2018: target_subnet_mask.setBackground(new Color(display,
2019: bglevel, bglevel, bglevel));
2020: target_subnet_mask.setBackground(new Color(display,
2021: bglevel, bglevel, bglevel));
2022: target_subnet_mask.setForeground(display
2023: .getSystemColor(SWT.COLOR_WHITE));
2024: new IpAddressEditor(getConfig(), target_subnet_mask);
2025:
2026: new Label(group_target_subnet, SWT.SHADOW_NONE);
2027:
2028: target_subnet_push = new Button(group_target_subnet,
2029: SWT.PUSH);
2030: target_subnet_push.setText(getConfig().getString(
2031: "add_subnet"));
2032: target_subnet_push.setLayoutData(new GridData(
2033: GridData.HORIZONTAL_ALIGN_FILL));
2034: target_subnet_push
2035: .addSelectionListener(new SelectionListener() {
2036: public void widgetDefaultSelected(
2037: SelectionEvent e) {
2038: try {
2039: synchronized (sync_tree) {
2040: addTargetAtCurrentPosition(new TargetIPv4Subnet(
2041: "added by GUI",
2042: GenericTools
2043: .stringToInet4Address(target_subnet_address
2044: .getText()),
2045: GenericTools
2046: .stringToInet4Address(target_subnet_mask
2047: .getText())));
2048: target_subnet_address
2049: .setText("000.000.000.000");
2050: target_subnet_mask
2051: .setText("000.000.000.000");
2052: }
2053: } catch (final UnknownHostException ex) {
2054: log.error("Exception", ex);
2055: } catch (final AlgorithmException ex) {
2056: log.error("Exception", ex);
2057: System.exit(1);
2058: }
2059: }
2060:
2061: public void widgetSelected(SelectionEvent e) {
2062: widgetDefaultSelected(e);
2063: }
2064: });
2065:
2066: // Group for range targets
2067:
2068: group_target_range = new Group(groups_composite,
2069: SWT.SHADOW_ETCHED_IN);
2070: group_target_range_layout = new GridLayout();
2071: group_target_range_layout.numColumns = 2;
2072: group_target_range.setLayout(group_target_range_layout);
2073: group_target_range.setText(getConfig().getString(
2074: "create_range_target"));
2075:
2076: label3 = new Label(group_target_range, SWT.SHADOW_IN);
2077: label3.setText(getConfig().getString("first_address"));
2078: label3
2079: .setLayoutData(new GridData(
2080: GridData.FILL_HORIZONTAL));
2081: target_range_begin = new Text(group_target_range,
2082: SWT.READ_ONLY | SWT.SINGLE);
2083: target_range_begin.setLayoutData(new GridData(
2084: GridData.HORIZONTAL_ALIGN_END
2085: | GridData.FILL_VERTICAL));
2086: target_range_begin.setBackground(new Color(display,
2087: bglevel, bglevel, bglevel));
2088: target_range_begin.setForeground(display
2089: .getSystemColor(SWT.COLOR_WHITE));
2090: new IpAddressEditor(getConfig(), target_range_begin);
2091:
2092: label4 = new Label(group_target_range, SWT.SHADOW_IN);
2093: label4.setText(getConfig().getString("last_address"));
2094: label4
2095: .setLayoutData(new GridData(
2096: GridData.FILL_HORIZONTAL));
2097: target_range_end = new Text(group_target_range,
2098: SWT.READ_ONLY | SWT.SINGLE);
2099: target_range_end.setLayoutData(new GridData(
2100: GridData.HORIZONTAL_ALIGN_END
2101: | GridData.FILL_VERTICAL));
2102: target_range_end.setBackground(new Color(display, bglevel,
2103: bglevel, bglevel));
2104: target_range_end.setForeground(display
2105: .getSystemColor(SWT.COLOR_WHITE));
2106: new IpAddressEditor(getConfig(), target_range_end);
2107:
2108: new Label(group_target_range, SWT.SHADOW_NONE);
2109:
2110: target_range_push = new Button(group_target_range, SWT.PUSH);
2111: target_range_push.setText(getConfig()
2112: .getString("add_range"));
2113: target_range_push.setLayoutData(new GridData(
2114: GridData.HORIZONTAL_ALIGN_FILL));
2115: target_range_push
2116: .addSelectionListener(new SelectionListener() {
2117: public void widgetDefaultSelected(
2118: SelectionEvent e) {
2119: try {
2120: synchronized (sync_tree) {
2121: addTargetAtCurrentPosition(new TargetIPv4Range(
2122: "added by GUI",
2123: GenericTools
2124: .stringToInet4Address(target_range_begin
2125: .getText()),
2126: GenericTools
2127: .stringToInet4Address(target_range_end
2128: .getText())));
2129: target_range_begin
2130: .setText("000.000.000.000");
2131: target_range_end
2132: .setText("000.000.000.000");
2133: }
2134: } catch (final UnknownHostException ex) {
2135: log.error("Exception", ex);
2136: } catch (final AlgorithmException ex) {
2137: log.error("Exception", ex);
2138: System.exit(1);
2139: }
2140: }
2141:
2142: public void widgetSelected(SelectionEvent e) {
2143: widgetDefaultSelected(e);
2144: }
2145: });
2146:
2147: // Group for host targets
2148:
2149: group_target_host = new Group(groups_composite,
2150: SWT.SHADOW_ETCHED_IN);
2151: group_target_host_layout = new GridLayout();
2152: group_target_host_layout.numColumns = 2;
2153: group_target_host.setLayout(group_target_host_layout);
2154: group_target_host.setText(getConfig().getString(
2155: "create_ipv4_target"));
2156:
2157: label5 = new Label(group_target_host, SWT.SHADOW_IN);
2158: label5.setText(getConfig().getString("host_address"));
2159: label5
2160: .setLayoutData(new GridData(
2161: GridData.FILL_HORIZONTAL));
2162: target_host_value = new Text(group_target_host,
2163: SWT.READ_ONLY | SWT.SINGLE);
2164: target_host_value.setLayoutData(new GridData(
2165: GridData.HORIZONTAL_ALIGN_END
2166: | GridData.FILL_VERTICAL));
2167: target_host_value.setBackground(new Color(display, bglevel,
2168: bglevel, bglevel));
2169: target_host_value.setForeground(display
2170: .getSystemColor(SWT.COLOR_WHITE));
2171: new IpAddressEditor(getConfig(), target_host_value);
2172:
2173: new Label(group_target_host, SWT.SHADOW_NONE);
2174:
2175: target_host_push = new Button(group_target_host, SWT.PUSH);
2176: target_host_push.setText(getConfig().getString(
2177: "add_ipv4_host"));
2178: target_host_push.setLayoutData(new GridData(
2179: GridData.HORIZONTAL_ALIGN_FILL));
2180: target_host_push
2181: .addSelectionListener(new SelectionListener() {
2182: public void widgetDefaultSelected(
2183: SelectionEvent e) {
2184: try {
2185: synchronized (sync_tree) {
2186: final TargetIPv4 foo = new TargetIPv4(
2187: "added by GUI",
2188: GenericTools
2189: .stringToInet4Address(target_host_value
2190: .getText()),
2191: snmp_manager);
2192: if (addTargetAtCurrentPosition(foo) == true)
2193: foo.checkSNMPAwareness();
2194: target_host_value
2195: .setText("000.000.000.000");
2196: }
2197: } catch (final UnknownHostException ex) {
2198: log.error("Exception", ex);
2199: } catch (final AlgorithmException ex) {
2200: log.error("Exception", ex);
2201: System.exit(1);
2202: }
2203: }
2204:
2205: public void widgetSelected(SelectionEvent e) {
2206: widgetDefaultSelected(e);
2207: }
2208: });
2209:
2210: target_host_push.addControlListener(new ControlListener() {
2211: public void controlMoved(final ControlEvent e) {
2212: }
2213:
2214: public void controlResized(final ControlEvent e) {
2215: final GC gc = new GC(target_host_value);
2216: gc.setFont(target_host_value.getFont());
2217: ((GridData) (target_group_value.getLayoutData())).widthHint = gc
2218: .stringExtent(target_host_value.getText()).x;
2219: ((GridData) (target_host6_value.getLayoutData())).widthHint = gc
2220: .stringExtent(target_host_value.getText()).x;
2221: shell.changed(new Control[] { target_group_value,
2222: target_host6_value });
2223: }
2224: });
2225:
2226: // Group for IPv6 targets
2227:
2228: group_target_host6 = new Group(groups_composite,
2229: SWT.SHADOW_ETCHED_IN);
2230: group_target_host6_layout = new GridLayout();
2231: group_target_host6_layout.numColumns = 2;
2232: group_target_host6.setLayout(group_target_host6_layout);
2233: group_target_host6.setText(getConfig().getString(
2234: "create_ipv6_target"));
2235:
2236: label7 = new Label(group_target_host6, SWT.SHADOW_IN);
2237: label7.setText(getConfig().getString("ipv6_address"));
2238: label7
2239: .setLayoutData(new GridData(
2240: GridData.FILL_HORIZONTAL));
2241: target_host6_value = new Text(group_target_host6,
2242: SWT.SINGLE);
2243: target_host6_value.setLayoutData(new GridData(
2244: GridData.HORIZONTAL_ALIGN_END
2245: | GridData.FILL_VERTICAL));
2246: target_host6_value.setBackground(new Color(display,
2247: bglevel, bglevel, bglevel));
2248: target_host6_value.setForeground(display
2249: .getSystemColor(SWT.COLOR_WHITE));
2250:
2251: new Label(group_target_host6, SWT.SHADOW_NONE);
2252:
2253: target_host6_push = new Button(group_target_host6, SWT.PUSH);
2254: target_host6_push.setText(getConfig().getString(
2255: "add_ipv6_host"));
2256: target_host6_push.setLayoutData(new GridData(
2257: GridData.HORIZONTAL_ALIGN_FILL));
2258: target_host6_push
2259: .addSelectionListener(new SelectionListener() {
2260: public void widgetDefaultSelected(
2261: SelectionEvent e) {
2262: try {
2263: final Inet6Address address = GenericTools
2264: .stringToInet6Address(target_host6_value
2265: .getText());
2266: if (address == null) {
2267: final MessageBox dialog = new MessageBox(
2268: shell, SWT.ICON_ERROR
2269: | SWT.OK);
2270: dialog.setText(getConfig()
2271: .getString(
2272: "gnetwatch_error"));
2273: dialog
2274: .setMessage(getConfig()
2275: .getString(
2276: "cannot_parse_ipv6"));
2277: dialog.open();
2278: return;
2279: }
2280: synchronized (sync_tree) {
2281: final TargetIPv6 foo = new TargetIPv6(
2282: "added by GUI", address,
2283: snmp_manager);
2284: if (addTargetAtCurrentPosition(foo) == true)
2285: foo.checkSNMPAwareness();
2286: target_host6_value.setText("");
2287: }
2288: } catch (final UnknownHostException ex) {
2289: log.error("Exception", ex);
2290: final MessageBox dialog = new MessageBox(
2291: shell, SWT.ICON_ERROR | SWT.OK);
2292: dialog.setText("GNetWatch - Error");
2293: dialog
2294: .setMessage(getConfig()
2295: .getString(
2296: "cannot_parse_ipv6"));
2297: dialog.open();
2298: } catch (final AlgorithmException ex) {
2299: log.error("Exception", ex);
2300: System.exit(1);
2301: }
2302: }
2303:
2304: public void widgetSelected(
2305: final SelectionEvent e) {
2306: widgetDefaultSelected(e);
2307: }
2308: });
2309:
2310: // Group for group targets
2311:
2312: group_target_group = new Group(groups_composite,
2313: SWT.SHADOW_ETCHED_IN);
2314: group_target_group_layout = new GridLayout();
2315: group_target_group_layout.numColumns = 2;
2316: group_target_group.setLayout(group_target_group_layout);
2317: group_target_group.setText(getConfig().getString(
2318: "create_group_target"));
2319:
2320: label6 = new Label(group_target_group, SWT.SHADOW_IN);
2321: label6.setText(getConfig().getString("group_name"));
2322: label6
2323: .setLayoutData(new GridData(
2324: GridData.FILL_HORIZONTAL));
2325: target_group_value = new Text(group_target_group,
2326: SWT.SINGLE);
2327: target_group_value.setLayoutData(new GridData(
2328: GridData.HORIZONTAL_ALIGN_END
2329: | GridData.FILL_VERTICAL));
2330: target_group_value.setBackground(new Color(display,
2331: bglevel, bglevel, bglevel));
2332: target_group_value.setForeground(display
2333: .getSystemColor(SWT.COLOR_WHITE));
2334:
2335: new Label(group_target_group, SWT.SHADOW_NONE);
2336:
2337: target_group_push = new Button(group_target_group, SWT.PUSH);
2338: target_group_push.setText(getConfig()
2339: .getString("add_group"));
2340: target_group_push.setLayoutData(new GridData(
2341: GridData.HORIZONTAL_ALIGN_FILL));
2342: target_group_push
2343: .addSelectionListener(new SelectionListener() {
2344: public void widgetDefaultSelected(
2345: SelectionEvent e) {
2346: try {
2347: if (target_group_value.getText() != "")
2348: synchronized (sync_tree) {
2349: addTargetAtCurrentPosition(new TargetGroup(
2350: "added by GUI",
2351: target_group_value
2352: .getText()));
2353: }
2354: else {
2355: final MessageBox dialog = new MessageBox(
2356: shell, SWT.ICON_ERROR
2357: | SWT.OK);
2358: dialog.setText(getConfig()
2359: .getString(
2360: "gnetwatch_error"));
2361: dialog
2362: .setMessage(getConfig()
2363: .getString(
2364: "cannot_add_group"));
2365: dialog.open();
2366: }
2367: target_group_value.setText("");
2368: } catch (final AlgorithmException ex) {
2369: log.error("Exception", ex);
2370: System.exit(1);
2371: }
2372: }
2373:
2374: public void widgetSelected(
2375: final SelectionEvent e) {
2376: widgetDefaultSelected(e);
2377: }
2378: });
2379:
2380: // vertical space (hint to be sure left groups are visible at launch time)
2381: new Label(groups_composite, SWT.SHADOW_ETCHED_IN);
2382:
2383: // group container for data
2384:
2385: /*
2386: group_data = new Group(groups_composite, SWT.SHADOW_ETCHED_IN);
2387: group_data.setText("Data");
2388: group_data_layout = new GridLayout();
2389: group_data_layout.numColumns = 2;
2390: group_data.setLayout(group_target_subnet_layout);
2391: */
2392:
2393: // Sash for Tree and Label
2394: horizontal_sash = new SashForm(horizontal_composite,
2395: SWT.HORIZONTAL);
2396: horizontal_sash_grid_data = new GridData(GridData.FILL_BOTH);
2397: horizontal_sash.setLayoutData(horizontal_sash_grid_data);
2398:
2399: // Tree
2400: tree = new Tree(horizontal_sash, SWT.BORDER | SWT.H_SCROLL
2401: | SWT.V_SCROLL);
2402: tree.addSelectionListener(new SelectionListener() {
2403: public void widgetDefaultSelected(SelectionEvent e) {
2404: if (tree.getSelectionCount() == 1) {
2405: TreeItem current_item = tree.getSelection()[0];
2406: if (current_item != null) {
2407: synchronized (sync_tree) {
2408: final VisualElement visual_element = (VisualElement) current_item
2409: .getData(VisualElement.class
2410: .toString());
2411: if (visual_element != null)
2412: visual_element.informSelected();
2413: }
2414: widgetSelected(e);
2415: }
2416: }
2417: }
2418:
2419: public void widgetSelected(SelectionEvent e) {
2420: if (tree.getSelectionCount() == 1) {
2421: TreeItem current_item = tree.getSelection()[0];
2422: if (current_item != null) {
2423: synchronized (sync_tree) {
2424: final VisualElement visual_element = (VisualElement) current_item
2425: .getData(VisualElement.class
2426: .toString());
2427:
2428: if (visual_element.getProgress() != -1)
2429: setProgress(visual_element
2430: .getProgress());
2431:
2432: if (previous_selection != null)
2433: previous_selection.unselected();
2434: visual_element.selected();
2435: previous_selection = visual_element;
2436:
2437: if (TargetIPv4.class
2438: .isInstance(visual_element)
2439: || TargetIPv6.class
2440: .isInstance(visual_element)) {
2441: menu_item_credentials
2442: .setEnabled(true);
2443: menu_item_ip_options
2444: .setEnabled(true);
2445: menu_item_http_options
2446: .setEnabled(true);
2447: } else {
2448: menu_item_credentials
2449: .setEnabled(false);
2450: menu_item_ip_options
2451: .setEnabled(false);
2452: menu_item_http_options
2453: .setEnabled(false);
2454: }
2455:
2456: if (ActionFlood.class
2457: .isInstance(visual_element)) {
2458: menu_item_add_ping
2459: .setEnabled(false);
2460: menu_item_add_flood
2461: .setEnabled(false);
2462: menu_item_explore_snmp
2463: .setEnabled(false);
2464: menu_item_remove_action
2465: .setEnabled(true);
2466: menu_item_remove_action_ping
2467: .setEnabled(false);
2468: menu_item_remove_action_flood
2469: .setEnabled(true);
2470: menu_item_remove_action_explore
2471: .setEnabled(false);
2472: menu_item_remove_view
2473: .setEnabled(false);
2474: menu_item_remove_view_ping
2475: .setEnabled(false);
2476: menu_item_remove_view_flood
2477: .setEnabled(false);
2478: menu_item_remove_view_explore
2479: .setEnabled(false);
2480: } else if (ActionPing.class
2481: .isInstance(visual_element)) {
2482: menu_item_add_ping
2483: .setEnabled(false);
2484: menu_item_add_flood
2485: .setEnabled(false);
2486: menu_item_explore_snmp
2487: .setEnabled(false);
2488: menu_item_remove_action
2489: .setEnabled(true);
2490: menu_item_remove_action_ping
2491: .setEnabled(true);
2492: menu_item_remove_action_flood
2493: .setEnabled(false);
2494: menu_item_remove_action_explore
2495: .setEnabled(false);
2496: menu_item_remove_view
2497: .setEnabled(false);
2498: menu_item_remove_view_ping
2499: .setEnabled(false);
2500: menu_item_remove_view_flood
2501: .setEnabled(false);
2502: menu_item_remove_view_explore
2503: .setEnabled(false);
2504: } else if (ActionSNMP.class
2505: .isInstance(visual_element)) {
2506: menu_item_add_ping
2507: .setEnabled(false);
2508: menu_item_add_flood
2509: .setEnabled(false);
2510: menu_item_explore_snmp
2511: .setEnabled(false);
2512: menu_item_remove_action
2513: .setEnabled(true);
2514: menu_item_remove_action_ping
2515: .setEnabled(false);
2516: menu_item_remove_action_flood
2517: .setEnabled(false);
2518: menu_item_remove_action_explore
2519: .setEnabled(true);
2520: menu_item_remove_view
2521: .setEnabled(false);
2522: menu_item_remove_view_ping
2523: .setEnabled(false);
2524: menu_item_remove_view_flood
2525: .setEnabled(false);
2526: menu_item_remove_view_explore
2527: .setEnabled(false);
2528: } else if (ReachableView.class
2529: .isInstance(visual_element)) {
2530: menu_item_add_ping
2531: .setEnabled(false);
2532: menu_item_add_flood
2533: .setEnabled(false);
2534: menu_item_explore_snmp
2535: .setEnabled(false);
2536: menu_item_remove_action
2537: .setEnabled(false);
2538: menu_item_remove_action_ping
2539: .setEnabled(false);
2540: menu_item_remove_action_flood
2541: .setEnabled(false);
2542: menu_item_remove_action_explore
2543: .setEnabled(false);
2544: menu_item_remove_view
2545: .setEnabled(true);
2546: menu_item_remove_view_ping
2547: .setEnabled(true);
2548: menu_item_remove_view_flood
2549: .setEnabled(false);
2550: menu_item_remove_view_explore
2551: .setEnabled(false);
2552: } else if (FloodView.class
2553: .isInstance(visual_element)) {
2554: menu_item_add_ping
2555: .setEnabled(false);
2556: menu_item_add_flood
2557: .setEnabled(false);
2558: menu_item_explore_snmp
2559: .setEnabled(false);
2560: menu_item_remove_action
2561: .setEnabled(false);
2562: menu_item_remove_action_ping
2563: .setEnabled(false);
2564: menu_item_remove_action_flood
2565: .setEnabled(false);
2566: menu_item_remove_action_explore
2567: .setEnabled(false);
2568: menu_item_remove_view
2569: .setEnabled(true);
2570: menu_item_remove_view_ping
2571: .setEnabled(false);
2572: menu_item_remove_view_flood
2573: .setEnabled(true);
2574: menu_item_remove_view_explore
2575: .setEnabled(false);
2576: } else if (BytesReceivedView.class
2577: .isInstance(visual_element)
2578: || BytesSentView.class
2579: .isInstance(visual_element)) {
2580: menu_item_add_ping
2581: .setEnabled(false);
2582: menu_item_add_flood
2583: .setEnabled(false);
2584: menu_item_explore_snmp
2585: .setEnabled(false);
2586: menu_item_remove_action
2587: .setEnabled(false);
2588: menu_item_remove_action_ping
2589: .setEnabled(false);
2590: menu_item_remove_action_flood
2591: .setEnabled(false);
2592: menu_item_remove_action_explore
2593: .setEnabled(false);
2594: menu_item_remove_view
2595: .setEnabled(true);
2596: menu_item_remove_view_ping
2597: .setEnabled(false);
2598: menu_item_remove_view_flood
2599: .setEnabled(false);
2600: menu_item_remove_view_explore
2601: .setEnabled(true);
2602: } else {
2603: menu_item_add_ping.setEnabled(true);
2604: menu_item_add_flood
2605: .setEnabled(true);
2606: menu_item_explore_snmp
2607: .setEnabled(true);
2608: menu_item_remove_action
2609: .setEnabled(true);
2610: menu_item_remove_action_ping
2611: .setEnabled(true);
2612: menu_item_remove_action_flood
2613: .setEnabled(true);
2614: menu_item_remove_action_explore
2615: .setEnabled(true);
2616: menu_item_remove_view
2617: .setEnabled(true);
2618: menu_item_remove_view_ping
2619: .setEnabled(true);
2620: menu_item_remove_view_flood
2621: .setEnabled(true);
2622: menu_item_remove_view_explore
2623: .setEnabled(true);
2624: }
2625:
2626: if (net.fenyo.gnetwatch.actions.Action.class
2627: .isInstance(visual_element)) {
2628: setEnableGroupTargetSubnet(false);
2629: setEnableGroupTargetRange(false);
2630: setEnableGroupTargetHost(false);
2631: setEnableGroupTargetGroup(false);
2632: } else if (Target.class
2633: .isInstance(visual_element)) {
2634: try {
2635: boolean foo;
2636:
2637: final TargetGroup target_group = new TargetGroup(
2638: "", "");
2639: target_group.initialize(gui);
2640: foo = target_group
2641: .canAddTarget(visual_element)
2642: && visual_element
2643: .canManageThisChild(target_group);
2644: setEnableGroupTargetGroup(foo);
2645:
2646: // No name service is checked for the validity of the address.
2647: final Inet4Address bar = (Inet4Address) Inet4Address
2648: .getByAddress(
2649: "bar",
2650: new byte[] { 0,
2651: 0, 0, 0 });
2652:
2653: final TargetIPv4 target_ipv4 = new TargetIPv4(
2654: "", bar, null);
2655: target_ipv4.initialize(gui);
2656: foo = target_ipv4
2657: .canAddTarget(visual_element)
2658: && visual_element
2659: .canManageThisChild(target_ipv4);
2660: setEnableGroupTargetHost(foo);
2661:
2662: final TargetIPv4Range target_ipv4_range = new TargetIPv4Range(
2663: "", bar, bar);
2664: target_ipv4_range
2665: .initialize(gui);
2666: foo = target_ipv4_range
2667: .canAddTarget(visual_element)
2668: && visual_element
2669: .canManageThisChild(target_ipv4_range);
2670: setEnableGroupTargetRange(foo);
2671:
2672: final TargetIPv4Subnet target_ipv4_subnet = new TargetIPv4Subnet(
2673: "", bar, bar);
2674: target_ipv4_subnet
2675: .initialize(gui);
2676: foo = target_ipv4_subnet
2677: .canAddTarget(visual_element)
2678: && visual_element
2679: .canManageThisChild(target_ipv4_subnet);
2680: setEnableGroupTargetSubnet(foo);
2681: } catch (final AlgorithmException ex) {
2682: log.error("Exception", ex);
2683: } catch (final UnknownHostException ex) {
2684: log.error("Exception", ex);
2685: }
2686: } else if (net.fenyo.gnetwatch.activities.Queue.class
2687: .isInstance(visual_element)) {
2688: setEnableGroupTargetSubnet(false);
2689: setEnableGroupTargetRange(false);
2690: setEnableGroupTargetHost(false);
2691: setEnableGroupTargetGroup(false);
2692: } else if (DataView.class
2693: .isInstance(visual_element)) {
2694: setEnableGroupTargetSubnet(false);
2695: setEnableGroupTargetRange(false);
2696: setEnableGroupTargetHost(false);
2697: setEnableGroupTargetGroup(false);
2698: } else if (visual_element
2699: .equals(visual_transient)) {
2700: setEnableGroupTargetSubnet(false);
2701: setEnableGroupTargetRange(false);
2702: setEnableGroupTargetHost(false);
2703: setEnableGroupTargetGroup(true);
2704: } else {
2705: setEnableGroupTargetSubnet(false);
2706: setEnableGroupTargetRange(false);
2707: setEnableGroupTargetHost(false);
2708: setEnableGroupTargetGroup(false);
2709: }
2710: }
2711: }
2712: }
2713:
2714: }
2715: });
2716: tree.setHeaderVisible(true);
2717: tree_column1 = new TreeColumn(tree, SWT.LEFT);
2718: tree_column1.setText(getConfig().getString("items"));
2719: tree_column1.setWidth(150);
2720: tree_column2 = new TreeColumn(tree, SWT.LEFT);
2721: tree_column2.setText("Type");
2722: tree_column2.setWidth(50);
2723: tree_column3 = new TreeColumn(tree, SWT.RIGHT);
2724: tree_column3.setText("Description");
2725: tree_column3.setWidth(50);
2726:
2727: // Tree images
2728: image_folder = new Image(display,
2729: "pictures/folder_violet.png");
2730: image_oscillo = new Image(display,
2731: "pictures/oscilloscope-af.png");
2732: image_multirow = new Image(display, "pictures/multirow.png");
2733: image_exec = new Image(display, "pictures/exec.png");
2734: image_watch = new Image(display,
2735: "pictures/yahoo_idle-af.png");
2736: image_host = new Image(display,
2737: "pictures/network_local.png");
2738: image_host6 = new Image(display,
2739: "pictures/network_local-6-af.png");
2740: image_interface = new Image(display, "pictures/memory.png");
2741: image_queue = new Image(display,
2742: "pictures/jabber_group.png");
2743: image_network = new Image(display, "pictures/network.png");
2744: image_host_snmp = new Image(display,
2745: "pictures/network_local_snmp.png");
2746: image_host6_snmp = new Image(display,
2747: "pictures/network_local-6-af-snmp.png");
2748:
2749: visual_root = new VisualElement();
2750: visual_root.setParent(this , tree);
2751: visual_root.setItem(config.getString("collected_data"));
2752:
2753: visual_queues = new VisualElement();
2754: visual_queues.setParent(this , tree);
2755: visual_queues.setItem(config.getString("queues"));
2756:
2757: visual_transient = new VisualElement();
2758: visual_transient.setParent(this , visual_root);
2759: visual_transient.setItem(config.getString("targets"));
2760:
2761: visual_this host = new TargetGroup("added by GUI", config
2762: .getString("local_host"));
2763: visual_this host.setParent(this , visual_transient);
2764:
2765: visual_transient_all = new TargetGroup("added by GUI",
2766: config.getString("every_host"));
2767: visual_transient_all.setParent(this , visual_transient);
2768:
2769: visual_transient_networks = new TargetGroup("added by GUI",
2770: config.getString("every_network"));
2771: visual_transient_networks.setParent(this , visual_transient);
2772:
2773: user_defined = new TargetGroup("added by GUI", config
2774: .getString("user_defined"));
2775: user_defined.setParent(this , visual_transient);
2776: user_defined.setImage(getImageFolder());
2777:
2778: /*
2779: visual_persistent = new VisualElement();
2780: visual_persistent.setParent(this, visual_root);
2781: visual_persistent.setItem("persistent");
2782: visual_persistent.setImage(getImageFolder());
2783:
2784: visual_persistent_all = new VisualElement();
2785: visual_persistent_all.setParent(this, visual_persistent);
2786: visual_persistent_all.setItem("all targets");
2787: visual_persistent_all.setImage(getImageFolder());
2788: */
2789:
2790: for (final Enumeration nifs = NetworkInterface
2791: .getNetworkInterfaces(); nifs.hasMoreElements();) {
2792: final NetworkInterface nif = (NetworkInterface) nifs
2793: .nextElement();
2794: for (final Enumeration addrs = nif.getInetAddresses(); addrs
2795: .hasMoreElements();) {
2796: final InetAddress addr = (InetAddress) addrs
2797: .nextElement();
2798: if (Inet4Address.class.isInstance(addr)) {
2799: final TargetIPv4 foo = new TargetIPv4(
2800: "transient localhost",
2801: (Inet4Address) addr, snmp_manager);
2802: if (foo.addTarget(this , visual_this host) == true)
2803: foo.checkSNMPAwareness();
2804: }
2805:
2806: if (Inet6Address.class.isInstance(addr)) {
2807: // faire un getCanon... pour ipv6
2808: final TargetIPv6 target = new TargetIPv6(
2809: "transient localhost",
2810: (Inet6Address) addr, snmp_manager);
2811: target.setParent(this , visual_this host);
2812: }
2813: }
2814: }
2815:
2816: // CTabFolder
2817: tab_folder = new CTabFolder(horizontal_sash, SWT.BORDER);
2818: tab_folder.setSimple(false);
2819:
2820: tab_item1 = new CTabItem(tab_folder, SWT.None);
2821: tab_item1
2822: .setText(getConfig().getString("about_the_author"));
2823: final Browser browser = new Browser(tab_folder, SWT.BORDER
2824: | SWT.MULTI);
2825: browser.setUrl("http://www.fenyo.net");
2826: // browser.setText("<HTML><BODY BGCOLOR='red'><H1>Data</H1>target: <B>127.0.0.1</B></BODY></HTML>");
2827: tab_item1.setControl(browser);
2828:
2829: tab_item2 = new CTabItem(tab_folder, SWT.None);
2830: tab_item2.setText("Documentation");
2831: final Browser browser2 = new Browser(tab_folder, SWT.BORDER
2832: | SWT.MULTI);
2833: browser2.setUrl("http://gnetwatch.sourceforge.net/docs");
2834: tab_item2.setControl(browser2);
2835:
2836: // StyledText
2837: status = new StyledText(shell, SWT.BORDER);
2838: status_grid_data = new GridData(GridData.FILL_HORIZONTAL);
2839: status.setLayoutData(status_grid_data);
2840: status.setEditable(false);
2841: status.setEnabled(false);
2842: status.setText("Loading...");
2843: status.setBackground(shell.getBackground());
2844:
2845: // ProgressBar
2846: progress_bar = new ProgressBar(shell, SWT.SMOOTH);
2847: progress_bar.setBounds(10, 10, 200, 32);
2848: progress_bar.setSelection(0);
2849: progress_bar_grid_data = new GridData(
2850: GridData.FILL_HORIZONTAL);
2851: progress_bar.setLayoutData(progress_bar_grid_data);
2852:
2853: // instanciate queues
2854:
2855: final String[] queue_names = background.getQueues()
2856: .keySet().toArray(new String[] {});
2857: Arrays.sort(queue_names);
2858: for (final String queue_name : queue_names)
2859: background.getQueues().get(queue_name).setParent(this ,
2860: visual_queues);
2861:
2862: // set initial selections
2863: menu_item_credentials.setEnabled(false);
2864: menu_item_ip_options.setEnabled(false);
2865: menu_item_http_options.setEnabled(false);
2866: setEnableGroupTargetSubnet(false);
2867: setEnableGroupTargetRange(false);
2868: setEnableGroupTargetHost(false);
2869: setEnableGroupTargetGroup(false);
2870:
2871: } // end of synchronization with sync_tree
2872: tree.setBackground(getBackgroundColor());
2873:
2874: // display documentation at startup
2875: tab_folder.setSelection(tab_item2);
2876:
2877: // final operations
2878: shell.pack();
2879: shell.open();
2880:
2881: visual_root.expandTreeItems(true);
2882: visual_queues.expandTreeItems(true);
2883: visual_transient.expandTreeItems(true);
2884: tree.setSelection(visual_root.getTreeItems().get(0));
2885: tree.setFocus();
2886:
2887: synchronized (GUI_created) {
2888: GUI_created[0] = true;
2889: GUI_created.notifyAll();
2890: }
2891:
2892: // list network interfaces at startup
2893: text_console_do_not_go_on_top = 1;
2894: appendNetworkInterfaces();
2895:
2896: awtGUI = new AwtGUI(config);
2897: awtGUI.createAwtGUI();
2898: }
2899:
2900: // Queue thread
2901: public void informTargetHasNewEventClass(final Target target) {
2902: asyncExecIfNeeded(new Runnable() {
2903: public void run() {
2904: views.refreshDataViews(target);
2905: }
2906: });
2907: }
2908:
2909: /**
2910: * Wait for the creation of the GUI objects.
2911: * Can be called from any thread.
2912: * main thread.
2913: * @param none.
2914: * @return void.
2915: */
2916: public void waitForCreation() {
2917: synchronized (GUI_created) {
2918: while (GUI_created[0] == false) {
2919: try {
2920: GUI_created.wait();
2921: } catch (final InterruptedException e) {
2922: log.debug("waitForCreation(): " + e);
2923: }
2924: }
2925: }
2926: }
2927:
2928: /**
2929: * GUI thread.
2930: * @param none.
2931: * @return void.
2932: */
2933: public void run() {
2934: try {
2935: createGUI();
2936: } catch (final Exception ex) {
2937: log.error("Exception", ex);
2938: }
2939:
2940: while (!shell.isDisposed()) {
2941: if (!display.readAndDispatch())
2942: display.sleep();
2943: }
2944:
2945: try {
2946: display.dispose();
2947: } catch (final SWTException ex) {
2948: log.warn("Exception", ex);
2949: }
2950: }
2951:
2952: /**
2953: * Constructor.
2954: * main thread.
2955: * Builds a user interface.
2956: * main thread.
2957: * @param none.
2958: */
2959: public GUI(final Config config, final Background background,
2960: final Main main, final SNMPManager snmp_manager) {
2961: this .config = config;
2962: this .background = background;
2963: this .main = main;
2964: this .snmp_manager = snmp_manager;
2965: this .views = new Views(this );
2966: thread = new Thread(this , "GUI");
2967:
2968: // ((DebugQueue) background.getQueues().get("debug")).setGUI(this);
2969:
2970: thread.start();
2971: }
2972:
2973: // main thread
2974: public void end() throws InterruptedException {
2975: awtGUI.end();
2976: }
2977:
2978: /**
2979: * Waits for the main thread to terminate.
2980: * main thread.
2981: * @param none.
2982: * @return void.
2983: */
2984: public void join() {
2985: try {
2986: thread.join();
2987: } catch (final InterruptedException e) {
2988: log.debug("GUI thread already terminated.");
2989: }
2990: }
2991:
2992: /**
2993: * Enable/disable "add subnet" in the GUI.
2994: * @param enable enable/disable switch.
2995: * @return void.
2996: */
2997: private void setEnableGroupTargetSubnet(final boolean enable) {
2998: label1.setEnabled(enable);
2999: label2.setEnabled(enable);
3000: group_target_subnet.setEnabled(enable);
3001: target_subnet_address.setEnabled(enable);
3002: target_subnet_mask.setEnabled(enable);
3003: target_subnet_push.setEnabled(enable);
3004: menu_item_add_network.setEnabled(enable);
3005: item_add_network.setEnabled(enable);
3006: }
3007:
3008: /**
3009: * Enable/disable "add range" in the GUI.
3010: * @param enable enable/disable switch.
3011: * @return void.
3012: */
3013: private void setEnableGroupTargetRange(final boolean enable) {
3014: label3.setEnabled(enable);
3015: label4.setEnabled(enable);
3016: group_target_range.setEnabled(enable);
3017: target_range_begin.setEnabled(enable);
3018: target_range_end.setEnabled(enable);
3019: target_range_push.setEnabled(enable);
3020: menu_item_add_range.setEnabled(enable);
3021: }
3022:
3023: /**
3024: * Enable/disable "add host" in the GUI.
3025: * @param enable enable/disable switch.
3026: * @return void.
3027: */
3028: private void setEnableGroupTargetHost(final boolean enable) {
3029: label5.setEnabled(enable);
3030: label7.setEnabled(enable);
3031: group_target_host.setEnabled(enable);
3032: group_target_host6.setEnabled(enable);
3033: target_host_value.setEnabled(enable);
3034: target_host6_value.setEnabled(enable);
3035: target_host_push.setEnabled(enable);
3036: target_host6_push.setEnabled(enable);
3037: menu_item_add_host.setEnabled(enable);
3038: menu_item_add_host6.setEnabled(enable);
3039: item_add_host.setEnabled(enable);
3040: }
3041:
3042: /**
3043: * Enable/disable "add group" in the GUI.
3044: * @param enable enable/disable switch.
3045: * @return void.
3046: */
3047: private void setEnableGroupTargetGroup(final boolean enable) {
3048: label6.setEnabled(enable);
3049: group_target_group.setEnabled(enable);
3050: target_group_value.setEnabled(enable);
3051: target_group_push.setEnabled(enable);
3052: menu_item_add_group.setEnabled(enable);
3053: }
3054:
3055: /**
3056: * Parses a configuration file to create initial targets.
3057: * @param filename configuration file.
3058: * @return void.
3059: */
3060: public void createFromXML(final String filename) {
3061: final GUI gui = this ;
3062:
3063: asyncExecIfNeeded(new Runnable() {
3064: public void run() {
3065: try {
3066: final XMLConfiguration initial = new XMLConfiguration(
3067: filename);
3068: initial
3069: .setExpressionEngine(new XPathExpressionEngine());
3070:
3071: // limitation de l'implémentation : on n'autorise que les parents de type groupe
3072:
3073: for (final HierarchicalConfiguration subconf : (java.util.List<HierarchicalConfiguration>) initial
3074: .configurationsAt("/objects/target")) {
3075: if (subconf.getProperty("@targetType").equals(
3076: "group")) {
3077: final String name = subconf
3078: .getString("name");
3079:
3080: final java.util.List<String> parents = (java.util.List<String>) subconf
3081: .getList("parent[@parentType='group']");
3082: if (parents.size() == 0)
3083: new TargetGroup(
3084: "added by initial configuration",
3085: name).addTarget(gui,
3086: user_defined);
3087: else
3088: for (final String parent : parents) {
3089: final TargetGroup foo = new TargetGroup(
3090: "temporary", parent);
3091: final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
3092: if (target_parent == foo)
3093: log
3094: .error("Initial configuration: parent does not exist");
3095: else
3096: new TargetGroup(
3097: "added by initial configuration",
3098: name).addTarget(gui,
3099: target_parent);
3100: }
3101: }
3102:
3103: if (subconf.getProperty("@targetType").equals(
3104: "ipv4")) {
3105: final String address = subconf
3106: .getString("address");
3107:
3108: java.util.List<String> parents = (java.util.List<String>) subconf
3109: .getList("parent[@parentType='group']");
3110: if (parents.size() != 0)
3111: for (final String parent : parents) {
3112: final TargetGroup foo = new TargetGroup(
3113: "temporary", parent);
3114: final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
3115: if (target_parent == foo)
3116: log
3117: .error("Initial configuration: parent does not exist");
3118: else {
3119: final TargetIPv4 target = new TargetIPv4(
3120: "added by initial configuration",
3121: GenericTools
3122: .stringToInet4Address(address),
3123: snmp_manager);
3124: target.addTarget(gui,
3125: target_parent);
3126: if (subconf
3127: .getString("snmp/version") != null) {
3128: if (subconf.getString(
3129: "snmp/version")
3130: .equals("v1"))
3131: target.getSNMPQuerier()
3132: .setVersion(0);
3133: if (subconf.getString(
3134: "snmp/version")
3135: .equals("v2c"))
3136: target.getSNMPQuerier()
3137: .setVersion(1);
3138: if (subconf.getString(
3139: "snmp/version")
3140: .equals("v3"))
3141: target.getSNMPQuerier()
3142: .setVersion(2);
3143: }
3144: if (subconf
3145: .getString("community") != null)
3146: target
3147: .getSNMPQuerier()
3148: .setCommunity(
3149: subconf
3150: .getString("community"));
3151: if (subconf
3152: .getString("password-auth") != null)
3153: target
3154: .getSNMPQuerier()
3155: .setPasswordAuth(
3156: subconf
3157: .getString("password-auth"));
3158: if (subconf
3159: .getString("password-priv") != null)
3160: target
3161: .getSNMPQuerier()
3162: .setPasswordPriv(
3163: subconf
3164: .getString("password-priv"));
3165: if (subconf
3166: .getString("pdu-max-size") != null)
3167: target
3168: .getSNMPQuerier()
3169: .setPDUMaxSize(
3170: subconf
3171: .getInt("pdu-max-size"));
3172: if (subconf.getString("port") != null)
3173: target
3174: .getSNMPQuerier()
3175: .setPort(
3176: subconf
3177: .getInt("port"));
3178: if (subconf
3179: .getString("retries") != null)
3180: target
3181: .getSNMPQuerier()
3182: .setRetries(
3183: subconf
3184: .getInt("retries"));
3185: if (subconf
3186: .getString("security") != null
3187: && subconf
3188: .getString(
3189: "security")
3190: .equals(
3191: "NOAUTH_NOPRIV"))
3192: target
3193: .getSNMPQuerier()
3194: .setSec(
3195: SecurityLevel.NOAUTH_NOPRIV);
3196: if (subconf
3197: .getString("security") != null
3198: && subconf
3199: .getString(
3200: "security")
3201: .equals(
3202: "AUTH_NOPRIV"))
3203: target
3204: .getSNMPQuerier()
3205: .setSec(
3206: SecurityLevel.AUTH_NOPRIV);
3207: if (subconf
3208: .getString("security") != null
3209: && subconf
3210: .getString(
3211: "security")
3212: .equals(
3213: "AUTH_PRIV"))
3214: target
3215: .getSNMPQuerier()
3216: .setSec(
3217: SecurityLevel.AUTH_PRIV);
3218: if (subconf
3219: .getString("timeout") != null)
3220: target
3221: .getSNMPQuerier()
3222: .setTimeout(
3223: subconf
3224: .getInt("timeout"));
3225: target.getSNMPQuerier()
3226: .update();
3227: }
3228: }
3229: }
3230:
3231: if (subconf.getProperty("@targetType").equals(
3232: "ipv6")) {
3233: final String address = subconf
3234: .getString("address");
3235:
3236: java.util.List<String> parents = (java.util.List<String>) subconf
3237: .getList("parent[@parentType='group']");
3238: if (parents.size() != 0)
3239: for (final String parent : parents) {
3240: final TargetGroup foo = new TargetGroup(
3241: "temporary", parent);
3242: final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
3243: if (target_parent == foo)
3244: log
3245: .error("Initial configuration: parent does not exist");
3246: else
3247: new TargetIPv6(
3248: "added by initial configuration",
3249: GenericTools
3250: .stringToInet6Address(address),
3251: snmp_manager)
3252: .addTarget(gui,
3253: target_parent);
3254: }
3255: }
3256:
3257: if (subconf.getProperty("@targetType").equals(
3258: "ipv4range")) {
3259: final String begin = subconf
3260: .getString("begin");
3261: final String end = subconf.getString("end");
3262:
3263: java.util.List<String> parents = (java.util.List<String>) subconf
3264: .getList("parent[@parentType='group']");
3265: if (parents.size() != 0)
3266: for (final String parent : parents) {
3267: final TargetGroup foo = new TargetGroup(
3268: "temporary", parent);
3269: final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
3270: if (target_parent == foo)
3271: log
3272: .error("Initial configuration: parent does not exist");
3273: else
3274: new TargetIPv4Range(
3275: "added by initial configuration",
3276: GenericTools
3277: .stringToInet4Address(begin),
3278: GenericTools
3279: .stringToInet4Address(end))
3280: .addTarget(gui,
3281: target_parent);
3282: }
3283: }
3284:
3285: if (subconf.getProperty("@targetType").equals(
3286: "ipv4subnet")) {
3287: final String network = subconf
3288: .getString("network");
3289: final String netmask = subconf
3290: .getString("netmask");
3291:
3292: java.util.List<String> parents = (java.util.List<String>) subconf
3293: .getList("parent[@parentType='group']");
3294: if (parents.size() != 0)
3295: for (final String parent : parents) {
3296: final TargetGroup foo = new TargetGroup(
3297: "temporary", parent);
3298: final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
3299: if (target_parent == foo)
3300: log
3301: .error("Initial configuration: parent does not exist");
3302: else
3303: new TargetIPv4Subnet(
3304: "added by initial configuration",
3305: GenericTools
3306: .stringToInet4Address(network),
3307: GenericTools
3308: .stringToInet4Address(netmask))
3309: .addTarget(gui,
3310: target_parent);
3311: }
3312: }
3313: }
3314:
3315: // moves the application to the top of the drawing order
3316: shell.setActive();
3317: } catch (final ConfigurationException ex) {
3318: log.warn("Exception", ex);
3319: } catch (final AlgorithmException ex) {
3320: log.error("Exception", ex);
3321: } catch (final UnknownHostException ex) {
3322: log.error("Exception", ex);
3323: }
3324: }
3325: });
3326: }
3327: }
|