You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/11/05 15:46:37 UTC

svn commit: r592022 [3/4] - in /directory/sandbox/felixk/studio-connection-ui: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ src/ma...

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,234 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.properties;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionParameter;
+import org.apache.directory.studio.connection.core.Utils;
+import org.apache.directory.studio.connection.core.jobs.CloseConnectionsJob;
+import org.apache.directory.studio.connection.ui.ConnectionParameterPage;
+import org.apache.directory.studio.connection.ui.ConnectionParameterPageManager;
+import org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener;
+import org.apache.directory.studio.connection.ui.widgets.BaseWidgetUtils;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+
+/**
+ * The ConnectionPropertyPage displays the properties of a {@link Connection}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionPropertyPage extends PropertyPage implements ConnectionParameterPageModifyListener
+{
+
+    /** The tab folder. */
+    private TabFolder tabFolder;
+
+    /** The tabs. */
+    private TabItem[] tabs;
+
+    /** The connection property pages. */
+    private ConnectionParameterPage[] pages;
+
+
+    /**
+     * Creates a new instance of ConnectionPropertyPage.
+     */
+    public ConnectionPropertyPage()
+    {
+        super();
+        super.noDefaultAndApplyButton();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener#connectionParameterPageModified()
+     */
+    public void connectionParameterPageModified()
+    {
+        validate();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener#getTestConnectionParameters()
+     */
+    public ConnectionParameter getTestConnectionParameters()
+    {
+        ConnectionParameter connectionParameter = new ConnectionParameter();
+        for ( int i = 0; i < pages.length; i++ )
+        {
+            pages[i].saveParameters( connectionParameter );
+        }
+        return connectionParameter;
+    }
+
+
+    /**
+     * @see org.eclipse.jface.dialogs.DialogPage#setMessage(java.lang.String)
+     */
+    public void setMessage( String message )
+    {
+        super.setMessage( message, PropertyPage.WARNING );
+    }
+
+
+    /**
+     * @see org.eclipse.jface.preference.PreferencePage#setErrorMessage(java.lang.String)
+     */
+    public void setErrorMessage( String errorMessage )
+    {
+        super.setErrorMessage( errorMessage );
+    }
+
+
+    /**
+     * Validates the dialog.
+     */
+    private void validate()
+    {
+        int index = tabFolder.getSelectionIndex();
+        ConnectionParameterPage page = index >= 0 ? pages[tabFolder.getSelectionIndex()] : null;
+        if( page != null && !page.isValid() ) 
+        {
+            setMessage( page.getMessage() );
+            setErrorMessage( page.getErrorMessage() );
+            setValid( false );
+        }
+        else
+        {
+            for ( int i = 0; i < pages.length; i++ )
+            {
+                if ( !pages[i].isValid() )
+                {
+                    setMessage( pages[i].getMessage() );
+                    setErrorMessage( pages[i].getErrorMessage() );
+                    setValid( false );
+                    return;
+                }
+            }
+            
+            setMessage( null );
+            setErrorMessage( null );
+            setValid( true );
+            
+        }
+    }
+
+
+    static Connection getConnection( Object element )
+    {
+        Connection connection = null;
+        if ( element instanceof IAdaptable )
+        {
+            connection = ( Connection ) ( ( IAdaptable ) element ).getAdapter( Connection.class );
+        }
+        return connection;
+    }
+
+
+    /**
+     * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+     */
+    protected Control createContents( Composite parent )
+    {
+        Connection connection = getConnection( getElement() );
+        if ( connection != null )
+        {
+            super.setMessage( "Connection " + Utils.shorten( connection.getName(), 30 ) );
+            
+            pages = ConnectionParameterPageManager.getConnectionParameterPages();
+            
+            tabFolder = new TabFolder( parent, SWT.TOP );
+            
+            tabs = new TabItem[pages.length];
+            for ( int i = 0; i < pages.length; i++ )
+            {
+                Composite composite = new Composite( tabFolder, SWT.NONE );
+                GridLayout gl = new GridLayout( 1, false );
+                composite.setLayout( gl );
+                
+                pages[i].createComposite( composite );
+                pages[i].setRunnableContext( null );
+                pages[i].setConnectionParameterPageModifyListener( this );
+                pages[i].loadParameters( connection.getConnectionParameter() );
+                
+                tabs[i] = new TabItem( tabFolder, SWT.NONE );
+                tabs[i].setText( pages[i].getPageName() );
+                tabs[i].setControl( composite );
+            }
+            
+            return tabFolder;
+        }
+        else {
+            Label label = BaseWidgetUtils.createLabel( parent, "No connection", 1 );
+            return label;
+        }
+    }
+
+
+    /**
+     * @see org.eclipse.jface.preference.PreferencePage#performOk()
+     */
+    public boolean performOk()
+    {
+        // get current connection parameters
+        Connection connection = ( Connection ) getConnection( getElement() );
+        
+        // save modified parameters
+        boolean parametersModified = false;
+        boolean reconnectionRequired = false;
+        ConnectionParameter connectionParameter = new ConnectionParameter();
+        connectionParameter.setId( connection.getConnectionParameter().getId() );
+        for ( int i = 0; i < pages.length; i++ )
+        {
+            pages[i].saveParameters( connectionParameter );
+            pages[i].saveDialogSettings();
+            parametersModified |= pages[i].areParametersModifed();
+            reconnectionRequired |= pages[i].isReconnectionRequired();
+        }
+
+        if ( parametersModified )
+        {
+            // update connection parameters
+            connection.setConnectionParameter( connectionParameter );
+
+            if ( reconnectionRequired )
+            {
+                // close connection
+                new CloseConnectionsJob( connection ).execute();
+            }
+        }
+
+        return true;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,400 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionParameter;
+import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
+import org.apache.directory.studio.connection.core.jobs.CheckBindJob;
+import org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage;
+import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
+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.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 AuthenticationParameterPage is used the edit the authentication parameters of a
+ * connection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AuthenticationParameterPage extends AbstractConnectionParameterPage
+{
+
+    /** The combo to select the authentication method */
+    private Combo authenticationMethodCombo;
+
+    /** The bind user combo with the history of recently used bind users */
+    private Combo bindPrincipalCombo;
+
+    /** The text widget to input bind password */
+    private Text bindPasswordText;
+    
+    /** The text widget to input saslRealm */
+    private Combo saslRealmText;
+
+    /** The checkbox to choose if the bind password should be saved on disk */
+    private Button saveBindPasswordButton;
+
+    /** The button to check the authentication parameters */
+    private Button checkPrincipalPasswordAuthButton;;
+
+
+    /**
+     * Creates a new instance of AuthenticationParameterPage.
+     */
+    public AuthenticationParameterPage()
+    {
+    }
+
+
+    /**
+     * Gets the authentication method.
+     * 
+     * @return the authentication method
+     */
+    private ConnectionParameter.AuthenticationMethod getAuthenticationMethod()
+    {
+        switch ( authenticationMethodCombo.getSelectionIndex() )
+        {
+            case 1:
+                return ConnectionParameter.AuthenticationMethod.SIMPLE;
+            case 2:
+                return ConnectionParameter.AuthenticationMethod.SASL_DIGEST_MD5;
+            case 3:
+                return ConnectionParameter.AuthenticationMethod.SASL_CRAM_MD5;
+            case 4:
+                return ConnectionParameter.AuthenticationMethod.SASL_GSSAPI;
+            default:
+                return ConnectionParameter.AuthenticationMethod.NONE;
+        }
+    }
+
+
+    /**
+     * Gets the bind principal.
+     * 
+     * @return the bind principal
+     */
+    private String getBindPrincipal()
+    {
+        return bindPrincipalCombo.getText();
+    }
+
+
+    /**
+     * Gets the bind password.
+     * 
+     * @return the bind password
+     */
+    private String getBindPassword()
+    {
+        return isSaveBindPassword() ? bindPasswordText.getText() : null;
+    }
+    
+    private String getSaslRealm()
+    {
+        return saslRealmText.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 isSaveBindPassword()
+    {
+        return saveBindPasswordButton.getSelection();
+    }
+
+
+    /**
+     * Gets a temporary connection with all conection parameter 
+     * entered in this page. 
+     *
+     * @return a test connection
+     */
+    private Connection getTestConnection()
+    {
+        ConnectionParameter cp = connectionParameterPageModifyListener.getTestConnectionParameters();
+        Connection conn = new Connection( cp );
+        return conn;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#createComposite(org.eclipse.swt.widgets.Composite)
+     */
+    public void createComposite( Composite parent )
+    {
+        Composite composite1 = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Group group1 = BaseWidgetUtils.createGroup( composite1, "Authentication Method", 1 );
+        Composite groupComposite = BaseWidgetUtils.createColumnContainer( group1, 1, 1 );
+
+        String[] authMethods = new String[]
+            { "Anonymous Authentication", "Simple Authentication", "DIGEST-MD5 (SASL)", "CRAM-MD5 (SASL)" };
+        authenticationMethodCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, authMethods, 1, 2 );
+        authenticationMethodCombo.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent event )
+            {
+                connectionPageModified();
+            }
+        } );
+
+        Composite composite2 = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Group group2 = BaseWidgetUtils.createGroup( composite2, "Authentication Parameter", 1 );
+        Composite composite = BaseWidgetUtils.createColumnContainer( group2, 3, 1 );
+
+        BaseWidgetUtils.createLabel( composite, "Bind DN or user:", 1 );
+        String[] dnHistory = HistoryUtils.load( ConnectionUIConstants.DIALOGSETTING_KEY_PRINCIPAL_HISTORY );
+        bindPrincipalCombo = BaseWidgetUtils.createCombo( composite, dnHistory, -1, 2 );
+        bindPrincipalCombo.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent event )
+            {
+                connectionPageModified();
+            }
+        } );
+
+        BaseWidgetUtils.createLabel( composite, "Bind password:", 1 );
+        bindPasswordText = BaseWidgetUtils.createPasswordText( composite, "", 2 );
+        bindPasswordText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent event )
+            {
+                connectionPageModified();
+            }
+        } );
+
+        BaseWidgetUtils.createLabel( composite, "SASL Realm:", 1 );
+        String[] saslHistory = HistoryUtils.load( ConnectionUIConstants.DIALOGSETTING_KEY_REALM_HISTORY );
+        saslRealmText = BaseWidgetUtils.createCombo( composite, saslHistory, -1, 2 );
+        saslRealmText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent even )
+            {
+                connectionPageModified();
+            }
+        } );
+        
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        saveBindPasswordButton = BaseWidgetUtils.createCheckbox( composite, "Save password", 1 );
+        saveBindPasswordButton.setSelection( true );
+        saveBindPasswordButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent event )
+            {
+                connectionPageModified();
+            }
+        } );
+
+        checkPrincipalPasswordAuthButton = new Button( composite, SWT.PUSH );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalAlignment = SWT.RIGHT;
+        checkPrincipalPasswordAuthButton.setLayoutData( gd );
+        checkPrincipalPasswordAuthButton.setText( "Check Authentication" );
+        checkPrincipalPasswordAuthButton.setEnabled( false );
+        checkPrincipalPasswordAuthButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                Connection 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." );
+                }
+            }
+        } );
+        
+        validate();
+    }
+
+
+    /**
+     * Called when an input field was modified.
+     */
+    private void connectionPageModified()
+    {
+    	
+        validate();
+        fireConnectionPageModified();
+    }
+
+
+    /**
+     * Validates the input fields after each modification.
+     */
+    private void validate()
+    {
+        // set enabled/disabled state of fields and buttons
+        bindPrincipalCombo.setEnabled( isPrincipalPasswordEnabled() );
+        bindPasswordText.setEnabled( isPrincipalPasswordEnabled() && isSaveBindPassword() );
+        saveBindPasswordButton.setEnabled( isPrincipalPasswordEnabled() );
+        checkPrincipalPasswordAuthButton.setEnabled( isPrincipalPasswordEnabled() && isSaveBindPassword()
+            && !bindPrincipalCombo.getText().equals( "" ) && !bindPasswordText.getText().equals( "" ) );
+        saslRealmText.setEnabled( isSaslRealmTextEnabled() );
+
+        // validate input fields
+        message = null;
+        errorMessage = null;
+        if ( isPrincipalPasswordEnabled() )
+        {
+            if ( isSaveBindPassword() && "".equals( bindPasswordText.getText() ) )
+            {
+                message = "Please enter a bind password.";
+            }
+            if ( "".equals( bindPrincipalCombo.getText() ) )
+            {
+                message = "Please enter a bind DN or user.";
+            }
+        }
+        
+        if ( isSaslRealmTextEnabled() )
+        {
+            if ( "".equals( saslRealmText.getText() ) )
+            {
+                message = message != null ? message + "\n" : "";
+                message += "Please enter a SASL Realm otherwise any available SASL realm is chosen";
+            }
+        }
+    }
+
+
+    /**
+     * Checks if is principal password enabled.
+     * 
+     * @return true, if is principal password enabled
+     */
+    private boolean isPrincipalPasswordEnabled()
+    {
+        return ( getAuthenticationMethod() == AuthenticationMethod.SIMPLE )
+            || ( getAuthenticationMethod() == AuthenticationMethod.SASL_DIGEST_MD5 )
+            || ( getAuthenticationMethod() == AuthenticationMethod.SASL_CRAM_MD5 );
+    }
+    
+    
+    private boolean isSaslRealmTextEnabled(){
+    	return getAuthenticationMethod() == AuthenticationMethod.SASL_DIGEST_MD5;
+    }
+    
+    
+    private boolean isGssapiEnabled(){
+    	return getAuthenticationMethod() == AuthenticationMethod.SASL_GSSAPI;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#loadParameters(org.apache.directory.studio.connection.core.ConnectionParameter)
+     */
+    public void loadParameters( ConnectionParameter parameter )
+    {
+        this.connectionParameter = parameter;
+
+        int index = parameter.getAuthMethod() == AuthenticationMethod.SIMPLE ? 1
+            : parameter.getAuthMethod() == AuthenticationMethod.SASL_DIGEST_MD5 ? 2
+                : parameter.getAuthMethod() == AuthenticationMethod.SASL_CRAM_MD5 ? 3
+                    : parameter.getAuthMethod() == AuthenticationMethod.SASL_GSSAPI ? 4 : 0;
+        authenticationMethodCombo.select( index );
+        bindPrincipalCombo.setText( parameter.getBindPrincipal() );
+        bindPasswordText.setText( parameter.getBindPassword() != null ? parameter.getBindPassword() : "" );
+        saveBindPasswordButton.setSelection( parameter.getBindPassword() != null );
+        saslRealmText.setText( parameter.getSaslRealm() != null ? parameter.getSaslRealm() : "" );
+
+        connectionPageModified();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveParameters(org.apache.directory.studio.connection.core.ConnectionParameter)
+     */
+    public void saveParameters( ConnectionParameter parameter )
+    {
+        parameter.setAuthMethod( getAuthenticationMethod() );
+        parameter.setBindPrincipal( getBindPrincipal() );
+        parameter.setBindPassword( getBindPassword() );
+        parameter.setSaslRealm(getSaslRealm());
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveDialogSettings()
+     */
+    public void saveDialogSettings()
+    {
+        HistoryUtils.save( ConnectionUIConstants.DIALOGSETTING_KEY_PRINCIPAL_HISTORY, bindPrincipalCombo.getText() );
+        if ( getAuthenticationMethod().equals( AuthenticationMethod.SASL_DIGEST_MD5 ) )
+        {
+            HistoryUtils.save( ConnectionUIConstants.DIALOGSETTING_KEY_REALM_HISTORY, saslRealmText.getText() );
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#setFocus()
+     */
+    public void setFocus()
+    {
+        bindPrincipalCombo.setFocus();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#areParametersModifed()
+     */
+    public boolean areParametersModifed()
+    {
+        return isReconnectionRequired();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#isReconnectionRequired()
+     */
+    public boolean isReconnectionRequired()
+    {
+        return connectionParameter == null
+            || connectionParameter.getAuthMethod() != getAuthenticationMethod()
+            || !( connectionParameter.getBindPrincipal().equals( getBindPrincipal() ) )
+            || !( connectionParameter.getBindPassword().equals( getBindPassword() ) || !( connectionParameter
+                .getSaslRealm().equals( getSaslRealm() ) ) );
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,474 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+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.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * This class provides utility methods to create SWT widgets.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BaseWidgetUtils
+{
+
+    /**
+     * Creates a SWT {@link Group} under the given parent.
+     *
+     * @param parent the parent
+     * @param label the label of the group
+     * @param span the horizontal span
+     * @return the created group
+     */
+    public static Group createGroup( Composite parent, String label, int span )
+    {
+        Group group = new Group( parent, SWT.NONE );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.horizontalSpan = span;
+        group.setLayoutData( gd );
+        group.setText( label );
+        group.setLayout( new GridLayout() );
+        return group;
+    }
+
+
+    /**
+     * Creates a SWT {@link Composite} under the given parent. 
+     * A GridLayout with the given number of columns is used.
+     *
+     * @param parent the parent
+     * @param columnCount the number of columns
+     * @param span the horizontal span
+     * @return the created composite
+     */
+    public static Composite createColumnContainer( Composite parent, int columnCount, int span )
+    {
+        Composite container = new Composite( parent, SWT.NONE );
+        GridLayout gl = new GridLayout( columnCount, false );
+        gl.marginHeight = gl.marginWidth = 0;
+        container.setLayout( gl );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        container.setLayoutData( gd );
+        return container;
+    }
+
+
+    /**
+     * Creates a SWT {@link Label} under the given parent. 
+     *
+     * @param parent the parent
+     * @param text the label's text
+     * @param span the horizontal span
+     * @return the created label
+     */
+    public static Label createLabel( Composite parent, String text, int span )
+    {
+        Label l = new Label( parent, SWT.NONE );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        // gd.verticalAlignment = SWT.BEGINNING;
+        l.setLayoutData( gd );
+        l.setText( text );
+        return l;
+    }
+
+
+    /**
+     * Creates a SWT {@link Label} under the given parent. 
+     * The label is created with the SWT.WRAP style to enable line wrapping.
+     *
+     * @param parent the parent
+     * @param text the label's text
+     * @param span the horizontal span
+     * @return the created label
+     */
+    public static Label createWrappedLabel( Composite parent, String text, int span )
+    {
+        Label l = new Label( parent, SWT.WRAP );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        // gd.verticalAlignment = SWT.BEGINNING;
+        l.setLayoutData( gd );
+        l.setText( text );
+        return l;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control is modifyable.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control is modifyable.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param textWidth the width of the text control
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createText( Composite parent, String text, int textWidth, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        gd.widthHint = 9 * textWidth;
+        t.setLayoutData( gd );
+        t.setText( text );
+        t.setTextLimit( textWidth );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control is created with the SWT.PASSWORD style.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createPasswordText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control is created with the SWT.PASSWORD and 
+     * SWT.READ_ONLY style. So the created controls is not modifyable.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createReadonlyPasswordText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD | SWT.READ_ONLY );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setEditable( false );
+        t.setBackground( parent.getBackground() );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control behaves like a label: it has no border, 
+     * a grayed background and is not modifyable. 
+     * But the text is selectable and could be copied.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createLabeledText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setEditable( false );
+        t.setBackground( parent.getBackground() );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control behaves like a label: it has no border, 
+     * a grayed background and is not modifyable. 
+     * But the text is selectable and could be copied.
+     * The label is created with the SWT.WRAP style to enable line wrapping.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createWrappedLabeledText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.WRAP );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        gd.widthHint = 10;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = GridData.FILL;
+        t.setLayoutData( gd );
+        t.setEditable( false );
+        t.setBackground( parent.getBackground() );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The text is not modifyable, but the text is selectable 
+     * and could be copied.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createReadonlyText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.READ_ONLY );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setEditable( false );
+        t.setBackground( parent.getBackground() );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Combo} under the given parent.
+     * Beside the selection of an item it is also possible to type
+     * free text into the combo.
+     *
+     * @param parent the parent
+     * @param items the initial visible items
+     * @param selectedIndex the initial selected item, zero-based
+     * @param span the horizontal span
+     * @return the created combo
+     */
+    public static Combo createCombo( Composite parent, String[] items, int selectedIndex, int span )
+    {
+        Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        c.setLayoutData( gd );
+        c.setItems( items );
+        c.select( selectedIndex );
+        c.setVisibleItemCount( 20 );
+        return c;
+    }
+
+
+    /**
+     * Creates a SWT {@link Combo} under the given parent.
+     * It is not possible to type free text into the combo, only 
+     * selection of predefined items is possible.
+     *
+     * @param parent the parent
+     * @param items the initial visible items
+     * @param selectedIndex the initial selected item, zero-based
+     * @param span the horizontal span
+     * @return the created combo
+     */
+    public static Combo createReadonlyCombo( Composite parent, String[] items, int selectedIndex, int span )
+    {
+        Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        c.setLayoutData( gd );
+        // c.setBackground(parent.getBackground());
+        c.setItems( items );
+        c.select( selectedIndex );
+        c.setVisibleItemCount( 20 );
+        return c;
+    }
+
+
+    /**
+     * Creates a checkbox under the given parent.
+     *
+     * @param parent the parent
+     * @param text the label of the checkbox 
+     * @param span the horizontal span
+     * @return the created checkbox
+     */
+    public static Button createCheckbox( Composite parent, String text, int span )
+    {
+        Button checkbox = new Button( parent, SWT.CHECK );
+        checkbox.setText( text );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        checkbox.setLayoutData( gd );
+        return checkbox;
+    }
+
+
+    /**
+     * Creates a radio button under the given parent.
+     *
+     * @param parent the parent
+     * @param text the label of the radio button 
+     * @param span the horizontal span
+     * @return the created radio button
+     */
+    public static Button createRadiobutton( Composite parent, String text, int span )
+    {
+        Button radio = new Button( parent, SWT.RADIO );
+        radio.setText( text );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        radio.setLayoutData( gd );
+        return radio;
+    }
+
+
+    /**
+     * Creates a button under the given parent. 
+     * The button width is set to the default width.
+     *
+     * @param parent the parent
+     * @param text the label of the button 
+     * @param span the horizontal span
+     * @return the created button
+     */
+    public static Button createButton( Composite parent, String text, int span )
+    {
+        GC gc = new GC( parent );
+        gc.setFont( JFaceResources.getDialogFont() );
+        FontMetrics fontMetrics = gc.getFontMetrics();
+        gc.dispose();
+
+        Button button = new Button( parent, SWT.PUSH );
+        GridData gd = new GridData();
+        gd.widthHint = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH );
+        button.setLayoutData( gd );
+        button.setText( text );
+        return button;
+    }
+
+
+    /**
+     * Adds some space to indent radio buttons.
+     *
+     * @param parent the parent
+     * @param span the horizontal span
+     */
+    public static void createRadioIndent( Composite parent, int span )
+    {
+        Label l = new Label( parent, SWT.NONE );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        gd.horizontalIndent = 22;
+        l.setLayoutData( gd );
+    }
+
+
+    /**
+     * Creates a spacer.
+     *
+     * @param parent the parent
+     * @param span the horizontal span
+     */
+    public static void createSpacer( Composite parent, int span )
+    {
+        Label l = new Label( parent, SWT.NONE );
+        // GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        gd.heightHint = 1;
+        l.setLayoutData( gd );
+    }
+
+
+    /**
+     * Creates a separator line.
+     *
+     * @param parent the parent
+     * @param span the horizontal span
+     */
+    public static void createSeparator( Composite parent, int span )
+    {
+        Label l = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        // gd.heightHint = 1;
+        l.setLayoutData( gd );
+    }
+
+
+    /**
+     * Creates a SWT {@link Link} under the given parent.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Link createLink( Composite parent, String text, int span )
+    {
+        Link link = new Link( parent, SWT.NONE );
+        link.setText( text );
+        GridData gd = new GridData( SWT.FILL, SWT.BEGINNING, true, false );
+        gd.horizontalSpan = span;
+        gd.widthHint = 150;
+        link.setLayoutData( gd );
+        return link;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,355 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.directory.studio.connection.ui.actions.ActionHandlerManager;
+import org.apache.directory.studio.connection.ui.actions.CloseConnectionAction;
+import org.apache.directory.studio.connection.ui.actions.ConnectionViewActionProxy;
+import org.apache.directory.studio.connection.ui.actions.CopyAction;
+import org.apache.directory.studio.connection.ui.actions.DeleteAction;
+import org.apache.directory.studio.connection.ui.actions.NewConnectionAction;
+import org.apache.directory.studio.connection.ui.actions.NewConnectionFolderAction;
+import org.apache.directory.studio.connection.ui.actions.OpenConnectionAction;
+import org.apache.directory.studio.connection.ui.actions.PasteAction;
+import org.apache.directory.studio.connection.ui.actions.PropertiesAction;
+import org.apache.directory.studio.connection.ui.actions.RenameAction;
+import org.apache.directory.studio.connection.ui.actions.StudioActionProxy;
+import org.apache.directory.studio.connection.ui.dnd.ConnectionTransfer;
+import org.apache.directory.studio.connection.ui.dnd.DragConnectionListener;
+import org.apache.directory.studio.connection.ui.dnd.DropConnectionListener;
+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.Separator;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.commands.ICommandService;
+
+
+/**
+ * This class manages all the actions of the connection widget.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionActionGroup implements ActionHandlerManager, IMenuListener
+{
+
+    /** The Constant newConnectionAction. */
+    protected static final String newConnectionAction = "newConnectionAction";
+
+    /** The Constant newConnectionFolderAction. */
+    protected static final String newConnectionFolderAction = "newConnectionFolderAction";
+    
+    /** The Constant openConnectionAction. */
+    protected static final String openConnectionAction = "openConnectionAction";
+
+    /** The Constant closeConnectionAction. */
+    protected static final String closeConnectionAction = "closeConnectionAction";
+
+    /** The Constant copyConnectionAction. */
+    protected static final String copyConnectionAction = "copyConnectionAction";
+
+    /** The Constant pasteConnectionAction. */
+    protected static final String pasteConnectionAction = "pasteConnectionAction";
+
+    /** The Constant deleteConnectionAction. */
+    protected static final String deleteConnectionAction = "deleteConnectionAction";
+
+    /** The Constant renameConnectionAction. */
+    protected static final String renameConnectionAction = "renameConnectionAction";
+
+    /** The Constant propertyDialogAction. */
+    protected static final String propertyDialogAction = "propertyDialogAction";
+
+    /** The drag connection listener. */
+    private DragConnectionListener dragConnectionListener;
+
+    /** The drop connection listener. */
+    private DropConnectionListener dropConnectionListener;
+
+    /** The action map. */
+    protected Map<String, ConnectionViewActionProxy> connectionActionMap;
+
+    /** The action bars. */
+    protected IActionBars actionBars;
+
+    /** The connection main widget. */
+    protected ConnectionWidget mainWidget;
+
+
+    /**
+     * Creates a new instance of ConnectionActionGroup.
+     *
+     * @param mainWidget the connection main widget
+     * @param configuration the connection widget configuration
+     */
+    public ConnectionActionGroup( ConnectionWidget mainWidget, ConnectionConfiguration configuration )
+    {
+        this.mainWidget = mainWidget;
+        this.connectionActionMap = new HashMap<String, ConnectionViewActionProxy>();
+
+        TreeViewer viewer = mainWidget.getViewer();
+        connectionActionMap.put( newConnectionAction, new ConnectionViewActionProxy( viewer, this,
+            new NewConnectionAction() ) );
+        connectionActionMap.put( newConnectionFolderAction, new ConnectionViewActionProxy( viewer, this,
+            new NewConnectionFolderAction() ) );
+        connectionActionMap.put( openConnectionAction, new ConnectionViewActionProxy( viewer, this,
+            new OpenConnectionAction() ) );
+        connectionActionMap.put( closeConnectionAction, new ConnectionViewActionProxy( viewer, this,
+            new CloseConnectionAction() ) );
+        connectionActionMap
+            .put( pasteConnectionAction, new ConnectionViewActionProxy( viewer, this, new PasteAction() ) );
+        connectionActionMap.put( copyConnectionAction, new ConnectionViewActionProxy( viewer, this, new CopyAction(
+            ( StudioActionProxy ) connectionActionMap.get( pasteConnectionAction ) ) ) );
+        connectionActionMap.put( deleteConnectionAction, new ConnectionViewActionProxy( viewer, this,
+            new DeleteAction() ) );
+        connectionActionMap.put( renameConnectionAction, new ConnectionViewActionProxy( viewer, this,
+            new RenameAction() ) );
+        connectionActionMap.put( propertyDialogAction, new ConnectionViewActionProxy( viewer, this,
+            new PropertiesAction() ) );
+
+        // DND support
+        dropConnectionListener = new DropConnectionListener();
+        dragConnectionListener = new DragConnectionListener();
+        int ops = DND.DROP_COPY | DND.DROP_MOVE;
+        Transfer[] transfers = new Transfer[]
+            { ConnectionTransfer.getInstance() };
+        viewer.addDragSupport( ops, transfers, dragConnectionListener );
+        viewer.addDropSupport( ops, transfers, dropConnectionListener );
+    }
+
+
+    /**
+     * Disposes this action group.
+     */
+    public void dispose()
+    {
+        if ( mainWidget != null )
+        {
+            for ( Iterator<String> it = connectionActionMap.keySet().iterator(); it.hasNext(); )
+            {
+                String key = it.next();
+                ConnectionViewActionProxy action = ( ConnectionViewActionProxy ) this.connectionActionMap.get( key );
+                action.dispose();
+                action = null;
+                it.remove();
+            }
+            connectionActionMap.clear();
+            connectionActionMap = null;
+
+            actionBars = null;
+            mainWidget = null;
+            
+            dragConnectionListener = null;
+            dropConnectionListener = null;
+        }
+    }
+
+
+    /**
+     * Enables the action handlers.
+     *
+     * @param actionBars the action bars
+     */
+    public void enableGlobalActionHandlers( IActionBars actionBars )
+    {
+        this.actionBars = actionBars;
+        activateGlobalActionHandlers();
+    }
+
+
+    /**
+     * Fills the tool bar.
+     *
+     * @param toolBarManager the tool bar manager
+     */
+    public void fillToolBar( IToolBarManager toolBarManager )
+    {
+        toolBarManager.add( ( IAction ) this.connectionActionMap.get( newConnectionAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( ( IAction ) this.connectionActionMap.get( openConnectionAction ) );
+        toolBarManager.add( ( IAction ) this.connectionActionMap.get( closeConnectionAction ) );
+
+        toolBarManager.update( true );
+    }
+
+
+    /**
+     * Fills the local menu.
+     *
+     * @param menuManager the local menu manager
+     */
+    public void fillMenu( IMenuManager menuManager )
+    {
+        // menuManager.add(this.openSortDialogAction);
+        // menuManager.add(new Separator());
+        // menuManager.update(true);
+    }
+
+
+    /**
+     * Fills the context menu.
+     *
+     * @param menuManager the context menu manager
+     */
+    public void fillContextMenu( IMenuManager menuManager )
+    {
+        menuManager.setRemoveAllWhenShown( true );
+        menuManager.addMenuListener( this );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation fills the context menu.
+     */
+    public void menuAboutToShow( IMenuManager menuManager )
+    {
+        // add
+        menuManager.add( ( IAction ) connectionActionMap.get( newConnectionAction ) );
+        menuManager.add( ( IAction ) connectionActionMap.get( newConnectionFolderAction ) );
+        menuManager.add( new Separator() );
+
+        // open/close
+        if ( ( ( IAction ) connectionActionMap.get( closeConnectionAction ) ).isEnabled() )
+        {
+            menuManager.add( ( IAction ) connectionActionMap.get( closeConnectionAction ) );
+        }
+        else if ( ( ( IAction ) connectionActionMap.get( openConnectionAction ) ).isEnabled() )
+        {
+            menuManager.add( ( IAction ) connectionActionMap.get( openConnectionAction ) );
+        }
+        menuManager.add( new Separator() );
+
+        // copy/paste/...
+        menuManager.add( ( IAction ) connectionActionMap.get( copyConnectionAction ) );
+        menuManager.add( ( IAction ) connectionActionMap.get( pasteConnectionAction ) );
+        menuManager.add( ( IAction ) connectionActionMap.get( deleteConnectionAction ) );
+        menuManager.add( ( IAction ) connectionActionMap.get( renameConnectionAction ) );
+        menuManager.add( new Separator() );
+
+        // additions
+        menuManager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );
+
+        // properties
+        menuManager.add( ( IAction ) connectionActionMap.get( propertyDialogAction ) );
+    }
+
+
+    /**
+     * Activates the action handlers.
+     */
+    public void activateGlobalActionHandlers()
+    {
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), ( IAction ) connectionActionMap
+                .get( copyConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), ( IAction ) connectionActionMap
+                .get( pasteConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), ( IAction ) connectionActionMap
+                .get( deleteConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.RENAME.getId(), ( IAction ) connectionActionMap
+                .get( renameConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), ( IAction ) connectionActionMap
+                .get( propertyDialogAction ) );
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction ca = ( IAction ) connectionActionMap.get( copyConnectionAction );
+                ca.setActionDefinitionId( "org.apache.directory.studio.ldapbrowser.action.copy" );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( new ActionHandler( ca ) );
+
+                IAction pa = ( IAction ) connectionActionMap.get( pasteConnectionAction );
+                pa.setActionDefinitionId( "org.apache.directory.studio.ldapbrowser.action.paste" );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( new ActionHandler( pa ) );
+
+                IAction da = ( IAction ) connectionActionMap.get( deleteConnectionAction );
+                da.setActionDefinitionId( "org.apache.directory.studio.ldapbrowser.action.delete" );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( new ActionHandler( da ) );
+
+                IAction pda = ( IAction ) connectionActionMap.get( propertyDialogAction );
+                pda.setActionDefinitionId( "org.apache.directory.studio.ldapbrowser.action.properties" );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( new ActionHandler( pda ) );
+
+            }
+        }
+    }
+
+
+    /**
+     * Deactivates the 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.RENAME.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), null );
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction ca = ( IAction ) connectionActionMap.get( copyConnectionAction );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( null );
+
+                IAction pa = ( IAction ) connectionActionMap.get( pasteConnectionAction );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( null );
+
+                IAction da = ( IAction ) connectionActionMap.get( deleteConnectionAction );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( null );
+
+                IAction pda = ( IAction ) connectionActionMap.get( propertyDialogAction );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( null );
+
+            }
+        }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,166 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Menu;
+
+
+/**
+ * The ConnectionConfiguration contains the content provider, the
+ * label provider and the context menu manager for the
+ * connection widget. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionConfiguration
+{
+
+    /** The disposed flag */
+    private boolean disposed = false;
+
+    /** The content provider. */
+    private ConnectionContentProvider contentProvider;
+
+    /** The label provider. */
+    private ConnectionLabelProvider labelProvider;
+
+    /** The sorter. */
+    private ConnectionSorter sorter;
+    
+    /** The context menu manager. */
+    private MenuManager contextMenuManager;
+
+
+    /**
+     * Creates a new instance of ConnectionConfiguration.
+     */
+    public ConnectionConfiguration()
+    {
+    }
+
+
+    /**
+     * Disposes this configuration.
+     */
+    public void dispose()
+    {
+        if ( !disposed )
+        {
+
+            if ( contentProvider != null )
+            {
+                contentProvider.dispose();
+                contentProvider = null;
+            }
+
+            if ( labelProvider != null )
+            {
+                labelProvider.dispose();
+                labelProvider = null;
+            }
+
+            if ( contextMenuManager != null )
+            {
+                contextMenuManager.dispose();
+                contextMenuManager = null;
+            }
+
+            disposed = true;
+        }
+    }
+
+
+    /**
+     * Gets the context menu manager.
+     * 
+     * @param viewer the connection widget's table viewer 
+     * 
+     * @return the context menu manager
+     */
+    public IMenuManager getContextMenuManager( TreeViewer viewer )
+    {
+        if ( this.contextMenuManager == null )
+        {
+            this.contextMenuManager = new MenuManager();
+            Menu menu = this.contextMenuManager.createContextMenu( viewer.getControl() );
+            viewer.getControl().setMenu( menu );
+        }
+        return this.contextMenuManager;
+    }
+
+
+    /**
+     * Gets the content provider.
+     * 
+     * @param viewer the connection widget's table viewer
+     * 
+     * @return the content provider
+     */
+    public ConnectionContentProvider getContentProvider( TreeViewer viewer )
+    {
+        if ( contentProvider == null )
+        {
+            contentProvider = new ConnectionContentProvider();
+        }
+
+        return contentProvider;
+    }
+
+
+    /**
+     * Gets the label provider.
+     * 
+     * @param viewer the connection widget's table viewer
+     * 
+     * @return the label provider
+     */
+    public ConnectionLabelProvider getLabelProvider( TreeViewer viewer )
+    {
+        if ( labelProvider == null )
+        {
+            labelProvider = new ConnectionLabelProvider();
+        }
+
+        return labelProvider;
+    }
+    
+    
+    /**
+     * Gets the sorter.
+     * 
+     * @return the sorter
+     */
+    public ConnectionSorter getSorter()
+    {
+        if ( sorter == null )
+        {
+            sorter = new ConnectionSorter();
+        }
+        
+        return sorter;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,150 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.ConnectionFolderManager;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * The ConnectionContentProvider represents the content provider for
+ * the connection widget. It accepts the ConnectionManager as input
+ * and returns its connections as elements.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionContentProvider implements ITreeContentProvider
+{
+
+    /**
+     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+     */
+    public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+    {
+    }
+
+
+    /**
+     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+     */
+    public void dispose()
+    {
+    }
+
+
+    /**
+     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+     */
+    public Object[] getElements( Object inputElement )
+    {
+        if ( inputElement != null && inputElement instanceof ConnectionFolderManager )
+        {
+            ConnectionFolderManager cfm = ( ConnectionFolderManager ) inputElement;
+            ConnectionFolder rootConnectionFolder = cfm.getRootConnectionFolder();
+            Object[] elements = getChildren( rootConnectionFolder );
+            return elements;
+        }
+        else
+        {
+            return getChildren( inputElement );
+        }
+    }
+
+
+    /**
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+     */
+    public Object[] getChildren( Object parentElement )
+    {
+        if ( parentElement != null && parentElement instanceof ConnectionFolder )
+        {
+            List<Object> children = new ArrayList<Object>();
+
+            ConnectionFolder folder = ( ConnectionFolder ) parentElement;
+            List<String> subFolderIds = folder.getSubFolderIds();
+            List<String> connectionIds = folder.getConnectionIds();
+
+            for ( String subFolderId : subFolderIds )
+            {
+                ConnectionFolder subFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager()
+                    .getConnectionFolderById( subFolderId );
+                if ( subFolder != null )
+                {
+                    children.add( subFolder );
+                }
+            }
+            for ( String connectionId : connectionIds )
+            {
+                Connection conn = ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionById(
+                    connectionId );
+                if ( conn != null )
+                {
+                    children.add( conn );
+                }
+            }
+
+            return children.toArray();
+        }
+        return null;
+    }
+
+
+    /**
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+     */
+    public Object getParent( Object element )
+    {
+        if ( element instanceof ConnectionFolder )
+        {
+            return ConnectionCorePlugin.getDefault().getConnectionFolderManager().getParentConnectionFolder(
+                ( ConnectionFolder ) element );
+        }
+        else if ( element instanceof Connection )
+        {
+            return ConnectionCorePlugin.getDefault().getConnectionFolderManager().getParentConnectionFolder(
+                ( Connection ) element );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+     */
+    public boolean hasChildren( Object element )
+    {
+        Object[] children = getChildren( element );
+        return children != null && children.length > 0;
+    }
+
+}
\ No newline at end of file

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,107 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
+import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
+import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * The ConnectionLabelProvider represents the label provider for
+ * the connection widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionLabelProvider extends LabelProvider
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation returns the connection name and appends information
+     * about the used encryption method.
+     */
+    public String getText( Object obj )
+    {
+        if ( obj instanceof ConnectionFolder )
+        {
+            ConnectionFolder folder = (ConnectionFolder) obj;
+            return folder.getName();
+        }
+        if ( obj instanceof Connection )
+        {
+            Connection conn = ( Connection ) obj;
+            if ( conn.getEncryptionMethod() == EncryptionMethod.LDAPS )
+            {
+                return conn.getName() + " (LDAPS)";
+            }
+            else if ( conn.getEncryptionMethod() == EncryptionMethod.START_TLS )
+            {
+                return conn.getName() + " (StartTLS)";
+            }
+            else
+            {
+                return conn.getName();
+            }
+        }
+        else if ( obj != null )
+        {
+            return obj.toString();
+        }
+        else
+        {
+            return "";
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation returns a icon for connected or disconnected state.
+     */
+    public Image getImage( Object obj )
+    {
+        if ( obj instanceof ConnectionFolder )
+        {
+            return ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CONNECTION_FOLDER );
+        }
+        else if ( obj instanceof Connection )
+        {
+            Connection conn = ( Connection ) obj;
+            return conn.getJNDIConnectionWrapper().isConnected() ? ConnectionUIPlugin.getDefault().getImage(
+                ConnectionUIConstants.IMG_CONNECTION_CONNECTED ) : ConnectionUIPlugin.getDefault().getImage(
+                ConnectionUIConstants.IMG_CONNECTION_DISCONNECTED );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+}
\ No newline at end of file

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionSorter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionSorter.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionSorter.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionSorter.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,82 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+
+/**
+ * The ConnectionSorter implements the sorter for the connection widget. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionSorter extends ViewerSorter
+{
+
+    /**
+     * Creates a new instance of ConnectionSorter.
+     */
+    public ConnectionSorter()
+    {
+    }
+
+
+    /**
+     * Connects the tree viewer to this sorter.
+     *
+     * @param viewer the tree viewer
+     */
+    public void connect( TreeViewer viewer )
+    {
+        viewer.setSorter( this );
+    }
+
+
+    /**
+     * Disposes this sorter.
+     */
+    public void dispose()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This method is used to categorize connection folders and connections.
+     */
+    public int category( Object element )
+    {
+        if ( element instanceof ConnectionFolder )
+        {
+            return 1;
+        }
+        else
+        {
+            return 2;
+        }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionSorter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java Mon Nov  5 06:46:32 2007
@@ -0,0 +1,159 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
+import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
+import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+
+
+/**
+ * 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
+{
+
+    /** The tree viewer */
+    protected TreeViewer viewer;
+
+    /** This listener expands/collapses a connection folder when double clicking */
+    private IDoubleClickListener viewerDoubleClickListener = new IDoubleClickListener()
+    {
+        public void doubleClick( DoubleClickEvent event )
+        {
+            if ( event.getSelection() instanceof IStructuredSelection )
+            {
+                Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                if ( obj instanceof ConnectionFolder )
+                {
+                    if ( viewer.getExpandedState( obj ) )
+                    {
+                        viewer.collapseToLevel( obj, 1 );
+                    }
+                    else if ( ( ( ITreeContentProvider ) viewer.getContentProvider() ).hasChildren( obj ) )
+                    {
+                        viewer.expandToLevel( obj, 1 );
+                    }
+                }
+            }
+        }
+    };
+    
+    /**
+     * Creates a new instance of ConnectionUniversalListener.
+     *
+     * @param viewer the tree viewer
+     */
+    public ConnectionUniversalListener( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+
+        this.viewer.addDoubleClickListener( viewerDoubleClickListener );
+        ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionUIPlugin.getDefault().getEventRunner() );
+    }
+
+
+    /**
+     * Disposes this universal listener.
+     */
+    public void dispose()
+    {
+        if ( viewer != null )
+        {
+            ConnectionEventRegistry.removeConnectionUpdateListener( this );
+            viewer = null;
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionUpdated(org.apache.directory.studio.connection.core.Connection)
+     */
+    public void connectionUpdated( Connection connection )
+    {
+        if ( viewer != null )
+        {
+            viewer.refresh();
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionAdded(org.apache.directory.studio.connection.core.Connection)
+     */
+    public void connectionAdded( Connection connection )
+    {
+        connectionUpdated( connection );
+        if ( viewer != null )
+        {
+            viewer.setSelection( new StructuredSelection( connection ), true );
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionRemoved(org.apache.directory.studio.connection.core.Connection)
+     */
+    public void connectionRemoved( Connection connection )
+    {
+        connectionUpdated( connection );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionOpened(org.apache.directory.studio.connection.core.Connection)
+     */
+    public void connectionOpened( Connection connection )
+    {
+        connectionUpdated( connection );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionClosed(org.apache.directory.studio.connection.core.Connection)
+     */
+    public void connectionClosed( Connection connection )
+    {
+        connectionUpdated( connection );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder)
+     */
+    public void connectionFolderModified( ConnectionFolder connectionFolder )
+    {
+        connectionUpdated( null );
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionWidget.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionWidget.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionWidget.java Mon Nov  5 06:46:32 2007
@@ -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.studio.connection.ui.widgets;
+
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.TreeViewer;
+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.Tree;
+import org.eclipse.ui.IActionBars;
+
+
+/**
+ * The ConnectionWidget is a reusable widget that displays all connections
+ * in a table viewer. It is used by 
+ * org.apache.directory.studio.ldapbrowser.ui.views.connection.ConnectionView, 
+ * org.apache.directory.studio.ldapbrowser.common.dialogs.SelectConnectionDialog and 
+ * org.apache.directory.studio.ldapbrowser.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 tree widget used by the tree viewer */
+    private Tree tree;
+
+    /** The tree viewer */
+    private TreeViewer 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 )
+    {
+        tree = new Tree( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 450;
+        data.heightHint = 250;
+        tree.setLayoutData( data );
+        viewer = new TreeViewer( tree );
+
+        // setup sorter
+        configuration.getSorter().connect( viewer );
+
+        // setup providers
+        viewer.setContentProvider( configuration.getContentProvider( viewer ) );
+        viewer.setLabelProvider( configuration.getLabelProvider( viewer ) );
+
+        return tree;
+    }
+
+
+    /**
+     * 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.getTree().setFocus();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        if ( viewer != null )
+        {
+            configuration.dispose();
+            configuration = null;
+
+            tree.dispose();
+            tree = null;
+            viewer = null;
+        }
+    }
+
+
+    /**
+     * Gets the tree viewer.
+     * 
+     * @return the tree viewer
+     */
+    public TreeViewer getViewer()
+    {
+        return viewer;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionWidget.java
------------------------------------------------------------------------------
    svn:eol-style = native