Author: adietish
Date: 2010-11-19 07:02:22 -0500 (Fri, 19 Nov 2010)
New Revision: 26753
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/ShowRSEViewRunnable.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/RSEUtils.java
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/internal/deltacloud/ui/utils/UIUtils.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java
Log:
[JBIDE-7642] refactored RSEUtils
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/RSEUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/RSEUtils.java 2010-11-19
11:11:53 UTC (rev 26752)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/RSEUtils.java 2010-11-19
12:02:22 UTC (rev 26753)
@@ -10,11 +10,16 @@
******************************************************************************/
package org.jboss.tools.deltacloud.ui;
+import java.text.MessageFormat;
+
import org.eclipse.core.runtime.Assert;
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.jface.dialogs.ErrorDialog;
import org.eclipse.rse.core.IRSECoreRegistry;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.RSECorePlugin;
@@ -23,13 +28,16 @@
import org.eclipse.rse.core.model.SystemStartHere;
import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.ui.commands.AbstractCloudJob;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
+import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
public class RSEUtils {
+ private static final String VIEW_REMOTESYSEXPLORER_ID =
"org.eclipse.rse.ui.view.systemView";
private final static String RSE_CONNECTING_MSG = "ConnectingRSE.msg";
//$NON-NLS-1$
public static IRSESystemType getSSHOnlySystemType() {
@@ -41,6 +49,8 @@
if (sysType.getId().equals(IRSESystemType.SYSTEMTYPE_SSH_ONLY_ID))
sshType = sysType;
}
+ Assert.isTrue(sshType != null,
+ "Remote System Explorer could not initialize SSH subsystem: ssh type not
found");
return sshType;
}
@@ -49,23 +59,29 @@
}
public static String createConnectionName(DeltaCloudInstance instance) {
+ Assert.isLegal(instance != null, "Cannot create connection name: instance is not
defined");
return instance.getName() + " [" + instance.getId() + "]";
//$NON-NLS-1$ //$NON-NLS-2$
}
public static String createHostName(DeltaCloudInstance instance) {
- if (instance == null) {
- return null;
- }
- return instance.getHostName();
+ Assert.isLegal(instance != null, "Cannot get hostname: instance is not
defined");
+
+ String hostName = instance.getHostName();
+ Assert.isTrue(hostName != null && hostName.length() > 0,
+ MessageFormat.format("Cannot get host name: not defined for instance {0}",
instance.getName()));
+ return hostName;
}
- public static IHost createHost(String connectionName, String hostname) throws Exception
{
- ISystemRegistry registry = getSystemRegistry();
- IRSESystemType sshOnlySystemType = getSSHOnlySystemType();
- // TODO: Internationalize string
- Assert.isTrue(sshOnlySystemType != null,
- "Remote System Explorer could not initialize SSH subsystem: ssh type not
found");
- IHost host = registry.createHost(sshOnlySystemType, connectionName, hostname, null);
+ public static IHost createHost(String connectionName, String hostname, IRSESystemType
systemType,
+ ISystemRegistry systemRegistry) throws Exception {
+ // TODO: Internationalize strings
+ Assert.isLegal(connectionName != null && connectionName.length() > 0,
+ "Cannot create Host: connectionName is not defined");
+ Assert.isLegal(hostname != null && hostname.length() > 0, "Cannot
create Host: hostname is not defined");
+ Assert.isLegal(systemType != null, "Cannot create Host: system type is not
defined");
+ Assert.isLegal(systemRegistry != null, "Cannot create Host: system registry is not
defined");
+
+ IHost host = systemRegistry.createHost(systemType, connectionName, hostname, null);
host.setDefaultUserId("root"); //$NON-NLS-1$
return host;
}
@@ -78,16 +94,19 @@
return services[0];
}
- public static void connect(final String instanceName, final IConnectorService service,
String connectionName) {
+ public static Job connect(String connectionName, final IConnectorService service)
+ throws Exception {
// TODO: internationalize strings
+ Assert.isLegal(connectionName != null,
+ "Remote System Explorer could not connect: connection name is not
defined");
Assert.isLegal(service != null, "Remote System Explorer could not connect:
connector service not found.");
- Job connect = new AbstractCloudJob(CVMessages.getFormattedString(RSE_CONNECTING_MSG,
connectionName)) {
+
+ Job job = new AbstractCloudJob(CVMessages.getFormattedString(RSE_CONNECTING_MSG,
connectionName)) {
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
monitor.worked(1);
service.connect(monitor);
- Display.getDefault().asyncExec(new ShowRSEViewRunnable(instanceName));
monitor.done();
return Status.OK_STATUS;
} catch (Exception e) {
@@ -95,17 +114,80 @@
}
}
};
- connect.setUser(true);
- connect.schedule();
+ job.setUser(true);
+ job.schedule();
+ return job;
}
+
+ public static void showRemoteSystemExplorer(Job job) {
+ job.addJobChangeListener(new JobChangeAdapter() {
- public static void launchRemoteSystemExplorer(String instanceName, String
connectionName, IHost host) throws Exception {
- if (host != null) {
- IConnectorService service = RSEUtils.getConnectorService(host);
- connect(instanceName, service, connectionName);
- } else {
- // Assume failure is due to name already in use
- Display.getDefault().asyncExec(new ShowRSEViewRunnable(instanceName));
- }
+ @Override
+ public void done(IJobChangeEvent event) {
+ super.done(event);
+ showRemoteSystemExplorer();
+ }});
}
+
+ public static void showRemoteSystemExplorer() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ UIUtils.showView(VIEW_REMOTESYSEXPLORER_ID);
+ } catch (PartInitException e) {
+ IStatus status = StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
e.getMessage(), e);
+ // TODO: internationalize strings
+ ErrorDialog.openError(UIUtils.getActiveShell(),
+ "Error",
+ "Could not launch remote system explorer",
+ status);
+ }
+ }
+ });
+ }
+
+ // private static void test() {
+ // ISystemRegistry registry = SystemStartHere.getSystemRegistry();
+ // RSECorePlugin rsep = RSECorePlugin.getDefault();
+ // IRSECoreRegistry coreRegistry = rsep.getCoreRegistry();
+ // IRSESystemType[] sysTypes = coreRegistry.getSystemTypes();
+ // IRSESystemType sshType = null;
+ // for (IRSESystemType sysType : sysTypes) {
+ // if (sysType.getId().equals(IRSESystemType.SYSTEMTYPE_SSH_ONLY_ID))
+ // sshType = sysType;
+ // }
+ // String connectionName = instance.getName() + " [" + instance.getId() +
"]"; //$NON-NLS-1$ //$NON-NLS-2$
+ // try {
+ // 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);
+ // return Status.OK_STATUS;
+ // } catch (Exception e) {
+ // return Status.CANCEL_STATUS;
+ // }
+ // }
+ // };
+ // connect.setUser(true);
+ // connect.schedule();
+ // }
+ // }
+ // } catch (Exception e) {
+ // // TODO Auto-generated catch block
+ // Activator.log(e);
+ // }
+ //
+ // }
+
}
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/ShowRSEViewRunnable.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/ShowRSEViewRunnable.java 2010-11-19
11:11:53 UTC (rev 26752)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/ShowRSEViewRunnable.java 2010-11-19
12:02:22 UTC (rev 26753)
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 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.deltacloud.ui;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.jboss.tools.common.log.StatusFactory;
-
-public class ShowRSEViewRunnable implements Runnable {
-
- private static final String VIEW_REMOTESYSEXPLORER_ID =
"org.eclipse.rse.ui.view.systemView";
-
- private String instanceName;
-
- public ShowRSEViewRunnable(String instanceName) {
- this.instanceName = instanceName;
- }
-
- @Override
- public void run() {
- try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage()
- .showView(VIEW_REMOTESYSEXPLORER_ID);
- } catch (PartInitException e) {
- IStatus status = StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
e.getMessage(), e);
- // TODO: internationalize strings
- ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
- "Error",
- "Could not launch remote system explorer for instance \"" +
instanceName + "\"",
- status);
- }
- }
-}
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-19
11:11:53 UTC (rev 26752)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/ShowInRemoteSystemExplorerHandler.java 2010-11-19
12:02:22 UTC (rev 26753)
@@ -16,6 +16,7 @@
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.rse.core.model.IHost;
@@ -38,10 +39,14 @@
DeltaCloudInstance instance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
try {
String connectionName = RSEUtils.createConnectionName(instance);
- IHost host = RSEUtils.createHost(connectionName, RSEUtils.createHostName(instance));
- RSEUtils.launchRemoteSystemExplorer(instance.getName(), connectionName, host);
+ IHost host = RSEUtils.createHost(connectionName,
+ RSEUtils.createHostName(instance),
+ RSEUtils.getSSHOnlySystemType(),
+ RSEUtils.getSystemRegistry());
+ Job connectJob = RSEUtils.connect(connectionName,
RSEUtils.getConnectorService(host));
+ RSEUtils.showRemoteSystemExplorer(connectJob);
} catch (Exception e) {
- return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
+ return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
"Could not launch remote system explorer for instance \"" +
instance.getName() + "\"",
e);
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/UIUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/UIUtils.java 2010-11-19
11:11:53 UTC (rev 26752)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/UIUtils.java 2010-11-19
12:02:22 UTC (rev 26753)
@@ -38,6 +38,7 @@
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.menus.IMenuService;
import org.eclipse.ui.part.EditorPart;
@@ -328,4 +329,9 @@
return site.getPage();
}
+ public static void showView(String viewId) throws PartInitException {
+ Assert.isLegal(viewId != null && viewId.length() > 0);
+ getActivePage().showView(viewId);
+ }
+
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java 2010-11-19
11:11:53 UTC (rev 26752)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java 2010-11-19
12:02:22 UTC (rev 26753)
@@ -46,9 +46,9 @@
private final static String DONT_SHOW_THIS_AGAIN_MSG =
"DontShowThisAgain.msg"; //$NON-NLS-1$
private final static String STARTING_INSTANCE_MSG = "StartingInstance.msg";
//$NON-NLS-1$
private final static String STARTING_INSTANCE_TITLE =
"StartingInstance.title"; //$NON-NLS-1$
-
+
private NewInstancePage mainPage;
-
+
private DeltaCloud cloud;
private DeltaCloudImage image;
private DeltaCloudInstance instance;
@@ -57,38 +57,39 @@
this.cloud = cloud;
this.image = image;
}
-
+
@Override
public void addPages() {
mainPage = new NewInstancePage(cloud, image);
addPage(mainPage);
}
-
+
@Override
public boolean canFinish() {
return mainPage.isPageComplete();
}
-
-
+
private class WatchCreateJob extends Job {
-
+
private DeltaCloud cloud;
private String instanceId;
private String instanceName;
-
- public WatchCreateJob(String title, DeltaCloud cloud,
+
+ public WatchCreateJob(String title, DeltaCloud cloud,
String instanceId, String instanceName) {
super(title);
this.cloud = cloud;
this.instanceId = instanceId;
this.instanceName = instanceName;
}
-
+
public IStatus run(IProgressMonitor pm) {
- if (!pm.isCanceled()){
+ if (!pm.isCanceled()) {
DeltaCloudInstance instance = null;
try {
- pm.beginTask(WizardMessages.getFormattedString(STARTING_INSTANCE_MSG, new String[]
{instanceName}), IProgressMonitor.UNKNOWN);
+ pm.beginTask(
+ WizardMessages.getFormattedString(STARTING_INSTANCE_MSG, new String[] {
instanceName }),
+ IProgressMonitor.UNKNOWN);
pm.worked(1);
cloud.registerInstanceJob(instanceId, this);
instance = cloud.waitWhilePending(instanceId, pm);
@@ -103,24 +104,27 @@
if (hostname != null && hostname.length() > 0 && autoConnect) {
try {
String connectionName = RSEUtils.createConnectionName(instance);
- IHost host = RSEUtils.createHost(connectionName,
RSEUtils.createHostName(instance));
- RSEUtils.launchRemoteSystemExplorer(instance.getName(), connectionName, host);
+ IHost host = RSEUtils.createHost(connectionName,
+ RSEUtils.createHostName(instance),
+ RSEUtils.getSSHOnlySystemType(),
+ RSEUtils.getSystemRegistry());
+ RSEUtils.connect(connectionName, RSEUtils.getConnectorService(host));
} catch (Exception e) {
- ErrorUtils.handleError("Error", "Could not launch remote system
explorer for instance \"" + instance.getName() + "\"", e,
getShell());
+ ErrorUtils.handleError("Error", "Could not launch remote system
explorer for instance \""
+ + instance.getName() + "\"", e, getShell());
return Status.OK_STATUS;
}
}
pm.done();
}
return Status.OK_STATUS;
- }
- else {
+ } else {
pm.done();
return Status.CANCEL_STATUS;
}
};
};
-
+
@Override
public boolean performFinish() {
String imageId = image.getId();
@@ -135,24 +139,27 @@
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
-
+ }
+
boolean result = false;
String errorMessage = WizardMessages.getString(DEFAULT_REASON);
try {
Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
- boolean dontShowDialog =
prefs.getBoolean(IDeltaCloudPreferenceConstants.DONT_CONFIRM_CREATE_INSTANCE, false);
+ boolean dontShowDialog =
prefs.getBoolean(IDeltaCloudPreferenceConstants.DONT_CONFIRM_CREATE_INSTANCE,
+ false);
if (!dontShowDialog) {
MessageDialogWithToggle dialog =
- MessageDialogWithToggle.openOkCancelConfirm(getShell(),
WizardMessages.getString(CONFIRM_CREATE_TITLE),
- WizardMessages.getString(CONFIRM_CREATE_MSG),
- WizardMessages.getString(DONT_SHOW_THIS_AGAIN_MSG),
- false, null, null);
+ MessageDialogWithToggle.openOkCancelConfirm(getShell(),
+ WizardMessages.getString(CONFIRM_CREATE_TITLE),
+ WizardMessages.getString(CONFIRM_CREATE_MSG),
+ WizardMessages.getString(DONT_SHOW_THIS_AGAIN_MSG),
+ false, null, null);
int retCode = dialog.getReturnCode();
boolean toggleState = dialog.getToggleState();
if (retCode == Dialog.CANCEL)
return true;
- // If warning turned off by user, set the preference for future usage
+ // If warning turned off by user, set the preference for future
+ // usage
if (toggleState) {
prefs.putBoolean(IDeltaCloudPreferenceConstants.DONT_CONFIRM_CREATE_INSTANCE,
true);
}
@@ -173,9 +180,11 @@
errorMessage = e.getLocalizedMessage();
}
if (!result) {
- ErrorDialog.openError(this.getShell(),
+ ErrorDialog.openError(
+ this.getShell(),
WizardMessages.getString(CREATE_INSTANCE_FAILURE_TITLE),
- WizardMessages.getFormattedString(CREATE_INSTANCE_FAILURE_MSG, new String[] {name,
imageId, realmId, profileId}),
+ WizardMessages.getFormattedString(CREATE_INSTANCE_FAILURE_MSG, new String[] { name,
imageId,
+ realmId, profileId }),
new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMessage));
}
return result;
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java 2010-11-19
11:11:53 UTC (rev 26752)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java 2010-11-19
12:02:22 UTC (rev 26753)
@@ -97,10 +97,14 @@
if (hostname != null && hostname.length() > 0 && isAutoconnect())
{
try {
String connectionName = RSEUtils.createConnectionName(instance);
- IHost host = RSEUtils.createHost(connectionName,
RSEUtils.createHostName(instance), RSEUtils.getSSHOnlySystemType());
- RSEUtils.launchRemoteSystemExplorer(instance.getName(), connectionName, host);
+ IHost host = RSEUtils.createHost(connectionName,
+ RSEUtils.createHostName(instance),
+ RSEUtils.getSSHOnlySystemType(),
+ RSEUtils.getSystemRegistry());
+ RSEUtils.connect(connectionName, RSEUtils.getConnectorService(host));
} catch (Exception e) {
- ErrorUtils.handleError("Error", "Could not launch remote system
explorer for instance \"" + instance.getName() + "\"", e,
getShell());
+ ErrorUtils.handleError("Error", "Could not launch remote system
explorer for instance \""
+ + instance.getName() + "\"", e, getShell());
return Status.OK_STATUS;
}
}
@@ -133,7 +137,7 @@
// Save persistent settings for this particular cloud
cloud.setLastImageId(imageId);
cloud.setLastKeyname(keyname);
-
+
Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
boolean result = false;