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

svn commit: r592011 [5/6] - in /directory/sandbox/felixk/studio-aciitemeditor: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ src/ma...

Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java Mon Nov  5 06:27:47 2007
@@ -0,0 +1,513 @@
+/*
+ *  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.aciitemeditor.widgets;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.aci.GrantAndDenial;
+import org.apache.directory.shared.ldap.aci.ItemPermission;
+import org.apache.directory.shared.ldap.aci.UserClass;
+import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext;
+import org.apache.directory.studio.aciitemeditor.Activator;
+import org.apache.directory.studio.aciitemeditor.dialogs.ItemPermissionDialog;
+import org.apache.directory.studio.aciitemeditor.model.UserClassWrapper;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+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;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+
+
+/**
+ * This composite contains GUI elements to add, edit and delete ACI item permissions.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIItemItemPermissionsComposite extends Composite
+{
+
+    /** The context. */
+    private ACIItemValueWithContext context;
+
+    /** The inner composite for all the content */
+    private Composite composite = null;
+
+    /** The description label */
+    private Label label = null;
+
+    /** The table control for the table viewer */
+    private Table table = null;
+
+    /** The table viewer containing all item classes */
+    private TableViewer tableViewer = null;
+
+    /** The composite containing the buttons */
+    private Composite buttonComposite = null;
+
+    /** The add button */
+    private Button addButton = null;
+
+    /** The edit button */
+    private Button editButton = null;
+
+    /** The delete button */
+    private Button deleteButton = null;
+
+    /** The selected item permissions, input of the table viewer */
+    private List<ItemPermissionWrapper> itemPermissionWrappers = new ArrayList<ItemPermissionWrapper>();
+
+    /**
+     * ItemPermissionWrappers are used as input of the table viewer.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    private class ItemPermissionWrapper
+    {
+        /** The item permission bean. */
+        private ItemPermission itemPermission;
+
+
+        /**
+         * Creates a new instance of ItemPermissionWrapper.
+         *
+         * @param itemClassClass
+         */
+        private ItemPermissionWrapper( ItemPermission itemPermission )
+        {
+            this.itemPermission = itemPermission;
+        }
+
+
+        /**
+         * Returns a user-friedly string, displayed in the table.
+         * 
+         * @return the string
+         */
+        public String toString()
+        {
+            if ( itemPermission == null )
+            {
+                return "<UNKNOWN>"; //$NON-NLS-1$
+            }
+            else
+            {
+                StringBuffer buffer = new StringBuffer();
+                if ( itemPermission.getPrecedence() > -1 )
+                {
+                    buffer.append( '(' );
+                    buffer.append( itemPermission.getPrecedence() );
+                    buffer.append( ')' );
+                    buffer.append( ' ' );
+                }
+                for ( Iterator<UserClass> it = ( ( Collection<UserClass> ) itemPermission.getUserClasses() ).iterator(); it
+                    .hasNext(); )
+                {
+                    UserClass uc = it.next();
+                    String s = UserClassWrapper.classToDisplayMap.get( uc.getClass() );
+                    buffer.append( s );
+
+                    if ( it.hasNext() )
+                    {
+                        buffer.append( ',' );
+                    }
+                }
+                buffer.append( ':' );
+                buffer.append( ' ' );
+                for ( Iterator<GrantAndDenial> it = ( ( Collection<GrantAndDenial> ) itemPermission
+                    .getGrantsAndDenials() ).iterator(); it.hasNext(); )
+                {
+                    GrantAndDenial gd = it.next();
+                    buffer.append( gd.isGrant() ? '+' : '-' );
+                    buffer.append( gd.getMicroOperation().getName() );
+
+                    if ( it.hasNext() )
+                    {
+                        buffer.append( ',' );
+                    }
+                }
+
+                String s = buffer.toString();
+                s = s.replace( '\r', ' ' );
+                s = s.replace( '\n', ' ' );
+                if ( s.length() > 50 )
+                {
+                    String temp = s;
+                    s = temp.substring( 0, 25 );
+                    s = s + "..."; //$NON-NLS-1$
+                    s = s + temp.substring( temp.length() - 25, temp.length() );
+                }
+                return s;
+            }
+        }
+    }
+
+
+    /**
+     * 
+     * Creates a new instance of ACIItemItemPermissionsComposite.
+     *
+     * @param parent
+     * @param style
+     */
+    public ACIItemItemPermissionsComposite( Composite parent, int style )
+    {
+        super( parent, style );
+
+        GridLayout layout = new GridLayout();
+        layout.horizontalSpacing = 0;
+        layout.verticalSpacing = 0;
+        layout.marginHeight = 0;
+        layout.marginWidth = 0;
+        setLayout( layout );
+
+        GridData layoutData = new GridData();
+        layoutData.horizontalAlignment = GridData.FILL;
+        layoutData.grabExcessHorizontalSpace = true;
+        layoutData.verticalAlignment = GridData.CENTER;
+        setLayoutData( layoutData );
+
+        createComposite();
+    }
+
+
+    /**
+     * This method initializes composite    
+     *
+     */
+    private void createComposite()
+    {
+
+        GridData labelGridData = new GridData();
+        labelGridData.horizontalSpan = 2;
+        labelGridData.verticalAlignment = GridData.CENTER;
+        labelGridData.grabExcessHorizontalSpace = true;
+        labelGridData.horizontalAlignment = GridData.FILL;
+
+        GridLayout gridLayout = new GridLayout();
+        gridLayout.makeColumnsEqualWidth = false;
+        gridLayout.numColumns = 2;
+
+        GridData gridData = new GridData();
+        gridData.horizontalAlignment = GridData.FILL;
+        gridData.grabExcessHorizontalSpace = true;
+        gridData.verticalSpan = 1;
+        gridData.verticalAlignment = GridData.BEGINNING;
+
+        composite = new Composite( this, SWT.NONE );
+        composite.setLayoutData( gridData );
+        composite.setLayout( gridLayout );
+
+        label = new Label( composite, SWT.NONE );
+        label.setText( Messages.getString( "ACIItemItemPermissionsComposite.description" ) ); //$NON-NLS-1$
+        label.setLayoutData( labelGridData );
+
+        createTable();
+
+        createButtonComposite();
+    }
+
+
+    /**
+     * This method initializes table and table viewer
+     *
+     */
+    private void createTable()
+    {
+        GridData tableGridData = new GridData();
+        tableGridData.grabExcessHorizontalSpace = true;
+        tableGridData.verticalAlignment = GridData.FILL;
+        tableGridData.horizontalAlignment = GridData.FILL;
+        //tableGridData.heightHint = 100;
+
+        table = new Table( composite, SWT.BORDER );
+        table.setHeaderVisible( false );
+        table.setLayoutData( tableGridData );
+        table.setLinesVisible( false );
+        tableViewer = new TableViewer( table );
+        tableViewer.setContentProvider( new ArrayContentProvider() );
+        tableViewer.setLabelProvider( new LabelProvider() );
+        tableViewer.setInput( itemPermissionWrappers );
+
+        tableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                itemPermissionSelected();
+            }
+        } );
+
+        tableViewer.addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                editItemPermission();
+            }
+        } );
+    }
+
+
+    /**
+     * This method initializes buttons  
+     *
+     */
+    private void createButtonComposite()
+    {
+        GridData deleteButtonGridData = new GridData();
+        deleteButtonGridData.horizontalAlignment = GridData.FILL;
+        deleteButtonGridData.grabExcessHorizontalSpace = false;
+        deleteButtonGridData.verticalAlignment = GridData.BEGINNING;
+        deleteButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridData editButtonGridData = new GridData();
+        editButtonGridData.horizontalAlignment = GridData.FILL;
+        editButtonGridData.grabExcessHorizontalSpace = false;
+        editButtonGridData.verticalAlignment = GridData.BEGINNING;
+        editButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridData addButtonGridData = new GridData();
+        addButtonGridData.horizontalAlignment = GridData.FILL;
+        addButtonGridData.grabExcessHorizontalSpace = false;
+        addButtonGridData.verticalAlignment = GridData.BEGINNING;
+        addButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridLayout gridLayout = new GridLayout();
+        gridLayout.marginWidth = 0;
+        gridLayout.marginHeight = 0;
+        GridData gridData = new GridData();
+        gridData.horizontalAlignment = GridData.CENTER;
+        gridData.grabExcessHorizontalSpace = false;
+        gridData.grabExcessVerticalSpace = false;
+        gridData.verticalAlignment = GridData.FILL;
+
+        buttonComposite = new Composite( composite, SWT.NONE );
+        buttonComposite.setLayoutData( gridData );
+        buttonComposite.setLayout( gridLayout );
+
+        addButton = new Button( buttonComposite, SWT.NONE );
+        addButton.setText( Messages.getString( "ACIItemItemPermissionsComposite.add.button" ) ); //$NON-NLS-1$
+        addButton.setLayoutData( addButtonGridData );
+        addButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                addItemPermission();
+            }
+        } );
+
+        editButton = new Button( buttonComposite, SWT.NONE );
+        editButton.setText( Messages.getString( "ACIItemItemPermissionsComposite.edit.button" ) ); //$NON-NLS-1$
+        editButton.setLayoutData( editButtonGridData );
+        editButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                editItemPermission();
+            }
+        } );
+        editButton.setEnabled( false );
+
+        deleteButton = new Button( buttonComposite, SWT.NONE );
+        deleteButton.setText( Messages.getString( "ACIItemItemPermissionsComposite.delete.button" ) ); //$NON-NLS-1$
+        deleteButton.setLayoutData( deleteButtonGridData );
+        deleteButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                deleteItemPermission();
+            }
+        } );
+        deleteButton.setEnabled( false );
+
+    }
+
+
+    /**
+     * Shows or hides this composite.
+     * 
+     * @param visible true if visible
+     */
+    public void setVisible( boolean visible )
+    {
+        super.setVisible( visible );
+        ( ( GridData ) getLayoutData() ).heightHint = visible ? -1 : 0;
+    }
+
+
+    /**
+     * Sets the context.
+     * 
+     * @param context the context
+     */
+    public void setContext( ACIItemValueWithContext context )
+    {
+        this.context = context;
+    }
+
+
+    /**
+     * Sets the item permissions. 
+     *
+     * @param itemPermissions
+     */
+    public void setItemPermissions( Collection<ItemPermission> itemPermissions )
+    {
+        itemPermissionWrappers.clear();
+
+        for ( ItemPermission itemPermission : itemPermissions )
+        {
+            ItemPermissionWrapper itemPermissionWrapper = new ItemPermissionWrapper( itemPermission );
+
+            itemPermissionWrappers.add( itemPermissionWrapper );
+        }
+
+        tableViewer.refresh();
+    }
+
+
+    /**
+     * Returns the item permissions as selected by the user.
+     *
+     * @return the item permissions
+     */
+    public Collection<ItemPermission> getItemPermissions()
+    {
+        Collection<ItemPermission> itemPermissions = new ArrayList<ItemPermission>();
+
+        for ( ItemPermissionWrapper itemPermissionWrapper : itemPermissionWrappers )
+        {
+            itemPermissions.add( itemPermissionWrapper.itemPermission );
+        }
+
+        return itemPermissions;
+    }
+
+
+    /**
+     * 
+     * @return the item permission that is selected in the table viewer, or null.
+     */
+    private ItemPermissionWrapper getSelectedItemPermissionWrapper()
+    {
+        ItemPermissionWrapper itemPermissionWrapper = null;
+
+        IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            Object element = selection.getFirstElement();
+            if ( element instanceof ItemPermissionWrapper )
+            {
+                itemPermissionWrapper = ( ItemPermissionWrapper ) element;
+            }
+        }
+
+        return itemPermissionWrapper;
+    }
+
+
+    /**
+     * Opens the ItemPermissionDialog and adds the composed 
+     * item permission to the list.
+     */
+    private void addItemPermission()
+    {
+        ItemPermissionDialog dialog = new ItemPermissionDialog( getShell(), null, context );
+        if ( dialog.open() == ItemPermissionDialog.OK && dialog.getItemPermission() != null )
+        {
+            ItemPermissionWrapper itemPermissionWrapper = new ItemPermissionWrapper( dialog.getItemPermission() );
+            itemPermissionWrappers.add( itemPermissionWrapper );
+
+            tableViewer.refresh();
+        }
+    }
+
+
+    /**
+     * Opens the ItemPermissionDialog with the currently selected
+     * item permission and puts the modified item permission into the list.
+     */
+    private void editItemPermission()
+    {
+        ItemPermissionWrapper oldItemPermissionWrapper = getSelectedItemPermissionWrapper();
+        if ( oldItemPermissionWrapper != null )
+        {
+            ItemPermissionDialog dialog = new ItemPermissionDialog( getShell(),
+                oldItemPermissionWrapper.itemPermission, context );
+            if ( dialog.open() == ItemPermissionDialog.OK )
+            {
+                oldItemPermissionWrapper.itemPermission = dialog.getItemPermission();
+                tableViewer.refresh();
+            }
+        }
+    }
+
+
+    /**
+     * Deletes the currently selected item permission from list.
+     */
+    private void deleteItemPermission()
+    {
+        ItemPermissionWrapper itemPermissionWrapper = getSelectedItemPermissionWrapper();
+        if ( itemPermissionWrapper != null )
+        {
+            itemPermissionWrappers.remove( itemPermissionWrapper );
+            tableViewer.refresh();
+        }
+    }
+
+
+    /**
+     * Called when an item permission is selected in table viewer.
+     * Updates the enabled/disabled state of the buttons.
+     */
+    private void itemPermissionSelected()
+    {
+        ItemPermissionWrapper itemPermissionWrapper = getSelectedItemPermissionWrapper();
+
+        if ( itemPermissionWrapper == null )
+        {
+            editButton.setEnabled( false );
+            deleteButton.setEnabled( false );
+        }
+        else
+        {
+            editButton.setEnabled( true );
+            deleteButton.setEnabled( true );
+        }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java Mon Nov  5 06:27:47 2007
@@ -0,0 +1,539 @@
+/*
+ *  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.aciitemeditor.widgets;
+
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.aci.ProtectedItem;
+import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext;
+import org.apache.directory.studio.aciitemeditor.Activator;
+import org.apache.directory.studio.aciitemeditor.dialogs.MultiValuedDialog;
+import org.apache.directory.studio.aciitemeditor.model.ProtectedItemWrapper;
+import org.apache.directory.studio.aciitemeditor.model.ProtectedItemWrapperFactory;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Value;
+import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Label;
+import org.eclipse.swt.widgets.Table;
+
+
+/**
+ * This composite contains GUI elements to edit ACI item protected items.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIItemProtectedItemsComposite extends Composite
+{
+
+    /** The context. */
+    private ACIItemValueWithContext context;
+
+    /** The inner composite for all the content */
+    private Composite composite = null;
+
+    /** The description label */
+    private Label label = null;
+
+    /** The table control for the table viewer */
+    private Table table = null;
+
+    /** The table viewer containing all protected items */
+    private CheckboxTableViewer tableViewer = null;
+
+    /** The composite containing the buttons */
+    private Composite buttonComposite = null;
+
+    /** The edit button */
+    private Button editButton = null;
+
+    /** The select all button */
+    private Button selectAllButton = null;
+
+    /** The deselect all button */
+    private Button deselectAllButton = null;
+
+    /** The reverse button */
+    private Button reverseSelectionButton = null;
+
+    /** The possible protected items, used as input for the table viewer */
+    private ProtectedItemWrapper[] protectedItemWrappers = ProtectedItemWrapperFactory.createProtectedItemWrappers();
+
+
+    /**
+     * Creates a new instance of ACIItemProtectedItemsComposite.
+     *
+     * @param parent
+     * @param style
+     */
+    public ACIItemProtectedItemsComposite( Composite parent, int style )
+    {
+        super( parent, style );
+
+        GridLayout layout = new GridLayout();
+        layout.horizontalSpacing = 0;
+        layout.verticalSpacing = 0;
+        layout.marginHeight = 0;
+        layout.marginWidth = 0;
+        setLayout( layout );
+
+        GridData layoutData = new GridData();
+        layoutData.horizontalAlignment = GridData.FILL;
+        layoutData.grabExcessHorizontalSpace = true;
+        layoutData.verticalAlignment = GridData.CENTER;
+        setLayoutData( layoutData );
+
+        createComposite();
+    }
+
+
+    /**
+     * This method initializes composite	
+     *
+     */
+    private void createComposite()
+    {
+
+        GridData labelGridData = new GridData();
+        labelGridData.horizontalSpan = 2;
+        labelGridData.verticalAlignment = GridData.CENTER;
+        labelGridData.grabExcessHorizontalSpace = true;
+        labelGridData.horizontalAlignment = GridData.FILL;
+
+        GridLayout gridLayout = new GridLayout();
+        gridLayout.makeColumnsEqualWidth = false;
+        gridLayout.numColumns = 2;
+
+        GridData gridData = new GridData();
+        gridData.horizontalAlignment = GridData.FILL;
+        gridData.grabExcessHorizontalSpace = true;
+        gridData.verticalSpan = 1;
+        gridData.verticalAlignment = GridData.BEGINNING;
+
+        composite = new Composite( this, SWT.NONE );
+        composite.setLayoutData( gridData );
+        composite.setLayout( gridLayout );
+
+        label = new Label( composite, SWT.NONE );
+        label.setText( Messages.getString( "ACIItemProtectedItemsComposite.description" ) ); //$NON-NLS-1$
+        label.setLayoutData( labelGridData );
+
+        createTable();
+
+        createButtonComposite();
+    }
+
+
+    /**
+     * This method initializes table and table viewer
+     *
+     */
+    private void createTable()
+    {
+        GridData tableGridData = new GridData();
+        tableGridData.grabExcessHorizontalSpace = true;
+        tableGridData.verticalAlignment = GridData.FILL;
+        tableGridData.horizontalAlignment = GridData.FILL;
+        //tableGridData.heightHint = 100;
+
+        table = new Table( composite, SWT.BORDER | SWT.CHECK );
+        table.setHeaderVisible( false );
+        table.setLayoutData( tableGridData );
+        table.setLinesVisible( false );
+        tableViewer = new CheckboxTableViewer( table );
+        tableViewer.setContentProvider( new ArrayContentProvider() );
+        tableViewer.setLabelProvider( new ProtectedItemsLabelProvider() );
+        tableViewer.setInput( protectedItemWrappers );
+
+        tableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                protectedItemSelected();
+            }
+        } );
+        tableViewer.addCheckStateListener( new ICheckStateListener()
+        {
+            public void checkStateChanged( CheckStateChangedEvent event )
+            {
+                protectedItemChecked();
+            }
+        } );
+        tableViewer.addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                if ( editButton.isEnabled() )
+                {
+                    editProtectedItem();
+                }
+            }
+        } );
+    }
+
+
+    /**
+     * This method initializes buttons	
+     *
+     */
+    private void createButtonComposite()
+    {
+        GridData reverseSelectionButtonGridData = new GridData();
+        reverseSelectionButtonGridData.horizontalAlignment = GridData.FILL;
+        reverseSelectionButtonGridData.grabExcessHorizontalSpace = false;
+        reverseSelectionButtonGridData.verticalAlignment = GridData.BEGINNING;
+        reverseSelectionButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridData deselectAllButtonGridData = new GridData();
+        deselectAllButtonGridData.horizontalAlignment = GridData.FILL;
+        deselectAllButtonGridData.grabExcessHorizontalSpace = false;
+        deselectAllButtonGridData.verticalAlignment = GridData.BEGINNING;
+        deselectAllButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridData selectAllButtonGridData = new GridData();
+        selectAllButtonGridData.horizontalAlignment = GridData.FILL;
+        selectAllButtonGridData.grabExcessHorizontalSpace = false;
+        selectAllButtonGridData.verticalAlignment = GridData.BEGINNING;
+        selectAllButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridData editButtonGridData = new GridData();
+        editButtonGridData.horizontalAlignment = GridData.FILL;
+        editButtonGridData.grabExcessHorizontalSpace = false;
+        editButtonGridData.verticalAlignment = GridData.BEGINNING;
+        editButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridLayout gridLayout = new GridLayout();
+        gridLayout.marginWidth = 0;
+        gridLayout.marginHeight = 0;
+        GridData gridData = new GridData();
+        gridData.horizontalAlignment = GridData.CENTER;
+        gridData.grabExcessHorizontalSpace = false;
+        gridData.grabExcessVerticalSpace = false;
+        gridData.verticalAlignment = GridData.FILL;
+
+        buttonComposite = new Composite( composite, SWT.NONE );
+        buttonComposite.setLayoutData( gridData );
+        buttonComposite.setLayout( gridLayout );
+
+        editButton = new Button( buttonComposite, SWT.NONE );
+        editButton.setText( Messages.getString( "ACIItemProtectedItemsComposite.edit.button" ) ); //$NON-NLS-1$
+        editButton.setLayoutData( editButtonGridData );
+        editButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                editProtectedItem();
+            }
+        } );
+        editButton.setEnabled( false );
+
+        selectAllButton = new Button( buttonComposite, SWT.NONE );
+        selectAllButton.setText( Messages.getString( "ACIItemProtectedItemsComposite.selectAll.button" ) ); //$NON-NLS-1$
+        selectAllButton.setLayoutData( selectAllButtonGridData );
+        selectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                tableViewer.setCheckedElements( protectedItemWrappers );
+                refreshTable();
+            }
+        } );
+
+        deselectAllButton = new Button( buttonComposite, SWT.NONE );
+        deselectAllButton.setText( Messages.getString( "ACIItemProtectedItemsComposite.deselectAll.button" ) ); //$NON-NLS-1$
+        deselectAllButton.setLayoutData( deselectAllButtonGridData );
+        deselectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                tableViewer.setCheckedElements( new ProtectedItem[0] );
+                refreshTable();
+            }
+        } );
+
+        reverseSelectionButton = new Button( buttonComposite, SWT.NONE );
+        reverseSelectionButton.setText( Messages.getString( "ACIItemProtectedItemsComposite.revers.button" ) ); //$NON-NLS-1$
+        reverseSelectionButton.setLayoutData( reverseSelectionButtonGridData );
+        reverseSelectionButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                List<Object> elements = new ArrayList<Object>();
+                elements.addAll( Arrays.asList( protectedItemWrappers ) );
+                elements.removeAll( Arrays.asList( tableViewer.getCheckedElements() ) );
+                tableViewer.setCheckedElements( elements.toArray() );
+                refreshTable();
+            }
+        } );
+
+    }
+
+    /**
+     * The label provider used for this table viewer.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    private class ProtectedItemsLabelProvider extends LabelProvider
+    {
+
+        /**
+         * Returns the error icon if the protected item is checked and invalid.
+         * 
+         * @param element the element
+         * 
+         * @return the image
+         */
+        public Image getImage( Object element )
+        {
+            if ( element instanceof ProtectedItemWrapper )
+            {
+                ProtectedItemWrapper wrapper = ( ProtectedItemWrapper ) element;
+                if ( tableViewer.getChecked( wrapper ) )
+                {
+                    try
+                    {
+                        wrapper.getProtectedItem();
+                    }
+                    catch ( ParseException e )
+                    {
+                        return Activator.getDefault().getImage(
+                            Messages.getString( "ACIItemProtectedItemsComposite.error.icon" ) ); //$NON-NLS-1$
+                    }
+                }
+            }
+
+            return null;
+        }
+    }
+
+
+    /**
+     * Sets the context.
+     * 
+     * @param context the context
+     */
+    public void setContext( ACIItemValueWithContext context )
+    {
+        this.context = context;
+    }
+
+
+    /**
+     * Sets the protected items. 
+     *
+     * @param protectedItems
+     */
+    public void setProtectedItems( Collection<ProtectedItem> protectedItems )
+    {
+        // reset first
+        for ( ProtectedItemWrapper protectedItemWrapper : protectedItemWrappers )
+        {
+            tableViewer.setChecked( protectedItemWrapper, false );
+        }
+
+        for ( ProtectedItem item : protectedItems )
+        {
+            for ( ProtectedItemWrapper protectedItemWrapper : protectedItemWrappers )
+            {
+
+                if ( protectedItemWrapper.getClazz() == item.getClass() )
+                {
+                    protectedItemWrapper.setProtectedItem( item );
+                    tableViewer.setChecked( protectedItemWrapper, true );
+                }
+            }
+        }
+
+        refreshTable();
+    }
+
+
+    /**
+     * Returns the protected items as selected by the user.
+     *
+     * @return the protected items
+     * @throws ParseException if the protected items or its values are not valid.
+     */
+    public Collection<ProtectedItem> getProtectedItems() throws ParseException
+    {
+
+        Collection<ProtectedItem> protectedItems = new ArrayList<ProtectedItem>();
+
+        for ( ProtectedItemWrapper protectedItemWrapper : protectedItemWrappers )
+        {
+            if ( tableViewer.getChecked( protectedItemWrapper ) )
+            {
+                ProtectedItem protectedItem = protectedItemWrapper.getProtectedItem();
+                protectedItems.add( protectedItem );
+            }
+        }
+
+        return protectedItems;
+    }
+
+
+    /**
+     * Shows or hides this composite.
+     * 
+     * @param visible true if visible
+     */
+    public void setVisible( boolean visible )
+    {
+        super.setVisible( visible );
+        ( ( GridData ) getLayoutData() ).heightHint = visible ? -1 : 0;
+    }
+
+
+    /**
+     * 
+     * @return the protected item that is selected in the table viewer, or null.
+     */
+    private ProtectedItemWrapper getSelectedProtectedItemWrapper()
+    {
+        ProtectedItemWrapper protectedItemWrapper = null;
+
+        IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            Object element = selection.getFirstElement();
+            if ( element instanceof ProtectedItemWrapper )
+            {
+                protectedItemWrapper = ( ProtectedItemWrapper ) element;
+            }
+        }
+
+        return protectedItemWrapper;
+    }
+
+
+    /**
+     * Called, when a protected item is selected in the table viewer.
+     * - enables/disables the edit button
+     *
+     */
+    private void protectedItemSelected()
+    {
+        ProtectedItemWrapper protectedItemWrapper = getSelectedProtectedItemWrapper();
+
+        if ( protectedItemWrapper == null || !protectedItemWrapper.isEditable() )
+        {
+            editButton.setEnabled( false );
+        }
+        else
+        {
+            editButton.setEnabled( true );
+        }
+    }
+
+
+    /**
+     * Called, when a protected item checkbox is checked or unchecked.
+     */
+    private void protectedItemChecked()
+    {
+        refreshTable();
+    }
+
+
+    /**
+     * Called, when pushing the edit button. Opens the text editor.
+     *
+     */
+    private void editProtectedItem()
+    {
+        ProtectedItemWrapper protectedItemWrapper = getSelectedProtectedItemWrapper();
+
+        AbstractDialogStringValueEditor valueEditor = protectedItemWrapper.getValueEditor();
+        if ( valueEditor != null )
+        {
+            if ( protectedItemWrapper.isMultivalued() )
+            {
+                MultiValuedDialog dialog = new MultiValuedDialog( getShell(), protectedItemWrapper.getDisplayName(),
+                    protectedItemWrapper.getValues(), context, valueEditor );
+                dialog.open();
+                refreshTable();
+            }
+            else
+            {
+                List<String> values = protectedItemWrapper.getValues();
+                String oldValue = values.isEmpty() ? null : values.get( 0 );
+                if ( oldValue == null )
+                {
+                    oldValue = ""; //$NON-NLS-1$
+                }
+
+                IAttribute attribute = new Attribute( context.getEntry(), "" ); //$NON-NLS-1$
+                IValue value = new Value( attribute, oldValue ); //$NON-NLS-1$
+                Object oldRawValue = valueEditor.getRawValue( value ); //$NON-NLS-1$
+
+                CellEditor cellEditor = valueEditor.getCellEditor();
+                cellEditor.setValue( oldRawValue );
+                cellEditor.activate();
+                Object newRawValue = cellEditor.getValue();
+
+                if ( newRawValue != null )
+                {
+                    String newValue = ( String ) valueEditor.getStringOrBinaryValue( newRawValue );
+
+                    values.clear();
+                    values.add( newValue );
+                    tableViewer.refresh();
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Refreshes the table viewer.
+     */
+    private void refreshTable()
+    {
+        tableViewer.refresh();
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemSourceEditorComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemSourceEditorComposite.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemSourceEditorComposite.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemSourceEditorComposite.java Mon Nov  5 06:27:47 2007
@@ -0,0 +1,190 @@
+/*
+ *  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.aciitemeditor.widgets;
+
+
+import java.text.ParseException;
+
+import org.apache.directory.shared.ldap.aci.ACIItem;
+import org.apache.directory.shared.ldap.aci.ACIItemParser;
+import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext;
+import org.apache.directory.studio.aciitemeditor.Activator;
+import org.apache.directory.studio.aciitemeditor.sourceeditor.ACISourceViewerConfiguration;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * This composite contains the source editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIItemSourceEditorComposite extends Composite
+{
+
+    /** The source editor */
+    private SourceViewer sourceEditor;
+
+    /** The source editor configuration. */
+    private SourceViewerConfiguration configuration;
+
+
+    /**
+     * Creates a new instance of ACIItemSourceEditorComposite.
+     *
+     * @param parent
+     * @param style
+     */
+    public ACIItemSourceEditorComposite( Composite parent, int style )
+    {
+        super( parent, style );
+        setLayout( new FillLayout() );
+
+        createSourceEditor();
+    }
+
+
+    /**
+     * Creates and configures the source editor.
+     *
+     */
+    private void createSourceEditor()
+    {
+        // create source editor
+        sourceEditor = new SourceViewer( this, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL );
+
+        // setup basic configuration
+        configuration = new ACISourceViewerConfiguration();
+        sourceEditor.configure( configuration );
+
+        // set text font
+        Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT );
+        sourceEditor.getTextWidget().setFont( font );
+
+        // setup document
+        IDocument document = new Document();
+        sourceEditor.setDocument( document );
+    }
+
+
+    /**
+     * Sets the input to the source editor.
+     * A syntax check is performed before setting the input, an 
+     * invalid syntax causes a ParseException.
+     *
+     * @param input the valid string representation of the ACI item
+     * @throws ParseException it the syntax check fails.
+     */
+    public void setInput( String input ) throws ParseException
+    {
+        ACIItemParser parser = Activator.getDefault().getACIItemParser();
+        parser.parse( input );
+
+        forceSetInput( input );
+    }
+
+
+    /**
+     * Set the input to the source editor without a syntax check.
+     *
+     * @param input The string representation of the ACI item, may be invalid
+     */
+    public void forceSetInput( String input )
+    {
+        sourceEditor.getDocument().set( input );
+
+        // format
+        IRegion region = new Region( 0, sourceEditor.getDocument().getLength() );
+        configuration.getContentFormatter( sourceEditor ).format( sourceEditor.getDocument(), region );
+
+    }
+
+
+    /**
+     * Returns the string representation of the ACI item.
+     * A syntax check is performed before returning the input, an 
+     * invalid syntax causes a ParseException.
+     *
+     * @return the valid string representation of the ACI item
+     * @throws ParseException it the syntax check fails.
+     */
+    public String getInput() throws ParseException
+    {
+        String input = forceGetInput();
+
+        // strip new lines
+        input = input.replaceAll( "\\n", " " ); //$NON-NLS-1$ //$NON-NLS-2$
+        input = input.replaceAll( "\\r", " " ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        ACIItemParser parser = Activator.getDefault().getACIItemParser();
+        ACIItem aciItem = parser.parse( input );
+
+        StringBuffer buffer = new StringBuffer();
+        if ( aciItem != null )
+        {
+            aciItem.printToBuffer( buffer );
+        }
+        return buffer.toString();
+    }
+
+
+    /**
+     * Returns the string representation of the ACI item without syntax check.
+     * In other words only the text in the source editor is returned.
+     *
+     * @return the string representation of the ACI item, may be invalid
+     */
+    public String forceGetInput()
+    {
+        return sourceEditor.getDocument().get();
+    }
+
+
+    /**
+     * Sets the context.
+     * 
+     * @param context the context
+     */
+    public void setContext( ACIItemValueWithContext context )
+    {
+
+    }
+
+
+    /**
+     * Formats the content.
+     */
+    public void format()
+    {
+        IRegion region = new Region( 0, sourceEditor.getDocument().getLength() );
+        configuration.getContentFormatter( sourceEditor ).format( sourceEditor.getDocument(), region );
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemSourceEditorComposite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemTabFolderComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemTabFolderComposite.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemTabFolderComposite.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemTabFolderComposite.java Mon Nov  5 06:27:47 2007
@@ -0,0 +1,296 @@
+/*
+ *  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.aciitemeditor.widgets;
+
+
+import java.text.ParseException;
+
+import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext;
+import org.apache.directory.studio.aciitemeditor.Activator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+
+
+/**
+ * This composite contains the tabs with visual and source editor.
+ * It also manages the synchronization between these two tabs.
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIItemTabFolderComposite extends Composite
+{
+
+    /** The index of the visual tab */
+    public static final int VISUAL_TAB_INDEX = 0;
+
+    /** The index of the source tab */
+    public static final int SOURCE_TAB_INDEX = 1;
+
+    /** The tab folder */
+    private TabFolder tabFolder;
+
+    /** The visual tab */
+    private TabItem visualTab;
+
+    /** The inner container of the visual tab */
+    private Composite visualContainer;
+
+    /** The visual editor composite */
+    private ACIItemVisualEditorComposite visualComposite;
+
+    /** Tehe source tab */
+    private TabItem sourceTab;
+
+    /** The inner container of the visual tab */
+    private Composite sourceContainer;
+
+    /** The source editor composite */
+    private ACIItemSourceEditorComposite sourceComposite;
+
+
+    /**
+     * Creates a new instance of TabFolderComposite.
+     *
+     * @param parent
+     * @param style
+     */
+    public ACIItemTabFolderComposite( Composite parent, int style )
+    {
+        super( parent, style );
+        setLayoutData( new GridData( GridData.FILL_BOTH ) );
+        GridLayout layout = new GridLayout( 1, false );
+        layout.marginWidth = 0;
+        layout.marginHeight = 0;
+        setLayout( layout );
+
+        createTabFolder();
+
+        createVisualTab();
+
+        createSourceTab();
+
+        initListeners();
+    }
+
+
+    /**
+     * Initializes the listeners.
+     *
+     */
+    private void initListeners()
+    {
+        tabFolder.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                tabSelected();
+            }
+        } );
+    }
+
+
+    /**
+     * Creates the source tab and configures the source editor.
+     *
+     */
+    private void createSourceTab()
+    {
+        // create inner container
+        sourceContainer = new Composite( tabFolder, SWT.BORDER );
+        sourceContainer.setLayout( new FillLayout() );
+
+        // create source editor
+        sourceComposite = new ACIItemSourceEditorComposite( sourceContainer, SWT.NONE );
+
+        // create tab
+        sourceTab = new TabItem( tabFolder, SWT.NONE, SOURCE_TAB_INDEX );
+        sourceTab.setText( Messages.getString( "ACIItemTabFolderComposite.source.tab" ) ); //$NON-NLS-1$
+        sourceTab.setControl( sourceContainer );
+    }
+
+
+    /**
+     * Creates the visual tab and the GUI editor.
+     *
+     */
+    private void createVisualTab()
+    {
+        // create inner container
+        visualContainer = new Composite( tabFolder, SWT.NONE );
+        visualContainer.setLayout( new FillLayout() );
+
+        // create the visual ACIItem composite
+        visualComposite = new ACIItemVisualEditorComposite( visualContainer, SWT.NONE );
+
+        // create tab
+        visualTab = new TabItem( tabFolder, SWT.NONE, VISUAL_TAB_INDEX );
+        visualTab.setText( Messages.getString( "ACIItemTabFolderComposite.visual.tab" ) ); //$NON-NLS-1$
+        visualTab.setControl( visualContainer );
+    }
+
+
+    /**
+     * Creates the tab folder and the listeners.
+     *
+     */
+    private void createTabFolder()
+    {
+        tabFolder = new TabFolder( this, SWT.TOP );
+        GridLayout mainLayout = new GridLayout();
+        mainLayout.marginWidth = 0;
+        mainLayout.marginHeight = 0;
+        tabFolder.setLayout( mainLayout );
+        tabFolder.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+    }
+
+
+    /** 
+     * Called, when a tab is selected. This method manages the synchronization
+     * between visual and source editor.
+     */
+    private void tabSelected()
+    {
+        int index = tabFolder.getSelectionIndex();
+
+        if ( index == SOURCE_TAB_INDEX )
+        {
+            // switched to source tab: serialize visual and set to source
+            // on parse error: print message and return to visual tab
+            try
+            {
+                String input = visualComposite.getInput();
+                sourceComposite.setInput( input );
+            }
+            catch ( ParseException pe )
+            {
+                IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages
+                    .getString( "ACIItemTabFolderComposite.error.onVisualEditor" ), pe ); //$NON-NLS-1$
+                ErrorDialog.openError( getShell(),
+                    Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$
+                tabFolder.setSelection( VISUAL_TAB_INDEX );
+            }
+        }
+        else if ( index == VISUAL_TAB_INDEX )
+        {
+            // switched to visual tab: parse source and populate to visual
+            // on parse error: print message and return to source tab
+            try
+            {
+                String input = sourceComposite.getInput();
+                visualComposite.setInput( input );
+            }
+            catch ( ParseException pe )
+            {
+                IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages
+                    .getString( "ACIItemTabFolderComposite.error.onSourceEditor" ), pe ); //$NON-NLS-1$
+                ErrorDialog.openError( getShell(),
+                    Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$
+                tabFolder.setSelection( SOURCE_TAB_INDEX );
+            }
+        }
+    }
+
+
+    /**
+     * Sets the input to both the source editor and to the visual editor.
+     * If the syntax is invalid the source editor is activated. 
+     *
+     * @param input The string representation of the ACI item
+     */
+    public void setInput( String input )
+    {
+        // set input to source editor
+        sourceComposite.forceSetInput( input );
+
+        // set input to visual editor, on parse error switch to source editor
+        try
+        {
+            visualComposite.setInput( input );
+        }
+        catch ( ParseException pe )
+        {
+            IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages
+                .getString( "ACIItemTabFolderComposite.error.onInput" ), pe ); //$NON-NLS-1$
+            ErrorDialog.openError( getShell(),
+                Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$
+
+            tabFolder.setSelection( SOURCE_TAB_INDEX );
+        }
+    }
+
+
+    /**
+     * Returns the string representation of the ACI item.
+     * A syntax check is performed before returning the input, an 
+     * invalid syntax causes a ParseException.
+     *
+     * @return the valid string representation of the ACI item
+     * @throws ParseException it the syntax check fails.
+     */
+    public String getInput() throws ParseException
+    {
+        int index = tabFolder.getSelectionIndex();
+        if ( index == VISUAL_TAB_INDEX )
+        {
+            String input = visualComposite.getInput();
+            return input;
+        }
+        else
+        {
+            String input = sourceComposite.getInput();
+            return input;
+        }
+    }
+
+
+    /**
+     * Sets the context.
+     * 
+     * @param context the context
+     */
+    public void setContext( ACIItemValueWithContext context )
+    {
+        sourceComposite.setContext( context );
+        visualComposite.setContext( context );
+    }
+
+
+    /**
+     * Formats the content.
+     */
+    public void format()
+    {
+        sourceComposite.format();
+        //visualComposite.format();
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemTabFolderComposite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserClassesComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserClassesComposite.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserClassesComposite.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserClassesComposite.java Mon Nov  5 06:27:47 2007
@@ -0,0 +1,503 @@
+/*
+ *  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.aciitemeditor.widgets;
+
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.aci.ProtectedItem;
+import org.apache.directory.shared.ldap.aci.UserClass;
+import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext;
+import org.apache.directory.studio.aciitemeditor.Activator;
+import org.apache.directory.studio.aciitemeditor.dialogs.MultiValuedDialog;
+import org.apache.directory.studio.aciitemeditor.model.UserClassWrapper;
+import org.apache.directory.studio.aciitemeditor.model.UserClassWrapperFactory;
+import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Label;
+import org.eclipse.swt.widgets.Table;
+
+
+/**
+ * This composite contains GUI elements to edit ACI item user classes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIItemUserClassesComposite extends Composite
+{
+
+    /** The context. */
+    private ACIItemValueWithContext context;
+
+    /** The inner composite for all the content */
+    private Composite composite = null;
+
+    /** The description label */
+    private Label label = null;
+
+    /** The table control for the table viewer */
+    private Table table = null;
+
+    /** The table viewer containing all user classes */
+    private CheckboxTableViewer tableViewer = null;
+
+    /** The composite containing the buttons */
+    private Composite buttonComposite = null;
+
+    /** The edit button */
+    private Button editButton = null;
+
+    /** The select all button */
+    private Button selectAllButton = null;
+
+    /** The deselect all button */
+    private Button deselectAllButton = null;
+
+    /** The reverse button */
+    private Button reverseSelectionButton = null;
+
+    /** The possible user classes, used as input for the table viewer */
+    private UserClassWrapper[] userClassWrappers = UserClassWrapperFactory.createUserClassWrappers();
+
+
+    /**
+     * Creates a new instance of ACIItemUserClassesComposite.
+     *
+     * @param parent
+     * @param style
+     */
+    public ACIItemUserClassesComposite( Composite parent, int style )
+    {
+        super( parent, style );
+
+        GridLayout layout = new GridLayout();
+        layout.horizontalSpacing = 0;
+        layout.verticalSpacing = 0;
+        layout.marginHeight = 0;
+        layout.marginWidth = 0;
+        setLayout( layout );
+
+        GridData layoutData = new GridData();
+        layoutData.horizontalAlignment = GridData.FILL;
+        layoutData.grabExcessHorizontalSpace = true;
+        layoutData.verticalAlignment = GridData.CENTER;
+        setLayoutData( layoutData );
+
+        createComposite();
+    }
+
+
+    /**
+     * This method initializes composite    
+     *
+     */
+    private void createComposite()
+    {
+
+        GridData labelGridData = new GridData();
+        labelGridData.horizontalSpan = 2;
+        labelGridData.verticalAlignment = GridData.CENTER;
+        labelGridData.grabExcessHorizontalSpace = true;
+        labelGridData.horizontalAlignment = GridData.FILL;
+
+        GridLayout gridLayout = new GridLayout();
+        gridLayout.makeColumnsEqualWidth = false;
+        gridLayout.numColumns = 2;
+
+        GridData gridData = new GridData();
+        gridData.horizontalAlignment = GridData.FILL;
+        gridData.grabExcessHorizontalSpace = true;
+        gridData.verticalSpan = 1;
+        gridData.verticalAlignment = GridData.BEGINNING;
+
+        composite = new Composite( this, SWT.NONE );
+        composite.setLayoutData( gridData );
+        composite.setLayout( gridLayout );
+
+        label = new Label( composite, SWT.NONE );
+        label.setText( Messages.getString( "ACIItemUserClassesComposite.description" ) ); //$NON-NLS-1$
+        label.setLayoutData( labelGridData );
+
+        createTable();
+
+        createButtonComposite();
+    }
+
+
+    /**
+     * This method initializes table and table viewer
+     *
+     */
+    private void createTable()
+    {
+        GridData tableGridData = new GridData();
+        tableGridData.grabExcessHorizontalSpace = true;
+        tableGridData.verticalAlignment = GridData.FILL;
+        tableGridData.horizontalAlignment = GridData.FILL;
+        //tableGridData.heightHint = 100;
+
+        table = new Table( composite, SWT.BORDER | SWT.CHECK );
+        table.setHeaderVisible( false );
+        table.setLayoutData( tableGridData );
+        table.setLinesVisible( false );
+        tableViewer = new CheckboxTableViewer( table );
+        tableViewer.setContentProvider( new ArrayContentProvider() );
+        tableViewer.setLabelProvider( new UserClassesLabelProvider() );
+        tableViewer.setInput( userClassWrappers );
+
+        tableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                userClassSelected();
+            }
+        } );
+        tableViewer.addCheckStateListener( new ICheckStateListener()
+        {
+            public void checkStateChanged( CheckStateChangedEvent event )
+            {
+                userClassChecked();
+            }
+        } );
+        tableViewer.addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                if ( editButton.isEnabled() )
+                {
+                    editUserClass();
+                }
+            }
+        } );
+    }
+
+
+    /**
+     * This method initializes buttons  
+     *
+     */
+    private void createButtonComposite()
+    {
+        GridData reverseSelectionButtonGridData = new GridData();
+        reverseSelectionButtonGridData.horizontalAlignment = GridData.FILL;
+        reverseSelectionButtonGridData.grabExcessHorizontalSpace = false;
+        reverseSelectionButtonGridData.verticalAlignment = GridData.BEGINNING;
+        reverseSelectionButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridData deselectAllButtonGridData = new GridData();
+        deselectAllButtonGridData.horizontalAlignment = GridData.FILL;
+        deselectAllButtonGridData.grabExcessHorizontalSpace = false;
+        deselectAllButtonGridData.verticalAlignment = GridData.BEGINNING;
+        deselectAllButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridData selectAllButtonGridData = new GridData();
+        selectAllButtonGridData.horizontalAlignment = GridData.FILL;
+        selectAllButtonGridData.grabExcessHorizontalSpace = false;
+        selectAllButtonGridData.verticalAlignment = GridData.BEGINNING;
+        selectAllButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridData editButtonGridData = new GridData();
+        editButtonGridData.horizontalAlignment = GridData.FILL;
+        editButtonGridData.grabExcessHorizontalSpace = false;
+        editButtonGridData.verticalAlignment = GridData.BEGINNING;
+        editButtonGridData.widthHint = Activator.getButtonWidth( this );
+
+        GridLayout gridLayout = new GridLayout();
+        gridLayout.marginWidth = 0;
+        gridLayout.marginHeight = 0;
+        GridData gridData = new GridData();
+        gridData.horizontalAlignment = GridData.CENTER;
+        gridData.grabExcessHorizontalSpace = false;
+        gridData.grabExcessVerticalSpace = false;
+        gridData.verticalAlignment = GridData.FILL;
+
+        buttonComposite = new Composite( composite, SWT.NONE );
+        buttonComposite.setLayoutData( gridData );
+        buttonComposite.setLayout( gridLayout );
+
+        editButton = new Button( buttonComposite, SWT.NONE );
+        editButton.setText( Messages.getString( "ACIItemUserClassesComposite.edit.button" ) ); //$NON-NLS-1$
+        editButton.setLayoutData( editButtonGridData );
+        editButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                editUserClass();
+            }
+        } );
+        editButton.setEnabled( false );
+
+        selectAllButton = new Button( buttonComposite, SWT.NONE );
+        selectAllButton.setText( Messages.getString( "ACIItemUserClassesComposite.selectAll.button" ) ); //$NON-NLS-1$
+        selectAllButton.setLayoutData( selectAllButtonGridData );
+        selectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                tableViewer.setCheckedElements( userClassWrappers );
+                refreshTable();
+            }
+        } );
+
+        deselectAllButton = new Button( buttonComposite, SWT.NONE );
+        deselectAllButton.setText( Messages.getString( "ACIItemUserClassesComposite.deselectAll.button" ) ); //$NON-NLS-1$
+        deselectAllButton.setLayoutData( deselectAllButtonGridData );
+        deselectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                tableViewer.setCheckedElements( new ProtectedItem[0] );
+                refreshTable();
+            }
+        } );
+
+        reverseSelectionButton = new Button( buttonComposite, SWT.NONE );
+        reverseSelectionButton.setText( Messages.getString( "ACIItemUserClassesComposite.revert.buton" ) ); //$NON-NLS-1$
+        reverseSelectionButton.setLayoutData( reverseSelectionButtonGridData );
+        reverseSelectionButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                List<Object> elements = new ArrayList<Object>();
+                elements.addAll( Arrays.asList( userClassWrappers ) );
+                elements.removeAll( Arrays.asList( tableViewer.getCheckedElements() ) );
+                tableViewer.setCheckedElements( elements.toArray() );
+                refreshTable();
+            }
+        } );
+
+    }
+
+    /**
+     * The label provider used for this table viewer.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    private class UserClassesLabelProvider extends LabelProvider
+    {
+
+        /**
+         * Returns the error icon if the user class is checked and invalid.
+         * 
+         * @param element the element
+         * 
+         * @return the image
+         */
+        public Image getImage( Object element )
+        {
+            if ( element instanceof UserClassWrapper )
+            {
+                UserClassWrapper wrapper = ( UserClassWrapper ) element;
+                if ( tableViewer.getChecked( wrapper ) )
+                {
+                    try
+                    {
+                        wrapper.getUserClass();
+                    }
+                    catch ( ParseException e )
+                    {
+                        return Activator.getDefault().getImage(
+                            Messages.getString( "ACIItemUserClassesComposite.error.icon" ) ); //$NON-NLS-1$
+                    }
+                }
+            }
+
+            return null;
+        }
+    }
+
+
+    /**
+     * Sets the context.
+     * 
+     * @param context the context
+     */
+    public void setContext( ACIItemValueWithContext context )
+    {
+        this.context = context;
+    }
+
+
+    /**
+     * Sets the user classes.
+     * 
+     * @param userClasses the user classes
+     */
+    public void setUserClasses( Collection<UserClass> userClasses )
+    {
+        // reset first
+        for ( UserClassWrapper userClassWrapper : userClassWrappers )
+        {
+            tableViewer.setChecked( userClassWrapper, false );
+        }
+
+        for ( UserClass userClass : userClasses )
+        {
+            for ( UserClassWrapper userClassWrapper : userClassWrappers )
+            {
+                if ( userClassWrapper.getClazz() == userClass.getClass() )
+                {
+                    userClassWrapper.setUserClass( userClass );
+                    tableViewer.setChecked( userClassWrapper, true );
+                }
+            }
+        }
+
+        refreshTable();
+    }
+
+
+    /**
+     * Returns the user classes as selected by the user.
+     *
+     * @return the user classes
+     * @throws ParseException if the user classes or its values are not valid.
+     */
+    public Collection<UserClass> getUserClasses() throws ParseException
+    {
+        Collection<UserClass> userClasses = new ArrayList<UserClass>();
+
+        for ( UserClassWrapper userClassWrapper : userClassWrappers )
+        {
+            if ( tableViewer.getChecked( userClassWrapper ) )
+            {
+                UserClass userClass = userClassWrapper.getUserClass();
+                userClasses.add( userClass );
+            }
+        }
+
+        return userClasses;
+    }
+
+
+    /**
+     * Shows or hides this composite.
+     * 
+     * @param visible true if visible
+     */
+    public void setVisible( boolean visible )
+    {
+        super.setVisible( visible );
+        ( ( GridData ) getLayoutData() ).heightHint = visible ? -1 : 0;
+    }
+
+
+    /**
+     * 
+     * @return the user class that is selected in the table viewer, or null.
+     */
+    private UserClassWrapper getSelectedUserClassWrapper()
+    {
+        UserClassWrapper userClassWrapper = null;
+
+        IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            Object element = selection.getFirstElement();
+            if ( element instanceof UserClassWrapper )
+            {
+                userClassWrapper = ( UserClassWrapper ) element;
+            }
+        }
+
+        return userClassWrapper;
+    }
+
+
+    /**
+     * Called, when a user class is selected in the table viewer.
+     * - enables/disables the edit button
+     *
+     */
+    private void userClassSelected()
+    {
+        UserClassWrapper userClassWrapper = getSelectedUserClassWrapper();
+
+        if ( userClassWrapper == null || !userClassWrapper.isEditable() )
+        {
+            editButton.setEnabled( false );
+        }
+        else
+        {
+            editButton.setEnabled( true );
+        }
+    }
+
+
+    /**
+     * Called, when a user class checkbox is checked or unchecked.
+     *
+     */
+    private void userClassChecked()
+    {
+        refreshTable();
+    }
+
+
+    /**
+     * Called, when pushing the edit button. Opens the editor.
+     */
+    private void editUserClass()
+    {
+        UserClassWrapper userClassWrapper = getSelectedUserClassWrapper();
+
+        AbstractDialogStringValueEditor editor = userClassWrapper.getValueEditor();
+        if ( editor != null )
+        {
+            MultiValuedDialog dialog = new MultiValuedDialog( getShell(), userClassWrapper.getDisplayName(),
+                userClassWrapper.getValues(), context, editor );
+            dialog.open();
+            refreshTable();
+        }
+    }
+
+
+    /**
+     * Refreshes the table viewer.
+     */
+    private void refreshTable()
+    {
+        tableViewer.refresh();
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserClassesComposite.java
------------------------------------------------------------------------------
    svn:eol-style = native