Author: xcoulon
Date: 2012-05-30 16:06:22 -0400 (Wed, 30 May 2012)
New Revision: 41548
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/RetrieveApplicationJob.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/VerifySSHSessionJob.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ApplicationPortForwardingAction.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java
Log:
Fixed - JBIDE-12018
first time I open Port forwarding on an app it pops up the dialog and closes it again
instantly
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java 2012-05-30
19:57:55 UTC (rev 41547)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java 2012-05-30
20:06:22 UTC (rev 41548)
@@ -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 {
@@ -350,18 +350,11 @@
}
};
- getContainer().getShell().getDisplay().asyncExec(new Runnable() {
- public void run() {
- try {
- IStatus status = WizardUtils.runInWizard(j, getContainer(),
getDataBindingContext());
- if(!status.isOK()) {
- getWizard().getContainer().getShell().close();
- }
- } catch(Exception e) {
- // ignore
- }
- }
- });
+ try {
+ WizardUtils.runInWizard(j, getContainer(), getDataBindingContext());
+ } catch (Exception e) {
+ Logger.error("Failed to load application's forwardable ports", e);
+ }
}
private void refreshViewerInput() {
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ApplicationPortForwardingAction.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ApplicationPortForwardingAction.java 2012-05-30
19:57:55 UTC (rev 41547)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ApplicationPortForwardingAction.java 2012-05-30
20:06:22 UTC (rev 41548)
@@ -1,25 +1,22 @@
package org.jboss.tools.openshift.express.internal.ui.action;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+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;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
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.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 org.jboss.tools.openshift.express.internal.ui.job.RetrieveApplicationJob;
+import org.jboss.tools.openshift.express.internal.ui.job.VerifySSHSessionJob;
import com.openshift.client.IApplication;
-import com.openshift.client.OpenShiftSSHOperationException;
-public class ApplicationPortForwardingAction extends AbstractSSHAction {
+public class ApplicationPortForwardingAction extends AbstractAction {
public ApplicationPortForwardingAction() {
super("Port forwarding...",
DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_LCL_DISCONNECT));
@@ -35,9 +32,9 @@
if (selection != null && selection instanceof ITreeSelection) {
Object sel = ((ITreeSelection) selection).getFirstElement();
if (sel instanceof IApplication) {
- openPortForwardingDialog((IApplication) sel);
+ openPortForwardingDialogFor((IApplication) sel);
} else if (sel instanceof IServer) {
- openPortForwardingDialog((IServer) sel);
+ openPortForwardingDialogFor((IServer) sel);
}
}
}
@@ -49,62 +46,53 @@
*
* @param server
*/
- private void openPortForwardingDialog(final IServer server) {
- Job job = new Job("Identifying OpenShift Application from selected
Server...") {
+ private void openPortForwardingDialogFor(final IServer server) {
+ final RetrieveApplicationJob job = new RetrieveApplicationJob(server);
+ job.addJobChangeListener(new JobChangeAdapter() {
@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;
+ public void done(IJobChangeEvent event) {
+ if (event.getResult().isOK()) {
+ final IApplication application = job.getApplication();
+ openPortForwardingDialogFor(application);
+ }
}
- };
+ });
job.setUser(true);
job.schedule();
}
- private void openPortForwardingDialog(final IApplication application) {
- Job job = new Job("Retrieving application's forwardable ports...") {
+ private void openPortForwardingDialogFor(final IApplication application) {
+ final VerifySSHSessionJob job = new VerifySSHSessionJob(application);
+ 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) {
+ if (event.getResult().isOK() && job.isValidSession()) {
+ openWizardDialog(application);
}
}
- };
+ });
+
job.setUser(true);
job.schedule();
}
/**
+ * Opens the Port Forwarding dialog for good...
+ *
* @param application
*/
- private void runAsync(final IApplication application) {
- try {
- ApplicationPortForwardingWizard wizard = new ApplicationPortForwardingWizard(
- application);
- WizardDialog dialog = new ApplicationPortForwardingWizardDialog(Display.getCurrent()
- .getActiveShell(),
- wizard);
- dialog.setMinimumPageSize(700, 300);
- dialog.create();
- dialog.open();
- } catch (Exception e) {
- Logger.error(
- "Failed to perform 'port-forwarding' for application '" +
application.getName()
- + "'", e);
- }
+ private void openWizardDialog(final IApplication application) {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ ApplicationPortForwardingWizard wizard = new ApplicationPortForwardingWizard(
+ application);
+ WizardDialog dialog = new
ApplicationPortForwardingWizardDialog(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(),
+ wizard);
+ dialog.setMinimumPageSize(700, 300);
+ dialog.create();
+ dialog.open();
+ }
+ });
}
-
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java 2012-05-30
19:57:55 UTC (rev 41547)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java 2012-05-30
20:06:22 UTC (rev 41548)
@@ -12,28 +12,26 @@
import java.util.List;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.wst.server.core.IServer;
-import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.console.ConsoleUtils;
+import org.jboss.tools.openshift.express.internal.ui.job.RetrieveApplicationJob;
+import org.jboss.tools.openshift.express.internal.ui.job.VerifySSHSessionJob;
import
org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
import org.jboss.tools.openshift.express.internal.ui.utils.OpenShiftSshSessionFactory;
import com.openshift.client.IApplication;
-import com.openshift.client.OpenShiftSSHOperationException;
/**
* @author Xavier Coulon
*/
-public class ShowEnvironmentAction extends AbstractSSHAction {
+public class ShowEnvironmentAction extends AbstractAction {
public ShowEnvironmentAction() {
super(OpenShiftExpressUIMessages.SHOW_ENVIRONMENT_ACTION, true);
@@ -49,10 +47,10 @@
final ITreeSelection treeSelection = (ITreeSelection) selection;
if (selection instanceof ITreeSelection && treeSelection.getFirstElement()
instanceof IApplication) {
final IApplication application = (IApplication) treeSelection.getFirstElement();
- showEnvironmentProperties(application);
+ showEnvironmentPropertiesFor(application);
} else if (selection instanceof ITreeSelection &&
treeSelection.getFirstElement() instanceof IServer) {
final IServer server = (IServer) treeSelection.getFirstElement();
- showEnvironmentProperties(server);
+ showEnvironmentPropertiesFor(server);
}
}
@@ -64,40 +62,37 @@
*
* @param server
*/
- private void showEnvironmentProperties(final IServer server) {
- Job job = new Job("Identifying OpenShift Application from selected
Server...") {
+ private void showEnvironmentPropertiesFor(final IServer server) {
+ final RetrieveApplicationJob job = new RetrieveApplicationJob(server);
+ job.addJobChangeListener(new JobChangeAdapter() {
@Override
- protected IStatus run(IProgressMonitor monitor) {
- final IApplication application = ExpressServerUtils.getApplication(server);
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- showEnvironmentProperties(application);
- }
- });
- return Status.OK_STATUS;
+ public void done(IJobChangeEvent event) {
+ if (event.getResult().isOK()) {
+ final IApplication application = job.getApplication();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ showEnvironmentPropertiesFor(application);
+ }
+ });
+ }
}
- };
+ });
job.setUser(true);
job.schedule();
}
- private void showEnvironmentProperties(final IApplication application) {
- Job job = new Job("Retrieving selected OpenShift Application's environment
variables...") {
+ private void showEnvironmentPropertiesFor(final IApplication application) {
+ final VerifySSHSessionJob job = new VerifySSHSessionJob(application);
+ 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) {
+ if(event.getResult().isOK() && job.isValidSession()) {
+ showEnvironmentProperties(application);
}
}
- };
+ });
+
job.setUser(true);
job.schedule();
}
@@ -105,22 +100,27 @@
/**
* @param application
*/
- private void runAsync(final IApplication application) {
- try {
- if (!application.hasSSHSession()) {
- application.setSSHSession(OpenShiftSshSessionFactory.getInstance().createSession(application));
+ private void showEnvironmentProperties(final IApplication application) {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ if (!application.hasSSHSession()) {
+ application.setSSHSession(OpenShiftSshSessionFactory.getInstance().createSession(application));
+ }
+ List<String> props = application.getEnvironmentProperties();
+ final MessageConsole console =
ConsoleUtils.findMessageConsole(getMessageConsoleName(application));
+ console.clearConsole();
+ MessageConsoleStream stream = console.newMessageStream();
+ for (String prop : props) {
+ stream.println(prop);
+ }
+ ConsoleUtils.displayConsoleView(console);
+ } catch (Exception e) {
+ OpenShiftUIActivator.createErrorStatus("Failed to display remote environment
variables", e);
+ }
}
- List<String> props = application.getEnvironmentProperties();
- final MessageConsole console =
ConsoleUtils.findMessageConsole(getMessageConsoleName(application));
- console.clearConsole();
- MessageConsoleStream stream = console.newMessageStream();
- for (String prop : props) {
- stream.println(prop);
- }
- ConsoleUtils.displayConsoleView(console);
- } catch (Exception e) {
- OpenShiftUIActivator.createErrorStatus("Failed to display remote environment
variables", e);
- }
+ });
}
/**
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/RetrieveApplicationJob.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/RetrieveApplicationJob.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/RetrieveApplicationJob.java 2012-05-30
20:06:22 UTC (rev 41548)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.ui.job;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+import com.openshift.client.IApplication;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class RetrieveApplicationJob extends Job {
+
+ private IApplication application = null;
+
+ private final IServer server;
+
+ public RetrieveApplicationJob(final IServer server) {
+ super("Identifying OpenShift Application from selected Server...");
+ this.server = server;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ this.application = ExpressServerUtils.getApplication(server);
+ if(application == null) {
+ return OpenShiftUIActivator.createErrorStatus("Failed to retrieve Application
from the selected Server.\n" +
+ "Please verify that the associated OpenShift Application still exists.");
+ }
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * @return the application
+ */
+ public final IApplication getApplication() {
+ return application;
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/RetrieveApplicationJob.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/VerifySSHSessionJob.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/VerifySSHSessionJob.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/VerifySSHSessionJob.java 2012-05-30
20:06:22 UTC (rev 41548)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.ui.job;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
+import org.jboss.tools.openshift.express.internal.ui.utils.OpenShiftSshSessionFactory;
+
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import com.openshift.client.IApplication;
+import com.openshift.client.OpenShiftSSHOperationException;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class VerifySSHSessionJob extends Job {
+
+ private final IApplication application;
+
+ private boolean validSession = false;
+
+ public VerifySSHSessionJob(final IApplication application) {
+ super("Verifying SSH session to retrieve Application's ports...");
+ this.application = application;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ final boolean hasAlreadySSHSession = application.hasSSHSession();
+ if (!hasAlreadySSHSession) {
+ Logger.debug("Opening a new SSH Session for application '" +
application.getName() + "'");
+ Session session;
+ session = OpenShiftSshSessionFactory.getInstance().createSession(
+ application);
+ application.setSSHSession(session);
+ }
+ // now, check if the session is valid (ie, not null and still
+ // connected)
+ this.validSession = application.hasSSHSession();
+ return Status.OK_STATUS;
+ } catch (OpenShiftSSHOperationException e) {
+ return OpenShiftUIActivator.createErrorStatus(e.getMessage(), e.getCause());
+ }
+ }
+
+ /**
+ * @return the hasSession
+ */
+ public final boolean isValidSession() {
+ return validSession;
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/job/VerifySSHSessionJob.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java 2012-05-30
19:57:55 UTC (rev 41547)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java 2012-05-30
20:06:22 UTC (rev 41548)
@@ -446,6 +446,7 @@
@Override
public UserDelegate setUser(UserDelegate user) {
+ UserDelegate oldValue = (UserDelegate) getProperty(USER);
return (UserDelegate) setProperty(USER, user);
}