bug fix [ 1585369 ] CTable sorting is TOO LAZY
This commit is contained in:
parent
d32428739b
commit
c7d5c58609
|
@ -41,7 +41,11 @@ public class CTable extends JTable
|
||||||
{
|
{
|
||||||
super(new DefaultTableModel());
|
super(new DefaultTableModel());
|
||||||
setColumnSelectionAllowed(false);
|
setColumnSelectionAllowed(false);
|
||||||
|
/* ARHIPAC: TEO: BEGIN: ORIGINAL: @arhipac.tools.annotation.Bug(228) -------------------------------------------- *
|
||||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
/* ARHIPAC: TEO: BEGIN: MODIFIED: @arhipac.tools.annotation.Bug(228) ------------------------------------------- */
|
||||||
|
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||||
|
/* ARHIPAC: TEO: BEGIN: END: @arhipac.tools.annotation.Bug(228) --------------------------------------------------- */
|
||||||
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||||
getTableHeader().addMouseListener(new CTableMouseListener());
|
getTableHeader().addMouseListener(new CTableMouseListener());
|
||||||
setSurrendersFocusOnKeystroke(true);
|
setSurrendersFocusOnKeystroke(true);
|
||||||
|
@ -222,6 +226,7 @@ public class CTable extends JTable
|
||||||
DefaultTableModel model = (DefaultTableModel)getModel();
|
DefaultTableModel model = (DefaultTableModel)getModel();
|
||||||
MSort sort = new MSort(0, null);
|
MSort sort = new MSort(0, null);
|
||||||
sort.setSortAsc(p_asc);
|
sort.setSortAsc(p_asc);
|
||||||
|
/* ARHIPAC: teo_sarca: BEGIN: ORIGINAL: @arhipac.tools.annotation.Bug(226) ----------------------------------- *
|
||||||
// while something to sort
|
// while something to sort
|
||||||
sorting:
|
sorting:
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -251,7 +256,24 @@ public class CTable extends JTable
|
||||||
// log.config("done");
|
// log.config("done");
|
||||||
break;
|
break;
|
||||||
} // while something to sort
|
} // while something to sort
|
||||||
|
/* ARHIPAC: teo_sarca: MODIFIED: @arhipac.tools.annotation.Bug(226) -------------------------------------------- */
|
||||||
|
// This comparator is used to sort vectors of data
|
||||||
|
class ColumnSorter<T> implements Comparator<T> {
|
||||||
|
int colIndex;
|
||||||
|
MSort sort;
|
||||||
|
ColumnSorter(int colIndex, MSort sort) {
|
||||||
|
this.colIndex = colIndex;
|
||||||
|
this.sort = sort;
|
||||||
|
}
|
||||||
|
public int compare(Object o1, Object o2) {
|
||||||
|
Object item1 = ((Vector)o1).get(this.colIndex);
|
||||||
|
Object item2 = ((Vector)o2).get(this.colIndex);
|
||||||
|
return this.sort.compare(item1, item2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Collections.sort(model.getDataVector(), new ColumnSorter<Object>(modelColumnIndex, sort));
|
||||||
|
/* ARHIPAC: teo_sarca: END: @arhipac.tools.annotation.Bug(226) ---------------------------------------------------- */
|
||||||
|
|
||||||
// selection
|
// selection
|
||||||
clearSelection();
|
clearSelection();
|
||||||
if (selected != null)
|
if (selected != null)
|
||||||
|
@ -261,6 +283,7 @@ public class CTable extends JTable
|
||||||
if (selected.equals(getValueAt(r, selCol)))
|
if (selected.equals(getValueAt(r, selCol)))
|
||||||
{
|
{
|
||||||
setRowSelectionInterval(r,r);
|
setRowSelectionInterval(r,r);
|
||||||
|
scrollRectToVisible(getCellRect(r, modelColumnIndex, true)); // @arhipac.tools.annotation.Bug(226)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public final class MSort implements Comparator, Serializable
|
||||||
public int compare (Object o1, Object o2)
|
public int compare (Object o1, Object o2)
|
||||||
{
|
{
|
||||||
// Get Objects to compare
|
// Get Objects to compare
|
||||||
Object cmp1 = null;
|
Object cmp1 = o1; // @arhipac.tools.annotation.Bug(226)
|
||||||
if (o1 instanceof MSort)
|
if (o1 instanceof MSort)
|
||||||
cmp1 = ((MSort)o1).data;
|
cmp1 = ((MSort)o1).data;
|
||||||
if (cmp1 instanceof NamePair)
|
if (cmp1 instanceof NamePair)
|
||||||
|
@ -87,10 +87,10 @@ public final class MSort implements Comparator, Serializable
|
||||||
{
|
{
|
||||||
if (cmp2 == null)
|
if (cmp2 == null)
|
||||||
return 0;
|
return 0;
|
||||||
return -1;
|
return -1 * m_multiplier; // @arhipac.tools.annotation.Bug(226)
|
||||||
}
|
}
|
||||||
if (cmp2 == null)
|
if (cmp2 == null)
|
||||||
return 1;
|
return 1 * m_multiplier; // @arhipac.tools.annotation.Bug(226)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* compare different data types
|
* compare different data types
|
||||||
|
@ -100,7 +100,7 @@ public final class MSort implements Comparator, Serializable
|
||||||
if (cmp1 instanceof String && cmp2 instanceof String)
|
if (cmp1 instanceof String && cmp2 instanceof String)
|
||||||
{
|
{
|
||||||
String s = (String)cmp1;
|
String s = (String)cmp1;
|
||||||
return s.compareTo((String)cmp2) * m_multiplier;
|
return s.compareToIgnoreCase((String)cmp2) * m_multiplier; // @arhipac.tools.annotation.Bug(226)
|
||||||
}
|
}
|
||||||
// Date
|
// Date
|
||||||
else if (cmp1 instanceof Timestamp && cmp2 instanceof Timestamp)
|
else if (cmp1 instanceof Timestamp && cmp2 instanceof Timestamp)
|
||||||
|
@ -120,10 +120,18 @@ public final class MSort implements Comparator, Serializable
|
||||||
Integer d = (Integer)cmp1;
|
Integer d = (Integer)cmp1;
|
||||||
return d.compareTo((Integer)cmp2) * m_multiplier;
|
return d.compareTo((Integer)cmp2) * m_multiplier;
|
||||||
}
|
}
|
||||||
|
/* ARHIPAC: TEO: BEGIN: @arhipac.tools.annotation.Bug(226) ------------------------------ */
|
||||||
|
// Double
|
||||||
|
else if (cmp1 instanceof Double && cmp2 instanceof Double)
|
||||||
|
{
|
||||||
|
Double d = (Double)cmp1;
|
||||||
|
return d.compareTo((Double)cmp2) * m_multiplier;
|
||||||
|
}
|
||||||
|
/* ARHIPAC: TEO: END: @arhipac.tools.annotation.Bug(226) -------------------------------- */
|
||||||
|
|
||||||
// Convert to string value
|
// Convert to string value
|
||||||
String s = cmp1.toString();
|
String s = cmp1.toString();
|
||||||
return s.compareTo(cmp2.toString()) * m_multiplier;
|
return s.compareToIgnoreCase(cmp2.toString()) * m_multiplier; // @arhipac.tools.annotation.Bug(226)
|
||||||
} // compare
|
} // compare
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue