/*
 *  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.openldap.config.editor.databases;


import java.util.ArrayList;
import java.util.List;

import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.util.Strings;
import org.apache.directory.studio.common.ui.CommonUIUtils;
import org.apache.directory.studio.common.ui.widgets.AbstractWidget;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.common.ui.widgets.TableWidget;
import org.apache.directory.studio.common.ui.widgets.WidgetModifyListener;
import org.apache.directory.studio.common.ui.wrappers.StringValueWrapper;
import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.openldap.common.ui.model.DatabaseTypeEnum;
import org.apache.directory.studio.openldap.common.ui.model.RequireConditionEnum;
import org.apache.directory.studio.openldap.common.ui.model.RestrictOperationEnum;
import org.apache.directory.studio.openldap.common.ui.widgets.BooleanWithDefaultWidget;
import org.apache.directory.studio.openldap.common.ui.widgets.EntryWidget;
import org.apache.directory.studio.openldap.common.ui.widgets.PasswordWidget;
import org.apache.directory.studio.openldap.config.OpenLdapConfigurationPlugin;
import org.apache.directory.studio.openldap.config.OpenLdapConfigurationPluginConstants;
import org.apache.directory.studio.openldap.config.OpenLdapConfigurationPluginUtils;
import org.apache.directory.studio.openldap.config.editor.dialogs.OverlayDialog;
import org.apache.directory.studio.openldap.config.editor.dialogs.ReplicationConsumerDialog;
import org.apache.directory.studio.openldap.config.editor.dialogs.SizeLimitDialog;
import org.apache.directory.studio.openldap.config.editor.wrappers.DatabaseWrapper;
import org.apache.directory.studio.openldap.config.editor.wrappers.DnDecorator;
import org.apache.directory.studio.openldap.config.editor.wrappers.DnWrapper;
import org.apache.directory.studio.openldap.config.editor.wrappers.LimitsDecorator;
import org.apache.directory.studio.openldap.config.editor.wrappers.LimitsWrapper;
import org.apache.directory.studio.openldap.config.editor.wrappers.RequireConditionDecorator;
import org.apache.directory.studio.openldap.config.editor.wrappers.RestrictOperationDecorator;
import org.apache.directory.studio.openldap.config.editor.wrappers.SsfDecorator;
import org.apache.directory.studio.openldap.config.editor.wrappers.SsfWrapper;
import org.apache.directory.studio.openldap.config.editor.wrappers.TimeLimitDecorator;
import org.apache.directory.studio.openldap.config.editor.wrappers.TimeLimitWrapper;
import org.apache.directory.studio.openldap.config.model.OlcOverlayConfig;
import org.apache.directory.studio.openldap.config.model.database.OlcBdbConfig;
import org.apache.directory.studio.openldap.config.model.database.OlcDatabaseConfig;
import org.apache.directory.studio.openldap.config.model.database.OlcHdbConfig;
import org.apache.directory.studio.openldap.config.model.database.OlcLdifConfig;
import org.apache.directory.studio.openldap.config.model.database.OlcMdbConfig;
import org.apache.directory.studio.openldap.config.model.database.OlcNullConfig;
import org.apache.directory.studio.openldap.config.model.database.OlcRelayConfig;
import org.apache.directory.studio.openldap.syncrepl.Provider;
import org.apache.directory.studio.openldap.syncrepl.SyncRepl;
import org.apache.directory.studio.openldap.syncrepl.SyncReplParser;
import org.apache.directory.studio.openldap.syncrepl.SyncReplParserException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IDetailsPage;
import org.eclipse.ui.forms.IFormPart;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;


/**
 * This class represents the Details Page of the Server Configuration Editor for the Database type. 
 * We have 6 sections to manage :
 * <ul>
 * <li>general :</li>
 *   <ul>
 *     <li>olcSuffix(DN, SV/MV)</li>
 *     <li>olcRootDN(DN, SV)</li>
 *     <li>olcRootPw(String, SV)</li>
 *     <li></li>
 *   </ul>
 * <li>limits :</li>
 *   <ul>
 *     <li>olcSizeLimit(String, SV)</li>
 *     <li>olcTimeLimit(String, MV)</li>
 *     <li>olcLimits(String, MV, Ordered)</li>
 *     <li>olcMaxDerefDepth(Integer, SV)</li>
 *   </ul>
 * <li>security :</li>
 *   <ul>
 *     <li>olcHidden(Boolean)</li>
 *     <li>olcReadOnly(Boolean)</li>
 *     <li>olcRequires(String, MV)</li>
 *     <li>olcRestrict(String, MV)</li>
 *     <li>olcSecurity(String, MV)</li>
 *   </ul>
 * <li>access</li>
 *   <ul>
 *     <li>olcAccess(String, MV, Ordered)</li>
 *     <li>olcAddContentAcl(Boolean)</li>
 *   </ul>
 * <li>replication :</li>
 *   <ul>
 *     <li>olcMirrorMode(Boolean)</li>
 *     <li>olcSyncrepl(String, MV, Ordered)</li>
 *     <li>olcSyncUseSubentry(Boolean)</li>
 *     <li>olcUpdateDN(DN, SV)</li>
 *     <li>olcUpdateRef(String, MV)</li>
 *     <li>olcReplica(String, MV, Ordered)</li>
 *     <li>olcReplicaArgsFile(String, SV)</li>
 *     <li>olcReplicaPidFile(String, SV)</li>
 *     <li>olcReplicationInterval(Integer, SV)</li>
 *     <li>olcReplogFile(String, SV)</li>
 *   </ul>
 * <li>options :</li>
 *   <ul>
 *     <li>olcLastMod(Boolean)</li>
 *     <li>olcMonitoring(Boolean)</li>
 *     <li>olcPlugin(String, MV)</li>
 *     <li>olcExtraArgs(String, MV)</li>
 *     <li>olcSchemaDN(DN, SV)</li>
 *     <li>olcSubordinate(String, SV)</li>
 *   </ul>
 * </ul>
 * 
 * <pre>
 * +--------------------------------------------------------+
 * | .----------------------------------------------------. |
 * | |V XXXX Database general                             | |
 * | +----------------------------------------------------+ |
 * | | Root DN :       [ ] none [///////////////////////] | |
 * | | Root password : [ ] none [///////////////////////] | |
 * | | Suffix :                                           | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   +------------------------------------+           | |
 * | +----------------------------------------------------+ |
 * |                                                        |
 * | .----------------------------------------------------. |
 * | |V XXXX Database limits                              | |
 * | +----------------------------------------------------+ |
 * | | Size limit : [//////////] (Edit...)                | |
 * | | Max Deref Depth : [///]                            | |
 * | | Timelimit :                                        | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   +------------------------------------+           | |
 * | | Limits :                                           | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   |                                    | --------  | |
 * | |   |                                    | (Up...)   | |
 * | |   |                                    | (Down...) | |
 * | |   +------------------------------------+           | |
 * | +----------------------------------------------------+ |
 * |                                                        |
 * | .----------------------------------------------------. |
 * | |V XXXX Database security                            | |
 * | +----------------------------------------------------+ |
 * | | Hidden : [ ]                       Read Only : [ ] | |
 * | | Requires :                                         | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Delete)  | |
 * | |   |                                    |           | |
 * | |   +------------------------------------+           | |
 * | | Restrict :                                         | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Delete)  | |
 * | |   |                                    |           | |
 * | |   +------------------------------------+           | |
 * | | Security Strength Factors :                        | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   +------------------------------------+           | |
 * | +----------------------------------------------------+ |
 * |                                                        |
 * | .----------------------------------------------------. |
 * | |V XXXX Database access                              | |
 * | +----------------------------------------------------+ |
 * | | Add content ACL : [ ]                              | |
 * | | ACLs :                                             | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   |                                    | --------  | |
 * | |   |                                    | (Up...)   | |
 * | |   |                                    | (Down...) | |
 * | |   +------------------------------------+           | |
 * | +----------------------------------------------------+ |
 * |                                                        |
 * | .----------------------------------------------------. |
 * | |V XXXX Database replication                         | |
 * | +----------------------------------------------------+ |
 * | | MirrorMode :    [ ]     Use Subentry : [ ]         | |
 * | | Replication Interval :  [///]                      | |
 * | | Replication Args[fileo:e[////////////////////////] | |
 * | | Replication PID file :  [////////////////////////] | |
 * | | Replication Log file :  [////////////////////////] | |
 * | | Update DN : [-------------------------->] (Browse) | |
 * | | Update References :                                | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   +------------------------------------+           | |
 * | | Replicas :                                         | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   |                                    | --------  | |
 * | |   |                                    | (Up...)   | |
 * | |   |                                    | (Down...) | |
 * | |   +------------------------------------+           | |
 * | | Syncrepls :                                        | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   |                                    | --------  | |
 * | |   |                                    | (Up...)   | |
 * | |   |                                    | (Down...) | |
 * | |   +------------------------------------+           | |
 * | +----------------------------------------------------+ |
 * |                                                        |
 * | .----------------------------------------------------. |
 * | |V XXXX Database options                             | |
 * | +----------------------------------------------------+ |
 * | | Last Modification : [ ] Monitoring : [ ]           | |
 * | | Schema DN : [-------------------------->] (Browse) | |
 * | | Subordinate : [//////////////////////////////////] | |
 * | | Plugins :                                          | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   +------------------------------------+           | |
 * | | Extras Arguments :                                 | |
 * | |   +------------------------------------+           | |
 * | |   |                                    | (Add...)  | |
 * | |   |                                    | (Edit...) | |
 * | |   |                                    | (Delete)  | |
 * | |   +------------------------------------+           | |
 * | +----------------------------------------------------+ |
 * +--------------------------------------------------------+
 * </pre>
 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
 */
