Search in sources :

Example 1 with EnterPrimaryHostnameDlg

use of org.netxms.ui.eclipse.topology.dialogs.EnterPrimaryHostnameDlg in project netxms by netxms.

the class FindNodeByPrimaryHostname method run.

/* (non-Javadoc)
    * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
    */
@Override
public void run(IAction action) {
    final EnterPrimaryHostnameDlg dlg = new EnterPrimaryHostnameDlg(window.getShell());
    if (dlg.open() != Window.OK)
        return;
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob("Searching for hostname" + dlg.getHostname() + "in the network", null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<AbstractNode> nodes = session.findNodesByHostname((int) dlg.getZoneId(), dlg.getHostname());
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (nodes != null && !nodes.isEmpty()) {
                        StringBuilder sb = new StringBuilder();
                        sb.append("The following nodes matching the criteria have been found: ");
                        for (int i = 0; i < nodes.size(); i++) {
                            sb.append("\n" + nodes.get(i).getPrimaryName());
                        }
                        MessageDialogHelper.openInformation(shell, "Result", sb.toString());
                    } else
                        MessageDialogHelper.openInformation(shell, "Result", "No nodes found!");
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Search for hostname" + dlg.getHostname() + "failed.";
        }
    }.start();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) EnterPrimaryHostnameDlg(org.netxms.ui.eclipse.topology.dialogs.EnterPrimaryHostnameDlg) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Shell (org.eclipse.swt.widgets.Shell)1 NXCSession (org.netxms.client.NXCSession)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 EnterPrimaryHostnameDlg (org.netxms.ui.eclipse.topology.dialogs.EnterPrimaryHostnameDlg)1