directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1461216 - in /directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui: UIAuthHandler.java dialogs/CredentialsDialog.java dialogs/PasswordDialog.java
Date Tue, 26 Mar 2013 16:43:45 GMT
Author: pamarcelot
Date: Tue Mar 26 16:43:44 2013
New Revision: 1461216

URL: http://svn.apache.org/r1461216
Log:
Fix for DIRSTUDIO-895 (Add a 'Show password' checkbox to the CredentialsDialog used to ask
the connection's password when it's not saved).
Also renamed the class from 'CredentialsDialog' to 'PasswordDialog'.

Added:
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/PasswordDialog.java
      - copied, changed from r1459201, directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java
Removed:
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java
Modified:
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java?rev=1461216&r1=1461215&r2=1461216&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java
Tue Mar 26 16:43:44 2013
@@ -25,7 +25,7 @@ import org.apache.directory.studio.conne
 import org.apache.directory.studio.connection.core.Credentials;
 import org.apache.directory.studio.connection.core.IAuthHandler;
 import org.apache.directory.studio.connection.core.ICredentials;
-import org.apache.directory.studio.connection.ui.dialogs.CredentialsDialog;
+import org.apache.directory.studio.connection.ui.dialogs.PasswordDialog;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.ui.PlatformUI;
 
@@ -60,15 +60,15 @@ public class UIAuthHandler implements IA
             {
                 public void run()
                 {
-                    CredentialsDialog dialog = new CredentialsDialog(
+                    PasswordDialog dialog = new PasswordDialog(
                         PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                         NLS.bind(
                             Messages.getString( "UIAuthHandler.EnterPasswordFor" ), new String[]
{ connectionParameter.getName() } ), //$NON-NLS-1$
                         NLS.bind(
-                            Messages.getString( "UIAuthHandler.PleaseEnterPasswordOfUser"
), connectionParameter.getBindPrincipal() ), "", null ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
-                    if ( dialog.open() == CredentialsDialog.OK )
+                            Messages.getString( "UIAuthHandler.PleaseEnterPasswordOfUser"
), connectionParameter.getBindPrincipal() ), "" ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+                    if ( dialog.open() == PasswordDialog.OK )
                     {
-                        pw[0] = dialog.getValue();
+                        pw[0] = dialog.getPassword();
                     }
                     else
                     {

Copied: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/PasswordDialog.java
(from r1459201, directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java)
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/PasswordDialog.java?p2=directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/PasswordDialog.java&p1=directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java&r1=1459201&r2=1461216&rev=1461216&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/PasswordDialog.java
Tue Mar 26 16:43:44 2013
@@ -21,44 +21,149 @@
 package org.apache.directory.studio.connection.ui.dialogs;
 
 
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.jface.dialogs.InputDialog;
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
 
 
 /**
- * The CredentialsDialog is used to ask the user for credentials (paasword).
+ * The PasswordDialog is used to ask the user for password (credentials).
+ * <p>
+ * It has a useful checkbox that can show/hide the typed password.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class CredentialsDialog extends InputDialog
+public class PasswordDialog extends Dialog
 {
+    /** The title of the dialog */
+    private String title;
+
+    /** The message to display, or <code>null</code> if none */
+    private String message;
+
+    /** The input value; the empty string by default */
+    private String value = "";//$NON-NLS-1$
+
+    // UI Widgets
+    private Text text;
+    private Button showPasswordCheckbox;
+
 
     /**
      * Creates a new instance of CredentialsDialog.
      * 
      * @param parentShell the parent shell
-     * @param dialogTitle the dialog title
-     * @param dialogMessage the dialog message
+     * @param title the title
+     * @param message the dialog message
      * @param initialValue the initial value
-     * @param validator the validator
      */
-    public CredentialsDialog( Shell parentShell, String dialogTitle, String dialogMessage,
String initialValue,
-        IInputValidator validator )
+    public PasswordDialog( Shell parentShell, String title, String message, String initialValue
)
+    {
+        super( parentShell );
+        this.title = title;
+        this.message = message;
+
+        if ( initialValue == null )
+        {
+            value = "";//$NON-NLS-1$
+        }
+        else
+        {
+            value = initialValue;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+
+        if ( title != null )
+        {
+            shell.setText( title );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void buttonPressed( int buttonId )
     {
-        super( parentShell, dialogTitle, dialogMessage, initialValue, validator );
+        if ( buttonId == IDialogConstants.OK_ID )
+        {
+            value = text.getText();
+        }
+        else
+        {
+            value = null;
+        }
+        super.buttonPressed( buttonId );
     }
 
 
     /**
-     * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     * {@inheritDoc}
      */
     protected Control createDialogArea( Composite parent )
     {
         Composite composite = ( Composite ) super.createDialogArea( parent );
-        super.getText().setEchoChar( '\u2022' );
+
+        if ( message != null )
+        {
+            Label label = BaseWidgetUtils.createWrappedLabel( composite, message, 1 );
+            GridData data = new GridData( GridData.GRAB_HORIZONTAL
+                | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
+                | GridData.VERTICAL_ALIGN_CENTER );
+            data.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH
);
+            label.setLayoutData( data );
+        }
+
+        // Password Text
+        text = BaseWidgetUtils.createText( composite, value, 1 );
+        text.setEchoChar( '\u2022' );
+
+        // Show Password Checkbox
+        showPasswordCheckbox = BaseWidgetUtils.createCheckbox( composite, "Show password",
1 );
+        showPasswordCheckbox.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                if ( showPasswordCheckbox.getSelection() )
+                {
+                    text.setEchoChar( '\0' );
+                }
+                else
+                {
+                    text.setEchoChar( '\u2022' );
+                }
+            }
+        } );
+
+        applyDialogFont( composite );
         return composite;
     }
+
+
+    /**
+     * Returns the string typed into this password dialog.
+     * 
+     * @return the input string
+     */
+    public String getPassword()
+    {
+        return value;
+    }
 }



Mime
View raw message