[jbosstools-commits] JBoss Tools SVN: r43802 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui: wizard/ssh and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Tue Sep 18 12:59:25 EDT 2012
Author: adietish
Date: 2012-09-18 12:59:25 -0400 (Tue, 18 Sep 2012)
New Revision: 43802
Added:
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/AddSSHKeyJob.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizard.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
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/wizard/ssh/AddSSHKeyWizard.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/ManageSSHKeysWizard.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java
Log:
[JBIDE-11912] implementing "Add new SSH key"
Added: 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 (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/NonEmptyStringValidator.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -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 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();
+ }
+
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/NonEmptyStringValidator.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/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 (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -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;
+
+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;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class AddSSHKeyJob extends Job {
+
+ private AddSSHKeyWizardPageModel model;
+
+ public AddSSHKeyJob(AddSSHKeyWizardPageModel model) {
+ super("Adding SSH key " + model.getName() + "...");
+ this.model = model;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ model.addConfiguredSSHKey();
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ NLS.bind("Could not add SSH key {0} to OpenShift", model.getName()), e);
+ }
+ }
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.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/AddSSHKeyWizard.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizard.java 2012-09-18 15:25:00 UTC (rev 43801)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizard.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * 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,
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-18 15:25:00 UTC (rev 43801)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -10,26 +10,17 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard.ssh;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.ValidationStatusProvider;
import org.eclipse.core.databinding.beans.BeanProperties;
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.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -44,15 +35,10 @@
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.AlphanumericStringValidator;
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 com.openshift.client.OpenShiftException;
-import com.openshift.client.SSHPublicKey;
-
/**
* @author André Dietisheim
*/
@@ -88,42 +74,27 @@
.align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(nameText);
Binding nameBinding = ValueBindingBuilder
.bind(WidgetProperties.text(SWT.Modify).observe(nameText))
- .validatingAfterConvert(new AlphanumericStringValidator("key name") {
-
- @Override
- public IStatus validate(Object value) {
- IStatus validationStatus = super.validate(value);
- if (!validationStatus.isOK()) {
- return validationStatus;
- }
- String keyName = (String) value;
- if (pageModel.hasKeyName(keyName)) {
- return ValidationStatus.error("There's already a key with the name " + keyName);
- }
- return ValidationStatus.ok();
- }
-
- })
+ .validatingAfterConvert(new SSHPublicKeyNameValidator(pageModel))
.to(BeanProperties.value(AddSSHKeyWizardPageModel.PROPERTY_NAME).observe(pageModel))
.notUpdatingParticipant()
.in(dbc);
ControlDecorationSupport.create(
nameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
- Label fileLabel = new Label(addSSHKeyGroup, SWT.NONE);
+ Label publicKeyLabel = new Label(addSSHKeyGroup, SWT.NONE);
GridDataFactory.fillDefaults()
- .align(SWT.LEFT, SWT.CENTER).applyTo(fileLabel);
- fileLabel.setText("SSH Key:");
+ .align(SWT.LEFT, SWT.CENTER).applyTo(publicKeyLabel);
+ publicKeyLabel.setText("Public Key:");
- Text fileText = new Text(addSSHKeyGroup, SWT.BORDER);
- fileText.setEditable(false);
+ Text publicKeyText = new Text(addSSHKeyGroup, SWT.BORDER);
+ publicKeyText.setEditable(false);
GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fileText);
- IObservableValue filePathObservable =
- WidgetProperties.text(SWT.Modify).observe(fileText);
+ .align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(publicKeyText);
+ IObservableValue publicKeyObservable =
+ WidgetProperties.text(SWT.Modify).observe(publicKeyText);
ValueBindingBuilder
- .bind(filePathObservable)
- .to(BeanProperties.value(AddSSHKeyWizardPageModel.PROPERTY_FILEPATH).observe(pageModel))
+ .bind(publicKeyObservable)
+ .to(BeanProperties.value(AddSSHKeyWizardPageModel.PROPERTY_PUBLICKEY_PATH).observe(pageModel))
.in(dbc);
Button browseButton = new Button(addSSHKeyGroup, SWT.PUSH);
@@ -132,7 +103,7 @@
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.CENTER).applyTo(browseButton);
- ValidationStatusProvider sshPublicKeyValidator = new SSHPublicKeyValidator(filePathObservable);
+ ValidationStatusProvider sshPublicKeyValidator = new SSHPublicKeyValidator(publicKeyObservable, pageModel);
dbc.addValidationStatusProvider(sshPublicKeyValidator);
ControlDecorationSupport.create(
sshPublicKeyValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
@@ -147,7 +118,7 @@
dialog.setFilterPath(SSHUtils.getSSH2Home());
String filePath = null;
if ((filePath = dialog.open()) != null) {
- pageModel.setFilePath(filePath);
+ pageModel.setPublicKeyPath(filePath);
}
}
};
@@ -155,60 +126,9 @@
public IStatus addConfiguredSSHKey() {
try {
- return WizardUtils.runInWizard(new AddSSHKeyJob(), getContainer());
+ return WizardUtils.runInWizard(new AddSSHKeyJob(pageModel), getContainer());
} catch (Exception e) {
return OpenShiftUIActivator.createErrorStatus("Could not add ssh key " + pageModel.getName() + ".");
}
}
-
- private class AddSSHKeyJob extends Job {
-
- public AddSSHKeyJob() {
- super("Adding SSH key " + pageModel.getName() + "...");
- }
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- pageModel.addConfiguredSSHKey();
- return Status.OK_STATUS;
- } catch (Exception e) {
- return OpenShiftUIActivator.createErrorStatus(
- NLS.bind("Could not add SSH key {0} to OpenShift", pageModel.getName()), e);
- }
- }
- }
-
- public class SSHPublicKeyValidator extends MultiValidator {
-
- private IObservableValue filePathObservable;
-
- public SSHPublicKeyValidator(IObservableValue filePathObservable) {
- this.filePathObservable = filePathObservable;
- }
-
- @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 (pageModel.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;
- }
-
- }
-
}
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-18 15:25:00 UTC (rev 43801)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * 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,
@@ -25,7 +25,7 @@
*/
public class AddSSHKeyWizardPageModel extends ObservableUIPojo {
- public static final String PROPERTY_FILEPATH = "filePath";
+ public static final String PROPERTY_PUBLICKEY_PATH = "publicKeyPath";
public static final String PROPERTY_NAME = "name";
private String name;
@@ -36,10 +36,14 @@
this.user = user;
}
- public String getFilePath() {
+ public String getPublicKeyPath() {
return filePath;
}
+ public void setPublicKeyPath(String filePath) {
+ firePropertyChange(PROPERTY_PUBLICKEY_PATH, this.filePath, this.filePath = filePath);
+ }
+
public String getName() {
return name;
}
@@ -48,10 +52,6 @@
firePropertyChange(PROPERTY_NAME, this.name, this.name = name);
}
- public void setFilePath(String filePath) {
- firePropertyChange(PROPERTY_FILEPATH, this.filePath, this.filePath = filePath);
- }
-
public boolean hasKeyName(String name) {
return user.hasSSHKeyName(name);
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizard.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizard.java 2012-09-18 15:25:00 UTC (rev 43801)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizard.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * 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,
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java 2012-09-18 15:25:00 UTC (rev 43801)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -19,6 +19,7 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.databinding.viewers.ViewerProperties;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
@@ -80,17 +81,18 @@
.to(BeanProperties.value(ManageSSHKeysWizardPageModel.PROPERTY_SELECTED_KEY).observe(pageModel))
.in(dbc);
- Button addButton = new Button(sshKeysGroup, SWT.PUSH);
+ Button addExistingButton = new Button(sshKeysGroup, SWT.PUSH);
GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.FILL).applyTo(addButton);
- addButton.setText("Add Existing...");
- addButton.addSelectionListener(onAdd());
+ .align(SWT.FILL, SWT.FILL).applyTo(addExistingButton);
+ addExistingButton.setText("Add Existing...");
+ addExistingButton.addSelectionListener(onAddExisting());
- Button newButton = new Button(sshKeysGroup, SWT.PUSH);
+ Button addNewButton = new Button(sshKeysGroup, SWT.PUSH);
GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.FILL).applyTo(newButton);
- newButton.setText("New...");
-
+ .align(SWT.FILL, SWT.FILL).applyTo(addNewButton);
+ addNewButton.setText("New...");
+ addNewButton.addSelectionListener(onAddNew());
+
Button removeButton = new Button(sshKeysGroup, SWT.PUSH);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).applyTo(removeButton);
@@ -134,12 +136,16 @@
};
}
- private SelectionListener onAdd() {
+ private SelectionListener onAddExisting() {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- WizardUtils.openWizardDialog(new AddSSHKeyWizard(pageModel.getUser()), getShell());
+ if (WizardUtils.openWizardDialog(new AddSSHKeyWizard(pageModel.getUser()), getShell())
+ == Dialog.CANCEL) {
+ return;
+ }
+
try {
WizardUtils.runInWizard(
new RefreshViewerJob(),
@@ -152,6 +158,28 @@
};
}
+ private SelectionListener onAddNew() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if(WizardUtils.openWizardDialog(new NewSSHKeyWizard(pageModel.getUser()), getShell())
+ == Dialog.CANCEL) {
+ return;
+ }
+
+ try {
+ WizardUtils.runInWizard(
+ new RefreshViewerJob(),
+ getContainer());
+ } catch (Exception ex) {
+ StatusManager.getManager().handle(
+ OpenShiftUIActivator.createErrorStatus("Could not refresh keys.", ex), StatusManager.LOG);
+ }
+ }
+ };
+ }
+
protected TableViewer createTable(Composite tableContainer) {
Table table =
new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizard.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizard.java (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizard.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.wizard.Wizard;
+import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+
+/**
+ * @author André Dietisheim
+ */
+public class NewSSHKeyWizard extends Wizard {
+
+ private UserDelegate user;
+ private NewSSHKeyWizardPage newSSHKeyWizardPage;
+
+ public NewSSHKeyWizard(UserDelegate user) {
+ this.user = user;
+ setNeedsProgressMonitor(true);
+ }
+
+ @Override
+ public boolean performFinish() {
+ IStatus status = newSSHKeyWizardPage.addConfiguredSSHKey();
+ return status.isOK();
+ }
+
+ @Override
+ public void addPages() {
+ addPage(this.newSSHKeyWizardPage = new NewSSHKeyWizardPage(user, this));
+ }
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizard.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/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 (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * 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.eclipse.core.databinding.Binding;
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.common.ui.WizardUtils;
+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.RequiredControlDecorationUpdater;
+import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
+import org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftWizardPage;
+
+/**
+ * @author André Dietisheim
+ */
+public class NewSSHKeyWizardPage extends AbstractOpenShiftWizardPage {
+
+ private NewSSHKeyWizardPageModel pageModel;
+
+ public NewSSHKeyWizardPage(UserDelegate user, IWizard wizard) {
+ super("Add new SSH key", "Add a new SSH key to your OpenShift account",
+ "NewSSHKeysPage", wizard);
+ this.pageModel = new NewSSHKeyWizardPageModel(user);
+ }
+
+ @Override
+ protected void doCreateControls(Composite parent, DataBindingContext dbc) {
+ GridLayoutFactory.fillDefaults()
+ .margins(10, 10).applyTo(parent);
+
+ Group newSSHKeyGroup = new Group(parent, SWT.NONE);
+ newSSHKeyGroup.setText("New SSH Key");
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(newSSHKeyGroup);
+ GridLayoutFactory.fillDefaults()
+ .numColumns(3).margins(6, 6).applyTo(newSSHKeyGroup);
+
+ Label nameLabel = new Label(newSSHKeyGroup, SWT.NONE);
+ nameLabel.setText("Name:");
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).applyTo(nameLabel);
+
+ Text nameText = new Text(newSSHKeyGroup, SWT.BORDER);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(nameText);
+ Binding nameBinding = ValueBindingBuilder
+ .bind(WidgetProperties.text(SWT.Modify).observe(nameText))
+ .validatingAfterConvert(new SSHPublicKeyNameValidator(pageModel))
+ .to(BeanProperties.value(NewSSHKeyWizardPageModel.PROPERTY_NAME).observe(pageModel))
+ .notUpdatingParticipant()
+ .in(dbc);
+ ControlDecorationSupport.create(
+ nameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
+
+ Label ssh2HomeLabel = new Label(newSSHKeyGroup, SWT.NONE);
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).applyTo(ssh2HomeLabel);
+ ssh2HomeLabel.setText("SSH2 Home:");
+
+ Text ssh2HomeText = new Text(newSSHKeyGroup, SWT.BORDER);
+ ssh2HomeText.setEditable(false);
+ GridDataFactory.fillDefaults()
+ .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"))
+ .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());
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).applyTo(ss2HomeBrowseButton);
+
+ Label privateKeyLabel = new Label(newSSHKeyGroup, SWT.NONE);
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).applyTo(privateKeyLabel);
+ privateKeyLabel.setText("Private Key:");
+
+ Text privateKeyText = new Text(newSSHKeyGroup, SWT.BORDER);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 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))
+ .in(dbc);
+ ControlDecorationSupport.create(
+ privateKeyBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
+
+ Label passphraseLabel = new Label(newSSHKeyGroup, SWT.NONE);
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).applyTo(passphraseLabel);
+ passphraseLabel.setText("Private Key Passphrase:");
+
+ Text passphraseText = new Text(newSSHKeyGroup, SWT.BORDER | SWT.PASSWORD);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 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);
+
+ Label publicKeyLabel = new Label(newSSHKeyGroup, SWT.NONE);
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).applyTo(publicKeyLabel);
+ publicKeyLabel.setText("Public Key:");
+
+ Text publicKeyText = new Text(newSSHKeyGroup, SWT.BORDER);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 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))
+ .in(dbc);
+ ControlDecorationSupport.create(
+ publicKeyBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
+ }
+
+ private SelectionListener onBrowse() {
+ 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);
+ }
+ }
+ };
+ }
+
+ public IStatus addConfiguredSSHKey() {
+ try {
+ return WizardUtils.runInWizard(new AddSSHKeyJob(pageModel), getContainer());
+ } catch (Exception e) {
+ return OpenShiftUIActivator.createErrorStatus("Could not add ssh key " + pageModel.getName() + ".");
+ }
+ }
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.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/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 (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -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.wizard.ssh;
+
+import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+
+import com.openshift.client.SSHKeyType;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class NewSSHKeyWizardPageModel extends AddSSHKeyWizardPageModel {
+
+ 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_PRIVATEKEY_PASSPHRASE = "privateKeyPassphrase";
+
+ private SSHKeyType type;
+ private String ssh2Home;
+ private String privateKeyPath;
+ private String privateKeyPathphrase;
+
+ public NewSSHKeyWizardPageModel(UserDelegate user) {
+ super(user);
+ }
+
+ public SSHKeyType getType() {
+ return type;
+ }
+
+ public void setType(SSHKeyType type) {
+ firePropertyChange(PROPERTY_TYPE, this.type, this.type = type);
+ }
+
+ public String getPrivateKeyPathphrase() {
+ return privateKeyPathphrase;
+ }
+
+ public void setPrivateKeyPathphrase(String privateKeyPathphrase) {
+ firePropertyChange(PROPERTY_PRIVATEKEY_PASSPHRASE,
+ this.privateKeyPathphrase, this.privateKeyPathphrase = privateKeyPathphrase);
+ }
+
+ public String getPrivateKeyPath() {
+ return privateKeyPath;
+ }
+
+ public void setPrivateKeyPath(String privateKeyPath) {
+ firePropertyChange(PROPERTY_PRIVATEKEY_PATH, this.privateKeyPath, this.privateKeyPath = privateKeyPath);
+ }
+
+ public String getSSH2Home() {
+ return ssh2Home;
+ }
+
+ public void setSSH2Home(String ssh2Home) {
+ firePropertyChange(PROPERTY_SSH2_HOME, this.ssh2Home, this.ssh2Home = ssh2Home);
+ }
+
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.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/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 (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyNameValidator.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -0,0 +1,29 @@
+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();
+
+ }
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyNameValidator.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/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 (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyValidator.java 2012-09-18 16:59:25 UTC (rev 43802)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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;
+ }
+
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/SSHPublicKeyValidator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
More information about the jbosstools-commits
mailing list