use of org.talend.core.download.DownloadHelper in project tdi-studio-se by Talend.
the class ImportExchangeDialog method okPressed.
@Override
protected void okPressed() {
//$NON-NLS-1$ //$NON-NLS-2$
IPath tempPath = new Path(System.getProperty("user.dir")).append("temp");
File pathFile = tempPath.toFile();
if (downloadproperty.getFileName() == null || downloadproperty.getFileName() == null) {
MessageBox box = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
//$NON-NLS-1$
box.setText(Messages.getString("ImportExchangeDialog.WARNING"));
//$NON-NLS-1$
box.setMessage(Messages.getString("ImportExchangeDialog.NOTSELECTWARNING"));
box.open();
return;
}
tempFile = new File(pathFile, downloadproperty.getFileName());
try {
url = new URL(downloadproperty.getDownloadUrl());
} catch (MalformedURLException e1) {
ExceptionHandler.process(e1);
}
if (!pathFile.exists()) {
pathFile.mkdirs();
}
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell().getShell());
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
//$NON-NLS-1$
monitor.beginTask(Messages.getString("ImportExchangeDialog.downloadProgressBar"), IProgressMonitor.UNKNOWN);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
new DownloadHelper().download(url, tempFile);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
});
monitor.done();
}
};
try {
progressDialog.run(true, true, runnable);
} catch (InvocationTargetException e1) {
ExceptionHandler.process(e1);
} catch (InterruptedException e1) {
ExceptionHandler.process(e1);
}
selectFile = tempFile.toString();
super.okPressed();
}
Aggregations