[jbosstools-commits] JBoss Tools SVN: r43754 - 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
Mon Sep 17 12:57:11 EDT 2012


Author: adietish
Date: 2012-09-17 12:57:11 -0400 (Mon, 17 Sep 2012)
New Revision: 43754

Added:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java
Removed:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/ValidationStatusControlDecoration.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CustomControlDecorationUpdater.java
Modified:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EditDomainWizardPage.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
   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/ManageSSHKeysWizardPageModel.java
Log:
[JBIDE-11912] implemented binding and decoration. Renamed CustomControlDecorationUpdater to RequiredControlDecorationUpdater & moved to databinding package. Extracted AlphanumerStringValidator. Extracted SSH2Home extraction from DomainWizard to util-class.

Deleted: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/ValidationStatusControlDecoration.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/ValidationStatusControlDecoration.java	2012-09-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/ValidationStatusControlDecoration.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -1,88 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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;
-
-import org.eclipse.core.databinding.ValidationStatusProvider;
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.observable.value.IValueChangeListener;
-import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.fieldassist.ControlDecoration;
-import org.eclipse.jface.fieldassist.FieldDecoration;
-import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.widgets.Control;
-
-/**
- * @author André Dietisheim
- */
-public class ValidationStatusControlDecoration {
-
-	private IObservableValue validationStatus;
-
-	public ValidationStatusControlDecoration(ValidationStatusProvider provider) {
-		this.validationStatus = provider.getValidationStatus();
-	}
-
-	public void showFor(Control control, int position) {
-		ControlDecoration decoration = createDecoration(control, position);
-		IValueChangeListener validationStatusListener = onValidationStatusChanged(decoration);
-		
-		validationStatus.addValueChangeListener(validationStatusListener);
-		control.addDisposeListener(onControlDisposed(validationStatusListener));
-
-	}
-	
-	private ControlDecoration createDecoration(Control control, int position) {
-		ControlDecoration controlDecoration = new ControlDecoration(control, position);
-		FieldDecoration fieldDecoration =
-				FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
-		controlDecoration.setImage(fieldDecoration.getImage());
-		if (validationStatus.getValue() instanceof IStatus) {
-			showDecoration(controlDecoration, (IStatus) validationStatus.getValue());
-		}
-		return controlDecoration;
-	}
-
-	private DisposeListener onControlDisposed(final IValueChangeListener validationStatusListener) {
-		return new DisposeListener() {
-			
-			@Override
-			public void widgetDisposed(DisposeEvent e) {
-				validationStatus.removeValueChangeListener(validationStatusListener);
-			}
-		};
-	}
-
-	private IValueChangeListener onValidationStatusChanged(final ControlDecoration controlDecoration) {
-		return new IValueChangeListener() {
-
-			@Override
-			public void handleValueChange(ValueChangeEvent event) {
-				if (!(event.diff.getNewValue() instanceof IStatus)) {
-					return;
-				}
-				IStatus validationStatus = (IStatus) event.diff.getNewValue();
-				showDecoration(controlDecoration, validationStatus);
-			}
-		};
-	}
-
-	private void showDecoration(final ControlDecoration controlDecoration, IStatus validationStatus) {
-		if (validationStatus.isOK()) {
-			controlDecoration.hide();
-		} else {
-			controlDecoration.show();
-		}
-	}
-
-}

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.utils;
+
+import org.eclipse.jsch.internal.core.IConstants;
+import org.eclipse.jsch.internal.core.JSchCorePlugin;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class SSHUtils {
+
+	public static String getSSH2Home() {
+		return JSchCorePlugin.getPlugin().getPluginPreferences().getString(IConstants.KEY_SSH2HOME);
+	}
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.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/ApplicationConfigurationWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java	2012-09-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -76,6 +76,7 @@
 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.RequiredControlDecorationUpdater;
 import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
 import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
 import org.jboss.tools.openshift.express.internal.ui.utils.UIUtils;
@@ -179,7 +180,7 @@
 						useExistingAppBtnSelection, existingAppNameTextObservable, existingApplicationsLoaded);
 		dbc.addValidationStatusProvider(existingAppValidator);
 		ControlDecorationSupport.create(
-				existingAppValidator, SWT.LEFT | SWT.TOP, null, new CustomControlDecorationUpdater(false));
+				existingAppValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(false));
 		return existingAppSelectionGroup;
 	}
 
@@ -262,7 +263,7 @@
 				new NewApplicationNameValidator(useExistingAppBtnSelection, applicationNameTextObservable);
 		dbc.addValidationStatusProvider(newApplicationNameValidator);
 		ControlDecorationSupport.create(
-				newApplicationNameValidator, SWT.LEFT | SWT.TOP, null, new CustomControlDecorationUpdater());
+				newApplicationNameValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
 
 		// application type
 		final Label newAppTypeLabel = new Label(newAppConfigurationGroup, SWT.NONE);
@@ -343,7 +344,7 @@
 				new NewApplicationTypeValidator(useExistingAppBtnSelection, selectedCartridgeIndexObservable);
 		dbc.addValidationStatusProvider(newApplicationTypeValidator);
 		ControlDecorationSupport.create(newApplicationTypeValidator, SWT.LEFT | SWT.TOP, null,
-				new CustomControlDecorationUpdater());
+				new RequiredControlDecorationUpdater());
 
 		// embeddable cartridges
 		this.newAppEmbeddableCartridgesGroup = new Group(newAppConfigurationGroup, SWT.NONE);

Deleted: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CustomControlDecorationUpdater.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CustomControlDecorationUpdater.java	2012-09-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CustomControlDecorationUpdater.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -1,70 +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;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.databinding.fieldassist.ControlDecorationUpdater;
-import org.eclipse.jface.fieldassist.FieldDecoration;
-import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * @author Xavier Coulon
- * 
- */
-public class CustomControlDecorationUpdater extends ControlDecorationUpdater {
-
-	private final boolean showRequiredDecorator;
-	
-	/**
-	 * Default constructor: provides a 'REQUIRED' decorator when the status is CANCEL
-	 */
-	public CustomControlDecorationUpdater() {
-		this(true);
-	}
-	
-	/**
-	 * Default constructor: provides a 'REQUIRED' decorator when the status is CANCEL
-	 */
-	public CustomControlDecorationUpdater(final boolean showRequiredDecorator) {
-		super();
-		this.showRequiredDecorator = showRequiredDecorator;
-	}
-	
-	/**
-	 * {@inheritDoc} Overrides the standard behaviour: for CANCEL status, items are decorated with the REQUIRED
-	 * decorator, not the ERROR one.
-	 */
-	@Override
-	protected Image getImage(IStatus status) {
-		if (status == null) {
-			return null;
-		}
-		String fieldDecorationID = null;
-		switch (status.getSeverity()) {
-		case IStatus.INFO:
-			fieldDecorationID = FieldDecorationRegistry.DEC_INFORMATION;
-			break;
-		case IStatus.WARNING:
-			fieldDecorationID = FieldDecorationRegistry.DEC_WARNING;
-			break;
-		case IStatus.ERROR:
-			fieldDecorationID = FieldDecorationRegistry.DEC_ERROR;
-			break;
-		case IStatus.CANCEL:
-			fieldDecorationID = showRequiredDecorator ? FieldDecorationRegistry.DEC_REQUIRED : null;
-			break;
-		}
-
-		FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(fieldDecorationID);
-		return fieldDecoration == null ? null : fieldDecoration.getImage();
-	}
-}

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EditDomainWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EditDomainWizardPage.java	2012-09-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EditDomainWizardPage.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -30,6 +30,7 @@
 import org.eclipse.swt.widgets.Text;
 import org.jboss.tools.common.ui.databinding.ParametrizableWizardPageSupport;
 import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
