BF [ 1734327 ] Acct Viewer sorting is very very slow

http://sourceforge.net/tracker/index.php?func=detail&aid=1734327&group_id=176962&atid=879332
This commit is contained in:
teo_sarca 2007-06-10 10:17:30 +00:00
parent 04105b1080
commit 12309cfd2a
3 changed files with 30 additions and 31 deletions

View File

@ -360,6 +360,16 @@ public class RModel implements Serializable
{
m_data.moveRow(from,to);
} // moveRow
/**
* Returns the ArrayList of ArrayLists that contains the table's data values.
* The ArrayLists contained in the outer vector are each a single row of values.
* @return the ArrayList of ArrayLists containing the tables data values
* @author Teo Sarca [ 1734327 ]
*/
protected ArrayList<ArrayList<Object>> getRows() {
return m_data.rows;
}
/*************************************************************************/

View File

@ -205,8 +205,7 @@ public class ResultTable extends JTable implements MouseListener
* Sort Table
* @param modelColumnIndex
*/
@SuppressWarnings("unchecked")
private void sort (int modelColumnIndex)
private void sort (final int modelColumnIndex)
{
int rows = getRowCount();
if (rows == 0)
@ -224,37 +223,16 @@ public class ResultTable extends JTable implements MouseListener
ResultTableModel model = (ResultTableModel)getModel();
// Prepare sorting
MSort sort = new MSort(0, null);
final MSort sort = new MSort(0, null);
sort.setSortAsc(m_asc);
// while something to sort
sorting:
while (true)
{
// Create sortList
ArrayList<MSort> sortList = new ArrayList<MSort>(rows);
// fill with data entity
for (int i = 0; i < rows; i++)
{
Object value = model.getValueAt(i, modelColumnIndex);
sortList.add(new MSort(i, value));
// Sort the data list - teo_sarca [ 1734327 ]
Collections.sort(model.getDataList(), new Comparator<Object>() {
public int compare(Object o1, Object o2) {
Object item1 = ((ArrayList)o1).get(modelColumnIndex);
Object item2 = ((ArrayList)o2).get(modelColumnIndex);
return sort.compare(item1, item2);
}
// sort list it
Collections.sort(sortList, sort);
// move out of sequence row
for (int i = 0; i < rows; i++)
{
int index = ((MSort)sortList.get(i)).index;
if (i != index)
{
// log.config( "move " + i + " to " + index);
model.moveRow (i, index);
continue sorting;
}
}
// we are done
// log.config( "done");
break;
} // while something to sort
});
} // sort
} // ResultTable

View File

@ -16,6 +16,8 @@
*****************************************************************************/
package org.compiere.report.core;
import java.util.ArrayList;
import javax.swing.event.*;
import javax.swing.table.*;
@ -121,4 +123,13 @@ class ResultTableModel extends AbstractTableModel
m_model.moveRow (from, to);
} // moveRow
/**
* Returns the ArrayList of ArrayLists that contains the table's data values.
* The ArrayLists contained in the outer vector are each a single row of values.
* @return the ArrayList of ArrayLists containing the tables data values
* @author Teo Sarca [ 1734327 ]
*/
protected ArrayList<ArrayList<Object>> getDataList() {
return m_model.getRows();
}
} // ResultTableModel