From d658c53b0599c067da9ae032b65d88fa057a3fc2 Mon Sep 17 00:00:00 2001 From: Shireesh Anjal Date: Wed, 9 Nov 2011 14:00:59 +0530 Subject: Introduced system property login.password for avoiding human intervention on login dialog while running SWTBot automated tests. --- .../management/console/ConsoleConstants.java | 1 + .../management/console/dialogs/LoginDialog.java | 26 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/com.gluster.storage.management.console/src/com/gluster/storage') diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ConsoleConstants.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ConsoleConstants.java index 47293228..4b5bbe15 100644 --- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ConsoleConstants.java +++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ConsoleConstants.java @@ -24,4 +24,5 @@ package com.gluster.storage.management.console; public class ConsoleConstants { public static final String CONSOLE_TITLE = "Gluster Management Console"; public static final String TERMINAL_VIEW_ID = "org.eclipse.tm.terminal.view.TerminalView"; + public static final String PROPERTY_LOGIN_PASSWORD = "login.password"; } diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java index 4622dc84..22e0620c 100644 --- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java +++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java @@ -34,6 +34,8 @@ import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.layout.GridData; @@ -49,9 +51,10 @@ import org.eclipse.swt.widgets.Text; import com.gluster.storage.management.client.ClustersClient; import com.gluster.storage.management.client.UsersClient; import com.gluster.storage.management.console.Activator; +import com.gluster.storage.management.console.ConsoleConstants; import com.gluster.storage.management.console.GlusterDataModelManager; import com.gluster.storage.management.console.IImageKeys; -import static com.gluster.storage.management.console.dialogs.ClusterSelectionDialog.CLUSTER_MODE; +import com.gluster.storage.management.console.dialogs.ClusterSelectionDialog.CLUSTER_MODE; import com.gluster.storage.management.console.preferences.PreferenceConstants; import com.gluster.storage.management.console.utils.GUIHelper; import com.gluster.storage.management.console.validators.StringRequiredValidator; @@ -171,6 +174,7 @@ public class LoginDialog extends Dialog { createPasswordLabel(composite); createPasswordText(composite); + setupAutoLoginIfRequired(); return composite; } @@ -203,6 +207,26 @@ public class LoginDialog extends Dialog { setupDataBinding(); } + private void setupAutoLoginIfRequired() { + final String password = System.getProperty(ConsoleConstants.PROPERTY_LOGIN_PASSWORD, null); + if (password == null) { + return; + } + getShell().addShellListener(new ShellAdapter() { + @Override + public void shellActivated(ShellEvent e) { + super.shellActivated(e); + + if (passwordText.getText().isEmpty()) { + // Check whether the password has been passed as system parameter. This can be used for avoiding + // human intervention on login dialog while running SWTBot automated tests. + passwordText.setText(password); + okPressed(); + } + } + }); + } + /** * Sets up data binding between the text fields and the connection details object. Also attaches a "string required" * validator to the "password" text field. This validator is configured to do the following on validation failure
-- cgit