Search in sources :

Example 46 with ConsoleJob

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

the class AlarmList method terminateAlarms.

/**
 * Terminate selected alarms
 */
private void terminateAlarms() {
    IStructuredSelection selection = (IStructuredSelection) alarmViewer.getSelection();
    if (selection.isEmpty())
        return;
    final List<Long> alarmIds = new ArrayList<Long>(selection.size());
    for (Object o : selection.toList()) alarmIds.add(((Alarm) o).getId());
    new ConsoleJob(Messages.get().TerminateAlarm_JobTitle, viewPart, Activator.PLUGIN_ID, AlarmList.JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Map<Long, Integer> terminationFails = session.bulkTerminateAlarms(alarmIds);
            if (!terminationFails.isEmpty()) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        AlarmStateChangeFailureDialog dlg = new AlarmStateChangeFailureDialog(viewPart.getSite().getShell(), terminationFails);
                        if (dlg.open() == Window.OK) {
                            return;
                        }
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().TerminateAlarm_ErrorMessage;
        }
    }.start();
}
Also used : ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) AlarmStateChangeFailureDialog(org.netxms.ui.eclipse.alarmviewer.dialogs.AlarmStateChangeFailureDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Map(java.util.Map) HashMap(java.util.HashMap)

Example 47 with ConsoleJob

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

the class AlarmList method acknowledgeAlarms.

/**
 * Acknowledge selected alarms
 *
 * @param sticky
 */
private void acknowledgeAlarms(final boolean sticky, final int time) {
    IStructuredSelection selection = (IStructuredSelection) alarmViewer.getSelection();
    if (selection.size() == 0)
        return;
    final Object[] alarms = selection.toArray();
    new ConsoleJob(Messages.get().AcknowledgeAlarm_JobName, viewPart, Activator.PLUGIN_ID, AlarmList.JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get(getDisplay()).AcknowledgeAlarm_TaskName, alarms.length);
            for (Object o : alarms) {
                if (monitor.isCanceled())
                    break;
                if (o instanceof Alarm)
                    session.acknowledgeAlarm(((Alarm) o).getId(), sticky, time);
                monitor.worked(1);
            }
            monitor.done();
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().AcknowledgeAlarm_ErrorMessage;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 48 with ConsoleJob

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

the class AlarmList method showIssue.

/**
 * Show in web browser helpdesk ticket (issue) linked to selected alarm
 */
private void showIssue() {
    IStructuredSelection selection = (IStructuredSelection) alarmViewer.getSelection();
    if (selection.size() != 1)
        return;
    final long id = ((Alarm) selection.getFirstElement()).getId();
    new ConsoleJob(Messages.get().AlarmList_JobTitle_ShowTicket, viewPart, Activator.PLUGIN_ID, AlarmList.JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final String url = session.getHelpdeskIssueUrl(id);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
                    launcher.openURL(url);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().AlarmList_JobError_ShowTicket;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UrlLauncher(org.eclipse.rap.rwt.client.service.UrlLauncher) Alarm(org.netxms.client.events.Alarm) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 49 with ConsoleJob

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

the class ExportToCsvAction method run.

/* (non-Javadoc)
	 * @see org.eclipse.jface.action.Action#run()
	 */
@Override
public void run() {
    if (viewerProvider != null)
        viewer = viewerProvider.getViewer();
    final List<String[]> data = new ArrayList<String[]>();
    if (viewer instanceof TableViewer) {
        int numColumns = ((TableViewer) viewer).getTable().getColumnCount();
        if (numColumns == 0)
            numColumns = 1;
        TableColumn[] columns = ((TableViewer) viewer).getTable().getColumns();
        String[] headerRow = new String[numColumns];
        for (int i = 0; i < numColumns; i++) {
            headerRow[i] = columns[i].getText();
        }
        data.add(headerRow);
        TableItem[] selection = selectionOnly ? ((TableViewer) viewer).getTable().getSelection() : ((TableViewer) viewer).getTable().getItems();
        for (TableItem item : selection) {
            String[] row = new String[numColumns];
            for (int i = 0; i < numColumns; i++) row[i] = item.getText(i);
            if (selectionOnly)
                // for some reason RAP implementation returns selected table items in reverse order, so we reverse them here
                data.add(1, row);
            else
                data.add(row);
        }
    } else if (viewer instanceof TreeViewer) {
        int numColumns = ((TreeViewer) viewer).getTree().getColumnCount();
        if (numColumns == 0)
            numColumns = 1;
        TreeItem[] selection = selectionOnly ? ((TreeViewer) viewer).getTree().getSelection() : ((TreeViewer) viewer).getTree().getItems();
        for (TreeItem item : selection) {
            String[] row = new String[numColumns];
            for (int i = 0; i < numColumns; i++) row[i] = item.getText(i);
            data.add(row);
            if (!selectionOnly) {
                addSubItems(item, data, numColumns);
            }
        }
    }
    final String title = viewPart.getTitle();
    new ConsoleJob("Save data to CSV file", viewPart, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final File tmpFile = File.createTempFile("ExportCSV_" + viewPart.hashCode(), "_" + System.currentTimeMillis());
            BufferedWriter out = new BufferedWriter(new FileWriter(tmpFile));
            for (String[] row : data) {
                for (int i = 0; i < row.length; i++) {
                    if (i > 0)
                        out.write(',');
                    out.write('"');
                    // $NON-NLS-1$ //$NON-NLS-2$
                    out.write(row[i].replace("\"", "\"\""));
                    out.write('"');
                }
                out.newLine();
            }
            out.close();
            DownloadServiceHandler.addDownload(tmpFile.getName(), title + ".csv", tmpFile, "text/csv");
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    DownloadServiceHandler.startDownload(tmpFile.getName());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ExportToCsvAction_SaveError;
        }
    }.start();
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TableItem(org.eclipse.swt.widgets.TableItem) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) TableColumn(org.eclipse.swt.widgets.TableColumn) BufferedWriter(java.io.BufferedWriter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File)

Example 50 with ConsoleJob

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

the class SendSMS method run.

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.sendSMS(dlg.getPhoneNumber(), dlg.getMessage());
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    final String message = Messages.get().SendSMS_DialogTextPrefix + dlg.getPhoneNumber() + Messages.get().SendSMS_DialogTextSuffix;
                    MessageDialogHelper.openInformation(window.getShell(), Messages.get().SendSMS_DialogTitle, message);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SendSMS_SendError + dlg.getPhoneNumber();
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) SendSMSDialog(org.netxms.ui.eclipse.console.dialogs.SendSMSDialog)

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