public class DatabasesDetailsPage implements IDetailsPage
{
    /** The frontend database type array */
    private static final DatabaseTypeEnum[] FRONTEND_DATABASE_TYPES = new DatabaseTypeEnum[]
    {
        DatabaseTypeEnum.FRONTEND
    };

    /** The frontend database type array */
    private static final DatabaseTypeEnum[] CONFIG_DATABASE_TYPES = new DatabaseTypeEnum[]
        {
            DatabaseTypeEnum.CONFIG
    };

    /** The class instance */
    private DatabasesDetailsPage instance;

    /** The associated Master Details Block */
    private DatabasesMasterDetailsBlock masterDetailsBlock;

    /** The database wrapper */
    private DatabaseWrapper databaseWrapper;

    /** The database specific details block */
    private DatabaseSpecificDetailsBlock databaseSpecificDetailsBlock;

    /** The browser connection */
    private IBrowserConnection browserConnection;

    /** The dirty flag */
    private boolean dirty = false;

    // UI widgets
    private Composite parentComposite;
    private FormToolkit toolkit;
    //private ComboViewer databaseTypeComboViewer;
    
    // UI General sesstings widgets
    /** The olcSuffixDN attribute */
    private TableWidget<DnWrapper> suffixDnTableWidget;

    /** The olcRootDN attribute */
    private EntryWidget rootDnEntryWidget;

