[Fedora-directory-commits] console/src/com/netscape/management/client/components Table.java, 1.1.1.1, 1.2 TableSorter.java, 1.1.1.1, 1.2

Richard Allen Megginson rmeggins at fedoraproject.org
Tue Dec 16 22:16:12 UTC 2008


Author: rmeggins

Update of /cvs/dirsec/console/src/com/netscape/management/client/components
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv22177/console/src/com/netscape/management/client/components

Modified Files:
	Table.java TableSorter.java 
Log Message:
Resolves: bug 198090
Bug Description: ACI editor table sort problem
Reviewed by: nkinder (Thanks!)
Fix Description: The main problem was that the Table Model code was not checking the type of the model change event, and was just unconditionally resetting/initializing the internal indexes array every time the checkbox was checked.  This caused the table to revert back to the original order every time a checkbox was checked on or off.  The only events which should cause the indexes to be reset/initialized are the INSERT and DELETE types, not the UPDATE type.  There were also some problems with setting up the initial model, and I cleaned up some bogus code.
Platforms tested: RHEL5
Flag Day: no
Doc impact: no



Index: Table.java
===================================================================
RCS file: /cvs/dirsec/console/src/com/netscape/management/client/components/Table.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- Table.java	18 Jul 2005 00:34:13 -0000	1.1.1.1
+++ Table.java	16 Dec 2008 22:16:09 -0000	1.2
@@ -96,7 +96,8 @@
      */
     public Table(TableModel dm, boolean enableClientSideSorting)
     {
-        this((enableClientSideSorting ? new TableSorter(dm) : dm), null, null);
+        this(((enableClientSideSorting && !(dm instanceof ISortableTableModel)) ?
+                new TableSorter(dm) : dm), null, null);
         this.enableClientSideSorting = enableClientSideSorting; 
     }
     
@@ -135,7 +136,6 @@
     {
         super(dm, cm, sm);
         initialize();
-        TableModel tm = getModel();
 		initializeColumnHeaders();
 	}
 
@@ -214,11 +214,16 @@
         Enumeration e = tcm.getColumns();
         int viewColumnIndex = 0;
         TableModel tm  = getModel();
+        // can't refer to this.enableClientSideSorting here because initializeColumnHeaders
+        // can be called from ctor, before this members are set - but the ctor will have
+        // wrapped tm in a sortable interface, so check the type of the model to see if it
+        // is sortable
+        boolean isSortable = (tm instanceof ISortableTableModel);
         while (e.hasMoreElements())
         {
             int columnIndex = convertColumnIndexToModel(viewColumnIndex); 
             int alignment = getTableHeaderAlignmentByClass(tm.getColumnClass(columnIndex));
-            TextHeaderRenderer headerRenderer = new TextHeaderRenderer(alignment, this.enableClientSideSorting);
+            TextHeaderRenderer headerRenderer = new TextHeaderRenderer(alignment, isSortable);
             TableColumn column = (TableColumn)e.nextElement();
             column.setHeaderRenderer(headerRenderer);
             viewColumnIndex++;
@@ -318,29 +323,12 @@
 	 */
 	public void setModel(TableModel dataModel) throws IllegalArgumentException
 	{
-
-        //tableModel = dataModel;
-        if (this.enableClientSideSorting) {
-          super.setModel(new TableSorter(dataModel));
-        } else {
-          super.setModel(dataModel);
-        }
-
+	    super.setModel(dataModel);
 		initializeColumnHeaders();
 	}
 
 
 	/**
-	 * Gets the data model for this table.
-	 * 
-	 * @return TableModel the data source for this table
-	 * @see JTable#setModel()
-	 */
-    public TableModel getModel() {
-        return super.getModel();
-    }
-	
-	/**
 	 * Sets the column model for this table to newModel and registers 
 	 * for listener notifications from the new column model. Also sets 
 	 * the column model of the JTableHeader to columnModel.


Index: TableSorter.java
===================================================================
RCS file: /cvs/dirsec/console/src/com/netscape/management/client/components/TableSorter.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- TableSorter.java	18 Jul 2005 00:34:14 -0000	1.1.1.1
+++ TableSorter.java	16 Dec 2008 22:16:09 -0000	1.2
@@ -184,6 +184,10 @@
     public void reallocateIndexes() {
         int rowCount = model.getRowCount();
         Debug.println(8, "TableSorter.reallocateIndexes: getRowCount=" + rowCount);
+        if ((indexes != null) && (rowCount == indexes.length)) {
+            Debug.println(8, "TableSorter.reallocateIndexes: the model row count is the same as our row count - no need to reallocate");
+            return;
+        }
 
         // Set up a new array of indexes with the right number of elements
         // for the new data model.
@@ -196,8 +200,13 @@
     }
 
     public void tableChanged(TableModelEvent e) {
-        Debug.println(8, "TableSorter.tableChanged"); 
-        reallocateIndexes();
+        Debug.println(8, "TableSorter.tableChanged");
+        if (e.getType() != TableModelEvent.UPDATE) {
+            Debug.println(8, "TableSorter.checkModel: table size was changed - need to reallocate indexes");
+            reallocateIndexes();
+        } else {
+            Debug.println(8, "TableSorter.checkModel: table size was not changed - no need to reallocate indexes");            
+        }
         super.tableChanged(e);
     }
 




More information about the Fedora-directory-commits mailing list