Search in sources :

Example 51 with ConsoleJob

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

the class LineChartElement method refreshData.

/**
 * Refresh graph's data
 */
private void refreshData() {
    if (updateInProgress)
        return;
    updateInProgress = true;
    ConsoleJob job = new ConsoleJob(Messages.get().LineChartElement_JobTitle, viewPart, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        private ChartDciConfig currentDci;

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Date from = new Date(System.currentTimeMillis() - config.getTimeRangeMillis());
            final Date to = new Date(System.currentTimeMillis());
            final ChartDciConfig[] dciList = config.getDciList();
            final DciData[] data = new DciData[dciList.length];
            for (int i = 0; i < dciList.length; i++) {
                currentDci = dciList[i];
                if (currentDci.type == ChartDciConfig.ITEM)
                    data[i] = session.getCollectedData(currentDci.nodeId, currentDci.dciId, from, to, 0, false);
                else
                    data[i] = session.getCollectedTableData(currentDci.nodeId, currentDci.dciId, currentDci.instance, currentDci.column, from, to, 0);
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (!((Widget) chart).isDisposed()) {
                        dataCache.clear();
                        chart.setTimeRange(from, to);
                        for (int i = 0; i < data.length; i++) {
                            chart.updateParameter(i, data[i], false);
                            dataCache.add(new DataCacheElement(dciList[i], data[i]));
                        }
                        chart.refresh();
                        chart.clearErrors();
                    }
                    updateInProgress = false;
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().LineChartElement_JobError, session.getObjectName(currentDci.nodeId), currentDci.name);
        }

        @Override
        protected void jobFailureHandler() {
            updateInProgress = false;
            super.jobFailureHandler();
        }

        @Override
        protected IStatus createFailureStatus(final Exception e) {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    chart.addError(getErrorMessage() + " (" + e.getLocalizedMessage() + ")");
                }
            });
            return Status.OK_STATUS;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) Widget(org.eclipse.swt.widgets.Widget) DciData(org.netxms.client.datacollection.DciData) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 52 with ConsoleJob

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

the class AlarmLogViewer method createIssue.

/**
 * Create helpdesk ticket (issue) from selected alarms
 */
private void createIssue() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final long id = Long.parseLong(((TableRow) selection.getFirstElement()).get(0).getValue());
    new ConsoleJob("Create helpdesk ticket", this, Activator.PLUGIN_ID, JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.openHelpdeskIssue(id);
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot create helpdesk ticket from alarm";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TableRow(org.netxms.client.TableRow) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 53 with ConsoleJob

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

the class AlarmLogViewer method unlinkIssue.

/**
 * Unlink helpdesk ticket (issue) from selected alarm
 */
private void unlinkIssue() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final long id = Long.parseLong(((TableRow) selection.getFirstElement()).get(0).getValue());
    new ConsoleJob("Unlink alarm from helpdesk ticket", this, Activator.PLUGIN_ID, JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.unlinkHelpdeskIssue(id);
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot unlink alarm from helpdesk ticket";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TableRow(org.netxms.client.TableRow) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 54 with ConsoleJob

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

the class CloneDashboard method run.

@Override
public void run(final IAction action) {
    final long parentId = sourceObject.getParentIdList()[0];
    final CreateObjectDialog dlg = new CreateObjectDialog(window.getShell(), Messages.get().CloneDashboard_Dashboard);
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().CloneDashboard_JobTitle, part, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_DASHBOARD, dlg.getObjectName(), parentId);
                final long newDashboardId = session.createObject(cd);
                final NXCObjectModificationData md = new NXCObjectModificationData(newDashboardId);
                md.setDashboardElements(sourceObject.getElements());
                md.setColumnCount(sourceObject.getNumColumns());
                md.setObjectFlags(sourceObject.getOptions());
                session.modifyObject(md);
            }

            @Override
            protected String getErrorMessage() {
                return String.format(Messages.get().CloneDashboard_Error, 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) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 55 with ConsoleJob

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

the class CreateDashboardGroup 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(), "Create dashboard group");
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob("Create dashboard group", part, Activator.PLUGIN_ID, null) {

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

        @Override
        protected String getErrorMessage() {
            return String.format("Cannot create dashboard group object %s", 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)

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