You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/12/18 18:57:49 UTC

svn commit: r488371 [7/14] - in /directory/sandbox/pamarcelot/ldapstudio: ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/jobs/ ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/perspective/ ldapstudio-browser-ui...

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/browser/OpenSortDialogAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/browser/OpenSortDialogAction.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/browser/OpenSortDialogAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/browser/OpenSortDialogAction.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.PlatformUI;
+
+
+public class OpenSortDialogAction extends Action
+{
+
+    private BrowserPreferences preferences;
+
+
+    public OpenSortDialogAction( BrowserPreferences preferences )
+    {
+        super( "Sorting...", BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_SORT ) );
+        super.setEnabled( true );
+
+        this.preferences = preferences;
+    }
+
+
+    public void run()
+    {
+        BrowserSorterDialog dlg = new BrowserSorterDialog( PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+            this.preferences );
+        dlg.open();
+    }
+
+
+    public void dispose()
+    {
+        this.preferences = null;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionActionGroup.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionActionGroup.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionActionGroup.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionActionGroup.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,271 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.connection;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.ui.actions.CloseConnectionAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.CopyAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.DeleteAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.NewConnectionAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.OpenConnectionAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.PasteAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.PropertiesAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.RenameAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.proxy.ConnectionViewActionProxy;
+import org.apache.directory.ldapstudio.browser.ui.actions.proxy.BrowserActionProxy;
+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;
+
+
+public class ConnectionActionGroup implements IMenuListener
+{
+
+    protected static final String newConnectionAction = "newConnectionAction";
+
+    protected static final String openConnectionAction = "openConnectionAction";
+
+    protected static final String closeConnectionAction = "closeConnectionAction";
+
+    protected static final String copyConnectionAction = "copyConnectionAction";
+
+    protected static final String pasteConnectionAction = "pasteConnectionAction";
+
+    protected static final String deleteConnectionAction = "deleteConnectionAction";
+
+    protected static final String renameConnectionAction = "renameConnectionAction";
+
+    protected static final String propertyDialogAction = "propertyDialogAction";
+
+    protected Map connectionActionMap;
+
+    protected IActionBars actionBars;
+
+    protected ConnectionWidget mainWidget;
+
+
+    public ConnectionActionGroup( ConnectionWidget mainWidget, ConnectionConfiguration configuration )
+    {
+        this.mainWidget = mainWidget;
+        this.connectionActionMap = new HashMap();
+        TableViewer viewer = mainWidget.getViewer();
+
+        this.connectionActionMap.put( newConnectionAction, new ConnectionViewActionProxy( viewer,
+            new NewConnectionAction() ) );
+        this.connectionActionMap.put( openConnectionAction, new ConnectionViewActionProxy( viewer,
+            new OpenConnectionAction() ) );
+        this.connectionActionMap.put( closeConnectionAction, new ConnectionViewActionProxy( viewer,
+            new CloseConnectionAction() ) );
+        this.connectionActionMap
+            .put( pasteConnectionAction, new ConnectionViewActionProxy( viewer, new PasteAction() ) );
+        this.connectionActionMap.put( copyConnectionAction, new ConnectionViewActionProxy( viewer, new CopyAction(
+            ( BrowserActionProxy ) this.connectionActionMap.get( pasteConnectionAction ) ) ) );
+        this.connectionActionMap.put( deleteConnectionAction,
+            new ConnectionViewActionProxy( viewer, new DeleteAction() ) );
+        this.connectionActionMap.put( renameConnectionAction,
+            new ConnectionViewActionProxy( viewer, new RenameAction() ) );
+        this.connectionActionMap.put( propertyDialogAction, new ConnectionViewActionProxy( viewer,
+            new PropertiesAction() ) );
+
+    }
+
+
+    public void dispose()
+    {
+        if ( this.mainWidget != null )
+        {
+
+            for ( Iterator it = this.connectionActionMap.keySet().iterator(); it.hasNext(); )
+            {
+                String key = ( String ) it.next();
+                ConnectionViewActionProxy action = ( ConnectionViewActionProxy ) this.connectionActionMap.get( key );
+                action.dispose();
+                action = null;
+                it.remove();
+            }
+            this.connectionActionMap.clear();
+            this.connectionActionMap = null;
+
+            this.actionBars = null;
+            this.mainWidget = null;
+        }
+    }
+
+
+    public void enableGlobalActionHandlers( IActionBars actionBars )
+    {
+        this.actionBars = actionBars;
+        this.activateGlobalActionHandlers();
+    }
+
+
+    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 );
+
+    }
+
+
+    public void fillMenu( IMenuManager menuManager )
+    {
+        // menuManager.add(this.openSortDialogAction);
+        // menuManager.add(new Separator());
+        // menuManager.update(true);
+    }
+
+
+    public void fillContextMenu( IMenuManager menuManager )
+    {
+        menuManager.setRemoveAllWhenShown( true );
+        menuManager.addMenuListener( this );
+    }
+
+
+    public void menuAboutToShow( IMenuManager menuManager )
+    {
+
+        // add
+        menuManager.add( ( IAction ) this.connectionActionMap.get( newConnectionAction ) );
+        menuManager.add( new Separator() );
+
+        // open/close
+        if ( ( ( IAction ) this.connectionActionMap.get( closeConnectionAction ) ).isEnabled() )
+            menuManager.add( ( IAction ) this.connectionActionMap.get( closeConnectionAction ) );
+        else if ( ( ( IAction ) this.connectionActionMap.get( openConnectionAction ) ).isEnabled() )
+            menuManager.add( ( IAction ) this.connectionActionMap.get( openConnectionAction ) );
+        menuManager.add( new Separator() );
+
+        // copy/paste/...
+        menuManager.add( ( IAction ) this.connectionActionMap.get( copyConnectionAction ) );
+        menuManager.add( ( IAction ) this.connectionActionMap.get( pasteConnectionAction ) );
+        menuManager.add( ( IAction ) this.connectionActionMap.get( deleteConnectionAction ) );
+        menuManager.add( ( IAction ) this.connectionActionMap.get( renameConnectionAction ) );
+        menuManager.add( new Separator() );
+
+        // additions
+        menuManager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );
+
+        // properties
+        menuManager.add( ( IAction ) this.connectionActionMap.get( propertyDialogAction ) );
+    }
+
+
+    public void activateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( this.actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), ( IAction ) this.connectionActionMap
+                .get( copyConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), ( IAction ) this.connectionActionMap
+                .get( pasteConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), ( IAction ) this.connectionActionMap
+                .get( deleteConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.RENAME.getId(), ( IAction ) this.connectionActionMap
+                .get( renameConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), ( IAction ) this.connectionActionMap
+                .get( propertyDialogAction ) );
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction ca = ( IAction ) this.connectionActionMap.get( copyConnectionAction );
+                ca.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.copy" );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( new ActionHandler( ca ) );
+
+                IAction pa = ( IAction ) this.connectionActionMap.get( pasteConnectionAction );
+                pa.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.paste" );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( new ActionHandler( pa ) );
+
+                IAction da = ( IAction ) this.connectionActionMap.get( deleteConnectionAction );
+                da.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.delete" );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( new ActionHandler( da ) );
+
+                IAction pda = ( IAction ) this.connectionActionMap.get( propertyDialogAction );
+                pda.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.properties" );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( new ActionHandler( pda ) );
+
+            }
+        }
+
+    }
+
+
+    public void deactivateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( this.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 ) this.connectionActionMap.get( copyConnectionAction );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( null );
+
+                IAction pa = ( IAction ) this.connectionActionMap.get( pasteConnectionAction );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( null );
+
+                IAction da = ( IAction ) this.connectionActionMap.get( deleteConnectionAction );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( null );
+
+                IAction pda = ( IAction ) this.connectionActionMap.get( propertyDialogAction );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( null );
+
+            }
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionConfiguration.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionConfiguration.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionConfiguration.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,100 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.connection;
+
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.widgets.Menu;
+
+
+public class ConnectionConfiguration
+{
+
+    private boolean disposed = false;
+
+    private ConnectionContentProvider contentProvider;
+
+    private ConnectionLabelProvider labelProvider;
+
+    private MenuManager contextMenuManager;
+
+
+    public ConnectionConfiguration()
+    {
+    }
+
+
+    public void dispose()
+    {
+        if ( !this.disposed )
+        {
+
+            if ( this.contentProvider != null )
+                this.contentProvider.dispose();
+            this.contentProvider = null;
+
+            if ( this.labelProvider != null )
+                this.labelProvider.dispose();
+            this.labelProvider = null;
+
+            if ( this.contextMenuManager != null )
+                this.contextMenuManager.dispose();
+            this.contextMenuManager = null;
+
+            this.disposed = true;
+        }
+    }
+
+
+    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;
+    }
+
+
+    public ConnectionContentProvider getContentProvider( TableViewer viewer )
+    {
+        if ( this.contentProvider == null )
+            this.contentProvider = new ConnectionContentProvider();
+
+        return contentProvider;
+    }
+
+
+    public ConnectionLabelProvider getLabelProvider( TableViewer viewer )
+    {
+        if ( this.labelProvider == null )
+        {
+            this.labelProvider = new ConnectionLabelProvider();
+        }
+
+        return labelProvider;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionContentProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionContentProvider.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionContentProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionContentProvider.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,57 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+public class ConnectionContentProvider implements IStructuredContentProvider
+{
+
+    public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+    {
+    }
+
+
+    public void dispose()
+    {
+    }
+
+
+    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

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionLabelProvider.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionLabelProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionLabelProvider.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,73 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+
+public class ConnectionLabelProvider extends LabelProvider
+{
+
+    public String getText( Object obj )
+    {
+        if ( obj instanceof IConnection )
+        {
+            IConnection conn = ( IConnection ) obj;
+            if ( conn.getEncryptionMethod() == IConnection.ENCYRPTION_LDAPS )
+                return conn.getName() + " (LDAPS)";
+            else if ( conn.getEncryptionMethod() == IConnection.ENCYRPTION_STARTTLS )
+                return conn.getName() + " (StartTLS)";
+            else
+                return conn.getName();
+        }
+        else if ( obj != null )
+        {
+            return obj.toString();
+        }
+        else
+        {
+            return "";
+        }
+    }
+
+
+    public Image getImage( Object obj )
+    {
+        if ( obj instanceof IConnection )
+        {
+            IConnection conn = ( IConnection ) obj;
+            return conn.isOpened() ? BrowserUIPlugin.getDefault()
+                .getImage( BrowserUIConstants.IMG_CONNECTION_CONNECTED ) : BrowserUIPlugin.getDefault().getImage(
+                BrowserUIConstants.IMG_CONNECTION_DISCONNECTED );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+}
\ No newline at end of file

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionPageModifyListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionPageModifyListener.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionPageModifyListener.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionPageModifyListener.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+
+
+public interface ConnectionPageModifyListener
+{
+
+    public void connectionPageModified();
+
+
+    public void setMessage( String message );
+
+
+    public void setErrorMessage( String errorMessage );
+
+
+    public IConnection getRealConnection();
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionPageWrapper.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionPageWrapper.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionPageWrapper.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionPageWrapper.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,791 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.connection;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Connection;
+import org.apache.directory.ldapstudio.browser.core.jobs.CheckBindJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.CheckNetworkParameterJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.FetchBaseDNsJob;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.NameException;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.jobs.RunnableContextJobAdapter;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.HistoryUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.search.AliasesDereferencingWidget;
+import org.apache.directory.ldapstudio.browser.ui.widgets.search.LimitWidget;
+import org.apache.directory.ldapstudio.browser.ui.widgets.search.ReferralsHandlingWidget;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+
+
+public class ConnectionPageWrapper implements ModifyListener, SelectionListener
+{
+
+    private Text nameText;
+
+    private Combo hostCombo;
+
+    private Text hostText;
+
+    private Combo portCombo;
+
+    private Text portText;
+
+    private Combo encryptionMethodCombo;
+
+    private Button checkConnectionButton;
+
+    private Button autoFetchBaseDnsButton;
+
+    private Button fetchBaseDnsButton;
+
+    private Combo baseDNCombo;
+
+    private LimitWidget limitWidget;
+
+    private AliasesDereferencingWidget aliasesDereferencingWidget;
+
+    private ReferralsHandlingWidget referralsHandlingWidget;
+
+    private Button openConnectionButton;
+
+    private Button anonymousAuthButton;
+
+    private Button simpleAuthButton;
+
+    private Combo simpleAuthBindPrincipalCombo;
+
+    private Text simpleAuthBindPrincipalText;
+
+    private Text simpleAuthBindPasswordText;
+
+    private Button saveSimpleAuthBindPasswordButton;
+
+    private Button checkSimpleAuthButton;
+
+    private List listenerList;
+
+    private boolean isConnectionOpened;
+
+    private IRunnableContext runnableContext;
+
+
+    public ConnectionPageWrapper( ConnectionPageModifyListener listener, IRunnableContext runnableContext )
+    {
+        this.listenerList = new ArrayList( 5 );
+        this.listenerList.add( listener );
+        this.isConnectionOpened = listener.getRealConnection() != null && listener.getRealConnection().isOpened();
+        this.runnableContext = runnableContext;
+    }
+
+
+    public void addConnectionPageModifyListener( ConnectionPageModifyListener listener )
+    {
+        this.listenerList.add( listener );
+    }
+
+
+    public String getName()
+    {
+        return nameText.getText();
+    }
+
+
+    public String getHostName()
+    {
+        return hostCombo != null ? hostCombo.getText() : hostText.getText();
+    }
+
+
+    public int getPort()
+    {
+        return Integer.parseInt( portCombo != null ? portCombo.getText() : portText.getText() );
+    }
+
+
+    public int getEncyrptionMethod()
+    {
+        if ( this.encryptionMethodCombo != null )
+        {
+            switch ( this.encryptionMethodCombo.getSelectionIndex() )
+            {
+                case 1:
+                    return IConnection.ENCYRPTION_LDAPS;
+                case 2:
+                    return IConnection.ENCYRPTION_STARTTLS;
+                default:
+                    return IConnection.ENCYRPTION_NONE;
+            }
+        }
+        return IConnection.ENCYRPTION_NONE;
+    }
+
+
+    public boolean isAutoFetchBaseDns()
+    {
+        return autoFetchBaseDnsButton.getSelection();
+    }
+
+
+    public String getBaseDN()
+    {
+        return baseDNCombo.getText();
+    }
+
+
+    public int getCountLimit()
+    {
+        return limitWidget.getCountLimit();
+    }
+
+
+    public int getTimeLimit()
+    {
+        return limitWidget.getTimeLimit();
+    }
+
+
+    public int getAliasesDereferencingMethod()
+    {
+        return aliasesDereferencingWidget.getAliasesDereferencingMethod();
+    }
+
+
+    public int getReferralsHandlingMethod()
+    {
+        return referralsHandlingWidget.getReferralsHandlingMethod();
+    }
+
+
+    public void setOpenConnectionOnFinish( boolean b )
+    {
+        if ( openConnectionButton != null )
+        {
+            openConnectionButton.setSelection( b );
+        }
+    }
+
+
+    public boolean isOpenConnectionOnFinish()
+    {
+        return openConnectionButton.getSelection();
+    }
+
+
+    public int getAuthenticationMethod()
+    {
+        if ( this.anonymousAuthButton.getSelection() )
+        {
+            return IConnection.AUTH_ANONYMOUS;
+        }
+        else if ( this.simpleAuthButton.getSelection() )
+        {
+            return IConnection.AUTH_SIMPLE;
+        }
+
+        return IConnection.AUTH_ANONYMOUS;
+    }
+
+
+    public String getSimpleAuthBindDN()
+    {
+        return simpleAuthBindPrincipalCombo != null ? simpleAuthBindPrincipalCombo.getText()
+            : simpleAuthBindPrincipalText.getText();
+    }
+
+
+    public String getSimpleAuthBindPassword()
+    {
+        return simpleAuthBindPasswordText.getText();
+    }
+
+
+    public boolean isSaveSimpleAuthBindPassword()
+    {
+        return saveSimpleAuthBindPasswordButton.getSelection();
+    }
+
+
+    public void addMainInput( String name, String host, int port, int encryptionMethod, Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Composite nameComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
+        BaseWidgetUtils.createLabel( nameComposite, "Connection name:", 1 );
+        nameText = BaseWidgetUtils.createText( nameComposite, name, 1 );
+        nameText.addModifyListener( this );
+
+        BaseWidgetUtils.createSpacer( composite, 1 );
+
+        Group group = BaseWidgetUtils.createGroup( composite, "Network Parameter", 1 );
+
+        Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 );
+        BaseWidgetUtils.createLabel( groupComposite, "Hostname:", 1 );
+        if ( isConnectionOpened )
+        {
+            hostText = BaseWidgetUtils.createReadonlyText( groupComposite, host, 2 );
+        }
+        else
+        {
+            String[] hostHistory = HistoryUtils.load( BrowserUIConstants.DIALOGSETTING_KEY_HOST_HISTORY );
+            hostCombo = BaseWidgetUtils.createCombo( groupComposite, hostHistory, -1, 2 );
+            hostCombo.setText( host );
+            hostCombo.addModifyListener( this );
+        }
+
+        BaseWidgetUtils.createLabel( groupComposite, "Port:", 1 );
+        if ( isConnectionOpened )
+        {
+            portText = BaseWidgetUtils.createReadonlyText( groupComposite, Integer.toString( port ), 2 );
+        }
+        else
+        {
+            String[] portHistory = HistoryUtils.load( BrowserUIConstants.DIALOGSETTING_KEY_PORT_HISTORY );
+            portCombo = BaseWidgetUtils.createCombo( groupComposite, portHistory, -1, 2 );
+            portCombo.setText( Integer.toString( port ) );
+            portCombo.addVerifyListener( new VerifyListener()
+            {
+                public void verifyText( VerifyEvent e )
+                {
+                    if ( !e.text.matches( "[0-9]*" ) )
+                    {
+                        e.doit = false;
+                    }
+                    if ( portCombo.getText().length() > 4 && e.text.length() > 0 )
+                    {
+                        e.doit = false;
+                    }
+                }
+            } );
+            portCombo.addModifyListener( this );
+        }
+
+        String[] encMethods = new String[]
+            { "No encryption", "Use SSL encryption (ldaps://)", "Use StartTLS extension" };
+        BaseWidgetUtils.createLabel( groupComposite, "Encryption method:", 1 );
+        this.encryptionMethodCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, encMethods, encryptionMethod,
+            2 );
+        this.encryptionMethodCombo.addSelectionListener( this );
+        BaseWidgetUtils.createSpacer( groupComposite, 1 );
+        BaseWidgetUtils
+            .createLabel(
+                groupComposite,
+                "Warning: The current version doesn't support certificate validation, \nbe aware of invalid certificates or man-in-the-middle attacks!",
+                2 );
+
+        BaseWidgetUtils.createSpacer( groupComposite, 2 );
+        checkConnectionButton = new Button( groupComposite, SWT.PUSH );
+        GridData gd = new GridData();
+        gd.horizontalAlignment = SWT.RIGHT;
+        gd.verticalAlignment = SWT.BOTTOM;
+        checkConnectionButton.setLayoutData( gd );
+        checkConnectionButton.setText( "Check Network Parameter" );
+        checkConnectionButton.setEnabled( !isConnectionOpened );
+        checkConnectionButton.addSelectionListener( new SelectionListener()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                IConnection connection = getTestConnection();
+                CheckNetworkParameterJob job = new CheckNetworkParameterJob( connection );
+                RunnableContextJobAdapter.execute( job, runnableContext );
+                if ( job.getExternalResult().isOK() )
+                {
+                    MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check Network Parameter",
+                        "The connection was established successfully." );
+                }
+            }
+
+
+            public void widgetDefaultSelected( SelectionEvent e )
+            {
+            }
+        } );
+
+        this.setEnabled();
+    }
+
+
+    public void addBaseDNInput( boolean autoFetchBaseDNs, String baseDN, Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Group group = BaseWidgetUtils.createGroup( composite, "Base DN", 1 );
+        Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 );
+        GridData gd;
+
+        autoFetchBaseDnsButton = BaseWidgetUtils.createCheckbox( groupComposite, "Get base DNs from Root DSE", 2 );
+        autoFetchBaseDnsButton.setSelection( autoFetchBaseDNs );
+        autoFetchBaseDnsButton.addSelectionListener( this );
+
+        fetchBaseDnsButton = new Button( groupComposite, SWT.PUSH );
+        fetchBaseDnsButton.setText( "Fetch Base DNs" );
+        fetchBaseDnsButton.setEnabled( true );
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.RIGHT;
+        fetchBaseDnsButton.setLayoutData( gd );
+        fetchBaseDnsButton.addSelectionListener( new SelectionListener()
+        {
+
+            public void widgetSelected( SelectionEvent e )
+            {
+                IConnection connection = getTestConnection();
+
+                FetchBaseDNsJob job = new FetchBaseDNsJob( connection );
+                RunnableContextJobAdapter.execute( job, runnableContext );
+                if ( job.getExternalResult().isOK() )
+                {
+                    if ( job.getBaseDNs().length > 0 )
+                    {
+                        String[] baseDNs = job.getBaseDNs();
+                        baseDNCombo.setItems( baseDNs );
+                        baseDNCombo.select( 0 );
+
+                        String msg = "The server returned the following base DNs:";
+                        for ( int i = 0; i < baseDNs.length; i++ )
+                        {
+                            msg += "\n  - " + baseDNs[i];
+                        }
+                        MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Fetch Base DNs", msg );
+                    }
+                    else
+                    {
+                        MessageDialog.openWarning( Display.getDefault().getActiveShell(), "Fetch Base DNs",
+                            "No base DN returned from server. Please enter the base DN manually." );
+                        autoFetchBaseDnsButton.setSelection( false );
+                    }
+                }
+            }
+
+
+            public void widgetDefaultSelected( SelectionEvent e )
+            {
+            }
+        } );
+
+        BaseWidgetUtils.createLabel( groupComposite, "Base DN:", 1 );
+        baseDNCombo = BaseWidgetUtils.createCombo( groupComposite, new String[]
+            { baseDN.toString() }, 0, 2 );
+        baseDNCombo.setText( baseDN.toString() );
+        baseDNCombo.addModifyListener( this );
+
+        this.setEnabled();
+    }
+
+
+    public void addLimitInput( int countLimit, int timeLimit, int aliasesDereferencingMethod,
+        int referralsHandlingMethod, Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
+
+        limitWidget = new LimitWidget( countLimit, timeLimit );
+        limitWidget.createWidget( composite );
+
+        aliasesDereferencingWidget = new AliasesDereferencingWidget( aliasesDereferencingMethod );
+        aliasesDereferencingWidget.createWidget( composite );
+
+        referralsHandlingWidget = new ReferralsHandlingWidget( referralsHandlingMethod );
+        referralsHandlingWidget.createWidget( composite );
+
+        this.setEnabled();
+    }
+
+
+    public void addOpenConnectionInput( boolean openConnectionOnFinish, Composite parent )
+    {
+        openConnectionButton = BaseWidgetUtils.createCheckbox( parent, "Open connection on finish", 1 );
+        openConnectionButton.setSelection( openConnectionOnFinish );
+        openConnectionButton.addSelectionListener( this );
+    }
+
+
+    public void addAuthenticationMethodInput( int authMethod, Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Group group = BaseWidgetUtils.createGroup( composite, "Authentication Method", 1 );
+        Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 );
+
+        anonymousAuthButton = BaseWidgetUtils.createRadiobutton( groupComposite, "Anonymous Authentication", 1 );
+        anonymousAuthButton.setSelection( authMethod == IConnection.AUTH_ANONYMOUS );
+        anonymousAuthButton.addSelectionListener( this );
+
+        simpleAuthButton = BaseWidgetUtils.createRadiobutton( groupComposite, "Simple Authentication", 1 );
+        simpleAuthButton.setSelection( authMethod == IConnection.AUTH_SIMPLE );
+        simpleAuthButton.addSelectionListener( this );
+
+        // saslAuthButton = new Button(authenticationMethodGroup, SWT.RADIO);
+        // saslAuthButton.setText("SASL Authentication");
+        // saslAuthButton.setSelection(authMethod ==
+        // ConnectionParameter.AUTH_SASL);
+        // saslAuthButton.addSelectionListener(this);
+    }
+
+
+    public void addSimpleAuthInput( boolean saveBindPassword, String bindPrincipal, String bindPassword,
+        Composite parent )
+    {
+
+        Composite composite2 = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        Group group = BaseWidgetUtils.createGroup( composite2, "Authentication Parameter", 1 );
+        Composite composite = BaseWidgetUtils.createColumnContainer( group, 3, 1 );
+
+        BaseWidgetUtils.createLabel( composite, "Bind DN or user:", 1 );
+        if ( isConnectionOpened )
+        {
+            simpleAuthBindPrincipalText = BaseWidgetUtils.createReadonlyText( composite, bindPrincipal, 2 );
+        }
+        else
+        {
+            String[] dnHistory = HistoryUtils.load( BrowserUIConstants.DIALOGSETTING_KEY_DN_HISTORY );
+            simpleAuthBindPrincipalCombo = BaseWidgetUtils.createCombo( composite, dnHistory, -1, 2 );
+            simpleAuthBindPrincipalCombo.setText( bindPrincipal );
+            simpleAuthBindPrincipalCombo.addModifyListener( this );
+        }
+
+        BaseWidgetUtils.createLabel( composite, "Bind password:", 1 );
+        if ( isConnectionOpened )
+        {
+            simpleAuthBindPasswordText = BaseWidgetUtils.createReadonlyPasswordText( composite, bindPassword, 2 );
+        }
+        else
+        {
+            simpleAuthBindPasswordText = BaseWidgetUtils.createPasswordText( composite, bindPassword, 2 );
+        }
+        simpleAuthBindPasswordText.addModifyListener( this );
+
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        saveSimpleAuthBindPasswordButton = BaseWidgetUtils.createCheckbox( composite, "Save password", 1 );
+        saveSimpleAuthBindPasswordButton.setSelection( saveBindPassword );
+        saveSimpleAuthBindPasswordButton.addSelectionListener( this );
+
+        checkSimpleAuthButton = new Button( composite, SWT.PUSH );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalAlignment = SWT.RIGHT;
+        checkSimpleAuthButton.setLayoutData( gd );
+        checkSimpleAuthButton.setText( "Check Authentication" );
+        checkSimpleAuthButton.setEnabled( false );
+        checkSimpleAuthButton.addSelectionListener( new SelectionListener()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                IConnection connection = getTestConnection();
+                CheckBindJob job = new CheckBindJob( connection );
+                RunnableContextJobAdapter.execute( job, runnableContext );
+                if ( job.getExternalResult().isOK() )
+                {
+                    MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check Authentication",
+                        "The authentication was successful." );
+                }
+            }
+
+
+            public void widgetDefaultSelected( SelectionEvent e )
+            {
+            }
+        } );
+        this.setEnabled();
+    }
+
+
+    private void fireConnectionPageModified()
+    {
+        for ( Iterator it = listenerList.iterator(); it.hasNext(); )
+        {
+            ( ( ConnectionPageModifyListener ) it.next() ).connectionPageModified();
+        }
+    }
+
+
+    private void setEnabled()
+    {
+
+        if ( isConnectionOpened )
+        {
+            if ( this.encryptionMethodCombo != null && this.checkConnectionButton != null )
+            {
+                this.encryptionMethodCombo.setEnabled( false );
+                this.checkConnectionButton.setEnabled( false );
+            }
+
+            if ( this.baseDNCombo != null && this.autoFetchBaseDnsButton != null )
+            {
+                this.autoFetchBaseDnsButton.setEnabled( false );
+                this.baseDNCombo.setEnabled( false );
+                this.fetchBaseDnsButton.setEnabled( false );
+            }
+
+            if ( this.anonymousAuthButton != null && this.simpleAuthButton != null )
+            {
+                this.anonymousAuthButton.setEnabled( false );
+                this.simpleAuthButton.setEnabled( false );
+            }
+            if ( this.saveSimpleAuthBindPasswordButton != null && this.saveSimpleAuthBindPasswordButton != null )
+            {
+                this.saveSimpleAuthBindPasswordButton.setEnabled( false );
+                this.checkSimpleAuthButton.setEnabled( false );
+            }
+        }
+        else
+        {
+            if ( this.hostCombo != null && this.portCombo != null && this.checkConnectionButton != null )
+            {
+                if ( !this.hostCombo.getText().equals( "" ) && !this.hostCombo.getText().equals( "" ) )
+                {
+                    this.checkConnectionButton.setEnabled( true );
+                }
+                else
+                {
+                    this.checkConnectionButton.setEnabled( false );
+                }
+            }
+
+            if ( this.baseDNCombo != null && this.autoFetchBaseDnsButton != null )
+            {
+                if ( autoFetchBaseDnsButton.getSelection() )
+                {
+                    this.baseDNCombo.setEnabled( false );
+                }
+                else
+                {
+                    this.baseDNCombo.setEnabled( true );
+                }
+            }
+            if ( this.simpleAuthBindPrincipalCombo != null && this.simpleAuthBindPasswordText != null
+                && this.saveSimpleAuthBindPasswordButton != null )
+            {
+                boolean simpleAuthSelected = simpleAuthButton == null || simpleAuthButton.getSelection();
+                simpleAuthBindPrincipalCombo.setEnabled( simpleAuthSelected );
+                simpleAuthBindPasswordText.setEnabled( saveSimpleAuthBindPasswordButton.getSelection()
+                    && simpleAuthSelected );
+                saveSimpleAuthBindPasswordButton.setEnabled( simpleAuthSelected );
+                // try {
+                // new DN(simpleAuthBindPrincipalCombo.getText());
+                checkSimpleAuthButton.setEnabled( saveSimpleAuthBindPasswordButton.getSelection()
+                    && !simpleAuthBindPrincipalCombo.getText().equals( "" )
+                    && !simpleAuthBindPasswordText.getText().equals( "" ) && simpleAuthSelected );
+                // }
+                // catch (NameException e) {
+                // checkSimpleAuthButton.setEnabled(false);
+                // }
+            }
+        }
+    }
+
+
+    private void validate()
+    {
+        String message = null;
+        String errorMessage = null;
+
+        boolean simpleAuthSelected = simpleAuthButton == null || simpleAuthButton.getSelection();
+
+        if ( baseDNCombo != null && baseDNCombo.isVisible() )
+        {
+            if ( !autoFetchBaseDnsButton.getSelection() && "".equals( baseDNCombo.getText() ) )
+            {
+                message = "Please enter a base DN. You can use the 'Fetch base DN' button to fetch valid base DNs from directory.";
+            }
+            else
+            {
+                try
+                {
+                    /* DN baseDn = */new DN( baseDNCombo.getText() );
+                }
+                catch ( NameException e )
+                {
+                    message = "Please enter a valid base DN.";
+                }
+            }
+        }
+        if ( simpleAuthBindPasswordText != null && simpleAuthSelected && simpleAuthBindPasswordText.isVisible() )
+        {
+            if ( saveSimpleAuthBindPasswordButton.getSelection() && "".equals( simpleAuthBindPasswordText.getText() ) )
+            {
+                message = "Please enter a bind password.";
+            }
+        }
+        if ( simpleAuthBindPrincipalCombo != null && simpleAuthSelected && simpleAuthBindPrincipalCombo.isVisible() )
+        {
+            if ( "".equals( simpleAuthBindPrincipalCombo.getText() ) )
+            {
+                message = "Please enter a bind DN or user.";
+            }
+            else
+            {
+                // try {
+                // new DN(simpleAuthBindPrincipalCombo.getText());
+                // }
+                // catch (NameException e) {
+                // message = "Please enter a valid bind DN.";
+                // }
+            }
+
+        }
+        if ( portCombo != null && portCombo.isVisible() )
+        {
+            if ( "".equals( portCombo.getText() ) )
+            {
+                message = "Please enter a port. The default LDAP port is 389.";
+            }
+        }
+        if ( hostCombo != null && hostCombo.isVisible() )
+        {
+            if ( "".equals( hostCombo.getText() ) )
+            {
+                message = "Please enter a hostname.";
+            }
+        }
+        if ( nameText != null && nameText.isVisible() )
+        {
+            if ( "".equals( nameText.getText() ) )
+            {
+                message = "Please enter a connection name.";
+            }
+            if ( BrowserCorePlugin.getDefault().getConnectionManager().getConnection( nameText.getText() ) != null
+                && BrowserCorePlugin.getDefault().getConnectionManager().getConnection( nameText.getText() ) != ( ( ConnectionPageModifyListener ) listenerList
+                    .get( 0 ) ).getRealConnection() )
+            {
+                errorMessage = "A connection named '" + nameText.getText() + "' already exists.";
+            }
+        }
+
+        for ( Iterator it = listenerList.iterator(); it.hasNext(); )
+        {
+            ConnectionPageModifyListener listener = ( ConnectionPageModifyListener ) it.next();
+            listener.setMessage( message );
+            listener.setErrorMessage( errorMessage );
+        }
+    }
+
+
+    public void modifyText( ModifyEvent e )
+    {
+        this.setEnabled();
+        this.validate();
+        this.fireConnectionPageModified();
+    }
+
+
+    public void widgetSelected( SelectionEvent e )
+    {
+        this.setEnabled();
+        this.validate();
+        this.fireConnectionPageModified();
+    }
+
+
+    public void widgetDefaultSelected( SelectionEvent e )
+    {
+        this.setEnabled();
+        this.validate();
+        this.fireConnectionPageModified();
+    }
+
+
+    public IConnection getTestConnection()
+    {
+        if ( getAuthenticationMethod() == IConnection.AUTH_ANONYMOUS )
+        {
+            Connection conn;
+            try
+            {
+                conn = new Connection( null, getHostName(), getPort(), getEncyrptionMethod(), isAutoFetchBaseDns(),
+                    new DN( getBaseDN() ), getCountLimit(), getTimeLimit(), getAliasesDereferencingMethod(),
+                    getReferralsHandlingMethod(), IConnection.AUTH_ANONYMOUS, null, null );
+            }
+            catch ( NameException e )
+            {
+                conn = null;
+            }
+            return conn;
+        }
+        else if ( getAuthenticationMethod() == IConnection.AUTH_SIMPLE )
+        {
+            Connection conn;
+            try
+            {
+                conn = new Connection( null, getHostName(), getPort(), getEncyrptionMethod(), isAutoFetchBaseDns(),
+                    new DN( getBaseDN() ), getCountLimit(), getTimeLimit(), getAliasesDereferencingMethod(),
+                    getReferralsHandlingMethod(), IConnection.AUTH_SIMPLE, getSimpleAuthBindDN(),
+                    getSimpleAuthBindPassword() );
+            }
+            catch ( NameException e )
+            {
+                conn = null;
+            }
+            return conn;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    public void saveDialogSettings()
+    {
+        if ( !isConnectionOpened )
+        {
+            if ( this.hostCombo != null )
+            {
+                HistoryUtils.save( BrowserUIConstants.DIALOGSETTING_KEY_HOST_HISTORY, this.hostCombo.getText() );
+            }
+            if ( this.portCombo != null )
+            {
+                HistoryUtils.save( BrowserUIConstants.DIALOGSETTING_KEY_PORT_HISTORY, this.portCombo.getText() );
+            }
+            if ( this.simpleAuthBindPrincipalCombo != null )
+            {
+                HistoryUtils.save( BrowserUIConstants.DIALOGSETTING_KEY_DN_HISTORY, this.simpleAuthBindPrincipalCombo
+                    .getText() );
+            }
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionUniversalListener.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionUniversalListener.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionUniversalListener.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,108 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EntryUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateListener;
+
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+
+
+public class ConnectionUniversalListener implements ConnectionUpdateListener, EntryUpdateListener,
+    SearchUpdateListener, BookmarkUpdateListener
+{
+
+    protected TableViewer viewer;
+
+
+    public ConnectionUniversalListener( TableViewer viewer )
+    {
+        this.viewer = viewer;
+
+        EventRegistry.addConnectionUpdateListener( this );
+        EventRegistry.addEntryUpdateListener( this );
+        EventRegistry.addSearchUpdateListener( this );
+        EventRegistry.addBookmarkUpdateListener( this );
+    }
+
+
+    public void dispose()
+    {
+        if ( this.viewer != null )
+        {
+            EventRegistry.removeConnectionUpdateListener( this );
+            EventRegistry.removeEntryUpdateListener( this );
+            EventRegistry.removeSearchUpdateListener( this );
+            EventRegistry.removeBookmarkUpdateListener( this );
+            this.viewer = null;
+        }
+    }
+
+
+    public void connectionUpdated( ConnectionUpdateEvent connectionUpdateEvent )
+    {
+        if ( this.viewer != null )
+        {
+            this.viewer.refresh();
+            if ( connectionUpdateEvent.getDetail() == ConnectionUpdateEvent.CONNECTION_ADDED )
+            {
+                this.viewer.setSelection( new StructuredSelection( connectionUpdateEvent.getConnection() ) );
+            }
+        }
+    }
+
+
+    public void entryUpdated( EntryModificationEvent event )
+    {
+        if ( this.viewer != null )
+        {
+            this.viewer.refresh();
+        }
+    }
+
+
+    public void searchUpdated( SearchUpdateEvent searchUpdateEvent )
+    {
+        if ( this.viewer != null )
+        {
+            this.viewer.refresh();
+        }
+    }
+
+
+    public void bookmarkUpdated( BookmarkUpdateEvent bookmarkUpdateEvent )
+    {
+        if ( this.viewer != null )
+        {
+            this.viewer.refresh();
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionWidget.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionWidget.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/connection/ConnectionWidget.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,157 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.ui.widgets.ViewFormWidget;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.IActionBars;
+
+
+public class ConnectionWidget extends ViewFormWidget
+{
+
+    private ConnectionConfiguration configuration;
+
+    private IActionBars actionBars;
+
+    private Table table;
+
+    private TableViewer viewer;
+
+
+    public ConnectionWidget( ConnectionConfiguration configuration, IActionBars actionBars )
+    {
+        this.configuration = configuration;
+        this.actionBars = actionBars;
+    }
+
+
+    public void createWidget( Composite parent )
+    {
+        if ( actionBars == null )
+        {
+            super.createWidget( parent );
+        }
+        else
+        {
+            createContent( parent );
+        }
+    }
+
+
+    public IToolBarManager getToolBarManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getToolBarManager();
+        }
+        else
+        {
+            return actionBars.getToolBarManager();
+        }
+    }
+
+
+    public IMenuManager getMenuManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getMenuManager();
+
+        }
+        else
+        {
+            return actionBars.getMenuManager();
+        }
+    }
+
+
+    public IMenuManager getContextMenuManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getContextMenuManager();
+        }
+        else
+        {
+            return configuration.getContextMenuManager( viewer );
+        }
+    }
+
+
+    protected Control createContent( Composite parent )
+    {
+
+        this.table = new Table( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 450;
+        data.heightHint = 250;
+        this.table.setLayoutData( data );
+        this.viewer = new TableViewer( this.table );
+
+        // setup providers
+        this.viewer.setContentProvider( configuration.getContentProvider( this.viewer ) );
+        this.viewer.setLabelProvider( configuration.getLabelProvider( this.viewer ) );
+
+        return this.table;
+    }
+
+
+    public void setInput( Object input )
+    {
+        this.viewer.setInput( input );
+    }
+
+
+    public void setFocus()
+    {
+        this.viewer.getTable().setFocus();
+    }
+
+
+    public void dispose()
+    {
+        if ( this.viewer != null )
+        {
+            this.configuration.dispose();
+            this.configuration = null;
+
+            this.table.dispose();
+            this.table = null;
+            this.viewer = null;
+        }
+    }
+
+
+    public TableViewer getViewer()
+    {
+        return viewer;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/AbstractEntryEditorListenerAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/AbstractEntryEditorListenerAction.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/AbstractEntryEditorListenerAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/AbstractEntryEditorListenerAction.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,165 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EntryUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.ui.actions.SelectionUtils;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+
+
+public abstract class AbstractEntryEditorListenerAction extends Action implements ISelectionChangedListener,
+    EntryUpdateListener
+{
+
+    protected ISelectionProvider selectionProvider;
+
+    protected SelectionChangedEvent currentSelectionChangedEvent;
+
+    protected IEntry selectedEntry;
+
+    protected IAttribute[] selectedAttributes;
+
+    protected IValue[] selectedValues;
+
+
+    public AbstractEntryEditorListenerAction( ISelectionProvider selectionProvider, String title,
+        ImageDescriptor image, String command, int style )
+    {
+        super( title, style );
+        super.setText( title );
+        super.setToolTipText( title );
+        super.setImageDescriptor( image );
+        super.setActionDefinitionId( command );
+        super.setEnabled( false );
+
+        this.selectionProvider = selectionProvider;
+
+        this.init();
+    }
+
+
+    public AbstractEntryEditorListenerAction( ISelectionProvider selectionProvider, String title,
+        ImageDescriptor image, String command )
+    {
+        this( selectionProvider, title, image, command, Action.AS_PUSH_BUTTON );
+    }
+
+
+    private void init()
+    {
+        this.currentSelectionChangedEvent = null;
+        this.selectedEntry = null;
+        this.selectedValues = new IValue[0];
+        this.selectedAttributes = new IAttribute[0];
+
+        this.selectionProvider.addSelectionChangedListener( this );
+        EventRegistry.addEntryUpdateListener( this );
+    }
+
+
+    public void selectionChanged( SelectionChangedEvent event )
+    {
+        this.currentSelectionChangedEvent = event;
+
+        ISelection selection = event.getSelection();
+
+        this.selectedAttributes = SelectionUtils.getAttributes( selection );
+        this.selectedValues = SelectionUtils.getValues( selection );
+
+        if ( this.selectedAttributes.length > 0 )
+        {
+            this.selectedEntry = this.selectedAttributes[0].getEntry();
+        }
+        else if ( this.selectedValues.length > 0 )
+        {
+            this.selectedEntry = this.selectedValues[0].getAttribute().getEntry();
+        }
+        else
+        {
+            this.selectedEntry = null;
+        }
+
+        this.callUpdateEnabledState();
+
+        this.currentSelectionChangedEvent = null;
+    }
+
+
+    public final void entryUpdated( EntryModificationEvent event )
+    {
+        this.callUpdateEnabledState();
+    }
+
+
+    private void callUpdateEnabledState()
+    {
+        if ( this.selectionProvider != null )
+        {
+            this.updateEnabledState();
+        }
+    }
+
+
+    protected abstract void updateEnabledState();
+
+
+    public void dispose()
+    {
+        EventRegistry.removeEntryUpdateListener( this );
+        this.selectionProvider.removeSelectionChangedListener( this );
+
+        this.currentSelectionChangedEvent = null;
+        this.selectedEntry = null;
+        this.selectedValues = new IValue[0];
+        this.selectedAttributes = new IAttribute[0];
+
+        this.selectionProvider = null;
+    }
+
+
+    protected Set getValueSet()
+    {
+        Set valueSet = new HashSet();
+        for ( int i = 0; i < this.selectedAttributes.length; i++ )
+        {
+            valueSet.addAll( Arrays.asList( this.selectedAttributes[i].getValues() ) );
+        }
+        valueSet.addAll( Arrays.asList( this.selectedValues ) );
+        return valueSet;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/AbstractOpenEditorAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/AbstractOpenEditorAction.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/AbstractOpenEditorAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/AbstractOpenEditorAction.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,172 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.ModelModifier;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProviderManager;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+
+
+public abstract class AbstractOpenEditorAction extends AbstractEntryEditorListenerAction implements FocusListener,
+    KeyListener, ModelModifier
+{
+
+    protected EntryEditorWidgetActionGroup actionGroup;
+
+    protected ValueProviderManager valueProviderManager;
+
+    protected TreeViewer viewer;
+
+    protected CellEditor cellEditor;
+
+
+    protected AbstractOpenEditorAction( TreeViewer viewer, EntryEditorWidgetActionGroup actionGroup,
+        ValueProviderManager valueProviderManager )
+    {
+        super( viewer, "Editor", null, null );
+        this.viewer = viewer;
+        this.actionGroup = actionGroup;
+        this.valueProviderManager = valueProviderManager;
+    }
+
+
+    public void dispose()
+    {
+        this.valueProviderManager = null;
+        this.actionGroup = null;
+        this.viewer = null;
+        this.cellEditor = null;
+        super.dispose();
+    }
+
+
+    public CellEditor getCellEditor()
+    {
+        return this.cellEditor;
+    }
+
+
+    public void run()
+    {
+        this.activateEditor();
+    }
+
+
+    private void activateEditor()
+    {
+
+        if ( !this.viewer.isCellEditorActive()
+            && this.selectedValues.length == 1
+            && this.selectedAttributes.length == 0
+            && viewer.getCellModifier().canModify( this.selectedValues[0],
+                EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME ) )
+        {
+
+            // set cell editor to viewer
+            this.viewer.getCellEditors()[EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX] = this.cellEditor;
+
+            // add listener for end of editing
+            if ( this.cellEditor.getControl() != null )
+            {
+                this.cellEditor.getControl().addFocusListener( this );
+                this.cellEditor.getControl().addKeyListener( this );
+            }
+
+            // deactivate global actions
+            if ( this.actionGroup != null )
+                this.actionGroup.deactivateGlobalActionHandlers();
+
+            // start editing
+            this.viewer.editElement( this.selectedValues[0], EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX );
+
+            if ( !this.viewer.isCellEditorActive() )
+            {
+                this.editorClosed();
+            }
+        }
+        else
+        {
+            this.valueProviderManager.setUserSelectedValueProvider( null );
+        }
+    }
+
+
+    private void editorClosed()
+    {
+
+        // remove cell editors from viewer to prevend auto-editing
+        for ( int i = 0; i < this.viewer.getCellEditors().length; i++ )
+        {
+            this.viewer.getCellEditors()[i] = null;
+        }
+
+        // remove listener
+        if ( this.cellEditor.getControl() != null )
+        {
+            this.cellEditor.getControl().removeFocusListener( this );
+            this.cellEditor.getControl().removeKeyListener( this );
+        }
+
+        // activate global actions
+        if ( this.actionGroup != null )
+            this.actionGroup.activateGlobalActionHandlers();
+
+        // reset custom value provider and set selection to notify all
+        // openeditoractions to update their
+        // enabled state.
+        this.valueProviderManager.setUserSelectedValueProvider( null );
+        this.viewer.setSelection( this.viewer.getSelection() );
+    }
+
+
+    public void focusGained( FocusEvent e )
+    {
+    }
+
+
+    public void focusLost( FocusEvent e )
+    {
+        this.editorClosed();
+    }
+
+
+    public void keyPressed( KeyEvent e )
+    {
+        if ( e.character == SWT.ESC && e.stateMask == SWT.NONE )
+        {
+            e.doit = false;
+        }
+    }
+
+
+    public void keyReleased( KeyEvent e )
+    {
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EditAttributeDescriptionAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EditAttributeDescriptionAction.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EditAttributeDescriptionAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EditAttributeDescriptionAction.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,106 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.ModelModifier;
+import org.apache.directory.ldapstudio.browser.core.jobs.RenameValuesJob;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.actions.DeleteAction;
+import org.apache.directory.ldapstudio.browser.ui.wizards.AttributeWizard;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+
+
+public class EditAttributeDescriptionAction extends AbstractEntryEditorListenerAction implements ModelModifier
+{
+
+    private DeleteAction deleteAction;
+
+
+    public EditAttributeDescriptionAction( ISelectionProvider selectionProvider )
+    {
+        super( selectionProvider, "Edit Attribute Description", null,
+            BrowserUIConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION );
+        this.deleteAction = new DeleteAction();
+    }
+
+
+    public void dispose()
+    {
+        super.dispose();
+        this.deleteAction.dispose();
+        this.deleteAction = null;
+    }
+
+
+    public void run()
+    {
+        if ( this.selectedAttributes.length == 1 )
+        {
+            this.renameValues( this.selectedAttributes[0].getValues() );
+        }
+        else if ( this.selectedValues.length > 0 )
+        {
+            this.renameValues( this.selectedValues );
+        }
+    }
+
+
+    private void renameValues( final IValue[] values )
+    {
+        AttributeWizard wizard = new AttributeWizard( "Edit Attribute Description", true, false, values[0]
+            .getAttribute().getDescription(), values[0].getAttribute().getEntry() );
+        WizardDialog dialog = new WizardDialog( Display.getDefault().getActiveShell(), wizard );
+        dialog.setBlockOnOpen( true );
+        dialog.create();
+        if ( dialog.open() == Dialog.OK )
+        {
+            String newAttributeName = wizard.getAttributeDescription();
+            if ( newAttributeName != null && !"".equals( newAttributeName )
+                && !newAttributeName.equals( values[0].getAttribute().getDescription() ) )
+            {
+                new RenameValuesJob( this.selectedEntry, values, newAttributeName ).execute();
+            }
+        }
+    }
+
+
+    protected void updateEnabledState()
+    {
+
+        if ( this.deleteAction != null )
+        {
+            deleteAction.setSelectedAttributes( this.selectedAttributes );
+            deleteAction.setSelectedValues( this.selectedValues );
+            super.setEnabled( deleteAction.isEnabled() );
+        }
+        else
+        {
+            super.setEnabled( false );
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidget.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidget.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidget.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,164 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.ui.widgets.ViewFormWidget;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+
+
+public class EntryEditorWidget extends ViewFormWidget
+{
+
+    private EntryEditorWidgetConfiguration configuration;
+
+    private EntryEditorWidgetQuickFilterWidget quickFilterWidget;
+
+    private Tree tree;
+
+    private TreeViewer viewer;
+
+
+    public EntryEditorWidget( EntryEditorWidgetConfiguration configuration )
+    {
+        this.configuration = configuration;
+    }
+
+
+    protected Control createContent( Composite parent )
+    {
+
+        this.quickFilterWidget = new EntryEditorWidgetQuickFilterWidget( this.configuration.getFilter(), this );
+        this.quickFilterWidget.createComposite( parent );
+
+        // create tree widget and viewer
+        this.tree = new Tree( parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
+            | SWT.HIDE_SELECTION );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 450;
+        data.heightHint = 250;
+        this.tree.setLayoutData( data );
+        this.tree.setHeaderVisible( true );
+        this.tree.setLinesVisible( true );
+        this.viewer = new TreeViewer( this.tree );
+        this.viewer.setUseHashlookup( true );
+
+        // set tree columns
+        for ( int i = 0; i < EntryEditorWidgetTableMetadata.COLUM_NAMES.length; i++ )
+        {
+            TreeColumn column = new TreeColumn( this.tree, SWT.LEFT, i );
+            column.setText( EntryEditorWidgetTableMetadata.COLUM_NAMES[i] );
+            column.setWidth( 200 );
+            column.setResizable( true );
+
+        }
+        this.viewer.setColumnProperties( EntryEditorWidgetTableMetadata.COLUM_NAMES );
+        this.tree.addControlListener( new ControlAdapter()
+        {
+            public void controlResized( ControlEvent e )
+            {
+                if ( tree.getClientArea().width > 0 )
+                {
+                    int width = tree.getClientArea().width - 2 * tree.getBorderWidth();
+                    if ( tree.getVerticalBar().isVisible() )
+                    {
+                        width -= tree.getVerticalBar().getSize().x;
+                    }
+                    tree.getColumn( EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX ).setWidth(
+                        width - tree.getColumn( EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX ).getWidth() );
+                }
+            }
+        } );
+
+        // setup sorter, filter and layout
+        this.configuration.getSorter().connect( this.viewer );
+        this.configuration.getFilter().connect( this.viewer );
+        this.configuration.getPreferences().connect( this.viewer );
+
+        // setup providers
+        this.viewer.setContentProvider( configuration.getContentProvider( this ) );
+        this.viewer.setLabelProvider( configuration.getLabelProvider( this.viewer ) );
+
+        // set table cell editors
+        this.viewer.setCellModifier( configuration.getCellModifier( this.viewer ) );
+        CellEditor[] editors = new CellEditor[EntryEditorWidgetTableMetadata.COLUM_NAMES.length];
+        this.viewer.setCellEditors( editors );
+
+        return this.tree;
+
+    }
+
+
+    public void setFocus()
+    {
+        this.viewer.getTree().setFocus();
+    }
+
+
+    public void dispose()
+    {
+        if ( this.viewer != null )
+        {
+            this.configuration.dispose();
+            this.configuration = null;
+
+            if ( this.quickFilterWidget != null )
+            {
+                this.quickFilterWidget.dispose();
+                this.quickFilterWidget = null;
+            }
+
+            this.tree.dispose();
+            this.tree = null;
+            this.viewer = null;
+        }
+
+        super.dispose();
+    }
+
+
+    public TreeViewer getViewer()
+    {
+        return viewer;
+    }
+
+
+    public EntryEditorWidgetQuickFilterWidget getQuickFilterWidget()
+    {
+        return quickFilterWidget;
+    }
+
+
+    public void setEnabled( boolean enabled )
+    {
+        this.tree.setEnabled( enabled );
+    }
+
+}