Index: src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java (revision 41507) +++ src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java (working copy) @@ -331,7 +331,7 @@ @Override protected void onPageActivated(DataBindingContext dbc) { - final Job j = new Job("Retrieving application's forwardable ports...") { + final Job j = new Job("Loading application's forwardable ports...") { @Override protected IStatus run(IProgressMonitor monitor) { try { @@ -358,8 +358,9 @@ getWizard().getContainer().getShell().close(); } } catch(Exception e) { - // ignore + Logger.error("Failed to open Port-Forwarding wizard page", e); } + } }); } Index: src/org/jboss/tools/openshift/express/internal/core/job/ResultStatus.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/core/job/ResultStatus.java (revision 0) +++ src/org/jboss/tools/openshift/express/internal/core/job/ResultStatus.java (revision 0) @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.openshift.express.internal.core.job; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator; + +/** + * A custom job Status with a way to retrieve some job result after it is done. + * + * @author Xavier Coulon + * + * @param + */ +public class ResultStatus extends Status { + + private final T result; + + /** + * Constructor to use when the job runs correctly and some result needs to + * be retrieved outside of the job, after it has run. The result can be of any type, but the status of the job is {@link IStatus.OK} + * + * @param result the job result + */ + public ResultStatus(T result) { + super(IStatus.OK, OpenShiftUIActivator.PLUGIN_ID, null); + this.result = result; + } + + /** + * Constructor to use of an exception occurred during the job execution. In that case, the job result is set to null. + * @param severity the status severity + * @param message the status message + * @param exception the underlying exception + */ + public ResultStatus(int severity, String message, Throwable exception) { + super(severity, OpenShiftUIActivator.PLUGIN_ID, message, exception); + this.result = null; + } + + + + /** + * @return the result + */ + public T getResult() { + return result; + } + +} Index: src/org/jboss/tools/openshift/express/internal/ui/action/ApplicationPortForwardingAction.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/action/ApplicationPortForwardingAction.java (revision 41507) +++ src/org/jboss/tools/openshift/express/internal/ui/action/ApplicationPortForwardingAction.java (working copy) @@ -2,8 +2,9 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.viewers.ITreeSelection; @@ -11,13 +12,12 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.wst.server.core.IServer; import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils; +import org.jboss.tools.openshift.express.internal.core.job.ResultStatus; import org.jboss.tools.openshift.express.internal.core.portforward.ApplicationPortForwardingWizard; import org.jboss.tools.openshift.express.internal.core.portforward.ApplicationPortForwardingWizardDialog; -import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator; import org.jboss.tools.openshift.express.internal.ui.utils.Logger; import com.openshift.client.IApplication; -import com.openshift.client.OpenShiftSSHOperationException; public class ApplicationPortForwardingAction extends AbstractSSHAction { @@ -54,50 +54,34 @@ @Override protected IStatus run(IProgressMonitor monitor) { final IApplication application = ExpressServerUtils.getApplication(server); - Display.getDefault().asyncExec(new Runnable() { - public void run() { - openPortForwardingDialog(application); - } - }); - return Status.OK_STATUS; + return new ResultStatus(application); } }; - job.setUser(true); - job.schedule(); - } - - private void openPortForwardingDialog(final IApplication application) { - Job job = new Job("Retrieving application's forwardable ports...") { + job.addJobChangeListener(new JobChangeAdapter() { @Override - protected IStatus run(IProgressMonitor monitor) { - try { - verifyApplicationSSHSession(application); - Display.getDefault().asyncExec(new Runnable() { - public void run() { - runAsync(application); - } - }); - return Status.OK_STATUS; - } catch (OpenShiftSSHOperationException e) { - return OpenShiftUIActivator.createErrorStatus(e.getMessage(), e.getCause()); + public void done(IJobChangeEvent event) { + @SuppressWarnings("unchecked") + ResultStatus status = (ResultStatus) event.getResult(); + if (status.isOK()) { + final IApplication application = status.getResult(); + openPortForwardingDialog(application); } } - }; + }); job.setUser(true); job.schedule(); + } - /** - * @param application - */ - private void runAsync(final IApplication application) { + private void openPortForwardingDialog(final IApplication application) { try { ApplicationPortForwardingWizard wizard = new ApplicationPortForwardingWizard( application); - WizardDialog dialog = new ApplicationPortForwardingWizardDialog(Display.getCurrent() + WizardDialog dialog = new ApplicationPortForwardingWizardDialog(Display.getDefault() .getActiveShell(), wizard); dialog.setMinimumPageSize(700, 300); + dialog.setBlockOnOpen(true); dialog.create(); dialog.open(); } catch (Exception e) {