directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r568990 [2/3] - in /directory/studio/trunk/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/main...
Date Thu, 23 Aug 2007 13:47:13 GMT
Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java Thu Aug 23 06:47:09 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.actions;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+
+/**
+ * The SelectionUtils are used to extract specific beans from the current
+ * selection (org.eclipse.jface.viewers.ISelection).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class SelectionUtils
+{
+
+    /**
+     * Gets the Strings contained in the given selection.
+     *
+     * @param selection the selection
+     * @return an array with Strings, may be empty.
+     */
+    public static String[] getProperties( ISelection selection )
+    {
+        List<Object> list = getTypes( selection, String.class );
+        return list.toArray( new String[list.size()] );
+    }
+
+
+    /**
+     * Gets all beans of the requested type contained in the given selection.
+     *
+     * @param selection the selection
+     * @param type the requested type
+     * @return a list containg beans of the requesten type
+     */
+    private static List<Object> getTypes( ISelection selection, Class type )
+    {
+        List<Object> list = new ArrayList<Object>();
+        if ( selection instanceof IStructuredSelection )
+        {
+            IStructuredSelection structuredSelection = ( IStructuredSelection ) selection;
+            Iterator it = structuredSelection.iterator();
+            while ( it.hasNext() )
+            {
+                Object o = it.next();
+                if ( type.isInstance( o ) )
+                {
+                    list.add( o );
+                }
+            }
+        }
+        return list;
+    }
+
+
+    /**
+     * Gets the Connection beans contained in the given selection.
+     *
+     * @param selection the selection
+     * @return an array with Connection beans, may be empty.
+     */
+    public static Connection[] getConnections( ISelection selection )
+    {
+        List<Object> list = getTypes( selection, Connection.class );
+        return list.toArray( new Connection[list.size()] );
+    }
+
+
+    /**
+     * Gets the objects contained in the given selection.
+     *
+     * @param selection the selection
+     * @return an array with object, may be empty.
+     */
+    public static Object[] getObjects( ISelection selection )
+    {
+        List<Object> list = getTypes( selection, Object.class );
+        return list.toArray( new Object[list.size()] );
+    }
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java Thu Aug 23 06:47:09 2007
@@ -0,0 +1,236 @@
+/*
+ *  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.actions;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This abstract class must be extended by each Action related to the Browser.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class StudioAction implements IWorkbenchWindowActionDelegate
+{
+    /** The selected Connections */
+    private Connection[] selectedConnections;
+
+    /** The input */
+    private Object input;
+
+
+    /**
+     * Creates a new instance of BrowserAction.
+     */
+    protected StudioAction()
+    {
+        this.init();
+    }
+
+
+    /**
+     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+     */
+    public void init( IWorkbenchWindow window )
+    {
+        this.init();
+    }
+
+
+    /**
+     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+     */
+    public void run( IAction action )
+    {
+        this.run();
+    }
+
+
+    /**
+     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+     */
+    public void selectionChanged( IAction action, ISelection selection )
+    {
+        setSelectedConnections( SelectionUtils.getConnections( selection ) );
+
+        action.setEnabled( this.isEnabled() );
+        action.setText( this.getText() );
+        action.setToolTipText( this.getText() );
+    }
+
+
+    /**
+     * Returns the text for this action.
+     * <p>
+     * This method is associated with the <code>TEXT</code> property;
+     * property change events are reported when its value changes.
+     * </p>
+     *
+     * @return the text, or <code>null</code> if none
+     */
+    public abstract String getText();
+
+
+    /**
+     * Returns the image for this action as an image descriptor.
+     * <p>
+     * This method is associated with the <code>IMAGE</code> property;
+     * property change events are reported when its value changes.
+     * </p>
+     *
+     * @return the image, or <code>null</code> if this action has no image
+     */
+    public abstract ImageDescriptor getImageDescriptor();
+
+
+    /**
+     * Returns the command identifier.
+     *
+     * @return
+     *      the command identifier
+     */
+    public abstract String getCommandId();
+
+
+    /**
+     * Returns whether this action is enabled.
+     * <p>
+     * This method is associated with the <code>ENABLED</code> property;
+     * property change events are reported when its value changes.
+     * </p>
+     *
+     * @return <code>true</code> if enabled, and
+     *   <code>false</code> if disabled
+     */
+    public abstract boolean isEnabled();
+
+
+    /**
+     * Runs this action.
+     * Each action implementation must define the steps needed to carry out this action.
+     * The default implementation of this method in <code>Action</code>
+     * does nothing.
+     */
+    public abstract void run();
+
+
+    /**
+     * Initializes this action
+     */
+    private void init()
+    {
+        this.selectedConnections = new Connection[0];
+
+        this.input = null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        this.selectedConnections = new Connection[0];
+
+        this.input = null;
+    }
+
+
+    /**
+     * Returns the current active shell
+     *
+     * @return
+     *      the current active shell
+     */
+    protected Shell getShell()
+    {
+        return PlatformUI.getWorkbench().getDisplay().getActiveShell();
+    }
+
+
+    /**
+     * This method is fired when a Connection is updated.
+     *
+     * @param connection
+     *      the connection
+     */
+    public void connectionUpdated( Connection connection )
+    {
+    }
+
+
+    /**
+     * Gets the selected Connections.
+     *
+     * @return
+     *      the selected Connections
+     */
+    public Connection[] getSelectedConnections()
+    {
+        return selectedConnections;
+    }
+
+
+    /**
+     * Sets the selected Connections.
+     *
+     * @param selectedConnections
+     *      the selected Connections to set
+     */
+    public void setSelectedConnections( Connection[] selectedConnections )
+    {
+        this.selectedConnections = selectedConnections;
+    }
+
+
+    /**
+     * Gets the input.
+     *
+     * @return
+     *      the input
+     */
+    public Object getInput()
+    {
+        return input;
+    }
+
+
+    /**
+     * Sets the input.
+     *
+     * @param input
+     *      the input to set
+     */
+    public void setInput( Object input )
+    {
+        this.input = input;
+    }
+
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java Thu Aug 23 06:47:09 2007
@@ -0,0 +1,258 @@
+/*
+ *  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.actions;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+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.action.Action;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+
+/**
+ * Proxy class for actions. The proxy class registers for modification events and 
+ * updates the real actions on every modificaton. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class StudioActionProxy extends Action implements ISelectionChangedListener, ConnectionUpdateListener
+{
+
+    /** The action handler manager, used to deactivate and activate the action handlers and key bindings. */
+    private ActionHandlerManager actionHandlerManager;
+
+    /** The real action. */
+    protected StudioAction action;
+
+    /** The selection provider. */
+    protected ISelectionProvider selectionProvider;
+
+
+    /**
+     * Creates a new instance of StudioActionProxy.
+     * 
+     * @param selectionProvider the selection provider
+     * @param actionHandlerManager the action handler manager
+     * @param action the action
+     * @param style the style
+     */
+    protected StudioActionProxy( ISelectionProvider selectionProvider, ActionHandlerManager actionHandlerManager,
+        StudioAction action, int style )
+    {
+        super( action.getText(), style );
+        this.selectionProvider = selectionProvider;
+        this.actionHandlerManager = actionHandlerManager;
+        this.action = action;
+
+        super.setImageDescriptor( action.getImageDescriptor() );
+        super.setActionDefinitionId( action.getCommandId() );
+
+        selectionProvider.addSelectionChangedListener( this );
+
+        ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionUIPlugin.getDefault().getEventRunner() );
+
+        updateAction();
+    }
+
+
+    /**
+     * Creates a new instance of StudioActionProxy.
+     * 
+     * @param selectionProvider the selection provider
+     * @param actionHandlerManager the action handler manager
+     * @param action the action
+     */
+    protected StudioActionProxy( ISelectionProvider selectionProvider, ActionHandlerManager actionHandlerManager,
+        StudioAction action )
+    {
+        this( selectionProvider, actionHandlerManager, action, Action.AS_PUSH_BUTTON );
+    }
+
+
+    /**
+     * Disposes this action proxy.
+     */
+    public void dispose()
+    {
+        ConnectionEventRegistry.removeConnectionUpdateListener( this );
+        selectionProvider.removeSelectionChangedListener( this );
+
+        action.dispose();
+        action = null;
+    }
+
+
+    /**
+     * Checks if is disposed.
+     * 
+     * @return true, if is disposed
+     */
+    public boolean isDisposed()
+    {
+        return action == null;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionUpdated(org.apache.directory.studio.connection.core.Connection)
+     */
+    public final void connectionUpdated( Connection connection )
+    {
+        if ( !isDisposed() )
+        {
+            action.connectionUpdated( connection );
+            updateAction();
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionAdded(org.apache.directory.studio.connection.core.Connection)
+     */
+    public void connectionAdded( Connection connection )
+    {
+        connectionUpdated( connection );
+    }
+
+
+    /**
+     * @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#connectionRenamed(org.apache.directory.studio.connection.core.Connection, java.lang.String)
+     */
+    public void connectionRenamed( Connection connection, String oldName )
+    {
+        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 );
+    }
+
+
+    /**
+     * Input changed.
+     * 
+     * @param input the input
+     */
+    public void inputChanged( Object input )
+    {
+        if ( !isDisposed() )
+        {
+            action.setInput( input );
+            selectionChanged( new SelectionChangedEvent( this.selectionProvider, new StructuredSelection() ) );
+            // updateAction();
+        }
+    }
+
+
+    /**
+     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+     */
+    public void selectionChanged( SelectionChangedEvent event )
+    {
+        if ( !isDisposed() )
+        {
+            ISelection selection = event.getSelection();
+            action.setSelectedConnections( SelectionUtils.getConnections( selection ) );
+            updateAction();
+        }
+    }
+
+
+    /**
+     * Updates the action.
+     */
+    public void updateAction()
+    {
+        if ( !isDisposed() )
+        {
+            setText( action.getText() );
+            setToolTipText( action.getText() );
+            setEnabled( action.isEnabled() );
+            setImageDescriptor( action.getImageDescriptor() );
+        }
+    }
+
+
+    /**
+     * @see org.eclipse.jface.action.Action#run()
+     */
+    public void run()
+    {
+        if ( !isDisposed() )
+        {
+            // deactivate global actions
+            if ( actionHandlerManager != null )
+            {
+                actionHandlerManager.deactivateGlobalActionHandlers();
+            }
+
+            action.run();
+
+            // activate global actions
+            if ( actionHandlerManager != null )
+            {
+                actionHandlerManager.activateGlobalActionHandlers();
+            }
+        }
+    }
+
+
+    /**
+     * Gets the real action.
+     * 
+     * @return the real action
+     */
+    public StudioAction getAction()
+    {
+        return action;
+    }
+
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java Thu Aug 23 06:47:09 2007
@@ -0,0 +1,66 @@
+/*
+ *  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.dialogs;
+
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * The CredentialsDialog is used to ask the user for credentials (paasword).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CredentialsDialog extends InputDialog
+{
+
+    /**
+     * Creates a new instance of CredentialsDialog.
+     * 
+     * @param parentShell the parent shell
+     * @param dialogTitle the dialog title
+     * @param dialogMessage the dialog message
+     * @param initialValue the initial value
+     * @param validator the validator
+     */
+    public CredentialsDialog( Shell parentShell, String dialogTitle, String dialogMessage, String initialValue,
+        IInputValidator validator )
+    {
+        super( parentShell, dialogTitle, dialogMessage, initialValue, validator );
+    }
+
+
+    /**
+     * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        super.getText().setEchoChar( '*' );
+        return composite;
+    }
+
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java Thu Aug 23 06:47:09 2007
@@ -0,0 +1,194 @@
+/*
+ *  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.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+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.ConnectionManager;
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link Connection} objects.
+ * Note that only the connection name is converted to a platform specific 
+ * representation, not the complete object. To convert it back to an {@link Connection} 
+ * object the {@link ConnectionManager#getConnection(String)} method is invoked.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionTransfer extends ByteArrayTransfer
+{
+
+    /** The Constant TYPENAME. */
+    private static final String TYPENAME = "org.apache.directory.studio.ldapbrowser.connection";
+
+    /** The Constant TYPEID. */
+    private static final int TYPEID = registerType( TYPENAME );
+
+    /** The instance. */
+    private static ConnectionTransfer instance = new ConnectionTransfer();
+
+
+    /**
+     * Creates a new instance of ConnectionTransfer.
+     */
+    private ConnectionTransfer()
+    {
+    }
+
+
+    /**
+     * Gets the instance.
+     * 
+     * @return the instance
+     */
+    public static ConnectionTransfer getInstance()
+    {
+        return instance;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation only accepts {@link Connection} objects. 
+     * It just converts the name of the connection to the platform 
+     * specific representation.
+     */
+    public void javaToNative( Object object, TransferData transferData )
+    {
+        if ( object == null || !( object instanceof Connection[] ) )
+        {
+            return;
+        }
+
+        if ( isSupportedType( transferData ) )
+        {
+            Connection[] connections = ( Connection[] ) object;
+            try
+            {
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                DataOutputStream writeOut = new DataOutputStream( out );
+
+                for ( int i = 0; i < connections.length; i++ )
+                {
+                    byte[] name = connections[i].getName().getBytes();
+                    writeOut.writeInt( name.length );
+                    writeOut.write( name );
+                }
+
+                byte[] buffer = out.toByteArray();
+                writeOut.close();
+
+                super.javaToNative( buffer, transferData );
+
+            }
+            catch ( IOException e )
+            {
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation just converts the platform specific representation
+     * to the connection name and invokes 
+     * {@link ConnectionManager#getConnection(String)} to get the
+     * {@link Connection} object.
+     */
+    public Object nativeToJava( TransferData transferData )
+    {
+        if ( isSupportedType( transferData ) )
+        {
+            byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+            if ( buffer == null )
+            {
+                return null;
+            }
+
+            List<Connection> connectionList = new ArrayList<Connection>();
+            try
+            {
+                ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+                DataInputStream readIn = new DataInputStream( in );
+
+                do
+                {
+                    if ( readIn.available() > 1 )
+                    {
+                        int size = readIn.readInt();
+                        byte[] connectionName = new byte[size];
+                        readIn.read( connectionName );
+                        Connection connection = ConnectionCorePlugin.getDefault().getConnectionManager().getConnection(
+                            new String( connectionName ) );
+                        connectionList.add( connection );
+                    }
+                }
+                while ( readIn.available() > 1 );
+
+                readIn.close();
+            }
+            catch ( IOException ex )
+            {
+                return null;
+            }
+
+            return connectionList.toArray( new Connection[0] );
+        }
+
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected String[] getTypeNames()
+    {
+        return new String[]
+            { TYPENAME };
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected int[] getTypeIds()
+    {
+        return new int[]
+            { TYPEID };
+    }
+
+}
\ No newline at end of file

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java Thu Aug 23 06:47:09 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.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.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.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;
+    }
+
+
+    /**
+     * @see org.eclipse.jface.preference.PreferencePage#performOk()
+     */
+    public boolean performOk()
+    {
+        // get current connection parameters
+        Connection connection = ( Connection ) getConnection( getElement() );
+        ConnectionParameter connectionParameter = connection.getConnectionParameter();
+        
+        // save modified parameters
+        for ( int i = 0; i < pages.length; i++ )
+        {
+            pages[i].saveParameters( connectionParameter );
+            pages[i].saveDialogSettings();
+        }
+        
+        // update persistent connection
+        connection.setConnectionParameter( connectionParameter );
+        connection.setName( connection.getName() );
+        connection.setHost( connection.getHost() );
+        
+        // close connection
+        new CloseConnectionsJob( connection ).execute();
+
+        return true;
+    }
+
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java Thu Aug 23 06:47:09 2007
@@ -0,0 +1,329 @@
+/*
+ *  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 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;
+            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;
+    }
+
+
+    /**
+     * 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.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( "" ) );
+
+        // 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.";
+            }
+        }
+    }
+
+
+    /**
+     * 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 );
+    }
+
+
+    /**
+     * @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 : 0;
+        authenticationMethodCombo.select( index );
+        bindPrincipalCombo.setText( parameter.getBindPrincipal() );
+        bindPasswordText.setText( parameter.getBindPassword() != null ? parameter.getBindPassword() : "" );
+        saveBindPasswordButton.setSelection( parameter.getBindPassword() != null );
+
+        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() );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveDialogSettings()
+     */
+    public void saveDialogSettings()
+    {
+        HistoryUtils.save( ConnectionUIConstants.DIALOGSETTING_KEY_PRINCIPAL_HISTORY, bindPrincipalCombo.getText() );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#setFocus()
+     */
+    public void setFocus()
+    {
+        bindPrincipalCombo.setFocus();
+    }
+
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/BaseWidgetUtils.java Thu Aug 23 06:47:09 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;
+    }
+
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java Thu Aug 23 06:47:09 2007
@@ -0,0 +1,325 @@
+/*
+ *  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.StudioActionProxy;
+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.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.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.TableViewer;
+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 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 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>();
+
+        TableViewer viewer = mainWidget.getViewer();
+        connectionActionMap.put( newConnectionAction, new ConnectionViewActionProxy( viewer, this,
+            new NewConnectionAction() ) );
+        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() ) );
+    }
+
+
+    /**
+     * Disposes this action group.
+     */
+    public void dispose()
+    {
+        if ( mainWidget != null )
+        {
+            for ( Iterator it = connectionActionMap.keySet().iterator(); it.hasNext(); )
+            {
+                String key = ( String ) it.next();
+                ConnectionViewActionProxy action = ( ConnectionViewActionProxy ) this.connectionActionMap.get( key );
+                action.dispose();
+                action = null;
+                it.remove();
+            }
+            connectionActionMap.clear();
+            connectionActionMap = null;
+
+            actionBars = null;
+            mainWidget = 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( 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 );
+
+            }
+        }
+    }
+
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java Thu Aug 23 06:47:09 2007
@@ -0,0 +1,147 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.connection.ui.widgets;
+
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.TableViewer;
+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 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( TableViewer 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( TableViewer 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( TableViewer viewer )
+    {
+        if ( labelProvider == null )
+        {
+            labelProvider = new ConnectionLabelProvider();
+        }
+
+        return labelProvider;
+    }
+
+}

Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java?rev=568990&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java Thu Aug 23 06:47:09 2007
@@ -0,0 +1,79 @@
+/*
+ *  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.ConnectionManager;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+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 IStructuredContentProvider
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation does nothing.
+     */
+    public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation does nothing.
+     */
+    public void dispose()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation accepts the ConnectionManager and returns its connections.
+     */
+    public Object[] getElements( Object inputElement )
+    {
+        if ( inputElement != null && inputElement instanceof ConnectionManager )
+        {
+            ConnectionManager cm = ( ConnectionManager ) inputElement;
+            return cm.getConnections();
+        }
+        else
+        {
+            return new Object[]
+                {};
+        }
+    }
+
+}
\ No newline at end of file



Mime
View raw message