Search in sources :

Example 1 with DownloadHelper

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();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) MalformedURLException(java.net.MalformedURLException) IPath(org.eclipse.core.runtime.IPath) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) DownloadHelper(org.talend.core.download.DownloadHelper) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageBox(org.eclipse.swt.widgets.MessageBox) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) File(java.io.File)

Aggregations

File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 DownloadHelper (org.talend.core.download.DownloadHelper)1