    /** The olcRootPW attribute */
    private PasswordWidget rootPasswordWidget;

    // UI limits settings widgets
    /** The olcSizeLimit */
    private Text sizeLimitText;
    
    /** The SizeLimit edit Button */
    private Button sizeLimitEditButton;

    /** The olcMaxDerefDepth parameter */
    private Text maxDerefDepthText;

    /** The olcTimeLimit Table */
    private TableWidget<TimeLimitWrapper> timeLimitTableWidget;

    /** The olcLimits Table */
    private TableWidget<LimitsWrapper> limitsTableWidget;

    /** The olcSchemaDN attribute */
    private EntryWidget schemaDnEntryWidget;

    // The Security UI Widgets
    /** The olcReadOnly attribute */
    private Button readOnlyButton;

    /** The olcHidden attribute */
    private Button hiddenButton;
    
    /** The olcRequires parameter */
    private TableWidget<RequireConditionEnum> requireConditionTableWidget;

    /** The olcRestrict parameter */
    private TableWidget<RestrictOperationEnum> restrictOperationTableWidget;
    
    /** The olcSecurity table widget */
    private TableWidget<SsfWrapper> securityTableWidget;
    
    // The Access UI Widgets
    /** The olcAddContentAcl Button */
    private Button addContentAclCheckbox;

