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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations