You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/11/05 16:05:02 UTC
svn commit: r592029 [2/2] - in
/directory/sandbox/felixk/studio-valueeditors: ./ META-INF/ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/directory/
src/main/java/org/apache/directory/studio/ src/mai...
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageValueEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerDialog.java?rev=592029&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerDialog.java (added)
+++ directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerDialog.java Mon Nov 5 07:04:58 2007
@@ -0,0 +1,139 @@
+/*
+ * 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.studio.valueeditors.integer;
+
+
+import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
+import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Spinner;
+
+
+/**
+ * This class provides a dialog to enter or choose an integer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class IntegerDialog extends Dialog
+{
+
+ /** The dialog title */
+ public static final String DIALOG_TITLE = "Integer Editor";
+
+ /** The initial value. */
+ private int initialValue;
+
+ /** The return value. */
+ private int returnValue;
+
+ /** The spinner to select an integer */
+ private Spinner spinner = null;
+
+
+ /**
+ * Creates a new instance of IntegerDialog.
+ *
+ * @param parentShell the parent shell
+ * @param initialValue the initial value
+ */
+ public IntegerDialog( Shell parentShell, int initialValue )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ this.initialValue = initialValue;
+ this.returnValue = -1;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( DIALOG_TITLE );
+ shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_INTEGEREDITOR ) );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+ createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void okPressed()
+ {
+ returnValue = spinner.getSelection();
+ super.okPressed();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Control createDialogArea( Composite parent )
+ {
+ // create composite
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ composite.setLayout( new GridLayout() );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ composite.setLayoutData( gd );
+
+ spinner = new Spinner( composite, SWT.BORDER );
+ spinner.setMinimum( 0 );
+ spinner.setMaximum( Integer.MAX_VALUE );
+ spinner.setDigits( 0 );
+ spinner.setIncrement( 1 );
+ spinner.setPageIncrement( 100 );
+ spinner.setSelection( initialValue );
+ spinner.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ /**
+ * Gets the integer.
+ *
+ * @return the integer
+ */
+ public int getInteger()
+ {
+ return returnValue;
+ }
+}
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerValueEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerValueEditor.java?rev=592029&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerValueEditor.java (added)
+++ directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerValueEditor.java Mon Nov 5 07:04:58 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.studio.valueeditors.integer;
+
+
+import org.apache.directory.studio.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;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerValueEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassDialog.java?rev=592029&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassDialog.java (added)
+++ directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassDialog.java Mon Nov 5 07:04:58 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.studio.valueeditors.objectclass;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.ListContentProposalProvider;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
+import org.apache.directory.studio.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;
+ }
+}
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java?rev=592029&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java (added)
+++ directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java Mon Nov 5 07:04:58 2007
@@ -0,0 +1,186 @@
+/*
+ * 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.studio.valueeditors.objectclass;
+
+
+import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog;
+import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.ObjectClassDescription;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.studio.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().getBrowserConnection().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().getBrowserConnection(), value.getStringValue() );
+ }
+ }
+
+
+ private Object getRawValue( IBrowserConnection 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;
+ }
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordDialog.java?rev=592029&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordDialog.java (added)
+++ directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordDialog.java Mon Nov 5 07:04:58 2007
@@ -0,0 +1,584 @@
+/*
+ * 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.studio.valueeditors.password;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
+import org.apache.directory.studio.connection.core.jobs.CheckBindJob;
+import org.apache.directory.studio.connection.ui.widgets.RunnableContextJobAdapter;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.Password;
+import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
+import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
+import org.apache.directory.studio.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;
+
+
+/**
+ * The PasswordDialog is used from the password value editor to view the current password
+ * and to enter a new password.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PasswordDialog extends Dialog
+{
+
+ /** The supported hash methods */
+ private 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 };
+
+ private static final int CURRENT_TAB = 0;
+
+ private static final int NEW_TAB = 1;
+
+ private static final String SELECTED_TAB_DIALOGSETTINGS_KEY = PasswordDialog.class.getName() + ".tab";
+
+ private 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 Button showCurrentPasswordDetailsButton;
+
+ 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 Button showNewPasswordDetailsButton;
+
+ private byte[] returnPassword;
+
+ private Button okButton;
+
+
+ /**
+ * Creates a new instance of PasswordDialog.
+ *
+ * @param parentShell the parent shell
+ * @param currentPassword the current password, null if none
+ * @param entry the entry used to bind
+ */
+ 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;
+ }
+
+
+ /**
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( "Password Editor" );
+ shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_PASSWORDEDITOR ) );
+ }
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ protected void okPressed()
+ {
+ // create password
+ if ( newPassword != null )
+ {
+ returnPassword = newPassword.toBytes();
+ }
+ else
+ {
+ 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,
+ newPasswordHashMethodCombo.getText() );
+
+ super.okPressed();
+ }
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#close()
+ */
+ public boolean close()
+ {
+ // save selected tab to dialog settings
+ ValueEditorsActivator.getDefault().getDialogSettings().put( SELECTED_TAB_DIALOGSETTINGS_KEY,
+ tabFolder.getSelectionIndex() );
+
+ return super.close();
+ }
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ 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 ( currentPassword == null || currentPassword.toBytes().length == 0 )
+ {
+ tabIndex = NEW_TAB;
+ }
+ 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 ) )
+ {
+ newPasswordHashMethodCombo.setText( hashMethod );
+ }
+ }
+ catch ( Exception e )
+ {
+ }
+
+ // update on load
+ updateTabFolder();
+ }
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ 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 );
+
+ tabFolder = new TabFolder( composite, SWT.TOP );
+ GridLayout mainLayout = new GridLayout();
+ mainLayout.marginWidth = 0;
+ mainLayout.marginHeight = 0;
+ tabFolder.setLayout( mainLayout );
+ tabFolder.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ tabFolder.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ updateTabFolder();
+ }
+ } );
+
+ // current password
+ if ( currentPassword != null && currentPassword.toBytes().length > 0 )
+ {
+ currentPasswordContainer = new Composite( 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 );
+
+ 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 );
+ showCurrentPasswordDetailsButton = BaseWidgetUtils.createCheckbox( currentPasswordDetailContainer,
+ "Show current password details", 1 );
+ showCurrentPasswordDetailsButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ updateCurrentPasswordGroup();
+ }
+ } );
+
+ BaseWidgetUtils.createLabel( currentPasswordContainer, "Verify Password:", 1 );
+ testPasswordText = BaseWidgetUtils.createPasswordText( currentPasswordContainer, "", 1 );
+ testPasswordText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ updateCurrentPasswordGroup();
+ }
+ } );
+
+ 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();
+ }
+ } );
+
+ currentTab = new TabItem( tabFolder, SWT.NONE );
+ currentTab.setText( "Current Password" );
+ currentTab.setControl( currentPasswordContainer );
+ }
+
+ // new password
+ newPasswordContainer = new Composite( 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 );
+ showNewPasswordDetailsButton = BaseWidgetUtils.createCheckbox( newPasswordPreviewDetailContainer,
+ "Show new password details", 1 );
+ showNewPasswordDetailsButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ updateNewPasswordGroup();
+ }
+ } );
+
+ newTab = new TabItem( tabFolder, SWT.NONE );
+ newTab.setText( "New Password" );
+ newTab.setControl( newPasswordContainer );
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ /**
+ * Updates the current password tab.
+ */
+ private void updateCurrentPasswordGroup()
+ {
+ // set current password to the UI widgets
+ if ( currentPassword != null )
+ {
+ currentPasswordHashMethodText.setText( Utils.getNonNullString( currentPassword.getHashMethod() ) );
+ currentPasswordValueHexText.setText( Utils
+ .getNonNullString( currentPassword.getHashedPasswordAsHexString() ) );
+ currentPasswordSaltHexText.setText( Utils.getNonNullString( currentPassword.getSaltAsHexString() ) );
+ currentPasswordText.setText( currentPassword.toString() );
+ }
+
+ // show password details?
+ if ( showCurrentPasswordDetailsButton.getSelection() )
+ {
+ currentPasswordText.setEchoChar( '\0' );
+ currentPasswordValueHexText.setEchoChar( '\0' );
+ currentPasswordSaltHexText.setEchoChar( '\0' );
+ }
+ else
+ {
+ currentPasswordText.setEchoChar( '\u2022' );
+ currentPasswordValueHexText.setEchoChar( '\u2022' );
+ currentPasswordSaltHexText.setEchoChar( currentPasswordSaltHexText.getText().equals(
+ Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
+ }
+
+ // enable/disable test field and buttons
+ testPasswordText.setEnabled( currentPassword != null && currentPassword.getHashedPassword() != null
+ && currentPassword.toBytes().length > 0 );
+ verifyPasswordButton.setEnabled( testPasswordText.isEnabled() && !"".equals( testPasswordText.getText() ) );
+ bindPasswordButton.setEnabled( testPasswordText.isEnabled() && !"".equals( testPasswordText.getText() )
+ && entry != null );
+
+ // default dialog button
+ if ( verifyPasswordButton.isEnabled() )
+ {
+ getShell().setDefaultButton( verifyPasswordButton );
+ }
+ else
+ {
+ getShell().setDefaultButton( okButton );
+ }
+ }
+
+
+ /**
+ * Verifies the current password.
+ */
+ private void verifyCurrentPassword()
+ {
+ String testPassword = testPasswordText.getText();
+ if ( currentPassword != null )
+ {
+ if ( 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();
+ }
+ }
+ }
+
+
+ /**
+ * Binds to the directory using the test password.
+ */
+ private void bindCurrentPassword()
+ {
+ if ( !"".equals( testPasswordText.getText() ) && entry != null )
+ {
+ Connection connection = ( Connection ) entry.getBrowserConnection().getConnection().clone();
+ connection.setName( null );
+ connection.setBindPrincipal( entry.getDn().getUpName() );
+ connection.setBindPassword( testPasswordText.getText() );
+ connection.setAuthMethod( AuthenticationMethod.SIMPLE );
+
+ CheckBindJob job = new CheckBindJob( connection );
+ RunnableContextJobAdapter.execute( job );
+ if ( job.getExternalResult().isOK() )
+ {
+ MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check Authentication",
+ "The authentication was successful." );
+ }
+ }
+ }
+
+
+ /**
+ * Updates the new password tab.
+ */
+ private void updateNewPasswordGroup()
+ {
+ // set new password to the UI widgets
+ newPassword = new Password( newPasswordHashMethodCombo.getText(), newPasswordText.getText() );
+ if ( !"".equals( newPasswordText.getText() ) || newPassword.getHashMethod() == null )
+ {
+ newPasswordPreviewValueHexText
+ .setText( Utils.getNonNullString( newPassword.getHashedPasswordAsHexString() ) );
+ newPasswordPreviewSaltHexText.setText( Utils.getNonNullString( newPassword.getSaltAsHexString() ) );
+ newPasswordPreviewText.setText( newPassword.toString() );
+ newSaltButton.setEnabled( newPassword.getSalt() != null );
+ okButton.setEnabled( true );
+ getShell().setDefaultButton( okButton );
+ }
+ else
+ {
+ newPassword = null;
+ newPasswordPreviewValueHexText.setText( Utils.getNonNullString( null ) );
+ newPasswordPreviewSaltHexText.setText( Utils.getNonNullString( null ) );
+ newPasswordPreviewText.setText( Utils.getNonNullString( null ) );
+ newSaltButton.setEnabled( false );
+ okButton.setEnabled( false );
+ }
+
+ // show password details?
+ if ( showNewPasswordDetailsButton.getSelection() )
+ {
+ newPasswordPreviewText.setEchoChar( '\0' );
+ newPasswordPreviewValueHexText.setEchoChar( '\0' );
+ newPasswordPreviewSaltHexText.setEchoChar( '\0' );
+ }
+ else
+ {
+ newPasswordPreviewText.setEchoChar( newPasswordPreviewText.getText()
+ .equals( Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
+ newPasswordPreviewValueHexText.setEchoChar( newPasswordPreviewValueHexText.getText().equals(
+ Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
+ newPasswordPreviewSaltHexText.setEchoChar( newPasswordPreviewSaltHexText.getText().equals(
+ Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
+ }
+ }
+
+
+ /**
+ * Updates the tab folder and the tabs.
+ */
+ 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();
+ }
+ }
+
+
+ /**
+ * Gets the new password.
+ *
+ * @return the password, either encypted by the selected
+ * algorithm or as plain text.
+ */
+ public byte[] getNewPassword()
+ {
+ return returnPassword;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordValueEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordValueEditor.java?rev=592029&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordValueEditor.java (added)
+++ directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordValueEditor.java Mon Nov 5 07:04:58 2007
@@ -0,0 +1,168 @@
+/*
+ * 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.studio.valueeditors.password;
+
+
+import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.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() );
+ }
+
+
+ /**
+ * 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;
+ }
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordValueEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java?rev=592029&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java (added)
+++ directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java Mon Nov 5 07:04:58 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.studio.valueeditors.time;
+
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.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;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/addresseditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/addresseditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/addresseditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/administrativeroleeditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/administrativeroleeditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/administrativeroleeditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/dneditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/dneditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/dneditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/generalizedtimeeditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/generalizedtimeeditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/generalizedtimeeditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/imageeditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/imageeditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/imageeditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/inplace_oceditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/inplace_oceditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/inplace_oceditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/integereditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/integereditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/integereditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/objectclasseditor.png
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/objectclasseditor.png?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/objectclasseditor.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/passwordeditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/passwordeditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/passwordeditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/texteditor.gif
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/texteditor.gif?rev=592029&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/felixk/studio-valueeditors/src/main/resources/resources/icons/texteditor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream