Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 39240 invoked from network); 29 Aug 2007 16:23:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Aug 2007 16:23:04 -0000 Received: (qmail 24368 invoked by uid 500); 29 Aug 2007 16:23:00 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 24304 invoked by uid 500); 29 Aug 2007 16:23:00 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 24293 invoked by uid 99); 29 Aug 2007 16:22:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2007 09:22:59 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2007 16:23:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DAAF61A9832; Wed, 29 Aug 2007 09:22:38 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r570853 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards: NewAttributeTypeContentWizardPage.java NewAttributeTypeMatchingRulesWizardPage.java Date: Wed, 29 Aug 2007 16:22:37 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070829162238.DAAF61A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pamarcelot Date: Wed Aug 29 09:22:36 2007 New Revision: 570853 URL: http://svn.apache.org/viewvc?rev=570853&view=rev Log: Fixed bugs that caused the value of the UI to not be used when creating the AT. Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java?rev=570853&r1=570852&r2=570853&view=diff ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java (original) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.java Wed Aug 29 09:22:36 2007 @@ -20,10 +20,16 @@ package org.apache.directory.studio.apacheds.schemaeditor.view.wizards; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + import org.apache.directory.shared.ldap.schema.UsageEnum; import org.apache.directory.studio.apacheds.schemaeditor.Activator; import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants; import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler; +import org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl; import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.AttributeTypeSelectionDialog; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.ArrayContentProvider; @@ -157,11 +163,32 @@ // Syntax Label syntaxLabel = new Label( syntaxGroup, SWT.NONE ); syntaxLabel.setText( "Syntax:" ); - Combo syntaxCombo = new Combo( syntaxGroup, SWT.BORDER ); + Combo syntaxCombo = new Combo( syntaxGroup, SWT.READ_ONLY ); syntaxCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); syntaxComboViewer = new ComboViewer( syntaxCombo ); syntaxComboViewer.setContentProvider( new ArrayContentProvider() ); - syntaxComboViewer.setLabelProvider( new LabelProvider() ); + syntaxComboViewer.setLabelProvider( new LabelProvider() + { + public String getText( Object element ) + { + if ( element instanceof SyntaxImpl ) + { + SyntaxImpl syntax = ( SyntaxImpl ) element; + + String name = syntax.getName(); + if ( name != null ) + { + return name + " - (" + syntax.getOid() + ")"; + } + else + { + return "(None) - (" + syntax.getOid() + ")"; + } + } + + return super.getText( element ); + } + } ); // Syntax Length Label lengthLabel = new Label( syntaxGroup, SWT.NONE ); @@ -200,19 +227,72 @@ noUserModificationCheckbox = new Button( propertiesGroup, SWT.CHECK ); noUserModificationCheckbox.setText( "No User Modification" ); + initFields(); + setControl( composite ); } /** + * Initializes the UI fields. + */ + private void initFields() + { + if ( schemaHandler != null ) + { + // Getting the syntaxes + List syntaxes = new ArrayList( schemaHandler.getSyntaxes() ); + + // Sorting the syntaxes + Collections.sort( syntaxes, new Comparator() + { + + public int compare( SyntaxImpl o1, SyntaxImpl o2 ) + { + String[] o1Names = o1.getNames(); + String[] o2Names = o2.getNames(); + + // Comparing the First Name + if ( ( o1Names != null ) && ( o2Names != null ) ) + { + if ( ( o1Names.length > 0 ) && ( o2Names.length > 0 ) ) + { + return o1Names[0].compareToIgnoreCase( o2Names[0] ); + } + else if ( ( o1Names.length == 0 ) && ( o2Names.length > 0 ) ) + { + return "".compareToIgnoreCase( o2Names[0] ); + } + else if ( ( o1Names.length > 0 ) && ( o2Names.length == 0 ) ) + { + return o1Names[0].compareToIgnoreCase( "" ); + } + } + + // Default + return o1.toString().compareToIgnoreCase( o2.toString() ); + } + } ); + + // Setting the input + syntaxComboViewer.setInput( syntaxes ); + } + } + + + /** * Verifies if the superior exists and displays an error if not. */ private void verifySuperior() { - if ( schemaHandler.getAttributeType( superiorText.getText() ) == null ) + String superior = superiorText.getText(); + if ( ( superior != null ) && ( !superior.equals( "" ) ) ) { - displayErrorMessage( "The superior attribute type does not exist." ); - return; + if ( schemaHandler.getAttributeType( superiorText.getText() ) == null ) + { + displayErrorMessage( "The superior attribute type does not exist." ); + return; + } } displayErrorMessage( null ); @@ -241,7 +321,15 @@ */ public String getSuperiorValue() { - return superiorText.getText(); + String superior = superiorText.getText(); + if ( ( superior != null ) && ( !superior.equals( "" ) ) ) + { + return superior; + } + else + { + return null; + } } @@ -293,15 +381,14 @@ */ public String getSyntax() { - StructuredSelection selection = ( StructuredSelection ) syntaxComboViewer.getSelection(); - if ( !selection.isEmpty() ) + SyntaxImpl syntax = ( SyntaxImpl ) ( ( StructuredSelection ) syntaxComboViewer.getSelection() ) + .getFirstElement(); + if ( syntax != null ) { - return ( String ) selection.getFirstElement(); - } - else - { - return null; + return syntax.getOid(); } + + return null; } Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java?rev=570853&r1=570852&r2=570853&view=diff ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java (original) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.java Wed Aug 29 09:22:36 2007 @@ -20,11 +20,19 @@ package org.apache.directory.studio.apacheds.schemaeditor.view.wizards; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + import org.apache.directory.studio.apacheds.schemaeditor.Activator; import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants; +import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler; +import org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -47,6 +55,36 @@ */ public class NewAttributeTypeMatchingRulesWizardPage extends WizardPage { + /** The SchemaHandler */ + private SchemaHandler schemaHandler; + + /** The LabelProvider */ + private LabelProvider labelProvider = new LabelProvider() + { + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + */ + public String getText( Object element ) + { + if ( element instanceof MatchingRuleImpl ) + { + MatchingRuleImpl mr = ( MatchingRuleImpl ) element; + + String name = mr.getName(); + if ( name != null ) + { + return name + " - (" + mr.getOid() + ")"; + } + else + { + return "(None) - (" + mr.getOid() + ")"; + } + } + + return super.getText( element ); + } + }; + // UI fields private ComboViewer equalityComboViewer; private ComboViewer orderingComboViewer; @@ -63,6 +101,8 @@ setDescription( "Please specify the matching rules (equality, ordering and substring) to use for the attribute type." ); setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_ATTRIBUTE_TYPE_NEW_WIZARD ) ); + + schemaHandler = Activator.getDefault().getSchemaHandler(); } @@ -84,35 +124,86 @@ // Equality Label equalityLabel = new Label( matchingRulesGroup, SWT.NONE ); equalityLabel.setText( "Equality:" ); - Combo equalityCombo = new Combo( matchingRulesGroup, SWT.NONE ); + Combo equalityCombo = new Combo( matchingRulesGroup, SWT.READ_ONLY ); equalityCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); equalityComboViewer = new ComboViewer( equalityCombo ); equalityComboViewer.setContentProvider( new ArrayContentProvider() ); - equalityComboViewer.setLabelProvider( new LabelProvider() ); + equalityComboViewer.setLabelProvider( labelProvider ); // Ordering Label orderingLabel = new Label( matchingRulesGroup, SWT.NONE ); orderingLabel.setText( "Ordering:" ); - Combo orderingCombo = new Combo( matchingRulesGroup, SWT.NONE ); + Combo orderingCombo = new Combo( matchingRulesGroup, SWT.READ_ONLY ); orderingCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); orderingComboViewer = new ComboViewer( orderingCombo ); orderingComboViewer.setContentProvider( new ArrayContentProvider() ); - orderingComboViewer.setLabelProvider( new LabelProvider() ); + orderingComboViewer.setLabelProvider( labelProvider ); // Substring Label substringLabel = new Label( matchingRulesGroup, SWT.NONE ); substringLabel.setText( "Substring:" ); - Combo substringCombo = new Combo( matchingRulesGroup, SWT.NONE ); + Combo substringCombo = new Combo( matchingRulesGroup, SWT.READ_ONLY ); substringCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); substringComboViewer = new ComboViewer( substringCombo ); substringComboViewer.setContentProvider( new ArrayContentProvider() ); - substringComboViewer.setLabelProvider( new LabelProvider() ); + substringComboViewer.setLabelProvider( labelProvider ); + + initFields(); setControl( composite ); } /** + * Initializes the UI fields. + */ + private void initFields() + { + if ( schemaHandler != null ) + { + // Getting the matching rules + List matchingRules = new ArrayList( schemaHandler.getMatchingRules() ); + + // Sorting the matching rules + Collections.sort( matchingRules, new Comparator() + { + + public int compare( MatchingRuleImpl o1, MatchingRuleImpl o2 ) + { + String[] o1Names = o1.getNames(); + String[] o2Names = o2.getNames(); + + // Comparing the First Name + if ( ( o1Names != null ) && ( o2Names != null ) ) + { + if ( ( o1Names.length > 0 ) && ( o2Names.length > 0 ) ) + { + return o1Names[0].compareToIgnoreCase( o2Names[0] ); + } + else if ( ( o1Names.length == 0 ) && ( o2Names.length > 0 ) ) + { + return "".compareToIgnoreCase( o2Names[0] ); + } + else if ( ( o1Names.length > 0 ) && ( o2Names.length == 0 ) ) + { + return o1Names[0].compareToIgnoreCase( "" ); + } + } + + // Default + return o1.toString().compareToIgnoreCase( o2.toString() ); + } + } ); + + // Setting the input + equalityComboViewer.setInput( matchingRules ); + orderingComboViewer.setInput( matchingRules ); + substringComboViewer.setInput( matchingRules ); + } + } + + + /** * Gets the value of the equality matching rule. * * @return @@ -120,7 +211,22 @@ */ public String getEqualityMatchingRuleValue() { - return null; // TODO: implement + MatchingRuleImpl mr = ( MatchingRuleImpl ) ( ( StructuredSelection ) equalityComboViewer.getSelection() ) + .getFirstElement(); + if ( mr != null ) + { + String[] names = mr.getNames(); + if ( ( names != null ) && ( names.length > 0 ) ) + { + return mr.getName(); + } + else + { + return mr.getOid(); + } + } + + return null; } @@ -132,7 +238,22 @@ */ public String getOrderingMatchingRuleValue() { - return null; // TODO: implement + MatchingRuleImpl mr = ( MatchingRuleImpl ) ( ( StructuredSelection ) orderingComboViewer.getSelection() ) + .getFirstElement(); + if ( mr != null ) + { + String[] names = mr.getNames(); + if ( ( names != null ) && ( names.length > 0 ) ) + { + return mr.getName(); + } + else + { + return mr.getOid(); + } + } + + return null; } @@ -144,6 +265,21 @@ */ public String getSubstringMatchingRuleValue() { - return null; // TODO: implement + MatchingRuleImpl mr = ( MatchingRuleImpl ) ( ( StructuredSelection ) substringComboViewer.getSelection() ) + .getFirstElement(); + if ( mr != null ) + { + String[] names = mr.getNames(); + if ( ( names != null ) && ( names.length > 0 ) ) + { + return mr.getName(); + } + else + { + return mr.getOid(); + } + } + + return null; } }