Author: adietish
Date: 2010-11-15 14:35:05 -0500 (Mon, 15 Nov 2010)
New Revision: 26582
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/ShowInRemoteSystemExplorerHandler.java
Log:
[JBIDE-7603] added error dialogs and cleaned code
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/ShowInRemoteSystemExplorerHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/ShowInRemoteSystemExplorerHandler.java 2010-11-15
19:16:39 UTC (rev 26581)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/ShowInRemoteSystemExplorerHandler.java 2010-11-15
19:35:05 UTC (rev 26582)
@@ -18,6 +18,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.rse.core.IRSECoreRegistry;
@@ -28,9 +29,11 @@
import org.eclipse.rse.core.model.SystemStartHere;
import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
@@ -49,70 +52,46 @@
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
DeltaCloudInstance instance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
- launchRemoteSystemExplorer(instance);
+ Shell shell = HandlerUtil.getActiveShell(event);
+ try {
+ launchRemoteSystemExplorer(instance, shell);
+ } catch (Exception e) {
+ return showCannotLaunchRSEErrorDialog(instance, shell, e);
+ }
}
return Status.OK_STATUS;
}
- private void launchRemoteSystemExplorer(DeltaCloudInstance instance) {
+ private void launchRemoteSystemExplorer(final DeltaCloudInstance instance, final Shell
shell) throws Exception {
String hostname = instance.getHostName();
IRSESystemType sshType = getRSESystemType();
String connectionName = instance.getName() + " [" + instance.getId() +
"]"; //$NON-NLS-1$ //$NON-NLS-2$
- try {
- ISystemRegistry registry = SystemStartHere.getSystemRegistry();
- IHost host = registry.createHost(sshType, connectionName, hostname, null);
- if (host != null) {
- host.setDefaultUserId("root"); //$NON-NLS-1$
- IConnectorService[] services = host.getConnectorServices();
- if (services.length > 0) {
- final IConnectorService service = services[0];
- Job connect = new Job(CVMessages.getFormattedString(RSE_CONNECTING_MSG,
connectionName)) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- service.connect(monitor);
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage()
- .showView(VIEW_REMOTESYSEXPLORER_ID);
- } catch (PartInitException e) {
- // TODO Auto-generated catch
- // block
- Activator.log(e);
- }
- }
- });
- return Status.OK_STATUS;
- } catch (Exception e) {
- return Status.CANCEL_STATUS;
- }
- }
- };
- connect.setUser(true);
- connect.schedule();
- }
- } else {
- // Assume failure is due to name already in use
- Display.getDefault().asyncExec(new Runnable() {
-
+ ISystemRegistry registry = SystemStartHere.getSystemRegistry();
+ IHost host = registry.createHost(sshType, connectionName, hostname, null);
+ if (host != null) {
+ host.setDefaultUserId("root"); //$NON-NLS-1$
+ IConnectorService[] services = host.getConnectorServices();
+ if (services.length > 0) {
+ final IConnectorService service = services[0];
+ Job connect = new Job(CVMessages.getFormattedString(RSE_CONNECTING_MSG,
connectionName)) {
@Override
- public void run() {
+ protected IStatus run(IProgressMonitor monitor) {
try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .showView(VIEW_REMOTESYSEXPLORER_ID);
- } catch (PartInitException e) {
- Activator.log(e);
+ service.connect(monitor);
+ Display.getDefault().asyncExec(showRSEViewRunnable(instance, shell));
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
e.getMessage(), e);
}
}
-
- });
+ };
+ connect.setUser(true);
+ connect.schedule();
}
- } catch (Exception e) {
- Activator.log(e);
+ } else {
+ // Assume failure is due to name already in use
+ shell.getDisplay().asyncExec(showRSEViewRunnable(instance, shell));
}
}
@@ -127,4 +106,32 @@
}
return sshType;
}
+
+ private IStatus showCannotLaunchRSEErrorDialog(final DeltaCloudInstance instance, final
Shell shell,
+ Exception e) {
+ IStatus status = StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
e.getMessage(), e);
+ // TODO: internationalize strings
+ ErrorDialog.openError(shell,
+ "Error",
+ "Could not launch remote system explorer for instance \"" +
instance.getName() + "\"",
+ status);
+ return status;
+ }
+
+ private Runnable showRSEViewRunnable(final DeltaCloudInstance instance, final Shell
shell) {
+
+ return new Runnable() {
+ @Override
+ public void run() {
+ try {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage()
+ .showView(VIEW_REMOTESYSEXPLORER_ID);
+ } catch (PartInitException e) {
+ showCannotLaunchRSEErrorDialog(instance, shell, e);
+ }
+ }
+ };
+ }
+
}