[jbosstools-commits] JBoss Tools SVN: r43839 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui: utils and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Sep 19 13:39:17 EDT 2012


Author: adietish
Date: 2012-09-19 13:39:16 -0400 (Wed, 19 Sep 2012)
New Revision: 43839

Added:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/FileNameValidator.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredStringValidator.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/DirectoryValidator.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyNameValidator.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java
Removed:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/NonEmptyStringValidator.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyNameValidator.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyValidator.java
Modified:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java
Log:
[JBIDE-11912] implemented "Add new SSH key"

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -10,7 +10,6 @@
  ******************************************************************************/
 package org.jboss.tools.openshift.express.internal.ui.databinding;
 
-import org.eclipse.core.databinding.validation.IValidator;
 import org.eclipse.core.databinding.validation.ValidationStatus;
 import org.eclipse.core.runtime.IStatus;
 import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
@@ -18,21 +17,18 @@
 /**
  * @author Andre Dietisheim
  */
-public class AlphanumericStringValidator implements IValidator {
+public class AlphanumericStringValidator extends RequiredStringValidator {
 
 	private String fieldName;
 
 	public AlphanumericStringValidator(String fieldName) {
-		this.fieldName = fieldName;
+		super(fieldName);
 	}
 
 	@Override
-	public IStatus validate(Object value) {
-		String name = (String) value;
-		if (StringUtils.isEmpty(name)) {
-			return ValidationStatus.cancel("You have to provide a " + fieldName);
-		} else if (!StringUtils.isAlphaNumeric(name)) {
-			return ValidationStatus.cancel("You have to provide an alphanumeric " + fieldName);
+	public IStatus validateString(String value) {
+		if (!StringUtils.isAlphaNumeric(value)) {
+			return ValidationStatus.error("You have to provide an alphanumeric " + fieldName);
 		}
 		return ValidationStatus.ok();
 	}

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/FileNameValidator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/FileNameValidator.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/FileNameValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.databinding;
+
+import java.io.File;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * Validates a given String positively if it is non-empty and has no separator
+ * chars (it's a file name, not a path)
+ * 
+ * @author Andre Dietisheim
+ */
+public class FileNameValidator extends RequiredStringValidator implements IValidator {
+
+	public FileNameValidator() {
+		super("private key file name");
+	}
+
+	@Override
+	public IStatus validateString(String value) {
+		if (value.indexOf(File.separator) >= 0) {
+			ValidationStatus.error("You may only provide a file name, not a path.");
+		}
+		return ValidationStatus.ok();
+	}
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/FileNameValidator.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Deleted: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/NonEmptyStringValidator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/NonEmptyStringValidator.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/NonEmptyStringValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * 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.databinding;
-
-import org.eclipse.core.databinding.validation.IValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.IStatus;
-import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
-
-/**
- * @author Andre Dietisheim
- */
-public class NonEmptyStringValidator implements IValidator {
-
-	private String fieldName;
-
-	public NonEmptyStringValidator(String fieldName) {
-		this.fieldName = fieldName;
-	}
-
-	@Override
-	public IStatus validate(Object value) {
-		String name = (String) value;
-		if (StringUtils.isEmpty(name)) {
-			return ValidationStatus.cancel("You have to provide a " + fieldName);
-		}
-		return ValidationStatus.ok();
-	}
-
-}

Copied: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredStringValidator.java (from rev 43816, trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/NonEmptyStringValidator.java)
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredStringValidator.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredStringValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.databinding;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class RequiredStringValidator implements IValidator {
+
+	private String fieldName;
+
+	public RequiredStringValidator(String fieldName) {
+		this.fieldName = fieldName;
+	}
+
+	@Override
+	public IStatus validate(Object value) {
+		String name = (String) value;
+		if (StringUtils.isEmpty(name)) {
+			return ValidationStatus.cancel("You have to provide a " + fieldName);
+		}
+		return validateString((String)value);
+	}
+	
+	public IStatus validateString(String value) {
+		return ValidationStatus.ok();
+	}
+
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredStringValidator.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/utils/StringUtils.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -98,4 +98,12 @@
 				.toString();
 	}
 
+	public static String getWithoutSuffix(String string, String suffix) {
+		String stringNoSuffix = string;
+		int suffixIndex = string.indexOf(suffix);
+		if (suffixIndex >= 0) {
+			stringNoSuffix = string.substring(0, suffixIndex);
+		}
+		return stringNoSuffix;
+	}
 }

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.wizard.ssh;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+
+/**
+ * @author Andre Dietisheim
+ */
+public abstract class AbstractSSHKeyWizardPageModel extends ObservableUIPojo implements ISSHKeyWizardPageModel {
+
+	private String name;
+	private UserDelegate user;
+	
+	public AbstractSSHKeyWizardPageModel(UserDelegate user) {
+		this.user = user;
+	}
+
+	@Override
+	public String getName() {
+		return name;
+	}
+
+	@Override
+	public void setName(String name) {
+		firePropertyChange(PROPERTY_NAME, this.name, this.name = name);
+	}
+
+	@Override
+	public boolean hasKeyName(String name) {
+		return user.hasSSHKeyName(name);
+	}
+
+	@Override
+	public boolean hasPublicKey(String publicKeyContent) {
+		return user.hasSSHPublicKey(publicKeyContent);
+	}
+	
+	protected UserDelegate getUser() {
+		return user;
+	}
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.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/ssh/AddSSHKeyJob.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -22,9 +22,9 @@
  */
 public class AddSSHKeyJob extends Job {
 
-	private AddSSHKeyWizardPageModel model;
+	private ISSHKeyWizardPageModel model;
 
-	public AddSSHKeyJob(AddSSHKeyWizardPageModel model) {
+	public AddSSHKeyJob(ISSHKeyWizardPageModel model) {
 		super("Adding SSH key " + model.getName() + "...");
 		this.model = model;
 	}

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -38,6 +38,8 @@
 import org.jboss.tools.openshift.express.internal.ui.databinding.RequiredControlDecorationUpdater;
 import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
 import org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftWizardPage;
+import org.jboss.tools.openshift.express.internal.ui.wizard.ssh.databinding.SSHPublicKeyNameValidator;
+import org.jboss.tools.openshift.express.internal.ui.wizard.ssh.databinding.SSHPublicKeyValidator;
 
 /**
  * @author André Dietisheim

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -14,7 +14,6 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 
-import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
 import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
 
 import com.openshift.client.OpenShiftException;
@@ -23,47 +22,34 @@
 /**
  * @author Andre Dietisheim
  */
-public class AddSSHKeyWizardPageModel extends ObservableUIPojo {
+public class AddSSHKeyWizardPageModel extends AbstractSSHKeyWizardPageModel {
 
 	public static final String PROPERTY_PUBLICKEY_PATH = "publicKeyPath";
-	public static final String PROPERTY_NAME = "name";
 	
-	private String name;
-	private String filePath;
-	private UserDelegate user;
+	private String keyPath;
 	
 	public AddSSHKeyWizardPageModel(UserDelegate user) {
-		this.user = user;
+		super(user);
 	}
 
 	public String getPublicKeyPath() {
-		return filePath;
+		return keyPath;
 	}
 
-	public void setPublicKeyPath(String filePath) {
-		firePropertyChange(PROPERTY_PUBLICKEY_PATH, this.filePath, this.filePath = filePath);
+	public File getPublicKey() {
+		return new File(keyPath);
 	}
 
-	public String getName() {
-		return name;
+	public void setPublicKeyPath(String keyPath) {
+		firePropertyChange(PROPERTY_PUBLICKEY_PATH, this.keyPath, this.keyPath = keyPath);
 	}
 
-	public void setName(String name) {
-		firePropertyChange(PROPERTY_NAME, this.name, this.name = name);
-	}
-
-	public boolean hasKeyName(String name) {
-		return user.hasSSHKeyName(name);
-	}
-
 	public boolean hasPublicKey(String publicKeyContent) {
-		return user.hasSSHPublicKey(publicKeyContent);
-	}
-
+		return getUser().hasSSHPublicKey(publicKeyContent);
+	}	
+	
 	public void addConfiguredSSHKey() throws FileNotFoundException, OpenShiftException, IOException {
-		SSHPublicKey sshPublicKey = new SSHPublicKey(new File(filePath));
-		user.putSSHKey(name, sshPublicKey);
+		SSHPublicKey sshPublicKey = new SSHPublicKey(getPublicKey());
+		getUser().putSSHKey(getName(), sshPublicKey);
 	}
-
-	
 }

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.wizard.ssh;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import com.openshift.client.OpenShiftException;
+
+/**
+ * @author Andre Dietisheim
+ */
+public interface ISSHKeyWizardPageModel {
+
+	public static final String PROPERTY_NAME = "name";
+
+	public String getName();
+
+	public void setName(String name);
+
+	public boolean hasKeyName(String name);
+
+	public boolean hasPublicKey(String publicKeyContent);
+
+	public void addConfiguredSSHKey() throws FileNotFoundException, OpenShiftException, IOException;
+
+	public File getPublicKey();
+}
\ No newline at end of file


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.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/ssh/NewSSHKeyWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -36,10 +36,13 @@
 import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
 import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
 import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
-import org.jboss.tools.openshift.express.internal.ui.databinding.NonEmptyStringValidator;
+import org.jboss.tools.openshift.express.internal.ui.databinding.FileNameValidator;
 import org.jboss.tools.openshift.express.internal.ui.databinding.RequiredControlDecorationUpdater;
 import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
+import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
 import org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftWizardPage;
+import org.jboss.tools.openshift.express.internal.ui.wizard.ssh.databinding.DirectoryValidator;
+import org.jboss.tools.openshift.express.internal.ui.wizard.ssh.databinding.SSHPublicKeyNameValidator;
 
 import com.openshift.client.SSHKeyType;
 
@@ -66,7 +69,7 @@
 		GridDataFactory.fillDefaults()
 				.align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(newSSHKeyGroup);
 		GridLayoutFactory.fillDefaults()
-				.numColumns(3).margins(6, 6).applyTo(newSSHKeyGroup);
+				.numColumns(4).margins(6, 6).applyTo(newSSHKeyGroup);
 
 		Label nameLabel = new Label(newSSHKeyGroup, SWT.NONE);
 		nameLabel.setText("Name:");
@@ -75,7 +78,7 @@
 
 		Text nameText = new Text(newSSHKeyGroup, SWT.BORDER);
 		GridDataFactory.fillDefaults()
-				.align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(nameText);
+				.align(SWT.FILL, SWT.CENTER).grab(true, false).span(3, 1).applyTo(nameText);
 		Binding nameBinding = ValueBindingBuilder
 				.bind(WidgetProperties.text(SWT.Modify).observe(nameText))
 				.validatingAfterConvert(new SSHPublicKeyNameValidator(pageModel))
@@ -90,18 +93,19 @@
 		GridDataFactory.fillDefaults()
 				.align(SWT.LEFT, SWT.CENTER).applyTo(typeLabel);
 
-		ComboViewer typeCombo = new ComboViewer(newSSHKeyGroup, SWT.DEFAULT);
+		ComboViewer typeCombo = new ComboViewer(newSSHKeyGroup, SWT.READ_ONLY);
 		typeCombo.setContentProvider(ArrayContentProvider.getInstance());
 		typeCombo.setInput(SSHKeyType.values());
 		GridDataFactory.fillDefaults()
 				.align(SWT.LEFT, SWT.CENTER).applyTo(typeCombo.getControl());
-		ValueBindingBuilder.bind(
-				ViewerProperties.singleSelection().observe(typeCombo))
-				.to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_TYPE).observe(typeCombo))
+		ValueBindingBuilder
+				.bind(ViewerProperties.singleSelection().observe(typeCombo))
+				.to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_TYPE).observe(pageModel))
 				.in(dbc);
+
 		Label fillerLabel = new Label(newSSHKeyGroup, SWT.NONE);
 		GridDataFactory.fillDefaults()
-				.align(SWT.LEFT, SWT.CENTER).applyTo(fillerLabel);
+				.align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(fillerLabel);
 
 		Label ssh2HomeLabel = new Label(newSSHKeyGroup, SWT.NONE);
 		GridDataFactory.fillDefaults()
@@ -114,18 +118,26 @@
 				.align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(ssh2HomeText);
 		Binding ssh2HomeBinding = ValueBindingBuilder
 				.bind(WidgetProperties.text(SWT.Modify).observe(ssh2HomeText))
-				.validatingAfterConvert(new NonEmptyStringValidator("ssh2 home directory"))
+				.validatingAfterConvert(new DirectoryValidator("ssh2 home directory"))
 				.to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_SSH2_HOME).observe(pageModel))
 				.in(dbc);
 		ControlDecorationSupport.create(
 				ssh2HomeBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
 
-		Button ss2HomeBrowseButton = new Button(newSSHKeyGroup, SWT.PUSH);
-		ss2HomeBrowseButton.setText("Browse...");
-		ss2HomeBrowseButton.addSelectionListener(onBrowse());
+		Button ssh2HomeBrowseButton = new Button(newSSHKeyGroup, SWT.PUSH);
+		ssh2HomeBrowseButton.setText("Browse...");
+		ssh2HomeBrowseButton.addSelectionListener(onBrowse(ssh2HomeText));
 		GridDataFactory.fillDefaults()
-				.align(SWT.FILL, SWT.CENTER).applyTo(ss2HomeBrowseButton);
+				.align(SWT.FILL, SWT.CENTER).applyTo(ssh2HomeBrowseButton);
 
+		Button defaultSSH2HomeHomeButton = new Button(newSSHKeyGroup, SWT.CHECK);
+		defaultSSH2HomeHomeButton.setText("Default");
+		defaultSSH2HomeHomeButton.addSelectionListener(onDefault(ssh2HomeText, ssh2HomeBrowseButton));
+		defaultSSH2HomeHomeButton.setSelection(true);
+		updateSSH2HomeWidgets(true, ssh2HomeText, ssh2HomeBrowseButton);
+		GridDataFactory.fillDefaults()
+				.align(SWT.FILL, SWT.CENTER).applyTo(ssh2HomeBrowseButton);
+
 		Label privateKeyLabel = new Label(newSSHKeyGroup, SWT.NONE);
 		GridDataFactory.fillDefaults()
 				.align(SWT.LEFT, SWT.CENTER).applyTo(privateKeyLabel);
@@ -133,11 +145,11 @@
 
 		Text privateKeyText = new Text(newSSHKeyGroup, SWT.BORDER);
 		GridDataFactory.fillDefaults()
-				.align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(privateKeyText);
+				.align(SWT.FILL, SWT.CENTER).grab(true, false).span(3, 1).applyTo(privateKeyText);
 		Binding privateKeyBinding = ValueBindingBuilder
 				.bind(WidgetProperties.text(SWT.Modify).observe(privateKeyText))
-				.validatingAfterConvert(new NonEmptyStringValidator("private key file name"))
-				.to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_PRIVATEKEY_PATH).observe(pageModel))
+				.validatingAfterConvert(new FileNameValidator())
+				.to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_PRIVATEKEY_FILENAME).observe(pageModel))
 				.in(dbc);
 		ControlDecorationSupport.create(
 				privateKeyBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
@@ -149,10 +161,9 @@
 
 		Text passphraseText = new Text(newSSHKeyGroup, SWT.BORDER | SWT.PASSWORD);
 		GridDataFactory.fillDefaults()
-				.align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(passphraseText);
+				.align(SWT.FILL, SWT.CENTER).grab(true, false).span(3, 1).applyTo(passphraseText);
 		ValueBindingBuilder
 				.bind(WidgetProperties.text(SWT.Modify).observe(passphraseText))
-				.validatingAfterConvert(new NonEmptyStringValidator("pass phrase"))
 				.to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_PRIVATEKEY_PASSPHRASE).observe(pageModel))
 				.in(dbc);
 