+import org.jboss.tools.openshift.express.internal.ui.databinding.RequiredControlDecorationUpdater;
 import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
 
 /**
@@ -63,7 +64,7 @@
 		final NamespaceValidator namespaceValidator = new NamespaceValidator(namespaceTextObservable);
 		dbc.addValidationStatusProvider(namespaceValidator);
 		ControlDecorationSupport.create(namespaceValidator, SWT.LEFT | SWT.TOP, null,
-				new CustomControlDecorationUpdater());
+				new RequiredControlDecorationUpdater());
 		final IObservableValue namespaceModelObservable = BeanProperties.value(
 				EditDomainWizardPageModel.PROPERTY_DOMAIN_ID).observe(pageModel);
 		ValueBindingBuilder.bind(namespaceTextObservable).to(namespaceModelObservable).in(dbc);

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java	2012-09-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -53,8 +53,10 @@
 import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
 import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
 import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.databinding.RequiredControlDecorationUpdater;
 import org.jboss.tools.openshift.express.internal.ui.utils.FileUtils;
 import org.jboss.tools.openshift.express.internal.ui.utils.SSHUserConfig;
+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;
@@ -89,7 +91,7 @@
 		final NamespaceValidator namespaceValidator = new NamespaceValidator(namespaceTextObservable);
 		dbc.addValidationStatusProvider(namespaceValidator);
 		ControlDecorationSupport.create(namespaceValidator, SWT.LEFT | SWT.TOP, null,
-				new CustomControlDecorationUpdater());
+				new RequiredControlDecorationUpdater());
 		final IObservableValue namespaceModelObservable = BeanProperties.value(
 				NewDomainWizardPageModel.PROPERTY_DOMAIN_ID).observe(pageModel);
 		ValueBindingBuilder.bind(namespaceTextObservable).to(namespaceModelObservable).in(dbc);
@@ -232,7 +234,7 @@
 			if (pageModel.hasConfiguredFixedPrivateKeys()) {
 				return ValidationStatus.warning(
 						NLS.bind("Your SSH config ({0}) contains fixed keys for OpenShift servers. " +
-								"This can override any Eclipse specific SSH key preferences.", new SSHUserConfig(pageModel.getSSH2Home()).getFile()));
+								"This can override any Eclipse specific SSH key preferences.", new SSHUserConfig(SSHUtils.getSSH2Home()).getFile()));
 			} else if (!isKeyKnownToSsh((String) value)) {
 					return ValidationStatus.warning(
 							NLS.bind("Could not find the private portion for your public key in the preferences. "

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java	2012-09-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -23,6 +23,7 @@
 import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
 import org.jboss.tools.openshift.express.internal.ui.utils.FileUtils;
 import org.jboss.tools.openshift.express.internal.ui.utils.SSHUserConfig;
+import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
 
 import com.openshift.client.IDomain;
 import com.openshift.client.IOpenShiftSSHKey;
@@ -90,7 +91,7 @@
 	}
 
 	private String checkedGetSSH2Home() throws OpenShiftException {
-		String ssh2Home = getSSH2Home();
+		String ssh2Home = SSHUtils.getSSH2Home();
 		if (ssh2Home == null 
 				|| ssh2Home.trim().length() == 0) {
 			throw new OpenShiftException("Could not determine your ssh2 home directory");
@@ -98,10 +99,6 @@
 		return ssh2Home;
 	}
 	
-	public String getSSH2Home() {
-		return JSchCorePlugin.getPlugin().getPluginPreferences().getString(IConstants.KEY_SSH2HOME);
-	}
-
 	public boolean hasConfiguredFixedPrivateKeys() {
 		try {
 			SSHUserConfig sshUserConfig = new SSHUserConfig(checkedGetSSH2Home());

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-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizard.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -19,7 +19,8 @@
 public class AddSSHKeyWizard extends Wizard {
 
 	private UserDelegate user;
-
+	private AddSSHKeyWizardPage addSSHKeyWizardPage;
+	
 	public AddSSHKeyWizard(UserDelegate user) {
 		this.user = user;
 		setNeedsProgressMonitor(true);
@@ -27,11 +28,12 @@
 
 	@Override
 	public boolean performFinish() {
+		addSSHKeyWizardPage.addConfiguredSSHKey();
 		return true;
 	}
 
 	@Override
 	public void addPages() {
-		addPage(new AddSSHKeyWizardPage(user, this));
+		addPage(this.addSSHKeyWizardPage = new AddSSHKeyWizardPage(user, this));
 	}
 }

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-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -10,17 +10,29 @@
  ******************************************************************************/
 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.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.FileDialog;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
+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.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.wizard.AbstractOpenShiftWizardPage;
 
 /**
@@ -28,12 +40,12 @@
  */
 public class AddSSHKeyWizardPage extends AbstractOpenShiftWizardPage {
 
-	private UserDelegate user;
+	private AddSSHKeyWizardPageModel pageModel;
 
 	public AddSSHKeyWizardPage(UserDelegate user, IWizard wizard) {
 		super("Add existing SSH Key", "Add an exiting SSH key to your OpenShift account",
 				"AddSSHKeysPage", wizard);
-		this.user = user;
+		this.pageModel = new AddSSHKeyWizardPageModel(user);
 	}
 
 	@Override
@@ -54,9 +66,16 @@
 				.align(SWT.LEFT, SWT.CENTER).applyTo(nameLabel);
 
 		Text nameText = new Text(addSSHKeyGroup, SWT.BORDER);
-		nameText.setEditable(false);
 		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 AlphanumericStringValidator("key name"))
+				.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);
 		GridDataFactory.fillDefaults()
@@ -67,10 +86,38 @@
 		fileText.setEditable(false);
 		GridDataFactory.fillDefaults()
 				.align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fileText);
+		Binding filePathBinding = ValueBindingBuilder
+				.bind(WidgetProperties.text(SWT.Modify).observe(fileText))
+				.validatingAfterConvert(new AlphanumericStringValidator("key file"))
+				.to(BeanProperties.value(AddSSHKeyWizardPageModel.PROPERTY_FILEPATH).observe(pageModel))
+				.in(dbc);
+		ControlDecorationSupport.create(
+				filePathBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
 
 		Button browseButton = new Button(addSSHKeyGroup, SWT.PUSH);
+		browseButton.setText("Browse...");
+		browseButton.addSelectionListener(onBrowse());
 		GridDataFactory.fillDefaults()
 				.align(SWT.FILL, SWT.CENTER).applyTo(browseButton);
-		browseButton.setText("Browse...");
+
 	}
-}
\ No newline at end of file
+
+	private SelectionListener onBrowse() {
+		return new SelectionAdapter() {
+
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
+				dialog.setFilterPath(SSHUtils.getSSH2Home());
+				String filePath = null;
+				if ((filePath = dialog.open()) != null) {
+					pageModel.setFilePath(filePath);
+				}
+			}
+		};
+	}
+
+	public void addConfiguredSSHKey() {
+		pageModel.addConfiguredSSHKey();
+	}
+}

Added: 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	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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 class AddSSHKeyWizardPageModel extends ObservableUIPojo {
+
+	public static final String PROPERTY_FILEPATH = "filePath";
+	public static final String PROPERTY_NAME = "name";
+	
+	private String name;
+	private String filePath;
+	private UserDelegate user;
+	
+	public AddSSHKeyWizardPageModel(UserDelegate user) {
+		this.user = user;
+	}
+
+	public String getFilePath() {
+		return filePath;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		firePropertyChange(PROPERTY_NAME, this.name, this.name = name);
+	}
+
+	public void setFilePath(String filePath) {
+		firePropertyChange(PROPERTY_FILEPATH, this.filePath, this.filePath = filePath);
+	}
+	
+	public void addConfiguredSSHKey() {
+	}
+	
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.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/ManageSSHKeysWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPageModel.java	2012-09-17 16:54:41 UTC (rev 43753)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPageModel.java	2012-09-17 16:57:11 UTC (rev 43754)
@@ -41,7 +41,6 @@
 	}
 
 	public List<IOpenShiftSSHKey> setSSHKeys(List<IOpenShiftSSHKey> keys) {
-		this.keys = keys;
 		firePropertyChange(PROPERTY_SSH_KEYS, this.keys, this.keys = keys);
 		return this.keys;
 	}



More information about the jbosstools-commits mailing list