directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r521810 - in /directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main: java/org/apache/directory/ldapstudio/schemas/model/ java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ resources/org/apache/directory/ldapstu...
Date Fri, 23 Mar 2007 17:11:48 GMT
Author: pamarcelot
Date: Fri Mar 23 10:11:46 2007
New Revision: 521810

URL: http://svn.apache.org/viewvc?view=rev&rev=521810
Log:
Improved Syntax Selection in the Attribute Type Editor.

Added:
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboContentProvider.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboInput.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboLabelProvider.java
Modified:
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Syntaxes.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/AttributeTypeEditorOverviewPage.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/messages.properties

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Syntaxes.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Syntaxes.java?view=diff&rev=521810&r1=521809&r2=521810
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Syntaxes.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Syntaxes.java
Fri Mar 23 10:11:46 2007
@@ -24,7 +24,6 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 
 import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.directory.ldapstudio.schemas.Activator;
@@ -35,11 +34,15 @@
  * This class allows to get the list of all syntaxes
  * (which is initialized once parsing a XML file)
  * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
  */
 public class Syntaxes
 {
+    /** The Syntaxes */
     private static final ArrayList<Syntax> syntaxes;
 
+    // Syntaxes Initialization
     static
     {
         try
@@ -82,8 +85,10 @@
 
 
     /**
-     * Return the unique initialized ArrayList containing all syntaxes
-     * @return the syntaxes ArrayList
+     * Returns the unique initialized ArrayList containing all syntaxes.
+     * 
+     * @return
+     *      the syntaxes ArrayList
      */
     public static ArrayList<Syntax> getSyntaxes()
     {
@@ -92,17 +97,41 @@
 
 
     /**
-     * Return the syntax object corresponding to the name given in parameter
-     * If no syntax is corresponding, it returns null
-     * @param name the name of the syntax
-     * @return the coreesponding Syntax object
+     * Return the syntax object corresponding to the name given in parameter.
+     * If no syntax is corresponding, it returns null.
+     * 
+     * @param name
+     *      the name of the syntax
+     * @return
+     *      the coreesponding Syntax object
      */
-    public static Syntax getSyntax( String name )
+    public static Syntax getSyntaxFromName( String name )
     {
-        for ( Iterator iter = syntaxes.iterator(); iter.hasNext(); )
+        for ( Syntax syntax : syntaxes )
         {
-            Syntax syntax = ( Syntax ) iter.next();
             if ( syntax.getName().equals( name ) )
+            {
+                return syntax;
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * Returns the syntax object corresponding to the oid given in parameter.
+     * If no syntax is corresponding, it returns null.
+     * 
+     * @param oid
+     *      the oid of the syntax
+     * @return
+     *      the coreesponding Syntax object
+     */
+    public static Syntax getSyntaxFromOid( String oid )
+    {
+        for ( Syntax syntax : syntaxes )
+        {
+            if ( syntax.getOid().equals( oid ) )
             {
                 return syntax;
             }

Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboContentProvider.java?view=auto&rev=521810
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboContentProvider.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboContentProvider.java
Fri Mar 23 10:11:46 2007
@@ -0,0 +1,115 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.ldapstudio.schemas.view.editors.attributeType;
+
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.schemas.model.Syntax;
+import org.apache.directory.ldapstudio.schemas.model.Syntaxes;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * This class implements the Content Provider for the Syntax Combo of the Attribute Type
Editor.
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ATESyntaxComboContentProvider implements IStructuredContentProvider
+{
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+     */
+    public Object[] getElements( Object inputElement )
+    {
+        if ( inputElement instanceof ATESyntaxComboInput )
+        {
+            ATESyntaxComboInput input = ( ATESyntaxComboInput ) inputElement;
+
+            if ( input.getChildren().isEmpty() )
+            {
+                // Creating the '(None)' item
+                input.addChild( new NonExistingSyntax( NonExistingSyntax.NONE ) );
+
+                // Creating Children
+                List<Syntax> syntaxes = Syntaxes.getSyntaxes();
+                for ( Syntax syntax : syntaxes )
+                {
+                    input.addChild( syntax );
+                }
+            }
+
+            // Getting Children
+            List<Object> children = input.getChildren();
+
+            // Sorting Children
+            Collections.sort( children, new Comparator<Object>()
+            {
+                public int compare( Object o1, Object o2 )
+                {
+                    if ( o1 instanceof Syntax && o2 instanceof Syntax )
+                    {
+                        return ( ( Syntax ) o1 ).getName().compareToIgnoreCase( ( ( Syntax
) o2 ).getName() );
+                    }
+                    else if ( o1 instanceof Syntax && o2 instanceof NonExistingSyntax
)
+                    {
+                        return ( ( Syntax ) o1 ).getName().compareToIgnoreCase( ( ( NonExistingSyntax
) o2 ).getName() );
+                    }
+                    else if ( o1 instanceof NonExistingSyntax && o2 instanceof Syntax
)
+                    {
+                        return ( ( NonExistingSyntax ) o1 ).getName().compareToIgnoreCase(
( ( Syntax ) o2 ).getName() );
+                    }
+                    else if ( o1 instanceof NonExistingSyntax && o2 instanceof NonExistingSyntax
)
+                    {
+                        return ( ( NonExistingSyntax ) o1 ).getName().compareToIgnoreCase(
+                            ( ( NonExistingSyntax ) o2 ).getName() );
+                    }
+
+                    return 0;
+                }
+            } );
+
+            return children.toArray();
+        }
+
+        // Default
+        return new Object[0];
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+     */
+    public void dispose()
+    {
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
java.lang.Object, java.lang.Object)
+     */
+    public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+    {
+    }
+}

Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboInput.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboInput.java?view=auto&rev=521810
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboInput.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboInput.java
Fri Mar 23 10:11:46 2007
@@ -0,0 +1,71 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.ldapstudio.schemas.view.editors.attributeType;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * This class implements the Input of the Syntax Combo of the Attribute Type Editor
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ATESyntaxComboInput
+{
+    /** The children */
+    private List<Object> children;
+
+
+    /**
+     * Adds a child.
+     *
+     * @param child
+     *      the child to add
+     */
+    public void addChild( Object child )
+    {
+        if ( children == null )
+        {
+            children = new ArrayList<Object>();
+        }
+
+        children.add( child );
+    }
+
+
+    /**
+     * Gets the children.
+     *
+     * @return
+     *      the children
+     */
+    public List<Object> getChildren()
+    {
+        if ( children == null )
+        {
+            children = new ArrayList<Object>();
+        }
+
+        return children;
+    }
+}

Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboLabelProvider.java?view=auto&rev=521810
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboLabelProvider.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/ATESyntaxComboLabelProvider.java
Fri Mar 23 10:11:46 2007
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.ldapstudio.schemas.view.editors.attributeType;
+
+
+import org.apache.directory.ldapstudio.schemas.model.Syntax;
+import org.eclipse.jface.viewers.LabelProvider;
+
+
+/**
+ * This class implements the Label Provider of the Syntax Combo of the Attribute Type Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ATESyntaxComboLabelProvider extends LabelProvider
+{
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+     */
+    public String getText( Object obj )
+    {
+        if ( obj instanceof Syntax )
+        {
+            return ( ( Syntax ) obj ).getName();
+        }
+        else if ( obj instanceof NonExistingSyntax )
+        {
+            return ( ( NonExistingSyntax ) obj ).getDisplayName();
+        }
+
+        // Default
+        return null;
+    }
+}

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/AttributeTypeEditorOverviewPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/AttributeTypeEditorOverviewPage.java?view=diff&rev=521810&r1=521809&r2=521810
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/AttributeTypeEditorOverviewPage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/attributeType/AttributeTypeEditorOverviewPage.java
Fri Mar 23 10:11:46 2007
@@ -21,8 +21,6 @@
 package org.apache.directory.ldapstudio.schemas.view.editors.attributeType;
 
 
-import java.util.ArrayList;
-
 import org.apache.directory.ldapstudio.schemas.Messages;
 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent;
@@ -103,6 +101,7 @@
     private ComboViewer supComboViewer;
     private Combo usageCombo;
     private Combo syntaxCombo;
+    private ComboViewer syntaxComboViewer;
     private Text syntaxLengthText;
     private Button obsoleteCheckbox;
     private Button singleValueCheckbox;
@@ -300,14 +299,24 @@
     {
         public void modifyText( ModifyEvent e )
         {
-            if ( syntaxCombo.getItem( syntaxCombo.getSelectionIndex() ).equals(
-                Messages.getString( "AttributeTypeFormEditorOverviewPage.(None)" ) ) ) {
//$NON-NLS-1$
-                modifiedAttributeType.setSyntax( "" ); //$NON-NLS-1$
+            Object selectedItem = ( ( StructuredSelection ) syntaxComboViewer.getSelection()
).getFirstElement();
+
+            if ( selectedItem instanceof Syntax )
+            {
+                modifiedAttributeType.setSyntax( ( ( Syntax ) selectedItem ).getOid() );
             }
-            else
+            else if ( selectedItem instanceof NonExistingSyntax )
             {
-                modifiedAttributeType.setSyntax( Syntaxes.getSyntax(
-                    syntaxCombo.getItem( syntaxCombo.getSelectionIndex() ) ).getOid() );
+                NonExistingSyntax nes = ( NonExistingSyntax ) selectedItem;
+
+                if ( NonExistingMatchingRule.NONE.equals( nes.getName() ) )
+                {
+                    modifiedAttributeType.setSyntax( null );
+                }
+                else
+                {
+                    modifiedAttributeType.setSyntax( ( ( NonExistingSyntax ) selectedItem
).getName() );
+                }
             }
             setEditorDirty();
         }
@@ -592,7 +601,10 @@
             .getString( "AttributeTypeFormEditorOverviewPage.Synatx" ) ); //$NON-NLS-1$
         syntaxCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE );
         syntaxCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 )
);
-        initSyntaxCombo();
+        syntaxComboViewer = new ComboViewer( syntaxCombo );
+        syntaxComboViewer.setContentProvider( new ATESyntaxComboContentProvider() );
+        syntaxComboViewer.setLabelProvider( new ATESyntaxComboLabelProvider() );
+        syntaxComboViewer.setInput( new ATESyntaxComboInput() );
 
         // SYNTAX LENGTH Field
         toolkit.createLabel( client_general_information, Messages
@@ -682,6 +694,9 @@
     }
 
 
+    /**
+     * Initializes the Usage Combo.
+     */
     private void initUsageCombo()
     {
         usageCombo.add( "directoryOperation", 0 ); //$NON-NLS-1$
@@ -691,18 +706,6 @@
     }
 
 
-    private void initSyntaxCombo()
-    {
-        syntaxCombo.add( Messages.getString( "AttributeTypeFormEditorOverviewPage.(None)"
), 0 ); //$NON-NLS-1$
-        syntaxCombo.select( 0 );
-        ArrayList<Syntax> syntaxes = Syntaxes.getSyntaxes();
-        for ( Syntax syntax : syntaxes )
-        {
-            syntaxCombo.add( syntax.getName() );
-        }
-    }
-
-
     /**
      * Fills in the User Interface fields.
      */
@@ -743,14 +746,7 @@
         fillInUsageCombo();
 
         // SYNTAX Combo
-        if ( modifiedAttributeType.getSyntax() == null )
-        {
-            fillInSyntaxCombo( Messages.getString( "ObjectClassFormEditorOverviewPage.(None)"
) );
-        }
-        else
-        {
-            fillInSyntaxCombo( modifiedAttributeType.getSyntax() );
-        }
+        fillSyntaxCombo();
 
         // SYNTAX LENGTH Field
         if ( modifiedAttributeType.getLength() != -1 )
@@ -840,26 +836,34 @@
 
 
     /**
-     * Fills the Syntax Combo from the attribute type value
-     *
-     * @param name
-     *      the name to select
+     * Fills the the Syntax Combo with the correct value.
      */
-    private void fillInSyntaxCombo( String name )
+    private void fillSyntaxCombo()
     {
-        if ( name.equals( Messages.getString( "AttributeTypeFormEditorOverviewPage.(None)"
) ) )
+        if ( modifiedAttributeType.getSyntax() == null )
         {
-            syntaxCombo.select( 0 );
+            syntaxComboViewer.setSelection( new StructuredSelection( new NonExistingSyntax(
NonExistingSyntax.NONE ) ),
+                true );
         }
         else
         {
-            syntaxCombo.select( 0 );
-            for ( int i = 1; i < syntaxCombo.getItemCount(); i++ )
+            String syntaxOID = modifiedAttributeType.getSyntax();
+
+            Syntax syntax = Syntaxes.getSyntaxFromOid( syntaxOID );
+            if ( syntax != null )
+            {
+                syntaxComboViewer.setSelection( new StructuredSelection( syntax ), true );
+            }
+            else
             {
-                if ( Syntaxes.getSyntax( syntaxCombo.getItem( i ) ).getOid().equals( name
) )
+                ATESyntaxComboInput input = ( ATESyntaxComboInput ) syntaxComboViewer.getInput();
+                NonExistingSyntax nes = new NonExistingSyntax( syntaxOID );
+                if ( !input.getChildren().contains( nes ) )
                 {
-                    syntaxCombo.select( i );
+                    input.addChild( nes );
                 }
+                syntaxComboViewer.refresh();
+                syntaxComboViewer.setSelection( new StructuredSelection( nes ), true );
             }
         }
     }

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/messages.properties
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/messages.properties?view=diff&rev=521810&r1=521809&r2=521810
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/messages.properties
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/messages.properties
Fri Mar 23 10:11:46 2007
@@ -178,6 +178,10 @@
 NonExistingMatchingRule.(None)=(None)
 NonExistingMatchingRule.(This_matching_rule_doesnt_exist)=(This matching rule doesn't exist)
 
+# NonExistingSyntax  -  org.apache.directory.ldapstudio.schemas.view.editors
+NonExistingSyntax.(None)=(None)
+NonExistingSyntax.(This_syntax_doesnt_exist)=(This syntax doesn't exist)
+
 # SchemaFormEditor  -  org.apache.directory.ldapstudio.schemas.view.editors
 SchemaFormEditor.Source_code=Source code
 



Mime
View raw message