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

svn commit: r552495 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: ./ controller/ view/dialogs/ view/wizards/

Author: pamarcelot
Date: Mon Jul  2 06:56:10 2007
New Revision: 552495

URL: http://svn.apache.org/viewvc?view=rev&rev=552495
Log:
Added :
	o AttributeSelectionDialog
	o EditAliasesDialog
Improved:
	o NewAttributeTypeWizard

Added:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialog.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialogContentProvider.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/EditAliasesDialog.java
Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeGeneralWizardPage.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeWizard.java

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java?view=auto&rev=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java Mon Jul  2 06:56:10 2007
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.schemaeditor;
+
+
+/**
+ * This class contains helper methods.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PluginUtils
+{
+    /**
+     * Verifies that the given name is syntaxely correct according to the RFC 2252 
+     * (Lightweight Directory Access Protocol (v3): Attribute Syntax Definitions).
+     *
+     * @param name
+     *      the name to test
+     * @return
+     *      true if the name is correct, false if the name is not correct.
+     */
+    public static boolean verifyName( String name )
+    {
+        return name.matches( "[a-zA-Z]+[a-zA-Z0-9;-]*" ); //$NON-NLS-1$
+    }
+}

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java?view=diff&rev=552495&r1=552494&r2=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java Mon Jul  2 06:56:10 2007
@@ -879,4 +879,27 @@
             listener.syntaxRemoved( syntax );
         }
     }
