directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r521343 - in /directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main: java/org/apache/directory/ldapstudio/schemas/view/dialogs/ java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ resources/org/apache/directory/ld...
Date Thu, 22 Mar 2007 16:58:15 GMT
Author: pamarcelot
Date: Thu Mar 22 09:58:14 2007
New Revision: 521343

URL: http://svn.apache.org/viewvc?view=rev&rev=521343
Log:
Improved Attribute Type selection in the Object Class Editor.
Added a Content Provider and a Label Provider for both Attribute Tables in the Object Class Editor.

Added:
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableContentProvider.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableLabelProvider.java
Modified:
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialog.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogContentProvider.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogLabelProvider.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialog.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogContentProvider.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogLabelProvider.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorOverviewPage.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/view/dialogs/messages.properties

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialog.java?view=diff&rev=521343&r1=521342&r2=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialog.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialog.java Thu Mar 22 09:58:14 2007
@@ -21,17 +21,26 @@
 package org.apache.directory.ldapstudio.schemas.view.dialogs;
 
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.schemas.Activator;
+import org.apache.directory.ldapstudio.schemas.model.AttributeType;
+import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
+import org.apache.directory.ldapstudio.schemas.view.views.TableDecoratingLabelProvider;
+import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
 import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
@@ -39,7 +48,6 @@
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.PlatformUI;
 