    /** The olcAcess Table */
    private TableWidget<StringValueWrapper> aclsTableWidget;



    /** The associated overlays */
    private TableViewer overlaysTableViewer;
    private Button addOverlayButton;
    private Button editOverlayButton;
    private Button deleteOverlayButton;

    /** The specific configuration for each type of database */
    private Section specificSettingsSection;
    private Composite specificSettingsSectionComposite;
    private Composite databaseSpecificDetailsComposite;

    /** The olcMirrorMode flag */
    private BooleanWithDefaultWidget mirrorModeBooleanWithDefaultWidget;
    
    /** The olcDisabled flag (only available in OpenDLAP 2.4.36) */
    private BooleanWithDefaultWidget disabledBooleanWithDefaultWidget;
    
    /** The olcLastMod flag */
    private BooleanWithDefaultWidget lastModBooleanWithDefaultWidget;
    
    /** The olMonitoring flag */
    private BooleanWithDefaultWidget monitoringBooleanWithDefaultWidget;
    
    /** The Syncrepl consumer part */
    private TableViewer replicationConsumersTableViewer;
    private Button addReplicationConsumerButton;
    private Button editReplicationConsumerButton;
    private Button deleteReplicationConsumerButton;
    
    
    /**
     * The olcSuffixDn listener
     *
    private WidgetModifyListener suffixDnTableWidgetListener = new WidgetModifyListener()
    {
        public void widgetModified( WidgetModifyEvent e )
        {
            List<String> suffixDns = new ArrayList<String>();
            
            for ( DnWrapper dnWrapper : suffixDnTableWidget.getElements() )
            {
                suffixDns.add( dnWrapper.toString() );
            }
            
            getConfiguration().getGlobal().setOlcRequires( requires );
        }
    };
    
    
    /**
     * The listener for the sizeLimit Text
     */
    private SelectionListener sizeLimitEditSelectionListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            SizeLimitDialog dialog = new SizeLimitDialog( sizeLimitText.getShell(), sizeLimitText.getText() );