+
+
+    /**
+     * Verifies if the Alias is already taken by a schema object
+     *
+     * @param alias
+     *      the alias
+     * @return
+     *      true if the the alias is already taken
+     */
+    public boolean isAliasAlreadyTaken( String alias )
+    {
+        if ( attributeTypesMap.containsKey( alias ) )
+        {
+            return true;
+        }
+        else if ( objectClassesMap.containsKey( alias ) )
+        {
+            return true;
+        }
+        
+        return false;
+    }
 }

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialog.java?view=auto&rev=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialog.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialog.java Mon Jul  2 06:56:10 2007
@@ -0,0 +1,233 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.apacheds.schemaeditor.view.dialogs;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.LabelProvider;
+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.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class is Attribute Type Selection Dialog, that allows user to select an attribute type.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AttributeTypeSelectionDialog extends Dialog
+{
+    /** The selected attribute type */
+    private AttributeTypeImpl selectedAttributeType;
+
+    /** The hidden attribute types */
+    private List<AttributeTypeImpl> hiddenAttributeTypes;
+
+    // UI Fields
+    private Text searchText;
+    private Table attributeTypesTable;
+    private TableViewer attributeTypesTableViewer;
+
+
+    /**
+     * Creates a new instance of AttributeTypeSelectionDialog.
+     */
+    public AttributeTypeSelectionDialog()
+    {
+        super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
+        hiddenAttributeTypes = new ArrayList<AttributeTypeImpl>();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+     */
+    protected void configureShell( Shell newShell )
+    {
+        super.configureShell( newShell );
+        newShell.setText( "Attribute Type Selection" );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        Composite composite = new Composite( parent, SWT.NONE );
+        GridLayout layout = new GridLayout( 1, false );
+        composite.setLayout( layout );
+
+        Label chooseLabel = new Label( composite, SWT.NONE );
+        chooseLabel.setText( "Choose an attribute type" );
+        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 )
+            {
+                attributeTypesTableViewer.setInput( searchText.getText() );
+                attributeTypesTable.select( 0 );
+            }
+        } );
+        searchText.addKeyListener( new KeyAdapter()
+        {
+            public void keyPressed( KeyEvent e )
+            {
+                if ( e.keyCode == SWT.ARROW_DOWN )
+                {
+                    attributeTypesTable.setFocus();
+                }
+            }
+        } );
+
+        Label matchingLabel = new Label( composite, SWT.NONE );
+        matchingLabel.setText( "Matching attribute type(s)" );
+        matchingLabel.setLayoutData( new GridData( GridData.FILL, SWT.None, true, false ) );
+
+        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 = 148;
+        gridData.minimumHeight = 148;
+        gridData.widthHint = 350;
+        gridData.minimumWidth = 350;
+        attributeTypesTable.setLayoutData( gridData );
+        attributeTypesTable.addMouseListener( new MouseAdapter()
+        {
+            public void mouseDoubleClick( MouseEvent e )
+            {
+                if ( attributeTypesTable.getSelectionIndex() != -1 )
+                {
+                    okPressed();
+                }
+            }
+        } );
+
+        attributeTypesTableViewer = new TableViewer( attributeTypesTable );
+        attributeTypesTableViewer.setUseHashlookup( true );
+
+        attributeTypesTableViewer.setContentProvider( new AttributeTypeSelectionDialogContentProvider(
+            hiddenAttributeTypes ) );
+        attributeTypesTableViewer.setLabelProvider( new LabelProvider() );
+
+        // We need to force the input to load the complete list of attribute types
+        attributeTypesTableViewer.setInput( "" ); //$NON-NLS-1$
+        // We also need to force the selection of the first row
+        attributeTypesTable.select( 0 );
+
+        return composite;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+     */
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, "Add", true ); //$NON-NLS-1$
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+     */
+    protected void okPressed()
+    {
+        StructuredSelection selection = ( StructuredSelection ) attributeTypesTableViewer.getSelection();
+        if ( selection.isEmpty() )
+        {
+            MessageDialog.openError( getShell(), "Invalid Selection", "You have to choose an attribute type" );
+            return;
+        }
+        else
+        {
+            selectedAttributeType = ( AttributeTypeImpl ) selection.getFirstElement();
+        }
+
+        super.okPressed();
+    }
+
+
+    /**
+     * Returns the selected Attribute Type.
+     * 
+     * @return
+     *      the selected Attribute Type
+     */
+    public AttributeTypeImpl getSelectedAttributeType()
+    {
+        return selectedAttributeType;
+    }
+
+
+    /**
+     * Set the hidden Attribute Types.
+     *
+     * @param list
+     *      a list of Attribute Types to hide
+     */
+    public void setHiddenAttributeTypes( List<AttributeTypeImpl> list )
+    {
+        hiddenAttributeTypes = list;
+    }
+
+
+    /**
+     * Sets the hidden Attribute Types.
+     *
+     * @param attributeTypes
+     *      an array of Attribute Types to hide
+     */
+    public void setHiddenAttributeTypes( AttributeTypeImpl[] attributeTypes )
+    {
+        for ( AttributeTypeImpl objectClass : attributeTypes )
+        {
+            hiddenAttributeTypes.add( objectClass );
+        }
+    }
+}

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialogContentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialogContentProvider.java?view=auto&rev=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialogContentProvider.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/AttributeTypeSelectionDialogContentProvider.java Mon Jul  2 06:56:10 2007
@@ -0,0 +1,170 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.apacheds.schemaeditor.view.dialogs;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
+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 SchemaHandler schemaHandler;
+
+    /** The hidden Object Classes */
+    private List<AttributeTypeImpl> hiddenAttributeTypes;
+
+
+    /**
+     * Creates a new instance of AttributeTypeSelectionDialogContentProvider.
+     */
+    public AttributeTypeSelectionDialogContentProvider( List<AttributeTypeImpl> hiddenAttributeTypes )
+    {
+        this.hiddenAttributeTypes = hiddenAttributeTypes;
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+     */
+    public Object[] getElements( Object inputElement )
+    {
+        if ( inputElement instanceof String )
+        {
+            ArrayList<AttributeTypeImpl> results = new ArrayList<AttributeTypeImpl>();
+
+            String searchText = ( String ) inputElement;
+
+            String searchRegexp;
+            if ( searchText.length() == 0 )
+            {
+                searchRegexp = ".*"; //$NON-NLS-1$
+            }
+            else
+            {
+                searchRegexp = searchText + ".*"; //$NON-NLS-1$
+            }
+            Pattern pattern = Pattern.compile( searchRegexp, Pattern.CASE_INSENSITIVE );
+
+            List<AttributeTypeImpl> atList = schemaHandler.getAttributeTypes();
+
+            // Sorting the list
+            Collections.sort( atList, new Comparator<AttributeTypeImpl>()
+            {
+                public int compare( AttributeTypeImpl at1, AttributeTypeImpl at2 )
+                {
+                    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] );
+                    }
+                }
+            } );
+
+            // Searching for all matching elements
+            for ( AttributeTypeImpl at : atList )
+            {
+                for ( String name : at.getNames() )
+                {
+                    Matcher m = pattern.matcher( name );
+                    if ( m.matches() )
+                    {
+                        if ( !hiddenAttributeTypes.contains( at ) )
+                        {
+                            if ( !results.contains( at ) )
+                            {
+                                results.add( at );
+                            }
+                        }
+                        break;
+                    }
+                }
+                Matcher m = pattern.matcher( at.getOid() );
+                if ( m.matches() )
+                {
+                    if ( !hiddenAttributeTypes.contains( at ) )
+                    {
+                        if ( !results.contains( at ) )
+                        {
+                            results.add( at );
+                        }
+                    }
+                }
+            }
+
+            // Returns the results
+            return results.toArray();
+        }
+
+        // Default
+        return new Object[0];
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+     */
+    public void dispose()
+    {
+        // Nothing to do
+    }
+
+
+    /* (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 )
+    {
+        // Nothing to do
+    }
+}
\ No newline at end of file

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/EditAliasesDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/EditAliasesDialog.java?view=auto&rev=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/EditAliasesDialog.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/EditAliasesDialog.java Mon Jul  2 06:56:10 2007
@@ -0,0 +1,362 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.apacheds.schemaeditor.view.dialogs;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.PluginUtils;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+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.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class implements the Manage Aliases Dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EditAliasesDialog extends Dialog
+{
+    /** The aliases List */
+    private List<String> aliases;
+    private List<String> aliasesLowerCased;
+
+    /** The dirty flag */
+    private boolean dirty = false;
+
+    // UI Fields
+    private Table aliasesTable;
+    private Text newAliasText;
+    private Button newAliasAddButton;
+    private Composite errorComposite;
+    private Image errorImage;
+    private Label errorLabel;
+
+
+    /**
+     * Creates a new instance of EditAliasesDialog.
+     *
+     * @param aliases
+     *      the array containing the aliases
+     */
+    public EditAliasesDialog( String[] aliases )
+    {
+        super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
+        this.aliases = new ArrayList<String>();
+        aliasesLowerCased = new ArrayList<String>();
+        for ( String alias : aliases )
+        {
+            this.aliases.add( alias );
+            aliasesLowerCased.add( alias.toLowerCase() );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+     */
+    protected void configureShell( Shell newShell )
+    {
+        super.configureShell( newShell );
+        newShell.setText( "Edit Aliases" );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        Composite composite = new Composite( parent, SWT.NONE );
+        composite.setLayout( new GridLayout( 2, false ) );
+        composite.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
+
+        // ALIASES Label
+        Label aliases_label = new Label( composite, SWT.NONE );
+        aliases_label.setText( "Aliases" );
+        aliases_label.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, true, 2, 1 ) );
+
+        // ALIASES Table
+        aliasesTable = new Table( composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
+            | SWT.HIDE_SELECTION );
+        GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true, 2, 1 );
+        gridData.heightHint = 100;
+        gridData.minimumHeight = 100;
+        gridData.widthHint = 200;
+        gridData.minimumWidth = 200;
+        aliasesTable.setLayoutData( gridData );
+
+        // ADD Label
+        Label add_label = new Label( composite, SWT.NONE );
+        add_label.setText( "Add_an_alias" );
+        add_label.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, true, 2, 1 ) );
+
+        // NEW ALIAS Field
+        newAliasText = new Text( composite, SWT.BORDER );
+        newAliasText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+        // Add Button
+        newAliasAddButton = new Button( composite, SWT.PUSH );
+        newAliasAddButton.setText( "Add" );
+        newAliasAddButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) );
+        newAliasAddButton.setEnabled( false );
+
+        // Error Composite
+        errorComposite = new Composite( composite, SWT.NONE );
+        errorComposite.setLayout( new GridLayout( 2, false ) );
+        errorComposite.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true, 2, 1 ) );
+        errorComposite.setVisible( false );
+
+        // Error Image
+        errorImage = PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJS_ERROR_TSK );
+        Label label = new Label( errorComposite, SWT.NONE );
+        label.setImage( errorImage );
+        label.setSize( 16, 16 );
+
+        // Error Label
+        errorLabel = new Label( errorComposite, SWT.NONE );
+        errorLabel.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
+        errorLabel.setText( "An element with the same alias already exists." );
+
+        // Table initialization
+        fillAliasesTable();
+
+        // Listeners initialization
+        initListeners();
+
+        // Setting the focus to the text field
+        newAliasText.setFocus();
+
+        return composite;
+    }
+
+
+    /**
+     * Fills in the Aliases Table from the aliases list     */
+    private void fillAliasesTable()
+    {
+        aliasesTable.removeAll();
+        aliasesTable.setItemCount( 0 );
+        for ( String alias : aliases )
+        {
+            TableItem newItem = new TableItem( aliasesTable, SWT.NONE );
+            newItem.setText( alias );
+        }
+    }
+
+
+    /**
+     * Initializes the Listeners.
+     */
+    private void initListeners()
+    {
+        aliasesTable.addKeyListener( new KeyListener()
+        {
+            public void keyPressed( KeyEvent e )
+            {
+                if ( ( e.keyCode == SWT.DEL ) || ( e.keyCode == Action.findKeyCode( "BACKSPACE" ) ) ) { //$NON-NLS-1$
+                    // NOTE: I couldn't find the corresponding Identificator in the SWT.SWT Class,
+                    // so I Used JFace Action fineKeyCode method to get the Backspace keycode.
+
+                    removeAliases();
+                }
+            }
+
+
+            public void keyReleased( KeyEvent e )
+            {
+            }
+        } );
+
+        // Aliases Table's Popup Menu
+        Menu menu = new Menu( getShell(), SWT.POP_UP );
+        aliasesTable.setMenu( menu );
+        MenuItem deleteMenuItem = new MenuItem( menu, SWT.PUSH );
+        deleteMenuItem.setText( "Delete" );
+        deleteMenuItem.setImage( PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_TOOL_DELETE ) );
+        // Adding the listener
+        deleteMenuItem.addListener( SWT.Selection, new Listener()
+        {
+            public void handleEvent( Event event )
+            {
+                removeAliases();
+            }
+        } );
+
+        // NEW ALIAS Field
+        newAliasText.addTraverseListener( new TraverseListener()
+        {
+            public void keyTraversed( TraverseEvent e )
+            {
+                if ( e.detail == SWT.TRAVERSE_RETURN )
+                {
+                    String text = newAliasText.getText();
+
+                    if ( ( !"".equals( text ) ) && ( !aliasesLowerCased.contains( text.toLowerCase() ) ) //$NON-NLS-1$
+                        && ( !Activator.getDefault().getSchemaHandler().isAliasAlreadyTaken( text ) ) )
+                    {
+                        addANewAlias();
+                    }
+                }
+            }
+        } );
+
+        newAliasText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                errorComposite.setVisible( false );
+                newAliasAddButton.setEnabled( true );
+                String text = newAliasText.getText();
+
+                if ( "".equals( text ) ) //$NON-NLS-1$
+                {
+                    newAliasAddButton.setEnabled( false );
+                }
+                else if ( aliasesLowerCased.contains( text.toLowerCase() ) )
+                {
+                    errorComposite.setVisible( true );
+                    errorLabel.setText( "This alias already exists in the list." );
+                    newAliasAddButton.setEnabled( false );
+                }
+                else if ( Activator.getDefault().getSchemaHandler().isAliasAlreadyTaken( text ) )
+                {
+                    errorComposite.setVisible( true );
+                    errorLabel.setText( "An element with the same alias already exists." );
+                    newAliasAddButton.setEnabled( false );
+                }
+                else if ( !PluginUtils.verifyName( text ) )
+                {
+                    errorComposite.setVisible( true );
+                    errorLabel.setText( "Invalid_Alias." );
+                    newAliasAddButton.setEnabled( false );
+                }
+            }
+        } );
+
+        // ADD Button
+        newAliasAddButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                addANewAlias();
+            }
+        } );
+
+    }
+
+
+    /**
+     * Removes the selected aliases in the Aliases Table from the Aliases List.
+     */
+    private void removeAliases()
+    {
+        TableItem[] selectedItems = aliasesTable.getSelection();
+        for ( TableItem item : selectedItems )
+        {
+            aliases.remove( item.getText() );
+            aliasesLowerCased.remove( item.getText().toLowerCase() );
+        }
+        dirty = true;
+        fillAliasesTable();
+    }
+
+
+    /**
+     * Adds a new alias
+     */
+    private void addANewAlias()
+    {
+        if ( newAliasText.getText().length() != 0 )
+        {
+            aliases.add( newAliasText.getText() );
+            aliasesLowerCased.add( newAliasText.getText().toLowerCase() );
+            fillAliasesTable();
+            newAliasText.setText( "" ); //$NON-NLS-1$
+            newAliasText.setFocus();
+            this.dirty = true;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+     */
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    /**
+     * Returns the aliases.
+     *  
+     * @return
+     *      the aliases
+     */
+    public String[] getAliases()
+    {
+        return aliases.toArray( new String[0] );
+    }
+
+
+    /**
+     * Gets the Dirty flag of the dialog
+     *
+     * @return
+     *      the dirty flag of the dialog
+     */
+    public boolean isDirty()
+    {
+        return dirty;
+    }
+}

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java?view=diff&rev=552495&r1=552494&r2=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java Mon Jul  2 06:56:10 2007
@@ -20,13 +20,22 @@
 package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
 
 
+import org.apache.directory.shared.ldap.schema.UsageEnum;
 import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.AttributeTypeSelectionDialog;
+import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.ComboViewer;
 import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
@@ -50,6 +59,27 @@
  */
 public class NewAttributeTypeContentWizardPage extends WizardPage
 {
+    /** The SchemaHandler */
+    private SchemaHandler schemaHandler;
+
+    // The Usage values
+    private static final String DIRECTORY_OPERATION = "Directory Operation";
+    private static final String DISTRIBUTED_OPERATION = "Distributed Operation";
+    private static final String DSA_OPERATION = "DSA Operation";
+    private static final String USER_APPLICATIONS = "User Applications";
+
+    // UI Fields
+    private Text superiorText;
+    private Button superiorButton;
+    private ComboViewer usageComboViewer;
+    private ComboViewer syntaxComboViewer;
+    private Spinner lengthSpinner;
+    private Button obsoleteCheckbox;
+    private Button singleValueCheckbox;
+    private Button collectiveCheckbox;
+    private Button noUserModificationCheckbox;
+
+
     /**
      * Creates a new instance of NewAttributeTypeContentWizardPage.
      */
@@ -60,6 +90,7 @@
         setDescription( "Please enter the superior, usage, syntax and properties for the attribute type." );
         setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
             PluginConstants.IMG_ATTRIBUTE_TYPE_NEW_WIZARD ) );
