use of org.netxms.client.ProgressListener in project netxms by netxms.
the class PackageManager method installPackage.
/**
* Install new package
*/
private void installPackage() {
FileDialog fd = new FileDialog(getSite().getShell(), SWT.OPEN);
fd.setText(Messages.get().PackageManager_SelectFile);
String npiName = fd.open();
if (npiName != null) {
try {
final File npiFile = new File(npiName);
final PackageInfo p = new PackageInfo(npiFile);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().PackageManager_InstallPackage, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
final long id = session.installPackage(p, new File(npiFile.getParent(), p.getFileName()), new ProgressListener() {
long prevAmount = 0;
@Override
public void setTotalWorkAmount(long amount) {
monitor.beginTask(Messages.get(getDisplay()).PackageManager_UploadPackage, (int) amount);
}
@Override
public void markProgress(long amount) {
monitor.worked((int) (amount - prevAmount));
prevAmount = amount;
}
});
p.setId(id);
runInUIThread(new Runnable() {
@Override
public void run() {
packageList.add(p);
viewer.setInput(packageList.toArray());
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().PackageManager_InstallError;
}
}.start();
} catch (IOException e) {
MessageDialogHelper.openError(getSite().getShell(), Messages.get().PackageManager_Error, Messages.get().PackageManager_PkgFileOpenError + e.getLocalizedMessage());
}
}
}
use of org.netxms.client.ProgressListener in project netxms by netxms.
the class AgentFileManager method downloadFile.
/**
* Downloads file
* @throws NXCException
* @throws IOException
*/
private void downloadFile(final AgentFile sf, final String localName, final IProgressMonitor monitor, final boolean subTask, ConsoleJobCallingServerJob job) throws IOException, NXCException {
if (subTask)
monitor.subTask(String.format("Downloading file %s", sf.getFullName()));
final AgentFileData file = session.downloadFileFromAgent(objectId, sf.getFullName(), 0, false, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
if (!subTask)
monitor.beginTask(String.format("Downloading file %s", sf.getFullName()), (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, job);
if (file.getFile() != null) {
File outputFile = new File(localName);
outputFile.createNewFile();
InputStream in = new FileInputStream(file.getFile());
OutputStream out = new FileOutputStream(outputFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
outputFile.setLastModified(sf.getModifyicationTime().getTime());
}
}
use of org.netxms.client.ProgressListener in project netxms by netxms.
the class ImageLibrary method editImage.
/**
* @param galleryItem
* @param name
* @param category
* @param fileName
*/
protected void editImage(final GalleryItem galleryItem, final String name, final String category, final String fileName) {
final LibraryImage image = (LibraryImage) galleryItem.getData();
new ConsoleJob(Messages.get().ImageLibrary_UpdateJob, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
if (fileName != null) {
verifyImageFile(fileName);
FileInputStream stream = null;
try {
final long fileSize = new File(fileName).length();
stream = new FileInputStream(fileName);
byte[] imageData = new byte[(int) fileSize];
stream.read(imageData);
image.setBinaryData(imageData);
} finally {
if (stream != null)
stream.close();
}
}
if (!image.isProtected()) {
image.setName(name);
image.setCategory(category);
}
session.modifyImage(image, new ProgressListener() {
private long prevDone = 0;
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask(Messages.get(getDisplay()).ImageLibrary_UpdateImage, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) (workDone - prevDone));
prevDone = workDone;
}
});
ImageProvider.getInstance(display).syncMetaData();
refreshImages();
/* TODO: update single element */
monitor.done();
}
@Override
protected String getErrorMessage() {
return Messages.get().ImageLibrary_UpdateError;
}
}.start();
}
use of org.netxms.client.ProgressListener 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.client.ProgressListener in project netxms by netxms.
the class ObjectToolExecutor method executeFileDownload.
/**
* @param node
* @param tool
* @param inputValues
* @param inputValues
*/
private static void executeFileDownload(final ObjectContext node, final ObjectTool tool, final Map<String, String> inputValues) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
// $NON-NLS-1$
String[] parameters = tool.getData().split("\u007F");
final String fileName = parameters[0];
final int maxFileSize = Integer.parseInt(parameters[1]);
// $NON-NLS-1$
final boolean follow = parameters[2].equals("true") ? true : false;
ConsoleJobCallingServerJob job = new ConsoleJobCallingServerJob(Messages.get().ObjectToolsDynamicMenu_DownloadFromAgent, null, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, fileName, node.object.getObjectName());
}
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
final AgentFileData file = session.downloadFileFromAgent(node.object.getObjectId(), fileName, maxFileSize, follow, inputValues, node.getAlarmId(), new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask("Download file " + fileName, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, this);
runInUIThread(new Runnable() {
@Override
public void run() {
try {
// $NON-NLS-1$ //$NON-NLS-2$
String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8");
AgentFileViewer.createView(secondaryId, node.object.getObjectId(), file, follow);
} catch (Exception e) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
}
}
});
}
};
job.start();
}
Aggregations