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 2008/08/28 02:10:15 UTC
svn commit: r689675 - in /directory/studio/trunk:
ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/
ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/
Author: seelmann
Date: Wed Aug 27 17:10:14 2008
New Revision: 689675
URL: http://svn.apache.org/viewvc?rev=689675&view=rev
Log:
Fix for DIRSTUDIO-85: +, * and @ supported by search dialog, improved content assistent of returning attributes field
Modified:
directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesContentAssistProcessor.java
directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidget.java
directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/AttributeDescription.java
Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesContentAssistProcessor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesContentAssistProcessor.java?rev=689675&r1=689674&r2=689675&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesContentAssistProcessor.java (original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesContentAssistProcessor.java Wed Aug 27 17:10:14 2008
@@ -22,7 +22,8 @@
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -53,18 +54,18 @@
private char[] autoActivationCharacters;
/** The possible attribute types */
- private String[] possibleAttributeTypes;
+ private List<String> proposals;
/**
* Creates a new instance of ReturningAttributesContentAssistProcessor.
*
- * @param possibleAttributeNames
+ * @param proposals the proposals
*/
- public ReturningAttributesContentAssistProcessor( String[] possibleAttributeNames )
+ public ReturningAttributesContentAssistProcessor( List<String> proposals )
{
super();
- setPossibleAttributeTypes( possibleAttributeTypes );
+ setProposals( proposals );
}
@@ -80,24 +81,57 @@
/**
* Sets the possible attribute types.
*
- * @param possibleAttributeTypes the possible strings
+ * @param proposals the possible strings
*/
- public void setPossibleAttributeTypes( String[] possibleAttributeTypes )
+ public void setProposals( List<String> proposals )
{
- if ( possibleAttributeTypes == null )
+ if ( proposals == null )
{
- possibleAttributeTypes = new String[0];
+ proposals = new ArrayList<String>();
}
- // set possible strings
- Arrays.sort( possibleAttributeTypes );
- this.possibleAttributeTypes = possibleAttributeTypes;
+ // sort proposals, attributes first
+ Comparator<? super String> comparator = new Comparator<String>()
+ {
+ public int compare( String o1, String o2 )
+ {
+ if ( "+".equals( o1 ) && !"+".equals( o2 ) )
+ {
+ return 4;
+ }
+ if ( "+".equals( o2 ) && !"+".equals( o1 ) )
+ {
+ return -4;
+ }
+
+ if ( "*".equals( o1 ) && !"*".equals( o2 ) )
+ {
+ return 3;
+ }
+ if ( "*".equals( o2 ) && !"*".equals( o1 ) )
+ {
+ return -3;
+ }
+
+ if ( o1.startsWith( "@" ) && !o2.startsWith( "@" ) )
+ {
+ return 2;
+ }
+ if ( o2.startsWith( "@" ) && !o1.startsWith( "@" ) )
+ {
+ return -2;
+ }
+
+ return o1.compareToIgnoreCase( o2 );
+ }
+ };
+ Collections.sort( proposals, comparator );
+ this.proposals = proposals;
// set auto activation characters
Set<Character> characterSet = new HashSet<Character>();
- for ( int i = 0; i < possibleAttributeTypes.length; i++ )
+ for ( String string : proposals )
{
- String string = possibleAttributeTypes[i];
for ( int k = 0; k < string.length(); k++ )
{
char ch = string.charAt( k );
@@ -151,12 +185,12 @@
// create proposal list
List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>();
- for ( int k = 0; k < possibleAttributeTypes.length; k++ )
+ for ( String string : proposals )
{
- if ( possibleAttributeTypes[k].toUpperCase().startsWith( attribute.toUpperCase() ) )
+ if ( string.toUpperCase().startsWith( attribute.toUpperCase() ) )
{
- ICompletionProposal proposal = new CompletionProposal( possibleAttributeTypes[k] + ", ", start,
- documentOffset - start, possibleAttributeTypes[k].length() + 2, null, possibleAttributeTypes[k],
+ ICompletionProposal proposal = new CompletionProposal( string + ", ", start,
+ documentOffset - start, string.length() + 2, null, string,
null, null );
proposalList.add( proposal );
}
Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidget.java?rev=689675&r1=689674&r2=689675&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidget.java (original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidget.java Wed Aug 27 17:10:14 2008
@@ -22,6 +22,7 @@
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
@@ -104,7 +105,7 @@
returningAttributesCombo.setLayoutData( gd );
// Content assist
- contentAssistProcessor = new ReturningAttributesContentAssistProcessor( new String[0] );
+ contentAssistProcessor = new ReturningAttributesContentAssistProcessor( null );
DialogContentAssistant raca = new DialogContentAssistant();
raca.enableAutoInsert( true );
raca.enableAutoActivation( true );
@@ -141,8 +142,26 @@
public void setBrowserConnection( IBrowserConnection browserConnection )
{
this.browserConnection = browserConnection;
- contentAssistProcessor.setPossibleAttributeTypes( browserConnection == null ? new String[0] : SchemaUtils
- .getNamesAsArray( browserConnection.getSchema().getAttributeTypeDescriptions() ) );
+
+ List<String> proposals = new ArrayList<String>();
+ if ( browserConnection != null )
+ {
+ // add attribute types
+ proposals.addAll( SchemaUtils.getNames( browserConnection.getSchema().getAttributeTypeDescriptions() ) );
+
+ // add @<object class names>
+ Collection<String> ocNames = SchemaUtils.getNames( browserConnection.getSchema()
+ .getObjectClassDescriptions() );
+ for ( String ocName : ocNames )
+ {
+ proposals.add( "@" + ocName );
+ }
+
+ proposals.add( "+" );
+ proposals.add( "*" );
+ }
+
+ contentAssistProcessor.setProposals( proposals );
}
Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/AttributeDescription.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/AttributeDescription.java?rev=689675&r1=689674&r2=689675&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/AttributeDescription.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/AttributeDescription.java Wed Aug 27 17:10:14 2008
@@ -23,11 +23,15 @@
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.syntax.ObjectClassDescription;
import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
/**
@@ -198,7 +202,7 @@
/**
* Checks if the given attribute description is subtype of
- * this attriubte description.
+ * this attribute description.
*
* @param other the other attribute description
* @param schema the schema
@@ -222,9 +226,43 @@
return false;
}
- // check type
AttributeTypeDescription myAtd = schema.getAttributeTypeDescription( this.getParsedAttributeType() );
AttributeTypeDescription otherAtd = schema.getAttributeTypeDescription( other.getParsedAttributeType() );
+
+ // special case *: all user attributes (RFC4511)
+ if ( ISearch.ALL_USER_ATTRIBUTES.equals( other.description ) && !SchemaUtils.isOperational( myAtd ) )
+ {
+ return true;
+ }
+
+ // special case +: all operational attributes (RFC3673)
+ if ( ISearch.ALL_OPERATIONAL_ATTRIBUTES.equals( other.description ) && SchemaUtils.isOperational( myAtd ) )
+ {
+ return true;
+ }
+
+ // special case @: attributes by object class (RFC4529)
+ if ( other.description.length() > 1 && other.description.startsWith( "@" ) )
+ {
+ String objectClass = other.description.substring( 1 );
+ ObjectClassDescription ocd = schema.getObjectClassDescription( objectClass );
+ ocd.getMayAttributeTypes();
+ ocd.getMustAttributeTypes();
+
+ Collection<String> names = new HashSet<String>();
+ names.addAll( SchemaUtils.getMayAttributeTypeDescriptionNamesTransitive( ocd, schema ) );
+ names.addAll( SchemaUtils.getMustAttributeTypeDescriptionNamesTransitive( ocd, schema ) );
+ for ( String name : names )
+ {
+ AttributeTypeDescription atd = schema.getAttributeTypeDescription( name );
+ if ( myAtd == atd )
+ {
+ return true;
+ }
+ }
+ }
+
+ // check type
if ( myAtd != otherAtd )
{
AttributeTypeDescription superiorAtd = null;