directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r526695 [2/2] - in /directory/ldapstudio/trunk/ldapstudio-valueeditors: ./ META-INF/ resources/ resources/icons/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/or...
Date Mon, 09 Apr 2007 09:53:23 GMT
Added: directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/integer/IntegerValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/integer/IntegerValueEditor.java?view=auto&rev=526695
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/integer/IntegerValueEditor.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/integer/IntegerValueEditor.java
Mon Apr  9 02:53:20 2007
@@ -0,0 +1,67 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.valueeditors.integer;
+
+
+import org.apache.directory.ldapstudio.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * Implementation of IValueEditor for integer values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class IntegerValueEditor extends AbstractDialogStringValueEditor
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation opens the IntegerDialog.
+     */
+    public boolean openDialog( Shell shell )
+    {
+        Object value = getValue();
+        if ( value != null && value instanceof String )
+        {
+            String stringValue = ( String ) value;
+            int intValue;
+            try
+            {
+                intValue = Integer.valueOf( stringValue );
+            }
+            catch ( NumberFormatException e )
+            {
+                intValue = 0;
+            }
+            IntegerDialog dialog = new IntegerDialog( shell, intValue );
+            if ( dialog.open() == IntegerDialog.OK && dialog.getInteger() != -1 )
+            {
+                setValue( Integer.toString( dialog.getInteger() ) );
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/objectclass/ObjectClassDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/objectclass/ObjectClassDialog.java?view=auto&rev=526695
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/objectclass/ObjectClassDialog.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/objectclass/ObjectClassDialog.java
Mon Apr  9 02:53:20 2007
@@ -0,0 +1,177 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.valueeditors.objectclass;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.common.widgets.ListContentProposalProvider;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorsActivator;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorsConstants;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.fieldassist.ComboContentAdapter;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.DecoratedField;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IControlCreator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * This class provides a dialog to enter or select an object class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassDialog extends Dialog
+{
+
+    /** The dialog title */
+    public static final String DIALOG_TITLE = "Object Class Editor";
+
+    /** The schema. */
+    private Schema schema;
+
+    /** The initial value. */
+    private String initialValue;
+
+    /** The object class combo field. */
+    private DecoratedField objectClassComboField;
+
+    /** The object class combo. */
+    private Combo objectClassCombo;
+
+    /** The object class content proposal adapter */
+    private ContentProposalAdapter objectClassCPA;
+
+    /** The return value. */
+    private String returnValue;
+
+
+    /**
+     * Creates a new instance of ObjectClassDialog.
+     * 
+     * @param parentShell the parent shell
+     * @param schema the schema
+     * @param initialValue the initial value
+     */
+    public ObjectClassDialog( Shell parentShell, Schema schema, String initialValue )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.initialValue = initialValue;
+        this.schema = schema;
+        this.returnValue = null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( DIALOG_TITLE );
+        shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_OCDEDITOR
) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        super.createButtonsForButtonBar( parent );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void okPressed()
+    {
+        returnValue = objectClassCombo.getText();
+        super.okPressed();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        // create composite
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH
);
+        composite.setLayoutData( gd );
+
+        // combo widget
+        String[] allOcNames = schema.getObjectClassDescriptionNames();
+        Arrays.sort( allOcNames );
+
+        final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+            FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
+        objectClassComboField = new DecoratedField( composite, SWT.NONE, new IControlCreator()
+        {
+            public Control createControl( Composite parent, int style )
+            {
+                Combo combo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 );
+                combo.setVisibleItemCount( 20 );
+                return combo;
+            }
+        } );
+        objectClassComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true
);
+        objectClassComboField.getLayoutControl().setLayoutData( new GridData( SWT.FILL, SWT.CENTER,
true, false ) );
+        objectClassCombo = ( Combo ) objectClassComboField.getControl();
+        objectClassCombo.setItems( allOcNames );
+        objectClassCombo.setText( initialValue );
+
+        // content proposal adapter
+        objectClassCPA = new ContentProposalAdapter( objectClassCombo, new ComboContentAdapter(),
+            new ListContentProposalProvider( objectClassCombo.getItems() ), null, null );
+        objectClassCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE );
+        objectClassCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE
);
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    /**
+     * Gets the object class.
+     * 
+     * @return the object class, null if canceled
+     */
+    public String getObjectClass()
+    {
+        return returnValue;
+    }
+}

