directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r488368 [9/23] - in /directory/sandbox/pamarcelot/ldapstudio: ldapstudio-browser-ui/ ldapstudio-browser-ui/META-INF/ ldapstudio-browser-ui/about_files/ ldapstudio-browser-ui/icons/ ldapstudio-browser-ui/icons/ovr16/ ldapstudio-browser-ui/sr...
Date Mon, 18 Dec 2006 17:53:22 GMT
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/PasswordDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/PasswordDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/PasswordDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/PasswordDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,485 @@
+/*
+ *  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.browser.ui.dialogs;
+
+
+import java.util.Arrays;
+
+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.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.jobs.RunnableContextJobAdapter;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+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( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.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()
+        BrowserUIPlugin.getDefault().getDialogSettings().put( SELECTED_HASH_METHOD_DIALOGSETTINGS_KEY,
+            this.newPasswordHashMethodCombo.getText() );
+
+        super.okPressed();
+    }
+
+
+    public boolean close()
+    {
+        // save selected tab to dialog settings
+        BrowserUIPlugin.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 = BrowserUIPlugin.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 = BrowserUIPlugin.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( BaseWidgetUtils.getNonNullString( this.currentPassword
+                .getHashMethod() ) );
+            this.currentPasswordValueHexText.setText( BaseWidgetUtils.getNonNullString( this.currentPassword
+                .getHashedPasswordAsHexString() ) );
+            this.currentPasswordSaltHexText.setText( BaseWidgetUtils.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( BaseWidgetUtils.getNonNullString( this.newPassword
+                .getHashedPasswordAsHexString() ) );
+            newPasswordPreviewSaltHexText.setText( BaseWidgetUtils.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( BaseWidgetUtils.getNonNullString( null ) );
+            newPasswordPreviewSaltHexText.setText( BaseWidgetUtils.getNonNullString( null ) );
+            newPasswordPreviewText.setText( BaseWidgetUtils.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/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/RenameEntryDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/RenameEntryDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/RenameEntryDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/RenameEntryDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,170 @@
+/*
+ *  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.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.RDN;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.DnBuilderWidget;
+import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyEvent;
+import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyListener;
+
+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.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class RenameEntryDialog extends Dialog implements WidgetModifyListener
+{
+
+    public static final String DELETE_OLD_RDN_DIALOGSETTING_KEY = RenameEntryDialog.class.getName() + ".deleteOldRdn";
+
+    public static final String DIALOG_TITLE = "Rename Entry";
+
+    private IEntry entry;
+
+    private DnBuilderWidget dnBuilderWidget;
+
+    private Button deleteOldRdnButton;
+
+    private Button simulateRenameButton;
+
+    private Button okButton;
+
+    private RDN rdn;
+
+    private boolean deleteOldRdn;
+
+    private boolean simulateRename;
+
+
+    public RenameEntryDialog( Shell parentShell, IEntry entry )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.entry = entry;
+        this.rdn = null;
+
+        if ( BrowserUIPlugin.getDefault().getDialogSettings().get( DELETE_OLD_RDN_DIALOGSETTING_KEY ) == null )
+            BrowserUIPlugin.getDefault().getDialogSettings().put( DELETE_OLD_RDN_DIALOGSETTING_KEY, true );
+        this.deleteOldRdn = BrowserUIPlugin.getDefault().getDialogSettings().getBoolean(
+            DELETE_OLD_RDN_DIALOGSETTING_KEY );
+    }
+
+
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( DIALOG_TITLE );
+    }
+
+
+    public boolean close()
+    {
+        this.dnBuilderWidget.removeWidgetModifyListener( this );
+        this.dnBuilderWidget.dispose();
+        return super.close();
+    }
+
+
+    protected void okPressed()
+    {
+        this.rdn = this.dnBuilderWidget.getRdn();
+        this.deleteOldRdn = this.deleteOldRdnButton.getSelection();
+        this.simulateRename = this.simulateRenameButton.getSelection();
+
+        BrowserUIPlugin.getDefault().getDialogSettings().put( DELETE_OLD_RDN_DIALOGSETTING_KEY, this.deleteOldRdn );
+        this.dnBuilderWidget.saveDialogSettings();
+
+        super.okPressed();
+    }
+
+
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    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;
+        composite.setLayoutData( gd );
+
+        BaseWidgetUtils.createLabel( composite, "Please enter the new RDN of the selected entry.", 1 );
+
+        this.dnBuilderWidget = new DnBuilderWidget( true, false );
+        this.dnBuilderWidget.addWidgetModifyListener( this );
+        this.dnBuilderWidget.createContents( composite );
+        this.dnBuilderWidget.setInput( this.entry.getConnection(), this.entry.getSubschema().getAllAttributeNames(),
+            this.entry.getRdn(), null );
+
+        this.deleteOldRdnButton = BaseWidgetUtils.createCheckbox( composite, "Delete old RDN", 1 );
+        this.deleteOldRdnButton.setSelection( this.deleteOldRdn );
+
+        this.simulateRenameButton = BaseWidgetUtils.createCheckbox( composite,
+            "Simulate subtree renaming by searching/adding/deleting recursively", 1 );
+        this.simulateRenameButton.setSelection( false );
+        this.simulateRenameButton.setEnabled( false );
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    public void widgetModified( WidgetModifyEvent event )
+    {
+        if ( this.okButton != null )
+        {
+            this.okButton.setEnabled( this.dnBuilderWidget.getRdn() != null );
+        }
+    }
+
+
+    public RDN getRdn()
+    {
+        return this.rdn;
+    }
+
+
+    public boolean isDeleteOldRdn()
+    {
+        return this.deleteOldRdn;
+    }
+
+
+    public boolean isSimulateRename()
+    {
+        return simulateRename;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ScopeDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ScopeDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ScopeDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ScopeDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,120 @@
+/*
+ *  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.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+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.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class ScopeDialog extends Dialog
+{
+
+    private String dialogTitle;
+
+    private boolean multi;
+
+    private int scope = -1;
+
+    private Button objectScopeButton;
+
+    private Button onelevelScopeButton;
+
+    private Button subtreeScopeButton;
+
+
+    public ScopeDialog( Shell parentShell, String dialogTitle, boolean multi )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.dialogTitle = dialogTitle;
+        this.multi = multi;
+    }
+
+
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( dialogTitle );
+    }
+
+
+    public boolean close()
+    {
+        return super.close();
+    }
+
+
+    protected void okPressed()
+    {
+        this.scope = this.objectScopeButton.getSelection() ? ISearch.SCOPE_OBJECT : this.onelevelScopeButton
+            .getSelection() ? ISearch.SCOPE_ONELEVEL : ISearch.SCOPE_SUBTREE;
+        super.okPressed();
+    }
+
+
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    protected Control createDialogArea( Composite parent )
+    {
+
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        composite.setLayoutData( gd );
+
+        Group group = BaseWidgetUtils.createGroup( composite, "Please select the copy depth", 1 );
+        this.objectScopeButton = new Button( group, SWT.RADIO );
+        this.objectScopeButton.setSelection( true );
+        this.objectScopeButton.setText( this.multi ? "&Object (Only the copied entries)"
+            : "&Object (Only the copied entry)" );
+        this.onelevelScopeButton = new Button( group, SWT.RADIO );
+        this.onelevelScopeButton.setText( this.multi ? "O&ne Level (The copied entries and their direct children)"
+            : "O&ne Level (The copied entry and its direct children)" );
+        this.subtreeScopeButton = new Button( group, SWT.RADIO );
+        this.subtreeScopeButton.setText( this.multi ? "&Subtree (The whole subtrees)" : "&Subtree (The whole subtree)" );
+
+        applyDialogFont( composite );
+        return composite;
+
+    }
+
+
+    public int getScope()
+    {
+        return this.scope;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectConnectionDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectConnectionDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectConnectionDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectConnectionDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,202 @@
+/*
+ *  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.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.ui.widgets.connection.ConnectionActionGroup;
+import org.apache.directory.ldapstudio.browser.ui.widgets.connection.ConnectionConfiguration;
+import org.apache.directory.ldapstudio.browser.ui.widgets.connection.ConnectionUniversalListener;
+import org.apache.directory.ldapstudio.browser.ui.widgets.connection.ConnectionWidget;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+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;
+
+
+public class SelectConnectionDialog extends Dialog
+{
+
+    private String title;
+
+    private IConnection initialConnection;
+
+    private IConnection selectedConnection;
+
+    private ConnectionConfiguration configuration;
+
+    private ConnectionUniversalListener universalListener;
+
+    private ConnectionActionGroup actionGroup;
+
+    private ConnectionWidget mainWidget;
+
+
+    public SelectConnectionDialog( Shell parentShell, String title, IConnection initialConnection )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.title = title;
+        this.initialConnection = initialConnection;
+        this.selectedConnection = null;
+    }
+
+
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( title );
+    }
+
+
+    public boolean close()
+    {
+        if ( this.mainWidget != null )
+        {
+            this.configuration.dispose();
+            this.configuration = null;
+            this.actionGroup.deactivateGlobalActionHandlers();
+            this.actionGroup.dispose();
+            this.actionGroup = null;
+            this.universalListener.dispose();
+            this.universalListener = null;
+            this.mainWidget.dispose();
+            this.mainWidget = null;
+        }
+        return super.close();
+    }
+
+
+    protected void okPressed()
+    {
+        this.selectedConnection = initialConnection;
+        super.okPressed();
+    }
+
+
+    protected void cancelPressed()
+    {
+        this.selectedConnection = null;
+        super.cancelPressed();
+    }
+
+
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    protected Control createDialogArea( Composite parent )
+    {
+
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridLayout gl = new GridLayout();
+        composite.setLayout( gl );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+        gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
+        composite.setLayoutData( gd );
+
+        // create configuration
+        this.configuration = new ConnectionConfiguration();
+
+        // create main widget
+        this.mainWidget = new ConnectionWidget( this.configuration, null );
+        this.mainWidget.createWidget( composite );
+        this.mainWidget.setInput( BrowserCorePlugin.getDefault().getConnectionManager() );
+
+        // create actions and context menu (and register global actions)
+        this.actionGroup = new ConnectionActionGroup( this.mainWidget, this.configuration );
+        this.actionGroup.fillToolBar( this.mainWidget.getToolBarManager() );
+        this.actionGroup.fillMenu( this.mainWidget.getMenuManager() );
+        this.actionGroup.fillContextMenu( this.mainWidget.getContextMenuManager() );
+        this.actionGroup.activateGlobalActionHandlers();
+
+        // create the listener
+        this.universalListener = new ConnectionUniversalListener( this.mainWidget.getViewer() );
+
+        this.mainWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                if ( !event.getSelection().isEmpty() )
+                {
+                    Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                    if ( o instanceof IConnection )
+                    {
+                        initialConnection = ( IConnection ) o;
+                    }
+                }
+            }
+        } );
+
+        this.mainWidget.getViewer().addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                if ( !event.getSelection().isEmpty() )
+                {
+                    Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                    if ( o instanceof IConnection )
+                    {
+                        initialConnection = ( IConnection ) o;
+                        okPressed();
+                    }
+                }
+            }
+        } );
+
+        if ( this.initialConnection != null )
+        {
+            IConnection connection = this.initialConnection;
+            this.mainWidget.getViewer().reveal( connection );
+            this.mainWidget.getViewer().setSelection( new StructuredSelection( connection ), true );
+        }
+
+        applyDialogFont( composite );
+
+        this.mainWidget.setFocus();
+
+        return composite;
+
+    }
+
+
+    public IConnection getSelectedConnection()
+    {
+        return this.selectedConnection;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectEntryDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectEntryDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectEntryDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectEntryDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,197 @@
+/*
+ *  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.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserActionGroup;
+import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserConfiguration;
+import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserUniversalListener;
+import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserWidget;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class SelectEntryDialog extends Dialog
+{
+
+    private String title;
+
+    private Image image;
+
+    private IConnection connection;
+
+    private IEntry initialEntry;
+
+    private IEntry selectedEntry;
+
+    private BrowserConfiguration configuration;
+
+    private BrowserUniversalListener universalListener;
+
+    private BrowserActionGroup actionGroup;
+
+    private BrowserWidget mainWidget;
+
+
+    public SelectEntryDialog( Shell parentShell, String title, IConnection connection, IEntry initialEntry )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.title = title;
+        this.connection = connection;
+        this.initialEntry = initialEntry;
+        this.selectedEntry = null;
+    }
+
+
+    public SelectEntryDialog( Shell parentShell, String title, Image image, IConnection connection, IEntry initialEntry )
+    {
+        this( parentShell, title, connection, initialEntry );
+        this.image = image;
+    }
+
+
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( title );
+        shell.setImage( image );
+    }
+
+
+    public boolean close()
+    {
+        if ( this.mainWidget != null )
+        {
+            this.configuration.dispose();
+            this.configuration = null;
+            this.actionGroup.deactivateGlobalActionHandlers();
+            this.actionGroup.dispose();
+            this.actionGroup = null;
+            this.universalListener.dispose();
+            this.universalListener = null;
+            this.mainWidget.dispose();
+            this.mainWidget = null;
+        }
+        return super.close();
+    }
+
+
+    protected void okPressed()
+    {
+        this.selectedEntry = initialEntry;
+        super.okPressed();
+    }
+
+
+    protected void cancelPressed()
+    {
+        this.selectedEntry = null;
+        super.cancelPressed();
+    }
+
+
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    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 );
+        gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+        composite.setLayoutData( gd );
+
+        // create configuration
+        this.configuration = new BrowserConfiguration();
+
+        // create main widget
+        this.mainWidget = new BrowserWidget( this.configuration, null );
+        this.mainWidget.createWidget( composite );
+        this.mainWidget.setInput( this.connection.getBaseDNEntries() );
+
+        // create actions and context menu (and register global actions)
+        this.actionGroup = new BrowserActionGroup( this.mainWidget, this.configuration );
+        this.actionGroup.fillToolBar( this.mainWidget.getToolBarManager() );
+        this.actionGroup.fillMenu( this.mainWidget.getMenuManager() );
+        this.actionGroup.fillContextMenu( this.mainWidget.getContextMenuManager() );
+        this.actionGroup.activateGlobalActionHandlers();
+
+        // create the listener
+        this.universalListener = new BrowserUniversalListener( this.mainWidget.getViewer() );
+
+        this.mainWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                if ( !event.getSelection().isEmpty() )
+                {
+                    Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                    if ( o instanceof IEntry )
+                    {
+                        initialEntry = ( IEntry ) o;
+                    }
+                }
+            }
+        } );
+
+        if ( this.initialEntry != null )
+        {
+            IEntry entry = this.initialEntry;
+            this.mainWidget.getViewer().reveal( entry );
+            this.mainWidget.getViewer().refresh( entry, true );
+            this.mainWidget.getViewer().setSelection( new StructuredSelection( entry ), true );
+            this.mainWidget.getViewer().setSelection( new StructuredSelection( entry ), true );
+        }
+
+        applyDialogFont( composite );
+
+        this.mainWidget.setFocus();
+
+        return composite;
+
+    }
+
+
+    public IEntry getSelectedEntry()
+    {
+        return this.selectedEntry;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectReferralConnectionDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectReferralConnectionDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectReferralConnectionDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/SelectReferralConnectionDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,214 @@
+/*
+ *  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.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.URL;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.connection.ConnectionActionGroup;
+import org.apache.directory.ldapstudio.browser.ui.widgets.connection.ConnectionConfiguration;
+import org.apache.directory.ldapstudio.browser.ui.widgets.connection.ConnectionUniversalListener;
+import org.apache.directory.ldapstudio.browser.ui.widgets.connection.ConnectionWidget;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+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;
+
+
+public class SelectReferralConnectionDialog extends Dialog
+{
+
+    private String title;
+
+    private URL referralUrl;
+
+    private IConnection selectedConnection;
+
+    private ConnectionConfiguration configuration;
+
+    private ConnectionUniversalListener universalListener;
+
+    private ConnectionActionGroup actionGroup;
+
+    private ConnectionWidget mainWidget;
+
+
+    public SelectReferralConnectionDialog( Shell parentShell, URL referralUrl )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.title = "Select Referral Connection";
+        this.referralUrl = referralUrl;
+        this.selectedConnection = null;
+    }
+
+
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( title );
+    }
+
+
+    public boolean close()
+    {
+        if ( this.mainWidget != null )
+        {
+            this.configuration.dispose();
+            this.configuration = null;
+            this.actionGroup.deactivateGlobalActionHandlers();
+            this.actionGroup.dispose();
+            this.actionGroup = null;
+            this.universalListener.dispose();
+            this.universalListener = null;
+            this.mainWidget.dispose();
+            this.mainWidget = null;
+        }
+        return super.close();
+    }
+
+
+    protected void okPressed()
+    {
+        super.okPressed();
+    }
+
+
+    protected void cancelPressed()
+    {
+        this.selectedConnection = null;
+        super.cancelPressed();
+    }
+
+
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    protected Control createDialogArea( Composite parent )
+    {
+
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridLayout gl = new GridLayout();
+        composite.setLayout( gl );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+        gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
+        composite.setLayoutData( gd );
+
+        BaseWidgetUtils.createWrappedLabeledText( composite, "Please select a connection to handle referral "
+            + referralUrl, 1 );
+
+        // create configuration
+        this.configuration = new ConnectionConfiguration();
+
+        // create main widget
+        this.mainWidget = new ConnectionWidget( this.configuration, null );
+        this.mainWidget.createWidget( composite );
+        this.mainWidget.setInput( BrowserCorePlugin.getDefault().getConnectionManager() );
+
+        // create actions and context menu (and register global actions)
+        this.actionGroup = new ConnectionActionGroup( this.mainWidget, this.configuration );
+        this.actionGroup.fillToolBar( this.mainWidget.getToolBarManager() );
+        this.actionGroup.fillMenu( this.mainWidget.getMenuManager() );
+        this.actionGroup.fillContextMenu( this.mainWidget.getContextMenuManager() );
+        this.actionGroup.activateGlobalActionHandlers();
+
+        // create the listener
+        this.universalListener = new ConnectionUniversalListener( this.mainWidget.getViewer() );
+
+        this.mainWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                if ( !event.getSelection().isEmpty() )
+                {
+                    Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                    if ( o instanceof IConnection )
+                    {
+                        selectedConnection = ( IConnection ) o;
+                    }
+                }
+            }
+        } );
+
+        this.mainWidget.getViewer().addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                if ( !event.getSelection().isEmpty() )
+                {
+                    Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                    if ( o instanceof IConnection )
+                    {
+                        selectedConnection = ( IConnection ) o;
+                        okPressed();
+                    }
+                }
+            }
+        } );
+
+        if ( this.referralUrl != null )
+        {
+            IConnection[] connections = BrowserCorePlugin.getDefault().getConnectionManager().getConnections();
+            for ( int i = 0; i < connections.length; i++ )
+            {
+                IConnection connection = connections[i];
+                URL connectionUrl = connection.getUrl();
+                if ( connectionUrl != null && referralUrl.toString().startsWith( connectionUrl.toString() ) )
+                {
+                    this.mainWidget.getViewer().reveal( connection );
+                    this.mainWidget.getViewer().setSelection( new StructuredSelection( connection ), true );
+                }
+            }
+        }
+
+        applyDialogFont( composite );
+
+        this.mainWidget.setFocus();
+
+        return composite;
+
+    }
+
+
+    public IConnection getReferralConnection()
+    {
+        return this.selectedConnection;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/TextDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/TextDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/TextDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/TextDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,115 @@
+/*
+ *  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.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+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.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+
+public class TextDialog extends Dialog
+{
+
+    public static final String DIALOG_TITLE = "Text Editor";
+
+    public static final double MAX_WIDTH = 250.0;
+
+    public static final double MAX_HEIGHT = 250.0;
+
+    private String initialValue;
+
+    private String returnValue;
+
+    private Text text;
+
+
+    public TextDialog( Shell parentShell, String initialValue )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.initialValue = initialValue;
+        this.returnValue = null;
+    }
+
+
+    public boolean close()
+    {
+        return super.close();
+    }
+
+
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( DIALOG_TITLE );
+        shell.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_TEXTEDITOR ) );
+    }
+
+
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    protected void okPressed()
+    {
+        this.returnValue = this.text.getText();
+        super.okPressed();
+    }
+
+
+    protected Control createDialogArea( Composite parent )
+    {
+        // create composite
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        composite.setLayoutData( gd );
+
+        // text widget
+        text = new Text( composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL );
+        text.setText( this.initialValue );
+        // GridData gd = new GridData(GridData.GRAB_HORIZONTAL |
+        // GridData.HORIZONTAL_ALIGN_FILL);
+        gd = new GridData( GridData.FILL_BOTH );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+        gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
+        text.setLayoutData( gd );
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    public String getText()
+    {
+        return this.returnValue;
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributeDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributeDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributeDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributeDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,108 @@
+/*
+ *  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.browser.ui.dialogs.preferences;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.schema.BinaryAttribute;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class AttributeDialog extends Dialog
+{
+
+    private BinaryAttribute currentAttribute;
+
+    private String[] attributeTypesAndOids;
+
+    private BinaryAttribute returnAttribute;
+
+    private Combo typeOrOidCombo;
+
+
+    public AttributeDialog( Shell parentShell, BinaryAttribute currentAttribute, String[] attributeNamesAndOids )
+    {
+        super( parentShell );
+        this.currentAttribute = currentAttribute;
+        this.attributeTypesAndOids = attributeNamesAndOids;
+
+        this.returnAttribute = null;
+    }
+
+
+    protected void configureShell( Shell newShell )
+    {
+        super.configureShell( newShell );
+        newShell.setText( "Select Attribute Type or OID" );
+    }
+
+
+    protected void okPressed()
+    {
+        this.returnAttribute = new BinaryAttribute( typeOrOidCombo.getText() );
+        super.okPressed();
+    }
+
+
+    protected Control createDialogArea( Composite parent )
+    {
+
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+
+        Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
+        BaseWidgetUtils.createLabel( c, "Attribute Type or OID:", 1 );
+        this.typeOrOidCombo = BaseWidgetUtils.createCombo( c, this.attributeTypesAndOids, -1, 1 );
+        if ( this.currentAttribute != null )
+        {
+            this.typeOrOidCombo.setText( currentAttribute.getAttributeNumericOidOrName() );
+        }
+        this.typeOrOidCombo.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                validate();
+            }
+        } );
+
+        return composite;
+    }
+
+
+    private void validate()
+    {
+        super.getButton( IDialogConstants.OK_ID ).setEnabled( !"".equals( this.typeOrOidCombo.getText() ) );
+    }
+
+
+    public BinaryAttribute getAttribute()
+    {
+        return returnAttribute;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributeValueProviderDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributeValueProviderDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributeValueProviderDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributeValueProviderDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,147 @@
+/*
+ *  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.browser.ui.dialogs.preferences;
+
+
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeValueProviderRelation;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class AttributeValueProviderDialog extends Dialog
+{
+
+    private AttributeValueProviderRelation relation;
+
+    private SortedMap class2ValueProviderMap;
+
+    private String[] attributeTypesAndOids;
+
+    private SortedMap vpName2classMap;
+
+    private AttributeValueProviderRelation returnRelation;
+
+    private Combo typeOrOidCombo;
+
+    private Combo valueEditorCombo;
+
+
+    public AttributeValueProviderDialog( Shell parentShell, AttributeValueProviderRelation relation,
+        SortedMap class2ValueProviderMap, String[] attributeTypesAndOids )
+    {
+        super( parentShell );
+        this.relation = relation;
+        this.class2ValueProviderMap = class2ValueProviderMap;
+        this.attributeTypesAndOids = attributeTypesAndOids;
+
+        this.returnRelation = null;
+
+        this.vpName2classMap = new TreeMap();
+        for ( Iterator it = this.class2ValueProviderMap.values().iterator(); it.hasNext(); )
+        {
+            ValueProvider vp = ( ValueProvider ) it.next();
+            vpName2classMap.put( vp.getCellEditorName(), vp.getClass().getName() );
+        }
+    }
+
+
+    protected void configureShell( Shell newShell )
+    {
+        super.configureShell( newShell );
+        newShell.setText( "Attribute Value Editor" );
+    }
+
+
+    protected void okPressed()
+    {
+        this.returnRelation = new AttributeValueProviderRelation( this.typeOrOidCombo.getText(),
+            ( String ) this.vpName2classMap.get( this.valueEditorCombo.getText() ) );
+        super.okPressed();
+    }
+
+
+    protected Control createDialogArea( Composite parent )
+    {
+
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+
+        Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
+        BaseWidgetUtils.createLabel( c, "Attribute Type or OID:", 1 );
+        this.typeOrOidCombo = BaseWidgetUtils.createCombo( c, this.attributeTypesAndOids, -1, 1 );
+        if ( this.relation != null && this.relation.getAttributeNumericOidOrType() != null )
+        {
+            this.typeOrOidCombo.setText( this.relation.getAttributeNumericOidOrType() );
+        }
+        this.typeOrOidCombo.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                validate();
+            }
+        } );
+
+        BaseWidgetUtils.createLabel( c, "Value Editor:", 1 );
+        this.valueEditorCombo = BaseWidgetUtils.createReadonlyCombo( c, ( String[] ) vpName2classMap.keySet().toArray(
+            new String[0] ), -1, 1 );
+        if ( this.relation != null && this.relation.getValueProviderClassname() != null
+            && this.class2ValueProviderMap.containsKey( this.relation.getValueProviderClassname() ) )
+        {
+            this.valueEditorCombo.setText( ( ( ValueProvider ) this.class2ValueProviderMap.get( this.relation
+                .getValueProviderClassname() ) ).getCellEditorName() );
+        }
+        this.valueEditorCombo.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                validate();
+            }
+        } );
+
+        return composite;
+    }
+
+
+    private void validate()
+    {
+        super.getButton( IDialogConstants.OK_ID ).setEnabled(
+            !"".equals( this.valueEditorCombo.getText() ) && !"".equals( this.typeOrOidCombo.getText() ) );
+    }
+
+
+    public AttributeValueProviderRelation getRelation()
+    {
+        return returnRelation;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributesPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributesPreferencePage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributesPreferencePage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/AttributesPreferencePage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,217 @@
+/*
+ *  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.browser.ui.dialogs.preferences;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.eclipse.jface.preference.ColorSelector;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class AttributesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
+{
+
+    private final String[] ATTRIBUTE_TYPES = new String[]
+        { "Objectclass attribute:", "Must attributes:", "May attributes:", "Operational attributes:" };
+
+    private final String[] ATTRIBUTE_FONT_CONSTANTS = new String[]
+        { BrowserUIConstants.PREFERENCE_OBJECTCLASS_FONT, BrowserUIConstants.PREFERENCE_MUSTATTRIBUTE_FONT,
+            BrowserUIConstants.PREFERENCE_MAYATTRIBUTE_FONT, BrowserUIConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT };
+
+    private final String[] ATTRIBUTE_COLOR_CONSTANTS = new String[]
+        { BrowserUIConstants.PREFERENCE_OBJECTCLASS_COLOR, BrowserUIConstants.PREFERENCE_MUSTATTRIBUTE_COLOR,
+            BrowserUIConstants.PREFERENCE_MAYATTRIBUTE_COLOR, BrowserUIConstants.PREFERENCE_OPERATIONALATTRIBUTE_COLOR };
+
+    private Label[] attributeTypeLabels = new Label[ATTRIBUTE_TYPES.length];
+
+    private ColorSelector[] attributeColorSelectors = new ColorSelector[ATTRIBUTE_TYPES.length];
+
+    private Button[] attributeBoldButtons = new Button[ATTRIBUTE_TYPES.length];
+
+    private Button[] attributeItalicButtons = new Button[ATTRIBUTE_TYPES.length];
+
+    private Button showRawValuesButton;
+
+
+    public AttributesPreferencePage()
+    {
+        super( "Attributes" );
+        super.setPreferenceStore( BrowserUIPlugin.getDefault().getPreferenceStore() );
+        super.setDescription( "General settings for attributes:" );
+    }
+
+
+    public void init( IWorkbench workbench )
+    {
+    }
+
+
+    protected Control createContents( Composite parent )
+    {
+
+        Composite composite = new Composite( parent, SWT.NONE );
+        GridLayout layout = new GridLayout( 1, false );
+        layout.marginWidth = 0;
+        layout.marginHeight = 0;
+        layout.marginLeft = 0;
+        layout.marginRight = 0;
+        layout.marginTop = 0;
+        layout.marginBottom = 0;
+        composite.setLayout( layout );
+        composite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        Group colorsAndFontsGroup = BaseWidgetUtils.createGroup( composite, "Attribute Colors and Fonts", 1 );
+        colorsAndFontsGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        Composite colorsAndFontsComposite = BaseWidgetUtils.createColumnContainer( colorsAndFontsGroup, 4, 1 );
+        for ( int i = 0; i < ATTRIBUTE_TYPES.length; i++ )
+        {
+            final int index = i;
+
+            attributeTypeLabels[i] = BaseWidgetUtils.createLabel( colorsAndFontsComposite, ATTRIBUTE_TYPES[i], 1 );
+            attributeTypeLabels[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+            attributeColorSelectors[i] = new ColorSelector( colorsAndFontsComposite );
+            attributeBoldButtons[i] = BaseWidgetUtils.createCheckbox( colorsAndFontsComposite, "Bold", 1 );
+            attributeItalicButtons[i] = BaseWidgetUtils.createCheckbox( colorsAndFontsComposite, "Italic", 1 );
+
+            FontData[] fontDatas = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                .getPreferenceStore(), ATTRIBUTE_FONT_CONSTANTS[i] );
+            RGB rgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                ATTRIBUTE_COLOR_CONSTANTS[i] );
+            setColorsAndFonts( index, fontDatas, rgb );
+        }
+
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        showRawValuesButton = BaseWidgetUtils.createCheckbox( composite, "Show raw values", 1 );
+        showRawValuesButton.setSelection( getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_SHOW_RAW_VALUES ) );
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    private void setColorsAndFonts( int index, FontData[] fontDatas, RGB rgb )
+    {
+        boolean bold = isBold( fontDatas );
+        boolean italic = isItalic( fontDatas );
+        attributeColorSelectors[index].setColorValue( rgb );
+        attributeBoldButtons[index].setSelection( bold );
+        attributeItalicButtons[index].setSelection( italic );
+    }
+
+
+    private void setFontData( FontData[] fontDatas, Button boldButton, Button italicButton )
+    {
+        for ( int j = 0; j < fontDatas.length; j++ )
+        {
+            int style = SWT.NORMAL;
+            if ( boldButton.getSelection() )
+                style |= SWT.BOLD;
+            if ( italicButton.getSelection() )
+                style |= SWT.ITALIC;
+            fontDatas[j].setStyle( style );
+        }
+    }
+
+
+    private boolean isBold( FontData[] fontDatas )
+    {
+        boolean bold = false;
+        for ( int j = 0; j < fontDatas.length; j++ )
+        {
+            if ( ( fontDatas[j].getStyle() & SWT.BOLD ) != SWT.NORMAL )
+                bold = true;
+        }
+        return bold;
+    }
+
+
+    private boolean isItalic( FontData[] fontDatas )
+    {
+        boolean italic = false;
+        for ( int j = 0; j < fontDatas.length; j++ )
+        {
+            if ( ( fontDatas[j].getStyle() & SWT.ITALIC ) != SWT.NORMAL )
+                italic = true;
+        }
+        return italic;
+    }
+
+
+    public boolean performOk()
+    {
+
+        for ( int i = 0; i < ATTRIBUTE_TYPES.length; i++ )
+        {
+            FontData[] fontDatas = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                .getPreferenceStore(), ATTRIBUTE_FONT_CONSTANTS[i] );
+            setFontData( fontDatas, this.attributeBoldButtons[i], this.attributeItalicButtons[i] );
+            RGB rgb = attributeColorSelectors[i].getColorValue();
+            PreferenceConverter.setValue( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                ATTRIBUTE_FONT_CONSTANTS[i], fontDatas );
+            PreferenceConverter.setValue( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                ATTRIBUTE_COLOR_CONSTANTS[i], rgb );
+        }
+
+        getPreferenceStore().setValue( BrowserUIConstants.PREFERENCE_SHOW_RAW_VALUES,
+            this.showRawValuesButton.getSelection() );
+
+        return true;
+    }
+
+
+    protected void performDefaults()
+    {
+
+        for ( int i = 0; i < ATTRIBUTE_TYPES.length; i++ )
+        {
+            FontData[] fontDatas = PreferenceConverter.getDefaultFontDataArray( BrowserUIPlugin.getDefault()
+                .getPreferenceStore(), ATTRIBUTE_FONT_CONSTANTS[i] );
+            RGB rgb = PreferenceConverter.getDefaultColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                ATTRIBUTE_COLOR_CONSTANTS[i] );
+            setColorsAndFonts( i, fontDatas, rgb );
+        }
+
+        showRawValuesButton.setSelection( getPreferenceStore().getDefaultBoolean(
+            BrowserUIConstants.PREFERENCE_SHOW_RAW_VALUES ) );
+
+        super.performDefaults();
+    }
+
+}



Mime
View raw message