You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2007/07/12 16:02:39 UTC

svn commit: r555630 - in /directory/studio/trunk/studio-apacheds-schemaeditor: ./ src/main/java/org/apache/directory/studio/apacheds/schemaeditor/ src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ src/main/java/org/apache/dire...

Author: pamarcelot
Date: Thu Jul 12 07:02:37 2007
New Revision: 555630

URL: http://svn.apache.org/viewvc?view=rev&rev=555630
Log:
Added two new Import wizards:
	o ImportSchemasFromOpenLdapWizard
	o ImportSchemasFromXmlWizard
Updated SchemaChecker to check the whole schema inside an Eclipse Job.
Updated XMLSchemaFileImporter to import files with multiple schema definitions.
Fixed a bug in OpenLdapSchemaFileImporter which caused the schema to be empty with no AT and no OC.

Added:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizardPage.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java
Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/FakeLoader.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProblemsViewController.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/schemachecker/SchemaChecker.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml?view=diff&rev=555630&r1=555629&r2=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml Thu Jul 12 07:02:37 2007
@@ -115,4 +115,25 @@
           name="Export schemas as OpenLdap files">
     </wizard>
  </extension>
+ <extension
+       point="org.eclipse.ui.importWizards">
+    <category
+          id="org.apache.directory.studio.apacheds.schemaeditor.importWizardCategory"
+          name="Apache DS Schema Editor">
+    </category>
+    <wizard
+          category="org.apache.directory.studio.apacheds.schemaeditor.importWizardCategory"
+          class="org.apache.directory.studio.apacheds.schemaeditor.view.wizards.ImportSchemasFromXmlWizard"
+          icon="resources/icons/schemas_import.gif"
+          id="org.apache.directory.studio.apacheds.schemaeditor.wizards.ImportSchemasFromXmlWizard"
+          name="Import schemas from XML file(s)">
+    </wizard>
+    <wizard
+          category="org.apache.directory.studio.apacheds.schemaeditor.importWizardCategory"
+          class="org.apache.directory.studio.apacheds.schemaeditor.view.wizards.ImportSchemasFromOpenLdapWizard"
+          icon="resources/icons/schemas_import.gif"
+          id="org.apache.directory.studio.apacheds.schemaeditor.wizards.ImportSchemasFromOpenLdapWizard"
+          name="Import schemas from OpenLdap files">
+    </wizard>
+ </extension>
 </plugin>

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/FakeLoader.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/FakeLoader.java?view=diff&rev=555630&r1=555629&r2=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/FakeLoader.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/FakeLoader.java Thu Jul 12 07:02:37 2007
@@ -51,13 +51,5 @@
         oc1.setMustNamesList( new String[] { "at1" } );
         
         schemaHandler.addSchema( schema1 );
-        schemaHandler.addListener( new SchemaHandlerAdapter(){
-
-            public void schemaAdded( Schema schema )
-            {
-                System.out.println("schemaAdded");
-            }
-            
-        });
     }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java?view=diff&rev=555630&r1=555629&r2=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java Thu Jul 12 07:02:37 2007
@@ -48,6 +48,7 @@
     public static final String IMG_PROBLEMS_WARNING = "resources/icons/problems_warning.gif";
     public static final String IMG_SCHEMA = "resources/icons/schema.gif";
     public static final String IMG_SCHEMAS_EXPORT_WIZARD = "resources/icons/schemas_export_wizard.png";
+    public static final String IMG_SCHEMAS_IMPORT_WIZARD = "resources/icons/schemas_import_wizard.png";
     public static final String IMG_TOOLBAR_MENU = "resources/icons/toolbar_menu.gif";
 
     // Commands

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProblemsViewController.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProblemsViewController.java?view=diff&rev=555630&r1=555629&r2=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProblemsViewController.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProblemsViewController.java Thu Jul 12 07:02:37 2007
@@ -40,6 +40,7 @@
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
@@ -181,7 +182,13 @@
              */
             public void schemaCheckerUpdated()
             {
-                view.reloadViewer();
+                Display.getDefault().asyncExec( new Runnable()
+                {
+                    public void run()
+                    {
+                        view.reloadViewer();
+                    }
+                } );
             }
         } );
     }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OpenLdapSchemaFileImporter.java?view=diff&rev=555630&r1=555629&r2=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OpenLdapSchemaFileImporter.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OpenLdapSchemaFileImporter.java Thu Jul 12 07:02:37 2007