+        schemaHandler = Activator.getDefault().getSchemaHandler();
     }
 
 
@@ -76,44 +107,66 @@
         Group superiorUsageGroup = new Group( composite, SWT.NONE );
         superiorUsageGroup.setText( "Superior and Usage" );
         superiorUsageGroup.setLayout( new GridLayout( 3, false ) );
-        superiorUsageGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false) );
-        
+        superiorUsageGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
         // Superior
         Label superiorLabel = new Label( superiorUsageGroup, SWT.NONE );
         superiorLabel.setText( "Superior:" );
-        Text superiorText = new Text( superiorUsageGroup, SWT.BORDER );
+        superiorText = new Text( superiorUsageGroup, SWT.BORDER );
         superiorText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
-        Button superiorButton = new Button( superiorUsageGroup, SWT.PUSH );
-        superiorButton.setText( "Choose" );
-        superiorButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false) );
+        superiorText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent arg0 )
+            {
+                verifySuperior();
+            }
+        } );
+        superiorButton = new Button( superiorUsageGroup, SWT.PUSH );
+        superiorButton.setText( "Choose..." );
+        superiorButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) );
+        superiorButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent arg0 )
+            {
+                AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog();
+                if ( dialog.open() == Dialog.OK )
+                {
+                    superiorText.setText( dialog.getSelectedAttributeType().getName() );
+                }
+            }
+        } );
 
         // Usage
         Label usageLabel = new Label( superiorUsageGroup, SWT.NONE );
         usageLabel.setText( "Usage:" );
         Combo usageCombo = new Combo( superiorUsageGroup, SWT.READ_ONLY );
         usageCombo.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false, 2, 1 ) );
-        ComboViewer usageComboViewer = new ComboViewer( usageCombo );
+        usageComboViewer = new ComboViewer( usageCombo );
         usageComboViewer.setLabelProvider( new LabelProvider() );
         usageComboViewer.setContentProvider( new ArrayContentProvider() );
         usageComboViewer.setInput( new String[]
-            { "Directory Operation", "Distributed Operation", "DSA Operation", "User Applications" } );
+            { DIRECTORY_OPERATION, DISTRIBUTED_OPERATION, DSA_OPERATION, USER_APPLICATIONS } );
+        usageComboViewer.setSelection( new StructuredSelection( USER_APPLICATIONS ) );
 
         // Syntax Group
         Group syntaxGroup = new Group( composite, SWT.NONE );
         syntaxGroup.setText( "Syntax" );
         syntaxGroup.setLayout( new GridLayout( 2, false ) );
-        syntaxGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false) );
-        
+        syntaxGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
         // Syntax
         Label syntaxLabel = new Label( syntaxGroup, SWT.NONE );
         syntaxLabel.setText( "Syntax:" );
         Combo syntaxCombo = new Combo( syntaxGroup, SWT.BORDER );
         syntaxCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        syntaxComboViewer = new ComboViewer( syntaxCombo );
+        syntaxComboViewer.setContentProvider( new ArrayContentProvider() );
+        syntaxComboViewer.setLabelProvider( new LabelProvider() );
 
         // Syntax Length
         Label lengthLabel = new Label( syntaxGroup, SWT.NONE );
         lengthLabel.setText( "Length:" );
-        Spinner lengthSpinner = new Spinner( syntaxGroup, SWT.BORDER );
+        lengthSpinner = new Spinner( syntaxGroup, SWT.BORDER );
         lengthSpinner.setIncrement( 1 );
         lengthSpinner.setMinimum( 0 );
         lengthSpinner.setMaximum( Integer.MAX_VALUE );
@@ -125,28 +178,189 @@
         Group propertiesGroup = new Group( composite, SWT.NONE );
         propertiesGroup.setText( "Properties" );
         propertiesGroup.setLayout( new GridLayout() );
-        propertiesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false) );
-        
+        propertiesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
         // Obsolete
         new Label( composite, SWT.NONE );
-        Button obsoleteCheckbox = new Button( propertiesGroup, SWT.CHECK );
+        obsoleteCheckbox = new Button( propertiesGroup, SWT.CHECK );
         obsoleteCheckbox.setText( "Obsolete" );
 
         // Single value
         new Label( composite, SWT.NONE );
-        Button singleValueCheckbox = new Button( propertiesGroup, SWT.CHECK );
+        singleValueCheckbox = new Button( propertiesGroup, SWT.CHECK );
         singleValueCheckbox.setText( "Single Value" );
 
         // Collective
         new Label( composite, SWT.NONE );
-        Button collectiveCheckbox = new Button( propertiesGroup, SWT.CHECK );
+        collectiveCheckbox = new Button( propertiesGroup, SWT.CHECK );
         collectiveCheckbox.setText( "Collective" );
 
         // No User Modification
         new Label( composite, SWT.NONE );
-        Button noUserModificationCheckbox = new Button( propertiesGroup, SWT.CHECK );
+        noUserModificationCheckbox = new Button( propertiesGroup, SWT.CHECK );
         noUserModificationCheckbox.setText( "No User Modification" );
 
         setControl( composite );
+    }
+
+
+    /**
+     * Verifies if the superior exists and displays an error if not.
+     */
+    private void verifySuperior()
+    {
+        if ( schemaHandler.getAttributeType( superiorText.getText() ) == null )
+        {
+            displayErrorMessage( "The superior attribute type does not exist." );
+            return;
+        }
+        
+        displayErrorMessage( null );
+    }
+
+
+    /**
+     * Displays an error message and set the page status as incomplete
+     * if the message is not null.
+     *
+     * @param message
+     *      the message to display
+     */
+    private void displayErrorMessage( String message )
+    {
+        setErrorMessage( message );
+        setPageComplete( message == null );
+    }
+
+
+    /**
+     * Gets the superior value.
+     *
+     * @return
+     *      the superior value
+     */
+    public String getSuperiorValue()
+    {
+        return superiorText.getText();
+    }
+
+
+    /**
+     * Gets the usage value.
+     *
+     * @return
+     *      the usage value
+     */
+    public UsageEnum getUsageValue()
+    {
+        StructuredSelection selection = ( StructuredSelection ) usageComboViewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            String selectedUsage = ( String ) selection.getFirstElement();
+            if ( selectedUsage.equals( DIRECTORY_OPERATION ) )
+            {
+                return UsageEnum.DIRECTORY_OPERATION;
+            }
+            else if ( selectedUsage.equals( DISTRIBUTED_OPERATION ) )
+            {
+                return UsageEnum.DISTRIBUTED_OPERATION;
+            }
+            else if ( selectedUsage.equals( DSA_OPERATION ) )
+            {
+                return UsageEnum.DSA_OPERATION;
+            }
+            else if ( selectedUsage.equals( USER_APPLICATIONS ) )
+            {
+                return UsageEnum.USER_APPLICATIONS;
+            }
+            else
+            {
+                return UsageEnum.USER_APPLICATIONS;
+            }
+        }
+        else
+        {
+            return UsageEnum.USER_APPLICATIONS;
+        }
+    }
+
+
+    /**
+     * Gets the syntax value.
+     *
+     * @return
+     *      the syntax value
+     */
+    public String getSyntax()
+    {
+        StructuredSelection selection = ( StructuredSelection ) syntaxComboViewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            return ( String ) selection.getFirstElement();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * Gets the syntax length value.
+     *
+     * @return
+     *      the syntax length value
+     */
+    public int getSyntaxLengthValue()
+    {
+        return lengthSpinner.getSelection();
+    }
+
+
+    /**
+     * Gets the 'Obsolete' value.
+     *
+     * @return
+     *      the 'Obsolete' value
+     */
+    public boolean getObsoleteValue()
+    {
+        return obsoleteCheckbox.getSelection();
+    }
+
+
+    /**
+     * Gets the 'Single Value' value
+     *
+     * @return
+     *      the 'Single Value' value
+     */
+    public boolean getSingleValueValue()
+    {
+        return singleValueCheckbox.getSelection();
+    }
+
+
+    /**
+     * Gets the 'Collective' value.
+     *
+     * @return
+     *      the 'Collective' value
+     */
+    public boolean getCollectiveValue()
+    {
+        return collectiveCheckbox.getSelection();
+    }
+
+
+    /**
+     * Gets the 'No User Modification' value.
+     *
+     * @return
+     *      the 'No User Modification' value
+     */
+    public boolean getNoUserModificationValue()
+    {
+        return noUserModificationCheckbox.getSelection();
     }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeGeneralWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeGeneralWizardPage.java?view=diff&rev=552495&r1=552494&r2=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeGeneralWizardPage.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeGeneralWizardPage.java Mon Jul  2 06:56:10 2007
@@ -20,13 +20,26 @@
 package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
 
 
+import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.EditAliasesDialog;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.DialogPage;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
@@ -49,6 +62,20 @@
  */
 public class NewAttributeTypeGeneralWizardPage extends WizardPage
 {
+    /** The SchemaHandler */
+    private SchemaHandler schemaHandler;
+
+    /** The aliases */
+    private String[] aliases;
+
+    // UI fields
+    private ComboViewer schemaComboViewer;
+    private Text oidText;
+    private Text aliasesText;
+    private Button aliasesButton;
+    private Text descriptionText;
+
+
     /**
      * Creates a new instance of NewAttributeTypeGeneralWizardPage.
      */
@@ -59,6 +86,9 @@
         setDescription( "Create a new attribute type." );
         setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
             PluginConstants.IMG_ATTRIBUTE_TYPE_NEW_WIZARD ) );
+
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+        aliases = new String[0];
     }
 
 
@@ -82,9 +112,34 @@
         schemaLabel.setText( "Schema:" );
         Combo schemaCombo = new Combo( schemaGroup, SWT.READ_ONLY );
         schemaCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
-        ComboViewer schemaComboViewer = new ComboViewer( schemaCombo );
-        schemaComboViewer.setLabelProvider( new LabelProvider() );
+        schemaComboViewer = new ComboViewer( schemaCombo );
         schemaComboViewer.setContentProvider( new ArrayContentProvider() );
+        schemaComboViewer.setLabelProvider( new LabelProvider()
+        {
+            /* (non-Javadoc)
+             * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+             */
+            public String getText( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return ( ( Schema ) element ).getName();
+                }
+
+                // Default
+                return super.getText( element );
+            }
+        } );
+        schemaComboViewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            /* (non-Javadoc)
+             * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+             */
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                dialogChanged();
+            }
+        } );
 
         // Naming and Description Group
         Group namingDescriptionGroup = new Group( composite, SWT.NONE );
@@ -95,26 +150,214 @@
         // OID
         Label oidLabel = new Label( namingDescriptionGroup, SWT.NONE );
         oidLabel.setText( "OID:" );
-        Text oidText = new Text( namingDescriptionGroup, SWT.BORDER );
+        oidText = new Text( namingDescriptionGroup, SWT.BORDER );
         oidText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+        oidText.addModifyListener( new ModifyListener()
+        {
+            /* (non-Javadoc)
+             * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+             */
+            public void modifyText( ModifyEvent arg0 )
+            {
+                dialogChanged();
+            }
+        } );
 
         // Aliases
         Label aliasesLabel = new Label( namingDescriptionGroup, SWT.NONE );
         aliasesLabel.setText( "Aliases:" );
-        Text aliasesText = new Text( namingDescriptionGroup, SWT.BORDER );
+        aliasesText = new Text( namingDescriptionGroup, SWT.BORDER );
         aliasesText.setEnabled( false );
         aliasesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
-        Button aliasesButton = new Button( namingDescriptionGroup, SWT.PUSH );
-        aliasesButton.setText( "Edit" );
+        aliasesButton = new Button( namingDescriptionGroup, SWT.PUSH );
+        aliasesButton.setText( "Edit..." );
+        aliasesButton.addSelectionListener( new SelectionAdapter()
+        {
+            /* (non-Javadoc)
+             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+             */
+            public void widgetSelected( SelectionEvent arg0 )
+            {
+                EditAliasesDialog dialog = new EditAliasesDialog( aliases );
+
+                if ( ( dialog.open() == Dialog.OK ) && ( dialog.isDirty() ) )
+                {
+                    aliases = dialog.getAliases();
+                    fillInAliasesLabel();
+                    dialogChanged();
+                }
+            }
+        } );
 
         // Description
         Label descriptionLabel = new Label( namingDescriptionGroup, SWT.NONE );
         descriptionLabel.setText( "Description:" );
-        Text descriptionText = new Text( namingDescriptionGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL );
+        descriptionText = new Text( namingDescriptionGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL );
         GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 );
         descriptionGridData.heightHint = 67;
         descriptionText.setLayoutData( descriptionGridData );
+        descriptionText.addModifyListener( new ModifyListener()
+        {
+            /* (non-Javadoc)
+             * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+             */
+            public void modifyText( ModifyEvent arg0 )
+            {
+                dialogChanged();
+            }
+        } );
+
+        initFields();
 
         setControl( composite );