@@ -163,31 +174,57 @@
 
 		Text publicKeyText = new Text(newSSHKeyGroup, SWT.BORDER);
 		GridDataFactory.fillDefaults()
-				.align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(publicKeyText);
+				.align(SWT.FILL, SWT.CENTER).grab(true, false).span(3, 1).applyTo(publicKeyText);
 		Binding publicKeyBinding = ValueBindingBuilder
 				.bind(WidgetProperties.text(SWT.Modify).observe(publicKeyText))
-				.validatingAfterConvert(new NonEmptyStringValidator("public key file name"))
-				.to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_PUBLICKEY_PATH).observe(pageModel))
+				.validatingAfterConvert(new FileNameValidator())
+				.to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_PUBLICKEY_FILENAME).observe(pageModel))
 				.in(dbc);
 		ControlDecorationSupport.create(
 				publicKeyBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
 	}
 
-	private SelectionListener onBrowse() {
+	private SelectionListener onBrowse(final Text ssh2HomeText) {
 		return new SelectionAdapter() {
 
 			@Override
 			public void widgetSelected(SelectionEvent e) {
 				DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN);
-				dialog.setFilterPath(SSHUtils.getSSH2Home());
-				String filePath = null;
-				if ((filePath = dialog.open()) != null) {
-					pageModel.setPublicKeyPath(filePath);
+				dialog.setFilterPath(getFilterPath(ssh2HomeText.getText()));
+				String ssh2HomePath = null;
+				if ((ssh2HomePath = dialog.open()) != null) {
+					pageModel.setSSH2Home(ssh2HomePath);
 				}
 			}
+
+			private String getFilterPath(String currentFilterPath) {
+				if (StringUtils.isEmpty(currentFilterPath)) {
+					return currentFilterPath;
+				} else {
+					return SSHUtils.getSSH2Home();
+				}
+			}
 		};
 	}
 
+	private SelectionListener onDefault(final Text ssh2HomeText, final Button ssh2HomeBrowseButton) {
+		return new SelectionAdapter() {
+
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				updateSSH2HomeWidgets(((Button) e.widget).getSelection(), ssh2HomeText, ssh2HomeBrowseButton);
+			}
+		};
+	}
+
+	private void updateSSH2HomeWidgets(boolean isDefault, final Text ssh2HomeText, final Button ssh2HomeBrowseButton) {
+		ssh2HomeText.setEnabled(!isDefault);
+		ssh2HomeBrowseButton.setEnabled(!isDefault);
+		if (isDefault) {
+			ssh2HomeText.setText(SSHUtils.getSSH2Home());
+		}
+	}
+
 	public IStatus addConfiguredSSHKey() {
 		try {
 			return WizardUtils.runInWizard(new AddSSHKeyJob(pageModel), getContainer());

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -10,24 +10,35 @@
  ******************************************************************************/
 package org.jboss.tools.openshift.express.internal.ui.wizard.ssh;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
 import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
+import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
 
+import com.openshift.client.OpenShiftException;
+import com.openshift.client.SSHKeyPair;
 import com.openshift.client.SSHKeyType;
 
 /**
  * @author Andre Dietisheim
  */
-public class NewSSHKeyWizardPageModel extends AddSSHKeyWizardPageModel {
+public class NewSSHKeyWizardPageModel extends AbstractSSHKeyWizardPageModel {
 
 	public static final String PROPERTY_TYPE = "type";
-	public static final String PROPERTY_SSH2_HOME = "SSH22Home";
-	public static final String PROPERTY_PRIVATEKEY_PATH = "privateKeyPath";
+	public static final String PROPERTY_SSH2_HOME = "SSH2Home";
+	public static final String PROPERTY_PRIVATEKEY_FILENAME = "privateKeyName";
 	public static final String PROPERTY_PRIVATEKEY_PASSPHRASE = "privateKeyPassphrase";
+	public static final String PROPERTY_PUBLICKEY_FILENAME = "publicKeyName";
+	private static final String PUBLICKEY_SUFFIX = ".pub";
 
 	private SSHKeyType type = SSHKeyType.SSH_RSA;
-	private String ssh2Home;
-	private String privateKeyPath;
+	private String ssh2Home = SSHUtils.getSSH2Home();
+	private String privateKeyName;
 	private String privateKeyPathphrase;
+	private String publicKeyName;
 
 	public NewSSHKeyWizardPageModel(UserDelegate user) {
 		super(user);
@@ -50,14 +61,34 @@
 				this.privateKeyPathphrase, this.privateKeyPathphrase = privateKeyPathphrase);
 	}
 
-	public String getPrivateKeyPath() {
-		return privateKeyPath;
+	public String getPrivateKeyName() {
+		return privateKeyName;
 	}
 
-	public void setPrivateKeyPath(String privateKeyPath) {
-		firePropertyChange(PROPERTY_PRIVATEKEY_PATH, this.privateKeyPath, this.privateKeyPath = privateKeyPath);
+	public void setPrivateKeyName(String privateKeyName) {
+		firePropertyChange(PROPERTY_PRIVATEKEY_FILENAME, this.privateKeyName, this.privateKeyName = privateKeyName);
+		updatePublicKeyNameFromPrivateKey(privateKeyName);
 	}
 
+	private void updatePublicKeyNameFromPrivateKey(String privateKeyName) {
+		if (StringUtils.isEmpty(publicKeyName)) {
+			setPublicKeyName(privateKeyName + PUBLICKEY_SUFFIX);
+		} else {
+			String publicKeyNameNoSuffix = StringUtils.getWithoutSuffix(publicKeyName, PUBLICKEY_SUFFIX); 
+			if (privateKeyName.startsWith(publicKeyNameNoSuffix)) {
+				setPublicKeyName(privateKeyName + PUBLICKEY_SUFFIX);
+			}			
+		}
+	}
+
+	public String getPublicKeyName() {
+		return publicKeyName;
+	}
+
+	public void setPublicKeyName(String publicKeyName) {
+		firePropertyChange(PROPERTY_PUBLICKEY_FILENAME, this.publicKeyName, this.publicKeyName = publicKeyName);
+	}
+
 	public String getSSH2Home() {
 		return ssh2Home;
 	}
@@ -65,5 +96,17 @@
 	public void setSSH2Home(String ssh2Home) {
 		firePropertyChange(PROPERTY_SSH2_HOME, this.ssh2Home, this.ssh2Home = ssh2Home);
 	}
+	
+	public File getPublicKey() {
+		return new File(ssh2Home, publicKeyName);
+	}
+	
+	public void addConfiguredSSHKey() throws FileNotFoundException, OpenShiftException, IOException {
+		String privateKeyPath = new File(ssh2Home, privateKeyName).getAbsolutePath();
+		String publicKeyPath = new File(ssh2Home, publicKeyName).getAbsolutePath();
+		SSHKeyPair keyPair = SSHKeyPair.create(privateKeyPathphrase, privateKeyPath, publicKeyPath);
+		getUser().putSSHKey(getName(), keyPair);
+	}
 
+
 }

Deleted: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyNameValidator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyNameValidator.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyNameValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -1,29 +0,0 @@
-package org.jboss.tools.openshift.express.internal.ui.wizard.ssh;
-
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.IStatus;
-import org.jboss.tools.openshift.express.internal.ui.databinding.AlphanumericStringValidator;
-
-public class SSHPublicKeyNameValidator extends AlphanumericStringValidator {
-
-	private AddSSHKeyWizardPageModel model;
-
-	public SSHPublicKeyNameValidator(AddSSHKeyWizardPageModel model) {
-		super("key name");
-		this.model = model;
-	}
-
-	@Override
-	public IStatus validate(Object value) {
-		IStatus validationStatus = super.validate(value);
-		if (!validationStatus.isOK()) {
-			return validationStatus;
-		}
-		String keyName = (String) value;
-		if (model.hasKeyName(keyName)) {
-			return ValidationStatus.error("There's already a key with the name " + keyName);
-		}
-		return ValidationStatus.ok();
-
-	}
-}

Deleted: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyValidator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyValidator.java	2012-09-19 17:24:37 UTC (rev 43838)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * 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.wizard.ssh;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.validation.MultiValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
-
-import com.openshift.client.OpenShiftException;
-import com.openshift.client.SSHPublicKey;
-
-/**
- * @author Andre Dietisheim
- */
-public class SSHPublicKeyValidator extends MultiValidator {
-
-	private IObservableValue filePathObservable;
-	private AddSSHKeyWizardPageModel model;
-
-	public SSHPublicKeyValidator(IObservableValue filePathObservable, AddSSHKeyWizardPageModel model) {
-		this.filePathObservable = filePathObservable;
-		this.model = model;
-	}
-
-	@Override
-	protected IStatus validate() {
-		String filePath = (String) filePathObservable.getValue();
-		if (StringUtils.isEmpty(filePath)) {
-			return ValidationStatus.cancel("You have to supply a public SSH key.");
-		}
-		try {
-			SSHPublicKey sshPublicKey = new SSHPublicKey(filePath);
-			if (model.hasPublicKey(sshPublicKey.getPublicKey())) {
-				return ValidationStatus.error("The public key in " + filePath + " is already in use on OpenShift. Choose another key.");
-			}
-		} catch (FileNotFoundException e) {
-			return ValidationStatus.error("Could not load file: " + e.getMessage());
-		} catch (OpenShiftException e) {
-			return ValidationStatus.error(filePath + "is not a valid public SSH key: " + e.getMessage());
-		} catch (IOException e) {
-			return ValidationStatus.error("Could not load file: " + e.getMessage());
-		}
-
-		return Status.OK_STATUS;
-	}
-
-}

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/DirectoryValidator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/DirectoryValidator.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/DirectoryValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -0,0 +1,30 @@
+package org.jboss.tools.openshift.express.internal.ui.wizard.ssh.databinding;
+
+import java.io.File;
+
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.jboss.tools.openshift.express.internal.ui.databinding.RequiredStringValidator;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class DirectoryValidator extends RequiredStringValidator {
+
+	public DirectoryValidator(String fieldName) {
+		super(fieldName);
+	}
+
+	@Override
+	public IStatus validateString(String value) {
+		File ssh2HomeDirectory = new File(value);
+		if (!ssh2HomeDirectory.isDirectory()) {
+			return ValidationStatus.error(value + " is not a directory.");
+		}
+		if (!ssh2HomeDirectory.exists()) {
+			return ValidationStatus.error("The directory " + value + " does not exist.");
+		}
+		return ValidationStatus.ok();
+	}
+
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/DirectoryValidator.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Copied: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyNameValidator.java (from rev 43816, trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyNameValidator.java)
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyNameValidator.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyNameValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.wizard.ssh.databinding;
+
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.jboss.tools.openshift.express.internal.ui.databinding.AlphanumericStringValidator;
+import org.jboss.tools.openshift.express.internal.ui.wizard.ssh.ISSHKeyWizardPageModel;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class SSHPublicKeyNameValidator extends AlphanumericStringValidator {
+
+	private ISSHKeyWizardPageModel model;
+
+	public SSHPublicKeyNameValidator(ISSHKeyWizardPageModel model) {
+		super("key name");
+		this.model = model;
+	}
+
+	@Override
+	public IStatus validateString(String value) {
+		IStatus validationStatus = super.validateString(value);
+		if (!validationStatus.isOK()) {
+			return validationStatus;
+		}
+		if (model.hasKeyName(value)) {
+			return ValidationStatus.error("There's already a key with the name " + value);
+		}
+		return ValidationStatus.ok();
+
+	}
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyNameValidator.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Copied: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java (from rev 43816, trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyValidator.java)
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java	2012-09-19 17:39:16 UTC (rev 43839)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.wizard.ssh.databinding;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.validation.MultiValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
+import org.jboss.tools.openshift.express.internal.ui.wizard.ssh.AddSSHKeyWizardPageModel;
+
+import com.openshift.client.OpenShiftException;
+import com.openshift.client.SSHPublicKey;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class SSHPublicKeyValidator extends MultiValidator {
+
+	private IObservableValue filePathObservable;
+	private AddSSHKeyWizardPageModel model;
+
+	public SSHPublicKeyValidator(IObservableValue filePathObservable, AddSSHKeyWizardPageModel model) {
+		this.filePathObservable = filePathObservable;
+		this.model = model;
+	}
+
+	@Override
+	protected IStatus validate() {
+		String filePath = (String) filePathObservable.getValue();
+		if (StringUtils.isEmpty(filePath)) {
+			return ValidationStatus.cancel("You have to supply a public SSH key.");
+		}
+		try {
+			SSHPublicKey sshPublicKey = new SSHPublicKey(filePath);
+			if (model.hasPublicKey(sshPublicKey.getPublicKey())) {
+				return ValidationStatus.error("The public key in " + filePath + " is already in use on OpenShift. Choose another key.");
+			}
+		} catch (FileNotFoundException e) {
+			return ValidationStatus.error("Could not load file: " + e.getMessage());
+		} catch (OpenShiftException e) {
+			return ValidationStatus.error(filePath + "is not a valid public SSH key: " + e.getMessage());
+		} catch (IOException e) {
+			return ValidationStatus.error("Could not load file: " + e.getMessage());
+		}
+
+		return Status.OK_STATUS;
+	}
+
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list