You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2006/12/26 22:47:15 UTC

svn commit: r490383 [3/3] - in /directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor: ./ META-INF/ icons/ icons/old/ lib/ src/ src/org/ src/org/apache/ src/org/apache/directory/ src/org/apache/directory/ldapstudio/ src/org/apache/directory/ldapstu...

Added: directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemUserPermissionsComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemUserPermissionsComposite.java?view=auto&rev=490383
==============================================================================
--- directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemUserPermissionsComposite.java (added)
+++ directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemUserPermissionsComposite.java Tue Dec 26 13:47:13 2006
@@ -0,0 +1,431 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.ldapstudio.aciitemeditor.widgets;
+
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.aciitemeditor.dialogs.TextDialog;
+import org.apache.directory.ldapstudio.aciitemeditor.dialogs.UserPermissionDialog;
+import org.apache.directory.shared.ldap.aci.UserPermission;
+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 edit ACI item user permissions.
+
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIItemUserPermissionsComposite extends Composite
+{
+
+    /** 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 TableViewer tableViewer = null;
+    
+    /** The composite containing the buttons */
+    private Composite buttonComposite = null;
+    
+    /** The add button */
+    private Button addButton = null;
+    
+    /** The select all button */
+    private Button editButton = null;
+    
+    /** The deselect all button */
+    private Button deleteButton = null;
+    
+    /** The selected user permissions, also input of the table viewer */
+    List<UserPermissionWrapper> userPermissionWrappers = new ArrayList<UserPermissionWrapper>();
+    
+    
+    private class UserPermissionWrapper
+    {
+        /** The class of the user permission, never null. */
+        private final Class userPermissionClass;
+        
+        /** The user permission bean, may be null. */
+        private UserPermission userPermission;
+        
+        /**
+         * Creates a new instance of UserPermissionWrapper.
+         *
+         * @param userClassClass
+         */
+        public UserPermissionWrapper( Class userPermissionClass )
+        {
+            this.userPermissionClass = userPermissionClass;
+            this.userPermission = null;
+        }
+        
+        public String toString()
+        {
+            return getUserPermissionValue();
+        }
+        private String getUserPermissionValue()
+        {
+            if(userPermission == null)
+            {
+                return "<UNKNOWN>";
+            }
+            else 
+            {
+                String s = userPermission.toString();
+                s = s.replace( '\r', ' ' );
+                s = s.replace( '\n', ' ' );
+                s = ": " + s;
+                if(s.length() > 40)
+                {
+                    String temp = s;
+                    s = temp.substring( 0, 20 );
+                    s = s + "...";
+                    s = s + temp.substring( temp.length() - 20, temp.length() );
+                }
+                return s;
+            }
+        }
+    }
+    
+    
+    public ACIItemUserPermissionsComposite( 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 );
+        
+        createComposite();
+
+        GridData layoutData = new GridData();
+        layoutData.horizontalAlignment = GridData.FILL;
+        layoutData.grabExcessHorizontalSpace = true;
+        layoutData.verticalAlignment = GridData.CENTER;
+        setLayoutData( layoutData );
+    }
+
+
+    /**
+     * 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("User Permissions:");
+        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( true );
+        tableViewer = new TableViewer( table );
+        tableViewer.setContentProvider( new ArrayContentProvider() );
+        tableViewer.setLabelProvider( new LabelProvider() );
+        tableViewer.setInput( userPermissionWrappers );
+
+        tableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                userPermissionSelected();
+            }
+        } );
+        
+        tableViewer.addDoubleClickListener( new IDoubleClickListener(){
+            public void doubleClick( DoubleClickEvent event )
+            {
+                editUserPermission();
+            }
+        } );
+    }
+    
+    
+    /**
+     * This method initializes buttons  
+     *
+     */
+    private void createButtonComposite()
+    {
+        GridData deleteButtonGridData = new GridData();
+        deleteButtonGridData.horizontalAlignment = GridData.FILL;
+        deleteButtonGridData.grabExcessHorizontalSpace = false;
+        deleteButtonGridData.verticalAlignment = GridData.BEGINNING;
+        
+        GridData editButtonGridData = new GridData();
+        editButtonGridData.horizontalAlignment = GridData.FILL;
+        editButtonGridData.grabExcessHorizontalSpace = false;
+        editButtonGridData.verticalAlignment = GridData.BEGINNING;
+        
+        GridData addButtonGridData = new GridData();
+        addButtonGridData.horizontalAlignment = GridData.FILL;
+        addButtonGridData.grabExcessHorizontalSpace = false;
+        addButtonGridData.verticalAlignment = GridData.BEGINNING;
+        
+        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("Add...");
+        addButton.setLayoutData(addButtonGridData);
+        addButton.addSelectionListener( new SelectionAdapter(){
+            public void widgetSelected( SelectionEvent e )
+            {
+                addUserPermission();
+            }
+        } );
+        
+        editButton = new Button(buttonComposite, SWT.NONE);
+        editButton.setText("Edit...");
+        editButton.setLayoutData(editButtonGridData);
+        editButton.addSelectionListener( new SelectionAdapter(){
+            public void widgetSelected( SelectionEvent e )
+            {
+                editUserPermission();
+            }
+        } );
+        editButton.setEnabled( false );
+        
+        deleteButton = new Button(buttonComposite, SWT.NONE);
+        deleteButton.setText("Delete");
+        deleteButton.setLayoutData(deleteButtonGridData);
+        deleteButton.addSelectionListener( new SelectionAdapter(){
+            public void widgetSelected( SelectionEvent e )
+            {
+                deleteUserPermission();
+            }
+        } );
+        deleteButton.setEnabled( false );
+        
+    }
+    
+
+    
+    public void setVisible( boolean visible )
+    {
+        super.setVisible( visible );
+        ((GridData)getLayoutData()).heightHint = visible ? -1 : 0;
+    }
+    
+    
+    /**
+     * Sets the user permissions. 
+     *
+     * @param userPermissions
+     */
+    public void setUserPermissions( Collection<UserPermission> userPermissions )
+    {
+        for ( UserPermission userPermission : userPermissions )
+        {
+            UserPermissionWrapper userPermissionWrapper = new UserPermissionWrapper(userPermission.getClass());
+            userPermissionWrapper.userPermission = userPermission;
+            
+            userPermissionWrappers.add( userPermissionWrapper );
+        }
+
+        tableViewer.refresh();
+    }
+
+    
+    /**
+     * Returns the user permissions as selected by the user.
+     *
+     * @return the user permissions
+     * @throws ParseException 
+     */
+    public Collection<UserPermission> getUserPermissions() throws ParseException
+    {
+        Collection<UserPermission> userPermissions = new ArrayList<UserPermission>();
+
+        for ( UserPermissionWrapper userPermissionWrapper : userPermissionWrappers )
+        {
+            userPermissions.add( userPermissionWrapper.userPermission );
+        }
+
+        return userPermissions;
+    }
+    
+    /**
+     * 
+     * @return the user permission that is selected in the table viewer, or null.
+     */
+    private UserPermissionWrapper getSelectedUserPermissionWrapper() 
+    {
+        UserPermissionWrapper userPermissionWrapper = null;
+        
+        IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            Object element = selection.getFirstElement();
+            if ( element instanceof UserPermissionWrapper )
+            {
+                userPermissionWrapper = (UserPermissionWrapper) element;
+            }
+        }
+        
+        return userPermissionWrapper;
+    }
+    
+    
+    private void addUserPermission() 
+    {
+        UserPermissionDialog dialog = new UserPermissionDialog( getShell(), null );
+        if ( dialog.open() == TextDialog.OK && dialog.getUserPermission() != null )
+        {
+            UserPermissionWrapper userPermissionWrapper = new UserPermissionWrapper(dialog.getUserPermission().getClass());
+            userPermissionWrapper.userPermission = dialog.getUserPermission();
+            userPermissionWrappers.add( userPermissionWrapper );
+            
+            tableViewer.refresh();
+        }
+    }
+    
+    
+    private void editUserPermission() 
+    {
+        UserPermissionWrapper oldUserPermissionWrapper = getSelectedUserPermissionWrapper();
+        if(oldUserPermissionWrapper != null)
+        {
+            UserPermissionDialog dialog = new UserPermissionDialog( getShell(), oldUserPermissionWrapper.userPermission );
+            if ( dialog.open() == TextDialog.OK )
+            {
+                // remove old
+                userPermissionWrappers.remove( oldUserPermissionWrapper );
+                
+                // create and add new
+                UserPermissionWrapper newUserPermissionWrapper = new UserPermissionWrapper(dialog.getUserPermission().getClass());
+                newUserPermissionWrapper.userPermission = dialog.getUserPermission();
+                userPermissionWrappers.add( newUserPermissionWrapper );
+                
+                tableViewer.refresh();
+            }
+        }
+    }
+    
+    
+    private void deleteUserPermission() 
+    {
+        UserPermissionWrapper userPermissionWrapper = getSelectedUserPermissionWrapper();
+        if(userPermissionWrapper != null)
+        {
+            userPermissionWrappers.remove( userPermissionWrapper );
+            tableViewer.refresh();
+        }
+    }
+    
+    
+    private void userPermissionSelected()
+    {
+        UserPermissionWrapper userPermissionWrapper = getSelectedUserPermissionWrapper();
+
+        if ( userPermissionWrapper == null )
+        {
+            editButton.setEnabled( false );
+            deleteButton.setEnabled( false );
+        }
+        else
+        {
+            editButton.setEnabled( true );
+            deleteButton.setEnabled( true );
+        }
+    }
+
+}

Added: directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/WidgetModifyEvent.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/WidgetModifyEvent.java?view=auto&rev=490383
==============================================================================
--- directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/WidgetModifyEvent.java (added)
+++ directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/WidgetModifyEvent.java Tue Dec 26 13:47:13 2006
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.aciitemeditor.widgets;
+
+
+import java.util.EventObject;
+
+
+public class WidgetModifyEvent extends EventObject
+{
+
+    private static final long serialVersionUID = 2421335730580648878L;
+
+
+    public WidgetModifyEvent( Object source )
+    {
+        super( source );
+
+    }
+
+}

Added: directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/WidgetModifyListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/WidgetModifyListener.java?view=auto&rev=490383
==============================================================================
--- directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/WidgetModifyListener.java (added)
+++ directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/WidgetModifyListener.java Tue Dec 26 13:47:13 2006
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.aciitemeditor.widgets;
+
+
+public interface WidgetModifyListener
+{
+
+    public void widgetModified( WidgetModifyEvent event );
+
+}

Added: directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/test.aci
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/test.aci?view=auto&rev=490383
==============================================================================
    (empty)