Search in sources :

Example 1 with AgentTunnel

use of org.netxms.client.AgentTunnel in project netxms by netxms.

the class TunnelManager method fillContextMenu.

/**
 * Fill context menu
 * @param manager Menu manager
 */
protected void fillContextMenu(IMenuManager manager) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if ((selection.size() == 1) && !((AgentTunnel) selection.getFirstElement()).isBound()) {
        manager.add(actionBind);
        manager.add(actionCreateNode);
    } else {
        for (Object o : selection.toList()) {
            if (((AgentTunnel) o).isBound()) {
                manager.add(actionUnbind);
                break;
            }
        }
    }
    manager.add(actionShowFilter);
}
Also used : AgentTunnel(org.netxms.client.AgentTunnel) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with AgentTunnel

use of org.netxms.client.AgentTunnel in project netxms by netxms.

the class TunnelListComparator method compare.

/* (non-Javadoc)
    * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
    */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    AgentTunnel t1 = (AgentTunnel) e1;
    AgentTunnel t2 = (AgentTunnel) e2;
    int result;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case TunnelManager.COL_AGENT_VERSION:
            result = t1.getAgentVersion().compareToIgnoreCase(t2.getAgentVersion());
            break;
        case TunnelManager.COL_CHANNELS:
            result = t1.getActiveChannelCount() - t2.getActiveChannelCount();
            break;
        case TunnelManager.COL_ID:
            result = t1.getId() - t2.getId();
            break;
        case TunnelManager.COL_IP_ADDRESS:
            result = ComparatorHelper.compareInetAddresses(t1.getAddress(), t2.getAddress());
            break;
        case TunnelManager.COL_NODE:
            NXCSession session = ConsoleSharedData.getSession();
            result = session.getObjectName(t1.getNodeId()).compareToIgnoreCase(session.getObjectName(t2.getNodeId()));
            break;
        case TunnelManager.COL_PLATFORM:
            result = t1.getPlatformName().compareToIgnoreCase(t2.getPlatformName());
            break;
        case TunnelManager.COL_STATE:
            result = (t1.isBound() ? 1 : 0) - (t2.isBound() ? 1 : 0);
            break;
        case TunnelManager.COL_SYSINFO:
            result = t1.getSystemInformation().compareToIgnoreCase(t2.getSystemInformation());
            break;
        case TunnelManager.COL_SYSNAME:
            result = t1.getSystemName().compareToIgnoreCase(t2.getSystemName());
            break;
        default:
            result = 0;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : AgentTunnel(org.netxms.client.AgentTunnel) NXCSession(org.netxms.client.NXCSession) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 3 with AgentTunnel

use of org.netxms.client.AgentTunnel in project netxms by netxms.

the class TunnelManager method bindTunnel.

/**
 * Bind tunnel to node
 */
private void bindTunnel() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final AgentTunnel tunnel = (AgentTunnel) selection.getFirstElement();
    if (tunnel.isBound())
        return;
    ObjectSelectionDialog dlg = new ObjectSelectionDialog(getSite().getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
    if (dlg.open() != Window.OK)
        return;
    final long nodeId = dlg.getSelectedObjects().get(0).getObjectId();
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Bind tunnels", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.bindAgentTunnel(tunnel.getId(), nodeId);
            final List<AgentTunnel> tunnels = session.getAgentTunnels();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(tunnels);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot bind tunnel";
        }
    }.start();
}
Also used : AgentTunnel(org.netxms.client.AgentTunnel) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 4 with AgentTunnel

use of org.netxms.client.AgentTunnel in project netxms by netxms.

the class TunnelManager method createNode.

/**
 * Create new node and bind tunnel
 */
private void createNode() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final AgentTunnel tunnel = (AgentTunnel) selection.getFirstElement();
    if (tunnel.isBound())
        return;
    CreateNodeDialog dlg = new CreateNodeDialog(getSite().getShell(), null);
    dlg.setEnableShowAgainFlag(false);
    dlg.setObjectName(tunnel.getSystemName());
    dlg.setZoneUIN(tunnel.getZoneUIN());
    if (dlg.open() != Window.OK)
        return;
    final NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_NODE, dlg.getObjectName(), 2);
    cd.setCreationFlags(dlg.getCreationFlags());
    cd.setPrimaryName(dlg.getHostName());
    cd.setAgentPort(dlg.getAgentPort());
    cd.setSnmpPort(dlg.getSnmpPort());
    cd.setAgentProxyId(dlg.getAgentProxy());
    cd.setSnmpProxyId(dlg.getSnmpProxy());
    cd.setIcmpProxyId(dlg.getIcmpProxy());
    cd.setSshProxyId(dlg.getSshProxy());
    cd.setZoneUIN(dlg.getZoneUIN());
    cd.setSshLogin(dlg.getSshLogin());
    cd.setSshPassword(dlg.getSshPassword());
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Create new node and bind tunnel", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            long nodeId = session.createObject(cd);
            session.bindAgentTunnel(tunnel.getId(), nodeId);
            final List<AgentTunnel> tunnels = session.getAgentTunnels();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(tunnels);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot create node and bind tunnel";
        }
    }.start();
}
Also used : AgentTunnel(org.netxms.client.AgentTunnel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectCreationData(org.netxms.client.NXCObjectCreationData) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) CreateNodeDialog(org.netxms.ui.eclipse.objectmanager.dialogs.CreateNodeDialog)

Example 5 with AgentTunnel

use of org.netxms.client.AgentTunnel in project netxms by netxms.

the class TunnelManager method unbindTunnel.

/**
 * Unbind tunnel
 */
private void unbindTunnel() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    if (!MessageDialogHelper.openQuestion(getSite().getShell(), "Unbind Tunnel", "Selected tunnels will be unbound. Are you sure?"))
        return;
    final Object[] tunnels = selection.toArray();
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Unbind tunnels", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (Object o : tunnels) {
                AgentTunnel t = (AgentTunnel) o;
                if (!t.isBound())
                    continue;
                session.unbindAgentTunnel(t.getNodeId());
            }
            final List<AgentTunnel> tunnels = session.getAgentTunnels();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(tunnels);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot unbind tunnel";
        }
    }.start();
}
Also used : AgentTunnel(org.netxms.client.AgentTunnel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

AgentTunnel (org.netxms.client.AgentTunnel)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 NXCSession (org.netxms.client.NXCSession)4 List (java.util.List)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 AbstractObject (org.netxms.client.objects.AbstractObject)2 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)1 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)1 CreateNodeDialog (org.netxms.ui.eclipse.objectmanager.dialogs.CreateNodeDialog)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1