directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r526693 [12/17] - in /directory/ldapstudio/trunk/ldapstudio-browser-common: ./ META-INF/ resources/ resources/icons/ resources/templates/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/di...
Date Mon, 09 Apr 2007 09:49:57 GMT
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionPageWrapper.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionPageWrapper.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionPageWrapper.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionPageWrapper.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,982 @@
+/*
+ *  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.common.widgets.connection;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.jobs.RunnableContextJobAdapter;
+import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.common.widgets.HistoryUtils;
+import org.apache.directory.ldapstudio.browser.common.widgets.search.AliasesDereferencingWidget;
+import org.apache.directory.ldapstudio.browser.common.widgets.search.LimitWidget;
+import org.apache.directory.ldapstudio.browser.common.widgets.search.ReferralsHandlingWidget;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Connection;
+import org.apache.directory.ldapstudio.browser.core.jobs.CheckBindJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.CheckNetworkParameterJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.FetchBaseDNsJob;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.NameException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * The ConnectionPageWrapper is a wrapper for all UI widgets needed for the
+ * connection configuration. It is used by the new connection wizard as well
+ * as the connection property page. So all widgets and functionality is 
+ * implemented only once in this wrapper.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionPageWrapper implements ModifyListener, SelectionListener
+{
+
+    /** The connection name text widget */
+    private Text nameText;
+
+    /** The host name combo with the history of recently used host names */
+    private Combo hostCombo;
+
+    /** The host name text widget */
+    private Text hostText;
+
+    /** The host combo with the history of recently used ports */
+    private Combo portCombo;
+
+    /** The port text widget */
+    private Text portText;
+
+    /** The combo to select the encryption method */
+    private Combo encryptionMethodCombo;
+
+    /** The button to check the connection parameters */
+    private Button checkConnectionButton;
+
+    /** The checkbox to fetch the base DN's from namingContexts whenever opening the connection */
+    private Button autoFetchBaseDnsButton;
+
+    /** The button to fetch the base DN's from namingContexts attribute */
+    private Button fetchBaseDnsButton;
+
+    /** The combo that displays the fetched base DN's */
+    private Combo baseDNCombo;
+
+    /** The widget with the count and time limits */
+    private LimitWidget limitWidget;
+
+    /** The widget to select the alias dereferencing method */
+    private AliasesDereferencingWidget aliasesDereferencingWidget;
+
+    /** The widget to select the referrals handling method */
+    private ReferralsHandlingWidget referralsHandlingWidget;
+
+    /** The checkbox to choose wether the connection should be opened when finishing the wizard */
+    private Button openConnectionButton;
+
+    /** The radio to select anonymous authentication */
+    private Button anonymousAuthButton;
+
+    /** The radio to select simple authentication */
+    private Button simpleAuthButton;
+
+    /** The bind user combo with the history of recently used bind users */
+    private Combo simpleAuthBindPrincipalCombo;
+
+    /** The text widget with the bind user */
+    private Text simpleAuthBindPrincipalText;
+
+    /** The text widget to input bind password */
+    private Text simpleAuthBindPasswordText;
+
+    /** The checkbox to choose if the bind password should be saved on disk */
+    private Button saveSimpleAuthBindPasswordButton;
+
+    /** The button to check the authentication parameters */
+    private Button checkSimpleAuthButton;
+
+    /** The list of listerns that are interested in modifications in this page */
+    private List<ConnectionPageModifyListener> listenerList;
+
+    /** 
+     * This flag indicats if the connection is opened. It is used to determin wether to render
+     * the combos or just simple text widgets.
+     */
+    private boolean isConnectionOpened;
+
+    /** The runnable contxt that is used for long-running operations such as connection checks */
+    private IRunnableContext runnableContext;
+
+
+    /**
+     * Creates a new instance of ConnectionPageWrapper.
+     *
+     * @param listener the initial modify listener, may be null
+     * @param runnableContext the runnable context
+     */
+    public ConnectionPageWrapper( ConnectionPageModifyListener listener, IRunnableContext runnableContext )
+    {
+        this.listenerList = new ArrayList<ConnectionPageModifyListener>( 5 );
+        if ( listener != null )
+        {
+            this.listenerList.add( listener );
+            this.isConnectionOpened = listener.getRealConnection() != null && listener.getRealConnection().isOpened();
+        }
+        else
+        {
+            this.isConnectionOpened = false;
+        }
+        this.runnableContext = runnableContext;
+    }
+
+
+    /**
+     * Add the give listnere to the list of modify listeners.
+     *
+     * @param listener the modify listener
+     */
+    public void addConnectionPageModifyListener( ConnectionPageModifyListener listener )
+    {
+        listenerList.add( listener );
+    }
+
+
+    /**
+     * Gets the connection name.
+     * 
+     * @return the connectio name
+     */
+    public String getName()
+    {
+        return nameText.getText();
+    }
+
+
+    /**
+     * Gets the host name.
+     * 
+     * @return the host name
+     */
+    public String getHostName()
+    {
+        return hostCombo != null ? hostCombo.getText() : hostText.getText();
+    }
+
+
+    /**
+     * Gets the port.
+     * 
+     * @return the port
+     */
+    public int getPort()
+    {
+        return Integer.parseInt( portCombo != null ? portCombo.getText() : portText.getText() );
+    }
+
+
+    /**
+     * Gets the encyrption method, one of IConnection.ENCYRPTION_NONE, 
+     * IConnection.ENCYRPTION_LDAPS or IConnection.ENCYRPTION_STARTTLS.
+     * 
+     * @return the encyrption method
+     */
+    public int getEncyrptionMethod()
+    {
+        if ( encryptionMethodCombo != null )
+        {
+            switch ( encryptionMethodCombo.getSelectionIndex() )
+            {
+                case 1:
+                    return IConnection.ENCYRPTION_LDAPS;
+                case 2:
+                    return IConnection.ENCYRPTION_STARTTLS;
+                default:
+                    return IConnection.ENCYRPTION_NONE;
+            }
+        }
+        return IConnection.ENCYRPTION_NONE;
+    }
+
+
+    /**
+     * Returns true if base DN's should be fetched 
+     * whenever opening the connection.
+     * 
+     * @return true, if base DN's should be fetched
+     */
+    public boolean isAutoFetchBaseDns()
+    {
+        return autoFetchBaseDnsButton.getSelection();
+    }
+
+
+    /**
+     * Gets the base DN.
+     * 
+     * @return the base DN
+     */
+    public String getBaseDN()
+    {
+        return baseDNCombo.getText();
+    }
+
+
+    /**
+     * Gets the count limit.
+     * 
+     * @return the count limit
+     */
+    public int getCountLimit()
+    {
+        return limitWidget.getCountLimit();
+    }
+
+
+    /**
+     * Gets the time limit.
+     * 
+     * @return the time limit
+     */
+    public int getTimeLimit()
+    {
+        return limitWidget.getTimeLimit();
+    }
+
+
+    /**
+     * Gets the aliases dereferencing method.
+     * 
+     * @return the aliases dereferencing method
+     */
+    public int getAliasesDereferencingMethod()
+    {
+        return aliasesDereferencingWidget.getAliasesDereferencingMethod();
+    }
+
+
+    /**
+     * Gets the referrals handling method.
+     * 
+     * @return the referrals handling method
+     */
+    public int getReferralsHandlingMethod()
+    {
+        return referralsHandlingWidget.getReferralsHandlingMethod();
+    }
+
+
+    /**
+     * Sets the open connection on finish flag.
+     * 
+     * @param b the open connection on finish flag
+     */
+    public void setOpenConnectionOnFinish( boolean b )
+    {
+        if ( openConnectionButton != null )
+        {
+            openConnectionButton.setSelection( b );
+        }
+    }
+
+
+    /**
+     * Returns true if the connection should be opened
+     * when finishing the wizard.
+     * 
+     * @return true, if the connection should be opened
+     */
+    public boolean isOpenConnectionOnFinish()
+    {
+        return openConnectionButton.getSelection();
+    }
+
+
+    /**
+     * Gets the authentication method, one of IConnection.AUTH_ANONYMOUS
+     * or IConnection.AUTH_SIMPLE.
+     * 
+     * @return the authentication method
+     */
+    public int getAuthenticationMethod()
+    {
+        if ( anonymousAuthButton.getSelection() )
+        {
+            return IConnection.AUTH_ANONYMOUS;
+        }
+        else if ( simpleAuthButton.getSelection() )
+        {
+            return IConnection.AUTH_SIMPLE;
+        }
+
+        return IConnection.AUTH_ANONYMOUS;
+    }
+
+
+    /**
+     * Gets the simple auth bind principal.
+     * 
+     * @return the simple auth bind principal
+     */
+    public String getSimpleAuthBindPrincipal()
+    {
+        return simpleAuthBindPrincipalCombo != null ? simpleAuthBindPrincipalCombo.getText()
+            : simpleAuthBindPrincipalText.getText();
+    }
+
+
+    /**
+     * Gets the simple auth bind password.
+     * 
+     * @return the simple auth bind password
+     */
+    public String getSimpleAuthBindPassword()
+    {
+        return simpleAuthBindPasswordText.getText();
+    }
+
+
+    /**
+     * Returns true if the bind password should be saved on disk.
+     * 
+     * @return true, if the bind password should be saved on disk
+     */
+    public boolean isSaveSimpleAuthBindPassword()
+    {
+        return saveSimpleAuthBindPasswordButton.getSelection();
+    }
+
+
+    /**
+     * Adds the main input widgets. In includes widgets for the connection name,
+     * host, port and encrypition method 
+     * 
+     * @param name the initial name
+     * @param host the initial host
+     * @param port the initial port
+     * @param encryptionMethod the initial encryption method
+     * @param parent the parent
+     */
+    public void addMainInput( String name, String host, int port, int encryptionMethod, Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Composite nameComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
+        BaseWidgetUtils.createLabel( nameComposite, "Connection name:", 1 );
+        nameText = BaseWidgetUtils.createText( nameComposite, name, 1 );
+        nameText.addModifyListener( this );
+
+        BaseWidgetUtils.createSpacer( composite, 1 );
+
+        Group group = BaseWidgetUtils.createGroup( composite, "Network Parameter", 1 );
+
+        Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 );
+        BaseWidgetUtils.createLabel( groupComposite, "Hostname:", 1 );
+        if ( isConnectionOpened )
+        {
+            hostText = BaseWidgetUtils.createReadonlyText( groupComposite, host, 2 );
+        }
+        else
+        {
+            String[] hostHistory = HistoryUtils.load( BrowserCommonConstants.DIALOGSETTING_KEY_HOST_HISTORY );
+            hostCombo = BaseWidgetUtils.createCombo( groupComposite, hostHistory, -1, 2 );
+            hostCombo.setText( host );
+            hostCombo.addModifyListener( this );
+        }
+
+        BaseWidgetUtils.createLabel( groupComposite, "Port:", 1 );
+        if ( isConnectionOpened )
+        {
+            portText = BaseWidgetUtils.createReadonlyText( groupComposite, Integer.toString( port ), 2 );
+        }
+        else
+        {
+            String[] portHistory = HistoryUtils.load( BrowserCommonConstants.DIALOGSETTING_KEY_PORT_HISTORY );
+            portCombo = BaseWidgetUtils.createCombo( groupComposite, portHistory, -1, 2 );
+            portCombo.setText( Integer.toString( port ) );
+            portCombo.addVerifyListener( new VerifyListener()
+            {
+                public void verifyText( VerifyEvent e )
+                {
+                    if ( !e.text.matches( "[0-9]*" ) )
+                    {
+                        e.doit = false;
+                    }
+                    if ( portCombo.getText().length() > 4 && e.text.length() > 0 )
+                    {
+                        e.doit = false;
+                    }
+                }
+            } );
+            portCombo.addModifyListener( this );
+        }
+
+        String[] encMethods = new String[]
+            { "No encryption", "Use SSL encryption (ldaps://)", "Use StartTLS extension" };
+        BaseWidgetUtils.createLabel( groupComposite, "Encryption method:", 1 );
+        encryptionMethodCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, encMethods, encryptionMethod, 2 );
+        encryptionMethodCombo.addSelectionListener( this );
+        BaseWidgetUtils.createSpacer( groupComposite, 1 );
+        BaseWidgetUtils
+            .createLabel(
+                groupComposite,
+                "Warning: The current version doesn't support certificate validation, \nbe aware of invalid certificates or man-in-the-middle attacks!",
+                2 );
+
+        BaseWidgetUtils.createSpacer( groupComposite, 2 );
+        checkConnectionButton = new Button( groupComposite, SWT.PUSH );
+        GridData gd = new GridData();
+        gd.horizontalAlignment = SWT.RIGHT;
+        gd.verticalAlignment = SWT.BOTTOM;
+        checkConnectionButton.setLayoutData( gd );
+        checkConnectionButton.setText( "Check Network Parameter" );
+        checkConnectionButton.setEnabled( !isConnectionOpened );
+        checkConnectionButton.addSelectionListener( new SelectionListener()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                IConnection connection = getTestConnection();
+                CheckNetworkParameterJob job = new CheckNetworkParameterJob( connection );
+                RunnableContextJobAdapter.execute( job, runnableContext );
+                if ( job.getExternalResult().isOK() )
+                {
+                    MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check Network Parameter",
+                        "The connection was established successfully." );
+                }
+            }
+
+
+            public void widgetDefaultSelected( SelectionEvent e )
+            {
+            }
+        } );
+
+        setEnabled();
+    }
+
+
+    /**
+     * Adds the base DN input.
+     * 
+     * @param autoFetchBaseDNs the initial auto fetch base DN's flag
+     * @param baseDN the initial base DN
+     * @param parent the parent
+     */
+    public void addBaseDNInput( boolean autoFetchBaseDNs, String baseDN, Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Group group = BaseWidgetUtils.createGroup( composite, "Base DN", 1 );
+        Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 );
+        GridData gd;
+
+        autoFetchBaseDnsButton = BaseWidgetUtils.createCheckbox( groupComposite, "Get base DNs from Root DSE", 2 );
+        autoFetchBaseDnsButton.setSelection( autoFetchBaseDNs );
+        autoFetchBaseDnsButton.addSelectionListener( this );
+
+        fetchBaseDnsButton = new Button( groupComposite, SWT.PUSH );
+        fetchBaseDnsButton.setText( "Fetch Base DNs" );
+        fetchBaseDnsButton.setEnabled( true );
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.RIGHT;
+        fetchBaseDnsButton.setLayoutData( gd );
+        fetchBaseDnsButton.addSelectionListener( new SelectionListener()
+        {
+
+            public void widgetSelected( SelectionEvent e )
+            {
+                IConnection connection = getTestConnection();
+
+                FetchBaseDNsJob job = new FetchBaseDNsJob( connection );
+                RunnableContextJobAdapter.execute( job, runnableContext );
+                if ( job.getExternalResult().isOK() )
+                {
+                    if ( job.getBaseDNs().length > 0 )
+                    {
+                        String[] baseDNs = job.getBaseDNs();
+                        baseDNCombo.setItems( baseDNs );
+                        baseDNCombo.select( 0 );
+
+                        String msg = "The server returned the following base DNs:";
+                        for ( int i = 0; i < baseDNs.length; i++ )
+                        {
+                            msg += "\n  - " + baseDNs[i];
+                        }
+                        MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Fetch Base DNs", msg );
+                    }
+                    else
+                    {
+                        MessageDialog.openWarning( Display.getDefault().getActiveShell(), "Fetch Base DNs",
+                            "No base DN returned from server. Please enter the base DN manually." );
+                        autoFetchBaseDnsButton.setSelection( false );
+                    }
+                }
+            }
+
+
+            public void widgetDefaultSelected( SelectionEvent e )
+            {
+            }
+        } );
+
+        BaseWidgetUtils.createLabel( groupComposite, "Base DN:", 1 );
+        baseDNCombo = BaseWidgetUtils.createCombo( groupComposite, new String[]
+            { baseDN.toString() }, 0, 2 );
+        baseDNCombo.setText( baseDN.toString() );
+        baseDNCombo.addModifyListener( this );
+
+        setEnabled();
+    }
+
+
+    /**
+     * Adds the limit input.
+     * 
+     * @param countLimit the initial count limit
+     * @param timeLimit the initial time limit
+     * @param aliasesDereferencingMethod the initial aliases dereferencing method
+     * @param referralsHandlingMethod the initial referrals handling method
+     * @param parent the parent
+     */
+    public void addLimitInput( int countLimit, int timeLimit, int aliasesDereferencingMethod,
+        int referralsHandlingMethod, Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
+
+        limitWidget = new LimitWidget( countLimit, timeLimit );
+        limitWidget.createWidget( composite );
+
+        aliasesDereferencingWidget = new AliasesDereferencingWidget( aliasesDereferencingMethod );
+        aliasesDereferencingWidget.createWidget( composite );
+
+        referralsHandlingWidget = new ReferralsHandlingWidget( referralsHandlingMethod );
+        referralsHandlingWidget.createWidget( composite );
+
+        setEnabled();
+    }
+
+
+    /**
+     * Adds the open connection on finish input.
+     * 
+     * @param openConnectionOnFinish the initial value
+     * @param parent the parent
+     */
+    public void addOpenConnectionInput( boolean openConnectionOnFinish, Composite parent )
+    {
+        openConnectionButton = BaseWidgetUtils.createCheckbox( parent, "Open connection on finish", 1 );
+        openConnectionButton.setSelection( openConnectionOnFinish );
+        openConnectionButton.addSelectionListener( this );
+    }
+
+
+    /**
+     * Adds the authentication method input.
+     * 
+     * @param authMethod the initial auth method
+     * @param parent the parent
+     */
+    public void addAuthenticationMethodInput( int authMethod, Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Group group = BaseWidgetUtils.createGroup( composite, "Authentication Method", 1 );
+        Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 );
+
+        anonymousAuthButton = BaseWidgetUtils.createRadiobutton( groupComposite, "Anonymous Authentication", 1 );
+        anonymousAuthButton.setSelection( authMethod == IConnection.AUTH_ANONYMOUS );
+        anonymousAuthButton.addSelectionListener( this );
+
+        simpleAuthButton = BaseWidgetUtils.createRadiobutton( groupComposite, "Simple Authentication", 1 );
+        simpleAuthButton.setSelection( authMethod == IConnection.AUTH_SIMPLE );
+        simpleAuthButton.addSelectionListener( this );
+
+        // saslAuthButton = new Button(authenticationMethodGroup, SWT.RADIO);
+        // saslAuthButton.setText("SASL Authentication");
+        // saslAuthButton.setSelection(authMethod ==
+        // ConnectionParameter.AUTH_SASL);
+        // saslAuthButton.addSelectionListener(this);
+    }
+
+
+    /**
+     * Adds the simple auth input.
+     * 
+     * @param saveBindPassword the initial save bind password flag
+     * @param bindPrincipal the initial bind principal
+     * @param bindPassword the initial bind password
+     * @param parent the parent
+     */
+    public void addSimpleAuthInput( boolean saveBindPassword, String bindPrincipal, String bindPassword,
+        Composite parent )
+    {
+
+        Composite composite2 = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Group group = BaseWidgetUtils.createGroup( composite2, "Authentication Parameter", 1 );
+        Composite composite = BaseWidgetUtils.createColumnContainer( group, 3, 1 );
+
+        BaseWidgetUtils.createLabel( composite, "Bind DN or user:", 1 );
+        if ( isConnectionOpened )
+        {
+            simpleAuthBindPrincipalText = BaseWidgetUtils.createReadonlyText( composite, bindPrincipal, 2 );
+        }
+        else
+        {
+            String[] dnHistory = HistoryUtils.load( BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY );
+            simpleAuthBindPrincipalCombo = BaseWidgetUtils.createCombo( composite, dnHistory, -1, 2 );
+            simpleAuthBindPrincipalCombo.setText( bindPrincipal );
+            simpleAuthBindPrincipalCombo.addModifyListener( this );
+        }
+
+        BaseWidgetUtils.createLabel( composite, "Bind password:", 1 );
+        if ( isConnectionOpened )
+        {
+            simpleAuthBindPasswordText = BaseWidgetUtils.createReadonlyPasswordText( composite, bindPassword, 2 );
+        }
+        else
+        {
+            simpleAuthBindPasswordText = BaseWidgetUtils.createPasswordText( composite, bindPassword, 2 );
+        }
+        simpleAuthBindPasswordText.addModifyListener( this );
+
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        saveSimpleAuthBindPasswordButton = BaseWidgetUtils.createCheckbox( composite, "Save password", 1 );
+        saveSimpleAuthBindPasswordButton.setSelection( saveBindPassword );
+        saveSimpleAuthBindPasswordButton.addSelectionListener( this );
+
+        checkSimpleAuthButton = new Button( composite, SWT.PUSH );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalAlignment = SWT.RIGHT;
+        checkSimpleAuthButton.setLayoutData( gd );
+        checkSimpleAuthButton.setText( "Check Authentication" );
+        checkSimpleAuthButton.setEnabled( false );
+        checkSimpleAuthButton.addSelectionListener( new SelectionListener()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                IConnection connection = getTestConnection();
+                CheckBindJob job = new CheckBindJob( connection );
+                RunnableContextJobAdapter.execute( job, runnableContext );
+                if ( job.getExternalResult().isOK() )
+                {
+                    MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check Authentication",
+                        "The authentication was successful." );
+                }
+            }
+
+
+            public void widgetDefaultSelected( SelectionEvent e )
+            {
+            }
+        } );
+        setEnabled();
+    }
+
+
+    /**
+     * Fires a connection page modified event when then page was modified.
+     */
+    private void fireConnectionPageModified()
+    {
+        for ( Iterator<ConnectionPageModifyListener> it = listenerList.iterator(); it.hasNext(); )
+        {
+            it.next().connectionPageModified();
+        }
+    }
+
+
+    /**
+     * Sets the enabled/disabled state of all widgets depending on the connection state.
+     */
+    private void setEnabled()
+    {
+
+        if ( isConnectionOpened )
+        {
+            if ( encryptionMethodCombo != null && checkConnectionButton != null )
+            {
+                encryptionMethodCombo.setEnabled( false );
+                checkConnectionButton.setEnabled( false );
+            }
+
+            if ( baseDNCombo != null && autoFetchBaseDnsButton != null )
+            {
+                autoFetchBaseDnsButton.setEnabled( false );
+                baseDNCombo.setEnabled( false );
+                fetchBaseDnsButton.setEnabled( false );
+            }
+
+            if ( anonymousAuthButton != null && simpleAuthButton != null )
+            {
+                anonymousAuthButton.setEnabled( false );
+                simpleAuthButton.setEnabled( false );
+            }
+            if ( saveSimpleAuthBindPasswordButton != null && saveSimpleAuthBindPasswordButton != null )
+            {
+                saveSimpleAuthBindPasswordButton.setEnabled( false );
+                checkSimpleAuthButton.setEnabled( false );
+            }
+        }
+        else
+        {
+            if ( hostCombo != null && portCombo != null && checkConnectionButton != null )
+            {
+                if ( !hostCombo.getText().equals( "" ) && !hostCombo.getText().equals( "" ) )
+                {
+                    checkConnectionButton.setEnabled( true );
+                }
+                else
+                {
+                    checkConnectionButton.setEnabled( false );
+                }
+            }
+
+            if ( baseDNCombo != null && autoFetchBaseDnsButton != null )
+            {
+                if ( autoFetchBaseDnsButton.getSelection() )
+                {
+                    baseDNCombo.setEnabled( false );
+                }
+                else
+                {
+                    baseDNCombo.setEnabled( true );
+                }
+            }
+            if ( simpleAuthBindPrincipalCombo != null && simpleAuthBindPasswordText != null
+                && saveSimpleAuthBindPasswordButton != null )
+            {
+                boolean simpleAuthSelected = simpleAuthButton == null || simpleAuthButton.getSelection();
+                simpleAuthBindPrincipalCombo.setEnabled( simpleAuthSelected );
+                simpleAuthBindPasswordText.setEnabled( saveSimpleAuthBindPasswordButton.getSelection()
+                    && simpleAuthSelected );
+                saveSimpleAuthBindPasswordButton.setEnabled( simpleAuthSelected );
+                checkSimpleAuthButton.setEnabled( saveSimpleAuthBindPasswordButton.getSelection()
+                    && !simpleAuthBindPrincipalCombo.getText().equals( "" )
+                    && !simpleAuthBindPasswordText.getText().equals( "" ) && simpleAuthSelected );
+            }
+        }
+    }
+
+
+    /**
+     * Validates the connection parameters after each modification.
+     */
+    private void validate()
+    {
+        String message = null;
+        String errorMessage = null;
+
+        boolean simpleAuthSelected = simpleAuthButton == null || simpleAuthButton.getSelection();
+
+        if ( baseDNCombo != null && baseDNCombo.isVisible() )
+        {
+            try
+            {
+                new DN( baseDNCombo.getText() );
+            }
+            catch ( NameException e )
+            {
+                message = "Please enter a valid base DN.";
+            }
+        }
+        if ( simpleAuthBindPasswordText != null && simpleAuthSelected && simpleAuthBindPasswordText.isVisible() )
+        {
+            if ( saveSimpleAuthBindPasswordButton.getSelection() && "".equals( simpleAuthBindPasswordText.getText() ) )
+            {
+                message = "Please enter a bind password.";
+            }
+        }
+        if ( simpleAuthBindPrincipalCombo != null && simpleAuthSelected && simpleAuthBindPrincipalCombo.isVisible() )
+        {
+            if ( "".equals( simpleAuthBindPrincipalCombo.getText() ) )
+            {
+                message = "Please enter a bind DN or user.";
+            }
+            else
+            {
+                // every bind principal is accepted
+            }
+        }
+        if ( portCombo != null && portCombo.isVisible() )
+        {
+            if ( "".equals( portCombo.getText() ) )
+            {
+                message = "Please enter a port. The default LDAP port is 389.";
+            }
+        }
+        if ( hostCombo != null && hostCombo.isVisible() )
+        {
+            if ( "".equals( hostCombo.getText() ) )
+            {
+                message = "Please enter a hostname.";
+            }
+        }
+        if ( nameText != null && nameText.isVisible() )
+        {
+            if ( "".equals( nameText.getText() ) )
+            {
+                message = "Please enter a connection name.";
+            }
+            if ( BrowserCorePlugin.getDefault().getConnectionManager().getConnection( nameText.getText() ) != null
+                && BrowserCorePlugin.getDefault().getConnectionManager().getConnection( nameText.getText() ) != listenerList
+                    .get( 0 ).getRealConnection() )
+            {
+                errorMessage = "A connection named '" + nameText.getText() + "' already exists.";
+            }
+        }
+
+        for ( Iterator<ConnectionPageModifyListener> it = listenerList.iterator(); it.hasNext(); )
+        {
+            ConnectionPageModifyListener listener = it.next();
+            listener.setMessage( message );
+            listener.setErrorMessage( errorMessage );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void modifyText( ModifyEvent e )
+    {
+        setEnabled();
+        validate();
+        fireConnectionPageModified();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void widgetSelected( SelectionEvent e )
+    {
+        setEnabled();
+        validate();
+        fireConnectionPageModified();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void widgetDefaultSelected( SelectionEvent e )
+    {
+        setEnabled();
+        validate();
+        fireConnectionPageModified();
+    }
+
+
+    /**
+     * Gets a temporary connection with all conection parameter 
+     * entered in this page. 
+     *
+     * @return a test connection
+     */
+    public IConnection getTestConnection()
+    {
+        if ( getAuthenticationMethod() == IConnection.AUTH_ANONYMOUS )
+        {
+            Connection conn;
+            try
+            {
+                conn = new Connection( null, getHostName(), getPort(), getEncyrptionMethod(), isAutoFetchBaseDns(),
+                    new DN( getBaseDN() ), getCountLimit(), getTimeLimit(), getAliasesDereferencingMethod(),
+                    getReferralsHandlingMethod(), IConnection.AUTH_ANONYMOUS, null, null );
+            }
+            catch ( NameException e )
+            {
+                conn = null;
+            }
+            return conn;
+        }
+        else if ( getAuthenticationMethod() == IConnection.AUTH_SIMPLE )
+        {
+            Connection conn;
+            try
+            {
+                conn = new Connection( null, getHostName(), getPort(), getEncyrptionMethod(), isAutoFetchBaseDns(),
+                    new DN( getBaseDN() ), getCountLimit(), getTimeLimit(), getAliasesDereferencingMethod(),
+                    getReferralsHandlingMethod(), IConnection.AUTH_SIMPLE, getSimpleAuthBindPrincipal(),
+                    getSimpleAuthBindPassword() );
+            }
+            catch ( NameException e )
+            {
+                conn = null;
+            }
+            return conn;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * Saved the dialog settings. The curren values of host, port and bind principal are added
+     * to the history.
+     */
+    public void saveDialogSettings()
+    {
+        if ( !isConnectionOpened )
+        {
+            if ( hostCombo != null )
+            {
+                HistoryUtils.save( BrowserCommonConstants.DIALOGSETTING_KEY_HOST_HISTORY, hostCombo.getText() );
+            }
+            if ( portCombo != null )
+            {
+                HistoryUtils.save( BrowserCommonConstants.DIALOGSETTING_KEY_PORT_HISTORY, portCombo.getText() );
+            }
+            if ( simpleAuthBindPrincipalCombo != null )
+            {
+                HistoryUtils.save( BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY, simpleAuthBindPrincipalCombo
+                    .getText() );
+            }
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionUniversalListener.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionUniversalListener.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionUniversalListener.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,148 @@
+/*
+ *  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.common.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EntryUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+
+
+/**
+ * The ConnectionUniversalListener manages all events for the connection widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionUniversalListener implements ConnectionUpdateListener, EntryUpdateListener,
+    SearchUpdateListener, BookmarkUpdateListener
+{
+
+    /** The table viewer */
+    protected TableViewer viewer;
+
+
+    /**
+     * Creates a new instance of ConnectionUniversalListener.
+     *
+     * @param viewer the table viewer
+     */
+    public ConnectionUniversalListener( TableViewer viewer )
+    {
+        this.viewer = viewer;
+
+        EventRegistry.addConnectionUpdateListener( this );
+        EventRegistry.addEntryUpdateListener( this );
+        EventRegistry.addSearchUpdateListener( this );
+        EventRegistry.addBookmarkUpdateListener( this );
+    }
+
+
+    /**
+     * Disposes this universal listener.
+     */
+    public void dispose()
+    {
+        if ( viewer != null )
+        {
+            EventRegistry.removeConnectionUpdateListener( this );
+            EventRegistry.removeEntryUpdateListener( this );
+            EventRegistry.removeSearchUpdateListener( this );
+            EventRegistry.removeBookmarkUpdateListener( this );
+            viewer = null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation refreshes the viewer. If a new connection was added
+     * this connection is selected.
+     */
+    public void connectionUpdated( ConnectionUpdateEvent connectionUpdateEvent )
+    {
+        if ( viewer != null )
+        {
+            viewer.refresh();
+            if ( connectionUpdateEvent.getDetail() == ConnectionUpdateEvent.CONNECTION_ADDED )
+            {
+                viewer.setSelection( new StructuredSelection( connectionUpdateEvent.getConnection() ) );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation refreshes the viewer.
+     */
+    public void entryUpdated( EntryModificationEvent event )
+    {
+        if ( viewer != null )
+        {
+            viewer.refresh();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation refreshes the viewer.
+     */
+    public void searchUpdated( SearchUpdateEvent searchUpdateEvent )
+    {
+        if ( viewer != null )
+        {
+            viewer.refresh();
+
+            // select the right connection
+            ISearch search = searchUpdateEvent.getSearch();
+            viewer.setSelection( new StructuredSelection( search.getConnection() ), true );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation refreshes the viewer.
+     */
+    public void bookmarkUpdated( BookmarkUpdateEvent bookmarkUpdateEvent )
+    {
+        if ( viewer != null )
+        {
+            viewer.refresh();
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionWidget.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionWidget.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionWidget.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionWidget.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,213 @@
+/*
+ *  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.common.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.common.widgets.ViewFormWidget;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.TableViewer;
+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.Table;
+import org.eclipse.ui.IActionBars;
+
+
+/**
+ * The ConnectionWidget is a reusable widget that displays all connections
+ * in a table viewer. It is used by 
+ * {@link org.apache.directory.ldapstudio.browser.ui.views.connection.ConnectionView}, 
+ * {@link org.apache.directory.ldapstudio.browser.common.dialogs.SelectConnectionDialog} and 
+ * {@link org.apache.directory.ldapstudio.browser.common.dialogs.SelectReferralConnectionDialog}. 
+ * 
+ * It includes a content and label provider to display connections with a nice icon.
+ * 
+ * Further is provides a context menu and a local toolbar with actions to
+ * add, modify, delete, open and close connections.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionWidget extends ViewFormWidget
+{
+
+    /** The widget's configuration with the content provider, label provider and menu manager */
+    private ConnectionConfiguration configuration;
+
+    /** The action bars */
+    private IActionBars actionBars;
+
+    /** The table widget used by the table viewer */
+    private Table table;
+
+    /** The table viewer */
+    private TableViewer viewer;
+
+
+    /**
+     * Creates a new instance of ConnectionWidget.
+     *
+     * @param configuration the configuration
+     * @param actionBars the action bars
+     */
+    public ConnectionWidget( ConnectionConfiguration configuration, IActionBars actionBars )
+    {
+        this.configuration = configuration;
+        this.actionBars = actionBars;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createWidget( Composite parent )
+    {
+        if ( actionBars == null )
+        {
+            super.createWidget( parent );
+        }
+        else
+        {
+            createContent( parent );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IToolBarManager getToolBarManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getToolBarManager();
+        }
+        else
+        {
+            return actionBars.getToolBarManager();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IMenuManager getMenuManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getMenuManager();
+
+        }
+        else
+        {
+            return actionBars.getMenuManager();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IMenuManager getContextMenuManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getContextMenuManager();
+        }
+        else
+        {
+            return configuration.getContextMenuManager( viewer );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createContent( Composite parent )
+    {
+
+        table = new Table( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 450;
+        data.heightHint = 250;
+        table.setLayoutData( data );
+        viewer = new TableViewer( table );
+
+        // setup providers
+        viewer.setContentProvider( configuration.getContentProvider( viewer ) );
+        viewer.setLabelProvider( configuration.getLabelProvider( viewer ) );
+
+        return table;
+    }
+
+
+    /**
+     * Sets the input to the table viewer.
+     *
+     * @param input the input
+     */
+    public void setInput( Object input )
+    {
+        viewer.setInput( input );
+    }
+
+
+    /**
+     * Sets focus to the table viewer.
+     */
+    public void setFocus()
+    {
+        viewer.getTable().setFocus();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        if ( viewer != null )
+        {
+            configuration.dispose();
+            configuration = null;
+
+            table.dispose();
+            table = null;
+            viewer = null;
+        }
+    }
+
+
+    /**
+     * Gets the table viewer.
+     * 
+     * @return the table viewer
+     */
+    public TableViewer getViewer()
+    {
+        return viewer;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/AbstractOpenEditorAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/AbstractOpenEditorAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/AbstractOpenEditorAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/AbstractOpenEditorAction.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,219 @@
+/*
+ *  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.common.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+
+
+/**
+ * The base class for all value editor actions of the entry editor widget.
+ * It manages activation and closing of value editors. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractOpenEditorAction extends BrowserAction implements FocusListener, KeyListener
+{
+
+    /** The action group. */
+    protected EntryEditorWidgetActionGroup actionGroup;
+
+    /** The value editor manager. */
+    protected ValueEditorManager valueEditorManager;
+
+    /** The viewer. */
+    protected TreeViewer viewer;
+
+    /** The cell editor. */
+    protected CellEditor cellEditor;
+
+
+    /**
+     * Creates a new instance of AbstractOpenEditorAction.
+     * 
+     * @param viewer the viewer
+     * @param actionGroup the action group
+     * @param valueEditorManager the value editor manager
+     */
+    protected AbstractOpenEditorAction( TreeViewer viewer, EntryEditorWidgetActionGroup actionGroup,
+        ValueEditorManager valueEditorManager )
+    {
+        this.viewer = viewer;
+        this.actionGroup = actionGroup;
+        this.valueEditorManager = valueEditorManager;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        valueEditorManager = null;
+        actionGroup = null;
+        viewer = null;
+        cellEditor = null;
+        super.dispose();
+    }
+
+
+    /**
+     * Gets the cell editor.
+     * 
+     * @return the cell editor
+     */
+    public CellEditor getCellEditor()
+    {
+        return cellEditor;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        activateEditor();
+    }
+
+
+    /**
+     * Activates the editor.
+     */
+    private void activateEditor()
+    {
+
+        if ( !viewer.isCellEditorActive()
+            && getSelectedValues().length == 1
+            && getSelectedAttributes().length == 0
+            && viewer.getCellModifier().canModify( getSelectedValues()[0],
+                EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME ) )
+        {
+
+            // set cell editor to viewer
+            viewer.getCellEditors()[EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX] = cellEditor;
+
+            // add listener for end of editing
+            if ( cellEditor.getControl() != null )
+            {
+                cellEditor.getControl().addFocusListener( this );
+                cellEditor.getControl().addKeyListener( this );
+            }
+
+            // deactivate global actions
+            if ( actionGroup != null )
+            {
+                actionGroup.deactivateGlobalActionHandlers();
+            }
+
+            // start editing
+            viewer.editElement( getSelectedValues()[0], EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX );
+
+            if ( !viewer.isCellEditorActive() )
+            {
+                editorClosed();
+            }
+        }
+        else
+        {
+            valueEditorManager.setUserSelectedValueEditor( null );
+        }
+    }
+
+
+    /**
+     * Editor closed.
+     */
+    private void editorClosed()
+    {
+
+        // remove cell editors from viewer to prevend auto-editing
+        for ( int i = 0; i < viewer.getCellEditors().length; i++ )
+        {
+            viewer.getCellEditors()[i] = null;
+        }
+
+        // remove listener
+        if ( cellEditor.getControl() != null )
+        {
+            cellEditor.getControl().removeFocusListener( this );
+            cellEditor.getControl().removeKeyListener( this );
+        }
+
+        // activate global actions
+        if ( actionGroup != null )
+        {
+            actionGroup.activateGlobalActionHandlers();
+        }
+
+        // reset custom value editor and set selection to notify all
+        // openeditoractions to update their enabled state.
+        valueEditorManager.setUserSelectedValueEditor( null );
+        viewer.setSelection( viewer.getSelection() );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void focusGained( FocusEvent e )
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void focusLost( FocusEvent e )
+    {
+        editorClosed();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void keyPressed( KeyEvent e )
+    {
+        if ( e.character == SWT.ESC && e.stateMask == SWT.NONE )
+        {
+            e.doit = false;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void keyReleased( KeyEvent e )
+    {
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EditAttributeDescriptionAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EditAttributeDescriptionAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EditAttributeDescriptionAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EditAttributeDescriptionAction.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,142 @@
+/*
+ *  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.common.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction;
+import org.apache.directory.ldapstudio.browser.common.actions.DeleteAction;
+import org.apache.directory.ldapstudio.browser.common.actions.proxy.EntryEditorActionProxy;
+import org.apache.directory.ldapstudio.browser.common.wizards.AttributeWizard;
+import org.apache.directory.ldapstudio.browser.core.jobs.RenameValuesJob;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * This Action is used to edit an attribute description within the entry edtitor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EditAttributeDescriptionAction extends BrowserAction
+{
+
+    /** To avoid duplicate implementations of the isEnabled() code we use a delete action */
+    private EntryEditorActionProxy deleteActionProxy;
+
+
+    /**
+     * Creates a new instance of EditAttributeDescriptionAction.
+     * 
+     * @param viewer the viewer
+     */
+    public EditAttributeDescriptionAction( Viewer viewer )
+    {
+        deleteActionProxy = new EntryEditorActionProxy( viewer, new DeleteAction() );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getCommandId()
+    {
+        return BrowserCommonConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ImageDescriptor getImageDescriptor()
+    {
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getText()
+    {
+        return "Edit Attribute Description";
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isEnabled()
+    {
+        return deleteActionProxy.getAction().isEnabled();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void run()
+    {
+        if ( getSelectedAttributes().length == 1 )
+        {
+            renameValues( getSelectedAttributes()[0].getValues() );
+        }
+        else if ( getSelectedValues().length > 0 )
+        {
+            renameValues( getSelectedValues() );
+        }
+    }
+
+
+    /**
+     * Rename the given values.
+     * 
+     * @param values the values
+     */
+    private void renameValues( final IValue[] values )
+    {
+        AttributeWizard wizard = new AttributeWizard( "Edit Attribute Description", true, false, values[0]
+            .getAttribute().getDescription(), values[0].getAttribute().getEntry() );
+        WizardDialog dialog = new WizardDialog( Display.getDefault().getActiveShell(), wizard );
+        dialog.setBlockOnOpen( true );
+        dialog.create();
+        if ( dialog.open() == Dialog.OK )
+        {
+            String newAttributeName = wizard.getAttributeDescription();
+            if ( newAttributeName != null && !"".equals( newAttributeName )
+                && !newAttributeName.equals( values[0].getAttribute().getDescription() ) )
+            {
+                new RenameValuesJob( values[0].getAttribute().getEntry(), values, newAttributeName ).execute();
+            }
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidget.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidget.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidget.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidget.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,211 @@
+/*
+ *  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.common.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.common.widgets.ViewFormWidget;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+
+
+/**
+ * The EntryEditorWidget is a reusable widget to display and edit the attributes of an entry.
+ * It is used by 
+ * {@link org.apache.directory.ldapstudio.browser.ui.editors.entry.EntryEditor}, 
+ * {@link org.apache.directory.ldapstudio.browser.common.dialogs.MultivaluedDialog}, 
+ * {@link org.apache.directory.ldapstudio.browser.common.dialogs.LdifEntryEditorDialog} and 
+ * {@link org.apache.directory.ldapstudio.browser.common.wizards.NewEntryAttributesWizardPage}. 
+ * 
+ * It provides a context menu and a local toolbar with actions to
+ * manage attributes. Further there is an instant search feature to filter 
+ * the visible attributes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidget extends ViewFormWidget
+{
+
+    /** The configuration. */
+    private EntryEditorWidgetConfiguration configuration;
+
+    /** The quick filter widget. */
+    private EntryEditorWidgetQuickFilterWidget quickFilterWidget;
+
+    /** The tree. */
+    private Tree tree;
+
+    /** The viewer. */
+    private TreeViewer viewer;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidget.
+     * 
+     * @param configuration the configuration
+     */
+    public EntryEditorWidget( EntryEditorWidgetConfiguration configuration )
+    {
+        this.configuration = configuration;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createContent( Composite parent )
+    {
+        quickFilterWidget = new EntryEditorWidgetQuickFilterWidget( configuration.getFilter(), this );
+        quickFilterWidget.createComposite( parent );
+
+        // create tree widget and viewer
+        tree = new Tree( parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
+            | SWT.HIDE_SELECTION );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 450;
+        data.heightHint = 250;
+        tree.setLayoutData( data );
+        tree.setHeaderVisible( true );
+        tree.setLinesVisible( true );
+        viewer = new TreeViewer( tree );
+        viewer.setUseHashlookup( true );
+
+        // set tree columns
+        for ( int i = 0; i < EntryEditorWidgetTableMetadata.COLUM_NAMES.length; i++ )
+        {
+            TreeColumn column = new TreeColumn( tree, SWT.LEFT, i );
+            column.setText( EntryEditorWidgetTableMetadata.COLUM_NAMES[i] );
+            column.setWidth( 200 );
+            column.setResizable( true );
+
+        }
+        viewer.setColumnProperties( EntryEditorWidgetTableMetadata.COLUM_NAMES );
+        tree.addControlListener( new ControlAdapter()
+        {
+            public void controlResized( ControlEvent e )
+            {
+                if ( tree.getClientArea().width > 0 )
+                {
+                    int width = tree.getClientArea().width - 2 * tree.getBorderWidth();
+                    if ( tree.getVerticalBar().isVisible() )
+                    {
+                        width -= tree.getVerticalBar().getSize().x;
+                    }
+                    tree.getColumn( EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX ).setWidth(
+                        width - tree.getColumn( EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX ).getWidth() );
+                }
+            }
+        } );
+
+        // setup sorter, filter and layout
+        configuration.getSorter().connect( viewer );
+        configuration.getFilter().connect( viewer );
+        configuration.getPreferences().connect( viewer );
+
+        // setup providers
+        viewer.setContentProvider( configuration.getContentProvider( this ) );
+        viewer.setLabelProvider( configuration.getLabelProvider( viewer ) );
+
+        // set table cell editors
+        viewer.setCellModifier( configuration.getCellModifier( viewer ) );
+        CellEditor[] editors = new CellEditor[EntryEditorWidgetTableMetadata.COLUM_NAMES.length];
+        viewer.setCellEditors( editors );
+
+        return tree;
+
+    }
+
+
+    /**
+     * Sets the focus to the tree viewer.
+     */
+    public void setFocus()
+    {
+        viewer.getTree().setFocus();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        if ( viewer != null )
+        {
+            configuration.dispose();
+            configuration = null;
+
+            if ( quickFilterWidget != null )
+            {
+                quickFilterWidget.dispose();
+                quickFilterWidget = null;
+            }
+
+            tree.dispose();
+            tree = null;
+            viewer = null;
+        }
+
+        super.dispose();
+    }
+
+
+    /**
+     * Gets the viewer.
+     * 
+     * @return the viewer
+     */
+    public TreeViewer getViewer()
+    {
+        return viewer;
+    }
+
+
+    /**
+     * Gets the quick filter widget.
+     * 
+     * @return the quick filter widget
+     */
+    public EntryEditorWidgetQuickFilterWidget getQuickFilterWidget()
+    {
+        return quickFilterWidget;
+    }
+
+
+    /**
+     * Enables or disables this widget.
+     *
+     * @param enabled true to enable this widget, false to disable this widget
+     */
+    public void setEnabled( boolean enabled )
+    {
+        tree.setEnabled( enabled );
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetActionGroup.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetActionGroup.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetActionGroup.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetActionGroup.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,442 @@
+/*
+ *  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.common.widgets.entryeditor;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.actions.CopyAction;
+import org.apache.directory.ldapstudio.browser.common.actions.DeleteAction;
+import org.apache.directory.ldapstudio.browser.common.actions.NewValueAction;
+import org.apache.directory.ldapstudio.browser.common.actions.PasteAction;
+import org.apache.directory.ldapstudio.browser.common.actions.PropertiesAction;
+import org.apache.directory.ldapstudio.browser.common.actions.SelectAllAction;
+import org.apache.directory.ldapstudio.browser.common.actions.ShowRawValuesAction;
+import org.apache.directory.ldapstudio.browser.common.actions.ValueEditorPreferencesAction;
+import org.apache.directory.ldapstudio.browser.common.actions.proxy.BrowserActionProxy;
+import org.apache.directory.ldapstudio.browser.common.actions.proxy.EntryEditorActionProxy;
+import org.apache.directory.ldapstudio.valueeditors.IValueEditor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.commands.ICommandService;
+
+
+/**
+ * The EntryEditorWidgetActionGroup manages all actions of the entry editor widget.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetActionGroup
+{
+
+    /** The open sort dialog action. */
+    protected OpenSortDialogAction openSortDialogAction;
+
+    /** The show raw values action. */
+    protected ShowRawValuesAction showRawValuesAction;
+
+    /** The show quick filter action. */
+    protected ShowQuickFilterAction showQuickFilterAction;
+
+    /** The open default editor action. */
+    protected EntryEditorActionProxy openDefaultValueEditorActionProxy;
+
+    /** The open best editor action. */
+    protected EntryEditorActionProxy openBestValueEditorActionProxy;
+
+    /** The open editor actions. */
+    protected EntryEditorActionProxy[] openValueEditorActionProxies;
+
+    /** The open value editor preferences action. */
+    protected ValueEditorPreferencesAction openValueEditorPreferencesAction;
+
+    /** The Constant newValueAction. */
+    protected final static String newValueAction = "newValueAction";
+
+    /** The Constant copyAction. */
+    protected final static String copyAction = "copyAction";
+
+    /** The Constant pasteAction. */
+    protected final static String pasteAction = "pasteAction";
+
+    /** The Constant deleteAction. */
+    protected final static String deleteAction = "deleteAction";
+
+    /** The Constant selectAllAction. */
+    protected final static String selectAllAction = "selectAllAction";
+
+    /** The Constant propertyDialogAction. */
+    protected final static String propertyDialogAction = "propertyDialogAction";
+
+    /** The entry editor action map. */
+    protected Map<String, EntryEditorActionProxy> entryEditorActionMap;
+
+    /** The action bars. */
+    protected IActionBars actionBars;
+
+    /** The main widget. */
+    private EntryEditorWidget mainWidget;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetActionGroup.
+     * 
+     * @param mainWidget the main widget
+     * @param configuration the configuration
+     */
+    public EntryEditorWidgetActionGroup( EntryEditorWidget mainWidget, EntryEditorWidgetConfiguration configuration )
+    {
+        this.mainWidget = mainWidget;
+
+        entryEditorActionMap = new HashMap<String, EntryEditorActionProxy>();
+        TreeViewer viewer = mainWidget.getViewer();
+
+        openSortDialogAction = new OpenSortDialogAction( configuration.getPreferences() );
+        showRawValuesAction = new ShowRawValuesAction();
+        showQuickFilterAction = new ShowQuickFilterAction( mainWidget.getQuickFilterWidget() );
+
+        openBestValueEditorActionProxy = new EntryEditorActionProxy( viewer, new OpenBestEditorAction( viewer, this,
+            configuration.getValueEditorManager( viewer ) ) );
+        openDefaultValueEditorActionProxy = new EntryEditorActionProxy( viewer, new OpenDefaultEditorAction( viewer,
+            openBestValueEditorActionProxy, false ) );
+        IValueEditor[] valueEditors = configuration.getValueEditorManager( viewer ).getAllValueEditors();
+        openValueEditorActionProxies = new EntryEditorActionProxy[valueEditors.length];
+        for ( int i = 0; i < openValueEditorActionProxies.length; i++ )
+        {
+            openValueEditorActionProxies[i] = new EntryEditorActionProxy( viewer, new OpenEditorAction( viewer, this,
+                configuration.getValueEditorManager( viewer ), valueEditors[i] ) );
+        }
+        openValueEditorPreferencesAction = new ValueEditorPreferencesAction();
+
+        entryEditorActionMap.put( newValueAction, new EntryEditorActionProxy( viewer, new NewValueAction() ) );
+
+        entryEditorActionMap.put( pasteAction, new EntryEditorActionProxy( viewer, new PasteAction() ) );
+        entryEditorActionMap.put( copyAction, new EntryEditorActionProxy( viewer, new CopyAction(
+            ( BrowserActionProxy ) entryEditorActionMap.get( pasteAction ) ) ) );
+        entryEditorActionMap.put( deleteAction, new EntryEditorActionProxy( viewer, new DeleteAction() ) );
+        entryEditorActionMap.put( selectAllAction, new EntryEditorActionProxy( viewer, new SelectAllAction( viewer ) ) );
+
+        entryEditorActionMap.put( propertyDialogAction, new EntryEditorActionProxy( viewer, new PropertiesAction() ) );
+    }
+
+
+    /**
+     * Disposes this action group.
+     */
+    public void dispose()
+    {
+        if ( mainWidget != null )
+        {
+            openSortDialogAction = null;
+            showQuickFilterAction.dispose();
+            showQuickFilterAction = null;
+            showRawValuesAction = null;
+
+            openDefaultValueEditorActionProxy.dispose();
+            openDefaultValueEditorActionProxy = null;
+            openBestValueEditorActionProxy.dispose();
+            openBestValueEditorActionProxy = null;
+            for ( int i = 0; i < openValueEditorActionProxies.length; i++ )
+            {
+                openValueEditorActionProxies[i].dispose();
+                openValueEditorActionProxies[i] = null;
+            }
+            openValueEditorPreferencesAction = null;
+
+            for ( Iterator it = entryEditorActionMap.keySet().iterator(); it.hasNext(); )
+            {
+                String key = ( String ) it.next();
+                EntryEditorActionProxy action = ( EntryEditorActionProxy ) entryEditorActionMap.get( key );
+                action.dispose();
+                action = null;
+                it.remove();
+            }
+            entryEditorActionMap.clear();
+            entryEditorActionMap = null;
+
+            actionBars = null;
+            mainWidget = null;
+        }
+    }
+
+
+    /**
+     * Enables global action handlers.
+     * 
+     * @param actionBars the action bars
+     */
+    public void enableGlobalActionHandlers( IActionBars actionBars )
+    {
+        this.actionBars = actionBars;
+        activateGlobalActionHandlers();
+    }
+
+
+    /**
+     * Fill the tool bar.
+     * 
+     * @param toolBarManager the tool bar manager
+     */
+    public void fillToolBar( IToolBarManager toolBarManager )
+    {
+
+        toolBarManager.add( ( IAction ) entryEditorActionMap.get( newValueAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( ( IAction ) entryEditorActionMap.get( deleteAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( showQuickFilterAction );
+        toolBarManager.update( true );
+
+    }
+
+
+    /**
+     * Fills the menu.
+     * 
+     * @param menuManager the menu manager
+     */
+    public void fillMenu( IMenuManager menuManager )
+    {
+        menuManager.add( openSortDialogAction );
+        menuManager.add( showRawValuesAction );
+        menuManager.addMenuListener( new IMenuListener()
+        {
+            public void menuAboutToShow( IMenuManager manager )
+            {
+                showRawValuesAction.setChecked( BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+                    BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES ) );
+            }
+        } );
+    }
+
+
+    /**
+     * Fills the context menu. Adds a menu listener to the given menu manager
+     * to fill the context menu whenever it pops up.
+     * 
+     * @param menuManager the menu manager
+     */
+    public void fillContextMenu( IMenuManager menuManager )
+    {
+        menuManager.setRemoveAllWhenShown( true );
+        menuManager.addMenuListener( new IMenuListener()
+        {
+            public void menuAboutToShow( IMenuManager manager )
+            {
+                contextMenuAboutToShow( manager );
+            }
+        } );
+    }
+
+
+    /**
+     * Fills the context menu.
+     * 
+     * @param menuManager the menu manager
+     */
+    protected void contextMenuAboutToShow( IMenuManager menuManager )
+    {
+        // new
+        menuManager.add( ( IAction ) entryEditorActionMap.get( newValueAction ) );
+        menuManager.add( new Separator() );
+
+        // copy, paste, delete
+        menuManager.add( ( IAction ) entryEditorActionMap.get( copyAction ) );
+        menuManager.add( ( IAction ) entryEditorActionMap.get( pasteAction ) );
+        menuManager.add( ( IAction ) entryEditorActionMap.get( deleteAction ) );
+        menuManager.add( ( IAction ) entryEditorActionMap.get( selectAllAction ) );
+        menuManager.add( new Separator() );
+
+        // edit
+        addEditMenu( menuManager );
+        menuManager.add( new Separator() );
+
+        // properties
+        menuManager.add( ( IAction ) entryEditorActionMap.get( propertyDialogAction ) );
+    }
+
+
+    /**
+     * Adds the value editors to the menu.
+     * 
+     * @param menuManager the menu manager
+     */
+    protected void addEditMenu( IMenuManager menuManager )
+    {
+        menuManager.add( openDefaultValueEditorActionProxy );
+        MenuManager editorMenuManager = new MenuManager( "Edit Value With" );
+        if ( openBestValueEditorActionProxy.isEnabled() )
+        {
+            editorMenuManager.add( openBestValueEditorActionProxy );
+            editorMenuManager.add( new Separator() );
+        }
+        for ( int i = 0; i < openValueEditorActionProxies.length; i++ )
+        {
+            if ( openValueEditorActionProxies[i].isEnabled()
+                && ( ( OpenEditorAction ) openValueEditorActionProxies[i].getAction() ).getValueEditor().getClass() != ( ( OpenBestEditorAction ) openBestValueEditorActionProxy
+                    .getAction() ).getBestValueEditor().getClass() )
+            {
+                editorMenuManager.add( openValueEditorActionProxies[i] );
+            }
+        }
+        editorMenuManager.add( new Separator() );
+        editorMenuManager.add( openValueEditorPreferencesAction );
+        menuManager.add( editorMenuManager );
+    }
+
+
+    /**
+     * Activates global action handlers.
+     */
+    public void activateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), ( IAction ) entryEditorActionMap
+                .get( copyAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), ( IAction ) entryEditorActionMap
+                .get( pasteAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), ( IAction ) entryEditorActionMap
+                .get( deleteAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.SELECT_ALL.getId(), ( IAction ) entryEditorActionMap
+                .get( selectAllAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), ( IAction ) entryEditorActionMap
+                .get( propertyDialogAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.FIND.getId(), showQuickFilterAction ); // IWorkbenchActionDefinitionIds.FIND_REPLACE
+
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction da = ( IAction ) entryEditorActionMap.get( deleteAction );
+                da.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.delete" );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( new ActionHandler( da ) );
+
+                IAction ca = ( IAction ) entryEditorActionMap.get( copyAction );
+                ca.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.copy" );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( new ActionHandler( ca ) );
+
+                IAction pa = ( IAction ) entryEditorActionMap.get( pasteAction );
+                pa.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.paste" );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( new ActionHandler( pa ) );
+
+                showQuickFilterAction.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.find" );
+                commandService.getCommand( showQuickFilterAction.getActionDefinitionId() ).setHandler(
+                    new ActionHandler( showQuickFilterAction ) );
+
+                IAction pda = ( IAction ) entryEditorActionMap.get( propertyDialogAction );
+                pda.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.properties" );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( new ActionHandler( pda ) );
+            }
+        }
+
+        if ( commandService != null )
+        {
+            IAction nva = ( IAction ) entryEditorActionMap.get( newValueAction );
+            commandService.getCommand( nva.getActionDefinitionId() ).setHandler( new ActionHandler( nva ) );
+            commandService.getCommand( openDefaultValueEditorActionProxy.getActionDefinitionId() ).setHandler(
+                new ActionHandler( openDefaultValueEditorActionProxy ) );
+        }
+
+    }
+
+
+    /**
+     * Deactivates global action handlers.
+     */
+    public void deactivateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.SELECT_ALL.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.FIND.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), null );
+
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction da = ( IAction ) entryEditorActionMap.get( deleteAction );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( null );
+
+                IAction ca = ( IAction ) entryEditorActionMap.get( copyAction );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( null );
+
+                IAction pa = ( IAction ) entryEditorActionMap.get( pasteAction );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( null );
+
+                commandService.getCommand( showQuickFilterAction.getActionDefinitionId() ).setHandler( null );
+
+                IAction pda = ( IAction ) entryEditorActionMap.get( propertyDialogAction );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( null );
+            }
+        }
+
+        if ( commandService != null )
+        {
+            IAction nva = ( IAction ) entryEditorActionMap.get( newValueAction );
+            commandService.getCommand( nva.getActionDefinitionId() ).setHandler( null );
+            commandService.getCommand( openDefaultValueEditorActionProxy.getActionDefinitionId() ).setHandler( null );
+        }
+
+    }
+
+
+    /**
+     * Gets the open default editor action.
+     * 
+     * @return the open default editor action
+     */
+    public OpenDefaultEditorAction getOpenDefaultEditorAction()
+    {
+        return ( OpenDefaultEditorAction ) openDefaultValueEditorActionProxy.getAction();
+    }
+
+}



Mime
View raw message