Example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

Introduction

In this page you can find the example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress.

Prototype

IRunnableWithProgress

Source Link

Usage

From source file:com.aptana.ide.update.internal.manager.P2PluginManager.java

private static ProvisioningPlan getUninstallationProvisioningPlan(final IInstallableUnit[] ius,
        final String profileId) {
    final ProvisioningPlan[] plan = new ProvisioningPlan[1];
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            try {
                ProfileChangeRequest request = ProfileChangeRequest.createByProfileId(profileId);
                request.removeInstallableUnits(ius);
                plan[0] = ProvisioningUtil.getProvisioningPlan(request, new ProvisioningContext(), monitor);
            } catch (ProvisionException e) {
                ProvUI.handleException(e, Messages.ProfileModificationAction_UnexpectedError,
                        StatusManager.BLOCK | StatusManager.LOG);
            }// www. j a v  a  2 s.  co  m
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        ProvUI.handleException(e.getCause(), Messages.ProfileModificationAction_UnexpectedError,
                StatusManager.BLOCK | StatusManager.LOG);
    }
    return plan[0];
}

From source file:com.aptana.jira.ui.preferences.JiraPreferencePageProvider.java

License:Open Source License

private boolean login(boolean test) {
    final String username = usernameText.getText();
    final String password = passwordText.getText();
    if (StringUtil.isEmpty(username)) {
        if (test) {
            MessageDialog.openError(main.getShell(), Messages.JiraPreferencePageProvider_ERR_InvalidInput_Title,
                    Messages.JiraPreferencePageProvider_ERR_EmptyUsername);
            return false;
        }/*from w ww .j  a  v a  2  s.c o m*/
        return true;
    }
    if (StringUtil.isEmpty(password)) {
        if (test) {
            MessageDialog.openError(main.getShell(), Messages.JiraPreferencePageProvider_ERR_InvalidInput_Title,
                    Messages.JiraPreferencePageProvider_ERR_EmptyPassword);
            return false;
        }
        return true;
    }

    setUILocked(true);
    firePreValidationStartEvent();
    try {
        ModalContext.run(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.JiraPreferencePageProvider_ValidateCredentials,
                        IProgressMonitor.UNKNOWN);
                try {
                    getJiraManager().login(username, password);
                    // successful; now re-layout to show the logout components
                    UIUtils.getDisplay().asyncExec(new Runnable() {

                        public void run() {
                            updateUserText();
                            layout();
                        }
                    });
                } catch (JiraException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    if (!monitor.isCanceled()) {
                        monitor.done();
                    }
                }
            }
        }, true, getProgressMonitor(), UIUtils.getDisplay());
    } catch (InvocationTargetException e) {
        if (main != null && !main.isDisposed()) {
            MessageDialog.openError(main.getShell(), Messages.JiraPreferencePageProvider_ERR_LoginFailed_Title,
                    e.getTargetException().getMessage());
        }
        return false;
    } catch (Exception e) {
        IdeLog.logError(JiraUIPlugin.getDefault(), e);
    } finally {
        setUILocked(false);
        firePostValidationEndEvent();
    }

    return true;
}

From source file:com.aptana.portal.ui.eclipse36.dispatch.configurationProcessors.PluginsConfigurationProcessor.java

License:Open Source License

private Collection<IInstallableUnit> getInstallationUnits(final String updateSite, final String featureID,
        final String profileId, final ProvisioningUI provisioningUI) throws InvocationTargetException {
    final List<IInstallableUnit> units = new ArrayList<IInstallableUnit>();

    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, 1);
            sub.setTaskName(Messages.PluginsConfigurationProcessor_locatingFeatures);
            try {
                URI siteURL = new URI(updateSite);
                IMetadataRepository repo = provisioningUI.loadMetadataRepository(siteURL, true,
                        new NullProgressMonitor());
                if (repo == null) {
                    throw new ProvisionException(
                            Messages.PluginsConfigurationProcessor_metadataRepoNotFound + siteURL);
                }//from   w ww .j  a va2 s .  com
                sub.worked(1);
                IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) provisioningUI
                        .getSession().getProvisioningAgent()
                        .getService(IArtifactRepositoryManager.SERVICE_NAME);
                IArtifactRepository artifactRepo = artifactManager.loadRepository(siteURL,
                        new NullProgressMonitor());
                if (artifactRepo == null) {
                    throw new ProvisionException(
                            Messages.PluginsConfigurationProcessor_artifactRepoNotFound + siteURL);
                }
                if (!artifactManager.isEnabled(siteURL)) {
                    artifactManager.setEnabled(siteURL, true);
                }
                sub.worked(1);

                IQuery<IInstallableUnit> query;
                if (featureID == null) {
                    query = QueryUtil.createIUQuery(null, VersionRange.emptyRange);
                } else {
                    query = QueryUtil.createIUQuery(featureID + FEATURE_IU_SUFFIX, VersionRange.emptyRange);
                }
                IQueryResult<IInstallableUnit> roots = repo.query(query, monitor);

                if (roots.isEmpty()) {
                    if (monitor.isCanceled()) {
                        return;
                    }

                    IProfile profile = ProvUI.getProfileRegistry(provisioningUI.getSession())
                            .getProfile(profileId);
                    if (profile != null) {
                        roots = profile.query(query, monitor);
                    } else {
                        // Log this
                        IdeLog.logError(PortalUI36Plugin.getDefault(),
                                MessageFormat.format(
                                        "Error while retrieving the profile for ''{0}'' update site", //$NON-NLS-1$
                                        updateSite),
                                new RuntimeException(MessageFormat.format("The profile for ''{0}'' was null", //$NON-NLS-1$
                                        profileId)));
                    }
                }
                units.addAll(roots.toSet());
                sub.worked(2);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    }
    return units;
}

From source file:com.aptana.projects.internal.wizards.AbstractNewProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    newProject = mainPage.getProjectHandle();
    destPath = mainPage.getLocationPath();
    location = null;/*from  ww w  .  j  a  va  2  s  .  c o m*/
    if (!mainPage.useDefaults()) {
        location = mainPage.getLocationURI();
    } else {
        destPath = destPath.append(newProject.getName());
    }

    if (templatesPage != null) {
        selectedTemplate = templatesPage.getSelectedTemplate();
    }

    if (referencePage != null) {
        refProjects = referencePage.getReferencedProjects();
    }

    boolean success = false;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                createNewProject(monitor);
            }
        });
        success = true;
    } catch (InterruptedException e) {
        StatusManager.getManager().handle(
                new Status(IStatus.ERROR, ProjectsPlugin.PLUGIN_ID, e.getMessage(), e), StatusManager.BLOCK);
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(new Status(IStatus.WARNING, ProjectsPlugin.PLUGIN_ID,
                        NLS.bind(Messages.NewProjectWizard_Warning_DirectoryExists,
                                mainPage.getProjectHandle().getName()),
                        cause));
            } else {
                status = new StatusAdapter(new Status(cause.getStatus().getSeverity(), ProjectsPlugin.PLUGIN_ID,
                        Messages.NewProjectWizard_CreationProblem, cause));
            }
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
                    Messages.NewProjectWizard_CreationProblem);
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ProjectsPlugin.PLUGIN_ID, 0,
                    NLS.bind(Messages.NewProjectWizard_InternalError, t.getMessage()), t));
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
                    Messages.NewProjectWizard_CreationProblem);
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
    }

    if (!success) {
        return false;
    }

    // TODO Run all of this in a job?
    updatePerspective();
    selectAndReveal(newProject);
    openIndexFile();
    sendProjectCreateEvent();

    return true;
}