@@ -114,6 +114,7 @@
         {
             AttributeTypeImpl at = convertAttributeType( ( AttributeTypeLiteral ) ats.get( i ) );
             at.setSchema( schemaName );
+            schema.addAttributeType( at );
         }
 
         List<?> ocs = parser.getObjectClassTypes();
@@ -121,6 +122,7 @@
         {
             ObjectClassImpl oc = convertObjectClass( ( ObjectClassLiteral ) ocs.get( i ) );
             oc.setSchema( schemaName );
+            schema.addObjectClass( oc );
         }
 
         return schema;

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java?view=diff&rev=555630&r1=555629&r2=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java Thu Jul 12 07:02:37 2007
@@ -71,6 +71,7 @@
     private static final String OPTIONAL_TAG = "optional";
     private static final String ORDERING_TAG = "ordering";
     private static final String SCHEMA_TAG = "schema";
+    private static final String SCHEMAS_TAG = "schemas";
     private static final String SINGLE_VALUE_TAG = "singlevalue";
     private static final String SUBSTRING_TAG = "substring";
     private static final String SUPERIOR_TAG = "superior";
@@ -84,6 +85,49 @@
 
 
     /**
+     * Extracts the Schemas from the given path.
+     *
+     * @param path
+     *      the path of the file.
+     * @return
+     *      the corresponding schema
+     * @throws XMLSchemaFileImportException
+     *      if an error occurs when importing the schema
+     */
+    public static Schema[] getSchemas( String path ) throws XMLSchemaFileImportException
+    {
+        List<Schema> schemas = new ArrayList<Schema>();
+
+        SAXReader reader = new SAXReader();
+        Document document = null;
+        try
+        {
+            document = reader.read( path );
+        }
+        catch ( DocumentException e )
+        {
+            throw new XMLSchemaFileImportException( "The file '" + path + "' can not be read correctly." );
+        }
+
+        Element rootElement = document.getRootElement();
+        if ( !rootElement.getName().equals( SCHEMAS_TAG ) )
+        {
+            throw new XMLSchemaFileImportException( "The file '" + path + "' does not seem to be a valid Schema file." );
+        }
+        
+        for ( Iterator<?> i = rootElement.elementIterator( SCHEMA_TAG ); i.hasNext(); )
+        {
+            Element schemaElement = ( Element ) i.next();
+            Schema schema = new SchemaImpl( null );
+            readSchema( schemaElement, schema, path );
+            schemas.add( schema );
+        }
+        
+        return schemas.toArray( new Schema[0] );
+    }
+
+
+    /**
      * Extracts the Schema from the given path.
      *
      * @param path
@@ -109,30 +153,54 @@
             throw new XMLSchemaFileImportException( "The file '" + path + "' can not be read correctly." );
         }
 
+        Element rootElement = document.getRootElement();
+        if ( !rootElement.getName().equals( SCHEMA_TAG ) )
+        {
+            throw new XMLSchemaFileImportException( "The file '" + path + "' does not seem to be a valid Schema file." );
+        }
+
+        readSchema( document.getRootElement(), schema, path );
+
+        return schema;
+    }
+
+
+    /**
+     * Reads a schema.
+     *
+     * @param element
+     *      the element
+     * @param schema
+     *      the schema
+     * @param path
+     *      the path of the file
+     * @throws XMLSchemaFileImportException
+     *      if an error occurs when importing the schema
+     */
+    private static void readSchema( Element element, Schema schema, String path ) throws XMLSchemaFileImportException
+    {
         // Name
-        schema.setName( getSchemaName( document, path ) );
+        schema.setName( getSchemaName( element, path ) );
 
         // Attribute Types
-        readAttributeTypes( document, schema );
+        readAttributeTypes( element, schema );
 
         // Object Classes
-        readObjectClasses( document, schema );
+        readObjectClasses( element, schema );
 
         // Matching Rules
-        readMatchingRules( document, schema );
+        readMatchingRules( element, schema );
 
         // Syntaxes
-        readSyntaxes( document, schema );
-
-        return schema;
+        readSyntaxes( element, schema );
     }
 
 
     /**
      * Gets the name of the schema.
      *
-     * @param document
-     *      the Document
+     * @param element
+     *      the element
      * @param path
      *      the path
      * @return
@@ -140,15 +208,14 @@
      * @throws XMLSchemaFileImportException
      *      if an error occurs when reading the file
      */
