directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592094 [24/35] - in /directory/sandbox/felixk/studio-schemaeditor: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ src/m...
Date Mon, 05 Nov 2007 17:15:02 GMT
Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java Mon Nov  5 09:14:24 2007
@@ -0,0 +1,365 @@
+/*
+ *  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.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginConstants;
+import org.apache.directory.studio.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.schemaeditor.model.Schema;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.LabelProvider;
+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.graphics.Image;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class represents the WizardPage of the ExportSchemasAsOpenLdapWizard.
+ * <p>
+ * It is used to let the user enter the informations about the
+ * schemas he wants to export and where to export.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportSchemasAsOpenLdapWizardPage extends WizardPage
+{
+    /** The selected schemas */
+    private Schema[] selectedSchemas = new Schema[0];
+
+    /** The SchemaHandler */
+    private SchemaHandler schemaHandler;
+
+    // UI Fields
+    private CheckboxTableViewer schemasTableViewer;
+    private Button schemasTableSelectAllButton;
+    private Button schemasTableDeselectAllButton;
+    private Label exportDirectoryLabel;
+    private Text exportDirectoryText;
+    private Button exportDirectoryButton;
+
+
+    /**
+     * Creates a new instance of ExportSchemasAsXmlWizardPage.
+     */
+    protected ExportSchemasAsOpenLdapWizardPage()
+    {
+        super( "ExportSchemasAsOpenLdapWizardPage" );
+        setTitle( "Export schemas as OpenLdap files" );
+        setDescription( "Please select the schemas to export as OpenLdap files." );
+        setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+            PluginConstants.IMG_SCHEMAS_EXPORT_WIZARD ) );
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+     */
+    public void createControl( Composite parent )
+    {
+        Composite composite = new Composite( parent, SWT.NULL );
+        GridLayout layout = new GridLayout();
+        composite.setLayout( layout );
+
+        // Schemas Group
+        Group schemasGroup = new Group( composite, SWT.NONE );
+        schemasGroup.setText( "Schemas" );
+        schemasGroup.setLayout( new GridLayout( 2, false ) );
+        schemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Schemas TableViewer
+        Label schemasLabel = new Label( schemasGroup, SWT.NONE );
+        schemasLabel.setText( "Select the schemas to export:" );
+        schemasLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+        schemasTableViewer = new CheckboxTableViewer( new Table( schemasGroup, SWT.BORDER | SWT.CHECK
+            | SWT.FULL_SELECTION ) );
+        GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 );
+        schemasTableViewerGridData.heightHint = 125;
+        schemasTableViewer.getTable().setLayoutData( schemasTableViewerGridData );
+        schemasTableViewer.setContentProvider( new ArrayContentProvider() );
+        schemasTableViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return ( ( Schema ) element ).getName();
+                }
+
+                // Default
+                return super.getText( element );
+            }
+
+
+            public Image getImage( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_SCHEMA )
+                        .createImage();
+                }
+
+                // Default
+                return super.getImage( element );
+            }
+        } );
+        schemasTableViewer.addCheckStateListener( new ICheckStateListener()
+        {
+            /**
+             * Notifies of a change to the checked state of an element.
+             *
+             * @param event
+             *      event object describing the change
+             */
+            public void checkStateChanged( CheckStateChangedEvent event )
+            {
+                dialogChanged();
+            }
+        } );
+        schemasTableSelectAllButton = new Button( schemasGroup, SWT.PUSH );
+        schemasTableSelectAllButton.setText( "Select All" );
+        schemasTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemasTableSelectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemasTableViewer.setAllChecked( true );
+                dialogChanged();
+            }
+        } );
+        schemasTableDeselectAllButton = new Button( schemasGroup, SWT.PUSH );
+        schemasTableDeselectAllButton.setText( "Deselect All" );
+        schemasTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemasTableDeselectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemasTableViewer.setAllChecked( false );
+                dialogChanged();
+            }
+        } );
+
+        // Export Destination Group
+        Group exportDestinationGroup = new Group( composite, SWT.NULL );
+        exportDestinationGroup.setText( "Export Destination" );
+        exportDestinationGroup.setLayout( new GridLayout( 3, false ) );
+        exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        exportDirectoryLabel = new Label( exportDestinationGroup, SWT.NONE );
+        exportDirectoryLabel.setText( "Directory:" );
+        exportDirectoryText = new Text( exportDestinationGroup, SWT.BORDER );
+        exportDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        exportDirectoryText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        exportDirectoryButton = new Button( exportDestinationGroup, SWT.PUSH );
+        exportDirectoryButton.setText( "Browse..." );
+        exportDirectoryButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseExportDirectory();
+                dialogChanged();
+            }
+        } );
+
+        initFields();
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Initializes the UI Fields.
+     */
+    private void initFields()
+    {
+        // Filling the Schemas table
+        if ( schemaHandler != null )
+        {
+            List<Schema> schemas = new ArrayList<Schema>();
+            schemas.addAll( schemaHandler.getSchemas() );
+
+            Collections.sort( schemas, new Comparator<Schema>()
+            {
+                public int compare( Schema o1, Schema o2 )
+                {
+                    return o1.getName().compareToIgnoreCase( o2.getName() );
+                }
+            } );
+
+            schemasTableViewer.setInput( schemas );
+
+            // Setting the selected schemas
+            schemasTableViewer.setCheckedElements( selectedSchemas );
+        }
+
+        displayErrorMessage( null );
+        setPageComplete( false );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles 'browse' button is selected.
+     */
+    private void chooseExportDirectory()
+    {
+        DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
+        dialog.setText( "Choose Folder" );
+        dialog.setMessage( "Select the folder in which export the files." );
+
+        String selectedDirectory = dialog.open();
+        if ( selectedDirectory != null )
+        {
+            exportDirectoryText.setText( selectedDirectory );
+        }
+    }
+
+
+    /**
+     * This method is called when the user modifies something in the UI.
+     */
+    private void dialogChanged()
+    {
+        // Schemas table
+        if ( schemasTableViewer.getCheckedElements().length == 0 )
+        {
+            displayErrorMessage( "One or several schemas must be selected." );
+            return;
+        }
+
+        // Export Directory
+        String directory = exportDirectoryText.getText();
+        if ( ( directory == null ) || ( directory.equals( "" ) ) )
+        {
+            displayErrorMessage( "A directory must be selected." );
+            return;
+        }
+        else
+        {
+            File directoryFile = new File( directory );
+            if ( !directoryFile.exists() )
+            {
+                displayErrorMessage( "The selected directory does not exist." );
+                return;
+            }
+            else if ( !directoryFile.isDirectory() )
+            {
+                displayErrorMessage( "The selected directory is not a directory." );
+                return;
+            }
+            else if ( !directoryFile.canWrite() )
+            {
+                displayErrorMessage( "The selected directory is not writable." );
+                return;
+            }
+        }
+
+        displayErrorMessage( null );
+    }
+
+
+    /**
+     * Displays an error message and set the page status as incomplete
+     * if the message is not null.
+     *
+     * @param message
+     *      the message to display
+     */
+    private void displayErrorMessage( String message )
+    {
+        setErrorMessage( message );
+        setPageComplete( message == null );
+    }
+
+
+    /**
+     * Gets the selected schemas.
+     *
+     * @return
+     *      the selected schemas
+     */
+    public Schema[] getSelectedSchemas()
+    {
+        Object[] selectedSchemas = schemasTableViewer.getCheckedElements();
+
+        List<Schema> schemas = new ArrayList<Schema>();
+        for ( Object schema : selectedSchemas )
+        {
+            schemas.add( ( Schema ) schema );
+        }
+
+        return schemas.toArray( new Schema[0] );
+    }
+
+
+    /**
+     * Sets the selected projects.
+     *
+     * @param schemas
+     *      the schemas
+     */
+    public void setSelectedSchemas( Schema[] schemas )
+    {
+        selectedSchemas = schemas;
+    }
+
+
+    /**
+     * Gets the export directory.
+     *
+     * @return
+     *      the export directory
+     */
+    public String getExportDirectory()
+    {
+        return exportDirectoryText.getText();
+    }
+}

Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java Mon Nov  5 09:14:24 2007
@@ -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.studio.schemaeditor.view.wizards;
+
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginUtils;
+import org.apache.directory.studio.schemaeditor.model.Schema;
+import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileExporter;
+import org.apache.directory.studio.schemaeditor.view.ViewUtils;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+
+
+/**
+ * This class represents the wizard to export schemas as XML.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportSchemasAsXmlWizard extends Wizard implements IExportWizard
+{
+    public static final String ID = Activator.PLUGIN_ID + ".wizards.ExportSchemasAsXmlWizard";
+
+    /** The selected schemas */
+    private Schema[] selectedSchemas = new Schema[0];
+
+    // The pages of the wizard
+    private ExportSchemasAsXmlWizardPage page;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages()
+    {
+        // Creating pages
+        page = new ExportSchemasAsXmlWizardPage();
+        page.setSelectedSchemas( selectedSchemas );
+
+        // Adding pages
+        addPage( page );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    public boolean performFinish()
+    {
+        final Schema[] selectedSchemas = page.getSelectedSchemas();
+
+        int exportType = page.getExportType();
+        if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_MULTIPLE_FILES )
+        {
+            final String exportDirectory = page.getExportDirectory();
+            try
+            {
+                getContainer().run( true, true, new IRunnableWithProgress()
+                {
+                    public void run( IProgressMonitor monitor )
+                    {
+                        monitor.beginTask( "Exporting schemas: ", selectedSchemas.length );
+                        for ( Schema schema : selectedSchemas )
+                        {
+                            monitor.subTask( schema.getName() );
+
+                            try
+                            {
+                                BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportDirectory + "/"
+                                    + schema.getName() + ".xml" ) );
+                                buffWriter.write( XMLSchemaFileExporter.toXml( schema ) );
+                                buffWriter.close();
+                            }
+                            catch ( IOException e )
+                            {
+                                PluginUtils.logError( "An error occured when saving the schema " + schema.getName()
+                                    + ".", e );
+                                ViewUtils.displayErrorMessageBox( "Error", "An error occured when saving the schema "
+                                    + schema.getName() + "." );
+                            }
+                            monitor.worked( 1 );
+                        }
+                        monitor.done();
+                    }
+                } );
+            }
+            catch ( InvocationTargetException e )
+            {
+                // Nothing to do (it will never occur)
+            }
+            catch ( InterruptedException e )
+            {
+                // Nothing to do.
+            }
+        }
+        else if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_SINGLE_FILE )
+        {
+            final String exportFile = page.getExportFile();
+            try
+            {
+                getContainer().run( true, true, new IRunnableWithProgress()
+                {
+                    public void run( IProgressMonitor monitor )
+                    {
+                        monitor.beginTask( "Exporting schemas", 1 );
+                        try
+                        {
+                            BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportFile ) );
+                            buffWriter.write( XMLSchemaFileExporter.toXml( selectedSchemas ) );
+                            buffWriter.close();
+                        }
+                        catch ( IOException e )
+                        {
+                            PluginUtils.logError( "An error occured when saving the schemas.", e );
+                            ViewUtils.displayErrorMessageBox( "Error", "An error occured when saving the schemas." );
+                        }
+                        monitor.worked( 1 );
+                        monitor.done();
+                    }
+                } );
+            }
+            catch ( InvocationTargetException e )
+            {
+                // Nothing to do (it will never occur)
+            }
+            catch ( InterruptedException e )
+            {
+                // Nothing to do.
+            }
+        }
+
+        return true;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+     */
+    public void init( IWorkbench workbench, IStructuredSelection selection )
+    {
+        setNeedsProgressMonitor( true );
+    }
+
+
+    /**
+     * Sets the selected projects.
+     *
+     * @param schemas
+     *      the schemas
+     */
+    public void setSelectedSchemas( Schema[] schemas )
+    {
+        selectedSchemas = schemas;
+    }
+}

Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java Mon Nov  5 09:14:24 2007
@@ -0,0 +1,542 @@
+/*
+ *  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.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginConstants;
+import org.apache.directory.studio.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.schemaeditor.model.Schema;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.LabelProvider;
+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.graphics.Image;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class represents the WizardPage of the ExportSchemasAsXmlWizard.
+ * <p>
+ * It is used to let the user enter the informations about the
+ * schemas he wants to export and where to export.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportSchemasAsXmlWizardPage extends WizardPage
+{
+    /** The selected schemas */
+    private Schema[] selectedSchemas = new Schema[0];
+
+    /** The SchemaHandler */
+    private SchemaHandler schemaHandler;
+
+    public static final int EXPORT_MULTIPLE_FILES = 0;
+    public static final int EXPORT_SINGLE_FILE = 1;
+
+    // UI Fields
+    private CheckboxTableViewer schemasTableViewer;
+    private Button schemasTableSelectAllButton;
+    private Button schemasTableDeselectAllButton;
+    private Button exportMultipleFilesRadio;
+    private Label exportMultipleFilesLabel;
+    private Text exportMultipleFilesText;
+    private Button exportMultipleFilesButton;
+    private Button exportSingleFileRadio;
+    private Label exportSingleFileLabel;
+    private Text exportSingleFileText;
+    private Button exportSingleFileButton;
+
+
+    /**
+     * Creates a new instance of ExportSchemasAsXmlWizardPage.
+     */
+    protected ExportSchemasAsXmlWizardPage()
+    {
+        super( "ExportSchemasAsXmlWizardPage" );
+        setTitle( "Export schemas as XML file(s)" );
+        setDescription( "Please select the schemas to export as XML file(s)." );
+        setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+            PluginConstants.IMG_SCHEMAS_EXPORT_WIZARD ) );
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+     */
+    public void createControl( Composite parent )
+    {
+        Composite composite = new Composite( parent, SWT.NULL );
+        GridLayout layout = new GridLayout();
+        composite.setLayout( layout );
+
+        // Schemas Group
+        Group schemasGroup = new Group( composite, SWT.NONE );
+        schemasGroup.setText( "Schemas" );
+        schemasGroup.setLayout( new GridLayout( 2, false ) );
+        schemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Schemas TableViewer
+        Label schemasLabel = new Label( schemasGroup, SWT.NONE );
+        schemasLabel.setText( "Select the schemas to export:" );
+        schemasLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+        schemasTableViewer = new CheckboxTableViewer( new Table( schemasGroup, SWT.BORDER | SWT.CHECK
+            | SWT.FULL_SELECTION ) );
+        GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 );
+        schemasTableViewerGridData.heightHint = 125;
+        schemasTableViewer.getTable().setLayoutData( schemasTableViewerGridData );
+        schemasTableViewer.setContentProvider( new ArrayContentProvider() );
+        schemasTableViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return ( ( Schema ) element ).getName();
+                }
+
+                // Default
+                return super.getText( element );
+            }
+
+
+            public Image getImage( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_SCHEMA )
+                        .createImage();
+                }
+
+                // Default
+                return super.getImage( element );
+            }
+        } );
+        schemasTableViewer.addCheckStateListener( new ICheckStateListener()
+        {
+            /**
+             * Notifies of a change to the checked state of an element.
+             *
+             * @param event
+             *      event object describing the change
+             */
+            public void checkStateChanged( CheckStateChangedEvent event )
+            {
+                dialogChanged();
+            }
+        } );
+        schemasTableSelectAllButton = new Button( schemasGroup, SWT.PUSH );
+        schemasTableSelectAllButton.setText( "Select All" );
+        schemasTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemasTableSelectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemasTableViewer.setAllChecked( true );
+                dialogChanged();
+            }
+        } );
+        schemasTableDeselectAllButton = new Button( schemasGroup, SWT.PUSH );
+        schemasTableDeselectAllButton.setText( "Deselect All" );
+        schemasTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemasTableDeselectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemasTableViewer.setAllChecked( false );
+                dialogChanged();
+            }
+        } );
+
+        // Export Destination Group
+        Group exportDestinationGroup = new Group( composite, SWT.NULL );
+        exportDestinationGroup.setText( "Export Destination" );
+        exportDestinationGroup.setLayout( new GridLayout( 4, false ) );
+        exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Export Multiple Files
+        exportMultipleFilesRadio = new Button( exportDestinationGroup, SWT.RADIO );
+        exportMultipleFilesRadio.setText( "Export each schema as a separate file." );
+        exportMultipleFilesRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 4, 1 ) );
+        exportMultipleFilesRadio.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                exportMultipleFilesSelected();
+                dialogChanged();
+            }
+        } );
+        Label exportMultipleFilesFiller = new Label( exportDestinationGroup, SWT.NONE );
+        exportMultipleFilesFiller.setText( "    " );
+        exportMultipleFilesLabel = new Label( exportDestinationGroup, SWT.NONE );
+        exportMultipleFilesLabel.setText( "Directory:" );
+        exportMultipleFilesText = new Text( exportDestinationGroup, SWT.BORDER );
+        exportMultipleFilesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        exportMultipleFilesText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        exportMultipleFilesButton = new Button( exportDestinationGroup, SWT.PUSH );
+        exportMultipleFilesButton.setText( "Browse..." );
+        exportMultipleFilesButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseExportDirectory();
+                dialogChanged();
+            }
+        } );
+
+        // Export Single File
+        exportSingleFileRadio = new Button( exportDestinationGroup, SWT.RADIO );
+        exportSingleFileRadio.setText( "Export the schemas as a single file." );
+        exportSingleFileRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 4, 1 ) );
+        exportSingleFileRadio.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                exportSingleFileSelected();
+                dialogChanged();
+            }
+        } );
+        Label exportSingleFileFiller = new Label( exportDestinationGroup, SWT.NONE );
+        exportSingleFileFiller.setText( "    " );
+        exportSingleFileLabel = new Label( exportDestinationGroup, SWT.NONE );
+        exportSingleFileLabel.setText( "Export File:" );
+        exportSingleFileText = new Text( exportDestinationGroup, SWT.BORDER );
+        exportSingleFileText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        exportSingleFileText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        exportSingleFileButton = new Button( exportDestinationGroup, SWT.PUSH );
+        exportSingleFileButton.setText( "Browse..." );
+        exportSingleFileButton.addSelectionListener( new SelectionAdapter()
+        {
+            /* (non-Javadoc)
+             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+             */
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseExportFile();
+                dialogChanged();
+            }
+        } );
+
+        initFields();
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Initializes the UI Fields.
+     */
+    private void initFields()
+    {
+        // Filling the Schemas table
+        if ( schemaHandler != null )
+        {
+            List<Schema> schemas = new ArrayList<Schema>();
+            schemas.addAll( schemaHandler.getSchemas() );
+
+            Collections.sort( schemas, new Comparator<Schema>()
+            {
+                public int compare( Schema o1, Schema o2 )
+                {
+                    return o1.getName().compareToIgnoreCase( o2.getName() );
+                }
+            } );
+
+            schemasTableViewer.setInput( schemas );
+
+            // Setting the selected schemas
+            schemasTableViewer.setCheckedElements( selectedSchemas );
+        }
+
+        // Selecting the Multiple Files choice
+        exportMultipleFilesSelected();
+
+        displayErrorMessage( null );
+        setPageComplete( false );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles radio button is selected.
+     */
+    private void exportMultipleFilesSelected()
+    {
+        exportMultipleFilesRadio.setSelection( true );
+        exportMultipleFilesLabel.setEnabled( true );
+        exportMultipleFilesText.setEnabled( true );
+        exportMultipleFilesButton.setEnabled( true );
+
+        exportSingleFileRadio.setSelection( false );
+        exportSingleFileLabel.setEnabled( false );
+        exportSingleFileText.setEnabled( false );
+        exportSingleFileButton.setEnabled( false );
+    }
+
+
+    /**
+     * This method is called when the exportSingleFile radio button is selected.
+     */
+    private void exportSingleFileSelected()
+    {
+        exportMultipleFilesRadio.setSelection( false );
+        exportMultipleFilesLabel.setEnabled( false );
+        exportMultipleFilesText.setEnabled( false );
+        exportMultipleFilesButton.setEnabled( false );
+
+        exportSingleFileRadio.setSelection( true );
+        exportSingleFileLabel.setEnabled( true );
+        exportSingleFileText.setEnabled( true );
+        exportSingleFileButton.setEnabled( true );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles 'browse' button is selected.
+     */
+    private void chooseExportDirectory()
+    {
+        DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
+        dialog.setText( "Choose Folder" );
+        dialog.setMessage( "Select the folder in which export the files." );
+
+        String selectedDirectory = dialog.open();
+        if ( selectedDirectory != null )
+        {
+            exportMultipleFilesText.setText( selectedDirectory );
+        }
+    }
+
+
+    /**
+     * This method is called when the exportSingleFile 'browse' button is selected.
+     */
+    private void chooseExportFile()
+    {
+        FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE );
+        dialog.setText( "Select File" );
+        dialog.setFilterExtensions( new String[]
+            { "*.xml", "*" } );
+        dialog.setFilterNames( new String[]
+            { "XML Files", "All Files" } );
+        dialog.setFilterPath( exportSingleFileText.getText() );
+
+        String selectedFile = dialog.open();
+        if ( selectedFile != null )
+        {
+            exportSingleFileText.setText( selectedFile );
+        }
+    }
+
+
+    /**
+     * This method is called when the user modifies something in the UI.
+     */
+    private void dialogChanged()
+    {
+        // Schemas table
+        if ( schemasTableViewer.getCheckedElements().length == 0 )
+        {
+            displayErrorMessage( "One or several schemas must be selected." );
+            return;
+        }
+
+        // Export option
+        if ( exportMultipleFilesRadio.getSelection() )
+        {
+            String directory = exportMultipleFilesText.getText();
+            if ( ( directory == null ) || ( directory.equals( "" ) ) )
+            {
+                displayErrorMessage( "A directory must be selected." );
+                return;
+            }
+            else
+            {
+                File directoryFile = new File( directory );
+                if ( !directoryFile.exists() )
+                {
+                    displayErrorMessage( "The selected directory does not exist." );
+                    return;
+                }
+                else if ( !directoryFile.isDirectory() )
+                {
+                    displayErrorMessage( "The selected directory is not a directory." );
+                    return;
+                }
+                else if ( !directoryFile.canWrite() )
+                {
+                    displayErrorMessage( "The selected directory is not writable." );
+                    return;
+                }
+            }
+        }
+        else if ( exportSingleFileRadio.getSelection() )
+        {
+            String exportFile = exportSingleFileText.getText();
+            if ( ( exportFile == null ) || ( exportFile.equals( "" ) ) )
+            {
+                displayErrorMessage( "A file must be selected." );
+                return;
+            }
+            else
+            {
+                File file = new File( exportFile );
+                if ( !file.getParentFile().canWrite() )
+                {
+                    displayErrorMessage( "The selected file is not writable." );
+                    return;
+                }
+            }
+        }
+
+        displayErrorMessage( null );
+    }
+
+
+    /**
+     * Displays an error message and set the page status as incomplete
+     * if the message is not null.
+     *
+     * @param message
+     *      the message to display
+     */
+    private void displayErrorMessage( String message )
+    {
+        setErrorMessage( message );
+        setPageComplete( message == null );
+    }
+
+
+    /**
+     * Gets the selected schemas.
+     *
+     * @return
+     *      the selected schemas
+     */
+    public Schema[] getSelectedSchemas()
+    {
+        Object[] selectedSchemas = schemasTableViewer.getCheckedElements();
+
+        List<Schema> schemas = new ArrayList<Schema>();
+        for ( Object schema : selectedSchemas )
+        {
+            schemas.add( ( Schema ) schema );
+        }
+
+        return schemas.toArray( new Schema[0] );
+    }
+
+
+    /**
+     * Sets the selected projects.
+     *
+     * @param schemas
+     *      the schemas
+     */
+    public void setSelectedSchemas( Schema[] schemas )
+    {
+        selectedSchemas = schemas;
+    }
+
+
+    /**
+     * Gets the type of export.
+     * <p>
+     * Values can either EXPORT_MULTIPLE_FILES or EXPORT_SINGLE_FILE.
+     * 
+     * @return
+     *      the type of export
+     */
+    public int getExportType()
+    {
+        if ( exportMultipleFilesRadio.getSelection() )
+        {
+            return EXPORT_MULTIPLE_FILES;
+        }
+        else if ( exportSingleFileRadio.getSelection() )
+        {
+            return EXPORT_SINGLE_FILE;
+        }
+
+        // Default 
+        return EXPORT_MULTIPLE_FILES;
+    }
+
+
+    /**
+     * Gets the export directory.
+     *
+     * @return
+     *      the export directory
+     */
+    public String getExportDirectory()
+    {
+        return exportMultipleFilesText.getText();
+    }
+
+
+    /**
+     * Gets the export file.
+     *
+     * @return
+     *      the export file
+     */
+    public String getExportFile()
+    {
+        return exportSingleFileText.getText();
+    }
+}

Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java Mon Nov  5 09:14:24 2007
@@ -0,0 +1,489 @@
+/*
+ *  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.schemaeditor.view.wizards;
+
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.converter.schema.AttributeTypeHolder;
+import org.apache.directory.shared.converter.schema.ObjectClassHolder;
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginUtils;
+import org.apache.directory.studio.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.schemaeditor.model.Schema;
+import org.apache.directory.studio.schemaeditor.view.ViewUtils;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+
+
+/**
+ * This class represents the wizard to export schemas for Apache DS.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportSchemasForADSWizard extends Wizard implements IExportWizard
+{
+    public static final String ID = Activator.PLUGIN_ID + ".wizards.ExportSchemasForADSWizard";
+
+    /** The selected schemas */
+    private Schema[] selectedSchemas = new Schema[0];
+
+    // The pages of the wizard
+    private ExportSchemasForADSWizardPage page;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages()
+    {
+        // Creating pages
+        page = new ExportSchemasForADSWizardPage();
+        page.setSelectedSchemas( selectedSchemas );
+
+        // Adding pages
+        addPage( page );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    public boolean performFinish()
+    {
+        final Schema[] selectedSchemas = page.getSelectedSchemas();
+
+        int exportType = page.getExportType();
+        if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_MULTIPLE_FILES )
+        {
+            final String exportDirectory = page.getExportDirectory();
+            try
+            {
+                getContainer().run( true, true, new IRunnableWithProgress()
+                {
+                    public void run( IProgressMonitor monitor )
+                    {
+                        monitor.beginTask( "Exporting schemas: ", selectedSchemas.length );
+                        for ( Schema schema : selectedSchemas )
+                        {
+                            monitor.subTask( schema.getName() );
+
+                            StringBuffer sb = new StringBuffer();
+                            DateFormat format = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.MEDIUM );
+                            Date date = new Date();
+                            sb.append( "# Generated by Apache Directory Studio on " + format.format( date ) + "\n" );
+                            sb.append( "\n" );
+
+                            try
+                            {
+                                toLdif( schema, sb );
+
+                                BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportDirectory + "/"
+                                    + schema.getName() + ".ldif" ) );
+                                buffWriter.write( sb.toString() );
+                                buffWriter.close();
+                            }
+                            catch ( IOException e )
+                            {
+                                PluginUtils.logError( "An error occured when saving the schema " + schema.getName()
+                                    + ".", e );
+                                ViewUtils.displayErrorMessageBox( "Error", "An error occured when saving the schema "
+                                    + schema.getName() + "." );
+                            }
+                            catch ( NamingException e )
+                            {
+                                PluginUtils.logError( "An error occured when saving the schema " + schema.getName()
+                                    + ".", e );
+                                ViewUtils.displayErrorMessageBox( "Error", "An error occured when saving the schema "
+                                    + schema.getName() + "." );
+                            }
+                            monitor.worked( 1 );
+                        }
+                        monitor.done();
+                    }
+                } );
+            }
+            catch ( InvocationTargetException e )
+            {
+                // Nothing to do (it will never occur)
+                e.printStackTrace();
+            }
+            catch ( InterruptedException e )
+            {
+                // Nothing to do.
+            }
+        }
+        else if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_SINGLE_FILE )
+        {
+            final String exportFile = page.getExportFile();
+            try
+            {
+                getContainer().run( true, true, new IRunnableWithProgress()
+                {
+                    public void run( IProgressMonitor monitor )
+                    {
+                        monitor.beginTask( "Exporting schemas ", 1 );
+
+                        StringBuffer sb = new StringBuffer();
+                        DateFormat format = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.MEDIUM );
+                        Date date = new Date();
+                        sb.append( "# Generated by Apache Directory Studio on " + format.format( date ) + "\n" );
+                        sb.append( "\n" );
+
+                        for ( Schema schema : selectedSchemas )
+                        {
+                            try
+                            {
+                                toLdif( schema, sb );
+                            }
+                            catch ( NamingException e )
+                            {
+                                PluginUtils.logError( "An error occured when saving the schema " + schema.getName()
+                                    + ".", e );
+                                ViewUtils.displayErrorMessageBox( "Error", "An error occured when saving the schema "
+                                    + schema.getName() + "." );
+                            }
+                        }
+
+                        try
+                        {
+                            BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportFile ) );
+                            buffWriter.write( sb.toString() );
+                            buffWriter.close();
+                        }
+                        catch ( IOException e )
+                        {
+                            PluginUtils.logError( "An error occured when saving the schemas.", e );
+                            ViewUtils.displayErrorMessageBox( "Error", "An error occured when saving the schemas." );
+                        }
+                        monitor.worked( 1 );
+                        monitor.done();
+                    }
+                } );
+            }
+            catch ( InvocationTargetException e )
+            {
+                // Nothing to do (it will never occur)
+            }
+            catch ( InterruptedException e )
+            {
+                // Nothing to do.
+            }
+        }
+
+        return true;
+    }
+
+
+    /**
+     * Converts the given schema as its LDIF for Apache DS representation and stores it into the given StringBuffer.
+     *
+     * @param schema
+     *      the schema
+     * @param sb
+     *      the StringBuffer
+     * @throws NamingException
+     *      if an error occurs during the conversion
+     */
+    private void toLdif( Schema schema, StringBuffer sb ) throws NamingException
+    {
+        sb.append( "# SCHEMA '" + schema.getName().toUpperCase() + "'\n" );
+
+        sb.append( "dn: cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: metaSchema\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "cn: " + schema.getName() + "\n" );
+        String[] schemaDependencies = getSchemaDependencies( schema );
+        for ( String schemaName : schemaDependencies )
+        {
+            sb.append( "m-dependencies: " + schemaName + "\n" );
+        }
+        sb.append( "\n" );
+
+        // Generation the Attribute Types Node
+        sb.append( "dn: ou=attributeTypes, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: attributetypes\n" );
+        sb.append( "\n" );
+
+        // Generating LDIF for Attributes Types
+        for ( AttributeTypeImpl at : schema.getAttributeTypes() )
+        {
+            AttributeTypeHolder holder = new AttributeTypeHolder( at.getOid() );
+            holder.setCollective( at.isCollective() );
+            holder.setDescription( at.getDescription() );
+            holder.setEquality( at.getEqualityName() );
+            List<String> names = new ArrayList<String>();
+            for ( String name : at.getNames() )
+            {
+                names.add( name );
+            }
+            holder.setNames( names );
+            holder.setNoUserModification( !at.isCanUserModify() );
+            holder.setObsolete( at.isObsolete() );
+            holder.setOrdering( at.getOrderingName() );
+            holder.setSingleValue( at.isSingleValue() );
+            holder.setSubstr( at.getSubstrName() );
+            holder.setSuperior( at.getSuperiorName() );
+            holder.setSyntax( at.getSyntaxOid() );
+            holder.setOidLen( at.getLength() );
+            holder.setUsage( at.getUsage() );
+
+            sb.append( holder.toLdif( schema.getName() ) + "\n" );
+        }
+
+        // Generation the Comparators Node
+        sb.append( "dn: ou=comparators, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: comparators\n" );
+        sb.append( "\n" );
+
+        // Generation the DIT Content Rules Node
+        sb.append( "dn: ou=ditContentRules, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: ditcontentrules\n" );
+        sb.append( "\n" );
+
+        // Generation the DIT Structure RulesNode
+        sb.append( "dn: ou=ditStructureRules, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: ditstructurerules\n" );
+        sb.append( "\n" );
+
+        // Generation the Matching Rules Node
+        sb.append( "dn: ou=matchingRules, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: matchingrules\n" );
+        sb.append( "\n" );
+
+        // Generation the Matching Rule Use Node
+        sb.append( "dn: ou=matchingRuleUse, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: matchingruleuse\n" );
+        sb.append( "\n" );
+
+        // Generation the Name Forms Node
+        sb.append( "dn: ou=nameForms, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: nameforms\n" );
+        sb.append( "\n" );
+
+        // Generation the Normalizers Node
+        sb.append( "dn: ou=normalizers, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: normalizers\n" );
+        sb.append( "\n" );
+
+        // Generation the Object Classes Node
+        sb.append( "dn: ou=objectClasses, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: objectClasses\n" );
+        sb.append( "\n" );
+
+        // Generating LDIF for Object Classes
+        for ( ObjectClassImpl oc : schema.getObjectClasses() )
+        {
+            ObjectClassHolder holder = new ObjectClassHolder( oc.getOid() );
+            holder.setClassType( oc.getType() );
+            holder.setDescription( oc.getDescription() );
+            List<String> mayList = new ArrayList<String>();
+            for ( String may : oc.getMayNamesList() )
+            {
+                mayList.add( may );
+            }
+            holder.setMay( mayList );
+            List<String> mustList = new ArrayList<String>();
+            for ( String must : oc.getMustNamesList() )
+            {
+                mustList.add( must );
+            }
+            holder.setMust( mustList );
+            List<String> names = new ArrayList<String>();
+            for ( String name : oc.getNames() )
+            {
+                names.add( name );
+            }
+            holder.setNames( names );
+            List<String> superiorList = new ArrayList<String>();
+            for ( String superior : oc.getSuperClassesNames() )
+            {
+                superiorList.add( superior );
+            }
+            holder.setSuperiors( superiorList );
+            holder.setObsolete( oc.isObsolete() );
+
+            sb.append( holder.toLdif( schema.getName() ) + "\n" );
+        }
+
+        // Generation the Syntax Checkers Node
+        sb.append( "dn: ou=syntaxCheckers, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: syntaxcheckers\n" );
+        sb.append( "\n" );
+
+        // Generation the Syntaxes Node
+        sb.append( "dn: ou=syntaxes, cn=" + schema.getName() + ", ou=schema\n" );
+        sb.append( "objectclass: organizationalUnit\n" );
+        sb.append( "objectclass: top\n" );
+        sb.append( "ou: syntaxes\n" );
+        sb.append( "\n" );
+    }
+
+
+    /**
+     * Gets the schema dependencies.
+     *
+     * @param schema
+     *      the schema
+     * @return
+     *      an array containing the names of all the schemas which the given
+     *      schema depends on
+     */
+    private String[] getSchemaDependencies( Schema schema )
+    {
+        Set<String> schemaNames = new HashSet<String>();
+        SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
+
+        // Looping on Attribute Types
+        for ( AttributeTypeImpl at : schema.getAttributeTypes() )
+        {
+            // Superior
+            String supName = at.getSuperiorName();
+            if ( supName != null )
+            {
+                AttributeTypeImpl sup = schemaHandler.getAttributeType( supName );
+                if ( sup != null )
+                {
+                    if ( !schema.getName().toLowerCase().equals( sup.getSchema().toLowerCase() ) )
+                    {
+                        schemaNames.add( sup.getSchema() );
+                    }
+                }
+            }
+        }
+
+        // Looping on Object Classes
+        for ( ObjectClassImpl oc : schema.getObjectClasses() )
+        {
+            // Superiors
+            String[] supNames = oc.getSuperClassesNames();
+            if ( supNames != null )
+            {
+                for ( String supName : oc.getSuperClassesNames() )
+                {
+                    ObjectClassImpl sup = schemaHandler.getObjectClass( supName );
+                    if ( sup != null )
+                    {
+                        if ( !schema.getName().toLowerCase().equals( sup.getSchema().toLowerCase() ) )
+                        {
+                            schemaNames.add( sup.getSchema() );
+                        }
+                    }
+                }
+            }
+
+            // Mays
+            String[] mayNames = oc.getMayNamesList();
+            if ( mayNames != null )
+            {
+                for ( String mayName : mayNames )
+                {
+                    AttributeTypeImpl may = schemaHandler.getAttributeType( mayName );
+                    if ( may != null )
+                    {
+                        if ( !schema.getName().toLowerCase().equals( may.getSchema().toLowerCase() ) )
+                        {
+                            schemaNames.add( may.getSchema() );
+                        }
+                    }
+                }
+
+            }
+
+            // Musts
+            String[] mustNames = oc.getMustNamesList();
+            if ( mustNames != null )
+            {
+                for ( String mustName : oc.getMustNamesList() )
+                {
+                    AttributeTypeImpl must = schemaHandler.getAttributeType( mustName );
+                    if ( must != null )
+                    {
+                        if ( !schema.getName().toLowerCase().equals( must.getSchema().toLowerCase() ) )
+                        {
+                            schemaNames.add( must.getSchema() );
+                        }
+                    }
+                }
+            }
+        }
+
+        return schemaNames.toArray( new String[0] );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+     */
+    public void init( IWorkbench workbench, IStructuredSelection selection )
+    {
+        setNeedsProgressMonitor( true );
+    }
+
+
+    /**
+     * Sets the selected projects.
+     *
+     * @param schemas
+     *      the schemas
+     */
+    public void setSelectedSchemas( Schema[] schemas )
+    {
+        selectedSchemas = schemas;
+    }
+}

Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizardPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizardPage.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizardPage.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizardPage.java Mon Nov  5 09:14:24 2007
@@ -0,0 +1,542 @@
+/*
+ *  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.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginConstants;
+import org.apache.directory.studio.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.schemaeditor.model.Schema;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.LabelProvider;
+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.graphics.Image;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class represents the WizardPage of the ExportSchemasForADSWizard.
+ * <p>
+ * It is used to let the user enter the informations about the
+ * schemas he wants to export and where to export.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportSchemasForADSWizardPage extends WizardPage
+{
+    /** The selected schemas */
+    private Schema[] selectedSchemas = new Schema[0];
+
+    /** The SchemaHandler */
+    private SchemaHandler schemaHandler;
+
+    public static final int EXPORT_MULTIPLE_FILES = 0;
+    public static final int EXPORT_SINGLE_FILE = 1;
+
+    // UI Fields
+    private CheckboxTableViewer schemasTableViewer;
+    private Button schemasTableSelectAllButton;
+    private Button schemasTableDeselectAllButton;
+    private Button exportMultipleFilesRadio;
+    private Label exportMultipleFilesLabel;
+    private Text exportMultipleFilesText;
+    private Button exportMultipleFilesButton;
+    private Button exportSingleFileRadio;
+    private Label exportSingleFileLabel;
+    private Text exportSingleFileText;
+    private Button exportSingleFileButton;
+
+
+    /**
+     * Creates a new instance of ExportSchemasAsXmlWizardPage.
+     */
+    protected ExportSchemasForADSWizardPage()
+    {
+        super( "ExportSchemasForADSWizardPage" );
+        setTitle( "Export schemas for Apache DS" );
+        setDescription( "Please select the schemas to export for Apache DS." );
+        setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+            PluginConstants.IMG_SCHEMAS_EXPORT_FOR_ADS_WIZARD ) );
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+     */
+    public void createControl( Composite parent )
+    {
+        Composite composite = new Composite( parent, SWT.NULL );
+        GridLayout layout = new GridLayout();
+        composite.setLayout( layout );
+
+        // Schemas Group
+        Group schemasGroup = new Group( composite, SWT.NONE );
+        schemasGroup.setText( "Schemas" );
+        schemasGroup.setLayout( new GridLayout( 2, false ) );
+        schemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Schemas TableViewer
+        Label schemasLabel = new Label( schemasGroup, SWT.NONE );
+        schemasLabel.setText( "Select the schemas to export:" );
+        schemasLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+        schemasTableViewer = new CheckboxTableViewer( new Table( schemasGroup, SWT.BORDER | SWT.CHECK
+            | SWT.FULL_SELECTION ) );
+        GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 );
+        schemasTableViewerGridData.heightHint = 125;
+        schemasTableViewer.getTable().setLayoutData( schemasTableViewerGridData );
+        schemasTableViewer.setContentProvider( new ArrayContentProvider() );
+        schemasTableViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return ( ( Schema ) element ).getName();
+                }
+
+                // Default
+                return super.getText( element );
+            }
+
+
+            public Image getImage( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_SCHEMA )
+                        .createImage();
+                }
+
+                // Default
+                return super.getImage( element );
+            }
+        } );
+        schemasTableViewer.addCheckStateListener( new ICheckStateListener()
+        {
+            /**
+             * Notifies of a change to the checked state of an element.
+             *
+             * @param event
+             *      event object describing the change
+             */
+            public void checkStateChanged( CheckStateChangedEvent event )
+            {
+                dialogChanged();
+            }
+        } );
+        schemasTableSelectAllButton = new Button( schemasGroup, SWT.PUSH );
+        schemasTableSelectAllButton.setText( "Select All" );
+        schemasTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemasTableSelectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemasTableViewer.setAllChecked( true );
+                dialogChanged();
+            }
+        } );
+        schemasTableDeselectAllButton = new Button( schemasGroup, SWT.PUSH );
+        schemasTableDeselectAllButton.setText( "Deselect All" );
+        schemasTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemasTableDeselectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemasTableViewer.setAllChecked( false );
+                dialogChanged();
+            }
+        } );
+
+        // Export Destination Group
+        Group exportDestinationGroup = new Group( composite, SWT.NULL );
+        exportDestinationGroup.setText( "Export Destination" );
+        exportDestinationGroup.setLayout( new GridLayout( 4, false ) );
+        exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Export Multiple Files
+        exportMultipleFilesRadio = new Button( exportDestinationGroup, SWT.RADIO );
+        exportMultipleFilesRadio.setText( "Export each schema as a separate file." );
+        exportMultipleFilesRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 4, 1 ) );
+        exportMultipleFilesRadio.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                exportMultipleFilesSelected();
+                dialogChanged();
+            }
+        } );
+        Label exportMultipleFilesFiller = new Label( exportDestinationGroup, SWT.NONE );
+        exportMultipleFilesFiller.setText( "    " );
+        exportMultipleFilesLabel = new Label( exportDestinationGroup, SWT.NONE );
+        exportMultipleFilesLabel.setText( "Directory:" );
+        exportMultipleFilesText = new Text( exportDestinationGroup, SWT.BORDER );
+        exportMultipleFilesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        exportMultipleFilesText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        exportMultipleFilesButton = new Button( exportDestinationGroup, SWT.PUSH );
+        exportMultipleFilesButton.setText( "Browse..." );
+        exportMultipleFilesButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseExportDirectory();
+                dialogChanged();
+            }
+        } );
+
+        // Export Single File
+        exportSingleFileRadio = new Button( exportDestinationGroup, SWT.RADIO );
+        exportSingleFileRadio.setText( "Export the schemas as a single file." );
+        exportSingleFileRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 4, 1 ) );
+        exportSingleFileRadio.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                exportSingleFileSelected();
+                dialogChanged();
+            }
+        } );
+        Label exportSingleFileFiller = new Label( exportDestinationGroup, SWT.NONE );
+        exportSingleFileFiller.setText( "    " );
+        exportSingleFileLabel = new Label( exportDestinationGroup, SWT.NONE );
+        exportSingleFileLabel.setText( "Export File:" );
+        exportSingleFileText = new Text( exportDestinationGroup, SWT.BORDER );
+        exportSingleFileText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        exportSingleFileText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        exportSingleFileButton = new Button( exportDestinationGroup, SWT.PUSH );
+        exportSingleFileButton.setText( "Browse..." );
+        exportSingleFileButton.addSelectionListener( new SelectionAdapter()
+        {
+            /* (non-Javadoc)
+             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+             */
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseExportFile();
+                dialogChanged();
+            }
+        } );
+
+        initFields();
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Initializes the UI Fields.
+     */
+    private void initFields()
+    {
+        // Filling the Schemas table
+        if ( schemaHandler != null )
+        {
+            List<Schema> schemas = new ArrayList<Schema>();
+            schemas.addAll( schemaHandler.getSchemas() );
+
+            Collections.sort( schemas, new Comparator<Schema>()
+            {
+                public int compare( Schema o1, Schema o2 )
+                {
+                    return o1.getName().compareToIgnoreCase( o2.getName() );
+                }
+            } );
+
+            schemasTableViewer.setInput( schemas );
+
+            // Setting the selected schemas
+            schemasTableViewer.setCheckedElements( selectedSchemas );
+        }
+
+        // Selecting the Multiple Files choice
+        exportMultipleFilesSelected();
+
+        displayErrorMessage( null );
+        setPageComplete( false );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles radio button is selected.
+     */
+    private void exportMultipleFilesSelected()
+    {
+        exportMultipleFilesRadio.setSelection( true );
+        exportMultipleFilesLabel.setEnabled( true );
+        exportMultipleFilesText.setEnabled( true );
+        exportMultipleFilesButton.setEnabled( true );
+
+        exportSingleFileRadio.setSelection( false );
+        exportSingleFileLabel.setEnabled( false );
+        exportSingleFileText.setEnabled( false );
+        exportSingleFileButton.setEnabled( false );
+    }
+
+
+    /**
+     * This method is called when the exportSingleFile radio button is selected.
+     */
+    private void exportSingleFileSelected()
+    {
+        exportMultipleFilesRadio.setSelection( false );
+        exportMultipleFilesLabel.setEnabled( false );
+        exportMultipleFilesText.setEnabled( false );
+        exportMultipleFilesButton.setEnabled( false );
+
+        exportSingleFileRadio.setSelection( true );
+        exportSingleFileLabel.setEnabled( true );
+        exportSingleFileText.setEnabled( true );
+        exportSingleFileButton.setEnabled( true );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles 'browse' button is selected.
+     */
+    private void chooseExportDirectory()
+    {
+        DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
+        dialog.setText( "Choose Folder" );
+        dialog.setMessage( "Select the folder in which export the files." );
+
+        String selectedDirectory = dialog.open();
+        if ( selectedDirectory != null )
+        {
+            exportMultipleFilesText.setText( selectedDirectory );
+        }
+    }
+
+
+    /**
+     * This method is called when the exportSingleFile 'browse' button is selected.
+     */
+    private void chooseExportFile()
+    {
+        FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE );
+        dialog.setText( "Select File" );
+        dialog.setFilterExtensions( new String[]
+            { "*.ldif", "*" } );
+        dialog.setFilterNames( new String[]
+            { "LDIF Files", "All Files" } );
+        dialog.setFilterPath( exportSingleFileText.getText() );
+
+        String selectedFile = dialog.open();
+        if ( selectedFile != null )
+        {
+            exportSingleFileText.setText( selectedFile );
+        }
+    }
+
+
+    /**
+     * This method is called when the user modifies something in the UI.
+     */
+    private void dialogChanged()
+    {
+        // Schemas table
+        if ( schemasTableViewer.getCheckedElements().length == 0 )
+        {
+            displayErrorMessage( "One or several schemas must be selected." );
+            return;
+        }
+
+        // Export option
+        if ( exportMultipleFilesRadio.getSelection() )
+        {
+            String directory = exportMultipleFilesText.getText();
+            if ( ( directory == null ) || ( directory.equals( "" ) ) )
+            {
+                displayErrorMessage( "A directory must be selected." );
+                return;
+            }
+            else
+            {
+                File directoryFile = new File( directory );
+                if ( !directoryFile.exists() )
+                {
+                    displayErrorMessage( "The selected directory does not exist." );
+                    return;
+                }
+                else if ( !directoryFile.isDirectory() )
+                {
+                    displayErrorMessage( "The selected directory is not a directory." );
+                    return;
+                }
+                else if ( !directoryFile.canWrite() )
+                {
+                    displayErrorMessage( "The selected directory is not writable." );
+                    return;
+                }
+            }
+        }
+        else if ( exportSingleFileRadio.getSelection() )
+        {
+            String exportFile = exportSingleFileText.getText();
+            if ( ( exportFile == null ) || ( exportFile.equals( "" ) ) )
+            {
+                displayErrorMessage( "A file must be selected." );
+                return;
+            }
+            else
+            {
+                File file = new File( exportFile );
+                if ( !file.getParentFile().canWrite() )
+                {
+                    displayErrorMessage( "The selected file is not writable." );
+                    return;
+                }
+            }
+        }
+
+        displayErrorMessage( null );
+    }
+
+
+    /**
+     * Displays an error message and set the page status as incomplete
+     * if the message is not null.
+     *
+     * @param message
+     *      the message to display
+     */
+    private void displayErrorMessage( String message )
+    {
+        setErrorMessage( message );
+        setPageComplete( message == null );
+    }
+
+
+    /**
+     * Gets the selected schemas.
+     *
+     * @return
+     *      the selected schemas
+     */
+    public Schema[] getSelectedSchemas()
+    {
+        Object[] selectedSchemas = schemasTableViewer.getCheckedElements();
+
+        List<Schema> schemas = new ArrayList<Schema>();
+        for ( Object schema : selectedSchemas )
+        {
+            schemas.add( ( Schema ) schema );
+        }
+
+        return schemas.toArray( new Schema[0] );
+    }
+
+
+    /**
+     * Sets the selected projects.
+     *
+     * @param schemas
+     *      the schemas
+     */
+    public void setSelectedSchemas( Schema[] schemas )
+    {
+        selectedSchemas = schemas;
+    }
+
+
+    /**
+     * Gets the type of export.
+     * <p>
+     * Values can either EXPORT_MULTIPLE_FILES or EXPORT_SINGLE_FILE.
+     * 
+     * @return
+     *      the type of export
+     */
+    public int getExportType()
+    {
+        if ( exportMultipleFilesRadio.getSelection() )
+        {
+            return EXPORT_MULTIPLE_FILES;
+        }
+        else if ( exportSingleFileRadio.getSelection() )
+        {
+            return EXPORT_SINGLE_FILE;
+        }
+
+        // Default 
+        return EXPORT_MULTIPLE_FILES;
+    }
+
+
+    /**
+     * Gets the export directory.
+     *
+     * @return
+     *      the export directory
+     */
+    public String getExportDirectory()
+    {
+        return exportMultipleFilesText.getText();
+    }
+
+
+    /**
+     * Gets the export file.
+     *
+     * @return
+     *      the export file
+     */
+    public String getExportFile()
+    {
+        return exportSingleFileText.getText();
+    }
+}

Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizardPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java Mon Nov  5 09:14:24 2007
@@ -0,0 +1,131 @@
+/*
+ *  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.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginUtils;
+import org.apache.directory.studio.schemaeditor.controller.ProjectsHandler;
+import org.apache.directory.studio.schemaeditor.model.Project;
+import org.apache.directory.studio.schemaeditor.model.io.ProjectsImportException;
+import org.apache.directory.studio.schemaeditor.model.io.ProjectsImporter;
+import org.apache.directory.studio.schemaeditor.view.ViewUtils;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+
+
+/**
+ * This class represents the wizard to import schema projects.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportProjectsWizard extends Wizard implements IImportWizard
+{
+    public static final String ID = Activator.PLUGIN_ID + ".wizards.ImportProjectsWizard";
+
+    // The pages of the wizard
+    private ImportProjectsWizardPage page;
+
+    /** The ProjectsHandler */
+    private ProjectsHandler projectsHandler;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages()
+    {
+        // Creating pages
+        page = new ImportProjectsWizardPage();
+
+        // Adding pages
+        addPage( page );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    public boolean performFinish()
+    {
+        final File[] selectedProjectFiles = page.getSelectedProjectFiles();
+
+        try
+        {
+            getContainer().run( true, false, new IRunnableWithProgress()
+            {
+                public void run( IProgressMonitor monitor )
+                {
+                    monitor.beginTask( "Importing projects: ", selectedProjectFiles.length );
+
+                    for ( File projectFile : selectedProjectFiles )
+                    {
+                        monitor.subTask( projectFile.getName() );
+                        try
+                        {
+                            Project project = ProjectsImporter.getProject( projectFile.getAbsolutePath() );
+                            projectsHandler.addProject( project );
+                        }
+                        catch ( ProjectsImportException e )
+                        {
+                            PluginUtils.logError( "An error occured when importing project " + projectFile.getName()
+                                + ".", e );
+                            ViewUtils.displayErrorMessageBox( "Import Error",
+                                "An error occured when importing project " + projectFile.getName() + "." );
+                        }
+                        monitor.worked( 1 );
+                    }
+
+                    monitor.done();
+                }
+            } );
+        }
+        catch ( InvocationTargetException e )
+        {
+            // Nothing to do (it will never occur)
+            e.printStackTrace();
+        }
+        catch ( InterruptedException e )
+        {
+            // Nothing to do.
+        }
+
+        return true;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+     */
+    public void init( IWorkbench workbench, IStructuredSelection selection )
+    {
+        setNeedsProgressMonitor( true );
+
+        projectsHandler = Activator.getDefault().getProjectsHandler();
+    }
+}

Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message