From source file:com.aptana.projects.wizards.AbstractNewProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    newProject = mainPage.getProjectHandle();
    destPath = mainPage.getLocationPath();
    location = null;//from   ww w  . j  av a2 s. co m
    if (!mainPage.useDefaults()) {
        location = mainPage.getLocationURI();
    } else {
        destPath = destPath.append(newProject.getName());
    }

    if (templatesPage != null) {
        selectedTemplate = templatesPage.getSelectedTemplate();
    }

    if (referencePage != null) {
        refProjects = referencePage.getReferencedProjects();
    }

    boolean success = false;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

                    public void run(IProgressMonitor monitor) throws CoreException {
                        SubMonitor subMonitor = SubMonitor.convert(monitor, 6);
                        try {
                            createNewProject(subMonitor.newChild(4));
                        } catch (InvocationTargetException e) {
                            throw new CoreException(new Status(IStatus.ERROR, ProjectsPlugin.PLUGIN_ID, 0,
                                    e.getMessage(), e.getTargetException()));
                        }

                        // Allow the project contributors to do work
                        ProjectWizardContributionManager projectWizardContributionManager = ProjectsPlugin
                                .getDefault().getProjectWizardContributionManager();
                        final IStatus contributorStatus = projectWizardContributionManager
                                .performProjectFinish(newProject, subMonitor.newChild(1));
                        if (contributorStatus != null && !contributorStatus.isOK()) {
                            // FIXME This UI code shouldn't be here, throw an exception up and handle it!
                            // Show the error. Should we cancel project creation?
                            UIUtils.getDisplay().syncExec(new Runnable() {
                                public void run() {
                                    MessageDialog.openError(UIUtils.getActiveWorkbenchWindow().getShell(),
                                            Messages.AbstractNewProjectWizard_ProjectListenerErrorTitle,
                                            contributorStatus.getMessage());
                                }
                            });
                        }

                        // Perform post project hooks

                        IStudioProjectListener[] projectListeners = new IStudioProjectListener[0];
                        IProjectDescription description = newProject.getDescription();
                        if (description != null) {
                            projectListeners = StudioProjectListenersManager.getManager()
                                    .getProjectListeners(description.getNatureIds());
                        }

                        int listenerSize = projectListeners.length;
                        SubMonitor hookMonitor = SubMonitor.convert(subMonitor.newChild(1),
                                Messages.AbstractNewProjectWizard_ProjectListener_TaskName,
                                Math.max(1, listenerSize));

                        for (IStudioProjectListener projectListener : projectListeners) {
                            if (projectListener != null) {
                                final IStatus status = projectListener.projectCreated(newProject,
                                        hookMonitor.newChild(1));

                                // Show a dialog if there are failures
                                if (status != null && status.matches(IStatus.ERROR)) {
                                    // FIXME This UI code shouldn't be here, throw an exception up and handle it!
                                    UIUtils.getDisplay().syncExec(new Runnable() {
                                        public void run() {
                                            String message = status.getMessage();
                                            if (status instanceof ProcessStatus) {
                                                message = ((ProcessStatus) status).getStdErr();
                                            }
                                            MessageDialog.openError(
                                                    UIUtils.getActiveWorkbenchWindow().getShell(),
                                                    Messages.AbstractNewProjectWizard_ProjectListenerErrorTitle,
                                                    message);
                                        }
                                    });
                                }
                            }
                        }
                    }
                };
                try {
                    ResourcesPlugin.getWorkspace().run(runnable, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e,
                            Messages.AbstractNewProjectWizard_ProjectListener_NoDescriptor_Error);
                }
            }
        });
        success = true;
    } catch (InterruptedException e) {
        StatusManager.getManager().handle(
                new Status(IStatus.ERROR, ProjectsPlugin.PLUGIN_ID, e.getMessage(), e), StatusManager.BLOCK);
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(new Status(IStatus.WARNING, ProjectsPlugin.PLUGIN_ID,
                        NLS.bind(Messages.NewProjectWizard_Warning_DirectoryExists,
                                mainPage.getProjectHandle().getName()),
                        cause));
            } else {
                status = new StatusAdapter(new Status(cause.getStatus().getSeverity(), ProjectsPlugin.PLUGIN_ID,
                        Messages.NewProjectWizard_CreationProblem, cause));
            }
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
                    Messages.NewProjectWizard_CreationProblem);
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ProjectsPlugin.PLUGIN_ID, 0,
                    NLS.bind(Messages.NewProjectWizard_InternalError, t.getMessage()), t));
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
                    Messages.NewProjectWizard_CreationProblem);
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
    }

    if (!success) {
        return false;
    }

    // TODO Run all of this in a job?
    updatePerspective();
    selectAndReveal(newProject);
    openIndexFile();
    sendProjectCreateEvent();

    return true;
}

From source file:com.aptana.samples.ui.project.NewSampleProjectWizard.java

License:Open Source License