            if ( dialog.open() == OverlayDialog.OK )
            {
                String newSizeLimitStr = dialog.getNewLimit();
                
                if ( newSizeLimitStr != null )
                {
                    sizeLimitText.setText( newSizeLimitStr );
                }
            }
        }
    };

    // Listeners
    /**
     * A listener for changes on the Overlay table 
     */
    private ISelectionChangedListener overlaysTableViewerSelectionChangedListener = event -> updateOverlaysTableButtonsState();

    /**
     * A listener for selections on the Overlay table 
     */
    private IDoubleClickListener overlaysTableViewerDoubleClickListener = event -> editOverlayButtonAction();

    /**
     * A listener for the Overlay table Add button 
     */
    private SelectionListener addOverlayButtonListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            addOverlayButtonAction();
        }
    };

    /**
     * A listener for the Overlay table Edit button 
     */
    private SelectionListener editOverlayButtonListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            editOverlayButtonAction();
        }
    };

    /**
     * A listener for the Overlay table Delete button 
     */
    private SelectionListener deleteOverlayButtonListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            deleteOverlayButtonAction();
        }
    };

    /**
     * A listener for changes on the Replication Consumers table 
     */
    private ISelectionChangedListener replicationConsumersTableViewerSelectionChangedListener = event ->
            updateReplicationConsumersTableButtonsState();

    /**
     * A listener for selections on the Replication Consumers table 
     */
    private IDoubleClickListener replicationConsumersTableViewerDoubleClickListener = event ->
            editReplicationConsumerButtonAction();

    /**
     * A listener for the Replication Consumers table Add button 
     */
    private SelectionListener addReplicationConsumerButtonListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            addReplicationConsumerButtonAction();
        }
    };

    /**
     * A listener for the Replication Consumers table Edit button 
     */
    private SelectionListener editReplicationConsumerButtonListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            editReplicationConsumerButtonAction();
        }
    };

    /**
     * A listener for the Replication Consumers table Delete button 
     */
    private SelectionListener deleteReplicationConsumerButtonListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            deleteReplicationConsumerButtonAction();
        }
    };

    /**
     * The listener that manage the specific database parameters
     *
    private ISelectionChangedListener databaseTypeComboViewerSelectionChangedListener = new ISelectionChangedListener()
    {
        public void selectionChanged( SelectionChangedEvent event )
        {
            DatabaseTypeEnum type = ( DatabaseTypeEnum ) ( ( StructuredSelection ) databaseTypeComboViewer
                .getSelection() )
                .getFirstElement();

            if ( ( databaseWrapper != null ) && ( databaseWrapper.getDatabase() != null ) )
            {
                OlcDatabaseConfig database = databaseWrapper.getDatabase();

                switch ( type )
                {
                    case BDB:
                        OlcBdbConfig newBdbDatabase = new OlcBdbConfig();
                        copyDatabaseProperties( database, newBdbDatabase );
                        databaseWrapper.setDatabase( newBdbDatabase );
                        databaseSpecificDetailsBlock = new BerkeleyDbDatabaseSpecificDetailsBlock<OlcBdbConfig>(
                            instance, newBdbDatabase, browserConnection );
                        break;
                        
                    case HDB:
                        OlcHdbConfig newHdbDatabase = new OlcHdbConfig();
                        copyDatabaseProperties( database, newHdbDatabase );
                        databaseWrapper.setDatabase( newHdbDatabase );
                        databaseSpecificDetailsBlock = new BerkeleyDbDatabaseSpecificDetailsBlock<OlcHdbConfig>(
                            instance, newHdbDatabase, browserConnection );
                        break;

                    case MDB:
                        // The MDB database
                        OlcMdbConfig newMdbDatabase = new OlcMdbConfig();
                        copyDatabaseProperties( database, newMdbDatabase );
                        databaseWrapper.setDatabase( newMdbDatabase );
                        databaseSpecificDetailsBlock = new MdbDatabaseSpecificDetailsBlock( instance, newMdbDatabase,
                            browserConnection );
                        break;

                    case LDIF:
                        OlcLdifConfig newLdifDatabase = new OlcLdifConfig();
                        copyDatabaseProperties( database, newLdifDatabase );
                        databaseWrapper.setDatabase( newLdifDatabase );
                        databaseSpecificDetailsBlock = new LdifDatabaseSpecificDetailsBlock( instance,
                            newLdifDatabase );
                        break;
                    //                    case LDAP:
                    //                        OlcLDAPConfig newLdapDatabase = new OlcLDAPConfig();
                    //                        copyDatabaseProperties( database, newLdapDatabase );
                    //                        databaseWrapper.setDatabase( newLdapDatabase );
                    //                        // databaseSpecificDetailsBlock = new LdapDatabaseSpecificDetailsBlock( newLdapDatabase ); // TODO
                    //                        break;
                        
                    case NULL:
                        OlcNullConfig newNullDatabase = new OlcNullConfig();
                        copyDatabaseProperties( database, newNullDatabase );
                        databaseWrapper.setDatabase( newNullDatabase );
                        databaseSpecificDetailsBlock = new NullDatabaseSpecificDetailsBlock( instance,
                            newNullDatabase );
                        break;
                        
                    case RELAY:
                        OlcRelayConfig newRelayDatabase = new OlcRelayConfig();
                        copyDatabaseProperties( database, newRelayDatabase );
                        databaseWrapper.setDatabase( newRelayDatabase );
                        databaseSpecificDetailsBlock = new RelayDatabaseSpecificDetailsBlock( instance,
                            newRelayDatabase, browserConnection );
                        break;
                        
                    case NONE:
                        OlcDatabaseConfig newNoneDatabase = new OlcDatabaseConfig();
                        copyDatabaseProperties( database, newNoneDatabase );
                        databaseWrapper.setDatabase( newNoneDatabase );
                        databaseSpecificDetailsBlock = null;
                        break;
                        
                    default:
                        break;
                }

                updateDatabaseSpecificSettingsSection();

                setEditorDirty();
            }
        }
    };

    
    /** 
     * The modify listener which set the editor dirty 
     **/
    private WidgetModifyListener dirtyWidgetModifyListener = event -> setEditorDirty();

    
    /** 
     * The modify listener which set the editor dirty 
     **/
    private SelectionListener dirtySelectionListener = new SelectionListener()
    {
        
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            setEditorDirty();
        }
        
        @Override
        public void widgetDefaultSelected( SelectionEvent e )
        {
            // TODO Auto-generated method stub
        }
    };
    
    
    /**
     * A modify listener for text zones when they have been modified
     */
    protected ModifyListener dirtyModifyListener = event -> setEditorDirty();

    
    /**
     * The olcHidden listener
     */
    private SelectionListener hiddenButtonSelectionListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            setEditorDirty();
        }
    };

    
    /**
     * The olcReadOnly listener
     */
    private SelectionListener readOnlyButtonSelectionListener = new SelectionAdapter()
    {
        @Override
        public void widgetSelected( SelectionEvent e )
        {
            setEditorDirty();
        }
    };
    
    
    /**
     * The olcRequires listener
     */
    private WidgetModifyListener requireConditionListener = event ->
        {
            List<String> requires = new ArrayList<>();
            
            for ( RequireConditionEnum requireCondition : requireConditionTableWidget.getElements() )
            {
                requires.add( requireCondition.getName() );
            }
            
            //getConfiguration().getGlobal().setOlcRequires( requires );
        };
    
    
    /**
     * The olcRestrict listener
     */
    private WidgetModifyListener restrictOperationListener = event ->
        {
            List<String> restricts = new ArrayList<>();
            
            for ( RestrictOperationEnum restrictOperation : restrictOperationTableWidget.getElements() )
            {
                restricts.add( restrictOperation.getName() );
            }
            
            //getConfiguration().getGlobal().setOlcRestrict( restricts );
        };
    
    
    /**
     * The olcSecurity listener
     */
    private WidgetModifyListener securityListener = event ->
        {
            List<String> ssfWrappers = new ArrayList<>();
            
            for ( SsfWrapper ssfWrapper : securityTableWidget.getElements() )
            {
                ssfWrappers.add( ssfWrapper.toString() );
            }
            
            //getConfiguration().getGlobal().setOlcSecurity( ssfWrappers );
        };


    /**
     * Creates a new instance of PartitionDetailsPage.
     *
     * @param pmdb
     *      the associated Master Details Block
     */
    public DatabasesDetailsPage( DatabasesMasterDetailsBlock pmdb )
    {
        instance = this;
        masterDetailsBlock = pmdb;

        // Getting the browser connection associated with the connection in the configuration
        browserConnection = BrowserCorePlugin.getDefault().getConnectionManager()
            .getBrowserConnection( masterDetailsBlock.getPage().getConfiguration().getConnection() );
    }


    /**
     * Creates the Database general configuration panel. We have 8 sections :
     * <ul>
     * <li>General</li>
     * <li>Limits</li>
     * <li>Security</li>
     * <li>Access</li>
     * <li>Overlays</li>
     * <li>Replication</li>
     * <li>Options</li>
     * <li>Specific</li>
     * </ul>
     * {@inheritDoc}
     */
    public void createContents( Composite parent )
    {
        parentComposite = parent;
        parent.setLayout( new GridLayout() );

        createGeneralSettingsSection( parent, toolkit );
        createLimitsSettingsSection( parent, toolkit );
        createSecuritySettingsSection( parent, toolkit );
        createAccessSettingsSection( parent, toolkit );
        createOverlaySettingsSection( parent, toolkit );
        createReplicationConsumersSettingsSection( parent, toolkit );
        //createOptionsSettingsSection( parent, toolkit );
        createDatabaseSpecificSettingsSection( parent, toolkit );
    }


    /**
     * Creates the General Settings Section. This will expose the following attributes :
     * <ul>
     * <li>olcRootDN</li>
     * <li>olcRootPW</li>
     * <li>olcSuffix</li>
     * </ul>
     * 
     * <pre>
     * .----------------------------------------------------.
