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 2012/11/06 16:36:55 UTC

svn commit: r1406182 - in /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor: ReplicationDetailsPage.java ReplicationMasterDetailsBlock.java ReplicationPage.java

Author: pamarcelot
Date: Tue Nov  6 15:36:55 2012
New Revision: 1406182

URL: http://svn.apache.org/viewvc?rev=1406182&view=rev
Log:
Added master detail page layout for replication elements.

Added:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationDetailsPage.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationMasterDetailsBlock.java
Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationPage.java

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationDetailsPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationDetailsPage.java?rev=1406182&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationDetailsPage.java (added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationDetailsPage.java Tue Nov  6 15:36:55 2012
@@ -0,0 +1,231 @@
+/*
+ *  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.apacheds.configuration.v2.editor;
+
+
+import org.apache.directory.server.config.beans.ReplConsumerBean;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+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;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+
+
+/**
+ * This class represents the Details Page of the Server Configuration Editor for the Replication type
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ReplicationDetailsPage implements IDetailsPage
+{
+    /** The associated Master Details Block */
+    private ReplicationMasterDetailsBlock masterDetailsBlock;
+
+    /** The Managed Form */
+    private IManagedForm mform;
+
+    /** The input consumer */
+    private ReplConsumerBean input;
+
+
+    /**
+     * Creates a new instance of ReplicationDetailsPage.
+     *
+     * @param pmdb
+     *      the associated Master Details Block
+     */
+    public ReplicationDetailsPage( ReplicationMasterDetailsBlock pmdb )
+    {
+        masterDetailsBlock = pmdb;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createContents( Composite parent )
+    {
+        FormToolkit toolkit = mform.getToolkit();
+        TableWrapLayout layout = new TableWrapLayout();
+        layout.topMargin = 5;
+        layout.leftMargin = 5;
+        layout.rightMargin = 2;
+        layout.bottomMargin = 2;
+        parent.setLayout( layout );
+
+        createDetailsSection( parent, toolkit );
+    }
+
+
+    /**
+     * Creates the Details Section
+     *
+     * @param parent
+     *      the parent composite
+     * @param toolkit
+     *      the toolkit to use
+     */
+    private void createDetailsSection( Composite parent, FormToolkit toolkit )
+    {
+        Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
+        section.marginWidth = 10;
+        section.setText( "Replication Consumer Details" );
+        section.setDescription( "Set the properties of the replication consumer." );
+        TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP );
+        td.grabHorizontal = true;
+        section.setLayoutData( td );
+        Composite client = toolkit.createComposite( section );
+        toolkit.paintBordersFor( client );
+        GridLayout glayout = new GridLayout( 3, false );
+        client.setLayout( glayout );
+        section.setClient( client );
+
+    }
+
+
+    /**
+     * Create a new button grid data.
+     *
+     * @return the new button grid data
+     */
+    private GridData createNewButtonGridData()
+    {
+        GridData gd = new GridData( SWT.FILL, SWT.BEGINNING, false, false );
+        gd.widthHint = IDialogConstants.BUTTON_WIDTH;
+        return gd;
+    }
+
+
+    /**
+     * Adds listeners to UI fields.
+     */
+    private void addListeners()
+    {
+    }
+
+
+    /**
+     * Removes listeners to UI fields.
+     */
+    private void removeListeners()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void selectionChanged( IFormPart part, ISelection selection )
+    {
+        IStructuredSelection ssel = ( IStructuredSelection ) selection;
+        if ( ssel.size() == 1 )
+        {
+            input = ( ReplConsumerBean ) ssel.getFirstElement();
+        }
+        else
+        {
+            input = null;
+        }
+        refresh();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void commit( boolean onSave )
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void initialize( IManagedForm form )
+    {
+        this.mform = form;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isDirty()
+    {
+        return false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isStale()
+    {
+        return false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void refresh()
+    {
+        removeListeners();
+
+
+        
+        addListeners();
+    }
+
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setFocus()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean setFormInput( Object input )
+    {
+        return false;
+    }
+}

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationMasterDetailsBlock.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationMasterDetailsBlock.java?rev=1406182&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationMasterDetailsBlock.java (added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationMasterDetailsBlock.java Tue Nov  6 15:36:55 2012
@@ -0,0 +1,289 @@
+/*
+ *  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.apacheds.configuration.v2.editor;
+
+
+import org.apache.directory.server.config.beans.ReplConsumerBean;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Table;
+import org.eclipse.ui.forms.DetailsPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.MasterDetailsBlock;
+import org.eclipse.ui.forms.SectionPart;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+
+
+/**
+ * This class represents the Replication Master/Details Block used in the Replication Page.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ReplicationMasterDetailsBlock extends MasterDetailsBlock
+{
+    private static final String NEW_ID = "consumer";
+
+    /** The associated page */
+    private ReplicationPage page;
+
+    /** The Details Page */
+    private ReplicationDetailsPage detailsPage;
+
+    // UI Fields
+    private TableViewer viewer;
+    private Button addButton;
+    private Button deleteButton;
+
+
+    /**
+     * Creates a new instance of ReplicationMasterDetailsBlock.
+     *
+     * @param page
+     *      the associated page
+     */
+    public ReplicationMasterDetailsBlock( ReplicationPage page )
+    {
+        this.page = page;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createMasterPart( final IManagedForm managedForm, Composite parent )
+    {
+        FormToolkit toolkit = managedForm.getToolkit();
+
+        // Creating the Section
+        Section section = toolkit.createSection( parent, Section.TITLE_BAR );
+        section.setText( "All Replication Consummers" );
+        section.marginWidth = 10;
+        section.marginHeight = 5;
+        Composite client = toolkit.createComposite( section, SWT.WRAP );
+        GridLayout layout = new GridLayout();
+        layout.numColumns = 2;
+        layout.makeColumnsEqualWidth = false;
+        layout.marginWidth = 2;
+        layout.marginHeight = 2;
+        client.setLayout( layout );
+        toolkit.paintBordersFor( client );
+        section.setClient( client );
+
+        // Creating the Table and Table Viewer
+        Table table = toolkit.createTable( client, SWT.NULL );
+        GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 );
+        gd.heightHint = 20;
+        gd.widthHint = 100;
+        table.setLayoutData( gd );
+        final SectionPart spart = new SectionPart( section );
+        managedForm.addPart( spart );
+        viewer = new TableViewer( table );
+        viewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                managedForm.fireSelectionChanged( spart, event.getSelection() );
+            }
+        } );
+        viewer.setContentProvider( new ArrayContentProvider() );
+        //      viewer.setLabelProvider( PartitionsPage.PARTITIONS_LABEL_PROVIDER );
+
+        // Creating the button(s)
+        addButton = toolkit.createButton( client, "Add", SWT.PUSH );
+        addButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+
+        deleteButton = toolkit.createButton( client, "Delete", SWT.PUSH );
+        deleteButton.setEnabled( false );
+        deleteButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+
+        initFromInput();
+        addListeners();
+    }
+
+
+    /**
+     * Initializes the page with the Editor input.
+     */
+    private void initFromInput()
+    {
+        viewer.setInput( page.getConfigBean().getDirectoryServiceBean().getLdapServerBean().getReplConsumers() );
+    }
+
+
+    /**
+     * Add listeners to UI fields.
+     */
+    private void addListeners()
+    {
+        viewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                viewer.refresh();
+
+                // Getting the selection of the table viewer
+                StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+
+                // Delete button is enabled when something is selected
+                deleteButton.setEnabled( !selection.isEmpty() );
+            }
+        } );
+
+        addButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                addNewConsumer();
+            }
+        } );
+
+        deleteButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                deleteSelectedConsumer();
+            }
+        } );
+    }
+
+
+    /**
+     * This method is called when the 'Add' button is clicked.
+     */
+    private void addNewConsumer()
+    {
+        String newId = getNewId();
+
+        ReplConsumerBean consumerBean = new ReplConsumerBean();
+
+        consumerBean.setReplConsumerId( newId );
+
+        page.getConfigBean().getDirectoryServiceBean().getLdapServerBean().addReplConsumers( consumerBean );
+        viewer.refresh();
+        viewer.setSelection( new StructuredSelection( consumerBean ) );
+        setEditorDirty();
+    }
+
+
+    /**
+     * Gets a new ID for a new Partition.
+     *
+     * @return 
+     *      a new ID for a new Partition
+     */
+    private String getNewId()
+    {
+        int counter = 1;
+        String name = NEW_ID;
+        boolean ok = false;
+
+        while ( !ok )
+        {
+            ok = true;
+            name = NEW_ID + counter;
+
+            for ( ReplConsumerBean consumer : page.getConfigBean().getDirectoryServiceBean().getLdapServerBean()
+                .getReplConsumers() )
+            {
+                if ( consumer.getReplConsumerId().equalsIgnoreCase( name ) )
+                {
+                    ok = false;
+                }
+            }
+            counter++;
+        }
+
+        return name;
+    }
+
+
+    /**
+     * This method is called when the 'Delete' button is clicked.
+     */
+    private void deleteSelectedConsumer()
+    {
+        StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            ReplConsumerBean consumer = ( ReplConsumerBean ) selection.getFirstElement();
+
+            if ( MessageDialog.openConfirm( page.getManagedForm().getForm().getShell(), "Confirm Delete",
+                NLS.bind( "Are you sure you want to delete replication consumer ''{0}''?",
+                    consumer.getReplConsumerId() ) ) )
+            {
+                page.getConfigBean().getDirectoryServiceBean().getLdapServerBean().getReplConsumers().remove( consumer );
+                setEditorDirty();
+            }
+        }
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void registerPages( DetailsPart detailsPart )
+    {
+        detailsPage = new ReplicationDetailsPage( this );
+        detailsPart.registerPage( ReplConsumerBean.class, detailsPage );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createToolBarActions( IManagedForm managedForm )
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    /**
+     * Sets the Editor as dirty.
+     */
+    public void setEditorDirty()
+    {
+        ( ( ServerConfigurationEditor ) page.getEditor() ).setDirty( true );
+        viewer.refresh();
+    }
+
+
+    /**
+     * Saves the necessary elements to the input model.
+     */
+    public void save()
+    {
+        detailsPage.commit( true );
+    }
+}

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationPage.java?rev=1406182&r1=1406181&r2=1406182&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationPage.java (original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ReplicationPage.java Tue Nov  6 15:36:55 2012
@@ -20,11 +20,7 @@
 package org.apache.directory.studio.apacheds.configuration.v2.editor;
 
 
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 
 
@@ -35,8 +31,8 @@ import org.eclipse.ui.forms.widgets.Form
  */
 public class ReplicationPage extends ServerConfigurationEditorPage
 {
-    /** The Page ID*/
-    public static final String ID = ReplicationPage.class.getName(); //$NON-NLS-1$
+    /** The Page ID */
+    public static final String ID = ReplicationPage.class.getName();
 
     /** The Page Title */
     private static final String TITLE = "Replication";
@@ -59,12 +55,8 @@ public class ReplicationPage extends Ser
      */
     protected void createFormContent( Composite parent, FormToolkit toolkit )
     {
-        Composite composite = toolkit.createComposite( parent );
-        composite.setLayout( new GridLayout() );
-        composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
-
-        Label label = toolkit.createLabel( composite, "Coming soon..." );
-        label.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, true ) );
+        ReplicationMasterDetailsBlock masterDetailsBlock = new ReplicationMasterDetailsBlock( this );
+        masterDetailsBlock.createContent( getManagedForm() );
     }