directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r475795 [2/2] - in /directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin: ./ META-INF/ ressources/ ressources/help/ ressources/help/images/ ressources/help/images/exporting/ ressources/help/images/importing/ ressources/hel...
Date Thu, 16 Nov 2006 16:20:25 GMT
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizard.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizard.java?view=auto&rev=475795
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizard.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizard.java Thu Nov 16 08:20:22 2006
@@ -0,0 +1,470 @@
+/*
+ *  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.importexport.view;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Hashtable;
+
+import javax.naming.CommunicationException;
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+
+import org.apache.directory.ldapstudio.importexport.Activator;
+import org.apache.directory.ldapstudio.importexport.Messages;
+import org.apache.directory.server.tools.ToolCommandListener;
+import org.apache.directory.server.tools.commands.exportcmd.ExportCommandExecutor;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class implements the Export Wizards.
+ * Export Wizard is composed of two pages : one for general settings of the export,
+ * and one that is a preview of entries that are going to be exported
+ */
+public class ExportWizard extends Wizard implements INewWizard
+{
+    // The logger
+    private static Logger logger = LoggerFactory.getLogger( ExportWizard.class );
+    
+    // The two pages of the Wizard
+    private ExportWizardFirstPage exportWizardFirstPage;
+    private ExportWizardSecondPage exportWizardSecondPage;
+    
+    // The fetched entries
+    private NamingEnumeration entries;
+    
+    // Necessary fields to store the result of the User Input in the pages of the wizard
+    private String scopeString;
+    private int scope;
+    private String exportPoint;
+    private String destinationFile;
+    
+    // These fields are used when an error occurs while a progress monitor is running.
+    // Since we cannot use the setErrorMessage method while a progress monitor is running,
+    // we fire an error flag and store the error message.
+    private boolean exportError = false;
+    private String exportErrorMessage = ""; //$NON-NLS-1$
+    
+    // The counter used to show how many entries were exported
+    private int entriesCounter;
+    
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+     */
+    public void init( IWorkbench workbench, IStructuredSelection selection )
+    {
+        setWindowTitle( Messages.getString("ExportWizard.Export") ); //$NON-NLS-1$
+        setHelpAvailable( false );
+        setNeedsProgressMonitor( true );
+        logger.info( "Initializing Export Wizard" ); //$NON-NLS-1$
+    }
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages() {
+        exportWizardFirstPage = new ExportWizardFirstPage();
+        exportWizardSecondPage = new ExportWizardSecondPage();
+        addPage(exportWizardFirstPage);
+        addPage(exportWizardSecondPage);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    @Override
+    public boolean performFinish()
+    {
+        logger.info( "Starting Export" ); //$NON-NLS-1$
+        // Setting error notification variable to default
+        exportError = false;
+        exportErrorMessage = ""; //$NON-NLS-1$
+        
+        // Getting information from the first page
+        exportPoint = exportWizardFirstPage.getExportPoint(); 
+        scope = exportWizardFirstPage.getScope();
+        if ( scope == SearchControls.OBJECT_SCOPE )
+        {
+            scopeString = ExportCommandExecutor.SCOPE_OBJECT;
+        }
+        else if ( scope == SearchControls.ONELEVEL_SCOPE )
+        {
+            scopeString = ExportCommandExecutor.SCOPE_ONELEVEL;
+        }
+        else if ( scope == SearchControls.SUBTREE_SCOPE )
+        {
+            scopeString = ExportCommandExecutor.SCOPE_SUBTREE;
+        }
+        destinationFile = exportWizardFirstPage.getDestinationFile();
+        
+        if (logger.isDebugEnabled())
+        {
+            logger.debug( "Export Point: {}", exportPoint ); //$NON-NLS-1$
+            logger.debug( "Scope: {}", scope ); //$NON-NLS-1$
+            logger.debug( "Destination File: {}", destinationFile ); //$NON-NLS-1$
+        }
+        
+        // Checking if the file doesn't already exist
+        // We need to do that check separately from the rest of the code
+        // because once in the IRunnableWithProgress.run method, UI can't be accessed
+        // until the end of the method
+        if ( destinationFile == null )
+        {
+            displayErrorMessage( Messages.getString("ExportWizard.An_error_has_occurred_Export_couldnt_be_completed" ) ); //$NON-NLS-1$
+            return false;
+        }
+        File checkFile = new File( destinationFile );
+        
+        if ( checkFile.exists() )
+        {
+            logger.info( "The file {} already exists.", checkFile.getName()); //$NON-NLS-1$
+            
+            MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                SWT.ICON_QUESTION | SWT.YES | SWT.NO );
+            messageBox.setText( Messages.getString("ExportWizard.Replacing_existing_file") ); //$NON-NLS-1$
+            messageBox.setMessage( Messages.getString("ExportWizard.The_file") + checkFile.getName() + Messages.getString("ExportWizard.Already_exists") ); //$NON-NLS-1$ //$NON-NLS-2$
+            if ( SWT.YES != messageBox.open() )
+            {
+                logger.info( "The user doesn't want to replace existing file. The export stops here." ); //$NON-NLS-1$
+                return false;
+            }
+            else
+            {
+                // Erasing the file
+                logger.debug( "Deleting existing file ({}).", checkFile.getAbsolutePath() ); //$NON-NLS-1$
+                checkFile.delete();
+            }
+        }
+        else
+        {
+            // File doesn't exists, but does parent directories exists ?
+            String parentPathName = checkFile.getParent();
+            if ( parentPathName == null )
+            {
+                displayErrorMessage( Messages.getString("ExportWizard.The_path_to_the_destination_file_seems_to_be_wrong") ); //$NON-NLS-1$
+                logger.debug( "The path to the destination file seems to be wrong. Path is null." ); //$NON-NLS-1$
+                return false;
+            }
+            else
+            {
+                File parent = new File( parentPathName );
+                if ( ! parent.exists() )
+                {
+                    logger.info( "Target directory does not exist." ); //$NON-NLS-1$
+                    
+                    MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                        SWT.ICON_QUESTION | SWT.YES | SWT.NO );
+                    messageBox.setText( Messages.getString("ExportWizard.Create_directory") ); //$NON-NLS-1$
+                    messageBox.setMessage( Messages.getString("ExportWizard.Target_directory_doesnt_exist") ); //$NON-NLS-1$
+                    if ( SWT.YES != messageBox.open() )
+                    {
+                        logger.info( "The user doesn't want to create target directory. The export stops here." ); //$NON-NLS-1$
+                        return false;
+                    }
+                    else
+                    {
+                        // Creating target directory (and its sub-directories if necessary)
+                        logger.debug( "Constructing needed directory structure ({}).", parent.getAbsolutePath() ); //$NON-NLS-1$
+                        parent.mkdirs();
+                    }
+                }
+            }
+        }
+        
+        // Setting up the anonymous class to execute the progress monitor
+        IRunnableWithProgress op = new IRunnableWithProgress() {
+            public void run( IProgressMonitor monitor )
+            {
+                monitor.beginTask( Messages.getString("ExportWizard.Writing_file"), IProgressMonitor.UNKNOWN ); //$NON-NLS-1$
+                performFinish( monitor );
+                monitor.done();
+            }
+        };
+        
+        // Lauching the export command
+        logger.info( "Starting to export" ); //$NON-NLS-1$
+        try
+        {
+            getContainer().run(true, false, op);
+        }
+        catch ( InvocationTargetException e1 )
+        {
+            exportError = true;
+            exportErrorMessage = Messages.getString("ExportWizard.An_error_has_occurred_Export_couldnt_be_completed"); //$NON-NLS-1$
+        }
+        catch ( InterruptedException e1 )
+        {
+            exportError = true;
+            exportErrorMessage = Messages.getString("ExportWizard.An_error_has_occurred_Export_couldnt_be_completed"); //$NON-NLS-1$
+        }
+        
+        if ( exportError )
+        {
+            logger.error( exportErrorMessage );
+            displayErrorMessage( exportErrorMessage );
+            return false;
+        }
+        else
+        {
+            logger.info( "Export successful." ); //$NON-NLS-1$
+            MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                SWT.ICON_INFORMATION );
+            messageBox.setText( "Export successful" ); //$NON-NLS-1$
+            messageBox.setMessage( entriesCounter + "entries were succesfully exported." ); //$NON-NLS-1$
+            messageBox.open();
+            return true;
+        }
+    }
+    
+    /**
+     * Performs the export. Fetches entries and creates the corresponding LDIF file
+     * @param monitor the monitor to use to show progress
+     */
+    private void performFinish(final IProgressMonitor monitor )
+    {
+        // Initialization
+        entriesCounter = 1;
+        
+        // Preparing the call of the Export Command tool
+        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+        if (logger.isDebugEnabled())
+        {
+            logger.debug( "Connecting to LDAP server" ); //$NON-NLS-1$
+            logger.debug( "Host: {}", store.getString( ServerPreferencePage.HOST ) ); //$NON-NLS-1$
+            logger.debug( "Port: {}", store.getString( ServerPreferencePage.PORT ) ); //$NON-NLS-1$
+            logger.debug( "User DN: {}", store.getString( ServerPreferencePage.USER_DN ) ); //$NON-NLS-1$
+            logger.debug( "Base DN: {}", store.getString( ServerPreferencePage.BASE_BN ) ); //$NON-NLS-1$
+            logger.debug( "Authentication: simple" ); //$NON-NLS-1$
+        }
+        
+        // Initialization of the parameters
+        Parameter hostParam = new Parameter( ExportCommandExecutor.HOST_PARAMETER, store.getString( ServerPreferencePage.HOST ) ); //$NON-NLS-1$
+        Parameter portParam = new Parameter( ExportCommandExecutor.PORT_PARAMETER, new Integer( store.getString( ServerPreferencePage.PORT ) ) ); //$NON-NLS-1$
+        Parameter userParam = new Parameter( ExportCommandExecutor.USER_PARAMETER, store.getString( ServerPreferencePage.USER_DN ) ); //$NON-NLS-1$
+        Parameter passwordParam = new Parameter( ExportCommandExecutor.PASSWORD_PARAMETER, store.getString( ServerPreferencePage.PASSWORD ) ); //$NON-NLS-1$
+        Parameter authParam = new Parameter( ExportCommandExecutor.AUTH_PARAMETER, "simple" ); //$NON-NLS-1$ //$NON-NLS-2$
+        Parameter baseDNParam = new Parameter( ExportCommandExecutor.BASEDN_PARAMETER, store.getString( ServerPreferencePage.BASE_BN ) ); //$NON-NLS-1$
+        Parameter exportPointParam = new Parameter( ExportCommandExecutor.EXPORTPOINT_PARAMETER, exportPoint ); //$NON-NLS-1$
+        Parameter scopeParam = new Parameter( ExportCommandExecutor.SCOPE_PARAMETER, scopeString ); //$NON-NLS-1$
+        Parameter fileParam = new Parameter( ExportCommandExecutor.FILE_PARAMETER, destinationFile ); //$NON-NLS-1$
+
+        // Initialization of the listeners
+        ListenerParameter[] listenerParameters = initListeners( monitor );
+        
+        // Executing the command
+        ExportCommandExecutor executor = new ExportCommandExecutor();
+        executor.execute( new Parameter[]{ hostParam, portParam, userParam, passwordParam, authParam, baseDNParam, exportPointParam, scopeParam, fileParam },
+                            listenerParameters );
+        
+        logger.info( "File written on disk." ); //$NON-NLS-1$
+    }
+    
+    /**
+     * Returns the array of ListenerParameter for the Export Command
+     * @param monitor the progress monitor to update
+     * @return the array of ListenerParameter for the Export Command
+     */
+    private ListenerParameter[] initListeners(final IProgressMonitor monitor)
+    {
+        ListenerParameter entryWrittenListener = new ListenerParameter( ExportCommandExecutor.ENTRYWRITTENLISTENER_PARAMETER, new ToolCommandListener(){ //$NON-NLS-1$
+            public void notify( Serializable arg0 )
+            {
+                // Updating the progress monitor
+                if ( entriesCounter == 1 )
+                {
+                    monitor.setTaskName( Messages.getString("ExportWizard.Writing_file_to_disk_1_entry_done")); //$NON-NLS-1$
+                }
+                else
+                {
+                    monitor.setTaskName( Messages.getString("ExportWizard.Writing_file_to_disk") + entriesCounter + Messages.getString("ExportWizard.Entries_done")); //$NON-NLS-1$ //$NON-NLS-2$
+                }
+                entriesCounter++;
+                logger.debug( "-> Entry written" ); //$NON-NLS-1$      
+            }
+        });
+        
+        ListenerParameter exceptionListener = new ListenerParameter( ExportCommandExecutor.EXCEPTIONLISTENER_PARAMETER, new ToolCommandListener(){ //$NON-NLS-1$
+            public void notify( Serializable o )
+            {
+                if ( o instanceof CommunicationException )
+                {
+                    CommunicationException ce = ( CommunicationException ) o;
+                    logger.error( "Connection to server failed", ce ); //$NON-NLS-1$
+                    exportError = true;
+                    exportErrorMessage = Messages.getString("ExportWizard.Connection_to_server_failed"); //$NON-NLS-1$
+                    
+                }
+                else if ( o instanceof NameNotFoundException )
+                {
+                    NameNotFoundException nnfe = ( NameNotFoundException ) o;
+                    logger.error( "An error occurred when resolving Export Point.", nnfe ); //$NON-NLS-1$
+                    exportError = true;
+                    exportErrorMessage = Messages.getString("ExportWizard.Error_occurred_resolving_Export_Point"); //$NON-NLS-1$
+                    
+                }
+                else if ( o instanceof NamingException )
+                {
+                    NamingException ne = ( NamingException ) o;
+                    logger.error( "An error occurred while retrieving entries.", ne ); //$NON-NLS-1$
+                    exportError = true;
+                    exportErrorMessage = Messages.getString("ExportWizard.Error_occurred_retrieving_entries"); //$NON-NLS-1$
+                    
+                }
+                else if ( o instanceof IOException )
+                {
+                    IOException ioe = ( IOException ) o;
+                    logger.error( "An error occurred while writing the file to disk.", ioe ); //$NON-NLS-1$
+                    exportError = true;
+                    exportErrorMessage = Messages.getString("ExportWizard.Error_occurred_writing_file_to_disk_File_could_not_be_saved"); //$NON-NLS-1$
+                    
+                }
+                else
+                {
+                    exportError = true;
+                    exportErrorMessage = Messages.getString("ExportWizard.An_unknown_error_has_occured_File_could_not_be_saved"); //$NON-NLS-1$
+                }
+            }
+        });
+        
+        return new ListenerParameter[] { entryWrittenListener, exceptionListener};
+    }
+ 
+    @Override
+    public boolean canFinish()
+    {
+        return exportWizardFirstPage.isPageComplete();
+    }
+    
+    /**
+     * Fetches the entries on the server. The result is accessible using the getEntries() method.
+     * @throws NamingException 
+     */
+    @SuppressWarnings("unchecked") //$NON-NLS-1$
+    public void fetchEntries() throws NamingException
+    {
+        logger.debug( "Starting to fetch entries" ); //$NON-NLS-1$
+        // Reseting entries fetched from last search
+        resetEntries();
+        
+        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+        // Connecting to the LDAP Server
+        if (logger.isDebugEnabled())
+        {
+            logger.debug( "Connecting to LDAP server" ); //$NON-NLS-1$
+            logger.debug( "Host: {}",store.getString( ServerPreferencePage.HOST ) ); //$NON-NLS-1$
+            logger.debug( "Port: {}",store.getString( ServerPreferencePage.PORT ) ); //$NON-NLS-1$
+            logger.debug( "User DN: {}",store.getString( ServerPreferencePage.USER_DN ) ); //$NON-NLS-1$
+            logger.debug( "Base DN: {}",store.getString( ServerPreferencePage.BASE_BN ) ); //$NON-NLS-1$
+            logger.debug( "Authentication: simple" ); //$NON-NLS-1$
+        }
+        Hashtable env = new Hashtable();
+        env.put( Context.SECURITY_PRINCIPAL, store.getString( ServerPreferencePage.USER_DN ) );
+        env.put( Context.SECURITY_CREDENTIALS, store.getString( ServerPreferencePage.PASSWORD ) );
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" ); //$NON-NLS-1$
+        env.put( Context. PROVIDER_URL, "ldap://" + store.getString( ServerPreferencePage.HOST ) + ":" + store.getString( ServerPreferencePage.PORT ) + "/" + store.getString( ServerPreferencePage.BASE_BN ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); //$NON-NLS-1$
+        DirContext ctx = new InitialDirContext(env);
+        
+        // Setting up search scope
+        SearchControls ctls = new SearchControls();
+        ctls.setSearchScope( scope );
+        
+        // Fetching entries
+        entries = ctx.search( exportPoint, "(objectClass=*)", ctls); //$NON-NLS-1$
+        
+        logger.debug( "Entries fetched" ); //$NON-NLS-1$
+    }
+    
+    /**
+     * Displays the given message as an error message on the current page
+     * @param msg   the message to display
+     */
+    private void displayErrorMessage(String msg)
+    {
+        WizardPage page = ( WizardPage ) getContainer().getCurrentPage();
+        page.setErrorMessage( msg );     
+    }
+    
+    /**
+     * Returns the entries matching the user request.
+     * @return the entries matching the user request
+     */
+    public NamingEnumeration getEntries()
+    {
+        return entries;
+    }
+    
+    /**
+     * Resets already fetched entries.
+     */
+    public void resetEntries()
+    {
+        entries = null;
+    }
+    
+    public void setExportPoint( String exportPoint )
+    {
+        this.exportPoint = exportPoint;
+    }
+
+    public void setDestinationFile( String destinationFile )
+    {
+        this.destinationFile = destinationFile;
+    }
+
+    public void setScope( int scope )
+    {
+        this.scope = scope;
+    }
+        
+    /**
+     * Returns the first page of the wizard
+     * @return the first page of the wizard
+     */
+    public ExportWizardFirstPage getFirstPage()
+    {
+        return exportWizardFirstPage;
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizardFirstPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizardFirstPage.java?view=auto&rev=475795
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizardFirstPage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizardFirstPage.java Thu Nov 16 08:20:22 2006
@@ -0,0 +1,272 @@
+/*
+ *  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.importexport.view;
+
+import javax.naming.directory.SearchControls;
+
+import org.apache.directory.ldapstudio.importexport.Messages;
+import org.apache.directory.ldapstudio.importexport.Plugin;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class implements the first page of the Export Wizard
+ * On this page, the user provides all the information about the export, 
+ * such as: Base DN, Scope and destination file
+ */
+public class ExportWizardFirstPage extends WizardPage
+{  
+    // The logger
+    private static Logger logger = LoggerFactory.getLogger( ExportWizardFirstPage.class );
+    
+    private Text destionationFile_text;
+    private Text exportPoint_text;
+    private Button scopeObject_button;
+    private Button scopeOneLevel_button;
+    private Button scopeSubTree;
+    private Button destionationFile_button;
+
+    /**
+     * Default constructor
+     */
+    public ExportWizardFirstPage() {
+        super("ExportAsLDIF"); //$NON-NLS-1$
+        setTitle(Messages.getString("ExportWizardFirstPage.Export_as_LDIF")); //$NON-NLS-1$
+        setDescription(Messages.getString("ExportWizardFirstPage.Wizard_Page_Description")); //$NON-NLS-1$
+        setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Plugin.ID, ImageKeys.WIZARD_EXPORT ) );
+    }
+    
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+     */
+    public void createControl( Composite parent )
+    {
+        Composite container = new Composite(parent, SWT.NULL);
+        GridLayout layout = new GridLayout();
+        container.setLayout(layout);
+        layout.numColumns = 3;
+        
+        Label exportPoint_label = new Label(container, SWT.NONE);
+        exportPoint_label.setText( Messages.getString("ExportWizardFirstPage.Export_Point") ); //$NON-NLS-1$
+        
+        exportPoint_text = new Text(container, SWT.BORDER);
+        exportPoint_text.setLayoutData(new GridData(GridData.FILL, SWT.NONE, true, false, 2, 1));
+        
+        Group group = new Group( container, SWT.NONE );
+        group.setText( Messages.getString("ExportWizardFirstPage.Define_Scope") ); //$NON-NLS-1$
+        
+        group.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false, 3, 1 ) );
+        group.setLayout( new GridLayout() );
+        
+        
+        scopeObject_button = new Button( group, SWT.RADIO );
+        scopeObject_button.setText( Messages.getString("ExportWizardFirstPage.Object") ); //$NON-NLS-1$
+        
+        scopeOneLevel_button = new Button( group, SWT.RADIO );
+        scopeOneLevel_button.setText( Messages.getString("ExportWizardFirstPage.One_level") ); //$NON-NLS-1$
+        
+        scopeSubTree = new Button( group, SWT.RADIO );
+        scopeSubTree.setText( Messages.getString("ExportWizardFirstPage.Subtree") ); //$NON-NLS-1$
+        
+        Label destionationFile_label = new Label( container, SWT.NONE );
+        destionationFile_label.setText( Messages.getString("ExportWizardFirstPage.Destination_file") ); //$NON-NLS-1$
+        
+        destionationFile_text = new Text( container, SWT.BORDER );
+        destionationFile_text.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+        
+        destionationFile_button = new Button( container, SWT.BORDER );
+        destionationFile_button.setText( Messages.getString("ExportWizardFirstPage.Browse") ); //$NON-NLS-1$
+        destionationFile_button.addSelectionListener( new SelectionAdapter() {
+            public void widgetSelected( SelectionEvent e )
+            {
+                
+                FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE );
+                fd.setText( Messages.getString("ExportWizardFirstPage.Export_to_LDIF_file") ); //$NON-NLS-1$
+                fd.setFilterPath( System.getProperty( "user.home" ) ); //$NON-NLS-1$
+                fd.setFilterExtensions( new String[] { "*.ldif;*.LDIF", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$
+                fd.setFilterNames( new String[] { Messages.getString("ExportWizardFirstPage.LDIF_files"), Messages.getString("ExportWizardFirstPage.All_files") } ); //$NON-NLS-1$ //$NON-NLS-2$
+                destionationFile_text.setText( fd.open() );
+                logger.info( "Destination file has changed : " + destionationFile_text.getText() ); //$NON-NLS-1$
+            }
+        });
+        
+        setControl(container);
+        
+        initListeners();
+        initFields();
+        updatePageComplete();
+    }
+
+    /**
+     * Initializes SWT widgets listeners
+     */
+    private void initListeners()
+    {
+        // Export Point
+        exportPoint_text.addModifyListener( new ModifyListener(){
+            public void modifyText( ModifyEvent e )
+            {
+                resetEntries();
+                updatePageComplete();
+            }
+        });
+        
+        //SCOPE
+        scopeObject_button.addSelectionListener( new SelectionAdapter(){
+            public void widgetSelected( SelectionEvent e )
+            {
+                resetEntries();
+                updatePageComplete();
+            }
+        });
+        
+        scopeOneLevel_button.addSelectionListener( new SelectionAdapter(){
+            public void widgetSelected( SelectionEvent e )
+            {
+                resetEntries();
+                updatePageComplete();
+            }
+        });
+        
+        scopeSubTree.addSelectionListener( new SelectionAdapter(){
+            public void widgetSelected( SelectionEvent e )
+            {
+                resetEntries();
+                updatePageComplete();
+            }
+        });
+        
+        // Destination file
+        destionationFile_text.addModifyListener( new ModifyListener(){
+            public void modifyText( ModifyEvent e )
+            {
+                updatePageComplete();
+            }
+        });
+        
+        destionationFile_button.addSelectionListener( new SelectionAdapter(){
+            public void widgetSelected( SelectionEvent e )
+            {
+                updatePageComplete();
+            }
+        });
+    }
+
+    /**
+     * Initializes the fields with default value
+     */
+    private void initFields()
+    {
+        // SCOPE
+        scopeSubTree.setSelection( true );
+    }
+    
+    /**
+     * Checks if the page is complete and the user allowed to access the next page
+     */
+    private void updatePageComplete()
+    {
+        setPageComplete( false );
+        setErrorMessage( null );
+        
+        // SCOPE
+        if ( ( !scopeObject_button.getSelection() ) && ( !scopeOneLevel_button.getSelection() ) && ( !scopeSubTree.getSelection() ) )
+        {
+            return;
+        }
+        
+        // DESTINATION FILE
+        if ( ( destionationFile_text.getText() == null ) || ( "".equals( destionationFile_text.getText() ) ) )  //$NON-NLS-1$
+        {
+            return;
+        }
+        
+        setPageComplete( true );
+    }
+
+    /**
+     * Resets already fetched entries
+     */
+    private void resetEntries()
+    {
+        ExportWizard wizard = ( ExportWizard ) getWizard();
+        wizard.resetEntries();        
+    }
+
+    /**
+     * Returns the Export Point
+     * @return the Export Point
+     */
+    public String getExportPoint()
+    {
+        return this.exportPoint_text.getText();
+    }
+    
+    /**
+     * Returns the Scope of the export.
+     * Values can be : SearchControls.OBJECT_SCOPE, SearchControls.ONELEVEL_SCOPE,
+     * SearchControls.SUBTREE_SCOPE or -1 (if no scope has been choosen - should never occur)
+     * @return the Scope of the export
+     */
+    public int getScope()
+    {
+        if ( scopeObject_button.getSelection() )
+        {
+            return SearchControls.OBJECT_SCOPE;
+        }
+        else if ( scopeOneLevel_button.getSelection() )
+        {
+            return SearchControls.ONELEVEL_SCOPE;
+        }
+        else if ( scopeSubTree.getSelection() )
+        {
+            return SearchControls.SUBTREE_SCOPE;
+        }
+        
+        // Should never go there
+        return -1;
+    }
+    
+    /**
+     * Returns the destination file path
+     * @return the destination file path
+     */
+    public String getDestinationFile()
+    {
+        return destionationFile_text.getText();
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizardSecondPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizardSecondPage.java?view=auto&rev=475795
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizardSecondPage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ExportWizardSecondPage.java Thu Nov 16 08:20:22 2006
@@ -0,0 +1,288 @@
+/*
+ *  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.importexport.view;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.naming.CommunicationException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.ldapstudio.importexport.Messages;
+import org.apache.directory.ldapstudio.importexport.Plugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.WizardPage;
+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.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class implements the second page of the Export Wizard.
+ * On this page, the user can see which Entries are going to be exported,
+ * according to the information entered in the previous page. 
+ */
+public class ExportWizardSecondPage extends WizardPage
+{
+    // The logger
+    private static Logger logger = LoggerFactory.getLogger( ExportWizardSecondPage.class );
+    
+    // These fields are used when an error occurs while a progress monitor is running.
+    // Since we cannot use the setErrorMessage method while a progress monitor is running,
+    // we fire an error flag and store the error message.
+    private boolean errorOccurred = false;
+    private String errorMessage = ""; //$NON-NLS-1$
+    
+    private boolean connected = false;
+    
+    private Table table;
+    private Label label;
+
+    private int entriesCounter;
+
+    /**
+     * Default constructor
+     */
+    protected ExportWizardSecondPage()
+    {
+        super( "ExportAsLDIF2" ); //$NON-NLS-1$
+        setTitle( Messages.getString("ExportWizardSecondPage.Corresponding_entries") ); //$NON-NLS-1$
+        setDescription( Messages.getString("ExportWizardSecondPage.Wizard_Page_Description") ); //$NON-NLS-1$
+        setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Plugin.ID, ImageKeys.WIZARD_EXPORT ) );
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+     */
+    public void createControl( Composite parent )
+    {
+        Composite container = new Composite( parent, SWT.NULL );
+        GridLayout layout = new GridLayout();
+        container.setLayout( layout );
+        layout.numColumns = 1;
+        
+        table = new Table( container, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | 
+            SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
+        table.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
+        
+        label = new Label( container, SWT.NONE );
+        label.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+        
+        setControl( table );
+    }
+    
+    
+    /**
+     * This method is called each time the page is shown or hidden.
+     */
+    public void setVisible( boolean visible )
+    {
+        if ( visible )
+        {
+            setErrorMessage( null );
+
+            showEntries();
+            
+        }
+        super.setVisible( visible );
+    }
+    
+    private void showEntries() {
+        logger.info( "Starting to show entries" ); //$NON-NLS-1$
+       
+        // Resetting previous displays
+        table.clearAll();
+        // SWT Table seems buggy. The ClearAll method doesn't really clears the Table.
+        // ItemCount must be set to 0 to really reset the table.
+        table.setItemCount( 0 );
+        label.setText( "" ); //$NON-NLS-1$
+        connected = false;
+        errorOccurred = false;
+        errorMessage = "";  //$NON-NLS-1$
+        
+        ExportWizard wizard = ( ExportWizard ) getWizard();
+        wizard.setExportPoint( wizard.getFirstPage().getExportPoint() );
+        wizard.setScope( wizard.getFirstPage().getScope() );
+        wizard.setDestinationFile( wizard.getFirstPage().getDestinationFile() );
+        
+        // Setting up the anonymous class to execute the progress monitor
+        IRunnableWithProgress rwp = new IRunnableWithProgress() {
+            public void run( IProgressMonitor monitor )
+            {
+                monitor.beginTask( "Fetching entries", IProgressMonitor.UNKNOWN ); //$NON-NLS-1$
+                fetchEntries( monitor );
+                monitor.done();
+            }
+        };
+        
+        // Running the Runnable with progress
+        try
+        {
+            getContainer().run(true, false, rwp);
+        }
+        catch ( InvocationTargetException e1 )
+        {
+            errorOccurred = true;
+            errorMessage = Messages.getString("ExportWizard.An_error_has_occurred_Export_couldnt_be_completed"); //$NON-NLS-1$
+        }
+        catch ( InterruptedException e1 )
+        {
+            errorOccurred = true;
+            errorMessage = Messages.getString("ExportWizard.An_error_has_occurred_Export_couldnt_be_completed"); //$NON-NLS-1$
+        }
+     
+        if ( connected )
+        {
+            // Getting corresponding entries
+            final NamingEnumeration entries = wizard.getEntries();
+
+            // Setting up the anonymous class to execute the progress monitor
+            IRunnableWithProgress op = new IRunnableWithProgress() {
+                public void run( IProgressMonitor monitor )
+                {
+                    monitor.beginTask( "Fetching entries", IProgressMonitor.UNKNOWN ); //$NON-NLS-1$
+                    try
+                    {
+                        showEntries( monitor, entries );
+                    }
+                    catch ( NamingException e )
+                    {
+                        errorOccurred = true;
+                        errorMessage = Messages.getString("ExportWizardSecondPage.Error_occurred_retreiving_entries"); //$NON-NLS-1$
+                    }
+                    monitor.done();
+                }
+            };
+            
+            // Running the Runnable with progress
+            try
+            {
+                getContainer().run(true, false, op);
+            }
+            catch ( InvocationTargetException e1 )
+            {
+                errorOccurred = true;
+                errorMessage = Messages.getString("ExportWizard.An_error_has_occurred_Export_couldnt_be_completed"); //$NON-NLS-1$
+            }
+            catch ( InterruptedException e1 )
+            {
+                errorOccurred = true;
+                errorMessage = Messages.getString("ExportWizard.An_error_has_occurred_Export_couldnt_be_completed"); //$NON-NLS-1$
+            }
+        }
+        
+        // Getting number of entries
+        int numberOfEntries = table.getItemCount();
+        
+        // Displaying number of entries
+        if ( numberOfEntries == 0 )
+        {
+            label.setText( Messages.getString("ExportWizardSecondPage.No_corresponding_entries_found") );            //$NON-NLS-1$
+        }
+        else if ( numberOfEntries == 1 )
+        {
+            label.setText( Messages.getString("ExportWizardSecondPage.1_entry_found") ); //$NON-NLS-1$
+        }
+        else
+        {
+            label.setText( numberOfEntries + Messages.getString("ExportWizardSecondPage.x_entries_found") ); //$NON-NLS-1$
+        }
+        
+        // Displaying Error Message
+        if ( errorOccurred )
+        {
+            logger.error( errorMessage );
+            displayErrorMessage( errorMessage );
+        }
+    }
+    
+
+    private void fetchEntries( IProgressMonitor monitor )
+    {
+        // Connecting to the server and fetching entries
+        try
+        {
+            ExportWizard wizard = ( ExportWizard ) getWizard();
+            wizard.fetchEntries();
+            connected = true;
+        }
+        catch ( CommunicationException ce )
+        {
+            errorOccurred = true;
+            errorMessage = Messages.getString("ExportWizardSecondPage.Connection_to_server_failed"); //$NON-NLS-1$
+            connected = false;
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            errorOccurred = true;
+            errorMessage = Messages.getString("ExportWizardSecondPage.Error_occurred_resolving_Export_Point"); //$NON-NLS-1$
+            connected = false;
+        }
+        catch ( NamingException ne )
+        {
+            errorOccurred = true;
+            errorMessage = Messages.getString("ExportWizardSecondPage.Error_occurred_retreiving_entries"); //$NON-NLS-1$
+            connected = false;
+        }
+    }
+    
+    private void showEntries( IProgressMonitor monitor, NamingEnumeration entries ) throws NamingException
+    {
+        // Adding entries to the table
+        logger.debug( "Adding entries to the table" ); //$NON-NLS-1$
+        entriesCounter = 1;
+        while (entries.hasMore()) {
+            final SearchResult sr = (SearchResult) entries.next();
+            // We need to use asyncExec to be able to access the UI. See http://wiki.eclipse.org/index.php/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
+            Display.getDefault().asyncExec(new Runnable() {
+                public void run()
+                {
+                    TableItem item2 = new TableItem( table, SWT.NONE );
+                    item2.setText( sr.getNameInNamespace() );
+                    item2.setImage( AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.ID, ImageKeys.ENTRY).createImage() ); 
+                    
+                }});
+            logger.debug( "fetching : " + sr.getNameInNamespace() ); //$NON-NLS-1$
+            monitor.setTaskName( Messages.getString("ExportWizardSecondPage.Fetching_entries") + " " + entriesCounter + Messages.getString("ExportWizardSecondPage.entries_retrieved") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+            entriesCounter++;
+        }            
+    }
+    
+    /**
+     * Displays the given message as an error message on the current page
+     * @param msg   the message to display
+     */
+    private void displayErrorMessage(String msg)
+    {
+        WizardPage page = ( WizardPage ) getContainer().getCurrentPage();
+        page.setErrorMessage( msg );     
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ImageKeys.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ImageKeys.java?view=auto&rev=475795
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ImageKeys.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ImageKeys.java Thu Nov 16 08:20:22 2006
@@ -0,0 +1,33 @@
+/*
+ *  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.importexport.view;
+
+/**
+ * This class is used to define path for images
+ */
+public class ImageKeys
+{
+    // Images for Views
+    public static final String ENTRY = "ressources/icons/entry.gif"; //$NON-NLS-1$
+    public static final String ENTRY_ADDED = "ressources/icons/entry_added.gif"; //$NON-NLS-1$
+    public static final String ENTRY_ERROR = "ressources/icons/entry_error.gif"; //$NON-NLS-1$
+    public static final String WIZARD_EXPORT = "ressources/icons/wizard_export.gif"; //$NON-NLS-1$
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ImportEntriesOnErrorDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ImportEntriesOnErrorDialog.java?view=auto&rev=475795
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ImportEntriesOnErrorDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ImportEntriesOnErrorDialog.java Thu Nov 16 08:20:22 2006
@@ -0,0 +1,182 @@
+/*
+ *  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.importexport.view;
+
+import java.util.List;
+
+import org.apache.directory.ldapstudio.importexport.Messages;
+import org.apache.directory.ldapstudio.importexport.Plugin;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * This class implement a dialog that is shown when an import has errors.
+ * It shows all the entries successfully imported and the entries that
+ * could not be imported.
+ *
+ */
+public class ImportEntriesOnErrorDialog extends Dialog
+{
+    private List<String> addedEntries;
+    private List<String> errorEntries;
+    
+    private Table entriesSuccess_table;
+    private Table entriesError_table;
+
+    
+    /**
+     * Default constructor
+     * @param parentShell
+     */
+    public ImportEntriesOnErrorDialog( Shell parentShell, List<String> addedEntries, List<String> errorEntries )
+    {
+        super( parentShell );
+        this.addedEntries = addedEntries;
+        this.errorEntries = errorEntries;
+    }
+    
+    /**
+     * Default constructor
+     * @param parentShell
+     */
+    public ImportEntriesOnErrorDialog( Shell parentShell )
+    {
+        super( parentShell );
+    }
+    
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+     */
+    protected void configureShell(Shell newShell)
+    {
+        super.configureShell(newShell);
+        newShell.setText(Messages.getString("ImportEntriesOnErrorDialog.Import_error")); //$NON-NLS-1$
+    }
+    
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    protected Control createDialogArea(Composite parent) {
+        Composite composite = new Composite(parent, SWT.NONE);
+        GridLayout layout = new GridLayout(2, true);
+        composite.setLayout(layout);
+        
+        Composite header = new Composite(composite, SWT.NONE);
+        GridLayout layout2 = new GridLayout(2, false);
+        header.setLayout( layout2 );
+        header.setLayoutData( new GridData(GridData.FILL, SWT.NONE, true, false, 2, 1));
+      
+        Canvas canvas = new Canvas(header,SWT.NO_REDRAW_RESIZE);
+        canvas.addPaintListener(new PaintListener() {
+            public void paintControl(PaintEvent e) {
+                e.gc.drawImage(PlatformUI.getWorkbench().getDisplay().getSystemImage(SWT.ICON_ERROR),0,0);
+            }
+        });
+        GridData gridDatImage = new GridData(SWT.NONE, SWT.NONE, false, false);
+        gridDatImage.heightHint = 45;
+        gridDatImage.minimumHeight = 45;
+        gridDatImage.widthHint = 60;
+        gridDatImage.minimumWidth = 60;
+        canvas.setLayoutData( gridDatImage );
+        
+        Label errorMessage_label = new Label(header, SWT.NONE);
+        errorMessage_label.setText( Messages.getString("ImportEntriesOnErrorDialog.Some_entries_could_not_be_imported") ); //$NON-NLS-1$
+        errorMessage_label.setLayoutData(new GridData( SWT.NONE, SWT.NONE, false, false));
+        
+        Label filler = new Label(composite, SWT.NONE);
+        filler.setLayoutData(new GridData( GridData.FILL, SWT.NONE, true, false, 2, 1 ));
+        
+        Label entriesSuccess_label = new Label(composite, SWT.NONE);
+        entriesSuccess_label.setText(Messages.getString("ImportEntriesOnErrorDialog.Entries_successfully_imported")); //$NON-NLS-1$
+        entriesSuccess_label.setLayoutData(new GridData(GridData.FILL, SWT.NONE, true, false));
+        
+        Label entriesError_label = new Label(composite, SWT.NONE);
+        entriesError_label.setText(Messages.getString("ImportEntriesOnErrorDialog.Entries_on_error")); //$NON-NLS-1$
+        entriesError_label.setLayoutData(new GridData(GridData.FILL, SWT.NONE, true, false));
+               
+        entriesSuccess_table = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | 
+                SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
+        GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+        gridData.heightHint = 150;
+        gridData.minimumHeight = 150;
+        gridData.widthHint = 250;
+        gridData.minimumWidth = 250;
+        entriesSuccess_table.setLayoutData(gridData);
+        
+        entriesError_table = new Table( composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
+            | SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
+        gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
+        gridData.heightHint = 150;
+        gridData.minimumHeight = 150;
+        gridData.widthHint = 250;
+        gridData.minimumWidth = 250;
+        entriesError_table.setLayoutData( gridData );
+        
+        // Tables initialization
+        initTables();
+        
+        return composite;
+    }
+    
+    /**
+     * Initializes the tables for the entries that were successfully added and the entries
+     * that were on error.
+     */
+    private void initTables()
+    {
+        // Entries successfully imported
+        for ( int i = 0; i < addedEntries.size(); i++ )
+        {
+            String  entryName = addedEntries.get( i );
+            TableItem item = new TableItem( entriesSuccess_table, SWT.NONE );
+            item.setText( entryName );
+            item.setImage( AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.ID, ImageKeys.ENTRY_ADDED).createImage() );
+        }
+        
+        // Entries on error
+        for ( int i = 0; i < errorEntries.size(); i++ )
+        {
+            String  entryName = errorEntries.get( i );
+            TableItem item = new TableItem( entriesError_table, SWT.NONE );
+            item.setText( entryName );
+            item.setImage( AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.ID, ImageKeys.ENTRY_ERROR).createImage() );
+        }
+    }
+
+    protected void createButtonsForButtonBar(Composite parent)
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ServerPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ServerPreferencePage.java?view=auto&rev=475795
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ServerPreferencePage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/java/org/apache/directory/ldapstudio/importexport/view/ServerPreferencePage.java Thu Nov 16 08:20:22 2006
@@ -0,0 +1,126 @@
+/*
+ *  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.importexport.view;
+
+import org.apache.directory.ldapstudio.importexport.Activator;
+import org.apache.directory.ldapstudio.importexport.Messages;
+import org.apache.directory.ldapstudio.importexport.Plugin;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class implements the preference page for LDAP Server configuration
+ * Host, Base DN, Port, User DN and Password are stored into preferences
+ */
+public class ServerPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
+{
+    // The logger
+    private static Logger logger = LoggerFactory.getLogger( ServerPreferencePage.class );
+    
+    public static final String HOST = "ldapstudio.apacheds_tools.prefs_host"; //$NON-NLS-1$
+    public static final String HOST_DEFAULT = "localhost"; //$NON-NLS-1$
+    public static final String PORT = "ldapstudio.apacheds_tools.prefs_port"; //$NON-NLS-1$
+    public static final String PORT_DEFAULT = "10389"; //$NON-NLS-1$
+    public static final String USER_DN = "ldapstudio.apacheds_tools.prefs_user_dn"; //$NON-NLS-1$
+    public static final String USER_DN_DEFAULT = "uid=admin,ou=system"; //$NON-NLS-1$
+    public static final String PASSWORD = "ldapstudio.apacheds_tools.prefs_password"; //$NON-NLS-1$
+    public static final String PASSWORD_DEFAULT = "secret";  //$NON-NLS-1$
+    public static final String BASE_BN = "ldapstudio.apacheds_tools.prefs_base_dn"; //$NON-NLS-1$
+    public static final String BASE_BN_DEFAULT = "ou=system";   //$NON-NLS-1$
+    
+    private StringFieldEditor host_field;
+    private StringFieldEditor port_field;
+    private StringFieldEditor userDN_field;
+    private StringFieldEditor password_field;
+    private StringFieldEditor baseDN_field;
+    
+    public ServerPreferencePage()
+    {
+        super(GRID);
+        setPreferenceStore( new ScopedPreferenceStore( new ConfigurationScope(), Plugin.ID) );
+    }
+
+    @Override
+    protected void createFieldEditors()
+    {
+        host_field = new StringFieldEditor(
+            HOST,
+            Messages.getString("ServerPreferencePage.Host"), //$NON-NLS-1$
+            getFieldEditorParent());
+        addField(host_field);
+        
+        port_field = new StringFieldEditor(
+                PORT,
+                Messages.getString("ServerPreferencePage.Port"), //$NON-NLS-1$
+                getFieldEditorParent());
+        addField(port_field);
+        
+        userDN_field = new StringFieldEditor(
+                USER_DN,
+                Messages.getString("ServerPreferencePage.User_DN"), //$NON-NLS-1$
+                getFieldEditorParent());
+        addField(userDN_field);
+        
+        password_field = new StringFieldEditor(
+                PASSWORD,
+                Messages.getString("ServerPreferencePage.Password"), //$NON-NLS-1$
+                getFieldEditorParent());
+        addField(password_field);
+    
+        baseDN_field = new StringFieldEditor(
+                BASE_BN,
+                Messages.getString("ServerPreferencePage.Base_DN"), //$NON-NLS-1$
+                getFieldEditorParent());
+        addField(baseDN_field);
+    }
+
+    public void init( IWorkbench workbench )
+    {
+    }
+    
+    @Override
+    public boolean performOk()
+    {
+        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+        
+        // We store values into preferences
+        store.setValue( HOST, host_field.getStringValue() );
+        store.setValue( PORT, port_field.getStringValue() );
+        store.setValue( USER_DN, userDN_field.getStringValue() );
+        store.setValue( PASSWORD, password_field.getStringValue() );
+        store.setValue( BASE_BN, baseDN_field.getStringValue() );
+        
+        logger.info( "Saving preferences" ); //$NON-NLS-1$
+        logger.info( "Host: " + host_field.getStringValue() ); //$NON-NLS-1$
+        logger.info( "Port: " + port_field.getStringValue() ); //$NON-NLS-1$
+        logger.info( "User DN: " + userDN_field.getStringValue() ); //$NON-NLS-1$
+        logger.info( "Base DN: " + baseDN_field.getStringValue() ); //$NON-NLS-1$
+                
+        return super.performOk();
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/resources/org/apache/directory/ldapstudio/importexport/messages.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/resources/org/apache/directory/ldapstudio/importexport/messages.properties?view=auto&rev=475795
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/resources/org/apache/directory/ldapstudio/importexport/messages.properties (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/resources/org/apache/directory/ldapstudio/importexport/messages.properties Thu Nov 16 08:20:22 2006
@@ -0,0 +1,102 @@
+#
+#  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.  
+
+#
+# This file stores the Strings used by the User Interface of the application
+#
+
+# Strings used by ImportAction Class
+ImportAction.Open_a_LDIF_file=Open a LDIF file
+ImportAction.LDIF_Files=LDIF files
+ImportAction.All_files=All files
+ImportAction.The_Selected_file=The selected file "
+ImportAction.Doesnt_exist=" doesn't exist.\nPlease try again.
+ImportAction.Error_occurred_parsing_file=An error occurred while parsing the LDIF file.\n
+ImportAction.An_error_has_occurred=An error has occurred
+ImportAction.Import_successful=Import Successful
+ImportAction.Entries_were_successfully_added=\ entries were successfully added.
+ImportAction.Host_empy=Host value in the preference page is empty.\nPlease specify a host.
+ImportAction.Port_empty=Port value in the preference page is empty.\nPlease specify a port number.
+ImportAction.Port_not_a_number=Port value in the preference page does not seem to be a number.\nPlease verify the port value.
+ImportAction.UserDN_empty=User DN value in the preference page is empty.\nPlease specify a user DN.
+ImportAction.Importing_entries=Importing entries
+ImportAction.Adding_entries_1_on=Adding an entry (1 on 
+ImportAction.Parenthesis_close=)
+ImportAction.Done=Done
+ImportAction.Adding_entries_x=Adding entries (
+ImportAction.Adding_on=\ on 
+ImportAction.Import_error=Import Error \!
+
+# Strings used by ServerPreferencePage Class
+ServerPreferencePage.Host=Host:
+ServerPreferencePage.Port=Port:
+ServerPreferencePage.User_DN=User DN:
+ServerPreferencePage.Password=Password:
+ServerPreferencePage.Base_DN=Base DN:
+
+# Strings used by ImportEntriesOnErrorDialog Class
+ImportEntriesOnErrorDialog.Import_error=Import Error \!
+ImportEntriesOnErrorDialog.Some_entries_could_not_be_imported=Some entries could not be imported. See below to identify those entries.
+ImportEntriesOnErrorDialog.Entries_successfully_imported=Entries successfully imported:
+ImportEntriesOnErrorDialog.Entries_on_error=Entries on error:
+
+# Strings used by ExportWizard Class
+ExportWizard.Error_occurred_retrieving_entries=An error occurred while retrieving entries.
+ExportWizard.Writing_file_to_disk_1_entry_done=Writing file to disk... (1 entry done)
+ExportWizard.Error_occurred_resolving_Export_Point=An error occurred when resolving Export Point.
+ExportWizard.An_error_has_occurred_Export_couldnt_be_completed=An error has occured. Export could not be completed.
+ExportWizard.The_path_to_the_destination_file_seems_to_be_wrong=The path to the destination file seems to be wrong. Can't export to this location.
+ExportWizard.An_unknown_error_has_occured_File_could_not_be_saved=An unknown error has occurred. File could not be saved.
+ExportWizard.Replacing_existing_file=Replace existing file ?
+ExportWizard.Create_directory=\ Create directory ?
+ExportWizard.Export=Export
+ExportWizard.The_file=The file 
+ExportWizard.Already_exists=\ already exists.\nWould you like to replace it?
+ExportWizard.Writing_file=Writing file...
+ExportWizard.Entries_done=\ entries done)
+ExportWizard.Writing_file_to_disk=Writing file to disk... (
+ExportWizard.Target_directory_doesnt_exist=Target directory does not exist.\nWould you like to create it ?
+ExportWizard.Connection_to_server_failed=Connection to server failed. Please verify your server settings.
+ExportWizard.Error_occurred_writing_file_to_disk_File_could_not_be_saved=An error occurred while writing the file to disk. The file could not be saved.
+
+
+# Strings used by ExportWizardFirstPage Class
+ExportWizardFirstPage.Export_as_LDIF=Export as LDIF
+ExportWizardFirstPage.Wizard_Page_Description=Specify export point, export options and destination file.
+ExportWizardFirstPage.Export_Point=Export Point:
+ExportWizardFirstPage.Define_Scope=Define Scope
+ExportWizardFirstPage.Object=Object
+ExportWizardFirstPage.One_level=One level
+ExportWizardFirstPage.Subtree=Subtree
+ExportWizardFirstPage.Browse=Browse...
+ExportWizardFirstPage.LDIF_files=LDIF files
+ExportWizardFirstPage.All_files=All files
+ExportWizardFirstPage.Destination_file=Destination file:
+ExportWizardFirstPage.Export_to_LDIF_file=Export to LDIF file
+
+# Strings used by ExportWizardSecondPage Class
+ExportWizardSecondPage.Corresponding_entries=Corresponding entries
+ExportWizardSecondPage.Error_occurred_resolving_Export_Point=An error occurred when resolving Export Point.
+ExportWizardSecondPage.Wizard_Page_Description=The following entries are going to be exported.
+ExportWizardSecondPage.Connection_to_server_failed=Connection to server failed. Please verify your server settings.
+ExportWizardSecondPage.Error_occurred_retreiving_entries=An error occurred while retrieving entries.
+ExportWizardSecondPage.No_corresponding_entries_found=No corresponding entries were found.
+ExportWizardSecondPage.1_entry_found=1 entry was found.
+ExportWizardSecondPage.x_entries_found=\ entries were found.
+ExportWizardSecondPage.Fetching_entries=Fetching entries:
+ExportWizardSecondPage.entries_retrieved=\ entries retrieved

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/resources/plugin.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/resources/plugin.properties?view=auto&rev=475795
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/resources/plugin.properties (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-importexport-plugin/src/main/resources/plugin.properties Thu Nov 16 08:20:22 2006
@@ -0,0 +1,27 @@
+#
+#  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.  
+
+# Contains translated Strings for the Import/Export plugin
+ldapstudio-importexport.menu.name=LDIF
+ldapstudio-importexport.actions.import.label=Import...
+ldapstudio-importexport.actions.import.tooltip=Imports entries from LDIF file
+ldapstudio-importexport.actions.export.label=Export...
+ldapstudio-importexport.actions.export.tooltip=Exports entries to LDIF file
+ldapstudio-importexport.actions.preferences.label=Show preferences...
+ldapstudio-importexport.actions.preferences.tooltip=Shows preferences
+ldapstudio-importexport.wizards.export.name=Export as LDIF



Mime
View raw message