private void doBasicCreateProject(IProject project, final IProjectDescription description)
        throws CoreException {
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op = new CreateProjectOperation(description,
                    Messages.NewSampleProjectWizard_CreateOp_Title);
            try {
                // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // directly execute the operation so that the undo state is
                // not preserved. Making this undoable resulted in too many
                // accidental file deletions.
                op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            }// w  w w . j  a va 2  s . c  o  m
        }
    };

    // run the new project creation operation
    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        throw new CoreException(new Status(IStatus.ERROR, SamplesUIPlugin.PLUGIN_ID, e.getMessage(), e));
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(new Status(IStatus.WARNING, SamplesUIPlugin.PLUGIN_ID, MessageFormat
                        .format(Messages.NewSampleProjectWizard_Warning_DirectoryExists, project.getName()),
                        cause));
            } else {
                status = new StatusAdapter(new Status(cause.getStatus().getSeverity(),
                        SamplesUIPlugin.PLUGIN_ID, Messages.NewSampleProjectWizard_CreationProblems, cause));
            }
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
                    Messages.NewSampleProjectWizard_CreationProblems);
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, SamplesUIPlugin.PLUGIN_ID, 0,
                    MessageFormat.format(Messages.NewSampleProjectWizard_InternalError, t.getMessage()), t));
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
                    Messages.NewSampleProjectWizard_CreationProblems);
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
    }
}

From source file:com.aptana.ui.ftp.internal.FTPConnectionPropertyComposite.java

License:Open Source License

public boolean testConnection(ConnectionContext context, final IConnectionRunnable connectRunnable) {
    // WORKAROUND: getting contents after the control is disabled will return empty string if not called here
    hostText.getText();/*from  ww w  .ja va 2  s .co  m*/
    loginCombo.getText();
    passwordText.getText();
    remotePathText.getText();
    lockUI(true);
    ((GridData) progressMonitorPart.getLayoutData()).exclude = false;
    listener.layoutShell();
    try {
        final IBaseRemoteConnectionPoint connectionPoint = isNew ? ftpConnectionPoint
                : (IBaseRemoteConnectionPoint) CoreIOPlugin.getConnectionPointManager()
                        .cloneConnectionPoint(ftpConnectionPoint);
        savePropertiesTo(connectionPoint);
        if (context == null) {
            context = new ConnectionContext(); // $codepro.audit.disable questionableAssignment
            context.setBoolean(ConnectionContext.QUICK_CONNECT, true);
        }
        context.setBoolean(ConnectionContext.NO_PASSWORD_PROMPT, true);
        CoreIOPlugin.setConnectionContext(connectionPoint, context);

        ModalContext.run(new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    try {
                        if (connectRunnable != null) {
                            connectRunnable.beforeConnect(connectionPoint);
                        }
                        connectionPoint.connect(monitor);
                        if (connectRunnable != null) {
                            connectRunnable.afterConnect(connectionPoint, monitor);
                        }
                    } finally {
                        try {
                            connectionPoint.disconnect(monitor);
                        } catch (CoreException e) {
                            IdeLog.logWarning(FTPUIPlugin.getDefault(), e);
                        }
                    }
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    CoreIOPlugin.clearConnectionContext(connectionPoint);
                    monitor.done();
                }
            }
        }, true, progressMonitorPart, getShell().getDisplay());

        return connectionTested = true;
    } catch (InterruptedException e) {
        e.getCause();
    } catch (InvocationTargetException e) {
        showErrorDialog(e.getTargetException());
    } catch (CoreException e) {
        showErrorDialog(e);
    } finally {
        if (!progressMonitorPart.isDisposed()) {
            ((GridData) progressMonitorPart.getLayoutData()).exclude = true;
            listener.layoutShell();
            lockUI(false);
        }
    }
    return false;
}

From source file:com.aptana.ui.properties.ProjectNaturesPage.java

License:Open Source License

