Search in sources :

Example 16 with NXCSession

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

the class OpenAgentConfig method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    IViewReference vr = window.getActivePage().findViewReference(AgentConfigEditorView.ID, Long.toString(nodeId));
    if (vr != null) {
        AgentConfigEditorView view = (AgentConfigEditorView) vr.getView(true);
        if (view != null) {
            window.getActivePage().activate(view);
        }
    } else {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().OpenAgentConfig_GetConfig, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final String config = session.getAgentConfig(nodeId);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            AgentConfigEditorView view = (AgentConfigEditorView) window.getActivePage().showView(AgentConfigEditorView.ID, Long.toString(nodeId), IWorkbenchPage.VIEW_ACTIVATE);
                            view.setConfig(config);
                        } catch (PartInitException e) {
                            MessageDialogHelper.openError(window.getShell(), Messages.get().OpenAgentConfig_Error, Messages.get().OpenAgentConfig_OpenErrorPrefix + e.getLocalizedMessage());
                        }
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().OpenAgentConfig_OpenError;
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) IViewReference(org.eclipse.ui.IViewReference) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) AgentConfigEditorView(org.netxms.ui.eclipse.agentmanager.views.AgentConfigEditorView) PartInitException(org.eclipse.ui.PartInitException)

Example 17 with NXCSession

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

the class AbstractHandler method login.

/**
 * Login to NetXMS server
 * @param login
 * @param password
 * @return SessionToken
 */
protected SessionToken login(String login, String password) throws Exception {
    log.debug("Performing login to " + properties.getServerAddress() + ":" + properties.getServerPort());
    session = new NXCSession(properties.getServerAddress(), properties.getServerPort());
    session.connect();
    session.login(login, (password == null) ? "" : password);
    return SessionStore.getInstance(getServletContext()).registerSession(session);
}
Also used : NXCSession(org.netxms.client.NXCSession)

Example 18 with NXCSession

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

the class ActionSelectionDialog method createDialogArea.

/* (non-Javadoc)
    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createDialogArea(Composite parent) {
    final Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    dialogArea.setLayout(layout);
    viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ActionSelectionDialogLabelProvider());
    viewer.setComparator(new ViewerComparator() {

        /* (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) {
            return ((ServerAction) e1).getName().compareToIgnoreCase(((ServerAction) e2).getName());
        }
    });
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Get server actions", null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<ServerAction> list = session.getActions();
            runInUIThread(new Runnable() {

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

        @Override
        protected String getErrorMessage() {
            return "Cannot get server actions";
        }
    }.start();
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 400;
    viewer.getControl().setLayoutData(gd);
    return dialogArea;
}
Also used : ActionSelectionDialogLabelProvider(org.netxms.ui.eclipse.actionmanager.dialogs.helpers.ActionSelectionDialogLabelProvider) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer) ServerAction(org.netxms.client.ServerAction)

Example 19 with NXCSession

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

the class TunnelManager method refresh.

/**
 * Refresh view
 */
private void refresh() {
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Get list of active agent tunnels", this, Activator.PLUGIN_ID, null) {

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

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

        @Override
        protected String getErrorMessage() {
            return "Cannot get list of active agent tunnels";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 20 with NXCSession

use of org.netxms.client.NXCSession 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)

Aggregations

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10