directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r798544 - in /directory/studio/trunk/schemaeditor: ./ src/main/java/org/apache/directory/studio/schemaeditor/model/io/ src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/ src/main/java/org/apache/directory/studio/schema...
Date Tue, 28 Jul 2009 14:46:13 GMT
Author: seelmann
Date: Tue Jul 28 14:46:13 2009
New Revision: 798544

URL: http://svn.apache.org/viewvc?rev=798544&view=rev
Log:
DIRSTUDIO-509 (Load schema from the directory server)
o Activated code to load schema from directory server
o Added generic schema connector


Added:
    directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java
Modified:
    directory/studio/trunk/schemaeditor/plugin.xml
    directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/PluginPreferencePage.java
    directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java
    directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardInformationPage.java
    directory/studio/trunk/schemaeditor/src/main/resources/org.apache.directory.studio.schemaeditor.schemaConnectors.exsd

Modified: directory/studio/trunk/schemaeditor/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/plugin.xml?rev=798544&r1=798543&r2=798544&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/plugin.xml (original)
+++ directory/studio/trunk/schemaeditor/plugin.xml Tue Jul 28 14:46:13 2009
@@ -19,6 +19,7 @@
   under the License.
 -->
 <plugin>
+   <extension-point id="org.apache.directory.studio.schemaeditor.schemaConnectors" name="Schema Connectors" schema="src/main/resources/org.apache.directory.studio.schemaeditor.schemaConnectors.exsd"/>
    	<extension
          point="org.eclipse.ui.perspectives">
       <perspective
@@ -425,5 +426,20 @@
           schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
           sequence="DEL">
     </key>
+ </extension>
+ <extension
+       point="org.apache.directory.studio.schemaeditor.schemaConnectors">
+    <schemaConnector
+          class="org.apache.directory.studio.schemaeditor.model.io.ApacheDsSchemaConnector"
+          description="ApacheDS Schema Connector"
+          id="org.apache.directory.studio.schemaeditor.model.io.ApacheDsSchemaConnector"
+          name="ApacheDS Schema Connector">
+    </schemaConnector>
+    <schemaConnector
+          class="org.apache.directory.studio.schemaeditor.model.io.GenericSchemaConnector"
+          description="Generic Schema Connector"
+          id="org.apache.directory.studio.schemaeditor.model.io.GenericSchemaConnector"
+          name="Generic Schema Connector">
+    </schemaConnector>
  </extension>     
 </plugin>

