You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2007/08/29 18:22:37 UTC
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
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<SyntaxImpl> syntaxes = new ArrayList<SyntaxImpl>( schemaHandler.getSyntaxes() );
+
+ // Sorting the syntaxes
+ Collections.sort( syntaxes, new Comparator<SyntaxImpl>()
+ {
+
+ 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<MatchingRuleImpl> matchingRules = new ArrayList<MatchingRuleImpl>( schemaHandler.getMatchingRules() );
+
+ // Sorting the matching rules
+ Collections.sort( matchingRules, new Comparator<MatchingRuleImpl>()
+ {
+
+ 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;
}
}