Search in sources :

Example 31 with NXCSession

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

the class CreateTemplateGroup method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    final CreateObjectDialog dlg = new CreateObjectDialog(window.getShell(), Messages.get().CreateTemplateGroup_TemplateGroup);
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().CreateTemplateGroup_JobTitle, part, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_TEMPLATEGROUP, dlg.getObjectName(), parentId);
            session.createObject(cd);
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().CreateTemplateGroup_JobError, dlg.getObjectName());
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CreateObjectDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog) NXCSession(org.netxms.client.NXCSession) NXCObjectCreationData(org.netxms.client.NXCObjectCreationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 32 with NXCSession

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

the class SummaryTableWidget method forcePoll.

/**
 * @param pollAll
 */
private void forcePoll(boolean pollAll) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    final List<PollRequest> requests = new ArrayList<PollRequest>();
    for (Object o : selection.toList()) {
        TableRow r = (TableRow) o;
        long nodeId = r.getObjectId();
        if (pollAll) {
            int count = ((Table) viewer.getInput()).getColumnCount();
            for (int i = 1; i < count; i++) {
                long dciId = r.get(i).getObjectId();
                if (dciId != 0) {
                    requests.add(new PollRequest(nodeId, dciId));
                }
            }
        } else {
            int index = ((Table) viewer.getInput()).getColumnIndex(currentColumn.getText());
            long dciId = r.get(index).getObjectId();
            if (dciId != 0) {
                requests.add(new PollRequest(nodeId, dciId));
            }
        }
    }
    if (requests.isEmpty())
        return;
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SummaryTableWidget_ForceDciPoll, viewPart, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get().SummaryTableWidget_DciPoll, requests.size());
            for (PollRequest r : requests) {
                session.forceDCIPoll(r.nodeId, r.dciId);
                monitor.worked(1);
            }
            monitor.done();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    refresh();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SummaryTableWidget_13;
        }
    }.start();
}
Also used : Table(org.netxms.client.Table) NXCSession(org.netxms.client.NXCSession) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TableRow(org.netxms.client.TableRow) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 33 with NXCSession

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

the class SummaryTableFilter method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    if (isApply)
        setValid(false);
    table.setNodeFilter(filter.getText());
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SummaryTableFilter_JobName, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            synchronized (table) {
                int id = session.modifyDciSummaryTable(table);
                table.setId(id);
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SummaryTableFilter_JobError;
        }

        /* (non-Javadoc)
			 * @see org.netxms.ui.eclipse.jobs.ConsoleJob#jobFinalize()
			 */
        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        SummaryTableFilter.this.setValid(true);
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 34 with NXCSession

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

the class TableColumns method updateColumnsFromAgent.

/**
 * Update columns from real table
 */
private void updateColumnsFromAgent(final String name, final boolean interactive, final AbstractObject queryObject) {
    final NXCSession session = ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().TableColumns_JobName, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                final org.netxms.client.Table table;
                if (editor.getSourceNode() != 0) {
                    table = session.queryAgentTable(editor.getSourceNode(), name);
                } else {
                    table = session.queryAgentTable((queryObject != null) ? queryObject.getObjectId() : dci.getNodeId(), name);
                }
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        columns.clear();
                        for (int i = 0; i < table.getColumnCount(); i++) {
                            ColumnDefinition c = new ColumnDefinition(table.getColumnName(i), table.getColumnDisplayName(i));
                            c.setDataType(table.getColumnDefinition(i).getDataType());
                            c.setInstanceColumn(table.getColumnDefinition(i).isInstanceColumn());
                            columns.add(c);
                        }
                        columnList.setInput(columns.toArray());
                    }
                });
            } catch (Exception e) {
                Activator.logError("Cannot read table column definition from agent", e);
                if (interactive) {
                    final String msg = (e instanceof NXCException) ? e.getLocalizedMessage() : "Internal error";
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialogHelper.openError(getShell(), "Error", String.format("Cannot read table column definition from agent (%s)", msg));
                        }
                    });
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return null;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition)

Example 35 with NXCSession

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

the class General method performDefaults.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
	 */
@Override
protected void performDefaults() {
    super.performDefaults();
    NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    schedulingMode.select(0);
    pollingInterval.setSelection(session.getDefaultDciPollingInterval());
    statusActive.setSelection(true);
    statusDisabled.setSelection(false);
    statusUnsupported.setSelection(false);
    retentionTime.setSelection(session.getDefaultDciRetentionTime());
    checkInterpretRawSnmpValue.setSelection(false);
    checkUseCustomSnmpPort.setSelection(false);
    customSnmpPort.setSelection(161);
}
Also used : NXCSession(org.netxms.client.NXCSession)

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