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 [2/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/ACIItemGrantsAndDenialsComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemGrantsAndDenialsComposite.java?view=auto&rev=490383
==============================================================================
--- directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemGrantsAndDenialsComposite.java (added)
+++ directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemGrantsAndDenialsComposite.java Tue Dec 26 13:47:13 2006
@@ -0,0 +1,468 @@
+/*
+ * 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 org.apache.directory.ldapstudio.aciitemeditor.Activator;
+import org.apache.directory.shared.ldap.aci.GrantAndDenial;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+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.Item;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+
+public class ACIItemGrantsAndDenialsComposite extends Composite
+{
+
+ private static String PERMISSION = "Permission";
+ private static String GRANT = "Grant";
+ private static String DENY = "Deny";
+ private static String[] COLUMNS = new String[] { PERMISSION, GRANT, DENY };
+
+
+ private GrantAndDenialWrapper[] grantAndDenialWrappers = new GrantAndDenialWrapper[]
+ {
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_ADD, GrantAndDenial.DENY_ADD),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_DISCLOSE_ON_ERROR, GrantAndDenial.DENY_DISCLOSE_ON_ERROR),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_READ, GrantAndDenial.DENY_READ),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_REMOVE, GrantAndDenial.DENY_REMOVE),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_BROWSE, GrantAndDenial.DENY_BROWSE),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_EXPORT, GrantAndDenial.DENY_EXPORT),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_IMPORT, GrantAndDenial.DENY_IMPORT),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_MODIFY, GrantAndDenial.DENY_MODIFY),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_RENAME, GrantAndDenial.DENY_RENAME),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_RETURN_DN, GrantAndDenial.DENY_RETURN_DN),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_COMPARE, GrantAndDenial.DENY_COMPARE),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_FILTER_MATCH, GrantAndDenial.DENY_FILTER_MATCH),
+ new GrantAndDenialWrapper(GrantAndDenial.GRANT_INVOKE, GrantAndDenial.DENY_INVOKE),
+// new GrantAndDenialWrapper(MicroOperation.ADD),
+// new GrantAndDenialWrapper(MicroOperation.DISCLOSE_ON_ERROR),
+// new GrantAndDenialWrapper(MicroOperation.READ),
+// new GrantAndDenialWrapper(MicroOperation.REMOVE),
+// new GrantAndDenialWrapper(MicroOperation.BROWSE),
+// new GrantAndDenialWrapper(MicroOperation.EXPORT),
+// new GrantAndDenialWrapper(MicroOperation.IMPORT),
+// new GrantAndDenialWrapper(MicroOperation.MODIFY),
+// new GrantAndDenialWrapper(MicroOperation.RENAME),
+// new GrantAndDenialWrapper(MicroOperation.RETURN_DN),
+// new GrantAndDenialWrapper(MicroOperation.COMPARE),
+// new GrantAndDenialWrapper(MicroOperation.FILTER_MATCH),
+// new GrantAndDenialWrapper(MicroOperation.INVOKE)
+ };
+
+// private enum State {
+// UNSET,
+// GRANT,
+// DENY
+// }
+
+ private class GrantAndDenialWrapper
+ {
+ private static final String DUMMY =
+ "{ identificationTag \"id1\", precedence 1, authenticationLevel simple, "
+ + "itemOrUserFirst itemFirst: { protectedItems { entry }, "
+ + "itemPermissions { { userClasses { allUsers }, grantsAndDenials { #value# } } }"
+ + " } }";
+
+ private GrantAndDenial grant;
+ private GrantAndDenial deny;
+ private GrantAndDenial activeGrantAndDenial;
+ GrantAndDenialWrapper( GrantAndDenial grant, GrantAndDenial deny )
+ {
+ this.grant = grant;
+ this.deny = deny;
+ this.activeGrantAndDenial = null;
+ }
+
+// private MicroOperation microOperation;
+// private State state;
+// public GrantAndDenialWrapper( MicroOperation microOperation )
+// {
+// this.microOperation = microOperation;
+// this.state = State.UNSET;
+// }
+// public GrantAndDenial getGrantAndDenial() throws ParseException
+// {
+// String value = "";
+// if(state == State.GRANT) value += "grant";
+// if(state == State.DENY) value += "deny";
+// value += microOperation.getName();
+//
+//
+// String spec = DUMMY;
+// spec = spec.replaceAll( "#value#", value );
+// ACIItemParser parser = new ACIItemParser(null);
+// ItemFirstACIItem aci = ( ItemFirstACIItem ) parser.parse( spec );
+// ItemPermission itemPermission = ( ItemPermission ) aci.getItemPermissions().iterator().next();
+// GrantAndDenial grantAndDenial = ( GrantAndDenial ) itemPermission.getGrantsAndDenials().iterator().next();
+// return grantAndDenial;
+// }
+ }
+
+
+ private Composite composite = null;
+ private Label label = null;
+ private Table table = null;
+ private TableViewer tableViewer = null;
+ private Composite buttonComposite = null;
+ private Button grantAllButton = null;
+ private Button denyAllButton = null;
+ private Button deselectAllButton = null;
+
+ public ACIItemGrantsAndDenialsComposite( Composite parent, int style )
+ {
+ super( parent, style );
+ initialize();
+ }
+
+
+ private void initialize()
+ {
+ setSize( new Point( 300, 200 ) );
+
+ 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.verticalAlignment = GridData.BEGINNING;
+
+ composite = new Composite( this, SWT.NONE );
+ composite.setLayoutData(gridData);
+ composite.setLayout(gridLayout);
+
+ label = new Label(composite, SWT.NONE);
+ label.setText("Grants and Denials:");
+ label.setLayoutData(labelGridData);
+
+ createTable();
+
+ createButtonComposite();
+
+ }
+
+ /**
+ * This method initializes table
+ *
+ */
+ 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.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
+ table.setHeaderVisible(true);
+ table.setLayoutData(tableGridData);
+ table.setLinesVisible(true);
+
+ TableColumn c1 = new TableColumn(table, SWT.LEFT, 0);
+ c1.setText( COLUMNS[0] );
+ c1.setWidth( 160 );
+ TableColumn c2 = new TableColumn(table, SWT.CENTER, 1);
+ c2.setText( COLUMNS[1] );
+ c2.setWidth( 80 );
+ TableColumn c3 = new TableColumn(table, SWT.CENTER, 2);
+ c3.setText( COLUMNS[2] );
+ c3.setWidth( 80 );
+ TableColumn c4 = new TableColumn(table, SWT.LEFT, 3);
+ c4.setText( " " );
+ c4.setWidth( 1 );
+
+ tableViewer = new TableViewer(table);
+ tableViewer.setUseHashlookup(true);
+
+ tableViewer.setColumnProperties( COLUMNS );
+
+ ICellModifier cellModifier = new GrantsAndDenialsCellModifier();
+ tableViewer.setCellModifier( cellModifier );
+ CellEditor[] cellEditors = new CellEditor[]
+ {
+ null,
+ new CheckboxCellEditor(table),
+ new CheckboxCellEditor(table),
+ null
+ };
+ tableViewer.setCellEditors( cellEditors );
+ //tableViewer.setSorter( new ViewerSorter() );
+
+ tableViewer.setContentProvider( new ArrayContentProvider() );
+ tableViewer.setLabelProvider( new GrantsAndDenialsLabelProvider() );
+ tableViewer.setInput( grantAndDenialWrappers );
+
+
+ }
+
+ /**
+ * This method initializes buttonComposite
+ *
+ */
+ private void createButtonComposite()
+ {
+ GridData deselectAllButtonGridData = new GridData();
+ deselectAllButtonGridData.horizontalAlignment = GridData.FILL;
+ deselectAllButtonGridData.grabExcessHorizontalSpace = false;
+ deselectAllButtonGridData.verticalAlignment = GridData.BEGINNING;
+
+ GridData denyAllButtonGridData = new GridData();
+ denyAllButtonGridData.horizontalAlignment = GridData.FILL;
+ denyAllButtonGridData.grabExcessHorizontalSpace = false;
+ denyAllButtonGridData.verticalAlignment = GridData.BEGINNING;
+
+ GridData grantAllButtonGridData = new GridData();
+ grantAllButtonGridData.horizontalAlignment = GridData.FILL;
+ grantAllButtonGridData.grabExcessHorizontalSpace = false;
+ grantAllButtonGridData.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 );
+
+ grantAllButton = new Button(buttonComposite, SWT.NONE);
+ grantAllButton.setText("Grant All");
+ grantAllButton.setLayoutData(grantAllButtonGridData);
+
+ denyAllButton = new Button(buttonComposite, SWT.NONE);
+ denyAllButton.setText("Deny All");
+ denyAllButton.setLayoutData(denyAllButtonGridData);
+
+ deselectAllButton = new Button(buttonComposite, SWT.NONE);
+ deselectAllButton.setText("Deselect All");
+ deselectAllButton.setLayoutData(deselectAllButtonGridData);
+
+ }
+
+ private class GrantsAndDenialsCellModifier implements ICellModifier
+ {
+
+ public boolean canModify( Object element, String property )
+ {
+ //System.out.println("canModify() " + element + " " + property);
+
+ if(element instanceof GrantAndDenialWrapper)
+ {
+ return property.equals( GRANT ) || property.equals( DENY ) ;
+ }
+
+ return false;
+ }
+
+ public Object getValue( Object element, String property )
+ {
+ //System.out.println("getValue() " + element + " " + property);
+
+ if(element instanceof GrantAndDenialWrapper)
+ {
+ GrantAndDenialWrapper i = (GrantAndDenialWrapper) element;
+ if( property.equals( GRANT ) )
+ {
+ return new Boolean( i.activeGrantAndDenial == i.grant );
+ }
+ else if( property.equals( DENY ) )
+ {
+ return new Boolean( i.activeGrantAndDenial == i.deny );
+ }
+ }
+
+ return null;
+ }
+
+ public void modify( Object element, String property, Object value )
+ {
+ if ( element != null && element instanceof Item )
+ {
+ element = ( ( Item ) element ).getData();
+ }
+
+ //System.out.println("modify() " + element + " " + property + " " + value);
+
+ if(element instanceof GrantAndDenialWrapper)
+ {
+ GrantAndDenialWrapper i = (GrantAndDenialWrapper) element;
+ Boolean b = (Boolean) value;
+ if( property.equals( GRANT ) )
+ {
+ i.activeGrantAndDenial = b ? i.grant : null;
+ }
+ else if( property.equals( DENY ) )
+ {
+ i.activeGrantAndDenial = b ? i.deny : null;
+ }
+
+ //System.out.println("modify() " + property + " " + value + " = " + i.state);
+
+ }
+
+ tableViewer.refresh();
+ }
+
+ }
+
+ private class GrantsAndDenialsLabelProvider extends LabelProvider implements ITableLabelProvider
+ {
+
+ public Image getColumnImage( Object element, int columnIndex )
+ {
+ if ( element instanceof GrantAndDenialWrapper )
+ {
+ GrantAndDenialWrapper i = ( GrantAndDenialWrapper ) element;
+ switch ( columnIndex )
+ {
+ case 0:
+ return null;
+ case 1:
+ return i.activeGrantAndDenial == i.grant ?
+ Activator.getDefault().getImage( "icons/checkbox_checked.gif" )
+ : Activator.getDefault().getImage( "icons/checkbox_unchecked.gif" );
+ case 2:
+ return i.activeGrantAndDenial == i.deny ? Activator.getDefault().getImage( "icons/checkbox_checked.gif" )
+ : Activator.getDefault().getImage( "icons/checkbox_unchecked.gif" );
+ }
+ }
+ return null;
+ }
+
+ public String getColumnText( Object element, int columnIndex )
+ {
+ if(element instanceof GrantAndDenialWrapper)
+ {
+ if(columnIndex == 0)
+ {
+ GrantAndDenialWrapper i = (GrantAndDenialWrapper) element;
+ return i.grant.getMicroOperation().getName();
+ }
+ }
+
+ return "";
+ }
+ }
+
+
+ /**
+ * Sets the grants and denials.
+ *
+ * @param set
+ */
+ public void setGrantsAndDenials( Collection<GrantAndDenial> grantsAndDenials )
+ {
+ for ( GrantAndDenial grantAndDenial : grantsAndDenials )
+ {
+ for(int i=0; i<grantAndDenialWrappers.length; i++)
+ {
+ GrantAndDenialWrapper grantAndDenialWrapper = grantAndDenialWrappers[i];
+
+ if( grantAndDenialWrapper.grant == grantAndDenial )
+ {
+ grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.grant;
+ }
+ else if( grantAndDenialWrapper.deny == grantAndDenial )
+ {
+ grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.deny;
+ }
+ }
+ }
+
+ tableViewer.refresh();
+ }
+
+ /**
+ * Returns the grants and denials as selected by the user.
+ *
+ * @return the grants and denials
+ * @throws ParseException
+ */
+ public Collection<GrantAndDenial> getGrantsAndDenials() throws ParseException
+ {
+ Collection<GrantAndDenial> grantsAndDenials = new ArrayList<GrantAndDenial>();
+
+ for(int i=0; i<grantAndDenialWrappers.length; i++)
+ {
+ GrantAndDenialWrapper grantAndDenialWrapper = grantAndDenialWrappers[i];
+ if( grantAndDenialWrapper.activeGrantAndDenial != null )
+ {
+ grantsAndDenials.add( grantAndDenialWrapper.activeGrantAndDenial );
+ }
+ }
+
+ return grantsAndDenials;
+
+ }
+
+}
Added: directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java?view=auto&rev=490383
==============================================================================
--- directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java (added)
+++ directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java Tue Dec 26 13:47:13 2006
@@ -0,0 +1,555 @@
+/*
+ * 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.UserClassDialog;
+import org.apache.directory.shared.ldap.aci.ItemPermission;
+import org.apache.directory.shared.ldap.aci.UserClass;
+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 classes.
+
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIItemItemPermissionsComposite 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 classes, also input of the table viewer */
+ List<UserClassWrapper> userClasses = new ArrayList<UserClassWrapper>();
+
+
+ private class UserClassWrapper
+ {
+ /** The class of the user class, never null. */
+ private final Class userClassClass;
+
+ /** The user class bean, may be null. */
+ private UserClass userClass;
+
+ /** The user class as string, may be null. */
+ private String userClassValue;
+
+ /**
+ * Creates a new instance of UserClassWrapper.
+ *
+ * @param userClassClass
+ */
+ public UserClassWrapper( Class userClassClass )
+ {
+ this.userClassClass = userClassClass;
+ this.userClass = null;
+ this.userClassValue = null;
+ }
+
+ public String toString()
+ {
+ if(userClassClass == UserClass.AllUsers.class)
+ {
+ return "All Users";
+ }
+ else if(userClassClass == UserClass.ThisEntry.class)
+ {
+ return "This Entry";
+ }
+ else if(userClassClass == UserClass.Name.class)
+ {
+ return "Name" + getUserClassValue();
+ }
+ else if(userClassClass == UserClass.UserGroup.class)
+ {
+ return "User Group" + getUserClassValue();
+ }
+ else if(userClassClass == UserClass.Subtree.class)
+ {
+ return "Subtree" + getUserClassValue();
+ }
+
+ return "<UNKNOWN>";
+ }
+ private String getUserClassValue()
+ {
+ if(userClassValue == null)
+ {
+ return " ...";
+ }
+ else
+ {
+ String s = userClassValue;
+ 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 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 );
+
+ 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 Classes:");
+ 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( userClasses );
+
+ tableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ userClassSelected();
+ }
+ } );
+
+ tableViewer.addDoubleClickListener( new IDoubleClickListener(){
+ public void doubleClick( DoubleClickEvent event )
+ {
+ editUserClass();
+ }
+ } );
+ }
+
+
+ /**
+ * 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 )
+ {
+ addUserClass();
+ }
+ } );
+
+ editButton = new Button(buttonComposite, SWT.NONE);
+ editButton.setText("Edit...");
+ editButton.setLayoutData(editButtonGridData);
+ editButton.addSelectionListener( new SelectionAdapter(){
+ public void widgetSelected( SelectionEvent e )
+ {
+ editUserClass();
+ }
+ } );
+ editButton.setEnabled( false );
+
+ deleteButton = new Button(buttonComposite, SWT.NONE);
+ deleteButton.setText("Delete");
+ deleteButton.setLayoutData(deleteButtonGridData);
+ deleteButton.addSelectionListener( new SelectionAdapter(){
+ public void widgetSelected( SelectionEvent e )
+ {
+ deleteUserClass();
+ }
+ } );
+ deleteButton.setEnabled( false );
+
+ }
+
+
+
+
+
+// public void setUserClasses( List<UserClass> userClasses )
+// {
+// //this.userClasses = userClasses;
+//
+// for ( UserClass userClass : userClasses )
+// {
+// if ( userClass instanceof UserClass.AllUsers )
+// {
+// allUsersCheckBox.setSelection( true );
+// }
+// if ( userClass instanceof UserClass.ThisEntry )
+// {
+// thisEntryCheckBox.setSelection( true );
+// }
+// if ( userClass instanceof UserClass.Name )
+// {
+// nameCheckBox.setSelection( true );
+// UserClass.Name name = ( UserClass.Name ) userClass;
+// nameLabel.setText( getNumValuesText( name.getNames() ) );
+// nameNames = ( Set<LdapDN> ) name.getNames();
+// }
+// if ( userClass instanceof UserClass.UserGroup )
+// {
+// userGroupCheckBox.setSelection( true );
+// UserClass.UserGroup userGroup = ( UserClass.UserGroup ) userClass;
+// userGroupLabel.setText( getNumValuesText( userGroup.getNames() ) );
+// userGroupNames = ( Set<LdapDN> ) userGroup.getNames();
+// }
+// if ( userClass instanceof UserClass.Subtree )
+// {
+// subtreeCheckBox.setSelection( true );
+// UserClass.Subtree subtree = ( UserClass.Subtree ) userClass;
+// subtreeLabel.setText( getNumValuesText( subtree.getSubtreeSpecifications() ) );
+// subtreeSpecifications = ( Collection<SubtreeSpecification> ) subtree.getSubtreeSpecifications();
+// }
+// }
+// }
+
+
+
+
+// public List<UserClass> getUserClasses()
+// {
+//
+// List<UserClass> userClasses = new ArrayList<UserClass>();
+//
+// if ( allUsersCheckBox.getSelection() )
+// {
+// userClasses.add( UserClass.ALL_USERS );
+// }
+// if ( thisEntryCheckBox.getSelection() )
+// {
+// userClasses.add( UserClass.THIS_ENTRY );
+// }
+// if ( nameCheckBox.getSelection() )
+// {
+//
+// }
+// if ( userGroupCheckBox.getSelection() )
+// {
+//
+// }
+// if ( subtreeCheckBox.getSelection() )
+// {
+//
+// }
+//
+// return userClasses;
+//
+// }
+//
+
+ public void setVisible( boolean visible )
+ {
+ super.setVisible( visible );
+ ((GridData)getLayoutData()).heightHint = visible ? -1 : 0;
+ }
+
+
+
+ /**
+ * Sets the item permissions.
+ *
+ * @param protectedItems
+ */
+ public void setItemPermissions( Collection<ItemPermission> itemPermissions )
+ {
+ // TODO
+// for ( ProtectedItem item : protectedItems )
+// {
+// for(int i=0; i<protectedItemWrappers.length; i++)
+// {
+// ProtectedItemWrapper protectedItemWrapper = protectedItemWrappers[i];
+//
+// if( protectedItemWrapper.protectedItemClass == item.getClass() )
+// {
+// StringBuffer buffer = new StringBuffer();
+// item.printToBuffer( buffer );
+// String s = buffer.toString();
+// if(s.indexOf( ' ' ) > -1)
+// {
+// s = s.substring( s.indexOf( ' ' ), s.length() );
+// }
+// protectedItemWrapper.protectedItemValue = s;
+// tableViewer.setChecked( protectedItemWrapper, true );
+// }
+// }
+// }
+//
+// tableViewer.refresh();
+ }
+
+
+ /**
+ * Returns the item permissions as selected by the user.
+ *
+ * @return the item permissions
+ * @throws ParseException
+ */
+ public Collection<ItemPermission> getItemPermissions() throws ParseException
+ {
+
+ Collection<ItemPermission> itemPermissions = new ArrayList<ItemPermission>();
+
+ // TODO
+// this.
+//
+// for(int i=0; i<protectedItemWrappers.length; i++)
+// {
+// ProtectedItemWrapper protectedItemWrapper = protectedItemWrappers[i];
+// if(tableViewer.getChecked( protectedItemWrapper ) )
+// {
+// protectedItems.add( protectedItemWrapper.getProtectedItem() );
+// }
+// }
+
+ return itemPermissions;
+
+ }
+
+ /**
+ *
+ * @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;
+ }
+
+
+ private void addUserClass()
+ {
+ UserClassDialog dialog = new UserClassDialog( getShell(), null, null );
+ if ( dialog.open() == TextDialog.OK && dialog.getUserClassClass() != null )
+ {
+ UserClassWrapper userClassWrapper = new UserClassWrapper(dialog.getUserClassClass());
+ userClassWrapper.userClassValue = dialog.getText();
+ userClasses.add( userClassWrapper );
+
+ tableViewer.refresh();
+ }
+ }
+
+
+ private void editUserClass()
+ {
+ UserClassWrapper oldUserClassWrapper = getSelectedUserClassWrapper();
+ if(oldUserClassWrapper != null)
+ {
+ UserClassDialog dialog = new UserClassDialog( getShell(), oldUserClassWrapper.userClassClass, oldUserClassWrapper.userClassValue );
+ if ( dialog.open() == TextDialog.OK )
+ {
+ // remove old
+ userClasses.remove( oldUserClassWrapper );
+
+ // create and add new
+ UserClassWrapper newUserClassWrapper = new UserClassWrapper(dialog.getUserClassClass());
+ newUserClassWrapper.userClassValue = dialog.getText();
+ userClasses.add( newUserClassWrapper );
+
+ tableViewer.refresh();
+ }
+ }
+ }
+
+
+ private void deleteUserClass()
+ {
+ UserClassWrapper userClassWrapper = getSelectedUserClassWrapper();
+ if(userClassWrapper != null)
+ {
+ userClasses.remove( userClassWrapper );
+ tableViewer.refresh();
+ }
+ }
+
+
+ private void userClassSelected()
+ {
+ UserClassWrapper userClassWrapper = getSelectedUserClassWrapper();
+
+ if ( userClassWrapper == 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/ACIItemProtectedItemsComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java?view=auto&rev=490383
==============================================================================
--- directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java (added)
+++ directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java Tue Dec 26 13:47:13 2006
@@ -0,0 +1,600 @@
+/*
+ * 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.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.aciitemeditor.dialogs.TextDialog;
+import org.apache.directory.shared.ldap.aci.ACIItem;
+import org.apache.directory.shared.ldap.aci.ACIItemParser;
+import org.apache.directory.shared.ldap.aci.ItemFirstACIItem;
+import org.apache.directory.shared.ldap.aci.ProtectedItem;
+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.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;
+import org.eclipse.swt.widgets.TableItem;
+
+
+/**
+ * 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 protected items used as input for the table viewer */
+ private ProtectedItemWrapper[] protectedItemWrappers = new ProtectedItemWrapper[]
+ {
+ new ProtectedItemWrapper(ProtectedItem.Entry.class), // null
+ new ProtectedItemWrapper(ProtectedItem.AllUserAttributeTypes.class), // null
+ new ProtectedItemWrapper(ProtectedItem.AttributeType.class), // attributeType { 1.2.3, cn }
+ new ProtectedItemWrapper(ProtectedItem.AllAttributeValues.class), // allAttributeValues { 1.2.3, cn }
+ new ProtectedItemWrapper(ProtectedItem.AllUserAttributeTypesAndValues.class), // null
+ new ProtectedItemWrapper(ProtectedItem.AttributeValue.class), // attributeValue { ou=people, cn=Ersin }
+ new ProtectedItemWrapper(ProtectedItem.SelfValue.class), // selfValue { 1.2.3, cn }
+ new ProtectedItemWrapper(ProtectedItem.RangeOfValues.class), // rangeOfValues (cn=ErsinEr)
+ new ProtectedItemWrapper(ProtectedItem.MaxValueCount.class), // maxValueCount { { type 10.11.12, maxCount 10 }, { maxCount 20, type 11.12.13 } }
+ new ProtectedItemWrapper(ProtectedItem.MaxImmSub.class), // maxImmSub 3
+ new ProtectedItemWrapper(ProtectedItem.RestrictedBy.class), // restrictedBy { { type 10.11.12, valuesIn ou }, { valuesIn cn, type 11.12.13 } }
+ new ProtectedItemWrapper(ProtectedItem.Classes.class), // classes and : { item: xyz , or:{item:X,item:Y} }
+ };
+
+ private class ProtectedItemWrapper
+ {
+ private static final String DUMMY =
+ "{ identificationTag \"id1\", precedence 1, authenticationLevel simple, "
+ + "itemOrUserFirst itemFirst: { protectedItems { #item# #value# }, "
+ + "itemPermissions { { userClasses { allUsers }, grantsAndDenials { grantRead } } }"
+ + " } }";
+
+ /** The class of the protected item, never null. */
+ private final Class protectedItemClass;
+
+ /** The protected item as string, may be null. */
+ private String protectedItemValue;
+
+ /**
+ * Creates a new instance of ProtectedItemWrapper.
+ *
+ * @param protectedItemClass
+ */
+ public ProtectedItemWrapper( Class protectedItemClass )
+ {
+ this.protectedItemClass = protectedItemClass;
+ this.protectedItemValue = "";
+ }
+
+ public ProtectedItem getProtectedItem() throws ParseException
+ {
+ String type = "";
+
+ if(protectedItemClass == ProtectedItem.Entry.class)
+ {
+ type = "entry";
+ }
+ else if(protectedItemClass == ProtectedItem.AllUserAttributeTypes.class)
+ {
+ type = "allUserAttributeTypes";
+ }
+ else if(protectedItemClass == ProtectedItem.AttributeType.class)
+ {
+ type = "attributeType";
+ }
+ else if(protectedItemClass == ProtectedItem.AllAttributeValues.class)
+ {
+ type = "allAttributeValues";
+ }
+ else if(protectedItemClass == ProtectedItem.AllUserAttributeTypesAndValues.class)
+ {
+ type = "allUserAttributeTypesAndValues";
+ }
+ else if(protectedItemClass == ProtectedItem.AttributeValue.class)
+ {
+ type = "attributeValue";
+ }
+ else if(protectedItemClass == ProtectedItem.SelfValue.class)
+ {
+ type = "selfValue";
+ }
+ else if(protectedItemClass == ProtectedItem.RangeOfValues.class)
+ {
+ type = "rangeOfValues";
+ }
+ else if(protectedItemClass == ProtectedItem.MaxValueCount.class)
+ {
+ type = "maxValueCount";
+ }
+ else if(protectedItemClass == ProtectedItem.MaxImmSub.class)
+ {
+ type = "maxImmSub";
+ }
+ else if(protectedItemClass == ProtectedItem.RestrictedBy.class)
+ {
+ type = "restrictedBy";
+ }
+ else if(protectedItemClass == ProtectedItem.Classes.class)
+ {
+ type = "classes";
+ }
+
+ String spec = DUMMY;
+ spec = spec.replaceAll( "#item#", type );
+ spec = spec.replaceAll( "#value#", protectedItemValue );
+ ACIItemParser parser = new ACIItemParser(null);
+ ItemFirstACIItem aci = ( ItemFirstACIItem ) parser.parse( spec );
+ ProtectedItem item = ( ProtectedItem ) aci.getProtectedItems().iterator().next();
+ return item;
+ }
+
+ public String toString()
+ {
+ if(protectedItemClass == ProtectedItem.Entry.class)
+ {
+ return "Entry";
+ }
+ else if(protectedItemClass == ProtectedItem.AllUserAttributeTypes.class)
+ {
+ return "All User Attribute Types";
+ }
+ else if(protectedItemClass == ProtectedItem.AttributeType.class)
+ {
+ return "Attribute Type" + getProtectedItemValue();
+ }
+ else if(protectedItemClass == ProtectedItem.AllAttributeValues.class)
+ {
+ return "All Attribute Values" + getProtectedItemValue();
+ }
+ else if(protectedItemClass == ProtectedItem.AllUserAttributeTypesAndValues.class)
+ {
+ return "All User Attribute Types and Values";
+ }
+ else if(protectedItemClass == ProtectedItem.AttributeValue.class)
+ {
+ return "Attribute Value" + getProtectedItemValue();
+ }
+ else if(protectedItemClass == ProtectedItem.SelfValue.class)
+ {
+ return "Self Value" + getProtectedItemValue();
+ }
+ else if(protectedItemClass == ProtectedItem.RangeOfValues.class)
+ {
+ return "Range of Values" + getProtectedItemValue();
+ }
+ else if(protectedItemClass == ProtectedItem.MaxValueCount.class)
+ {
+ return "Max. Value Count" + getProtectedItemValue();
+ }
+ else if(protectedItemClass == ProtectedItem.MaxImmSub.class)
+ {
+ return "Max. Number of Immediate Subordinates" + getProtectedItemValue();
+ }
+ else if(protectedItemClass == ProtectedItem.RestrictedBy.class)
+ {
+ return "Restricted by" + getProtectedItemValue();
+ }
+ else if(protectedItemClass == ProtectedItem.Classes.class)
+ {
+ return "Classes" + getProtectedItemValue();
+ }
+
+ return "<UNKNOWN>";
+ }
+
+ private String getProtectedItemValue()
+ {
+ String s = protectedItemValue;
+ 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;
+ }
+ }
+
+ /** 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;
+
+
+ /**
+ * Creates a new instance of ACIItemProtectedItemsComposite.
+ *
+ * @param parent
+ * @param style
+ */
+ public ACIItemProtectedItemsComposite( Composite parent, int style )
+ {
+ super( parent, style );
+
+ //setSize( new Point( 300, 200 ) );
+
+ 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("Protected Items:");
+ 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( true );
+ tableViewer = new CheckboxTableViewer( table );
+ tableViewer.setContentProvider( new ArrayContentProvider() );
+ tableViewer.setLabelProvider( new LabelProvider() );
+ 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 )
+ {
+ editProtectedItem();
+ }
+ } );
+ }
+
+
+ /**
+ * This method initializes buttons
+ *
+ */
+ private void createButtonComposite()
+ {
+ GridData reverseSelectionButtonGridData = new GridData();
+ reverseSelectionButtonGridData.horizontalAlignment = GridData.FILL;
+ reverseSelectionButtonGridData.grabExcessHorizontalSpace = false;
+ reverseSelectionButtonGridData.verticalAlignment = GridData.BEGINNING;
+
+ GridData deselectAllButtonGridData = new GridData();
+ deselectAllButtonGridData.horizontalAlignment = GridData.FILL;
+ deselectAllButtonGridData.grabExcessHorizontalSpace = false;
+ deselectAllButtonGridData.verticalAlignment = GridData.BEGINNING;
+
+ GridData selectAllButtonGridData = new GridData();
+ selectAllButtonGridData.horizontalAlignment = GridData.FILL;
+ selectAllButtonGridData.grabExcessHorizontalSpace = false;
+ selectAllButtonGridData.verticalAlignment = GridData.BEGINNING;
+
+ GridData editButtonGridData = new GridData();
+ editButtonGridData.horizontalAlignment = GridData.FILL;
+ editButtonGridData.grabExcessHorizontalSpace = false;
+ editButtonGridData.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 );
+
+ editButton = new Button(buttonComposite, SWT.NONE);
+ editButton.setText("Edit...");
+ editButton.setLayoutData(editButtonGridData);
+ editButton.addSelectionListener( new SelectionAdapter(){
+ public void widgetSelected( SelectionEvent e )
+ {
+ editProtectedItem();
+ }
+ } );
+ editButton.setEnabled( false );
+
+ selectAllButton = new Button(buttonComposite, SWT.NONE);
+ selectAllButton.setText("Select All");
+ selectAllButton.setLayoutData(selectAllButtonGridData);
+ selectAllButton.addSelectionListener( new SelectionAdapter(){
+ public void widgetSelected( SelectionEvent e )
+ {
+ tableViewer.setCheckedElements( protectedItemWrappers );
+ }
+ } );
+
+ deselectAllButton = new Button(buttonComposite, SWT.NONE);
+ deselectAllButton.setText("Deselect All");
+ deselectAllButton.setLayoutData(deselectAllButtonGridData);
+ deselectAllButton.addSelectionListener( new SelectionAdapter(){
+ public void widgetSelected( SelectionEvent e )
+ {
+ tableViewer.setCheckedElements( new ProtectedItem[0] );
+ }
+ } );
+
+ reverseSelectionButton = new Button(buttonComposite, SWT.NONE);
+ reverseSelectionButton.setText("Reverse");
+ 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() );
+
+ }
+ } );
+
+ }
+
+
+ /**
+ * Sets the protected items.
+ *
+ * @param protectedItems
+ */
+ public void setProtectedItems( Collection<ProtectedItem> protectedItems )
+ {
+ for ( ProtectedItem item : protectedItems )
+ {
+ for(int i=0; i<protectedItemWrappers.length; i++)
+ {
+ ProtectedItemWrapper protectedItemWrapper = protectedItemWrappers[i];
+
+ if( protectedItemWrapper.protectedItemClass == item.getClass() )
+ {
+ StringBuffer buffer = new StringBuffer();
+ item.printToBuffer( buffer );
+ String s = buffer.toString();
+ if(s.indexOf( ' ' ) > -1)
+ {
+ s = s.substring( s.indexOf( ' ' ), s.length() );
+ protectedItemWrapper.protectedItemValue = s;
+ }
+ tableViewer.setChecked( protectedItemWrapper, true );
+ }
+ }
+ }
+
+ tableViewer.refresh();
+ }
+
+
+ /**
+ * Returns the protected items as selected by the user.
+ *
+ * @return the protected items
+ * @throws ParseException
+ */
+ public Collection<ProtectedItem> getProtectedItems() throws ParseException
+ {
+
+ Collection<ProtectedItem> protectedItems = new ArrayList<ProtectedItem>();
+
+ for(int i=0; i<protectedItemWrappers.length; i++)
+ {
+ ProtectedItemWrapper protectedItemWrapper = protectedItemWrappers[i];
+ if(tableViewer.getChecked( protectedItemWrapper ) )
+ {
+ protectedItems.add( protectedItemWrapper.getProtectedItem() );
+ }
+ }
+
+ return protectedItems;
+
+ }
+
+
+ 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.protectedItemClass == ProtectedItem.Entry.class
+ || protectedItemWrapper.protectedItemClass == ProtectedItem.AllUserAttributeTypes.class
+ || protectedItemWrapper.protectedItemClass == ProtectedItem.AllUserAttributeTypesAndValues.class )
+ {
+ editButton.setEnabled( false );
+ }
+ else
+ {
+ editButton.setEnabled( true );
+ }
+ }
+
+
+ private void protectedItemChecked()
+ {
+
+ }
+
+
+ /**
+ * Caled, when pushing the edit button. Opens the text editor.
+ *
+ */
+ private void editProtectedItem()
+ {
+ ProtectedItemWrapper protectedItemWrapper = getSelectedProtectedItemWrapper();
+
+ TextDialog dialog = new TextDialog( getShell(), protectedItemWrapper.protectedItemValue );
+ if ( dialog.open() == TextDialog.OK )
+ {
+ protectedItemWrapper.protectedItemValue = dialog.getText();
+ tableViewer.refresh();
+ }
+
+ }
+
+
+}
Added: directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemUserClassesComposite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemUserClassesComposite.java?view=auto&rev=490383
==============================================================================
--- directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemUserClassesComposite.java (added)
+++ directory/sandbox/seelmann/trunk/ldapstudio-aciitemeditor/src/org/apache/directory/ldapstudio/aciitemeditor/widgets/ACIItemUserClassesComposite.java Tue Dec 26 13:47:13 2006
@@ -0,0 +1,579 @@
+/*
+ * 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.UserClassDialog;
+import org.apache.directory.shared.ldap.aci.ACIItemParser;
+import org.apache.directory.shared.ldap.aci.ProtectedItem;
+import org.apache.directory.shared.ldap.aci.UserClass;
+import org.apache.directory.shared.ldap.aci.UserFirstACIItem;
+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 classes.
+
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIItemUserClassesComposite 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 classes, also input of the table viewer */
+ List<UserClassWrapper> userClassWrappers = new ArrayList<UserClassWrapper>();
+
+
+ private class UserClassWrapper
+ {
+ private static final String DUMMY =
+ "{ identificationTag \"id1\", precedence 1, authenticationLevel simple, "
+ + "itemOrUserFirst userFirst: { userClasses { #item# #value# }, "
+ + "userPermissions { { protectedItems { entry }, grantsAndDenials { grantRead } } }"
+ + " } }";
+
+ /** The class of the user class, never null. */
+ private final Class userClassClass;
+
+ /** The user class as string, may be null. */
+ private String userClassValue;
+
+ /**
+ * Creates a new instance of UserClassWrapper.
+ *
+ * @param userClassClass
+ */
+ public UserClassWrapper( Class userClassClass )
+ {
+ this.userClassClass = userClassClass;
+ this.userClassValue = null;
+ }
+
+ public UserClass getUserClass() throws ParseException
+ {
+ String type = "";
+
+ if(userClassClass == UserClass.AllUsers.class)
+ {
+ type = "allUsers";
+ }
+ else if(userClassClass == UserClass.ThisEntry.class)
+ {
+ type = "thisEntry";
+ }
+ else if(userClassClass == UserClass.Name.class)
+ {
+ type = "name";
+ }
+ else if(userClassClass == UserClass.UserGroup.class)
+ {
+ type = "userGroup";
+ }
+ else if(userClassClass == UserClass.Subtree.class)
+ {
+ type = "subtree";
+ }
+
+ String spec = DUMMY;
+ spec = spec.replaceAll( "#item#", type );
+ spec = spec.replaceAll( "#value#", userClassValue );
+ ACIItemParser parser = new ACIItemParser(null);
+ UserFirstACIItem aci = ( UserFirstACIItem ) parser.parse( spec );
+ UserClass userClass = ( UserClass ) aci.getUserClasses().iterator().next();
+ return userClass;
+ }
+
+ public String toString()
+ {
+ if(userClassClass == UserClass.AllUsers.class)
+ {
+ return "All Users";
+ }
+ else if(userClassClass == UserClass.ThisEntry.class)
+ {
+ return "This Entry";
+ }
+ else if(userClassClass == UserClass.Name.class)
+ {
+ return "Name" + getUserClassValue();
+ }
+ else if(userClassClass == UserClass.UserGroup.class)
+ {
+ return "User Group" + getUserClassValue();
+ }
+ else if(userClassClass == UserClass.Subtree.class)
+ {
+ return "Subtree" + getUserClassValue();
+ }
+
+ return "<UNKNOWN>";
+ }
+ private String getUserClassValue()
+ {
+ if(userClassValue == null)
+ {
+ return " ...";
+ }
+ else
+ {
+ String s = userClassValue;
+ 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 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 );
+
+ 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 Classes:");
+ 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( userClassWrappers );
+
+ tableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ userClassSelected();
+ }
+ } );
+
+ tableViewer.addDoubleClickListener( new IDoubleClickListener(){
+ public void doubleClick( DoubleClickEvent event )
+ {
+ editUserClass();
+ }
+ } );
+ }
+
+
+ /**
+ * 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 )
+ {
+ addUserClass();
+ }
+ } );
+
+ editButton = new Button(buttonComposite, SWT.NONE);
+ editButton.setText("Edit...");
+ editButton.setLayoutData(editButtonGridData);
+ editButton.addSelectionListener( new SelectionAdapter(){
+ public void widgetSelected( SelectionEvent e )
+ {
+ editUserClass();
+ }
+ } );
+ editButton.setEnabled( false );
+
+ deleteButton = new Button(buttonComposite, SWT.NONE);
+ deleteButton.setText("Delete");
+ deleteButton.setLayoutData(deleteButtonGridData);
+ deleteButton.addSelectionListener( new SelectionAdapter(){
+ public void widgetSelected( SelectionEvent e )
+ {
+ deleteUserClass();
+ }
+ } );
+ deleteButton.setEnabled( false );
+
+ }
+
+
+
+
+
+// public void setUserClasses( List<UserClass> userClasses )
+// {
+// //this.userClasses = userClasses;
+//
+// for ( UserClass userClass : userClasses )
+// {
+// if ( userClass instanceof UserClass.AllUsers )
+// {
+// allUsersCheckBox.setSelection( true );
+// }
+// if ( userClass instanceof UserClass.ThisEntry )
+// {
+// thisEntryCheckBox.setSelection( true );
+// }
+// if ( userClass instanceof UserClass.Name )
+// {
+// nameCheckBox.setSelection( true );
+// UserClass.Name name = ( UserClass.Name ) userClass;
+// nameLabel.setText( getNumValuesText( name.getNames() ) );
+// nameNames = ( Set<LdapDN> ) name.getNames();
+// }
+// if ( userClass instanceof UserClass.UserGroup )
+// {
+// userGroupCheckBox.setSelection( true );
+// UserClass.UserGroup userGroup = ( UserClass.UserGroup ) userClass;
+// userGroupLabel.setText( getNumValuesText( userGroup.getNames() ) );
+// userGroupNames = ( Set<LdapDN> ) userGroup.getNames();
+// }
+// if ( userClass instanceof UserClass.Subtree )
+// {
+// subtreeCheckBox.setSelection( true );
+// UserClass.Subtree subtree = ( UserClass.Subtree ) userClass;
+// subtreeLabel.setText( getNumValuesText( subtree.getSubtreeSpecifications() ) );
+// subtreeSpecifications = ( Collection<SubtreeSpecification> ) subtree.getSubtreeSpecifications();
+// }
+// }
+// }
+
+
+
+
+// public List<UserClass> getUserClasses()
+// {
+//
+// List<UserClass> userClasses = new ArrayList<UserClass>();
+//
+// if ( allUsersCheckBox.getSelection() )
+// {
+// userClasses.add( UserClass.ALL_USERS );
+// }
+// if ( thisEntryCheckBox.getSelection() )
+// {
+// userClasses.add( UserClass.THIS_ENTRY );
+// }
+// if ( nameCheckBox.getSelection() )
+// {
+//
+// }
+// if ( userGroupCheckBox.getSelection() )
+// {
+//
+// }
+// if ( subtreeCheckBox.getSelection() )
+// {
+//
+// }
+//
+// return userClasses;
+//
+// }
+//
+
+ public void setVisible( boolean visible )
+ {
+ super.setVisible( visible );
+ ((GridData)getLayoutData()).heightHint = visible ? -1 : 0;
+ }
+
+
+ /**
+ * Sets the user classes.
+ *
+ * @param userClasses
+ */
+ public void setUserClasses( Collection<UserClass> userClasses )
+ {
+ for ( UserClass userClass : userClasses )
+ {
+
+ UserClassWrapper userClassWrapper = new UserClassWrapper(userClass.getClass());
+
+ StringBuffer buffer = new StringBuffer();
+ userClass.printToBuffer( buffer );
+ String s = buffer.toString();
+ if(s.indexOf( ' ' ) > -1)
+ {
+ s = s.substring( s.indexOf( ' ' ), s.length() );
+ }
+ userClassWrapper.userClassValue = s;
+ }
+
+ tableViewer.refresh();
+ }
+
+
+ /**
+ * Returns the user classes as selected by the user.
+ *
+ * @return the user classes
+ * @throws ParseException
+ */
+ public Collection<UserClass> getUserClasses() throws ParseException
+ {
+
+ Collection<UserClass> userClasses = new ArrayList<UserClass>();
+
+ for ( UserClassWrapper userClassWrapper : this.userClassWrappers )
+ {
+ UserClass userClass = userClassWrapper.getUserClass();
+ userClasses.add( userClass );
+ }
+
+ return userClasses;
+
+ }
+
+ /**
+ *
+ * @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;
+ }
+
+
+ private void addUserClass()
+ {
+ UserClassDialog dialog = new UserClassDialog( getShell(), null, null );
+ if ( dialog.open() == TextDialog.OK && dialog.getUserClassClass() != null )
+ {
+ UserClassWrapper userClassWrapper = new UserClassWrapper(dialog.getUserClassClass());
+ userClassWrapper.userClassValue = dialog.getText();
+ userClassWrappers.add( userClassWrapper );
+
+ tableViewer.refresh();
+ }
+ }
+
+
+ private void editUserClass()
+ {
+ UserClassWrapper oldUserClassWrapper = getSelectedUserClassWrapper();
+ if(oldUserClassWrapper != null)
+ {
+ UserClassDialog dialog = new UserClassDialog( getShell(), oldUserClassWrapper.userClassClass, oldUserClassWrapper.userClassValue );
+ if ( dialog.open() == TextDialog.OK )
+ {
+ // remove old
+ userClassWrappers.remove( oldUserClassWrapper );
+
+ // create and add new
+ UserClassWrapper newUserClassWrapper = new UserClassWrapper(dialog.getUserClassClass());
+ newUserClassWrapper.userClassValue = dialog.getText();
+ userClassWrappers.add( newUserClassWrapper );
+
+ tableViewer.refresh();
+ }
+ }
+ }
+
+
+ private void deleteUserClass()
+ {
+ UserClassWrapper userClassWrapper = getSelectedUserClassWrapper();
+ if(userClassWrapper != null)
+ {
+ userClassWrappers.remove( userClassWrapper );
+ tableViewer.refresh();
+ }
+ }
+
+
+ private void userClassSelected()
+ {
+ UserClassWrapper userClassWrapper = getSelectedUserClassWrapper();
+
+ if ( userClassWrapper == null )
+ {
+ editButton.setEnabled( false );
+ deleteButton.setEnabled( false );
+ }
+ else
+ {
+ editButton.setEnabled( true );
+ deleteButton.setEnabled( true );
+ }
+ }
+
+}