@@ -52,9 +60,18 @@
  */
 public class AttributeTypeSelectionDialog extends Dialog
 {
-    private Table attributeTypes_table;
-    private String selectedAttributeType = null;
-    private Text search_text;
+    /** The selected Attribute Type */
+    private AttributeType selectedAttributeType;
+
+    /** The Schema Pool */
+    private SchemaPool schemaPool;
+
+    /** The hidden Attribute Types */
+    private List<AttributeType> hiddenAttributeTypes;
+
+    // UI Fields
+    private Text searchText;
+    private Table attributeTypesTable;
     private TableViewer tableViewer;
 
 
@@ -64,6 +81,7 @@
     public AttributeTypeSelectionDialog()
     {
         super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
+        schemaPool = SchemaPool.getInstance();
     }
 
 
@@ -86,92 +104,66 @@
         GridLayout layout = new GridLayout( 1, false );
         composite.setLayout( layout );
 
-        Label choose_label = new Label( composite, SWT.NONE );
-        choose_label.setText( Messages.getString( "AttributeTypeSelectionDialog.Choose_an_attribute_type" ) ); //$NON-NLS-1$
-        choose_label.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
-
-        search_text = new Text( composite, SWT.BORDER );
-        search_text.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
-        search_text.addModifyListener( new ModifyListener()
+        Label chooseLabel = new Label( composite, SWT.NONE );
+        chooseLabel.setText( Messages.getString( "AttributeTypeSelectionDialog.Choose_an_attribute_type" ) ); //$NON-NLS-1$
+        chooseLabel.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+        searchText = new Text( composite, SWT.BORDER );
+        searchText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+        searchText.addModifyListener( new ModifyListener()
         {
             public void modifyText( ModifyEvent e )
             {
-                tableViewer.setInput( search_text.getText() );
-                attributeTypes_table.select( 0 );
+                tableViewer.setInput( searchText.getText() );
+                attributeTypesTable.select( 0 );
             }
         } );
-        search_text.addKeyListener( new KeyListener()
+        searchText.addKeyListener( new KeyAdapter()
         {
             public void keyPressed( KeyEvent e )
             {
                 if ( e.keyCode == SWT.ARROW_DOWN )
                 {
-                    attributeTypes_table.setFocus();
+                    attributeTypesTable.setFocus();
                 }
             }
-
-
-            public void keyReleased( KeyEvent e )
-            {
-            }
         } );
 
-        Label matching_label = new Label( composite, SWT.NONE );
-        matching_label.setText( Messages.getString( "AttributeTypeSelectionDialog.Matching_attribute_types" ) ); //$NON-NLS-1$
-        matching_label.setLayoutData( new GridData( GridData.FILL, SWT.None, true, false ) );
+        Label matchingLabel = new Label( composite, SWT.NONE );
+        matchingLabel.setText( Messages.getString( "AttributeTypeSelectionDialog.Matching_attribute_type(s)" ) ); //$NON-NLS-1$
+        matchingLabel.setLayoutData( new GridData( GridData.FILL, SWT.None, true, false ) );
 
-        attributeTypes_table = new Table( composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
+        attributeTypesTable = new Table( composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
             | SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
         GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
-        gridData.heightHint = 150;
-        gridData.minimumHeight = 150;
+        gridData.heightHint = 148;
+        gridData.minimumHeight = 148;
         gridData.widthHint = 350;
         gridData.minimumWidth = 350;
-        attributeTypes_table.setLayoutData( gridData );
-        attributeTypes_table.setHeaderVisible( true );
-        attributeTypes_table.addMouseListener( new MouseListener()
+        attributeTypesTable.setLayoutData( gridData );
+        attributeTypesTable.addMouseListener( new MouseAdapter()
         {
             public void mouseDoubleClick( MouseEvent e )
             {
-                if ( attributeTypes_table.getSelectionIndex() != -1 )
+                if ( attributeTypesTable.getSelectionIndex() != -1 )
                 {
                     okPressed();
                 }
             }
-
-
-            public void mouseDown( MouseEvent e )
-            {
-            }
-
-
-            public void mouseUp( MouseEvent e )
-            {
-            }
         } );
 
-        TableColumn column = new TableColumn( attributeTypes_table, SWT.LEFT, 0 );
-        column.setText( "" ); //$NON-NLS-1$
-        column.setWidth( 20 );
-
-        column = new TableColumn( attributeTypes_table, SWT.LEFT, 1 );
-        column.setText( Messages.getString( "AttributeTypeSelectionDialog.Name" ) ); //$NON-NLS-1$
-        column.setWidth( 230 );
-
-        column = new TableColumn( attributeTypes_table, SWT.LEFT, 2 );
-        column.setText( Messages.getString( "AttributeTypeSelectionDialog.Schema" ) ); //$NON-NLS-1$
-        column.setWidth( 100 );
-
-        tableViewer = new TableViewer( attributeTypes_table );
+        tableViewer = new TableViewer( attributeTypesTable );
         tableViewer.setUseHashlookup( true );
 
-        tableViewer.setContentProvider( new AttributeTypeSelectionDialogContentProvider() );
-        tableViewer.setLabelProvider( new AttributeTypeSelectionDialogLabelProvider() );
+        tableViewer.setContentProvider( new AttributeTypeSelectionDialogContentProvider( hiddenAttributeTypes ) );
+        tableViewer.setLabelProvider( new TableDecoratingLabelProvider(
+            new AttributeTypeSelectionDialogLabelProvider(), Activator.getDefault().getWorkbench()
+                .getDecoratorManager().getLabelDecorator() ) );
 
         // We need to force the input to load the complete list of attribute types
         tableViewer.setInput( "" ); //$NON-NLS-1$
         // We also need to force the selection of the first row
-        attributeTypes_table.select( 0 );
+        attributeTypesTable.select( 0 );
 
         return composite;
     }
@@ -193,7 +185,9 @@
      */
     protected void okPressed()
     {
-        if ( attributeTypes_table.getSelectionIndex() == -1 )
+        StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection();
+
+        if ( selection.isEmpty() )
         {
             MessageDialog
                 .openError(
@@ -201,19 +195,75 @@
                     Messages.getString( "AttributeTypeSelectionDialog.Invalid_Selection" ), Messages.getString( "AttributeTypeSelectionDialog.You_have_to_choose_an_attribute_type" ) ); //$NON-NLS-1$ //$NON-NLS-2$
             return;
         }
-        selectedAttributeType = attributeTypes_table.getItem( attributeTypes_table.getSelectionIndex() ).getText( 1 );
+
+        AttributeTypeWrapper atw = ( AttributeTypeWrapper ) selection.getFirstElement();
+        if ( atw != null )
+        {
+            selectedAttributeType = atw.getMyAttributeType();
+        }
+
         super.okPressed();
     }
 
 
     /**
-     * Returns the selected attribute type.
+     * Returns the selected Attribute Type.
      * 
      * @return
-     *      the selected attribute type
+     *      the selected Attribute Type
      */
-    public String getSelectedAttributeType()
+    public AttributeType getSelectedAttributeType()
     {
         return selectedAttributeType;
+    }
+
+
+    /**
+     * Set the hidden Attribute Types.
+     *
+     * @param list
+     *      a list of Attribute Types to hide
+     */
+    public void setHiddenAttributeTypes( List<AttributeType> list )
+    {
+        hiddenAttributeTypes = list;
+    }
+
+
+    /**
+     * Sets the hidden Attribute Types.
+     *
+     * @param attributeTypes
+     *      an array of Attribute Types to hide
+     */
+    public void setHiddenAttributeTypes( AttributeType[] attributeTypes )
+    {
+        hiddenAttributeTypes = new ArrayList<AttributeType>();
+
+        for ( AttributeType objectClass : attributeTypes )
+        {
+            hiddenAttributeTypes.add( objectClass );
+        }
+    }
+
+
+    /**
+     * Sets the hidden Attribute Types.
+     *
+     * @param names
+     *      an array of names of Attribute Types to hide
+     */
+    public void setHiddenAttributeTypes( String[] names )
+    {
+        hiddenAttributeTypes = new ArrayList<AttributeType>();
+
+        for ( String name : names )
+        {
+            AttributeType at = schemaPool.getAttributeType( name );
+            if ( at != null )
+            {
+                hiddenAttributeTypes.add( at );
+            }
+        }
     }
 }

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogContentProvider.java?view=diff&rev=521343&r1=521342&r2=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogContentProvider.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogContentProvider.java Thu Mar 22 09:58:14 2007
@@ -30,19 +30,47 @@
 
 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
+import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.Viewer;
 
 
+/**
+ * This class is the Content Provider for the Attribute Type Selection Dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class AttributeTypeSelectionDialogContentProvider implements IStructuredContentProvider
 {
+    /** The Schema Pool */
+    private SchemaPool schemaPool;
 
-    @SuppressWarnings("unchecked")//$NON-NLS-1$
+    /** The hidden Object Classes */
+    private List<AttributeType> hiddenAttributeTypes;
+
+
+    /**
+     * Creates a new instance of AttributeTypeSelectionDialogContentProvider.
+     */
+    public AttributeTypeSelectionDialogContentProvider( List<AttributeType> hiddenAttributeTypes )
+    {
+        schemaPool = SchemaPool.getInstance();
+        this.hiddenAttributeTypes = hiddenAttributeTypes;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+     */
     public Object[] getElements( Object inputElement )
     {
         if ( inputElement instanceof String )
         {
+            ArrayList<AttributeTypeWrapper> results = new ArrayList<AttributeTypeWrapper>();
+
             String searchText = ( String ) inputElement;
+
             String searchRegexp;
             if ( searchText.length() == 0 )
             {
@@ -52,57 +80,92 @@
             {
                 searchRegexp = searchText + ".*"; //$NON-NLS-1$
             }
-
             Pattern pattern = Pattern.compile( searchRegexp, Pattern.CASE_INSENSITIVE );
-            ArrayList resultsList = new ArrayList();
-
-            SchemaPool schemaPool = SchemaPool.getInstance();
 
             List<AttributeType> atList = schemaPool.getAttributeTypes();
 
             // Sorting the list
             Collections.sort( atList, new Comparator<AttributeType>()
             {
-                public int compare( AttributeType arg0, AttributeType arg1 )
+                public int compare( AttributeType at1, AttributeType at2 )
                 {
-                    String oneName = arg0.getNames()[0];
-                    String twoName = arg1.getNames()[0];
-                    return oneName.compareTo( twoName );
+                    if ( ( at1.getNames() == null || at1.getNames().length == 0 )
+                        && ( at2.getNames() == null || at2.getNames().length == 0 ) )
+                    {
+                        return 0;
+                    }
+                    else if ( ( at1.getNames() == null || at1.getNames().length == 0 )
+                        && ( at2.getNames() != null && at2.getNames().length > 0 ) )
+                    {
+                        return "".compareToIgnoreCase( at2.getNames()[0] ); //$NON-NLS-1$
+                    }
+                    else if ( ( at1.getNames() != null && at1.getNames().length > 0 )
+                        && ( at2.getNames() == null || at2.getNames().length == 0 ) )
+                    {
+                        return at1.getNames()[0].compareToIgnoreCase( "" ); //$NON-NLS-1$
+                    }
+                    else
+                    {
+                        return at1.getNames()[0].compareToIgnoreCase( at2.getNames()[0] );
+                    }
                 }
             } );
 
-            //search for all matching elements
-            for ( AttributeType element : atList )
+            // Searching for all matching elements
+            for ( AttributeType at : atList )
             {
-
-                String[] names = element.getNames();
-                for ( String name : names )
+                for ( String name : at.getNames() )
                 {
                     Matcher m = pattern.matcher( name );
                     if ( m.matches() )
                     {
-                        if ( !resultsList.contains( element ) )
+                        if ( !hiddenAttributeTypes.contains( at ) )
                         {
-                            resultsList.add( element );
+                            AttributeTypeWrapper atw = new AttributeTypeWrapper( at, null );
+                            if ( !results.contains( atw ) )
+                            {
+                                results.add( new AttributeTypeWrapper( at, null ) );
+                            }
                         }
                         break;
                     }
                 }
+                Matcher m = pattern.matcher( at.getOid() );
+                if ( m.matches() )
+                {
+                    if ( !hiddenAttributeTypes.contains( at ) )
+                    {
+                        AttributeTypeWrapper atw = new AttributeTypeWrapper( at, null );
+                        if ( !results.contains( atw ) )
+                        {
+                            results.add( new AttributeTypeWrapper( at, null ) );
+                        }
+                    }
+                }
             }
-            //returns the result list
-            return resultsList.toArray();
+
+            // Returns the results
+            return results.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 )
     {
     }
 
-}
+}
\ No newline at end of file

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogLabelProvider.java?view=diff&rev=521343&r1=521342&r2=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogLabelProvider.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/AttributeTypeSelectionDialogLabelProvider.java Thu Mar 22 09:58:14 2007
@@ -23,47 +23,51 @@
 
 import org.apache.directory.ldapstudio.schemas.Activator;
 import org.apache.directory.ldapstudio.schemas.PluginConstants;
-import org.apache.directory.ldapstudio.schemas.model.SchemaElement;
+import org.apache.directory.ldapstudio.schemas.model.AttributeType;
+import org.apache.directory.ldapstudio.schemas.view.ViewUtils;
+import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper;
 import org.eclipse.jface.viewers.ITableLabelProvider;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 
 
+/**
+ * This class is the Label Provider for the Attribute Type Selection Dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class AttributeTypeSelectionDialogLabelProvider extends LabelProvider implements ITableLabelProvider
 {
-
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+     */
     public Image getColumnImage( Object element, int columnIndex )
     {
-        if ( columnIndex == 0 )
+        if ( element instanceof AttributeTypeWrapper )
         {
             return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_ATTRIBUTE_TYPE )
                 .createImage();
         }
+
+        // Default
         return null;
     }
 
 
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+     */
     public String getColumnText( Object element, int columnIndex )
     {
-        String result = ""; //$NON-NLS-1$
-        if ( element instanceof SchemaElement )
+        if ( element instanceof AttributeTypeWrapper )
         {
-            SchemaElement schemaElement = ( SchemaElement ) element;
-            switch ( columnIndex )
-            {
-                case 0: // COMPLETED_COLUMN
-                    break;
-                case 1:
-                    result = schemaElement.getNames()[0];
-                    break;
-                case 2:
-                    result = schemaElement.getOriginatingSchema().getName();
-                    break;
-                default:
-                    break;
-            }
+            AttributeType at = ( ( AttributeTypeWrapper ) element ).getMyAttributeType();
+            return ViewUtils.concateAliases( at.getNames() ) + "   [" + at.getOid() + "]";
         }
-        return result;
+
+        // Default
+        return null;
     }
 }

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialog.java?view=diff&rev=521343&r1=521342&r2=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialog.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialog.java Thu Mar 22 09:58:14 2007
@@ -60,7 +60,7 @@
  */
 public class ObjectClassSelectionDialog extends Dialog
 {
-    /** The selected Object Class*/
+    /** The selected Object Class */
     private ObjectClass selectedObjectClass;
 
     /** The Schema Pool */
@@ -70,9 +70,9 @@
     private List<ObjectClass> hiddenObjectClasses;
 
     // UI Fields
+    private Text searchText;
     private Table objectClassesTable;
     private TableViewer tableViewer;
-    private Text searchText;
 
 
     /**
@@ -130,7 +130,7 @@
         } );
 
         Label matchingLabel = new Label( composite, SWT.NONE );
-        matchingLabel.setText( Messages.getString( "ObjectClassSelectionDialog.Matching_object_classes" ) ); //$NON-NLS-1$
+        matchingLabel.setText( Messages.getString( "ObjectClassSelectionDialog.Matching_object_class(es)" ) ); //$NON-NLS-1$
         matchingLabel.setLayoutData( new GridData( GridData.FILL, SWT.None, true, false ) );
 
         objectClassesTable = new Table( composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
@@ -205,10 +205,10 @@
 
 
     /**
-     * Returns the selected object class.
+     * Returns the selected Object Class.
      * 
      * @return 
-     *      the selected object class
+     *      the selected Object Class
      */
     public ObjectClass getSelectedObjectClass()
     {

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogContentProvider.java?view=diff&rev=521343&r1=521342&r2=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogContentProvider.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogContentProvider.java Thu Mar 22 09:58:14 2007
@@ -97,12 +97,12 @@
                     else if ( ( oc1.getNames() == null || oc1.getNames().length == 0 )
                         && ( oc2.getNames() != null && oc2.getNames().length > 0 ) )
                     {
-                        return "".compareToIgnoreCase( oc2.getNames()[0] );
+                        return "".compareToIgnoreCase( oc2.getNames()[0] ); //$NON-NLS-1$
                     }
                     else if ( ( oc1.getNames() != null && oc1.getNames().length > 0 )
                         && ( oc2.getNames() == null || oc2.getNames().length == 0 ) )
                     {
-                        return oc1.getNames()[0].compareToIgnoreCase( "" );
+                        return oc1.getNames()[0].compareToIgnoreCase( "" ); //$NON-NLS-1$
                     }
                     else
                     {

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogLabelProvider.java?view=diff&rev=521343&r1=521342&r2=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogLabelProvider.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/dialogs/ObjectClassSelectionDialogLabelProvider.java Thu Mar 22 09:58:14 2007
@@ -50,6 +50,7 @@
             return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_OBJECT_CLASS )
                 .createImage();
         }
+        
         // Default
         return null;
     }
@@ -63,7 +64,6 @@
         if ( element instanceof ObjectClassWrapper )
         {
             ObjectClass oc = ( ( ObjectClassWrapper ) element ).getMyObjectClass();
-
             return ViewUtils.concateAliases( oc.getNames() ) + "   [" + oc.getOid() + "]";
         }
 

Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableContentProvider.java?view=auto&rev=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableContentProvider.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableContentProvider.java Thu Mar 22 09:58:14 2007
@@ -0,0 +1,104 @@
+/*
+ *  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.objectClass;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.schemas.model.AttributeType;
+import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
+import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper;
+import org.apache.directory.server.core.tools.schema.AttributeTypeLiteral;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * This class is the Content Provider for the Attributes Table of the Object Class Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassEditorAttributesTableContentProvider implements IStructuredContentProvider
+{
+    /** The Schema Pool */
+    private SchemaPool schemaPool;
+
+
+    /**
+     * Creates a new instance of ObjectClassEditorAttributesTableContentProvider.
+     */
+    public ObjectClassEditorAttributesTableContentProvider()
+    {
+        schemaPool = SchemaPool.getInstance();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+     */
+    public Object[] getElements( Object inputElement )
+    {
+        if ( inputElement instanceof String[] )
+        {
+            List<AttributeTypeWrapper> results = new ArrayList<AttributeTypeWrapper>();
+
+            String[] attributes = ( String[] ) inputElement;
+            for ( String attribute : attributes )
+            {
+                AttributeType at = schemaPool.getAttributeType( attribute );
+                if ( at != null )
+                {
+                    results.add( new AttributeTypeWrapper( at, null ) );
+                }
+                else
+                {
+                    AttributeTypeLiteral atl = new AttributeTypeLiteral( "" );
+                    atl.setNames( new String[]
+                        { attribute } );
+                    AttributeType newAT = new AttributeType( atl, null );
+                    results.add( new AttributeTypeWrapper( newAT, null ) );
+                }
+            }
+
+            return results.toArray();
+        }
+
+        // Default
+        return null;
+    }
+
+
+    /* (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/objectClass/ObjectClassEditorAttributesTableLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableLabelProvider.java?view=auto&rev=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableLabelProvider.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorAttributesTableLabelProvider.java Thu Mar 22 09:58:14 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.objectClass;
+
+
+import org.apache.directory.ldapstudio.schemas.Activator;
+import org.apache.directory.ldapstudio.schemas.PluginConstants;
+import org.apache.directory.ldapstudio.schemas.view.ViewUtils;
+import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class is the Label Provider for the Attributes Table of the Object Class Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassEditorAttributesTableLabelProvider extends LabelProvider implements ITableLabelProvider
+{
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+     */
+    public Image getColumnImage( Object element, int columnIndex )
+    {
+        if ( element instanceof AttributeTypeWrapper )
+        {
+            return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_ATTRIBUTE_TYPE )
+                .createImage();
+        }
+
+        // Default
+        return null;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+     */
+    public String getColumnText( Object element, int columnIndex )
+    {
+        if ( element instanceof AttributeTypeWrapper )
+        {
+            return ViewUtils.concateAliases( ( ( AttributeTypeWrapper ) element ).getMyAttributeType().getNames() );
+        }
+
+        // Default
+        return null;
+    }
+}

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorOverviewPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorOverviewPage.java?view=diff&rev=521343&r1=521342&r2=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorOverviewPage.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/objectClass/ObjectClassEditorOverviewPage.java Thu Mar 22 09:58:14 2007
@@ -22,11 +22,9 @@
 
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
-import org.apache.directory.ldapstudio.schemas.Activator;
-import org.apache.directory.ldapstudio.schemas.PluginConstants;
+import org.apache.directory.ldapstudio.schemas.model.AttributeType;
 import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
 import org.apache.directory.ldapstudio.schemas.model.Schema;
 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
@@ -39,11 +37,11 @@
 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditorInput;
 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditor;
 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditorInput;
+import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper;
 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ObjectClassWrapper;
 import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
 import org.apache.log4j.Logger;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.window.Window;
@@ -64,7 +62,6 @@
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
@@ -78,7 +75,6 @@
 import org.eclipse.ui.forms.widgets.Hyperlink;
 import org.eclipse.ui.forms.widgets.ScrolledForm;
 import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
 
 
 /**
@@ -112,9 +108,11 @@
     private Combo classTypeCombo;
     private Button obsoleteCheckbox;
     private Table mandatoryAttributesTable;
+    private TableViewer mandatoryAttributesTableViewer;
     private Button addButtonMandatoryTable;
     private Button removeButtonMandatoryTable;
     private Table optionalAttributesTable;
+    private TableViewer optionalAttributesTableViewer;
     private Button addButtonOptionalTable;
     private Button removeButtonOptionalTable;
 
@@ -258,15 +256,26 @@
     {
         public void mouseDoubleClick( MouseEvent e )
         {
+            StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection();
+            if ( selection.isEmpty() )
+            {
+                return;
+            }
+
+            AttributeTypeWrapper atw = ( AttributeTypeWrapper ) selection.getFirstElement();
+            if ( atw == null )
+            {
+                return;
+            }
+
             SchemaPool pool = SchemaPool.getInstance();
             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
 
-            AttributeTypeEditorInput input = new AttributeTypeEditorInput( pool
-                .getAttributeType( mandatoryAttributesTable.getSelection()[0].getText() ) );
-            String editorId = AttributeTypeEditor.ID;
+            AttributeTypeEditorInput input = new AttributeTypeEditorInput( pool.getAttributeType( atw
+                .getMyAttributeType().getNames()[0] ) );
             try
             {
-                page.openEditor( input, editorId );
+                page.openEditor( input, AttributeTypeEditor.ID );
             }
             catch ( PartInitException exception )
             {
@@ -294,45 +303,49 @@
     {
         public void widgetSelected( SelectionEvent e )
         {
-            AttributeTypeSelectionDialog selectionDialog = new AttributeTypeSelectionDialog();
-            if ( selectionDialog.open() != Window.OK )
+            AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog();
+            SchemaPool pool = SchemaPool.getInstance();
+            List<AttributeType> hiddenATs = new ArrayList<AttributeType>();
+            for ( String must : modifiedObjectClass.getMust() )
+            {
+                AttributeType at = pool.getAttributeType( must );
+                if ( at != null )
+                {
+                    hiddenATs.add( at );
+                }
+            }
+            for ( String may : modifiedObjectClass.getMay() )
+            {
+                AttributeType at = pool.getAttributeType( may );
+                if ( at != null )
+                {
+                    hiddenATs.add( at );
+                }
+            }
+            dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeType[0] ) );
+
+            if ( dialog.open() != Window.OK )
             {
                 return;
             }
-            if ( isAttributeTypeAlreadySpecified( selectionDialog.getSelectedAttributeType(), optionalAttributesTable ) )
+
+            AttributeType at = dialog.getSelectedAttributeType();
+            if ( at == null )
             {
-                // The selected attribute type is already in the Optionnal Attributes Table
-                MessageDialog
-                    .openError(
-                        null,
-                        Messages.getString( "ObjectClassFormEditorOverviewPage.Invalid_Selection" ), Messages.getString( "ObjectClassFormEditorOverviewPage.The_selected_attribute_type_is_already_in_the_Optionnal_Attributes_section" ) ); //$NON-NLS-1$ //$NON-NLS-2$
+                return;
             }
-            else
+
+            List<String> newMusts = new ArrayList<String>();
+            String[] musts = modifiedObjectClass.getMust();
+            for ( String must : musts )
             {
-                if ( isAttributeTypeAlreadySpecified( selectionDialog.getSelectedAttributeType(),
-                    mandatoryAttributesTable ) )
-                {
-                    // The selected attribute type is already in the Mandatory Attributes Table
-                    MessageDialog
-                        .openError(
-                            null,
-                            Messages.getString( "ObjectClassFormEditorOverviewPage.Invalid_Selection" ), Messages.getString( "ObjectClassFormEditorOverviewPage.The_selected_attribute_type_is_already_in_the_this_section" ) ); //$NON-NLS-1$ //$NON-NLS-2$
-                }
-                else
-                {
-                    // The selected attribute is not in any table, so it can be added
-                    ArrayList<String> mustList = new ArrayList<String>();
-                    String[] mustATs = modifiedObjectClass.getMust();
-                    for ( String mustAT : mustATs )
-                    {
-                        mustList.add( mustAT );
-                    }
-                    mustList.add( selectionDialog.getSelectedAttributeType() );
-                    modifiedObjectClass.setMust( mustList.toArray( new String[0] ) );
-                    fillInMandatoryAttributesTable();
-                    setEditorDirty();
-                }
+                newMusts.add( must );
             }
+            newMusts.add( at.getNames()[0] );
+            modifiedObjectClass.setMust( newMusts.toArray( new String[0] ) );
+
+            fillInMandatoryAttributesTable();
+            setEditorDirty();
         }
     };
 
@@ -341,19 +354,32 @@
     {
         public void widgetSelected( SelectionEvent e )
         {
-            String itemToRemove = mandatoryAttributesTable.getItem( mandatoryAttributesTable.getSelectionIndex() )
-                .getText();
+            StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection();
+            if ( selection.isEmpty() )
+            {
+                return;
+            }
 
-            ArrayList<String> mustList = new ArrayList<String>();
-            String[] mustATs = modifiedObjectClass.getMust();
-            for ( String mustAT : mustATs )
+            AttributeTypeWrapper atw = ( AttributeTypeWrapper ) selection.getFirstElement();
+            if ( atw == null )
             {
-                mustList.add( mustAT );
+                return;
             }
-            mustList.remove( itemToRemove );
-            modifiedObjectClass.setMust( mustList.toArray( new String[0] ) );
-            removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 );
+
+            List<String> newMusts = new ArrayList<String>();
+            String[] musts = modifiedObjectClass.getMust();
+            for ( String must : musts )
+            {
+                newMusts.add( must );
+            }
+            for ( String name : atw.getMyAttributeType().getNames() )
+            {
+                newMusts.remove( name );
+            }
+            modifiedObjectClass.setMust( newMusts.toArray( new String[0] ) );
+
             fillInMandatoryAttributesTable();
+            removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 );
             setEditorDirty();
         }
     };
@@ -363,15 +389,26 @@
     {
         public void mouseDoubleClick( MouseEvent e )
         {
+            StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection();
+            if ( selection.isEmpty() )
+            {
+                return;
+            }
+
+            AttributeTypeWrapper atw = ( AttributeTypeWrapper ) selection.getFirstElement();
+            if ( atw == null )
+            {
+                return;
+            }
+
             SchemaPool pool = SchemaPool.getInstance();
             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
 
-            AttributeTypeEditorInput input = new AttributeTypeEditorInput( pool
-                .getAttributeType( optionalAttributesTable.getSelection()[0].getText() ) );
-            String editorId = AttributeTypeEditor.ID;
+            AttributeTypeEditorInput input = new AttributeTypeEditorInput( pool.getAttributeType( atw
+                .getMyAttributeType().getNames()[0] ) );
             try
             {
-                page.openEditor( input, editorId );
+                page.openEditor( input, AttributeTypeEditor.ID );
             }
             catch ( PartInitException exception )
             {
@@ -394,45 +431,49 @@
     {
         public void widgetSelected( SelectionEvent e )
         {
-            AttributeTypeSelectionDialog selectionDialog = new AttributeTypeSelectionDialog();
-            if ( selectionDialog.open() != Window.OK )
+            AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog();
+            SchemaPool pool = SchemaPool.getInstance();
+            List<AttributeType> hiddenATs = new ArrayList<AttributeType>();
+            for ( String must : modifiedObjectClass.getMust() )
+            {
+                AttributeType at = pool.getAttributeType( must );
+                if ( at != null )
+                {
+                    hiddenATs.add( at );
+                }
+            }
+            for ( String may : modifiedObjectClass.getMay() )
+            {
+                AttributeType at = pool.getAttributeType( may );
+                if ( at != null )
+                {
+                    hiddenATs.add( at );
+                }
+            }
+            dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeType[0] ) );
+
+            if ( dialog.open() != Window.OK )
             {
                 return;
             }
-            if ( isAttributeTypeAlreadySpecified( selectionDialog.getSelectedAttributeType(), mandatoryAttributesTable ) )
+
+            AttributeType at = dialog.getSelectedAttributeType();
+            if ( at == null )
             {
-                // The selected attribute type is already in the Mandatory Attributes Table
-                MessageDialog
-                    .openError(
-                        null,
-                        Messages.getString( "ObjectClassFormEditorOverviewPage.Invalid_Selection" ), Messages.getString( "ObjectClassFormEditorOverviewPage.The_selected_attribute_type_is_already_in_the_Mandatory_Attributes_section" ) ); //$NON-NLS-1$ //$NON-NLS-2$
+                return;
             }
-            else
+
+            List<String> newMays = new ArrayList<String>();
+            String[] mays = modifiedObjectClass.getMay();
+            for ( String may : mays )
             {
-                if ( isAttributeTypeAlreadySpecified( selectionDialog.getSelectedAttributeType(),
-                    optionalAttributesTable ) )
-                {
-                    // The selected attribute type is already in the Optionnal Attributes Table
-                    MessageDialog
-                        .openError(
-                            null,
-                            Messages.getString( "ObjectClassFormEditorOverviewPage.Invalid_Selection" ), Messages.getString( "ObjectClassFormEditorOverviewPage.The_selected_attribute_type_is_already_in_the_this_section" ) ); //$NON-NLS-1$ //$NON-NLS-2$
-                }
-                else
-                {
-                    // The selected attribute is not in any table, so it can be added
-                    ArrayList<String> mayList = new ArrayList<String>();
-                    String[] mayATs = modifiedObjectClass.getMay();
-                    for ( int i = 0; i < mayATs.length; i++ )
-                    {
-                        mayList.add( mayATs[i] );
-                    }
-                    mayList.add( selectionDialog.getSelectedAttributeType() );
-                    modifiedObjectClass.setMay( mayList.toArray( new String[0] ) );
-                    fillInOptionalAttributesTable();
-                    setEditorDirty();
-                }
+                newMays.add( may );
             }
+            newMays.add( at.getNames()[0] );
+            modifiedObjectClass.setMay( newMays.toArray( new String[0] ) );
+
+            fillInOptionalAttributesTable();
+            setEditorDirty();
         }
     };
 
@@ -441,19 +482,32 @@
     {
         public void widgetSelected( SelectionEvent e )
         {
-            String itemToRemove = optionalAttributesTable.getItem( optionalAttributesTable.getSelectionIndex() )
-                .getText();
+            StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection();
+            if ( selection.isEmpty() )
+            {
+                return;
+            }
 
-            ArrayList<String> mayList = new ArrayList<String>();
-            String[] mayATs = modifiedObjectClass.getMay();
-            for ( String mayAT : mayATs )
+            AttributeTypeWrapper atw = ( AttributeTypeWrapper ) selection.getFirstElement();
+            if ( atw == null )
             {
-                mayList.add( mayAT );
+                return;
             }
-            mayList.remove( itemToRemove );
-            modifiedObjectClass.setMay( mayList.toArray( new String[0] ) );
-            removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 );
+
+            List<String> newMays = new ArrayList<String>();
+            String[] mays = modifiedObjectClass.getMay();
+            for ( String may : mays )
+            {
+                newMays.add( may );
+            }
+            for ( String name : atw.getMyAttributeType().getNames() )
+            {
+                newMays.remove( name );
+            }
+            modifiedObjectClass.setMay( newMays.toArray( new String[0] ) );
+
             fillInOptionalAttributesTable();
+            removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 );
             setEditorDirty();
         }
     };
@@ -478,12 +532,11 @@
             SchemaPool pool = SchemaPool.getInstance();
             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
 
-            ObjectClassEditorInput input = new ObjectClassEditorInput( pool.getObjectClass( ocw
-                .getMyObjectClass().getNames()[0] ) );
-            String editorId = ObjectClassEditor.ID;
+            ObjectClassEditorInput input = new ObjectClassEditorInput( pool.getObjectClass( ocw.getMyObjectClass()
+                .getNames()[0] ) );
             try
             {
-                page.openEditor( input, editorId );
+                page.openEditor( input, ObjectClassEditor.ID );
             }
             catch ( PartInitException exception )
             {
@@ -526,7 +579,6 @@
             }
 
             ObjectClass oc = dialog.getSelectedObjectClass();
-
             if ( oc == null )
             {
                 return;
@@ -749,6 +801,9 @@
         gd.verticalSpan = 2;
         gd.heightHint = 108;
         mandatoryAttributesTable.setLayoutData( gd );
+        mandatoryAttributesTableViewer = new TableViewer( mandatoryAttributesTable );
+        mandatoryAttributesTableViewer.setContentProvider( new ObjectClassEditorAttributesTableContentProvider() );
+        mandatoryAttributesTableViewer.setLabelProvider( new ObjectClassEditorAttributesTableLabelProvider() );
 
         addButtonMandatoryTable = toolkit.createButton( client, Messages
             .getString( "ObjectClassFormEditorOverviewPage.Add..." ), SWT.PUSH ); //$NON-NLS-1$
@@ -794,6 +849,9 @@
         gd.verticalSpan = 2;
         gd.heightHint = 108;
         optionalAttributesTable.setLayoutData( gd );
+        optionalAttributesTableViewer = new TableViewer( optionalAttributesTable );
+        optionalAttributesTableViewer.setContentProvider( new ObjectClassEditorAttributesTableContentProvider() );
+        optionalAttributesTableViewer.setLabelProvider( new ObjectClassEditorAttributesTableLabelProvider() );
 
         addButtonOptionalTable = toolkit.createButton( client, Messages
             .getString( "ObjectClassFormEditorOverviewPage.Add..." ), SWT.PUSH ); //$NON-NLS-1$
@@ -809,29 +867,6 @@
 
 
     /**
-     * Verifies if an attribute type is already present in a the given table
-     *
-     * @param name
-     *      the name of the attribute type to search
-     * @param table
-     *      the table to search in
-     * @return
-     *      true if the attribute type is already present in the given table
-     */
-    private boolean isAttributeTypeAlreadySpecified( String name, Table table )
-    {
-        for ( int i = 0; i < table.getItemCount(); i++ )
-        {
-            if ( table.getItem( i ).getText().equals( name ) )
-            {
-                return true;
-            }
-        }
-        return false;
-    }
-
-
-    /**
      * Initializes the UI fields from the input.
      */
     private void fillInUiFields()
@@ -926,27 +961,7 @@
      */
     private void fillInMandatoryAttributesTable()
     {
-        int selectionIndex = mandatoryAttributesTable.getSelectionIndex();
-        String selectAttribute = null;
-        if ( selectionIndex != -1 )
-        {
-            selectAttribute = mandatoryAttributesTable.getItem( selectionIndex ).getText();
-        }
-        mandatoryAttributesTable.clearAll();
-        mandatoryAttributesTable.setItemCount( 0 );
-        String[] mustArray = modifiedObjectClass.getMust();
-        Arrays.sort( mustArray );
-        for ( int i = 0; i < mustArray.length; i++ )
-        {
-            TableItem item = new TableItem( mandatoryAttributesTable, SWT.NONE, i );
-            item.setImage( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
-                PluginConstants.IMG_ATTRIBUTE_TYPE ).createImage() );
-            item.setText( mustArray[i] );
-            if ( ( selectionIndex != -1 ) && ( mustArray[i].equals( selectAttribute ) ) )
-            {
-                mandatoryAttributesTable.select( i );
-            }
-        }
+        mandatoryAttributesTableViewer.setInput( modifiedObjectClass.getMust() );
     }
 
 
@@ -955,27 +970,7 @@
      */
     private void fillInOptionalAttributesTable()
     {
-        int selectionIndex = optionalAttributesTable.getSelectionIndex();
-        String selectAttribute = null;
-        if ( selectionIndex != -1 )
-        {
-            selectAttribute = optionalAttributesTable.getItem( selectionIndex ).getText();
-        }
-        optionalAttributesTable.clearAll();
-        optionalAttributesTable.setItemCount( 0 );
-        String[] mayArray = modifiedObjectClass.getMay();
-        Arrays.sort( mayArray );
-        for ( int i = 0; i < mayArray.length; i++ )
-        {
-            TableItem item = new TableItem( optionalAttributesTable, SWT.NONE, i );
-            item.setImage( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
-                PluginConstants.IMG_ATTRIBUTE_TYPE ).createImage() );
-            item.setText( mayArray[i] );
-            if ( ( selectionIndex != -1 ) && ( mayArray[i].equals( selectAttribute ) ) )
-            {
-                optionalAttributesTable.select( i );
-            }
-        }
+        optionalAttributesTableViewer.setInput( modifiedObjectClass.getMay() );
     }
 
 

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/view/dialogs/messages.properties
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/view/dialogs/messages.properties?view=diff&rev=521343&r1=521342&r2=521343
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/view/dialogs/messages.properties (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/resources/org/apache/directory/ldapstudio/schemas/view/dialogs/messages.properties Thu Mar 22 09:58:14 2007
@@ -23,7 +23,7 @@
 # AttributeTypeSelectionDialog
 AttributeTypeSelectionDialog.Attribute_Type_Selection=Attribute Type Selection
 AttributeTypeSelectionDialog.Choose_an_attribute_type=Choose an attribute type:
-AttributeTypeSelectionDialog.Matching_attribute_types=Matching attribute types:
+AttributeTypeSelectionDialog.Matching_attribute_type(s)=Matching attribute type(s):
 AttributeTypeSelectionDialog.Add=Add
 AttributeTypeSelectionDialog.Invalid_Selection=Invalid Selection
 AttributeTypeSelectionDialog.You_have_to_choose_an_attribute_type=You have to choose an attribute type.
@@ -40,7 +40,7 @@
 # ObjectClassSelectionDialog
 ObjectClassSelectionDialog.Object_Class_Selection=Object Class Selection
 ObjectClassSelectionDialog.Choose_an_object_class=Choose an object class:
-ObjectClassSelectionDialog.Matching_object_classes=Matching object classes:
+ObjectClassSelectionDialog.Matching_object_class(es)=Matching object class(es):
 ObjectClassSelectionDialog.Add=Add
 ObjectClassSelectionDialog.Invalid_Selection=Invalid Selection
 ObjectClassSelectionDialog.You_have_to_choose_an_object_class=You have to choose an object class.



Mime
View raw message