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 [2/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/model/ProtectedItemWrapper.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapper.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapper.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapper.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,415 @@
+/*
+ * 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.model;
+
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+
+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.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.osgi.util.NLS;
+
+
+/**
+ * The ProtectedItemWrapper is used as input for the table viewer.
+ * The protected item values are always stored as raw string value.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ProtectedItemWrapper
+{
+ /** This map contains all possible protected item identifiers */
+ public static final Map<Class, String> classToIdentifierMap;
+ static
+ {
+ Map<Class, String> map = new HashMap<Class, String>();
+ map.put( ProtectedItem.Entry.class, "entry" ); //$NON-NLS-1$
+ map.put( ProtectedItem.AllUserAttributeTypes.class, "allUserAttributeTypes" ); //$NON-NLS-1$
+ map.put( ProtectedItem.AttributeType.class, "attributeType" ); //$NON-NLS-1$
+ map.put( ProtectedItem.AllAttributeValues.class, "allAttributeValues" ); //$NON-NLS-1$
+ map.put( ProtectedItem.AllUserAttributeTypesAndValues.class, "allUserAttributeTypesAndValues" ); //$NON-NLS-1$
+ map.put( ProtectedItem.AttributeValue.class, "attributeValue" ); //$NON-NLS-1$
+ map.put( ProtectedItem.SelfValue.class, "selfValue" ); //$NON-NLS-1$
+ map.put( ProtectedItem.RangeOfValues.class, "rangeOfValues" ); //$NON-NLS-1$
+ map.put( ProtectedItem.MaxValueCount.class, "maxValueCount" ); //$NON-NLS-1$
+ map.put( ProtectedItem.MaxImmSub.class, "maxImmSub" ); //$NON-NLS-1$
+ map.put( ProtectedItem.RestrictedBy.class, "restrictedBy" ); //$NON-NLS-1$
+ map.put( ProtectedItem.Classes.class, "classes" ); //$NON-NLS-1$
+ classToIdentifierMap = Collections.unmodifiableMap( map );
+ }
+
+ /** This map contains all protected item display values */
+ public static final Map<Class, String> classToDisplayMap;
+ static
+ {
+ Map<Class, String> map = new HashMap<Class, String>();
+ map.put( ProtectedItem.Entry.class, Messages.getString( "ProtectedItemWrapper.protectedItem.entry.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.AllUserAttributeTypes.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.allUserAttributeTypes.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.AttributeType.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.attributeType.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.AllAttributeValues.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.allAttributeValues.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.AllUserAttributeTypesAndValues.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.allUserAttributeTypesAndValues.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.AttributeValue.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.attributeValue.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.SelfValue.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.selfValue.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.RangeOfValues.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.rangeOfValues.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.MaxValueCount.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.maxValueCount.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.MaxImmSub.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.maxImmSub.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.RestrictedBy.class, Messages
+ .getString( "ProtectedItemWrapper.protectedItem.restrictedBy.label" ) ); //$NON-NLS-1$
+ map.put( ProtectedItem.Classes.class, Messages.getString( "ProtectedItemWrapper.protectedItem.classes.label" ) ); //$NON-NLS-1$
+ classToDisplayMap = Collections.unmodifiableMap( map );
+ }
+
+ /** A dummy ACI to check syntax of the protectedItemValue */
+ private static final String DUMMY = "{ identificationTag \"id1\", precedence 1, authenticationLevel simple, " //$NON-NLS-1$
+ + "itemOrUserFirst itemFirst: { protectedItems { #identifier# #values# }, " //$NON-NLS-1$
+ + "itemPermissions { { userClasses { allUsers }, grantsAndDenials { grantRead } } } } }"; //$NON-NLS-1$
+
+ /** The class of the protected item, never null. */
+ private final Class clazz;
+
+ /** The protected item values, may be empty. */
+ private List<String> values;
+
+ /** The value prefix, prepended to the value. */
+ private String valuePrefix;
+
+ /** The value suffix, appended to the value. */
+ private String valueSuffix;
+
+ /** The value editor, null means no value. */
+ private AbstractDialogStringValueEditor valueEditor;
+
+ /** The multivalued. */
+ private boolean isMultivalued;
+
+
+ /**
+ * Creates a new instance of ProtectedItemWrapper.
+ *
+ * @param clazz the java class of the UserClass
+ * @param isMultivalued the is multivalued
+ * @param valuePrefix the identifier
+ * @param valueSuffix the dislpay name
+ * @param valueEditor the value editor
+ */
+ public ProtectedItemWrapper( Class clazz, boolean isMultivalued, String valuePrefix, String valueSuffix,
+ AbstractDialogStringValueEditor valueEditor )
+ {
+ this.clazz = clazz;
+ this.isMultivalued = isMultivalued;
+ this.valuePrefix = valuePrefix;
+ this.valueSuffix = valueSuffix;
+ this.valueEditor = valueEditor;
+
+ this.values = new ArrayList<String>();
+ }
+
+
+ /**
+ * Creates a new protected item object. Therefore it uses the
+ * dummy ACI, injects the protected item and its value, parses
+ * the ACI and extracts the protected item from the parsed bean.
+ *
+ * @return the parsed protected item
+ *
+ * @throws ParseException if parsing fails
+ */
+ public ProtectedItem getProtectedItem() throws ParseException
+ {
+ String flatValue = getFlatValue();
+ String spec = DUMMY;
+ spec = spec.replaceAll( "#identifier#", getIdentifier() ); //$NON-NLS-1$
+ spec = spec.replaceAll( "#values#", flatValue ); //$NON-NLS-1$
+ ACIItemParser parser = new ACIItemParser( null );
+ ItemFirstACIItem aci = null;
+ try
+ {
+ aci = ( ItemFirstACIItem ) parser.parse( spec );
+ }
+ catch ( ParseException e )
+ {
+
+ String msg = NLS
+ .bind(
+ Messages.getString( "ProtectedItemWrapper.error.message" ), new String[] { getIdentifier(), flatValue } ); //$NON-NLS-1$
+ throw new ParseException( msg, 0 );
+ }
+ ProtectedItem item = ( ProtectedItem ) aci.getProtectedItems().iterator().next();
+ return item;
+ }
+
+
+ /**
+ * Sets the protected item.
+ *
+ * @param item the protected item
+ */
+ public void setProtectedItem( ProtectedItem item )
+ {
+ assert item.getClass() == getClazz();
+
+ // first clear values
+ values.clear();
+
+ // switch on userClass type
+ // no value in ProtectedItem.Entry, ProtectedItem.AllUserAttributeTypes and ProtectedItem.AllUserAttributeTypesAndValues
+ if ( item.getClass() == ProtectedItem.AttributeType.class )
+ {
+ ProtectedItem.AttributeType at = ( ProtectedItem.AttributeType ) item;
+ for ( Iterator it = at.iterator(); it.hasNext(); )
+ {
+ values.add( it.next().toString() );
+ }
+ }
+ else if ( item.getClass() == ProtectedItem.AllAttributeValues.class )
+ {
+ ProtectedItem.AllAttributeValues aav = ( ProtectedItem.AllAttributeValues ) item;
+ for ( Iterator it = aav.iterator(); it.hasNext(); )
+ {
+ values.add( it.next().toString() );
+ }
+ }
+ else if ( item.getClass() == ProtectedItem.AttributeValue.class )
+ {
+ ProtectedItem.AttributeValue av = ( ProtectedItem.AttributeValue ) item;
+ for ( Iterator it = av.iterator(); it.hasNext(); )
+ {
+ Attribute attribute = ( Attribute ) it.next();
+ try
+ {
+ values.add( attribute.getID() + "=" + attribute.get() ); //$NON-NLS-1$
+ }
+ catch ( NamingException e )
+ {
+ }
+ }
+ }
+ else if ( item.getClass() == ProtectedItem.SelfValue.class )
+ {
+ ProtectedItem.SelfValue sv = ( ProtectedItem.SelfValue ) item;
+ for ( Iterator it = sv.iterator(); it.hasNext(); )
+ {
+ values.add( it.next().toString() );
+ }
+ }
+ else if ( item.getClass() == ProtectedItem.RangeOfValues.class )
+ {
+ ProtectedItem.RangeOfValues rov = ( ProtectedItem.RangeOfValues ) item;
+ StringBuffer buffer = new StringBuffer();
+ rov.getFilter().printToBuffer( buffer );
+ values.add( buffer.toString() );
+ }
+ else if ( item.getClass() == ProtectedItem.MaxValueCount.class )
+ {
+ ProtectedItem.MaxValueCount mvc = ( ProtectedItem.MaxValueCount ) item;
+ for ( Iterator it = mvc.iterator(); it.hasNext(); )
+ {
+ ProtectedItem.MaxValueCountItem mvci = ( ProtectedItem.MaxValueCountItem ) it.next();
+ StringBuffer buffer = new StringBuffer();
+ mvci.printToBuffer( buffer );
+ values.add( buffer.toString() );
+ }
+ }
+ else if ( item.getClass() == ProtectedItem.MaxImmSub.class )
+ {
+ ProtectedItem.MaxImmSub mis = ( ProtectedItem.MaxImmSub ) item;
+ values.add( Integer.toString( mis.getValue() ) );
+ }
+ else if ( item.getClass() == ProtectedItem.RestrictedBy.class )
+ {
+ ProtectedItem.RestrictedBy rb = ( ProtectedItem.RestrictedBy ) item;
+ for ( Iterator it = rb.iterator(); it.hasNext(); )
+ {
+ ProtectedItem.RestrictedByItem rbi = ( ProtectedItem.RestrictedByItem ) it.next();
+ StringBuffer buffer = new StringBuffer();
+ rbi.printToBuffer( buffer );
+ values.add( buffer.toString() );
+ }
+ }
+ else if ( item.getClass() == ProtectedItem.Classes.class )
+ {
+ ProtectedItem.Classes classes = ( ProtectedItem.Classes ) item;
+ StringBuffer buffer = new StringBuffer();
+ classes.getClasses().printRefinementToBuffer( buffer );
+ values.add( buffer.toString() );
+ }
+
+ }
+
+
+ /**
+ * Returns a user-friedly string, displayed in the table.
+ *
+ * @return the string
+ */
+ public String toString()
+ {
+ String flatValue = getFlatValue();
+ if ( flatValue.length() > 0 )
+ {
+ flatValue = flatValue.replace( '\r', ' ' );
+ flatValue = flatValue.replace( '\n', ' ' );
+ flatValue = ": " + flatValue; //$NON-NLS-1$
+ if ( flatValue.length() > 40 )
+ {
+ String temp = flatValue;
+ flatValue = temp.substring( 0, 20 );
+ flatValue = flatValue + "..."; //$NON-NLS-1$
+ flatValue = flatValue + temp.substring( temp.length() - 20, temp.length() );
+ }
+ }
+
+ return getDisplayName() + " " + flatValue; //$NON-NLS-1$
+ }
+
+
+ /**
+ * Returns the flat value.
+ *
+ * @return the flat value
+ */
+ private String getFlatValue()
+ {
+ if ( valueEditor == null || values.isEmpty() )
+ {
+ return ""; //$NON-NLS-1$
+ }
+
+ StringBuffer sb = new StringBuffer();
+ if ( isMultivalued() )
+ {
+ sb.append( "{ " ); //$NON-NLS-1$
+ }
+ for ( Iterator<String> it = values.iterator(); it.hasNext(); )
+ {
+ sb.append( valuePrefix );
+ String value = it.next();
+ sb.append( value );
+ sb.append( valueSuffix );
+ if ( it.hasNext() )
+ {
+ sb.append( ", " ); //$NON-NLS-1$
+ }
+ }
+ if ( isMultivalued() )
+ {
+ sb.append( " }" ); //$NON-NLS-1$
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * Returns the list of values, may be modified.
+ *
+ * @return the modifyable list of values.
+ */
+ public List<String> getValues()
+ {
+ return values;
+ }
+
+
+ /**
+ * Gets the display name.
+ *
+ * @return the display name
+ */
+ public String getDisplayName()
+ {
+ return classToDisplayMap.get( clazz );
+ }
+
+
+ /**
+ * Gets the identifier.
+ *
+ * @return the identifier
+ */
+ public String getIdentifier()
+ {
+ return classToIdentifierMap.get( clazz );
+ }
+
+
+ /**
+ * Returns the class of the user class.
+ *
+ * @return the class of the user class.
+ */
+ public Class getClazz()
+ {
+ return clazz;
+ }
+
+
+ /**
+ * Checks if is editable.
+ *
+ * @return true, if is editable
+ */
+ public boolean isEditable()
+ {
+ return valueEditor != null;
+ }
+
+
+ /**
+ * Gets the value editor.
+ *
+ * @return the value editor, may be null.
+ */
+ public AbstractDialogStringValueEditor getValueEditor()
+ {
+ return valueEditor;
+ }
+
+
+ /**
+ * Checks if is multivalued.
+ *
+ * @return true, if is multivalued
+ */
+ public boolean isMultivalued()
+ {
+ return isMultivalued;
+ }
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapperFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapperFactory.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapperFactory.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapperFactory.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,118 @@
+/*
+ * 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.model;
+
+
+import org.apache.directory.shared.ldap.aci.ProtectedItem;
+import org.apache.directory.studio.aciitemeditor.valueeditors.AttributeTypeAndValueValueEditor;
+import org.apache.directory.studio.aciitemeditor.valueeditors.AttributeTypeValueEditor;
+import org.apache.directory.studio.aciitemeditor.valueeditors.FilterValueEditor;
+import org.apache.directory.studio.aciitemeditor.valueeditors.MaxValueCountValueEditor;
+import org.apache.directory.studio.aciitemeditor.valueeditors.RestrictedByValueEditor;
+import org.apache.directory.studio.valueeditors.TextValueEditor;
+import org.apache.directory.studio.valueeditors.integer.IntegerValueEditor;
+
+
+/**
+ * The ProtectedItemWrapperFactory creates the ProtectedItemWrappers, ready to
+ * be used in the protected item table.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ProtectedItemWrapperFactory
+{
+
+ /**
+ * Creates the protected item wrappers.
+ *
+ * @return the protected item wrapper[]
+ */
+ public static final ProtectedItemWrapper[] createProtectedItemWrappers()
+ {
+ ProtectedItemWrapper[] protectedItemWrappers = new ProtectedItemWrapper[]
+ {
+ // entry
+ new ProtectedItemWrapper( ProtectedItem.Entry.class, false, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ null ),
+
+ // allUserAttributeTypes
+ new ProtectedItemWrapper( ProtectedItem.AllUserAttributeTypes.class, false, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ null ),
+
+ // attributeType { 1.2.3, cn }
+ new ProtectedItemWrapper( ProtectedItem.AttributeType.class, true, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new AttributeTypeValueEditor() ),
+
+ // allAttributeValues { 1.2.3, cn }
+ new ProtectedItemWrapper( ProtectedItem.AllAttributeValues.class, true, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new AttributeTypeValueEditor() ),
+
+ // attributeType
+ new ProtectedItemWrapper( ProtectedItem.AllUserAttributeTypesAndValues.class, false, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ null ),
+
+ // attributeValue { ou=people, cn=Ersin }
+ new ProtectedItemWrapper( ProtectedItem.AttributeValue.class, true, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new AttributeTypeAndValueValueEditor() ),
+
+ // selfValue { 1.2.3, cn }
+ new ProtectedItemWrapper( ProtectedItem.SelfValue.class, true, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new AttributeTypeValueEditor() ),
+
+ // rangeOfValues (cn=E*)
+ new ProtectedItemWrapper( ProtectedItem.RangeOfValues.class, false, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new FilterValueEditor() ),
+
+ // maxValueCount { { type 10.11.12, maxCount 10 }, { maxCount 20, type 11.12.13 } }
+ new ProtectedItemWrapper( ProtectedItem.MaxValueCount.class, true, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new MaxValueCountValueEditor() ),
+
+ // maxImmSub 3
+ new ProtectedItemWrapper( ProtectedItem.MaxImmSub.class, false, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new IntegerValueEditor() ),
+
+ // restrictedBy { { type 10.11.12, valuesIn ou }, { valuesIn cn, type 11.12.13 } }
+ new ProtectedItemWrapper( ProtectedItem.RestrictedBy.class, true, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new RestrictedByValueEditor() ),
+
+ // classes and : { item: xyz , or:{item:X,item:Y} }
+ new ProtectedItemWrapper( ProtectedItem.Classes.class, false, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new TextValueEditor() // TODO: RefinementValueEditor
+ ),
+
+ };
+
+ return protectedItemWrappers;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapperFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapper.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapper.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapper.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapper.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,320 @@
+/*
+ * 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.model;
+
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.Name;
+
+import org.apache.directory.shared.ldap.aci.ACIItemParser;
+import org.apache.directory.shared.ldap.aci.UserClass;
+import org.apache.directory.shared.ldap.aci.UserFirstACIItem;
+import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
+import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.osgi.util.NLS;
+
+
+/**
+ * The UserClassWrapper is used as input for the table viewer.
+ * The user class values are always stored as raw string values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class UserClassWrapper
+{
+
+ /** This map contains all possible user class identifiers */
+ public static final Map<Class, String> classToIdentifierMap;
+ static
+ {
+ Map<Class, String> map = new HashMap<Class, String>();
+ map.put( UserClass.AllUsers.class, "allUsers" ); //$NON-NLS-1$
+ map.put( UserClass.ThisEntry.class, "thisEntry" ); //$NON-NLS-1$
+ map.put( UserClass.Name.class, "name" ); //$NON-NLS-1$
+ map.put( UserClass.UserGroup.class, "userGroup" ); //$NON-NLS-1$
+ map.put( UserClass.Subtree.class, "subtree" ); //$NON-NLS-1$
+ classToIdentifierMap = Collections.unmodifiableMap( map );
+ }
+
+ /** This map contains all user class display values */
+ public static final Map<Class, String> classToDisplayMap;
+ static
+ {
+ Map<Class, String> map = new HashMap<Class, String>();
+ map.put( UserClass.AllUsers.class, Messages.getString( "UserClassWrapper.userClass.allUsers.label" ) ); //$NON-NLS-1$
+ map.put( UserClass.ThisEntry.class, Messages.getString( "UserClassWrapper.userClass.thisEntry.label" ) ); //$NON-NLS-1$
+ map.put( UserClass.Name.class, Messages.getString( "UserClassWrapper.userClass.name.label" ) ); //$NON-NLS-1$
+ map.put( UserClass.UserGroup.class, Messages.getString( "UserClassWrapper.userClass.userGroup.label" ) ); //$NON-NLS-1$
+ map.put( UserClass.Subtree.class, Messages.getString( "UserClassWrapper.userClass.subtree.label" ) ); //$NON-NLS-1$
+ classToDisplayMap = Collections.unmodifiableMap( map );
+ }
+
+ /** A dummy ACI to check syntax of the userClassValue. */
+ private static final String DUMMY = "{ identificationTag \"id1\", precedence 1, authenticationLevel simple, " //$NON-NLS-1$
+ + "itemOrUserFirst userFirst: { userClasses { #identifier# #values# }, " //$NON-NLS-1$
+ + "userPermissions { { protectedItems { entry }, grantsAndDenials { grantRead } } } } }"; //$NON-NLS-1$
+
+ /** The class of the user class, never null. */
+ private final Class clazz;
+
+ /** The user class values, may be empty. */
+ private List<String> values;
+
+ /** The value prefix, prepended to the value. */
+ private String valuePrefix;
+
+ /** The value suffix, appended to the value. */
+ private String valueSuffix;
+
+ /** The value editor, null means no value. */
+ private AbstractDialogStringValueEditor valueEditor;
+
+
+ /**
+ * Creates a new instance of UserClassWrapper.
+ *
+ * @param clazz the java class of the UserClass
+ * @param valuePrefix the identifier
+ * @param valueSuffix the dislpay name
+ * @param valueEditor the value editor
+ */
+ public UserClassWrapper( Class clazz, String valuePrefix, String valueSuffix,
+ AbstractDialogStringValueEditor valueEditor )
+ {
+ this.clazz = clazz;
+ this.valuePrefix = valuePrefix;
+ this.valueSuffix = valueSuffix;
+ this.valueEditor = valueEditor;
+
+ this.values = new ArrayList<String>();
+ }
+
+
+ /**
+ * Creates a new user class object. Therefore it uses the
+ * dummy ACI, injects the user class and its value, parses
+ * the ACI and extracts the user class from the parsed bean.
+ *
+ * @return the parsed user class
+ *
+ * @throws ParseException if parsing fails
+ */
+ public UserClass getUserClass() throws ParseException
+ {
+ String flatValue = getFlatValue();
+ String spec = DUMMY;
+ spec = spec.replaceAll( "#identifier#", getIdentifier() ); //$NON-NLS-1$
+ spec = spec.replaceAll( "#values#", flatValue ); //$NON-NLS-1$
+ ACIItemParser parser = new ACIItemParser( null );
+ UserFirstACIItem aci = null;
+ try
+ {
+ aci = ( UserFirstACIItem ) parser.parse( spec );
+ }
+ catch ( ParseException e )
+ {
+ String msg = NLS.bind(
+ Messages.getString( "UserClassWrapper.error.message" ), new String[] { getIdentifier(), flatValue } ); //$NON-NLS-1$
+ throw new ParseException( msg, 0 );
+ }
+ UserClass userClass = ( UserClass ) aci.getUserClasses().iterator().next();
+ return userClass;
+ }
+
+
+ /**
+ * Sets the user class.
+ *
+ * @param userClass the user class
+ */
+ public void setUserClass( UserClass userClass )
+ {
+ assert userClass.getClass() == getClazz();
+
+ // first clear values
+ values.clear();
+
+ // switch on userClass type
+ // no value in UserClass.AllUsers and UserClass.ThisEntry
+ if ( userClass.getClass() == UserClass.Name.class )
+ {
+ UserClass.Name name = ( UserClass.Name ) userClass;
+ Set<Name> jndiNames = name.getNames();
+ for ( Name jndiName : jndiNames )
+ {
+ values.add( jndiName.toString() );
+ }
+ }
+ else if ( userClass.getClass() == UserClass.UserGroup.class )
+ {
+ UserClass.UserGroup userGrops = ( UserClass.UserGroup ) userClass;
+ Set<Name> jndiNames = userGrops.getNames();
+ for ( Name jndiName : jndiNames )
+ {
+ values.add( jndiName.toString() );
+ }
+ }
+ else if ( userClass.getClass() == UserClass.Subtree.class )
+ {
+ UserClass.Subtree subtree = ( UserClass.Subtree ) userClass;
+ Collection<SubtreeSpecification> subtreeSpecifications = subtree.getSubtreeSpecifications();
+ for ( SubtreeSpecification subtreeSpecification : subtreeSpecifications )
+ {
+ StringBuffer buffer = new StringBuffer();
+ subtreeSpecification.printToBuffer( buffer );
+ String s = buffer.toString();
+ values.add( s );
+ }
+ }
+ }
+
+
+ /**
+ * Returns a user-friedly string, displayed in the table.
+ *
+ * @return the string
+ */
+ public String toString()
+ {
+ String flatValue = getFlatValue();
+ if ( flatValue.length() > 0 )
+ {
+ flatValue = flatValue.replace( '\r', ' ' );
+ flatValue = flatValue.replace( '\n', ' ' );
+ flatValue = ": " + flatValue; //$NON-NLS-1$
+ if ( flatValue.length() > 40 )
+ {
+ String temp = flatValue;
+ flatValue = temp.substring( 0, 20 );
+ flatValue = flatValue + "..."; //$NON-NLS-1$
+ flatValue = flatValue + temp.substring( temp.length() - 20, temp.length() );
+ }
+ }
+
+ return getDisplayName() + " " + flatValue; //$NON-NLS-1$
+ }
+
+
+ /**
+ * Returns the flat value.
+ *
+ * @return the flat value
+ */
+ private String getFlatValue()
+ {
+ if ( valueEditor == null || values.isEmpty() )
+ {
+ return ""; //$NON-NLS-1$
+ }
+
+ StringBuffer sb = new StringBuffer();
+ sb.append( "{ " ); //$NON-NLS-1$
+ for ( Iterator<String> it = values.iterator(); it.hasNext(); )
+ {
+ sb.append( valuePrefix );
+ String value = it.next();
+ sb.append( value );
+ sb.append( valueSuffix );
+ if ( it.hasNext() )
+ {
+ sb.append( ", " ); //$NON-NLS-1$
+ }
+ }
+ sb.append( " }" ); //$NON-NLS-1$
+ return sb.toString();
+ }
+
+
+ /**
+ * Returns the list of values, may be modified.
+ *
+ * @return the modifyable list of values.
+ */
+ public List<String> getValues()
+ {
+ return values;
+ }
+
+
+ /**
+ * Gets the display name.
+ *
+ * @return the display name
+ */
+ public String getDisplayName()
+ {
+ return classToDisplayMap.get( clazz );
+ }
+
+
+ /**
+ * Gets the identifier.
+ *
+ * @return the identifier
+ */
+ public String getIdentifier()
+ {
+ return classToIdentifierMap.get( clazz );
+ }
+
+
+ /**
+ * Returns the class of the user class.
+ *
+ * @return the class of the user class.
+ */
+ public Class getClazz()
+ {
+ return clazz;
+ }
+
+
+ /**
+ * Checks if is editable.
+ *
+ * @return true, if is editable
+ */
+ public boolean isEditable()
+ {
+ return valueEditor != null;
+ }
+
+
+ /**
+ * Gets the value editor.
+ *
+ * @return the value editor, may be null.
+ */
+ public AbstractDialogStringValueEditor getValueEditor()
+ {
+ return valueEditor;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapperFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapperFactory.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapperFactory.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapperFactory.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,76 @@
+/*
+ * 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.model;
+
+
+import org.apache.directory.shared.ldap.aci.UserClass;
+import org.apache.directory.studio.aciitemeditor.valueeditors.SubtreeValueEditor;
+import org.apache.directory.studio.valueeditors.dn.DnValueEditor;
+
+
+/**
+ * The UserClassWrapperFactory creates the UserClassWrapper, ready to
+ * be used in the user classes table.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class UserClassWrapperFactory
+{
+
+ /**
+ * Creates the user class wrappers.
+ *
+ * @return the user class wrapper[]
+ */
+ public static final UserClassWrapper[] createUserClassWrappers()
+ {
+ UserClassWrapper[] userClassWrappers = new UserClassWrapper[]
+ {
+ // allUsers
+ new UserClassWrapper( UserClass.AllUsers.class, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ null ),
+
+ // thisEntry
+ new UserClassWrapper( UserClass.ThisEntry.class, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ null ),
+
+ // name
+ new UserClassWrapper( UserClass.Name.class, "\"", //$NON-NLS-1$
+ "\"", //$NON-NLS-1$
+ new DnValueEditor() ),
+
+ // userGroup
+ new UserClassWrapper( UserClass.UserGroup.class, "\"", //$NON-NLS-1$
+ "\"", //$NON-NLS-1$
+ new DnValueEditor() ),
+
+ // subtree
+ new UserClassWrapper( UserClass.Subtree.class, "", //$NON-NLS-1$
+ "", //$NON-NLS-1$
+ new SubtreeValueEditor( false )
+ ) };
+
+ return userClassWrappers;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapperFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/package-info.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/package-info.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/package-info.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/package-info.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ *
+ */
+/**
+ * Contains the model for the ACI item editor.
+ */
+package org.apache.directory.studio.aciitemeditor.model;
\ No newline at end of file
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/package-info.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/package-info.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/package-info.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/package-info.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ *
+ */
+/**
+ * Contains the ACI item editor's
+ * {@link org.apache.directory.studio.valueeditors.IValueEditor}
+ * implementation and the plugin activator.
+ */
+package org.apache.directory.studio.aciitemeditor;
\ No newline at end of file
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACICodeScanner.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACICodeScanner.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACICodeScanner.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACICodeScanner.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,236 @@
+/*
+ * 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.sourceeditor;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWhitespaceDetector;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+import org.eclipse.jface.text.rules.WordRule;
+
+
+/**
+ * Scanner used to analyse ACI code. Allows syntax coloring.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACICodeScanner extends RuleBasedScanner
+{
+ /** 'identificationTag' keyword */
+ public static final String identificationTagPartition = "identificationTag"; //$NON-NLS-1$
+
+ /** 'precedence' keyword */
+ public static final String precedencePartition = "precedence"; //$NON-NLS-1$
+
+ /** 'authenticationLevel' keyword */
+ public static final String authenticationLevelPartition = "authenticationLevel"; //$NON-NLS-1$
+
+ /** Keywords for the itemOrUserFirst Section */
+ public static final String[] itemOrUserFirstSectionPartition = new String[]
+ { "itemOrUserFirst", "itemFirst", "userFirst" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** Keywords for 'userFirst' section */
+ public static final String[] userSection = new String[]
+ { "userClasses", "userPermissions" }; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** Keywords for AciItems values */
+ public static final String[] aciKeywords = new String[]
+ { "protectedItems", //$NON-NLS-1$
+ "itemPermissions", //$NON-NLS-1$
+ "entry", //$NON-NLS-1$
+ "allUserAttributeTypes", //$NON-NLS-1$
+ "attributeType", //$NON-NLS-1$
+ "allAttributeValues", //$NON-NLS-1$
+ "allUserAttributeTypesAndValues", //$NON-NLS-1$
+ "attributeValue", //$NON-NLS-1$
+ "selfValue", //$NON-NLS-1$
+ "rangeOfValues", //$NON-NLS-1$
+ "maxValueCount", //$NON-NLS-1$
+ "maxImmSub", //$NON-NLS-1$
+ "restrictedBy", //$NON-NLS-1$
+ "classes", //$NON-NLS-1$
+ "grantsAndDenials", //$NON-NLS-1$
+ "allUsers", //$NON-NLS-1$
+ "thisEntry", //$NON-NLS-1$
+ "name", //$NON-NLS-1$
+ "userGroup", //$NON-NLS-1$
+ "subtree", //$NON-NLS-1$
+ "type", //$NON-NLS-1$
+ "valuesIn", //$NON-NLS-1$
+ "none", //$NON-NLS-1$
+ "simple", //$NON-NLS-1$
+ "strong" }; //$NON-NLS-1$
+
+ /** Keywords for grant values */
+ public static final String[] aciGrantValues = new String[]
+ { "grantAdd", //$NON-NLS-1$
+ "grantDiscloseOnError", //$NON-NLS-1$
+ "grantRead", //$NON-NLS-1$
+ "grantRemove", //$NON-NLS-1$
+ "grantBrowse", //$NON-NLS-1$
+ "grantExport", //$NON-NLS-1$
+ "grantImport", //$NON-NLS-1$
+ "grantModify", //$NON-NLS-1$
+ "grantRename", //$NON-NLS-1$
+ "grantReturnDN", //$NON-NLS-1$
+ "grantCompare", //$NON-NLS-1$
+ "grantFilterMatch", //$NON-NLS-1$
+ "grantInvoke", }; //$NON-NLS-1$
+
+ /** Keywords for deny values */
+ public static final String[] aciDenyValues = new String[]
+ { "denyAdd", //$NON-NLS-1$
+ "denyDiscloseOnError", //$NON-NLS-1$
+ "denyRead", //$NON-NLS-1$
+ "denyRemove", //$NON-NLS-1$
+ "denyBrowse", //$NON-NLS-1$
+ "denyExport", //$NON-NLS-1$
+ "denyImport", //$NON-NLS-1$
+ "denyModify", //$NON-NLS-1$
+ "denyRename", //$NON-NLS-1$
+ "denyReturnDN", //$NON-NLS-1$
+ "denyCompare", //$NON-NLS-1$
+ "denyFilterMatch", //$NON-NLS-1$
+ "denyInvoke" }; //$NON-NLS-1$
+
+
+ /**
+ * Creates a new instance of AciCodeScanner.
+ *
+ * @param provider
+ * the provider
+ */
+ public ACICodeScanner( ACITextAttributeProvider provider )
+ {
+ List<IRule> rules = new ArrayList<IRule>();
+
+ IToken keyword = new Token( provider.getAttribute( ACITextAttributeProvider.KEYWORD_ATTRIBUTE ) );
+ IToken undefined = new Token( provider.getAttribute( ACITextAttributeProvider.DEFAULT_ATTRIBUTE ) );
+ IToken string = new Token( provider.getAttribute( ACITextAttributeProvider.STRING_ATTRIBUTE ) );
+ IToken grantValue = new Token( provider.getAttribute( ACITextAttributeProvider.GRANT_VALUE ) );
+ IToken denyValue = new Token( provider.getAttribute( ACITextAttributeProvider.DENY_VALUE ) );
+ IToken identification = new Token( provider.getAttribute( ACITextAttributeProvider.IDENTIFICATION_ATTRIBUTE ) );
+ IToken precedence = new Token( provider.getAttribute( ACITextAttributeProvider.PRECEDENCE_ATTRIBUTE ) );
+ IToken authenticationLevel = new Token( provider
+ .getAttribute( ACITextAttributeProvider.AUTHENTICATIONLEVEL_ATTRIBUTE ) );
+ IToken itemOrUserFirst = new Token( provider.getAttribute( ACITextAttributeProvider.ITEMORUSERFIRST_ATTRIBUTE ) );
+ IToken user = new Token( provider.getAttribute( ACITextAttributeProvider.USER_ATTRIBUTE ) );
+
+ // Rules for Strings
+ rules.add( new SingleLineRule( "\"", "\"", string, '\0', true ) ); //$NON-NLS-1$ //$NON-NLS-2$
+ rules.add( new SingleLineRule( "'", "'", string, '\0', true ) ); //$NON-NLS-1$ //$NON-NLS-2$
+ // Generic rule for whitespaces
+ rules.add( new WhitespaceRule( new IWhitespaceDetector()
+ {
+ /**
+ * Indicates if the given character is a whitespace
+ * @param c the character to analyse
+ * @return <code>true</code> if the character is to be considered as a whitespace, <code>false</code> if not.
+ * @see org.eclipse.jface.text.rules.IWhitespaceDetector#isWhitespace(char)
+ */
+ public boolean isWhitespace( char c )
+ {
+ return Character.isWhitespace( c );
+ }
+ } ) );
+
+ // If the word isn't in the List, returns undefined
+ WordRule wr = new WordRule( new AciWordDetector(), undefined );
+
+ // Adding Keywords
+ for ( int i = 0; i < aciKeywords.length; ++i )
+ {
+ wr.addWord( aciKeywords[i], keyword );
+ }
+
+ // Adding GrantValues
+ for ( int i = 0; i < aciGrantValues.length; ++i )
+ {
+ wr.addWord( aciGrantValues[i], grantValue );
+ }
+
+ // Adding DenyValues
+ for ( int i = 0; i < aciDenyValues.length; ++i )
+ {
+ wr.addWord( aciDenyValues[i], denyValue );
+ }
+
+ // Adding itemOrUserFirstSectionPartition
+ for ( int i = 0; i < itemOrUserFirstSectionPartition.length; ++i )
+ {
+ wr.addWord( itemOrUserFirstSectionPartition[i], itemOrUserFirst );
+ }
+
+ // Adding User
+ for ( int i = 0; i < userSection.length; ++i )
+ {
+ wr.addWord( userSection[i], user );
+ }
+
+ wr.addWord( identificationTagPartition, identification );
+
+ wr.addWord( precedencePartition, precedence );
+
+ wr.addWord( authenticationLevelPartition, authenticationLevel );
+
+ rules.add( wr );
+
+ // Conversion de la List en tableau pour la passer à la méthode setRules
+ IRule[] param = new IRule[rules.size()];
+ rules.toArray( param );
+ setRules( param );
+ }
+
+ /**
+ * This class implements a word detector for ACI Items
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+ static class AciWordDetector implements IWordDetector
+ {
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isWordPart( char c )
+ {
+ return ( Character.isLetterOrDigit( c ) || c == '_' || c == '$' || c == '#' || c == '@' || c == '~'
+ || c == '.' || c == '?' );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isWordStart( char c )
+ {
+ return ( Character.isLetter( c ) || c == '.' || c == '_' || c == '?' || c == '$' );
+ }
+ }
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACICodeScanner.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIContentAssistProcessor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIContentAssistProcessor.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIContentAssistProcessor.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIContentAssistProcessor.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,151 @@
+/*
+ * 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.sourceeditor;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.studio.aciitemeditor.ACIITemConstants;
+import org.apache.directory.studio.aciitemeditor.Activator;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * This class implements the Content Assist Processor for ACI Item
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIContentAssistProcessor extends TemplateCompletionProcessor
+{
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
+ */
+ public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset )
+ {
+ List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>();
+
+ // Add context dependend template proposals
+ ICompletionProposal[] templateProposals = super.computeCompletionProposals( viewer, offset );
+ if ( templateProposals != null )
+ {
+ proposalList.addAll( Arrays.asList( templateProposals ) );
+ }
+
+ return ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
+ */
+ public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset )
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getCompletionProposalAutoActivationCharacters()
+ */
+ public char[] getCompletionProposalAutoActivationCharacters()
+ {
+
+ char[] chars = new char[52];
+ for ( int i = 0; i < 26; i++ )
+ {
+ chars[i] = ( char ) ( 'a' + i );
+ }
+ for ( int i = 0; i < 26; i++ )
+ {
+ chars[i + 26] = ( char ) ( 'A' + i );
+ }
+
+ return chars;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getContextInformationAutoActivationCharacters()
+ */
+ public char[] getContextInformationAutoActivationCharacters()
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getContextInformationValidator()
+ */
+ public IContextInformationValidator getContextInformationValidator()
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getErrorMessage()
+ */
+ public String getErrorMessage()
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getContextType(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
+ */
+ @Override
+ protected TemplateContextType getContextType( ITextViewer viewer, IRegion region )
+ {
+ return Activator.getDefault().getAciTemplateContextTypeRegistry().getContextType(
+ ACIITemConstants.ACI_ITEM_TEMPLATE_ID );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getImage(org.eclipse.jface.text.templates.Template)
+ */
+ @Override
+ protected Image getImage( Template template )
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getTemplates(java.lang.String)
+ */
+ @Override
+ protected Template[] getTemplates( String contextTypeId )
+ {
+ return Activator.getDefault().getAciTemplateStore().getTemplates( contextTypeId );
+ }
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIContentAssistProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIFormattingStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIFormattingStrategy.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIFormattingStrategy.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIFormattingStrategy.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,308 @@
+/*
+ * 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.sourceeditor;
+
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.eclipse.jface.text.formatter.IFormattingStrategy;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+/**
+ * This class implements the formatting strategy for the ACI Item Editor.
+ * <ul>
+ * <li>New line after a comma
+ * <li>New line after a opened left curly
+ * </ul>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACIFormattingStrategy implements IFormattingStrategy
+{
+
+ /** The Constant INDENT_STRING. */
+ public static final String INDENT_STRING = " "; //$NON-NLS-1$
+
+ /** The Constant NEWLINE. */
+ public static final String NEWLINE = BrowserCoreConstants.LINE_SEPARATOR;
+
+ /** The source viewer. */
+ private ISourceViewer sourceViewer;
+
+
+ /**
+ * Creates a new instance of ACIFormattingStrategy.
+ *
+ * @param sourceViewer the source viewer
+ */
+ public ACIFormattingStrategy( ISourceViewer sourceViewer )
+ {
+ this.sourceViewer = sourceViewer;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String format( String content, boolean isLineStart, String indentation, int[] positions )
+ {
+ String oldContent = sourceViewer.getDocument().get();
+ String newContent = internFormat ( oldContent );
+ sourceViewer.getDocument().set( newContent );
+
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void formatterStarts( String initialIndentation )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void formatterStops()
+ {
+ }
+
+ private String internFormat( String content )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ // flag to track if a new line was started
+ boolean newLineStarted = true;
+
+ // flag to track if we are within a quoted string
+ boolean inQuotedString = false;
+
+ // flag to track if the current expression is appended in one-line mode
+ boolean oneLineMode = false;
+
+ // the current indent
+ int indent = 0;
+
+ int contentLength = content.length();
+ for (int i=0; i<contentLength; i++)
+ {
+ char c = content.charAt( i );
+
+ // track quotes
+ if( c == '"')
+ {
+ inQuotedString = !inQuotedString;
+ }
+
+ if( c == '{' && !inQuotedString )
+ {
+ // check one-line mode
+ oneLineMode = checkInOneLine(i, content);
+
+ if(oneLineMode)
+ {
+ // no new line in one-line mode
+ sb.append( c );
+ newLineStarted = false;
+ }
+ else
+ {
+ // start a new line, but avoid blank lines if there are multiple opened curlies
+ if( !newLineStarted )
+ {
+ sb.append( NEWLINE );
+ for ( int x = 0; x < indent; x++ )
+ {
+ sb.append( INDENT_STRING );
+ }
+ }
+
+ // append the curly
+ sb.append( c );
+
+ // start a new line and increment indent
+ sb.append( NEWLINE );
+ newLineStarted = true;
+ indent++;
+ for ( int x = 0; x < indent; x++ )
+ {
+ sb.append( INDENT_STRING );
+ }
+ }
+ }
+ else if (c == '}' && !inQuotedString )
+ {
+ if(oneLineMode)
+ {
+ // no new line in one-line mode
+ sb.append( c );
+ newLineStarted = false;
+
+ // closed curly indicates end of one-line mode
+ oneLineMode = false;
+ }
+ else
+ {
+ // decrement indent
+ indent--;
+
+ // start a new line, but avoid blank lines if there are multiple closed curlies
+ if( newLineStarted )
+ {
+ // delete one indent
+ sb.delete( sb.length()-INDENT_STRING.length(), sb.length() );
+ }
+ else
+ {
+ sb.append( NEWLINE );
+ for ( int x = 0; x < indent; x++ )
+ {
+ sb.append( INDENT_STRING );
+ }
+ }
+
+ // append the curly
+ sb.append( c );
+
+ // start a new line
+ sb.append( NEWLINE );
+ newLineStarted = true;
+ for ( int x = 0; x < indent; x++ )
+ {
+ sb.append( INDENT_STRING );
+ }
+ }
+ }
+ else if (c == ',' && !inQuotedString )
+ {
+ // start new line on comma
+ if(oneLineMode)
+ {
+ sb.append( c );
+ newLineStarted = false;
+ }
+ else
+ {
+ sb.append( c );
+
+ sb.append( NEWLINE );
+ newLineStarted = true;
+
+ for ( int x = 0; x < indent; x++ )
+ {
+ sb.append( INDENT_STRING );
+ }
+ }
+ }
+ else if ( Character.isWhitespace( c ) )
+ {
+ char c1 = 'A';
+ if(i+1 < contentLength )
+ {
+ c1 = content.charAt( i+1 );
+ }
+
+ if( newLineStarted )
+ {
+ // ignore space after starting a new line
+ }
+ else if (c == '\n' || c == '\r' )
+ {
+ // ignore new lines
+ }
+ else if( Character.isWhitespace( c1 ) || c1 == '\n' || c1 == '\r' )
+ {
+ // compress whitespaces
+ }
+ else
+ {
+ sb.append( c );
+ }
+ }
+
+ else
+ {
+ // default case: append the char
+ sb.append( c );
+ newLineStarted = false;
+ }
+ }
+
+ return sb.toString();
+ }
+
+
+ /**
+ * Checks if an expression could be appended in one line. That is
+ * if the expression starting at index i doesn't contain nested
+ * expressions and only one comma.
+ *
+ * @param i the starting index of the expression
+ * @param content the content
+ *
+ * @return true, if the expression could be appended in one line
+ */
+ private boolean checkInOneLine( int i, String content )
+ {
+ // flag to track if we are within a quoted string
+ boolean inQuote = false;
+
+ // counter for commas
+ int commaCounter = 0;
+
+ int contentLength = content.length();
+ for ( int k=i+1; k<contentLength; k++)
+ {
+ char c = content.charAt( k );
+
+ // track quotes
+ if( c == '"')
+ {
+ inQuote = !inQuote;
+ }
+
+ // open curly indicates nested expression
+ if( ( c == '{' ) && !inQuote )
+ {
+ return false;
+ }
+
+ // closing curly indicates end of expression
+ if ( c == '}' && !inQuote )
+ {
+ return true;
+ }
+
+ // allow only single comma in an expression in one line
+ if (c == ',' && !inQuote )
+ {
+ commaCounter++;
+ if(commaCounter > 1)
+ {
+ return false;
+ }
+ }
+ }
+
+ return false;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIFormattingStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACISourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACISourceViewerConfiguration.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACISourceViewerConfiguration.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACISourceViewerConfiguration.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,94 @@
+/*
+ * 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.sourceeditor;
+
+
+import org.apache.directory.studio.aciitemeditor.Activator;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.formatter.ContentFormatter;
+import org.eclipse.jface.text.formatter.IContentFormatter;
+import org.eclipse.jface.text.formatter.IFormattingStrategy;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+
+
+/**
+ * This class enables the features of the editor (Syntax coloring, code completion, etc.)
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACISourceViewerConfiguration extends SourceViewerConfiguration
+{
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)
+ */
+ public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer )
+ {
+ PresentationReconciler reconciler = new PresentationReconciler();
+ reconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer ) );
+
+ // Creating the damager/repairer for code
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer( Activator.getDefault().getAciCodeScanner() );
+ reconciler.setDamager( dr, IDocument.DEFAULT_CONTENT_TYPE );
+ reconciler.setRepairer( dr, IDocument.DEFAULT_CONTENT_TYPE );
+
+ return reconciler;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
+ */
+ public IContentAssistant getContentAssistant( ISourceViewer sourceViewer )
+ {
+ // ContentAssistant assistant = new ContentAssistant();
+ ContentAssistant assistant = new DialogContentAssistant();
+ IContentAssistProcessor aciContentAssistProcessor = new ACIContentAssistProcessor();
+
+ assistant.setContentAssistProcessor( aciContentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE );
+ assistant.setDocumentPartitioning( "org.apache.directory.studio.aci" ); //$NON-NLS-1$
+ assistant.enableAutoActivation( true );
+ assistant.setAutoActivationDelay( 500 );
+ assistant.setProposalPopupOrientation( IContentAssistant.PROPOSAL_STACKED );
+ assistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE );
+
+ return assistant;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentFormatter(org.eclipse.jface.text.source.ISourceViewer)
+ */
+ public IContentFormatter getContentFormatter( ISourceViewer sourceViewer )
+ {
+ ContentFormatter formatter = new ContentFormatter();
+ IFormattingStrategy formattingStrategy = new ACIFormattingStrategy( sourceViewer );
+ formatter.enablePartitionAwareFormatting( false );
+ formatter.setFormattingStrategy( formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE );
+ return formatter;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACISourceViewerConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACITextAttributeProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACITextAttributeProvider.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACITextAttributeProvider.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACITextAttributeProvider.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,110 @@
+/*
+ * 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.sourceeditor;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * This class provides the TextAttributes elements for each kind of attribute
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ACITextAttributeProvider
+{
+ public static final String DEFAULT_ATTRIBUTE = "__pos_aci_default_attribute"; //$NON-NLS-1$
+ public static final String KEYWORD_ATTRIBUTE = "__pos_aci_keyword_attribute"; //$NON-NLS-1$
+ public static final String STRING_ATTRIBUTE = "__pos_aci_string_attribute"; //$NON-NLS-1$
+ public static final String GRANT_DENY_ATTRIBUTE = "__pos_aci_grant_deny_attribute"; //$NON-NLS-1$
+ public static final String IDENTIFICATION_ATTRIBUTE = "__pos_aci_identification_attribute"; //$NON-NLS-1$
+ public static final String PRECEDENCE_ATTRIBUTE = "__pos_aci_precedence_attribute"; //$NON-NLS-1$
+ public static final String AUTHENTICATIONLEVEL_ATTRIBUTE = "__pos_aci_authenticationlevel_attribute"; //$NON-NLS-1$
+ public static final String ITEMORUSERFIRST_ATTRIBUTE = "__pos_aci_itemoruserfirst_attribute"; //$NON-NLS-1$
+ public static final String USER_ATTRIBUTE = "__pos_aci_user_attribute"; //$NON-NLS-1$
+
+ public static final String GRANT_VALUE = "__pos_aci_grant_value"; //$NON-NLS-1$
+ public static final String DENY_VALUE = "__pos_aci_deny_value"; //$NON-NLS-1$
+
+ private Map<String, TextAttribute> attributes = new HashMap<String, TextAttribute>();
+
+
+ /**
+ * Creates a new instance of AciTextAttributeProvider.
+ */
+ public ACITextAttributeProvider()
+ {
+ attributes.put( DEFAULT_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 0, 0 ) ) ) );
+
+ attributes.put( KEYWORD_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 127, 0, 85 ) ),
+ null, SWT.BOLD ) );
+
+ attributes.put( STRING_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 0, 255 ) ) ) );
+
+ attributes.put( GRANT_DENY_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 125, 125,
+ 125 ) ) ) );
+
+ attributes.put( GRANT_VALUE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 150, 0 ) ) ) );
+ attributes.put( DENY_VALUE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 150, 0, 0 ) ) ) );
+
+ attributes.put( IDENTIFICATION_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 125, 0,
+ 0 ) ), null, SWT.BOLD ) );
+
+ attributes.put( PRECEDENCE_ATTRIBUTE, new TextAttribute(
+ new Color( Display.getCurrent(), new RGB( 0, 0, 125 ) ), null, SWT.BOLD ) );
+
+ attributes.put( AUTHENTICATIONLEVEL_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0,
+ 125, 0 ) ), null, SWT.BOLD ) );
+
+ attributes.put( ITEMORUSERFIRST_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 125, 0,
+ 125 ) ), null, SWT.BOLD ) );
+
+ attributes.put( USER_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 122, 255 ) ),
+ null, SWT.BOLD ) );
+
+ }
+
+
+ /**
+ * Gets the correct TextAttribute for the given type
+ *
+ * @param type
+ * the type of element
+ * @return
+ * the correct TextAttribute for the given type
+ */
+ public TextAttribute getAttribute( String type )
+ {
+ TextAttribute attr = ( TextAttribute ) attributes.get( type );
+ if ( attr == null )
+ {
+ attr = ( TextAttribute ) attributes.get( DEFAULT_ATTRIBUTE );
+ }
+ return attr;
+ }
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACITextAttributeProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/DialogContentAssistant.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/DialogContentAssistant.java?rev=592011&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/DialogContentAssistant.java (added)
+++ directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/DialogContentAssistant.java Mon Nov 5 06:27:47 2007
@@ -0,0 +1,209 @@
+/*
+ * 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.sourceeditor;
+
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.jface.contentassist.ComboContentAssistSubjectAdapter;
+import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
+import org.eclipse.jface.contentassist.TextContentAssistSubjectAdapter;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+
+
+/**
+ * This class implements the Content Assistant Dialog used in the ACI Item
+ * Source Editor for displaying proposals
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DialogContentAssistant extends SubjectControlContentAssistant implements FocusListener
+{
+ private Control control;
+
+ private IHandlerActivation handlerActivation;
+
+ private boolean possibleCompletionsVisible;
+
+
+ /**
+ * Creates a new instance of DialogContentAssistant.
+ */
+ public DialogContentAssistant()
+ {
+ super();
+ this.possibleCompletionsVisible = false;
+ }
+
+
+ /**
+ * Installs content assist support on the given subject.
+ *
+ * @param text
+ * the one who requests content assist
+ */
+ public void install( Text text )
+ {
+ this.control = text;
+ this.control.addFocusListener( this );
+ super.install( new TextContentAssistSubjectAdapter( text ) );
+ }
+
+
+ /**
+ * Installs content assist support on the given subject.
+ *
+ * @param combo
+ * the one who requests content assist
+ */
+ public void install( Combo combo )
+ {
+ this.control = combo;
+ this.control.addFocusListener( this );
+ super.install( new ComboContentAssistSubjectAdapter( combo ) );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.contentassist.ContentAssistant#install(org.eclipse.jface.text.ITextViewer)
+ */
+ public void install( ITextViewer viewer )
+ {
+ this.control = viewer.getTextWidget();
+ this.control.addFocusListener( this );
+
+ // stop traversal (ESC) if popup is shown
+ this.control.addTraverseListener( new TraverseListener()
+ {
+ public void keyTraversed( TraverseEvent e )
+ {
+ if ( possibleCompletionsVisible )
+ {
+ e.doit = false;
+ }
+ }
+ } );
+
+ super.install( viewer );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.contentassist.ContentAssistant#uninstall()
+ */
+ public void uninstall()
+ {
+ if ( this.handlerActivation != null )
+ {
+ IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+ IHandlerService.class );
+ handlerService.deactivateHandler( this.handlerActivation );
+ this.handlerActivation = null;
+ }
+
+ if ( this.control != null )
+ {
+ this.control.removeFocusListener( this );
+ }
+
+ super.uninstall();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.contentassist.ContentAssistant#restoreCompletionProposalPopupSize()
+ */
+ protected Point restoreCompletionProposalPopupSize()
+ {
+ possibleCompletionsVisible = true;
+ return super.restoreCompletionProposalPopupSize();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.contentassist.ContentAssistant#showPossibleCompletions()
+ */
+ public String showPossibleCompletions()
+ {
+ possibleCompletionsVisible = true;
+ return super.showPossibleCompletions();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.contentassist.ContentAssistant#possibleCompletionsClosed()
+ */
+ protected void possibleCompletionsClosed()
+ {
+ this.possibleCompletionsVisible = false;
+ super.possibleCompletionsClosed();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
+ */
+ public void focusGained( FocusEvent e )
+ {
+ IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+ IHandlerService.class );
+ if ( handlerService != null )
+ {
+ IHandler handler = new org.eclipse.core.commands.AbstractHandler()
+ {
+ public Object execute( ExecutionEvent event ) throws org.eclipse.core.commands.ExecutionException
+ {
+ showPossibleCompletions();
+ return null;
+ }
+ };
+ this.handlerActivation = handlerService.activateHandler(
+ ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, handler );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
+ */
+ public void focusLost( FocusEvent e )
+ {
+ if ( this.handlerActivation != null )
+ {
+ IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+ IHandlerService.class );
+ handlerService.deactivateHandler( this.handlerActivation );
+ this.handlerActivation = null;
+ }
+ }
+}
Propchange: directory/sandbox/felixk/studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/DialogContentAssistant.java
------------------------------------------------------------------------------
svn:eol-style = native