directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1694767 - in /directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl: dialogs/AclAttributeDialog.java model/AclAttribute.java model/AclAttributeWrapper.java
Date Sat, 08 Aug 2015 05:58:08 GMT
Author: elecharny
Date: Sat Aug  8 05:58:07 2015
New Revision: 1694767

URL: http://svn.apache.org/r1694767
Log:
Added the AclAttribute classes used by the TableWidget

Added:
    directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/dialogs/AclAttributeDialog.java
Modified:
    directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttribute.java
    directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeWrapper.java

Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/dialogs/AclAttributeDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/dialogs/AclAttributeDialog.java?rev=1694767&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/dialogs/AclAttributeDialog.java
(added)
+++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/dialogs/AclAttributeDialog.java
Sat Aug  8 05:58:07 2015
@@ -0,0 +1,427 @@
+package org.apache.directory.studio.openldap.config.acl.dialogs;
+
+import org.apache.directory.api.ldap.model.schema.SchemaUtils;
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.studio.common.ui.AddEditDialog;
+import org.apache.directory.studio.common.ui.CommonUIConstants;
+import org.apache.directory.studio.common.ui.CommonUIUtils;
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.openldap.config.acl.model.AclAttribute;
+import org.apache.directory.studio.openldap.config.acl.model.AclAttributeWrapper;
+import org.eclipse.jface.dialogs.IDialogConstants;
+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.events.SelectionListener;
+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.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * This Dialog is used to add a new AclAttribute. 
+ * 
+ * <pre>
+ * +---------------------------------------------+
+ * | ACL Attribute                               |
+ * | .-----------------------------------------. |
+ * | | (o) Attribute                           | |
+ * | | (o) Entry                               | |
+ * | | (o) Children                            | |
+ * | | (o) ObjectClass                         | |
+ * | | (o) ObjectClass exclusion               | |
+ * | |                                         | |
+ * | | Value : [/////////////////////////////] | |
+ * | '-----------------------------------------' |
+ * |                                             |
+ * |  (Cancel)                             (OK)  |
+ * +---------------------------------------------+
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AclAttributeDialog extends AddEditDialog<AclAttributeWrapper>
+{
+    /** The connection to the LDAP server */
+    private Connection connection;
+    
+    // The UI widgets
+    /** The Attribute checkbox */
+    private Button attributeCheckbox; 
+    
+    /** The entry checkbox */
+    private Button entryCheckbox;
+    
+    /** The children checkbox */
+    private Button childrenCheckbox;
+    
+    /** The OjectClass checkbox */
+    private Button objectClassCheckbox;
+    
+    /** The OjectClass Exclusioncheckbox */
+    private Button objectClassExclusionCheckbox;
+
+    /** The Attribute Value text */
+    private Text attributevalueText;
+    
+    /** A flag set when we clear the AttributeValue text */
+    private boolean clearText;
+    
+
+    /** A listener for the AttributeCheckBox */
+    private SelectionListener attributeCheckboxListener = new SelectionAdapter()
+    {
+        @Override
+        public void widgetSelected( SelectionEvent e )
+        {
+            Button selection = (Button)e.getSource();
+            
+            if ( selection.getSelection() )
+            {
+                // Clear the AttributeValue Text and disable it
+                clearText = true;
+                attributevalueText.setText( "" );
+                attributevalueText.setEnabled( true );
+                getButton( IDialogConstants.OK_ID ).setEnabled( false );
+            }
+        }
+    };
+
+    /** A listener for the EntryCheckBox */
+    private SelectionListener entryCheckboxListener = new SelectionAdapter()
+    {
+        @Override
+        public void widgetSelected( SelectionEvent e )
+        {
+            Button selection = (Button)e.getSource();
+            
+            if ( selection.getSelection() )
+            {
+                // Clear the AttributeValue Text and disable it
+                clearText = true;
+                attributevalueText.setText( "" );
+                attributevalueText.setEnabled( false );
+                getEditedElement().getAclAttribute().setName( "entry" );
+                getButton( IDialogConstants.OK_ID ).setEnabled( true );
+            }
+        }
+    };
+
+    /** A listener for the ChildrenCheckBox */
+    private SelectionListener childrenCheckboxListener = new SelectionAdapter()
+    {
+        @Override
+        public void widgetSelected( SelectionEvent e )
+        {
+            Button selection = (Button)e.getSource();
+            
+            if ( selection.getSelection() )
+            {
+                // Clear the AttributeValue Text and disable it
+                clearText = true;
+                attributevalueText.setText( "" );
+                attributevalueText.setEnabled( false );
+                getEditedElement().getAclAttribute().setName( "children" );
+                getButton( IDialogConstants.OK_ID ).setEnabled( true );
+            }
+        }
+    };
+
+    /** A listener for the ObjectClassCheckBox */
+    private SelectionListener objectClassCheckboxListener = new SelectionAdapter()
+    {
+        @Override
+        public void widgetSelected( SelectionEvent e )
+        {
+            Button selection = (Button)e.getSource();
+            
+            if ( selection.getSelection() )
+            {
+                // Clear the AttributeValue Text and enable it
+                clearText = true;
+                attributevalueText.setText( "" );
+                attributevalueText.setEnabled( true );
+                getButton( IDialogConstants.OK_ID ).setEnabled( false );
+            }
+        }
+    };
+
+    /** A listener for the ObjectClassExclusionCheckBox */
+    private SelectionListener objectClassExclusionCheckboxListener = new SelectionAdapter()
+    {
+        @Override
+        public void widgetSelected( SelectionEvent e )
+        {
+            Button selection = (Button)e.getSource();
+            
+            if ( selection.getSelection() )
+            {
+                // Clear the AttributeValue Text and enable it
+                clearText = true;
+                attributevalueText.setText( "" );
+                attributevalueText.setEnabled( true );
+                getButton( IDialogConstants.OK_ID ).setEnabled( false );
+            }
+        }
+    };
+    
+    /** A listener for the AttributeValuetext */
+    private ModifyListener attributeValueTextListener = new ModifyListener()
+    {
+        @Override
+        public void modifyText( ModifyEvent e )
+        {
+            // if the text has been clear by a button, don't do anything but switch the flag
+            if ( clearText )
+            {
+                clearText = false;
+                return;
+            }
+            
+            Button okButton = getButton( IDialogConstants.OK_ID );
+            
+            // This button might be null when the dialog is called.
+            if ( okButton == null )
+            {
+                return;
+            }
+
+            String attributeValue = attributevalueText.getText();
+            boolean isAttribute = attributeCheckbox.getSelection();
+            boolean isObjectClass = objectClassCheckbox.getSelection();
+            boolean isObjectExclusionClass = objectClassExclusionCheckbox.getSelection();
+            boolean isEntry = entryCheckbox.getSelection();
+            boolean isChildren = childrenCheckbox.getSelection();
+            
+            // Check that is a valid name, if needed
+            if ( isAttribute || isObjectClass || isObjectExclusionClass )
+            {
+                if ( Strings.isEmpty( attributeValue ) )
+                {
+                    okButton.setEnabled( false );
+                    return;
+                }
+                
+                if ( !SchemaUtils.isAttributeNameValid( attributeValue) )
+                {
+                    okButton.setEnabled( false );
+                    return;
+                }
+            }
+            
+            // Handle the various use cases
+            String result;
+            
+            if ( isAttribute )
+            {
+                // This is an attribute
+                result = attributeValue;
+            }
+            else if ( isEntry )
+            {
+                // This is the special attribute value Entry
+                result = AclAttribute.ENTRY;
+            }
+            else if ( isChildren )
+            {
+                // This is the special attribute value Children
+                result = AclAttribute.CHILDREN;
+            }
+            else if ( isObjectClass )
+            {
+                // This is an ObjectClass
+                StringBuilder buffer = new StringBuilder();
+                buffer.append( AclAttribute.OC ).append( attributeValue );
+                
+                result = buffer.toString();
+            }
+            else
+            {
+                // This is an ObjectClass exclusion
+                StringBuilder buffer = new StringBuilder( AclAttribute.OC_EX );
+                buffer.append( AclAttribute.OC_EX ).append( attributeValue );
+                
+                result = buffer.toString();
+            }
+
+            getEditedElement().setAclAttribute( result );
+            
+            // Check that the element does not already exist
+            if ( getElements().contains( getEditedElement() ) )
+            {
+                attributevalueText.setForeground( CommonUIConstants.RED_COLOR );
+                okButton.setEnabled( false );
+            }
+            else
+            {
+                attributevalueText.setForeground( CommonUIConstants.BLACK_COLOR );
+                okButton.setEnabled( true );
+            }
+        }
+    };
+    
+    
+    /**
+     * Creates a new instance of AclAttributeDialog.
+     * 
+     * @param shell the parent shell
+     */
+    public AclAttributeDialog( Shell shell, Connection connection )
+    {
+        super( shell );
+        //shell.setText( Messages.getString( "AclAttribute.Title" ) );
+        this.connection = connection;
+    }
+    
+    
+    /**
+     * Create the Dialog for AclAttribute :
+     * <pre>
+     * +---------------------------------------------+
+     * | ACL Attribute                               |
+     * | .-----------------------------------------. |
+     * | | (o) Attribute                           | |
+     * | | (o) entry                               | |
+     * | | (o) children                            | |
+     * | | (o) ObjectClass                         | |
+     * | | (o) ObjectClass exclusion               | |
+     * | |                                         | |
+     * | | Value : [/////////////////////////////] | |
+     * | '-----------------------------------------' |
+     * |                                             |
+     * |  (Cancel)                             (OK)  |
+     * +---------------------------------------------+
+     * </pre>
+     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        composite.setLayoutData( gd );
+        
+        createAclAttributeEditGroup( composite );
+        initDialog();
+        
+        applyDialogFont( composite );
+        
+        return composite;
+    }
+
+
+    /**
+     * Creates the AclAttribute input group.
+     * 
+     * <pre>
+     * ACL Attribute
+     * .-----------------------------------------.
+     * | (o) Attribute                           |
+     * | (o) entry                               |
+     * | (o) children                            |
+     * | (o) ObjectClass                         |
+     * | (o) ObjectClass exclusion               |
+     * |                                         |
+     * | Value : [/////////////////////////////] |
+     * '-----------------------------------------'
+     * </pre>
+     * @param parent the parent composite
+     */
+    private void createAclAttributeEditGroup( Composite parent )
+    {
+        // Disallow Feature Group
+        Group aclAttributeGroup = BaseWidgetUtils.createGroup( parent, "", 1 );
+        GridLayout aclAttributeGridLayout = new GridLayout( 2, false );
+        aclAttributeGroup.setLayout( aclAttributeGridLayout );
+        aclAttributeGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false )
);
+
+        // The Attribute checkbox
+        attributeCheckbox = BaseWidgetUtils.createRadiobutton( aclAttributeGroup, "Attribute",
2 );
+        attributeCheckbox.addSelectionListener( attributeCheckboxListener );
+        
+        // The entry checkbox
+        entryCheckbox = BaseWidgetUtils.createRadiobutton( aclAttributeGroup, "Entry", 2
);
+        entryCheckbox.addSelectionListener( entryCheckboxListener );
+        
+        // The children checkbox
+        childrenCheckbox = BaseWidgetUtils.createRadiobutton( aclAttributeGroup, "Children",
2 );
+        childrenCheckbox.addSelectionListener( childrenCheckboxListener );
+        
+        // The OjectClass checkbox
+        objectClassCheckbox = BaseWidgetUtils.createRadiobutton( aclAttributeGroup, "ObjectClass",
2 );
+        objectClassCheckbox.addSelectionListener( objectClassCheckboxListener );
+        
+        // The OjectClass Exclusioncheckbox
+        objectClassExclusionCheckbox = BaseWidgetUtils.createRadiobutton( aclAttributeGroup,
"ObjectClass Exclusion", 2 );
+        objectClassExclusionCheckbox.addSelectionListener( objectClassExclusionCheckboxListener
);
+        
+        // The Value Text
+        BaseWidgetUtils.createLabel( aclAttributeGroup, "Value : ", 1 );
+        attributevalueText = BaseWidgetUtils.createText( aclAttributeGroup, "", 1 );
+        attributevalueText.addModifyListener( attributeValueTextListener );
+    }
+
+    
+    @Override
+    protected void initDialog()
+    {
+        AclAttributeWrapper editedElement = (AclAttributeWrapper)getEditedElement();
+        
+        if ( editedElement != null )
+        {
+            AclAttribute aclAttribute =  editedElement.getAclAttribute();
+            
+            if ( aclAttribute.isEntry() )
+            {
+                entryCheckbox.setEnabled( true );
+            }
+            else if ( aclAttribute.isChildren() )
+            {
+                childrenCheckbox.setEnabled( true );
+            }
+            else if ( aclAttribute.isAttributeType() )
+            {
+                attributeCheckbox.setEnabled( true );
+                attributevalueText.setText( CommonUIUtils.getTextValue( aclAttribute.getName()
) );
+            }
+            else if ( aclAttribute.isObjectClass() )
+            {
+                objectClassCheckbox.setEnabled( true );
+                attributevalueText.setText( CommonUIUtils.getTextValue( aclAttribute.getName()
) );
+            }
+            else
+            {
+                objectClassExclusionCheckbox.setEnabled( true );
+                attributevalueText.setText( CommonUIUtils.getTextValue( aclAttribute.getName()
) );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void addNewElement()
+    {
+        // Default to none
+        setEditedElement( new AclAttributeWrapper( new AclAttribute( "", connection ) ) );
+    }
+
+    
+    /**
+     * Add an Element that will be edited
+     * 
+     * @param editedElement The element to edit
+     */
+    public void addNewElement( AclAttributeWrapper editedElement )
+    {
+        AclAttributeWrapper newElement = (AclAttributeWrapper)editedElement.clone();
+        setEditedElement( newElement );
+    }
+}

Modified: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttribute.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttribute.java?rev=1694767&r1=1694766&r2=1694767&view=diff
==============================================================================
--- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttribute.java
(original)
+++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttribute.java
Sat Aug  8 05:58:07 2015
@@ -35,6 +35,21 @@ import org.apache.directory.studio.openl
  */
 public class AclAttribute
 {
+    /** The special "entry" constant */
+    public static final String ENTRY = "entry";
+    
+    /** The special "children" constant */
+    public static final String CHILDREN = "children";
+    
+    /** The special ExtensibleObject constant*/
+    public static final String EXTENSIBLE_OBJECT = "extensibleObject";
+    
+    /** The prefix for ObjectClass */
+    public static final char OC = '@';
+    
+    /** The prefix for ObjectClass exclusion */
+    public static final char OC_EX = '!';
+    
     /** The AttributeType, if we know about it */
     private AttributeType attributeType;
     
@@ -59,6 +74,21 @@ public class AclAttribute
     /** A flag set when we stored the special 'children' attribute */
     private boolean isChildren = false;
     
+    /** The Connection to the LDAP server */
+    private Connection connection;
+    
+    /**
+     * Create a new AclAttribute with no name
+     * 
+     * @param connection The Connection on the LDAP Server 
+     */
+    public AclAttribute( Connection connection )
+    {
+        this.connection = connection;
+        setName( "" );
+    }
+    
+    
     /**
      * Create a new AclAttribute with specific name
      * 
@@ -66,25 +96,68 @@ public class AclAttribute
      */
     public AclAttribute( String name, Connection connection )
     {
-        if ( !Strings.isEmpty( name ) )
+        this.connection = connection;
+        setName( name );
+    }
+    
+
+    /**
+     * @return the attributeType
+     */
+    public AttributeType getAttributeType()
+    {
+        return attributeType;
+    }
+
+    
+    /**
+     * @return the objectClass
+     */
+    public ObjectClass getObjectClass()
+    {
+        return objectClass;
+    }
+
+    
+    /**
+     * @return the name
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    
+    /**
+     * @param name the name to set
+     */
+    public void setName( String name )
+    {
+        if ( Strings.isEmpty( name ) )
         {
-            if ( Strings.isCharASCII( name, 0, '!' ) )
+            //The default is externalObject ObjectClass
+            isObjectClass = true;
+            this.name = EXTENSIBLE_OBJECT;
+        }
+        else
+        {
+            if ( Strings.isCharASCII( name, 0, OC ) )
             {
                 isObjectClass = true;
                 this.name = name.substring( 1 );
             }
-            else if ( Strings.isCharASCII( name, 0, '@' ) )
+            else if ( Strings.isCharASCII( name, 0, OC_EX ) )
             {
                 isObjectClassNotAllowed = true;
                 this.name = name.substring( 1 );
             }
             else
             {
-                if ( "entry".equalsIgnoreCase( name ) )
+                if ( ENTRY.equalsIgnoreCase( name ) )
                 {
                     isEntry = true;
                 }
-                else if ( "children".equalsIgnoreCase( name ) )
+                else if ( CHILDREN.equalsIgnoreCase( name ) )
                 {
                     isChildren = true;
                 }
@@ -123,35 +196,8 @@ public class AclAttribute
             }
         }
     }
-    
-
-    /**
-     * @return the attributeType
-     */
-    public AttributeType getAttributeType()
-    {
-        return attributeType;
-    }
-
-    
-    /**
-     * @return the objectClass
-     */
-    public ObjectClass getObjectClass()
-    {
-        return objectClass;
-    }
 
-    
-    /**
-     * @return the name
-     */
-    public String getName()
-    {
-        return name;
-    }
 
-    
     /**
      * @return the isAttributeType
      */
@@ -169,7 +215,7 @@ public class AclAttribute
         return isObjectClass;
     }
 
-    
+
     /**
      * @return the isEntry
      */
@@ -178,7 +224,7 @@ public class AclAttribute
         return isEntry;
     }
 
-    
+
     /**
      * @return the isChildren
      */
@@ -211,11 +257,11 @@ public class AclAttribute
         
         if ( isObjectClass )
         {
-            buffer.append( '@' );
+            buffer.append( OC );
         }
         else
         {
-            buffer.append( '!' );
+            buffer.append( OC_EX );
         }
         
         buffer.append( name );

Modified: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeWrapper.java?rev=1694767&r1=1694766&r2=1694767&view=diff
==============================================================================
--- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeWrapper.java
(original)
+++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeWrapper.java
Sat Aug  8 05:58:07 2015
@@ -1,7 +1,5 @@
 package org.apache.directory.studio.openldap.config.acl.model;
 
-import org.apache.directory.api.util.Strings;
-
 public class AclAttributeWrapper implements Cloneable, Comparable<AclAttributeWrapper>
 {
     /** The AclAttribute */
@@ -9,6 +7,16 @@ public class AclAttributeWrapper impleme
     
     /**
      * Creates a new instance of AclAttributeWrapper.
+     */
+    public AclAttributeWrapper()
+    {
+        // Default to ExtensibleObject
+        aclAttribute = new AclAttribute( "extensibleObject", null );
+    }
+    
+    
+    /**
+     * Creates a new instance of AclAttributeWrapper.
      *
      * @param aclAttribute the aclAttribute
      */
@@ -35,6 +43,15 @@ public class AclAttributeWrapper impleme
         this.aclAttribute = aclAttribute;
     }
 
+    
+    /**
+     * @param aclAttribute the aclAttribute to set
+     */
+    public void setAclAttribute( String name )
+    {
+        this.aclAttribute = new AclAttribute( name, null );
+    }
+
 
     /**
      * Clone the current object
@@ -67,7 +84,10 @@ public class AclAttributeWrapper impleme
         {
             AclAttributeWrapper thatInstance = (AclAttributeWrapper)that;
 
-            return aclAttribute.getName().equalsIgnoreCase( thatInstance.aclAttribute.getName()
);
+            return aclAttribute.getName().equalsIgnoreCase( thatInstance.aclAttribute.getName()
) && 
+                   ( aclAttribute.isAttributeType() && thatInstance.aclAttribute.isAttributeType()
||
+                     ( ( aclAttribute.isObjectClass() || aclAttribute.isObjectClassNotAllowed()
) && 
+                         ( thatInstance.aclAttribute.isObjectClass() || thatInstance.aclAttribute.isObjectClassNotAllowed()
) ) );
         }
         else
         {



Mime
View raw message