Added: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java?rev=798544&view=auto
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java (added)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java Tue Jul 28 14:46:13 2009
@@ -0,0 +1,357 @@
+/*
+ *  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.model.io;
+
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.shared.ldap.schema.parsers.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.parsers.AttributeTypeDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.parsers.LdapSyntaxDescription;
+import org.apache.directory.shared.ldap.schema.parsers.LdapSyntaxDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.parsers.MatchingRuleDescription;
+import org.apache.directory.shared.ldap.schema.parsers.MatchingRuleDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.parsers.ObjectClassDescription;
+import org.apache.directory.shared.ldap.schema.parsers.ObjectClassDescriptionSchemaParser;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
+import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
+import org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper;
+import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
+import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.schemaeditor.model.MatchingRuleImpl;
+import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.schemaeditor.model.Schema;
+import org.apache.directory.studio.schemaeditor.model.SchemaImpl;
+import org.apache.directory.studio.schemaeditor.model.SyntaxImpl;
+
+
+/**
+ * A Generic Schema Connector, suitable for all LDAP servers.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class GenericSchemaConnector extends AbstractSchemaConnector implements SchemaConnector
+{
+
+    private static final AliasDereferencingMethod DEREF_ALIAS_METHOD = AliasDereferencingMethod.ALWAYS;
+    private static final ReferralHandlingMethod HANDLE_REFERALS_METHOD = ReferralHandlingMethod.FOLLOW;
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.studio.schemaeditor.model.io.SchemaConnector#exportSchema(org.apache.directory.studio.connection.core.Connection, org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    public void exportSchema( Connection connection, StudioProgressMonitor monitor )
+    {
+        // TODO Auto-generated method stub
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.studio.schemaeditor.model.io.SchemaConnector#importSchema(org.apache.directory.studio.connection.core.Connection, org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    public List<Schema> importSchema( Connection connection, StudioProgressMonitor monitor )
+    {
+        List<Schema> schemas = new ArrayList<Schema>();
+
+        JNDIConnectionWrapper wrapper = connection.getJNDIConnectionWrapper();
+
+        monitor.beginTask( "Fetching Schema: ", 1 );
+
+        SearchControls constraintSearch = new SearchControls();
+        constraintSearch.setSearchScope( SearchControls.OBJECT_SCOPE );
+        constraintSearch.setReturningAttributes( new String[]
+            { "attributeTypes", "objectClasses", "ldapSyntaxes", "matchingRules" } );
+        String schemaDn = getSubschemaSubentry( connection, monitor );
+        NamingEnumeration<SearchResult> answer = wrapper.search( schemaDn, "(objectclass=subschema)", constraintSearch,
+            DEREF_ALIAS_METHOD, HANDLE_REFERALS_METHOD, null, ( StudioProgressMonitor ) monitor, null );
+        if ( answer != null )
+        {
+            while ( answer.hasMoreElements() )
+            {
+                SearchResult searchResult = ( SearchResult ) answer.nextElement();
+                try
+                {
+                    schemas.add( getSchema( wrapper, searchResult, monitor ) );
+                }
+                catch ( Exception e )
+                {
+                    monitor.reportError( e );
+                }
+            }
+        }
+
+        monitor.worked( 1 );
+
+        return schemas;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.studio.schemaeditor.model.io.AbstractSchemaConnector#isSuitableConnector(org.apache.directory.studio.connection.core.Connection, org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    public boolean isSuitableConnector( Connection connection, StudioProgressMonitor monitor )
+    {
+        return getSubschemaSubentry( connection, monitor ) != null;
+    }
+
+
+    private static String getSubschemaSubentry( Connection connection, StudioProgressMonitor monitor )
+    {
+        JNDIConnectionWrapper wrapper = connection.getJNDIConnectionWrapper();
+
+        SearchControls constraintSearch = new SearchControls();
+        constraintSearch.setSearchScope( SearchControls.OBJECT_SCOPE );
+        constraintSearch.setReturningAttributes( new String[]
+            { "subschemaSubentry" } );
+
+        NamingEnumeration<SearchResult> answer = wrapper.search( "", "(objectclass=*)", constraintSearch,
+            DEREF_ALIAS_METHOD, HANDLE_REFERALS_METHOD, null, monitor, null );
+
+        if ( answer != null )
+        {
+            if ( answer.hasMoreElements() )
+            {
+                SearchResult searchResult = ( SearchResult ) answer.nextElement();
+
+                Attribute subschemaSubentryAttribute = searchResult.getAttributes().get( "subschemaSubentry" );
+                if ( subschemaSubentryAttribute == null )
+                {
+                    return null;
+                }
+
+                if ( subschemaSubentryAttribute.size() != 1 )
+                {
+                    return null;
+                }
+
+                String subschemaSubentry = null;
+                try
+                {
+                    subschemaSubentry = ( String ) subschemaSubentryAttribute.get();
+                }
+                catch ( NamingException e )
+                {
+                    return null;
+                }
+
+                return subschemaSubentry;
+            }
+        }
+
+        return null;
+    }
+
+
+    private static Schema getSchema( JNDIConnectionWrapper wrapper, SearchResult searchResult,
+        StudioProgressMonitor monitor ) throws NamingException, ParseException
+    {
+        monitor.subTask( "Reading schema" );
+
+        // Creating the schema
+        Schema schema = new SchemaImpl( "schema" );
+
+        Attribute attributeTypesAttribute = searchResult.getAttributes().get( "attributeTypes" );
+        if ( attributeTypesAttribute != null )
+        {
+            NamingEnumeration<?> ne = attributeTypesAttribute.getAll();
+            if ( ne != null )
+            {
+                while ( ne.hasMoreElements() )
+                {
+                    String value = ( String ) ne.nextElement();
+                    AttributeTypeDescriptionSchemaParser parser = new AttributeTypeDescriptionSchemaParser();
+                    parser.setQuirksMode( true );
+                    AttributeTypeDescription atd = parser.parseAttributeTypeDescription( value );
+
+                    AttributeTypeImpl impl = new AttributeTypeImpl( atd.getNumericOid() );
+                    impl.setOid( atd.getNumericOid() );
+                    impl.setNames( atd.getNames().toArray( new String[0] ) );
+                    impl.setDescription( atd.getDescription() );
+                    impl.setSuperiorName( atd.getSuperType() );
+                    impl.setUsage( atd.getUsage() );
+                    impl.setSyntaxOid( atd.getSyntax() );
+                    impl.setLength( atd.getSyntaxLength() );
+                    impl.setObsolete( atd.isObsolete() );
+                    impl.setCollective( atd.isCollective() );
+                    impl.setSingleValue( atd.isSingleValued() );
+                    impl.setCanUserModify( atd.isUserModifiable() );
+                    impl.setEqualityName( atd.getEqualityMatchingRule() );
+                    impl.setOrderingName( atd.getOrderingMatchingRule() );
+                    impl.setSubstrName( atd.getSubstringsMatchingRule() );
+                    impl.setSchema( schema.getName() );
+
+                    schema.addAttributeType( impl );
+                }
+            }
+        }
+
+        Attribute objectClassesAttribute = searchResult.getAttributes().get( "objectClasses" );
+        if ( objectClassesAttribute != null )
+        {
+            NamingEnumeration<?> ne = objectClassesAttribute.getAll();
+            if ( ne != null )
+            {
+                while ( ne.hasMoreElements() )
+                {
+                    String value = ( String ) ne.nextElement();
+                    ObjectClassDescriptionSchemaParser parser = new ObjectClassDescriptionSchemaParser();
+                    parser.setQuirksMode( true );
+                    ObjectClassDescription ocd = parser.parseObjectClassDescription( value );
+
+                    ObjectClassImpl impl = new ObjectClassImpl( ocd.getNumericOid() );
+                    impl.setOid( ocd.getNumericOid() );
+                    impl.setNames( ocd.getNames().toArray( new String[0] ) );
+                    impl.setDescription( ocd.getDescription() );
+                    impl.setSuperClassesNames( ocd.getSuperiorObjectClasses().toArray( new String[0] ) );
+                    impl.setType( ocd.getKind() );
+                    impl.setObsolete( ocd.isObsolete() );
+                    impl.setMustNamesList( ocd.getMustAttributeTypes().toArray( new String[0] ) );
+                    impl.setMayNamesList( ocd.getMayAttributeTypes().toArray( new String[0] ) );
+                    impl.setSchema( schema.getName() );
+
+                    schema.addObjectClass( impl );
+                }
+            }
+        }
+
+        Attribute ldapSyntaxesAttribute = searchResult.getAttributes().get( "ldapSyntaxes" );
+        if ( ldapSyntaxesAttribute != null )
+        {
+            NamingEnumeration<?> ne = ldapSyntaxesAttribute.getAll();
+            if ( ne != null )
+            {
+                while ( ne.hasMoreElements() )
+                {
+                    String value = ( String ) ne.nextElement();
+                    LdapSyntaxDescriptionSchemaParser parser = new LdapSyntaxDescriptionSchemaParser();
+                    parser.setQuirksMode( true );
+                    LdapSyntaxDescription lsd = parser.parseLdapSyntaxDescription( value );
+
+                    SyntaxImpl impl = new SyntaxImpl( lsd.getNumericOid() );
+                    impl.setDescription( lsd.getDescription() );
+                    impl.setNames( new String[]
+                        { lsd.getDescription() } );
+                    //impl.setObsolete( lsd.isObsolete() );
+                    impl.setHumanReadable( true );
+                    impl.setSchema( schema.getName() );
+
+                    schema.addSyntax( impl );
+                }
+            }
+        }
+        // TODO: if online -> all received syntaxes in attributes are valid -> create dummy syntaxes if missing
+        try
+        {
+            for ( AttributeTypeImpl at : schema.getAttributeTypes() )
+            {
+                String syntaxOid = at.getSyntaxOid();
+
+                if ( syntaxOid != null && schema.getSyntax( syntaxOid ) == null )
+                {
+                    SyntaxImpl impl = new SyntaxImpl( syntaxOid );
+                    impl.setSchema( schema.getName() );
+                    // TODO: lookup description/name
+                    impl.setDescription( "Dummy" );
+                    impl.setNames( new String[]
+                        { "Dummy" } );
+                    schema.addSyntax( impl );
+                }
+            }
+        }
+        catch ( Exception e1 )
+        {
+            // TODO Auto-generated catch block
+            e1.printStackTrace();
+        }
+
+        Attribute matchingRulesAttribute = searchResult.getAttributes().get( "matchingRules" );
+        if ( matchingRulesAttribute != null )
+        {
+            NamingEnumeration<?> ne = matchingRulesAttribute.getAll();
+            if ( ne != null )
+            {
+                while ( ne.hasMoreElements() )
+                {
+                    String value = ( String ) ne.nextElement();
+                    MatchingRuleDescriptionSchemaParser parser = new MatchingRuleDescriptionSchemaParser();
+                    parser.setQuirksMode( true );
+                    MatchingRuleDescription mrd = parser.parseMatchingRuleDescription( value );
+
+                    MatchingRuleImpl impl = new MatchingRuleImpl( mrd.getNumericOid() );
+                    impl.setDescription( mrd.getDescription() );
+                    impl.setNames( mrd.getNames().toArray( new String[0] ) );
+                    impl.setObsolete( mrd.isObsolete() );
+                    impl.setSyntaxOid( mrd.getSyntax() );
+                    impl.setSchema( schema.getName() );
+
+                    schema.addMatchingRule( impl );
+                }
+            }
+        }
+        // TODO: if online -> all received matching rules in attributes are valid -> create dummy matching rules if missing
+        try
+        {
+            for ( AttributeTypeImpl at : schema.getAttributeTypes() )
+            {
+                String equalityName = at.getEqualityName();
+                String orderingName = at.getOrderingName();
+                String substrName = at.getSubstrName();
+                checkMatchingRules( schema, equalityName, orderingName, substrName );
+            }
+        }
+        catch ( Exception e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        return schema;
+    }
+
+
+    private static void checkMatchingRules( Schema schema, String... matchingRuleNames )
+    {
+        for ( String matchingRuleName : matchingRuleNames )
+        {
+            if ( matchingRuleName != null && schema.getMatchingRule( matchingRuleName ) == null )
+            {
+                MatchingRuleImpl impl = new MatchingRuleImpl( matchingRuleName );
+                impl.setSchema( schema.getName() );
+                // TODO: lookup description/name
+                impl.setDescription( "Dummy" );
+                impl.setNames( new String[]
+                    { matchingRuleName } );
+                schema.addMatchingRule( impl );
+            }
+
+        }
+
+    }
+}

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/PluginPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/PluginPreferencePage.java?rev=798544&r1=798543&r2=798544&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/PluginPreferencePage.java (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/PluginPreferencePage.java Tue Jul 28 14:46:13 2009
@@ -76,89 +76,89 @@
         composite.setLayout( new GridLayout() );
         composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
 
-        //        // SchemaConnectors Group
-        //        Group schemaConnectorsGroup = new Group( composite, SWT.NONE );
-        //        schemaConnectorsGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
-        //        schemaConnectorsGroup.setLayout( new GridLayout( 2, true ) );
-        //        schemaConnectorsGroup.setText( "Schema Connectors" );
-        //
-        //        // Available Schema Connectors Label
-        //        Label availableSchemaConnectorsLabel = new Label( schemaConnectorsGroup, SWT.NONE );
-        //        availableSchemaConnectorsLabel.setText( "Available Connectors:" );
-        //
-        //        // Description Label
-        //        Label descriptionLabel = new Label( schemaConnectorsGroup, SWT.NONE );
-        //        descriptionLabel.setText( "Description:" );
-        //        // SchemaConnectors TableViewer
-        //        final TableViewer schemaConnectorsTableViewer = new TableViewer( schemaConnectorsGroup, SWT.BORDER | SWT.SINGLE
-        //            | SWT.FULL_SELECTION );
-        //        GridData gridData = new GridData( SWT.FILL, SWT.NONE, true, false );
-        //        gridData.heightHint = 125;
-        //        schemaConnectorsTableViewer.getTable().setLayoutData( gridData );
-        //        schemaConnectorsTableViewer.setContentProvider( new ArrayContentProvider() );
-        //        schemaConnectorsTableViewer.setLabelProvider( new LabelProvider()
-        //        {
-        //            public String getText( Object element )
-        //            {
-        //                return ( ( SchemaConnector ) element ).getName();
-        //            }
-        //
-        //
-        //            public Image getImage( Object element )
-        //            {
-        //                return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA_CONNECTOR );
-        //            }
-        //        } );
-        //
-        //        schemaConnectorsTableViewer.setComparator( new ViewerComparator( new Comparator<String>()
-        //        {
-        //            public int compare( String o1, String o2 )
-        //            {
-        //                if ( ( o1 != null ) && ( o2 != null ) )
-        //                {
-        //                    return o1.compareToIgnoreCase( o2 );
-        //                }
-        //
-        //                // Default
-        //                return 0;
-        //            }
-        //        } ) );
-        //
-        //        //      schemaConnectorsTableViewer.setComparator( new ViewerComparator( new Comparator<SchemaConnector>()
-        //        //      {
-        //        //          public int compare( SchemaConnector o1, SchemaConnector o2 )
-        //        //          {
-        //        //              String name1 = o1.getName();
-        //        //              String name2 = o2.getName();
-        //        //
-        //        //              if ( ( name1 != null ) && ( name2 != null ) )
-        //        //              {
-        //        //                  return name1.compareToIgnoreCase( name2 );
-        //        //              }
-        //        //
-        //        //              // Default
-        //        //              return 0;
-        //        //          }
-        //        //      } ) );
-        //        schemaConnectorsTableViewer.setInput( PluginUtils.getSchemaConnectors() );
-        //
-        //        // Description Text
-        //        final Text descriptionText = new Text( schemaConnectorsGroup, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY );
-        //        descriptionText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
-        //
-        //        schemaConnectorsTableViewer.addSelectionChangedListener( new ISelectionChangedListener()
-        //        {
-        //            public void selectionChanged( SelectionChangedEvent event )
-        //            {
-        //                SchemaConnector schemaConnector = ( SchemaConnector ) ( ( StructuredSelection ) schemaConnectorsTableViewer
-        //                    .getSelection() ).getFirstElement();
-        //
-        //                if ( schemaConnector != null )
-        //                {
-        //                    descriptionText.setText( schemaConnector.getDescription() );
-        //                }
-        //            }
-        //        } );
+        // SchemaConnectors Group
+        Group schemaConnectorsGroup = new Group( composite, SWT.NONE );
+        schemaConnectorsGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        schemaConnectorsGroup.setLayout( new GridLayout( 2, true ) );
+        schemaConnectorsGroup.setText( "Schema Connectors" );
+
+        // Available Schema Connectors Label
+        Label availableSchemaConnectorsLabel = new Label( schemaConnectorsGroup, SWT.NONE );
+        availableSchemaConnectorsLabel.setText( "Available Connectors:" );
+
+        // Description Label
+        Label descriptionLabel = new Label( schemaConnectorsGroup, SWT.NONE );
+        descriptionLabel.setText( "Description:" );
+        // SchemaConnectors TableViewer
+        final TableViewer schemaConnectorsTableViewer = new TableViewer( schemaConnectorsGroup, SWT.BORDER | SWT.SINGLE
+            | SWT.FULL_SELECTION );
+        GridData gridData = new GridData( SWT.FILL, SWT.NONE, true, false );
+        gridData.heightHint = 125;
+        schemaConnectorsTableViewer.getTable().setLayoutData( gridData );
+        schemaConnectorsTableViewer.setContentProvider( new ArrayContentProvider() );
+        schemaConnectorsTableViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                return ( ( SchemaConnector ) element ).getName();
+            }
+
+
+            public Image getImage( Object element )
+            {
+                return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA_CONNECTOR );
+            }
+        } );
+
+        schemaConnectorsTableViewer.setComparator( new ViewerComparator( new Comparator<String>()
+            {
+            public int compare( String o1, String o2 )
+            {
+                if ( ( o1 != null ) && ( o2 != null ) )
+                {
+                    return o1.compareToIgnoreCase( o2 );
+                }
+
+                // Default
+                return 0;
+            }
+            } ) );
+
+        //      schemaConnectorsTableViewer.setComparator( new ViewerComparator( new Comparator<SchemaConnector>()
+        //      {
+        //          public int compare( SchemaConnector o1, SchemaConnector o2 )
+        //          {
+        //              String name1 = o1.getName();
+        //              String name2 = o2.getName();
+        //
+        //              if ( ( name1 != null ) && ( name2 != null ) )
+        //              {
+        //                  return name1.compareToIgnoreCase( name2 );
+        //              }
+        //
+        //              // Default
+        //              return 0;
+        //          }
+        //      } ) );
+        schemaConnectorsTableViewer.setInput( PluginUtils.getSchemaConnectors() );
+
+        // Description Text
+        final Text descriptionText = new Text( schemaConnectorsGroup, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY );
+        descriptionText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+
+        schemaConnectorsTableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                SchemaConnector schemaConnector = ( SchemaConnector ) ( ( StructuredSelection ) schemaConnectorsTableViewer
+                    .getSelection() ).getFirstElement();
+
+                if ( schemaConnector != null )
+                {
+                    descriptionText.setText( schemaConnector.getDescription() );
+                }
+            }
+        } );
 
         return parent;
     }

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java?rev=798544&r1=798543&r2=798544&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java Tue Jul 28 14:46:13 2009
@@ -20,6 +20,12 @@
 package org.apache.directory.studio.schemaeditor.view.wizards;
 
 
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.schemaeditor.Activator;
 import org.apache.directory.studio.schemaeditor.PluginConstants;
 import org.apache.directory.studio.schemaeditor.PluginUtils;
@@ -28,7 +34,12 @@
 import org.apache.directory.studio.schemaeditor.model.Project;
 import org.apache.directory.studio.schemaeditor.model.ProjectType;
 import org.apache.directory.studio.schemaeditor.model.Schema;
+import org.apache.directory.studio.schemaeditor.model.io.GenericSchemaConnector;
+import org.apache.directory.studio.schemaeditor.model.io.SchemaConnector;
+import org.apache.directory.studio.schemaeditor.view.ViewUtils;
 import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget.ServerTypeEnum;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.Wizard;
@@ -48,11 +59,11 @@
 
     // The pages of the wizard
     private NewProjectWizardInformationPage informationPage;
-    //    private NewProjectWizardConnectionSelectionPage connectionSelectionPage;
+    private NewProjectWizardConnectionSelectionPage connectionSelectionPage;
     private NewProjectWizardSchemasSelectionPage schemasSelectionPage;
 
 
-    //    private Throwable exceptionThrown = null;
+    private Throwable exceptionThrown = null;
 
     /* (non-Javadoc)
      * @see org.eclipse.jface.wizard.Wizard#addPages()
@@ -61,12 +72,12 @@
     {
         // Creating pages
         informationPage = new NewProjectWizardInformationPage();
-        //        connectionSelectionPage = new NewProjectWizardConnectionSelectionPage();
+        connectionSelectionPage = new NewProjectWizardConnectionSelectionPage();
         schemasSelectionPage = new NewProjectWizardSchemasSelectionPage();
 
         // Adding pages
         addPage( informationPage );
-        //        addPage( connectionSelectionPage );
+        addPage( connectionSelectionPage );
         addPage( schemasSelectionPage );
     }
 
@@ -82,108 +93,121 @@
         // Creating the project
         final Project project = new Project( projectType, projectName );
 
-        //        if ( projectType.equals( ProjectType.ONLINE ) )
-        //        // Project is an "Online Project"
-        //        {
-        //            // Setting the connection to use
-        //            project.setConnection( connectionSelectionPage.getSelectedConnection() );
-        //
-        //            // Reseting the Exception Thrown
-        //            exceptionThrown = null;
-        //
-        //            try
-        //            {
-        //                getContainer().run( false, false, new IRunnableWithProgress()
-        //                {
-        //                    public void run( IProgressMonitor monitor )
-        //                    {
-        //                        StudioProgressMonitor studioProgressMonitor = new StudioProgressMonitor( monitor );
-        //
-        //                        // Getting the correct SchemaConnector for this connection
-        //                        List<SchemaConnector> correctSchemaConnectors = getCorrectSchemaConnectors( project
-        //                            .getConnection(), studioProgressMonitor );
-        //
-        //                        // If no suitable SchemaConnector has been found, we display an
-        //                        // error message and return false;
-        //                        if ( correctSchemaConnectors.size() == 0 )
-        //                        {
-        //                            studioProgressMonitor.reportError(
-        //                                "No suitable SchemaConnector has been found for the choosen Directory Server.",
-        //                                new NoSuitableSchemaConnectorException() );
-        //                        }
-        //
-        //                        // Getting the correct SchemaConnector
-        //                        SchemaConnector correctSchemaConnector = null;
-        //                        if ( correctSchemaConnectors.size() == 1 )
-        //                        {
-        //                            correctSchemaConnector = correctSchemaConnectors.get( 0 );
-        //                        }
-        //                        else
-        //                        {
-        //                            // TODO display a dialog in which the user can select the correct schema connector
-        //                        }
-        //
-        //                        project.setSchemaConnector( correctSchemaConnector );
-        //
-        //                        // Fetching the Online Schema
-        //                        project.fetchOnlineSchema( new StudioProgressMonitor( monitor ) );
-        //
-        //                        // Checking if an error has occured
-        //                        if ( studioProgressMonitor.errorsReported() )
-        //                        {
-        //                            exceptionThrown = studioProgressMonitor.getException();
-        //                            return;
-        //                        }
-        //                    }
-        //                } );
-        //            }
-        //            catch ( InvocationTargetException e )
-        //            {
-        //                // Nothing to do (it will never occur)
-        //            }
-        //            catch ( InterruptedException e )
-        //            {
-        //                // Nothing to do.
-        //            }
-        //
-        //            if ( exceptionThrown != null )
-        //            {
-        //                if ( exceptionThrown instanceof NoSuitableSchemaConnectorException )
-        //                // Special case for the 'NoSuitableSchemaConnectorException'
-        //                {
-        //                    PluginUtils.logError( "No suitable SchemaConnector has been found for the selected connection.",
-        //                        exceptionThrown );
-        //                    ViewUtils.displayErrorMessageBox( "Error", "An error occured when creating the project.\n"
-        //                        + "No suitable SchemaConnector has been found for the selected connection." );
-        //                }
-        //                else
-        //                // Standard case
-        //                {
-        //                    PluginUtils.logError( "An error occured when creating the project.", exceptionThrown );
-        //                    ViewUtils.displayErrorMessageBox( "Error", "An error occured when creating the project." );
-        //                }
-        //                return false;
-        //            }
-        //        }
-        //        else if ( projectType.equals( ProjectType.OFFLINE ) )
-        //        // Project is an "Offline Project"
-        //        {
-        // Getting the selected 'core' schemas
-        String[] selectedSchemas = schemasSelectionPage.getSelectedSchemas();
-        ServerTypeEnum serverType = schemasSelectionPage.getServerType();
-        if ( ( selectedSchemas != null ) && ( serverType != null ) )
+        if ( projectType.equals( ProjectType.ONLINE ) )
+            // Project is an "Online Project"
         {
-            SchemaHandler schemaHandler = project.getSchemaHandler();
-            for ( String selectedSchema : selectedSchemas )
+            // Setting the connection to use
+            project.setConnection( connectionSelectionPage.getSelectedConnection() );
+
+            // Reseting the Exception Thrown
+            exceptionThrown = null;
+
+            try
             {
-                Schema schema = PluginUtils.loadCoreSchema( serverType, selectedSchema );
-                if ( schema != null )
+                getContainer().run( false, false, new IRunnableWithProgress()
+                {
+                    public void run( IProgressMonitor monitor )
+                    {
+                        StudioProgressMonitor studioProgressMonitor = new StudioProgressMonitor( monitor );
+
+                        // Getting the correct SchemaConnector for this connection
+                        List<SchemaConnector> correctSchemaConnectors = getCorrectSchemaConnectors( project
+                            .getConnection(), studioProgressMonitor );
+
+                        // If no suitable SchemaConnector has been found, we display an
+                        // error message and return false;
+                        if ( correctSchemaConnectors.size() == 0 )
+                        {
+                            studioProgressMonitor.reportError(
+                                "No suitable SchemaConnector has been found for the choosen Directory Server.",
+                                new NoSuitableSchemaConnectorException() );
+                        }
+
+                        // Check if generic schema connector is included, then remove it to use a specific one
+                        if ( correctSchemaConnectors.size() > 1 )
+                        {
+                            for ( SchemaConnector schemaConnector : correctSchemaConnectors )
+                            {
+                                if ( schemaConnector instanceof GenericSchemaConnector )
+                                {
+                                    correctSchemaConnectors.remove( schemaConnector );
+                                    break;
+                                }
+                            }
+                        }
+
+                        // Getting the correct SchemaConnector
+                        SchemaConnector correctSchemaConnector = null;
+                        if ( correctSchemaConnectors.size() == 1 )
+                        {
+                            correctSchemaConnector = correctSchemaConnectors.get( 0 );
+                        }
+                        else
+                        {
+                            // TODO display a dialog in which the user can select the correct schema connector
+                        }
+
+                        project.setSchemaConnector( correctSchemaConnector );
+
+                        // Fetching the Online Schema
+                        project.fetchOnlineSchema( new StudioProgressMonitor( monitor ) );
+
+                        // Checking if an error has occured
+                        if ( studioProgressMonitor.errorsReported() )
+                        {
+                            exceptionThrown = studioProgressMonitor.getException();
+                            return;
+                        }
+                    }
+                } );
+            }
+            catch ( InvocationTargetException e )
+            {
+                // Nothing to do (it will never occur)
+            }
+            catch ( InterruptedException e )
+            {
+                // Nothing to do.
+            }
+
+            if ( exceptionThrown != null )
+            {
+                if ( exceptionThrown instanceof NoSuitableSchemaConnectorException )
+                    // Special case for the 'NoSuitableSchemaConnectorException'
+                {
+                    PluginUtils.logError( "No suitable SchemaConnector has been found for the selected connection.",
+                        exceptionThrown );
+                    ViewUtils.displayErrorMessageBox( "Error", "An error occured when creating the project.\n"
+                        + "No suitable SchemaConnector has been found for the selected connection." );
+                }
+                else
+                    // Standard case
                 {
-                    schemaHandler.addSchema( schema );
+                    PluginUtils.logError( "An error occured when creating the project.", exceptionThrown );
+                    ViewUtils.displayErrorMessageBox( "Error", "An error occured when creating the project." );
+                }
+                return false;
+            }
+        }
+        else if ( projectType.equals( ProjectType.OFFLINE ) )
+            // Project is an "Offline Project"
+        {
+            // Getting the selected 'core' schemas
+            String[] selectedSchemas = schemasSelectionPage.getSelectedSchemas();
+            ServerTypeEnum serverType = schemasSelectionPage.getServerType();
+            if ( ( selectedSchemas != null ) && ( serverType != null ) )
+            {
+                SchemaHandler schemaHandler = project.getSchemaHandler();
+                for ( String selectedSchema : selectedSchemas )
+                {
+                    Schema schema = PluginUtils.loadCoreSchema( serverType, selectedSchema );
+                    if ( schema != null )
+                    {
+                        schemaHandler.addSchema( schema );
+                    }
                 }
             }
         }
-        //        }
 
         ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler();
         projectsHandler.addProject( project );
@@ -193,66 +217,66 @@
     }
 
 
-    //    /**
-    //     * Gets the List of suitable SchemaConnectors
-    //     *
-    //     * @param connection
-    //     *      the connection to test the SchemaConnectors with
-    //     * @return
-    //     *      the List of suitable SchemaConnectors
-    //     */
-    //    private List<SchemaConnector> getCorrectSchemaConnectors( Connection connection, StudioProgressMonitor monitor )
-    //    {
-    //        List<SchemaConnector> suitableSchemaConnectors = new ArrayList<SchemaConnector>();
-    //
-    //        // Looping on the SchemaConnectors
-    //        List<SchemaConnector> schemaConectors = PluginUtils.getSchemaConnectors();
-    //        for ( SchemaConnector schemaConnector : schemaConectors )
-    //        {
-    //            // Testing if the SchemaConnector is suitable for this connection
-    //            if ( schemaConnector.isSuitableConnector( connection, monitor ) )
-    //            {
-    //                suitableSchemaConnectors.add( schemaConnector );
-    //            }
-    //        }
-    //
-    //        return suitableSchemaConnectors;
-    //    }
-
-    //    /* (non-Javadoc)
-    //     * @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
-    //     */
-    //    public IWizardPage getNextPage( IWizardPage page )
-    //    {
-    //        if ( page.equals( informationPage ) )
-    //        {
-    //            if ( informationPage.getProjectType().equals( ProjectType.ONLINE ) )
-    //            {
-    //                return connectionSelectionPage;
-    //            }
-    //            else if ( informationPage.getProjectType().equals( ProjectType.OFFLINE ) )
-    //            {
-    //                return schemasSelectionPage;
-    //            }
-    //        }
-    //
-    //        // Default
-    //        return null;
-    //    }
-
-    //    /* (non-Javadoc)
-    //     * @see org.eclipse.jface.wizard.Wizard#getPreviousPage(org.eclipse.jface.wizard.IWizardPage)
-    //     */
-    //    public IWizardPage getPreviousPage( IWizardPage page )
-    //    {
-    //        if ( ( page.equals( connectionSelectionPage ) ) || ( page.equals( schemasSelectionPage ) ) )
-    //        {
-    //            return informationPage;
-    //        }
-    //
-    //        // Default
-    //        return null;
-    //    }
+    /**
+     * Gets the List of suitable SchemaConnectors
+     *
+     * @param connection
+     *      the connection to test the SchemaConnectors with
+     * @return
+     *      the List of suitable SchemaConnectors
+     */
+    private List<SchemaConnector> getCorrectSchemaConnectors( Connection connection, StudioProgressMonitor monitor )
+    {
+        List<SchemaConnector> suitableSchemaConnectors = new ArrayList<SchemaConnector>();
+
+        // Looping on the SchemaConnectors
+        List<SchemaConnector> schemaConectors = PluginUtils.getSchemaConnectors();
+        for ( SchemaConnector schemaConnector : schemaConectors )
+        {
+            // Testing if the SchemaConnector is suitable for this connection
+            if ( schemaConnector.isSuitableConnector( connection, monitor ) )
+            {
+                suitableSchemaConnectors.add( schemaConnector );
+            }
+        }
+
+        return suitableSchemaConnectors;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
+     */
+    public IWizardPage getNextPage( IWizardPage page )
+    {
+        if ( page.equals( informationPage ) )
+        {
+            if ( informationPage.getProjectType().equals( ProjectType.ONLINE ) )
+            {
+                return connectionSelectionPage;
+            }
+            else if ( informationPage.getProjectType().equals( ProjectType.OFFLINE ) )
+            {
+                return schemasSelectionPage;
+            }
+        }
+
+        // Default
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#getPreviousPage(org.eclipse.jface.wizard.IWizardPage)
+     */
+    public IWizardPage getPreviousPage( IWizardPage page )
+    {
+        if ( ( page.equals( connectionSelectionPage ) ) || ( page.equals( schemasSelectionPage ) ) )
+        {
+            return informationPage;
+        }
+
+        // Default
+        return null;
+    }
 
     /* (non-Javadoc)
      * @see org.eclipse.jface.wizard.Wizard#canFinish()
@@ -269,10 +293,10 @@
         {
             return true;
         }
-        //        else if ( currentPage.equals( connectionSelectionPage ) )
-        //        {
-        //            return connectionSelectionPage.isPageComplete();
-        //        }
+        else if ( currentPage.equals( connectionSelectionPage ) )
+        {
+            return connectionSelectionPage.isPageComplete();
+        }
         else
         {
             return false;

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardInformationPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardInformationPage.java?rev=798544&r1=798543&r2=798544&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardInformationPage.java (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardInformationPage.java Tue Jul 28 14:46:13 2009
@@ -22,6 +22,7 @@
 
 import org.apache.directory.studio.schemaeditor.Activator;
 import org.apache.directory.studio.schemaeditor.PluginConstants;
+import org.apache.directory.studio.schemaeditor.PluginUtils;
 import org.apache.directory.studio.schemaeditor.controller.ProjectsHandler;
 import org.apache.directory.studio.schemaeditor.model.ProjectType;
 import org.eclipse.swt.SWT;
@@ -31,6 +32,7 @@
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
@@ -89,41 +91,41 @@
             }
         } );
 
-        //        if ( PluginUtils.getSchemaConnectors().size() > 0 )
-        //        {
-        //            // Type Group
-        //            Group typeGroup = new Group( composite, SWT.NONE );
-        //            typeGroup.setText( "Type" );
-        //            typeGroup.setLayout( new GridLayout() );
-        //            typeGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
-        //
-        //            typeOfflineRadio = new Button( typeGroup, SWT.RADIO );
-        //            typeOfflineRadio.setText( "Offline Schema" );
-        //            typeOfflineRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
-        //            typeOnlineRadio = new Button( typeGroup, SWT.RADIO );
-        //            typeOnlineRadio.setText( "Online Schema from a Directory Server" );
-        //            typeOnlineRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
-        //        }
+        if ( PluginUtils.getSchemaConnectors().size() > 0 )
+        {
+            // Type Group
+            Group typeGroup = new Group( composite, SWT.NONE );
+            typeGroup.setText( "Type" );
+            typeGroup.setLayout( new GridLayout() );
+            typeGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+
+            typeOfflineRadio = new Button( typeGroup, SWT.RADIO );
+            typeOfflineRadio.setText( "Offline Schema" );
+            typeOfflineRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+            typeOnlineRadio = new Button( typeGroup, SWT.RADIO );
+            typeOnlineRadio.setText( "Online Schema from a Directory Server" );
+            typeOnlineRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        }
 
-        //        initFields();
+        initFields();
 
         setControl( composite );
     }
 
 
-    //    /**
-    //     * Initializes the UI Fields.
-    //     */
-    //    private void initFields()
-    //    {
-    //        if ( typeOfflineRadio != null )
-    //        {
-    //            typeOfflineRadio.setSelection( true );
-    //        }
-    //
-    //        displayErrorMessage( null );
-    //        setPageComplete( false );
-    //    }
+    /**
+     * Initializes the UI Fields.
+     */
+    private void initFields()
+    {
+        if ( typeOfflineRadio != null )
+        {
+            typeOfflineRadio.setSelection( true );
+        }
+
+        displayErrorMessage( null );
+        setPageComplete( false );
+    }
 
     /**
      * This method is called when the user modifies something in the UI.

Modified: directory/studio/trunk/schemaeditor/src/main/resources/org.apache.directory.studio.schemaeditor.schemaConnectors.exsd
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/resources/org.apache.directory.studio.schemaeditor.schemaConnectors.exsd?rev=798544&r1=798543&r2=798544&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/resources/org.apache.directory.studio.schemaeditor.schemaConnectors.exsd (original)
+++ directory/studio/trunk/schemaeditor/src/main/resources/org.apache.directory.studio.schemaeditor.schemaConnectors.exsd Tue Jul 28 14:46:13 2009
@@ -14,6 +14,9 @@
 
    <element name="extension">
       <complexType>
+         <sequence>
+            <element ref="schemaConnector" minOccurs="1" maxOccurs="unbounded"/>
+         </sequence>
          <attribute name="point" type="string" use="required">
             <annotation>
                <documentation>



Mime
View raw message