+
+        displayErrorMessage( null );
+        setPageComplete( false );
+    }
+
+
+    /**
+     * Initializes the UI fields.
+     */
+    private void initFields()
+    {
+        schemaComboViewer.setInput( schemaHandler.getSchemas() );
+    }
+
+
+    /**
+     * This method is called when the user modifies something in the UI.
+     */
+    private void dialogChanged()
+    {
+        if ( schemaComboViewer.getSelection().isEmpty() )
+        {
+            displayErrorMessage( "A Schema must be specified." );
+            return;
+        }
+        else if ( oidText.getText().equals( "" ) )
+        {
+            displayErrorMessage( "An OID must be specified." );
+            return;
+        }
+        else if ( ( !oidText.getText().equals( "" ) ) && ( !OID.isOID( oidText.getText() ) ) )
+        {
+            displayErrorMessage( "Incorrect OID." );
+            return;
+        }
+        else if ( aliases.length == 0 )
+        {
+            displayWarningMessage( "The attribute type does not have any name. It is recommanded to add at least one name." );
+            return;
+        }
+
+        displayErrorMessage( null );
+    }
+
+
+    /**
+     * Displays an error message and set the page status as incomplete
+     * if the message is not null.
+     *
+     * @param message
+     *      the message to display
+     */
+    private void displayErrorMessage( String message )
+    {
+        setMessage( null, DialogPage.WARNING );
+        setErrorMessage( message );
+        setPageComplete( message == null );
+    }
+
+
+    /**
+     * Displays a warning message and set the page status as complete.
+     *
+     * @param message
+     *      the message to display
+     */
+    private void displayWarningMessage( String message )
+    {
+        setErrorMessage( null );
+        setMessage( message, DialogPage.WARNING );
+        setPageComplete( true );
+    }
+
+
+    /**
+     * Fills in the Aliases Label.
+     */
+    private void fillInAliasesLabel()
+    {
+        StringBuffer sb = new StringBuffer();
+        if ( aliases.length != 0 )
+        {
+            for ( String name : aliases )
+            {
+                sb.append( name );
+                sb.append( ", " );
+            }
+            sb.deleteCharAt( sb.length() - 1 );
+            sb.deleteCharAt( sb.length() - 1 );
+        }
+        aliasesText.setText( sb.toString() );
+    }
+
+
+    /**
+     * Get the name of the schema.
+     *
+     * @return
+     *      the name of the schema
+     */
+    public String getSchemaValue()
+    {
+        StructuredSelection selection = ( StructuredSelection ) schemaComboViewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            Schema schema = ( Schema ) selection.getFirstElement();
+
+            return schema.getName();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * Gets the value of the OID.
+     *
+     * @return
+     *      the value of the OID
+     */
+    public String getOidValue()
+    {
+        return oidText.getText();
+    }
+
+
+    /**
+     * Gets the value of the aliases.
+     *
+     * @return
+     *      the value of the aliases
+     */
+    public String[] getAliasesValue()
+    {
+        return aliases;
+    }
+
+
+    /**
+     * Gets the value of the description.
+     *
+     * @return
+     *      the value of the description
+     */
+    public String getDescriptionValue()
+    {
+        return descriptionText.getText();
     }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java?view=diff&rev=552495&r1=552494&r2=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java Mon Jul  2 06:56:10 2007
@@ -22,6 +22,9 @@
 
 import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
@@ -44,6 +47,12 @@
  */
 public class NewAttributeTypeMatchingRulesWizardPage extends WizardPage
 {
+    // UI fields
+    private ComboViewer equalityComboViewer;
+    private ComboViewer orderingComboViewer;
+    private ComboViewer substringComboViewer;
+
+
     /**
      * Creates a new instance of NewAttributeTypeMatchingRulesWizardPage.
      */
@@ -74,22 +83,67 @@
 
         // Equality
         Label equalityLabel = new Label( matchingRulesGroup, SWT.NONE );
-        equalityLabel.setText( "Equality" );
+        equalityLabel.setText( "Equality:" );
         Combo equalityCombo = new Combo( matchingRulesGroup, SWT.NONE );
         equalityCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        equalityComboViewer = new ComboViewer( equalityCombo );
+        equalityComboViewer.setContentProvider( new ArrayContentProvider() );
+        equalityComboViewer.setLabelProvider( new LabelProvider() );
 
         // Ordering
         Label orderingLabel = new Label( matchingRulesGroup, SWT.NONE );
-        orderingLabel.setText( "Ordering" );
+        orderingLabel.setText( "Ordering:" );
         Combo orderingCombo = new Combo( matchingRulesGroup, SWT.NONE );
         orderingCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        orderingComboViewer = new ComboViewer( orderingCombo );
+        orderingComboViewer.setContentProvider( new ArrayContentProvider() );
+        orderingComboViewer.setLabelProvider( new LabelProvider() );
 
         // Substring
         Label substringLabel = new Label( matchingRulesGroup, SWT.NONE );
-        substringLabel.setText( "Substring" );
+        substringLabel.setText( "Substring:" );
         Combo substringCombo = new Combo( matchingRulesGroup, SWT.NONE );
         substringCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        substringComboViewer = new ComboViewer( substringCombo );
+        substringComboViewer.setContentProvider( new ArrayContentProvider() );
+        substringComboViewer.setLabelProvider( new LabelProvider() );
 
         setControl( composite );
+    }
+
+
+    /**
+     * Gets the value of the equality matching rule.
+     *
+     * @return
+     *      the value of the equality matching rule
+     */
+    public String getEqualityMatchingRuleValue()
+    {
+        return null; // TODO: implement
+    }
+
+
+    /**
+     * Gets the value of the ordering matching rule.
+     *
+     * @return
+     *      the value of the ordering matching rule
+     */
+    public String getOrderingMatchingRuleValue()
+    {
+        return null; // TODO: implement
+    }
+
+
+    /**
+     * Gets the value of the substring matching rule.
+     *
+     * @return
+     *      the value of the substring matching rule
+     */
+    public String getSubstringMatchingRuleValue()
+    {
+        return null; // TODO: implement
     }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeWizard.java?view=diff&rev=552495&r1=552494&r2=552495
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeWizard.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeWizard.java Mon Jul  2 06:56:10 2007
@@ -20,9 +20,10 @@
 package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
 
 
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 
@@ -36,9 +37,9 @@
 public class NewAttributeTypeWizard extends Wizard implements INewWizard
 {
     // The pages of the wizards
-    private WizardPage generalPage;
-    private WizardPage contentPage;
-    private WizardPage matchingRulesPage;
+    private NewAttributeTypeGeneralWizardPage generalPage;
+    private NewAttributeTypeContentWizardPage contentPage;
+    private NewAttributeTypeMatchingRulesWizardPage matchingRulesPage;
 
 
     /* (non-Javadoc)
@@ -63,10 +64,27 @@
      */
     public boolean performFinish()
     {
-        // TODO Auto-generated method stub
-        return false;
+        AttributeTypeImpl newAT = new AttributeTypeImpl( generalPage.getOidValue() );
+        newAT.setSchema( generalPage.getSchemaValue() );
+        newAT.setNames( generalPage.getAliasesValue() );
+        newAT.setDescription( generalPage.getDescriptionValue() );
+        newAT.setSuperiorName( contentPage.getSuperiorValue() );
+        newAT.setUsage( contentPage.getUsageValue() );
+        newAT.setSyntaxOid( contentPage.getSyntax() );
+        newAT.setLength( contentPage.getSyntaxLengthValue() );
+        newAT.setObsolete( contentPage.getObsoleteValue() );
+        newAT.setSingleValue( contentPage.getSingleValueValue() );
+        newAT.setCollective( contentPage.getCollectiveValue() );
+        newAT.setCanUserModify( contentPage.getNoUserModificationValue() );
+        newAT.setEqualityName( matchingRulesPage.getEqualityMatchingRuleValue() );
+        newAT.setOrderingName( matchingRulesPage.getOrderingMatchingRuleValue() );
+        newAT.setSubstrName( matchingRulesPage.getSubstringMatchingRuleValue() );
+        
+        Activator.getDefault().getSchemaHandler().addAttributeType( newAT );
+        
+        return true;
     }
-
+    
 
     /* (non-Javadoc)
      * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)