Added: directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/objectclass/ObjectClassValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/objectclass/ObjectClassValueEditor.java?view=auto&rev=526695
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/objectclass/ObjectClassValueEditor.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/objectclass/ObjectClassValueEditor.java
Mon Apr  9 02:53:20 2007
@@ -0,0 +1,191 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.valueeditors.objectclass;
+
+
+import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * Implementation of IValueEditor for attribute objectClass.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassValueEditor extends AbstractDialogStringValueEditor
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation opens the ObjectClassDialog.
+     */
+    public boolean openDialog( Shell shell )
+    {
+        Object value = getValue();
+        if ( value != null && value instanceof ObjectClassValueEditorRawValueWrapper
)
+        {
+            ObjectClassValueEditorRawValueWrapper wrapper = ( ObjectClassValueEditorRawValueWrapper
) value;
+            ObjectClassDialog dialog = new ObjectClassDialog( shell, wrapper.schema, wrapper.objectClass
);
+            if ( dialog.open() == TextDialog.OK && !"".equals( dialog.getObjectClass()
) )
+            {
+                setValue( dialog.getObjectClass() );
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation appends the kind of object class,
+     * on of structural, abstract, auxiliary or obsolete. 
+     */
+    public String getDisplayValue( IValue value )
+    {
+        if ( getRawValue( value ) == null )
+        {
+            return "NULL";
+        }
+
+        String displayValue = value.getStringValue();
+
+        if ( !showRawValues() && !"".equals( displayValue ) )
+        {
+            Schema schema = value.getAttribute().getEntry().getConnection().getSchema();
+            ObjectClassDescription ocd = schema.getObjectClassDescription( displayValue );
+            if ( ocd.isStructural() )
+            {
+                displayValue = displayValue + " (structural)";
+            }
+            else if ( ocd.isAbstract() )
+            {
+                displayValue = displayValue + " (abstract)";
+            }
+            else if ( ocd.isAuxiliary() )
+            {
+                displayValue = displayValue + " (auxiliary)";
+            }
+            else if ( ocd.isObsolete() )
+            {
+                displayValue = displayValue + " (obsolete)";
+            }
+        }
+
+        return displayValue;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns null.
+     * Modification in search result editor not supported.
+     */
+    public Object getRawValue( AttributeHierarchy attributeHierarchy )
+    {
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns a ObjectClassValueEditorRawValueWrapper.
+     */
+    public Object getRawValue( IValue value )
+    {
+        if ( value == null || !value.isString() || !value.getAttribute().isObjectClassAttribute()
)
+        {
+            return null;
+        }
+        else
+        {
+            return getRawValue( value.getAttribute().getEntry().getConnection(), value.getStringValue()
);
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns a ObjectClassValueEditorRawValueWrapper.
+     */
+    public Object getRawValue( IConnection connection, Object value )
+    {
+        Schema schema = null;
+        if ( connection != null )
+        {
+            schema = connection.getSchema();
+        }
+        if ( schema == null || value == null || !( value instanceof String ) )
+        {
+            return null;
+        }
+
+        String ocValue = ( String ) value;
+        ObjectClassValueEditorRawValueWrapper wrapper = new ObjectClassValueEditorRawValueWrapper(
schema, ocValue );
+        return wrapper;
+    }
+
+    /**
+     * The ObjectClassValueEditorRawValueWrapper is used to pass contextual 
+     * information to the opened ObjectClassDialog.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    private class ObjectClassValueEditorRawValueWrapper
+    {
+        /** 
+         * The schema, used in ObjectClassDialog to build the list
+         * with possible object classes.
+         */
+        private Schema schema;
+
+        /** The object class, used as initial value in ObjectClassDialog. */
+        private String objectClass;
+
+
+        /**
+         * Creates a new instance of ObjectClassValueEditorRawValueWrapper.
+         *
+         * @param schema the schema
+         * @param objectClass the object class
+         */
+        private ObjectClassValueEditorRawValueWrapper( Schema schema, String objectClass
)
+        {
+            super();
+            this.schema = schema;
+            this.objectClass = objectClass;
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/password/PasswordDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/password/PasswordDialog.java?view=auto&rev=526695
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/password/PasswordDialog.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/password/PasswordDialog.java
Mon Apr  9 02:53:20 2007
@@ -0,0 +1,483 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.valueeditors.password;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.browser.common.jobs.RunnableContextJobAdapter;
+import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.core.jobs.CheckBindJob;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.Password;
+import org.apache.directory.ldapstudio.browser.core.utils.Utils;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorsActivator;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorsConstants;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+
+
+public class PasswordDialog extends Dialog
+{
+
+    public static final String DIALOG_TITLE = "Password Editor";
+
+    public static final String[] HASH_METHODS =
+        { Password.HASH_METHOD_SHA, Password.HASH_METHOD_SSHA, Password.HASH_METHOD_MD5,
Password.HASH_METHOD_SMD5,
+            Password.HASH_METHOD_CRYPT, Password.HASH_METHOD_NO };
+
+    public static final int CURRENT_TAB = 0;
+
+    public static final int NEW_TAB = 1;
+
+    public static final String SELECTED_TAB_DIALOGSETTINGS_KEY = PasswordDialog.class.getName()
+ ".tab";
+
+    public static final String SELECTED_HASH_METHOD_DIALOGSETTINGS_KEY = PasswordDialog.class.getName()
+ ".hashMethod";
+
+    private TabFolder tabFolder;
+
+    private TabItem currentTab;
+
+    private TabItem newTab;
+
+    private IEntry entry;
+
+    private Password currentPassword;
+
+    private Composite currentPasswordContainer;
+
+    private Text currentPasswordText;
+
+    private Text currentPasswordHashMethodText;
+
+    private Text currentPasswordValueHexText;
+
+    private Text currentPasswordSaltHexText;
+
+    private Text testPasswordText;
+
+    private Button verifyPasswordButton;
+
+    private Button bindPasswordButton;
+
+    private Password newPassword;
+
+    private Composite newPasswordContainer;
+
+    private Text newPasswordText;
+
+    private Combo newPasswordHashMethodCombo;
+
+    private Text newPasswordPreviewText;
+
+    private Text newPasswordPreviewValueHexText;
+
+    private Text newPasswordPreviewSaltHexText;
+
+    private Button newSaltButton;
+
+    private byte[] returnPassword;
+
+    private Button okButton;
+
+
+    public PasswordDialog( Shell parentShell, byte[] currentPassword, IEntry entry )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+
+        try
+        {
+            this.currentPassword = currentPassword != null ? new Password( currentPassword
) : null;
+        }
+        catch ( IllegalArgumentException e )
+        {
+        }
+        this.entry = entry;
+
+        this.returnPassword = null;
+    }
+
+
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( DIALOG_TITLE );
+        shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_PASSWORDEDITOR
) );
+    }
+
+
+    protected void okPressed()
+    {
+        // create password
+        if ( newPassword != null )
+        {
+            this.returnPassword = this.newPassword.toBytes();
+        }
+        else
+        {
+            this.returnPassword = null;
+        }
+
+        // save selected hash method to dialog settings, selected tab will be
+        // saved int close()
+        ValueEditorsActivator.getDefault().getDialogSettings().put( SELECTED_HASH_METHOD_DIALOGSETTINGS_KEY,
+            this.newPasswordHashMethodCombo.getText() );
+
+        super.okPressed();
+    }
+
+
+    public boolean close()
+    {
+        // save selected tab to dialog settings
+        ValueEditorsActivator.getDefault().getDialogSettings().put( SELECTED_TAB_DIALOGSETTINGS_KEY,
+            this.tabFolder.getSelectionIndex() );
+
+        return super.close();
+    }
+
+
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
false );
+
+        // load dialog settings
+        try
+        {
+            int tabIndex = ValueEditorsActivator.getDefault().getDialogSettings().getInt(
SELECTED_TAB_DIALOGSETTINGS_KEY );
+            if ( this.currentPassword == null || this.currentPassword.toBytes().length ==
0 )
+            {
+                tabIndex = NEW_TAB;
+            }
+            this.tabFolder.setSelection( tabIndex );
+        }
+        catch ( Exception e )
+        {
+        }
+        try
+        {
+            String hashMethod = ValueEditorsActivator.getDefault().getDialogSettings()
+                .get( SELECTED_HASH_METHOD_DIALOGSETTINGS_KEY );
+            if ( Arrays.asList( HASH_METHODS ).contains( hashMethod ) )
+            {
+                this.newPasswordHashMethodCombo.setText( hashMethod );
+            }
+        }
+        catch ( Exception e )
+        {
+        }
+
+        // update on load
+        updateTabFolder();
+    }
+
+
+    protected Control createDialogArea( Composite parent )
+    {
+
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH
) * 3 / 2;
+        gd.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH
) / 2;
+        composite.setLayoutData( gd );
+
+        this.tabFolder = new TabFolder( composite, SWT.TOP );
+        GridLayout mainLayout = new GridLayout();
+        mainLayout.marginWidth = 0;
+        mainLayout.marginHeight = 0;
+        this.tabFolder.setLayout( mainLayout );
+        this.tabFolder.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+        this.tabFolder.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                updateTabFolder();
+            }
+        } );
+
+        // current password
+        if ( this.currentPassword != null && this.currentPassword.toBytes().length
> 0 )
+        {
+            currentPasswordContainer = new Composite( this.tabFolder, SWT.NONE );
+            GridLayout currentLayout = new GridLayout( 2, false );
+            currentLayout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN
);
+            currentLayout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN
);
+            currentLayout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING
);
+            currentLayout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING
);
+            currentPasswordContainer.setLayout( currentLayout );
+
+            BaseWidgetUtils.createLabel( currentPasswordContainer, "Current Password:", 1
);
+            currentPasswordText = BaseWidgetUtils.createReadonlyText( currentPasswordContainer,
"", 1 );
+
+            /* Label dummy = */new Label( currentPasswordContainer, SWT.NONE );
+            Composite currentPasswordDetailContainer = BaseWidgetUtils.createColumnContainer(
currentPasswordContainer,
+                2, 1 );
+            BaseWidgetUtils.createLabel( currentPasswordDetailContainer, "Hash Method:",
1 );
+            currentPasswordHashMethodText = BaseWidgetUtils.createLabeledText( currentPasswordDetailContainer,
"", 1 );
+            BaseWidgetUtils.createLabel( currentPasswordDetailContainer, "Password (Hex):",
1 );
+            currentPasswordValueHexText = BaseWidgetUtils.createLabeledText( currentPasswordDetailContainer,
"", 1 );
+            BaseWidgetUtils.createLabel( currentPasswordDetailContainer, "Salt (Hex):", 1
);
+            currentPasswordSaltHexText = BaseWidgetUtils.createLabeledText( currentPasswordDetailContainer,
"", 1 );
+
+            BaseWidgetUtils.createLabel( currentPasswordContainer, "Verify Password:", 1
);
+            testPasswordText = BaseWidgetUtils.createPasswordText( currentPasswordContainer,
"", 1 );
+            testPasswordText.addModifyListener( new ModifyListener()
+            {
+                public void modifyText( ModifyEvent e )
+                {
+                    updateCurrentPasswordGroup();
+                }
+            } );
+
+            /* Label dummyLabel = */new Label( currentPasswordContainer, SWT.NONE );
+            Composite verifyPasswordButtonContainer = BaseWidgetUtils.createColumnContainer(
currentPasswordContainer,
+                2, 1 );
+            verifyPasswordButton = BaseWidgetUtils.createButton( verifyPasswordButtonContainer,
"Verify", 1 );
+            verifyPasswordButton.setEnabled( false );
+            verifyPasswordButton.addSelectionListener( new SelectionAdapter()
+            {
+                public void widgetSelected( SelectionEvent event )
+                {
+                    verifyCurrentPassword();
+                }
+            } );
+            bindPasswordButton = BaseWidgetUtils.createButton( verifyPasswordButtonContainer,
"Bind", 1 );
+            bindPasswordButton.setEnabled( false );
+            bindPasswordButton.addSelectionListener( new SelectionAdapter()
+            {
+                public void widgetSelected( SelectionEvent event )
+                {
+                    bindCurrentPassword();
+                }
+            } );
+
+            this.currentTab = new TabItem( this.tabFolder, SWT.NONE );
+            this.currentTab.setText( "Current Password" );
+            this.currentTab.setControl( currentPasswordContainer );
+        }
+
+        // new password
+        newPasswordContainer = new Composite( this.tabFolder, SWT.NONE );
+        GridLayout newLayout = new GridLayout( 2, false );
+        newLayout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN
);
+        newLayout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN
);
+        newLayout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING
);
+        newLayout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING
);
+        newPasswordContainer.setLayout( newLayout );
+
+        BaseWidgetUtils.createLabel( newPasswordContainer, "Enter New Password:", 1 );
+        newPasswordText = BaseWidgetUtils.createPasswordText( newPasswordContainer, "", 1
);
+        newPasswordText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                updateNewPasswordGroup();
+            }
+        } );
+
+        BaseWidgetUtils.createLabel( newPasswordContainer, "Select Hash Method:", 1 );
+        newPasswordHashMethodCombo = BaseWidgetUtils.createReadonlyCombo( newPasswordContainer,
HASH_METHODS, 0, 1 );
+        newPasswordHashMethodCombo.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent event )
+            {
+                updateNewPasswordGroup();
+            }
+        } );
+
+        BaseWidgetUtils.createLabel( newPasswordContainer, "Password Preview:", 1 );
+        newPasswordPreviewText = BaseWidgetUtils.createReadonlyText( newPasswordContainer,
"", 1 );
+
+        newSaltButton = BaseWidgetUtils.createButton( newPasswordContainer, "New Salt", 1
);
+        newSaltButton.setEnabled( false );
+        newSaltButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent event )
+            {
+                updateNewPasswordGroup();
+            }
+        } );
+        Composite newPasswordPreviewDetailContainer = BaseWidgetUtils
+            .createColumnContainer( newPasswordContainer, 2, 1 );
+        BaseWidgetUtils.createLabel( newPasswordPreviewDetailContainer, "Password (Hex):",
1 );
+        newPasswordPreviewValueHexText = BaseWidgetUtils.createLabeledText( newPasswordPreviewDetailContainer,
":", 1 );
+        BaseWidgetUtils.createLabel( newPasswordPreviewDetailContainer, "Salt (Hex):", 1
);
+        newPasswordPreviewSaltHexText = BaseWidgetUtils.createLabeledText( newPasswordPreviewDetailContainer,
"", 1 );
+
+        this.newTab = new TabItem( this.tabFolder, SWT.NONE );
+        this.newTab.setText( "New Password" );
+        this.newTab.setControl( newPasswordContainer );
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    private void updateCurrentPasswordGroup()
+    {
+        if ( this.currentPassword != null )
+        {
+            this.currentPasswordHashMethodText.setText( Utils.getNonNullString( this.currentPassword.getHashMethod()
) );
+            this.currentPasswordValueHexText.setText( Utils.getNonNullString( this.currentPassword
+                .getHashedPasswordAsHexString() ) );
+            this.currentPasswordSaltHexText
+                .setText( Utils.getNonNullString( this.currentPassword.getSaltAsHexString()
) );
+            this.currentPasswordText.setText( this.currentPassword.toString() );
+        }
+
+        this.testPasswordText.setEnabled( this.currentPassword != null
+            && this.currentPassword.getHashedPassword() != null && this.currentPassword.toBytes().length
> 0 );
+        this.verifyPasswordButton.setEnabled( this.testPasswordText.isEnabled()
+            && !"".equals( this.testPasswordText.getText() ) );
+        this.bindPasswordButton.setEnabled( this.testPasswordText.isEnabled()
+            && !"".equals( this.testPasswordText.getText() ) && this.entry
!= null );
+
+        if ( this.verifyPasswordButton.isEnabled() )
+            getShell().setDefaultButton( this.verifyPasswordButton );
+        else
+            getShell().setDefaultButton( this.okButton );
+        // this.currentPasswordText.getParent().layout();
+    }
+
+
+    private void verifyCurrentPassword()
+    {
+        String testPassword = this.testPasswordText.getText();
+        if ( this.currentPassword != null )
+        {
+            if ( this.currentPassword.verify( testPassword ) )
+            {
+                MessageDialog dialog = new MessageDialog( getShell(), "Password Verification",
getShell().getImage(),
+                    "Password verified sucessfully", MessageDialog.INFORMATION, new String[]
+                        { IDialogConstants.OK_LABEL }, 0 );
+                dialog.open();
+            }
+            else
+            {
+                MessageDialog dialog = new MessageDialog( getShell(), "Password Verification",
getShell().getImage(),
+                    "Password verification failed", MessageDialog.ERROR, new String[]
+                        { IDialogConstants.OK_LABEL }, 0 );
+                dialog.open();
+            }
+        }
+    }
+
+
+    private void bindCurrentPassword()
+    {
+
+        if ( !"".equals( this.testPasswordText.getText() ) && this.entry != null
)
+        {
+
+            IConnection connection = ( IConnection ) this.entry.getConnection().clone();;
+            connection.setName( null );
+            connection.setBindPrincipal( this.entry.getDn().toString() );
+            connection.setBindPassword( this.testPasswordText.getText() );
+            connection.setAuthMethod( IConnection.AUTH_SIMPLE );
+
+            CheckBindJob job = new CheckBindJob( connection );
+            RunnableContextJobAdapter.execute( job );
+            if ( job.getExternalResult().isOK() )
+            {
+                MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check
Authentication",
+                    "The authentication was successful." );
+            }
+
+        }
+    }
+
+
+    private void updateNewPasswordGroup()
+    {
+        this.newPassword = new Password( this.newPasswordHashMethodCombo.getText(), this.newPasswordText.getText()
);
+        if ( !"".equals( this.newPasswordText.getText() ) || this.newPassword.getHashMethod()
== null )
+        {
+            newPasswordPreviewValueHexText.setText( Utils.getNonNullString( this.newPassword
+                .getHashedPasswordAsHexString() ) );
+            newPasswordPreviewSaltHexText.setText( Utils.getNonNullString( this.newPassword.getSaltAsHexString()
) );
+            newPasswordPreviewText.setText( this.newPassword.toString() );
+            newSaltButton.setEnabled( this.newPassword.getSalt() != null );
+            this.okButton.setEnabled( true );
+            getShell().setDefaultButton( this.okButton );
+        }
+        else
+        {
+            this.newPassword = null;
+            newPasswordPreviewValueHexText.setText( Utils.getNonNullString( null ) );
+            newPasswordPreviewSaltHexText.setText( Utils.getNonNullString( null ) );
+            newPasswordPreviewText.setText( Utils.getNonNullString( null ) );
+            newSaltButton.setEnabled( false );
+            this.okButton.setEnabled( false );
+        }
+    }
+
+
+    private void updateTabFolder()
+    {
+        if ( testPasswordText != null && newPasswordText != null )
+        {
+            if ( tabFolder.getSelectionIndex() == CURRENT_TAB )
+            {
+                testPasswordText.setFocus();
+            }
+            else if ( tabFolder.getSelectionIndex() == NEW_TAB )
+            {
+                newPasswordText.setFocus();
+            }
+            updateCurrentPasswordGroup();
+            updateNewPasswordGroup();
+        }
+    }
+
+
+    /**
+     * 
+     * 
+     * @return Returns the password, either encypted by the selected
+     *         algorithm or as plain text.
+     */
+    public byte[] getNewPassword()
+    {
+        return this.returnPassword;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/password/PasswordValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/password/PasswordValueEditor.java?view=auto&rev=526695
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/password/PasswordValueEditor.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/password/PasswordValueEditor.java
Mon Apr  9 02:53:20 2007
@@ -0,0 +1,181 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.valueeditors.password;
+
+
+import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.valueeditors.AbstractDialogBinaryValueEditor;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * Implementation of IValueEditor for attribute userPassword.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PasswordValueEditor extends AbstractDialogBinaryValueEditor
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation opens the PasswordDialog.
+     */
+    protected boolean openDialog( Shell shell )
+    {
+        Object value = getValue();
+        if ( value != null && value instanceof PasswordValueEditorRawValueWrapper
)
+        {
+            PasswordValueEditorRawValueWrapper wrapper = ( PasswordValueEditorRawValueWrapper
) value;
+            if ( wrapper.password != null && wrapper.password instanceof byte[] )
+            {
+                byte[] pw = ( byte[] ) wrapper.password;
+                PasswordDialog dialog = new PasswordDialog( shell, pw, wrapper.entry );
+                if ( dialog.open() == TextDialog.OK )
+                {
+                    setValue( dialog.getNewPassword() );
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation returns information about the 
+     * used hash algorithm. The value stored in directory
+     * is only display when the showRawValues option is 
+     * active.
+     */
+    public String getDisplayValue( IValue value )
+    {
+        if ( showRawValues() )
+        {
+            return getPrintableString( value );
+        }
+        else
+        {
+            if ( value == null )
+            {
+                return "NULL";
+            }
+
+            String password = value.getStringValue();;
+            if ( password == null )
+            {
+                return "NULL";
+            }
+            else
+            {
+                String text;
+                if ( "".equals( password ) )
+                {
+                    text = "Empty password";
+                }
+                else if ( password.indexOf( '{' ) == 0 && password.indexOf( '}' )
> 0 )
+                {
+                    String encryptionMethod = password.substring( password.indexOf( '{' )
+ 1, password.indexOf( '}' ) );
+                    text = encryptionMethod + " encrypted password";
+                }
+                else
+                {
+                    text = "Plain text password";
+                }
+                return text;
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns a PasswordValueEditorRawValueWrapper with empty 
+     * password.
+     */
+    protected Object getEmptyRawValue( IAttribute attribute )
+    {
+        return new PasswordValueEditorRawValueWrapper( new byte[0], attribute.getEntry()
);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns a PasswordValueEditorRawValueWrapper.
+     */
+    public Object getRawValue( IValue value )
+    {
+        Object password = super.getRawValue( value );
+        return new PasswordValueEditorRawValueWrapper( password, value.getAttribute().getEntry()
);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns a PasswordValueEditorRawValueWrapper with 
+     * null entry.
+     */
+    public Object getRawValue( IConnection connection, Object value )
+    {
+        Object password = super.getRawValue( connection, value );
+        return new PasswordValueEditorRawValueWrapper( password, null );
+    }
+
+    /**
+     * The PasswordValueEditorRawValueWrapper is used to pass contextual 
+     * information to the opened PasswordDialog.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    private class PasswordValueEditorRawValueWrapper
+    {
+        /** The password, used as initial value in PasswordDialog */
+        private Object password;
+
+        /** The entry, used for the bind operation in PasswordDialog */
+        private IEntry entry;
+
+
+        /**
+         * Creates a new instance of PasswordValueEditorRawValueWrapper.
+         *
+         * @param password the password
+         * @param entry the entry
+         */
+        private PasswordValueEditorRawValueWrapper( Object password, IEntry entry )
+        {
+            this.password = password;
+            this.entry = entry;
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java?view=auto&rev=526695
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-valueeditors/src/main/java/org/apache/directory/ldapstudio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java
Mon Apr  9 02:53:20 2007
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.valueeditors.time;
+
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.valueeditors.AbstractInPlaceStringValueEditor;
+
+
+/**
+ * Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.24 
+ * (Generalized Time). 
+ * 
+ * Currently only the getDisplayXXX() methods are implemented.
+ * For modification the raw string must be edited.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class InPlaceGeneralizedTimeValueEditor extends AbstractInPlaceStringValueEditor
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns the proper formatted date and time, Timezone is 
+     * convertet to the default locale. 
+     * 
+     * Can handle 
+     * <ul>
+     * <li>default LDAP format: yyyyMMddHHmmssZ
+     * <li>Active Directory format: yyyyMMddHHmmss.SSSZ
+     * </ul>  
+     */
+    public String getDisplayValue( IValue value )
+    {
+        String displayValue = super.getDisplayValue( value );
+
+        if ( !showRawValues() )
+        {
+            DateFormat ldapFormat = new SimpleDateFormat( "yyyyMMddHHmmssZ" );
+            DateFormat activeDirectoryFormat = new SimpleDateFormat( "yyyyMMddHHmmss'.'SSSZ"
);
+            DateFormat targetFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM,
DateFormat.LONG );
+
+            String s = displayValue;
+            if ( s.matches( "[\\.0-9]+Z" ) )
+            {
+                s = s.replaceAll( "Z", "GMT" );
+            }
+
+            try
+            {
+                Date date = ldapFormat.parse( s );
+                displayValue = targetFormat.format( date ) + " (" + displayValue + ")";
+            }
+            catch ( ParseException e1 )
+            {
+                try
+                {
+                    Date date = activeDirectoryFormat.parse( s );
+                    displayValue = targetFormat.format( date ) + " (" + displayValue + ")";
+                }
+                catch ( ParseException e2 )
+                {
+                }
+            }
+        }
+
+        return displayValue;
+    }
+
+}



Mime
View raw message