Search in sources :

Example 31 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class SummaryTableManager method editSummaryTable.

/**
 * Edit existing dataset
 */
private void editSummaryTable() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final DciSummaryTableDescriptor d = (DciSummaryTableDescriptor) selection.getFirstElement();
    new ConsoleJob(Messages.get().SummaryTableManager_ReadJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final DciSummaryTable t = session.getDciSummaryTable(d.getId());
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, t);
                    dlg.getShell().setText(Messages.get().SummaryTableManager_TitleEdit);
                    dlg.open();
                    d.updateFromTable(t);
                    viewer.update(d, null);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SummaryTableManager_ReadJobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DciSummaryTable(org.netxms.client.datacollection.DciSummaryTable) PropertyDialog(org.eclipse.ui.internal.dialogs.PropertyDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor) PartInitException(org.eclipse.ui.PartInitException)

Example 32 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class LastValuesWidget method getDataFromServer.

/**
 * Get data from server
 */
private void getDataFromServer() {
    if (dcTarget == null) {
        dataViewer.setInput(new DciValue[0]);
        return;
    }
    ConsoleJob job = new ConsoleJob(Messages.get(getDisplay()).LastValuesWidget_JobTitle + dcTarget.getObjectName(), viewPart, Activator.PLUGIN_ID, LastValuesWidget.JOB_FAMILY, getDisplay()) {

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().LastValuesWidget_JobError, (dcTarget != null) ? dcTarget.getObjectName() : null);
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                final DciValue[] data = session.getLastValues(dcTarget.getObjectId());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        if (!isDisposed()) {
                            dataViewer.setInput(data);
                            hideMessage();
                        }
                    }
                });
            } catch (final Exception e) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        if (!isDisposed()) {
                            showMessage(ERROR, String.format("Cannot read data from server: %s", e.getLocalizedMessage()));
                        }
                    }
                });
            }
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DciValue(org.netxms.client.datacollection.DciValue) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) CoreException(org.eclipse.core.runtime.CoreException)

Example 33 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob 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 34 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob 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 35 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob 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)

Aggregations

ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)330 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)329 NXCSession (org.netxms.client.NXCSession)163 PartInitException (org.eclipse.ui.PartInitException)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)81 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 NXCException (org.netxms.client.NXCException)44 List (java.util.List)38 ArrayList (java.util.ArrayList)34 AbstractObject (org.netxms.client.objects.AbstractObject)33 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 IOException (java.io.IOException)27 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)16 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)13 File (java.io.File)12 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)10 Script (org.netxms.client.Script)10 Table (org.netxms.client.Table)10 CoreException (org.eclipse.core.runtime.CoreException)9 GridData (org.eclipse.swt.layout.GridData)9