use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class ImageLibrary method uploadNewImage.
/**
* @param name
* @param category
* @param fileName
*/
protected void uploadNewImage(final String name, final String category, final String fileName) {
new ConsoleJob(Messages.get().ImageLibrary_UploadJob, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
verifyImageFile(fileName);
final LibraryImage image = new LibraryImage();
final long fileSize = new File(fileName).length();
FileInputStream stream = null;
try {
stream = new FileInputStream(fileName);
byte[] imageData = new byte[(int) fileSize];
stream.read(imageData);
image.setBinaryData(imageData);
image.setName(name);
image.setCategory(category);
} finally {
if (stream != null)
stream.close();
}
session.createImage(image, new ProgressListener() {
private long prevDone = 0;
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask(Messages.get(getDisplay()).ImageLibrary_UploadImage, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) (workDone - prevDone));
prevDone = workDone;
}
});
// TODO: check
ImageProvider.getInstance(display).syncMetaData();
refreshImages();
/* TODO: update local copy */
monitor.done();
}
@Override
protected String getErrorMessage() {
return Messages.get().ImageLibrary_UploadError;
}
}.start();
}
use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class ViewAgentFilesProvider method getChildren.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
@Override
public Object[] getChildren(final Object parentElement) {
if (((AgentFile) parentElement).getChildren() == null) {
ConsoleJob job = new ConsoleJob(Messages.get().ViewAgentFilesProvider_JobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<AgentFile> files = session.listAgentFiles(((AgentFile) parentElement), ((AgentFile) parentElement).getFullName(), ((AgentFile) parentElement).getNodeId());
runInUIThread(new Runnable() {
@Override
public void run() {
((AgentFile) parentElement).setChildren(files);
((StructuredViewer) viewer).refresh(parentElement);
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().ViewAgentFilesProvider_JobError;
}
};
job.setUser(false);
job.start();
return new AgentFile[] { new AgentFile(Messages.get().ViewAgentFilesProvider_Loading, AgentFile.PLACEHOLDER, (AgentFile) parentElement, ((AgentFile) parentElement).getNodeId()) };
}
return ((AgentFile) parentElement).getChildren().toArray();
}
use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class DynamicFileViewer method startTracking.
/**
* Start file change tracking
*
* @param nodeId
* @param fileId
*/
public void startTracking(final long nodeId, final String fileId, final String remoteFileName) {
if (restartJob != null)
restartJob.cancel();
if (monitoringJob != null)
monitoringJob.cancel();
hideMessage();
this.fileId = fileId;
this.nodeId = nodeId;
this.remoteFileName = remoteFileName;
// text.setTopIndex(text.getLineCount() - 1);
monitoringJob = new ConsoleJob(Messages.get().DynamicFileViewer_TrackFileChanges, null, Activator.PLUGIN_ID, null) {
private boolean tracking = true;
@Override
protected void canceling() {
tracking = false;
}
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
while (tracking) {
final String s = session.waitForFileTail(fileId, 3000);
if (s != null) {
runInUIThread(new Runnable() {
@Override
public void run() {
if (!text.isDisposed()) {
append(s);
} else {
tracking = false;
}
}
});
}
}
session.cancelFileMonitoring(nodeId, fileId);
}
@Override
protected String getErrorMessage() {
return Messages.get().DynamicFileViewer_FileTrackingFailed;
}
};
monitoringJob.setUser(false);
monitoringJob.setSystem(true);
monitoringJob.start();
}
use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class EventObjectList method refreshView.
/**
* Refresh view
*/
private void refreshView() {
new ConsoleJob(Messages.get().EventConfigurator_OpenJob_Title, null, Activator.PLUGIN_ID, JOB_FAMILY) {
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.jobs.ConsoleJob#getErrorMessage()
*/
@Override
protected String getErrorMessage() {
return Messages.get().EventConfigurator_OpenJob_Error;
}
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.jobs.ConsoleJob#runInternal(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<EventObject> list = session.getEventObjects();
runInUIThread(new Runnable() {
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
eventObjects = new HashMap<Long, EventObject>(list.size());
for (final EventObject o : list) {
if ((o instanceof EventGroup) && !showGroups)
continue;
eventObjects.put(o.getCode(), o);
}
viewer.setInput(eventObjects.values().toArray());
}
});
}
}.start();
}
use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.
the class MapBackground method applyChanges.
/**
* Apply changes
*
* @param isApply true if update operation caused by "Apply" button
*/
protected boolean applyChanges(final boolean isApply) {
final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
if (radioTypeNone.getSelection()) {
md.setMapBackground(NXCommon.EMPTY_GUID, new GeoLocation(false), 0, ColorConverter.rgbToInt(backgroundColor.getColorValue()));
} else if (radioTypeImage.getSelection()) {
md.setMapBackground(image.getImageGuid(), new GeoLocation(false), 0, ColorConverter.rgbToInt(backgroundColor.getColorValue()));
} else if (!disableGeolocationBackground && radioTypeGeoMap.getSelection()) {
GeoLocation location;
try {
location = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
} catch (GeoLocationFormatException e) {
MessageDialogHelper.openError(getShell(), Messages.get().MapBackground_Error, Messages.get().MapBackground_GeoLocFormatError);
return false;
}
md.setMapBackground(NetworkMap.GEOMAP_BACKGROUND, location, zoomSpinner.getSelection(), ColorConverter.rgbToInt(backgroundColor.getColorValue()));
}
if (isApply)
setValid(false);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().MapBackground_JobTitle + object.getObjectName(), null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.modifyObject(md);
}
@Override
protected String getErrorMessage() {
return Messages.get().MapBackground_JobError + object.getObjectName();
}
@Override
protected void jobFinalize() {
if (isApply) {
runInUIThread(new Runnable() {
@Override
public void run() {
MapBackground.this.setValid(true);
}
});
}
}
}.start();
return true;
}
Aggregations