use of org.netxms.client.ScheduledTask in project netxms by netxms.
the class ScheduleTableEntryComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
int result;
ScheduledTask task1 = (ScheduledTask) e1;
ScheduledTask task2 = (ScheduledTask) e2;
switch(// $NON-NLS-1$
(Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
case ScheduledTaskView.SCHEDULE_ID:
result = (int) (task1.getId() - task2.getId());
break;
case ScheduledTaskView.CALLBACK_ID:
result = task1.getScheduledTaskId().compareToIgnoreCase(task2.getScheduledTaskId());
break;
case ScheduledTaskView.OBJECT:
AbstractObject obj1 = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(task1.getObjectId());
AbstractObject obj2 = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(task2.getObjectId());
String name1 = (obj1 != null) ? obj1.getObjectName() : "Unknown";
String name2 = (obj2 != null) ? obj2.getObjectName() : "Unknown";
result = name1.compareToIgnoreCase(name2);
break;
case ScheduledTaskView.PARAMETERS:
result = task1.getParameters().compareToIgnoreCase(task2.getParameters());
break;
case ScheduledTaskView.EXECUTION_TIME:
if (task1.getSchedule().isEmpty()) {
if (task2.getSchedule().isEmpty()) {
result = task1.getExecutionTime().compareTo(task2.getExecutionTime());
break;
} else {
result = 1;
break;
}
}
if (task2.getSchedule().isEmpty()) {
result = -1;
}
result = task1.getSchedule().compareToIgnoreCase(task2.getSchedule());
break;
case ScheduledTaskView.LAST_EXECUTION_TIME:
result = task1.getLastExecutionTime().compareTo(task2.getLastExecutionTime());
break;
case ScheduledTaskView.STATUS:
result = task1.getStatus().compareToIgnoreCase(task2.getStatus());
break;
case ScheduledTaskView.OWNER:
String user1 = "";
String user2 = "";
if ((task1.getFlags() & ScheduledTask.SYSTEM) > 0)
user1 = "Internal";
else
user1 = ((NXCSession) ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner()).getName();
if ((task2.getFlags() & ScheduledTask.SYSTEM) > 0)
user2 = "Internal";
else
user2 = ((NXCSession) ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner()).getName();
result = user1.compareTo(user2);
break;
case ScheduledTaskView.COMMENTS:
result = task1.getComments().compareToIgnoreCase(task2.getComments());
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.client.ScheduledTask in project netxms by netxms.
the class ScheduledTaskView method editTask.
/**
* Edit selected task
*/
protected void editTask() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
final ScheduledTask origin = (ScheduledTask) selection.toList().get(0);
new ConsoleJob("Update scheduled task", null, Activator.PLUGIN_ID, null) {
private ScheduledTask task = null;
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<String> taskList = session.listScheduleCallbacks();
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
ScheduledTaskEditor dialog = new ScheduledTaskEditor(getSite().getShell(), origin, taskList);
if (dialog.open() == Window.OK) {
task = dialog.getScheduledTask();
}
}
});
if (task != null)
session.updateSchedule(task);
}
@Override
protected String getErrorMessage() {
return "Cannot update scheduled tasks";
}
}.start();
}
use of org.netxms.client.ScheduledTask in project netxms by netxms.
the class ScheduledTaskView method rescheduleTask.
/**
* Reschedule task
*/
protected void rescheduleTask() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
final ScheduledTask origin = (ScheduledTask) selection.toList().get(0);
final RerunTimeDialog dialog = new RerunTimeDialog(getSite().getShell(), origin.getExecutionTime());
if (dialog.open() != Window.OK)
return;
new ConsoleJob("Reschedule task", null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
origin.setExecutionTime(dialog.getRerunDate());
origin.setFlags(origin.getFlags() & ~ScheduledTask.EXECUTED);
session.updateSchedule(origin);
}
@Override
protected String getErrorMessage() {
return "Cannot reschedule tasks";
}
}.start();
}
use of org.netxms.client.ScheduledTask in project netxms by netxms.
the class ScheduledTaskView method refresh.
/**
* Refresh list
*/
private void refresh() {
new ConsoleJob("Reloading scheduled task list", this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<ScheduledTask> schedules = session.listScheduleTasks();
runInUIThread(new Runnable() {
@Override
public void run() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
viewer.setInput(schedules.toArray());
if (!selection.isEmpty()) {
List<ScheduledTask> newSelection = new ArrayList<ScheduledTask>();
for (Object o : selection.toList()) {
long id = ((ScheduledTask) o).getId();
for (ScheduledTask s : schedules) {
if (s.getId() == id) {
newSelection.add(s);
break;
}
}
}
if (!newSelection.isEmpty())
viewer.setSelection(new StructuredSelection(newSelection));
}
}
});
}
@Override
protected String getErrorMessage() {
return "Cannot get list of scheduled tasks";
}
}.start();
}
use of org.netxms.client.ScheduledTask in project netxms by netxms.
the class ScheduledTaskEditor method okPressed.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
protected void okPressed() {
ScheduledTask task = scheduleSelector.getSchedule();
scheduledTask.setSchedule(task.getSchedule());
scheduledTask.setExecutionTime(task.getExecutionTime());
scheduledTask.setComments(textComments.getText());
if ((scheduledTask.getFlags() & ScheduledTask.SYSTEM) == 0) {
scheduledTask.setScheduledTaskId(scheduleTypeList.get(scheduleType.getSelectionIndex()));
scheduledTask.setParameters(textParameters.getText());
scheduledTask.setObjectId(selector.getObjectId());
}
super.okPressed();
}
Aggregations