From 03605532e7a79384ee40dcf1838135de8c5cdc7c Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 19 Nov 2008 02:19:09 +0000
Subject: [PATCH] Complete fix for issue 3622.  Make all the elements in the schema panels sorted without taking into account the case.

---
 opends/src/guitools/org/opends/guitools/controlpanel/util/LowerCaseComparator.java    |   61 ++++++++++++++++++++++++++++++
 opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardAttributePanel.java   |    7 ++-
 opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardObjectClassPanel.java |    7 ++-
 opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java        |   12 +-----
 opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java              |    2 
 opends/src/guitools/org/opends/guitools/controlpanel/ui/AttributeSyntaxPanel.java     |    5 ++
 6 files changed, 78 insertions(+), 16 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/AttributeSyntaxPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/AttributeSyntaxPanel.java
index 6ca22c1..37d0fbb 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/AttributeSyntaxPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/AttributeSyntaxPanel.java
@@ -33,6 +33,7 @@
 import java.awt.GridBagConstraints;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.util.Comparator;
 import java.util.TreeSet;
 
 import javax.swing.DefaultListModel;
@@ -41,6 +42,7 @@
 
 import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
 import org.opends.guitools.controlpanel.ui.components.TitlePanel;
+import org.opends.guitools.controlpanel.util.LowerCaseComparator;
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.messages.Message;
 import org.opends.server.api.AttributeSyntax;
@@ -204,7 +206,8 @@
     }
     description.setText(n);
 
-    TreeSet<String> attributes = new TreeSet<String>();
+    Comparator<String> lowerCaseComparator = new LowerCaseComparator();
+    TreeSet<String> attributes = new TreeSet<String>(lowerCaseComparator);
     for (AttributeType attr : schema.getAttributeTypes().values())
     {
       if (syntax == attr.getSyntax())
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java
index bf41891..4019934 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java
@@ -80,6 +80,7 @@
 import org.opends.guitools.controlpanel.ui.nodes.*;
 import org.opends.guitools.controlpanel.ui.renderer.CustomListCellRenderer;
 import org.opends.guitools.controlpanel.ui.renderer.TreeCellRenderer;
+import org.opends.guitools.controlpanel.util.LowerCaseComparator;
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.messages.Message;
 import org.opends.server.api.AttributeSyntax;
@@ -693,16 +694,7 @@
     }
     TreePath newSelectionPath = null;
 
-    /**
-     * {@inheritDoc}
-     */
-    Comparator<String> lowerCaseComparator = new Comparator<String>()
-    {
-      public int compare(String s1, String s2)
-      {
-        return s1.toLowerCase().compareTo(s2.toLowerCase());
-      }
-    };
+    Comparator<String> lowerCaseComparator = new LowerCaseComparator();
 
     TreeSet<String> standardOcNames = new TreeSet<String>(lowerCaseComparator);
     HashMap<String, StandardObjectClassTreeNode> hmStandardOcs =
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardAttributePanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardAttributePanel.java
index 4fb1188..7311e87 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardAttributePanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardAttributePanel.java
@@ -35,6 +35,7 @@
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -44,6 +45,7 @@
 
 import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
 import org.opends.guitools.controlpanel.ui.components.TitlePanel;
+import org.opends.guitools.controlpanel.util.LowerCaseComparator;
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.messages.Message;
 import org.opends.messages.MessageBuilder;
@@ -328,7 +330,8 @@
 
     type.setText(getTypeValue(attr).toString());
 
-    SortedSet<String> requiredByOcs = new TreeSet<String>();
+    Comparator<String> lowerCaseComparator = new LowerCaseComparator();
+    SortedSet<String> requiredByOcs = new TreeSet<String>(lowerCaseComparator);
     for (ObjectClass oc : schema.getObjectClasses().values())
     {
       if (oc.getRequiredAttributeChain().contains(attr))
@@ -344,7 +347,7 @@
       model.addElement(oc);
     }
 
-    SortedSet<String> optionalByOcs = new TreeSet<String>();
+    SortedSet<String> optionalByOcs = new TreeSet<String>(lowerCaseComparator);
     for (ObjectClass oc : schema.getObjectClasses().values())
     {
       if (oc.getOptionalAttributeChain().contains(attr))
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardObjectClassPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardObjectClassPanel.java
index 91eb782..203b6a8 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardObjectClassPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StandardObjectClassPanel.java
@@ -35,6 +35,7 @@
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -49,6 +50,7 @@
 
 import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
 import org.opends.guitools.controlpanel.ui.components.TitlePanel;
+import org.opends.guitools.controlpanel.util.LowerCaseComparator;
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.messages.Message;
 import org.opends.messages.MessageBuilder;
@@ -357,7 +359,8 @@
 
     type.setText(getTypeValue(oc).toString());
 
-    SortedSet<String> requiredAttrs = new TreeSet<String>();
+    Comparator<String> lowerCaseComparator = new LowerCaseComparator();
+    SortedSet<String> requiredAttrs = new TreeSet<String>(lowerCaseComparator);
     Set<String> inheritedAttrs = new HashSet<String>();
     for (AttributeType attr : oc.getRequiredAttributeChain())
     {
@@ -389,7 +392,7 @@
       hmAttrs.put(v, schema.getAttributeType(attr.toLowerCase()));
     }
 
-    SortedSet<String> optionalAttrs = new TreeSet<String>();
+    SortedSet<String> optionalAttrs = new TreeSet<String>(lowerCaseComparator);
     inheritedAttrs = new HashSet<String>();
     for (AttributeType attr : oc.getOptionalAttributeChain())
     {
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/util/LowerCaseComparator.java b/opends/src/guitools/org/opends/guitools/controlpanel/util/LowerCaseComparator.java
new file mode 100644
index 0000000..6ec01f0
--- /dev/null
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/util/LowerCaseComparator.java
@@ -0,0 +1,61 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Copyright 2008 Sun Microsystems, Inc.
+ */
+
+package org.opends.guitools.controlpanel.util;
+
+import java.util.Comparator;
+
+/**
+ * Class used to compare Strings without take into account the case.  It can
+ * be used to sort Strings in TreeSets for instance.
+ *
+ */
+public class LowerCaseComparator implements Comparator<String>
+{
+  /**
+   * {@inheritDoc}
+   */
+  public int compare(String s1, String s2)
+  {
+    if ((s1 != null) && (s2 != null))
+    {
+      return s1.toLowerCase().compareTo(s2.toLowerCase());
+    }
+    else if (s2 != null)
+    {
+      return -1;
+    }
+    else if (s1 != null)
+    {
+      return 1;
+    }
+    else
+    {
+      return 0;
+    }
+  }
+}
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java b/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
index fa481ca..b8cd3df 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -1721,7 +1721,7 @@
       }
       if (!isStandard)
       {
-        isStandard = fileName.indexOf("-rfc") != -1;
+        isStandard = fileName.toLowerCase().indexOf("-rfc") != -1;
       }
     }
     return isStandard;

--
Gitblit v1.10.0