-    private static String getSchemaName( Document document, String path ) throws XMLSchemaFileImportException
+    private static String getSchemaName( Element element, String path ) throws XMLSchemaFileImportException
     {
-        Element schemaElement = document.getRootElement();
-        if ( !schemaElement.getName().equals( SCHEMA_TAG ) )
+        if ( !element.getName().equals( SCHEMA_TAG ) )
         {
             throw new XMLSchemaFileImportException( "The file '" + path + "' does not seem to be a valid Schema file." );
         }
 
-        Attribute nameAttribute = schemaElement.attribute( NAME_TAG );
+        Attribute nameAttribute = element.attribute( NAME_TAG );
         if ( ( nameAttribute != null ) && ( !nameAttribute.getValue().equals( "" ) ) )
         {
             return nameAttribute.getValue();
@@ -185,15 +252,15 @@
     /**
      * Reads the attribute types.
      *
-     * @param document
-     *      the document
+     * @param element
+     *      the element
      * @param schema
      *      the schema
      * @throws XMLSchemaFileImportException 
      */
-    private static void readAttributeTypes( Document document, Schema schema ) throws XMLSchemaFileImportException
+    private static void readAttributeTypes( Element element, Schema schema ) throws XMLSchemaFileImportException
     {
-        for ( Iterator<?> i = document.getRootElement().elementIterator( ATTRIBUTE_TYPES_TAG ); i.hasNext(); )
+        for ( Iterator<?> i = element.elementIterator( ATTRIBUTE_TYPES_TAG ); i.hasNext(); )
         {
             Element attributesTypesElement = ( Element ) i.next();
             for ( Iterator<?> i2 = attributesTypesElement.elementIterator( ATTRIBUTE_TYPE_TAG ); i2.hasNext(); )
@@ -355,15 +422,15 @@
     /**
      * Reads the object classes
      *
-     * @param document
-     *      the document
+     * @param element
+     *      the element
      * @param schema
      *      the schema
      * @throws XMLSchemaFileImportException 
      */
-    private static void readObjectClasses( Document document, Schema schema ) throws XMLSchemaFileImportException
+    private static void readObjectClasses( Element element, Schema schema ) throws XMLSchemaFileImportException
     {
-        for ( Iterator<?> i = document.getRootElement().elementIterator( OBJECT_CLASSES_TAG ); i.hasNext(); )
+        for ( Iterator<?> i = element.elementIterator( OBJECT_CLASSES_TAG ); i.hasNext(); )
         {
             Element objectClassesElement = ( Element ) i.next();
             for ( Iterator<?> i2 = objectClassesElement.elementIterator( OBJECT_CLASS_TAG ); i2.hasNext(); )
@@ -502,15 +569,15 @@
     /**
      * Reads the matching rules.
      *
-     * @param document
-     *      the document
+     * @param element
+     *      the element
      * @param schema
      *      the schema
      * @throws XMLSchemaFileImportException 
      */
-    private static void readMatchingRules( Document document, Schema schema ) throws XMLSchemaFileImportException
+    private static void readMatchingRules( Element element, Schema schema ) throws XMLSchemaFileImportException
     {
-        for ( Iterator<?> i = document.getRootElement().elementIterator( MATCHING_RULES_TAG ); i.hasNext(); )
+        for ( Iterator<?> i = element.elementIterator( MATCHING_RULES_TAG ); i.hasNext(); )
         {
             Element matchingRulesElement = ( Element ) i.next();
             for ( Iterator<?> i2 = matchingRulesElement.elementIterator( MATCHING_RULE_TAG ); i2.hasNext(); )
@@ -593,15 +660,15 @@
     /**
      * Reads the syntaxes
      *
-     * @param document
-     *      the document
+     * @param element
+     *      the element
      * @param schema
      *      the schema
      * @throws XMLSchemaFileImportException
      */
-    private static void readSyntaxes( Document document, Schema schema ) throws XMLSchemaFileImportException
+    private static void readSyntaxes( Element element, Schema schema ) throws XMLSchemaFileImportException
     {
-        for ( Iterator<?> i = document.getRootElement().elementIterator( SYNTAXES_TAG ); i.hasNext(); )
+        for ( Iterator<?> i = element.elementIterator( SYNTAXES_TAG ); i.hasNext(); )
         {
             Element syntaxElement = ( Element ) i.next();
             for ( Iterator<?> i2 = syntaxElement.elementIterator( SYNTAX_TAG ); i2.hasNext(); )
@@ -704,6 +771,55 @@
         else
         {
             throw new XMLSchemaFileImportException( "The parser was not able to convert a boolean value." );
+        }
+    }
+
+    /**
+     * This enum represents the different types of schema files.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    public enum SchemaFileType
+    {
+        SINGLE, MULTIPLE
+    };
+
+
+    /**
+     * Gets the type of file.
+     *
+     * @param path
+     *      the path of the file
+     * @return
+     *      the type of the file
+     * @throws XMLSchemaFileImportException
+     */
+    public static SchemaFileType getSchemaFileType( String path ) throws XMLSchemaFileImportException
+    {
+        SAXReader reader = new SAXReader();
+        Document document = null;
+        try
+        {
+            document = reader.read( path );
+        }
+        catch ( DocumentException e )
+        {
+            throw new XMLSchemaFileImportException( "The file '" + path + "' can not be read correctly." );
+        }
+
+        Element rootElement = document.getRootElement();
+        if ( rootElement.getName().equals( SCHEMA_TAG ) )
+        {
+            return SchemaFileType.SINGLE;
+        }
+        else if ( rootElement.getName().equals( SCHEMAS_TAG ) )
+        {
+            return SchemaFileType.MULTIPLE;
+        }
+        else
+        {
+            throw new XMLSchemaFileImportException( "The file '" + path + "' does not seem to be a valid Schema file." );
         }
     }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/schemachecker/SchemaChecker.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/schemachecker/SchemaChecker.java?view=diff&rev=555630&r1=555629&r2=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/schemachecker/SchemaChecker.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/schemachecker/SchemaChecker.java Thu Jul 12 07:02:37 2007
@@ -35,6 +35,10 @@
 import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
 import org.apache.directory.studio.apacheds.schemaeditor.model.schemachecker.NonExistingMatchingRuleError.NonExistingMatchingRuleErrorEnum;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
 
 
 /**
@@ -213,21 +217,37 @@
      */
     private void checkWholeSchema()
     {
-        List<Schema> schemas = schemaHandler.getSchemas();
-        for ( Schema schema : schemas )
+        Job job = new Job( "Checking the Schema" )
         {
-            List<AttributeTypeImpl> ats = schema.getAttributeTypes();
-            for ( AttributeTypeImpl at : ats )
+            protected IStatus run( IProgressMonitor monitor )
             {
-                checkAttributeType( at );
-            }
-
-            List<ObjectClassImpl> ocs = schema.getObjectClasses();
-            for ( ObjectClassImpl oc : ocs )
-            {
-                checkObjectClass( oc );
-            }
-        }
+                List<Schema> schemas = schemaHandler.getSchemas();
+                monitor.beginTask( "Checking schemas: ", schemas.size() );
+                for ( Schema schema : schemas )
+                {
+                    monitor.subTask( schema.getName() );
+                    List<AttributeTypeImpl> ats = schema.getAttributeTypes();
+                    for ( AttributeTypeImpl at : ats )
+                    {
+                        checkAttributeType( at );
+                    }
+
+                    List<ObjectClassImpl> ocs = schema.getObjectClasses();
+                    for ( ObjectClassImpl oc : ocs )
+                    {
+                        checkObjectClass( oc );
+                    }
+                    monitor.worked( 1 );
+                }
+                monitor.done();
+
+                return Status.OK_STATUS;
+            }
+        };
+
+        job.setUser( true );
+        //        job.setPriority( Job.SHORT );
+        job.schedule();
     }
 
 

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java?view=auto&rev=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java Thu Jul 12 07:02:37 2007
@@ -0,0 +1,133 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.OpenLdapSchemaFileImportException;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.OpenLdapSchemaFileImporter;
+import org.apache.directory.studio.apacheds.schemaeditor.model.schemachecker.SchemaChecker;
+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 schemas from OpenLdap format.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportSchemasFromOpenLdapWizard extends Wizard implements IImportWizard
+{
+    /** The SchemaHandler */
+    private SchemaHandler schemaHandler;
+
+    /** The SchemaChecker */
+    private SchemaChecker schemaChecker;
+
+    // The pages of the wizard
+    private ImportSchemasFromOpenLdapWizardPage page;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages()
+    {
+        // Creating pages
+        page = new ImportSchemasFromOpenLdapWizardPage();
+
+        // Adding pages
+        addPage( page );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    public boolean performFinish()
+    {
+        final File[] selectedSchemasFiles = page.getSelectedSchemaFiles();
+        
+        schemaChecker.disableModificationsListening();
+        
+        try
+        {
+            getContainer().run( true, false, new IRunnableWithProgress()
+            {
+                public void run( IProgressMonitor monitor )
+                {
+                    schemaChecker.disableModificationsListening();
+                    monitor.beginTask( "Importing schemas: ", selectedSchemasFiles.length );
+
+                    for ( File schemaFile : selectedSchemasFiles )
+                    {
+                        monitor.subTask( schemaFile.getName() );
+                        try
+                        {
+                            Schema schema = OpenLdapSchemaFileImporter.getSchema( schemaFile.getAbsolutePath() );
+                            schemaHandler.addSchema( schema );
+                        }
+                        catch ( OpenLdapSchemaFileImportException e )
+                        {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
+                        }
+                        monitor.worked( 1 );
+                    }
+                    
+                    monitor.done();
+                }
+            } );
+        }
+        catch ( InvocationTargetException e )
+        {
+            // Nothing to do (it will never occur)
+        }
+        catch ( InterruptedException e )
+        {
+            // Nothing to do.
+        }
+
+        schemaChecker.enableModificationsListening();
+
+        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 );
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+        schemaChecker = Activator.getDefault().getSchemaChecker();
+    }
+}

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizardPage.java?view=auto&rev=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizardPage.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizardPage.java Thu Jul 12 07:02:37 2007
@@ -0,0 +1,335 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
+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 ImportSchemasFromOpenLdapWizard.
+ * <p>
+ * It is used to let the user enter the informations about the
+ * schemas he wants to import.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportSchemasFromOpenLdapWizardPage extends WizardPage
+{
+    // UI Fields
+    private Text fromDirectoryText;
+    private Button fromDirectoryButton;
+    private CheckboxTableViewer schemaFilesTableViewer;
+    private Button schemaFilesTableSelectAllButton;
+    private Button schemaFilesTableDeselectAllButton;
+
+
+    /**
+     * Creates a new instance of ImportSchemasFromOpenLdapWizardPage.
+     */
+    protected ImportSchemasFromOpenLdapWizardPage()
+    {
+        super( "ImportSchemasFromOpenLdapWizardPage" );
+        setTitle( "Import schemas from OpenLdap files" );
+        setDescription( "Please select the OpenLdap schema files to import." );
+        setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+            PluginConstants.IMG_SCHEMAS_IMPORT_WIZARD ) );
+    }
+
+
+    /* (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 );
+
+        // From Directory Group
+        Group fromDirectoryGroup = new Group( composite, SWT.NONE );
+        fromDirectoryGroup.setText( "From directory" );
+        fromDirectoryGroup.setLayout( new GridLayout( 3, false ) );
+        fromDirectoryGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // From Directory
+        Label fromDirectoryLabel = new Label( fromDirectoryGroup, SWT.NONE );
+        fromDirectoryLabel.setText( "From directory:" );
+        fromDirectoryText = new Text( fromDirectoryGroup, SWT.BORDER );
+        fromDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        fromDirectoryText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        fromDirectoryButton = new Button( fromDirectoryGroup, SWT.PUSH );
+        fromDirectoryButton.setText( "Browse..." );
+        fromDirectoryButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseFromDirectory();
+            }
+        } );
+
+        // Schema Files Group
+        Group schemaFilesGroup = new Group( composite, SWT.NONE );
+        schemaFilesGroup.setText( "Schema files" );
+        schemaFilesGroup.setLayout( new GridLayout( 2, false ) );
+        schemaFilesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Schema Files
+        schemaFilesTableViewer = new CheckboxTableViewer( new Table( schemaFilesGroup, SWT.BORDER | SWT.CHECK
+            | SWT.FULL_SELECTION ) );
+        GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 );
+        schemasTableViewerGridData.heightHint = 125;
+        schemaFilesTableViewer.getTable().setLayoutData( schemasTableViewerGridData );
+        schemaFilesTableViewer.setContentProvider( new ArrayContentProvider() );
+        schemaFilesTableViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                if ( element instanceof File )
+                {
+                    return ( ( File ) element ).getName();
+                }
+
+                // Default
+                return super.getText( element );
+            }
+
+
+            public Image getImage( Object element )
+            {
+                if ( element instanceof File )
+                {
+                    return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_SCHEMA )
+                        .createImage();
+                }
+
+                // Default
+                return super.getImage( element );
+            }
+        } );
+        schemaFilesTableViewer.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();
+            }
+        } );
+        schemaFilesTableSelectAllButton = new Button( schemaFilesGroup, SWT.PUSH );
+        schemaFilesTableSelectAllButton.setText( "Select All" );
+        schemaFilesTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemaFilesTableSelectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemaFilesTableViewer.setAllChecked( true );
+                dialogChanged();
+            }
+        } );
+        schemaFilesTableDeselectAllButton = new Button( schemaFilesGroup, SWT.PUSH );
+        schemaFilesTableDeselectAllButton.setText( "Deselect All" );
+        schemaFilesTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemaFilesTableDeselectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemaFilesTableViewer.setAllChecked( false );
+                dialogChanged();
+            }
+        } );
+
+        initFields();
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Initializes the UI Fields.
+     */
+    private void initFields()
+    {
+        displayErrorMessage( null );
+        setPageComplete( false );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles 'browse' button is selected.
+     */
+    private void chooseFromDirectory()
+    {
+        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 )
+        {
+            fromDirectoryText.setText( selectedDirectory );
+            fillInSchemaFilesTable( selectedDirectory );
+        }
+    }
+
+
+    /**
+     * Fills in the SchemaFilesTable with the schema files found in the given path.
+     *
+     * @param path
+     *      the path to search schema files in
+     */
+    private void fillInSchemaFilesTable( String path )
+    {
+        List<File> schemaFiles = new ArrayList<File>();
+        File selectedDirectory = new File( path );
+        if ( selectedDirectory.exists() )
+        {
+            for ( File file : selectedDirectory.listFiles() )
+            {
+                String fileName = file.getName();
+                if ( fileName.endsWith( ".schema" ) )
+                {
+                    schemaFiles.add( file );
+                }
+            }
+        }
+
+        schemaFilesTableViewer.setInput( schemaFiles );
+    }
+
+
+    /**
+     * This method is called when the user modifies something in the UI.
+     */
+    private void dialogChanged()
+    {
+        // Export Directory
+        String directory = fromDirectoryText.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.canRead() )
+            {
+                displayErrorMessage( "The selected directory is not readable." );
+                return;
+            }
+        }
+        
+        
+        // Schemas table
+        if ( schemaFilesTableViewer.getCheckedElements().length == 0 )
+        {
+            displayErrorMessage( "One or several schema files must be selected." );
+            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 schema files.
+     *
+     * @return
+     *      the selected schema files
+     */
+    public File[] getSelectedSchemaFiles()
+    {
+        Object[] selectedSchemaFile = schemaFilesTableViewer.getCheckedElements();
+
+        List<File> schemaFiles = new ArrayList<File>();
+        for ( Object schemaFile : selectedSchemaFile )
+        {
+            schemaFiles.add( ( File ) schemaFile );
+        }
+
+        return schemaFiles.toArray( new File[0] );
+    }
+
+}

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java?view=auto&rev=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java Thu Jul 12 07:02:37 2007
@@ -0,0 +1,147 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.XMLSchemaFileImportException;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.XMLSchemaFileImporter;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.XMLSchemaFileImporter.SchemaFileType;
+import org.apache.directory.studio.apacheds.schemaeditor.model.schemachecker.SchemaChecker;
+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 schemas from XML format.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportSchemasFromXmlWizard extends Wizard implements IImportWizard
+{
+    /** The SchemaHandler */
+    private SchemaHandler schemaHandler;
+
+    /** The SchemaChecker */
+    private SchemaChecker schemaChecker;
+
+    // The pages of the wizard
+    private ImportSchemasFromXmlWizardPage page;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages()
+    {
+        // Creating pages
+        page = new ImportSchemasFromXmlWizardPage();
+
+        // Adding pages
+        addPage( page );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    public boolean performFinish()
+    {
+        final String[] selectedSchemasFiles = page.getSelectedSchemaFiles();
+
+        schemaChecker.disableModificationsListening();
+
+        try
+        {
+            getContainer().run( true, false, new IRunnableWithProgress()
+            {
+                public void run( IProgressMonitor monitor )
+                {
+                    monitor.beginTask( "Importing schemas: ", selectedSchemasFiles.length );
+
+                    for ( String schemaFile : selectedSchemasFiles )
+                    {
+                        monitor.subTask( new File( schemaFile ).getName() );
+                        try
+                        {
+                            SchemaFileType schemaFileType = XMLSchemaFileImporter.getSchemaFileType( schemaFile );
+                            switch ( schemaFileType )
+                            {
+                                case SINGLE:
+                                    Schema importedSchema = XMLSchemaFileImporter.getSchema( schemaFile );
+                                    schemaHandler.addSchema( importedSchema );
+                                    break;
+                                case MULTIPLE:
+                                    Schema[] schemas = XMLSchemaFileImporter.getSchemas( schemaFile );
+                                    for ( Schema schema : schemas )
+                                    {
+                                        schemaHandler.addSchema( schema );
+                                    }
+                                    break;
+                            }
+                        }
+                        catch ( XMLSchemaFileImportException e )
+                        {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
+                        }
+                        monitor.worked( 1 );
+                    }
+
+                    monitor.done();
+                    schemaChecker.enableModificationsListening();
+                }
+            } );
+        }
+        catch ( InvocationTargetException e )
+        {
+            // Nothing to do (it will never occur)
+        }
+        catch ( InterruptedException e )
+        {
+            // Nothing to do.
+        }
+
+        schemaChecker.enableModificationsListening();
+
+        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 );
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+        schemaChecker = Activator.getDefault().getSchemaChecker();
+    }
+}

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java?view=auto&rev=555630
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java Thu Jul 12 07:02:37 2007
@@ -0,0 +1,335 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
+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 ImportSchemasFromOpenLdapWizard.
+ * <p>
+ * It is used to let the user enter the informations about the
+ * schemas he wants to import.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportSchemasFromXmlWizardPage extends WizardPage
+{
+    // UI Fields
+    private Text fromDirectoryText;
+    private Button fromDirectoryButton;
+    private CheckboxTableViewer schemaFilesTableViewer;
+    private Button schemaFilesTableSelectAllButton;
+    private Button schemaFilesTableDeselectAllButton;
+
+
+    /**
+     * Creates a new instance of ImportSchemasFromOpenLdapWizardPage.
+     */
+    protected ImportSchemasFromXmlWizardPage()
+    {
+        super( "ImportSchemasFromXmlWizardPage" );
+        setTitle( "Import schemas from XML file(s)" );
+        setDescription( "Please select the XML schema files to import." );
+        setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+            PluginConstants.IMG_SCHEMAS_IMPORT_WIZARD ) );
+    }
+
+
+    /* (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 );
+
+        // From Directory Group
+        Group fromDirectoryGroup = new Group( composite, SWT.NONE );
+        fromDirectoryGroup.setText( "From directory" );
+        fromDirectoryGroup.setLayout( new GridLayout( 3, false ) );
+        fromDirectoryGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // From Directory
+        Label fromDirectoryLabel = new Label( fromDirectoryGroup, SWT.NONE );
+        fromDirectoryLabel.setText( "From directory:" );
+        fromDirectoryText = new Text( fromDirectoryGroup, SWT.BORDER );
+        fromDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        fromDirectoryText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        fromDirectoryButton = new Button( fromDirectoryGroup, SWT.PUSH );
+        fromDirectoryButton.setText( "Browse..." );
+        fromDirectoryButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseFromDirectory();
+            }
+        } );
+
+        // Schema Files Group
+        Group schemaFilesGroup = new Group( composite, SWT.NONE );
+        schemaFilesGroup.setText( "Schema files" );
+        schemaFilesGroup.setLayout( new GridLayout( 2, false ) );
+        schemaFilesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Schema Files
+        schemaFilesTableViewer = new CheckboxTableViewer( new Table( schemaFilesGroup, SWT.BORDER | SWT.CHECK
+            | SWT.FULL_SELECTION ) );
+        GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 );
+        schemasTableViewerGridData.heightHint = 125;
+        schemaFilesTableViewer.getTable().setLayoutData( schemasTableViewerGridData );
+        schemaFilesTableViewer.setContentProvider( new ArrayContentProvider() );
+        schemaFilesTableViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                if ( element instanceof File )
+                {
+                    return ( ( File ) element ).getName();
+                }
+
+                // Default
+                return super.getText( element );
+            }
+
+
+            public Image getImage( Object element )
+            {
+                if ( element instanceof File )
+                {
+                    return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_SCHEMA )
+                        .createImage();
+                }
+
+                // Default
+                return super.getImage( element );
+            }
+        } );
+        schemaFilesTableViewer.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();
+            }
+        } );
+        schemaFilesTableSelectAllButton = new Button( schemaFilesGroup, SWT.PUSH );
+        schemaFilesTableSelectAllButton.setText( "Select All" );
+        schemaFilesTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemaFilesTableSelectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemaFilesTableViewer.setAllChecked( true );
+                dialogChanged();
+            }
+        } );
+        schemaFilesTableDeselectAllButton = new Button( schemaFilesGroup, SWT.PUSH );
+        schemaFilesTableDeselectAllButton.setText( "Deselect All" );
+        schemaFilesTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        schemaFilesTableDeselectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemaFilesTableViewer.setAllChecked( false );
+                dialogChanged();
+            }
+        } );
+
+        initFields();
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Initializes the UI Fields.
+     */
+    private void initFields()
+    {
+        displayErrorMessage( null );
+        setPageComplete( false );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles 'browse' button is selected.
+     */
+    private void chooseFromDirectory()
+    {
+        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 )
+        {
+            fromDirectoryText.setText( selectedDirectory );
+            fillInSchemaFilesTable( selectedDirectory );
+        }
+    }
+
+
+    /**
+     * Fills in the SchemaFilesTable with the schema files found in the given path.
+     *
+     * @param path
+     *      the path to search schema files in
+     */
+    private void fillInSchemaFilesTable( String path )
+    {
+        List<File> schemaFiles = new ArrayList<File>();
+        File selectedDirectory = new File( path );
+        if ( selectedDirectory.exists() )
+        {
+            for ( File file : selectedDirectory.listFiles() )
+            {
+                String fileName = file.getName();
+                if ( fileName.endsWith( ".xml" ) )
+                {
+                    schemaFiles.add( file );
+                }
+            }
+        }
+
+        schemaFilesTableViewer.setInput( schemaFiles );
+    }
+
+
+    /**
+     * This method is called when the user modifies something in the UI.
+     */
+    private void dialogChanged()
+    {
+        // Export Directory
+        String directory = fromDirectoryText.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.canRead() )
+            {
+                displayErrorMessage( "The selected directory is not readable." );
+                return;
+            }
+        }
+        
+        
+        // Schemas table
+        if ( schemaFilesTableViewer.getCheckedElements().length == 0 )
+        {
+            displayErrorMessage( "One or several schema files must be selected." );
+            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 schema files.
+     *
+     * @return
+     *      the selected schema files
+     */
+    public String[] getSelectedSchemaFiles()
+    {
+        Object[] selectedSchemaFile = schemaFilesTableViewer.getCheckedElements();
+
+        List<String> schemaFiles = new ArrayList<String>();
+        for ( Object schemaFile : selectedSchemaFile )
+        {
+            schemaFiles.add( (( File ) schemaFile).getAbsolutePath() );
+        }
+
+        return schemaFiles.toArray( new String[0] );
+    }
+
+}