Author: rob.stryker(a)jboss.com
Date: 2010-12-01 08:46:14 -0500 (Wed, 01 Dec 2010)
New Revision: 27050
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnectionWizard.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java
Log:
JBIDE-7715 - duplication in classes removed. One now extends the other
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-12-01
13:31:31 UTC (rev 27049)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-12-01
13:46:14 UTC (rev 27050)
@@ -53,6 +53,7 @@
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.common.log.LogHelper;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
@@ -270,7 +271,14 @@
this.connectionModel = new CloudConnectionModel();
this.cloudConnection = cloudConnection;
}
+
+ public CloudConnectionPage(String pageName, DeltaCloud initial, CloudConnection
connection)
+ throws MalformedURLException, DeltaCloudException {
+ this(pageName, initial.getName(), initial.getURL(), initial.getUsername(),
+ initial.getPassword(), initial.getType(), connection);
+ }
+
public CloudConnectionPage(String pageName, String defaultName, String defaultUrl,
String defaultUsername, String defaultPassword, String defaultType,
CloudConnection cloudConnection) throws MalformedURLException {
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnectionWizard.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnectionWizard.java 2010-12-01
13:31:31 UTC (rev 27049)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnectionWizard.java 2010-12-01
13:46:14 UTC (rev 27050)
@@ -10,82 +10,19 @@
*******************************************************************************/
package org.jboss.tools.internal.deltacloud.ui.wizards;
-import java.net.MalformedURLException;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloud;
-import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
-import org.jboss.tools.deltacloud.ui.Activator;
-import org.jboss.tools.deltacloud.ui.ErrorUtils;
-public class EditCloudConnectionWizard extends Wizard implements INewWizard,
CloudConnection {
+public class EditCloudConnectionWizard extends NewCloudConnectionWizard {
private static final String MAINPAGE_NAME = "EditCloudConnection.name";
//$NON-NLS-1$
private CloudConnectionPage mainPage;
- private DeltaCloud cloud;
public EditCloudConnectionWizard(DeltaCloud cloud) {
- super();
- this.cloud = cloud;
+ super(WizardMessages.getString(MAINPAGE_NAME), cloud);
}
@Override
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- }
-
- @Override
- public void addPages() {
- try {
- String cloudName = cloud.getName();
- String userName = cloud.getUsername();
- String password = cloud.getPassword();
- mainPage = new CloudConnectionPage(WizardMessages.getString(MAINPAGE_NAME),
- cloudName, cloud.getURL(), userName, password, cloud.getType(), this);
- addPage(mainPage);
- } catch (MalformedURLException e) {
- ErrorUtils.handleError(WizardMessages.getString("EditCloudConnectionError.title"),
- WizardMessages.getString("EditCloudConnectionError.message"), e,
getShell());
- } catch (DeltaCloudException e) {
- // TODO: internationalize strings
- ErrorUtils.handleError("Error",
- "Could not create wizard page", e, getShell());
- }
- }
-
- @Override
- public boolean canFinish() {
- return mainPage.isPageComplete();
- }
-
- public boolean performTest() {
- String name = mainPage.getName();
- String url = mainPage.getModel().getUrl();
- String username = mainPage.getModel().getUsername();
- String password = mainPage.getModel().getPassword();
- try {
- DeltaCloud newCloud = new DeltaCloud(name, url, username, password);
- return newCloud.testConnection();
- } catch (DeltaCloudException e) {
- IStatus status = StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
e.getMessage(), e);
- Activator.log(status);
- ErrorDialog.openError(
- getShell(),
- WizardMessages.getString("CloudConnectionAuthError.title"),
- WizardMessages.getFormattedString("CloudConnectionAuthError.message",
url),
- status);
- return false;
- }
- }
-
- @Override
public boolean performFinish() {
String name = mainPage.getModel().getName();
String url = mainPage.getModel().getUrl();
@@ -93,8 +30,8 @@
String password = mainPage.getModel().getPassword();
String type = getServerType();
try {
- String oldName = cloud.getName();
- cloud.editCloud(name, url, username, password, type);
+ String oldName = initialCloud.getName();
+ initialCloud.editCloud(name, url, username, password, type);
DeltaCloudManager.getDefault().saveClouds();
if (!name.equals(oldName)) {
DeltaCloudManager.getDefault().notifyCloudRename();
@@ -103,18 +40,4 @@
}
return true;
}
-
- private String getServerType() {
- DeltaCloudServerType type = mainPage.getModel().getType();
- if (type == null) {
- return null;
- }
-
- return type.toString();
- }
-
- @Override
- public boolean needsProgressMonitor() {
- return true;
- }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java 2010-12-01
13:31:31 UTC (rev 27049)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java 2010-12-01
13:46:14 UTC (rev 27050)
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.jboss.tools.internal.deltacloud.ui.wizards;
+import java.net.MalformedURLException;
import java.text.MessageFormat;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -22,32 +23,66 @@
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
import org.jboss.tools.deltacloud.ui.ErrorUtils;
-public class NewCloudConnectionWizard extends Wizard implements INewWizard,
CloudConnection {
+public class NewCloudConnectionWizard extends Wizard implements INewWizard,
CloudConnection {
private static final String MAINPAGE_NAME = "NewCloudConnection.name";
//$NON-NLS-1$
private CloudConnectionPage mainPage;
+ protected DeltaCloud initialCloud;
+ private String pageTitle;
public NewCloudConnectionWizard() {
+ this(WizardMessages.getString(MAINPAGE_NAME));
+ }
+
+ public NewCloudConnectionWizard(String pageTitle) {
super();
+ this.pageTitle = pageTitle;
}
+
+ public NewCloudConnectionWizard(String pageTitle, DeltaCloud initial) {
+ this(pageTitle);
+ this.initialCloud = initial;
+ }
+
+ protected CloudConnectionPage createCloudConnectionPage() {
+ Exception e = null;
+ try {
+ if( initialCloud == null )
+ return new CloudConnectionPage(pageTitle, this);
+ // else
+ return new CloudConnectionPage(pageTitle, initialCloud, this);
+ } catch (MalformedURLException e2) {
+ e = e2;
+ } catch (DeltaCloudException e2) {
+ e = e2;
+ }
+ if( e != null ) {
+ ErrorUtils.handleError(WizardMessages.getString("EditCloudConnectionError.title"),
+ WizardMessages.getString("EditCloudConnectionError.message"), e,
getShell());
+ }
+ return null;
+ }
+
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
}
- @Override
- public void addPages() {
- mainPage = new CloudConnectionPage(WizardMessages.getString(MAINPAGE_NAME), this);
- addPage(mainPage);
- }
@Override
public boolean canFinish() {
return mainPage.isPageComplete();
}
-
+
+ @Override
+ public void addPages() {
+ mainPage = createCloudConnectionPage();
+ if( mainPage != null )
+ addPage(mainPage);
+ }
+
public boolean performTest() {
- String name = mainPage.getModel().getName();
+ String name = mainPage.getName();
String url = mainPage.getModel().getUrl();
String username = mainPage.getModel().getUsername();
String password = mainPage.getModel().getPassword();
@@ -61,8 +96,22 @@
return true;
}
}
+
+ protected String getServerType() {
+ DeltaCloudServerType type = mainPage.getModel().getType();
+ if (type == null) {
+ return null;
+ }
+
+ return type.toString();
+ }
@Override
+ public boolean needsProgressMonitor() {
+ return true;
+ }
+
+ @Override
public boolean performFinish() {
String name = mainPage.getModel().getName();
String url = mainPage.getModel().getUrl();
@@ -80,18 +129,4 @@
}
return true;
}
-
- private String getServerType() {
- DeltaCloudServerType type = mainPage.getModel().getType();
- if (type == null) {
- return null;
- }
-
- return type.toString();
- }
-
- @Override
- public boolean needsProgressMonitor() {
- return true;
- }
}