@Override
public boolean performOk() {
    if (!fNaturesModified && !isPrimaryNatureModified()) {
        return true;
    }//from  w  w  w .j a  v  a  2 s.c  o  m

    Object[] checkedNatures = fTableViewer.getCheckedElements();
    final List<String> natureIds = new ArrayList<String>();
    for (Object nature : checkedNatures) {
        natureIds.add(nature.toString());
    }
    // promotes the primary nature to the front
    if (fPrimaryNature != null) {
        natureIds.remove(fPrimaryNature);
        natureIds.add(0, fPrimaryNature);
    }

    // set nature ids on the project
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                IProjectDescription description = fProject.getDescription();
                description.setNatureIds(natureIds.toArray(new String[natureIds.size()]));
                fProject.setDescription(description, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    try {
        // this will block until the progress is done
        new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // ignore
    } catch (InvocationTargetException e) {
        IdeLog.logError(UIEplPlugin.getDefault(), EplMessages.ProjectNaturesPage_ERR_SetNatures, e);
        return false;
    }
    resetProject();
    return true;
}

From source file:com.aptana.ui.properties.ProjectNaturesPage.java

License:Open Source License

/**
 * Ask to reset the project (e.g. Close and Open) to apply the changes.
 *///from  w  ww .j av a2s  . c o  m
protected void resetProject() {
    boolean reset = MessageDialog.openQuestion(getControl().getShell(),
            EplMessages.ProjectNaturesPage_ResetTitle, EplMessages.ProjectNaturesPage_ResetMessage);
    if (reset) {
        // close the project
        IRunnableWithProgress close = new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                // use the CloseResourceAction to provide a file saving
                // dialog in case the project has some unsaved
                // files
                UIJob job = new UIJob(EplMessages.ProjectNaturesPage_CloseProjectJob_Title + "...") //$NON-NLS-1$
                {
                    @Override
                    public IStatus runInUIThread(IProgressMonitor monitor) {
                        CloseResourceAction closeAction = new CloseResourceAction(new IShellProvider() {
                            public Shell getShell() {
                                return Display.getDefault().getActiveShell();
                            }
                        });
                        closeAction.selectionChanged(new StructuredSelection(new Object[] { fProject }));
                        closeAction.run();
                        monitor.done();
                        return Status.OK_STATUS;
                    }
                };
                job.schedule();
                try {
                    job.join();
                } catch (InterruptedException e) {
                    // ignore
                }
                monitor.done();
            }
        };
        try {
            new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, close);
        } catch (InterruptedException e) {
            // ignore
        } catch (InvocationTargetException e) {
            IdeLog.logError(UIEplPlugin.getDefault(), EplMessages.ProjectNaturesPage_ERR_CloseProject, e);
        }

        // re-open the project
        IRunnableWithProgress open = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    fProject.open(monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, open);
        } catch (InterruptedException e) {
            // ignore
        } catch (InvocationTargetException e) {
            IdeLog.logError(UIEplPlugin.getDefault(), EplMessages.ProjectNaturesPage_ERR_OpenProject, e);
        }
    }
}

From source file:com.aptana.ui.s3.internal.S3ConnectionPropertyComposite.java

License:Open Source License

public boolean testConnection(ConnectionContext context, final IConnectionRunnable connectRunnable) {
    // WORKAROUND: getting contents after the control is disabled will return empty string if not called here
    hostText.getText();/* ww  w  . ja  v  a  2 s. co  m*/
    accessKeyText.getText();
    passwordText.getText();
    remotePathText.getText();
    lockUI(true);
    ((GridData) progressMonitorPart.getLayoutData()).exclude = false;
    listener.layoutShell();
    try {
        final IBaseRemoteConnectionPoint connectionPoint = isNew ? s3ConnectionPoint
                : (IBaseRemoteConnectionPoint) CoreIOPlugin.getConnectionPointManager()
                        .cloneConnectionPoint(s3ConnectionPoint);
        savePropertiesTo(connectionPoint);
        if (context == null) {
            context = new ConnectionContext();
            context.setBoolean(ConnectionContext.QUICK_CONNECT, true);
        }
        context.setBoolean(ConnectionContext.NO_PASSWORD_PROMPT, true);
        CoreIOPlugin.setConnectionContext(connectionPoint, context);

        ModalContext.run(new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    try {
                        if (connectRunnable != null) {
                            connectRunnable.beforeConnect(connectionPoint);
                        }
                        connectionPoint.connect(monitor);
                        if (connectRunnable != null) {
                            connectRunnable.afterConnect(connectionPoint, monitor);
                        }
                    } finally {
                        try {
                            connectionPoint.disconnect(monitor);
                        } catch (CoreException e) {
                            IdeLog.logWarning(S3UIPlugin.getDefault(), e);
                        }
                    }
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    CoreIOPlugin.clearConnectionContext(connectionPoint);
                    monitor.done();
                }
            }
        }, true, progressMonitorPart, getShell().getDisplay());

        return connectionTested = true;
    } catch (InterruptedException e) {
    } catch (InvocationTargetException e) {
        showErrorDialog(e.getTargetException());
    } catch (CoreException e) {
        showErrorDialog(e);
    } finally {
        if (!progressMonitorPart.isDisposed()) {
            ((GridData) progressMonitorPart.getLayoutData()).exclude = true;
            listener.layoutShell();
            lockUI(false);
        }
    }
    return false;
}