Author: ruschein
Date: 2011-07-05 15:47:23 -0700 (Tue, 05 Jul 2011)
New Revision: 26038
Modified:
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
Log:
#72 Resolved slow cloumn sorting which was due to excessive calls to
CyTable.getMatchingRows().
Modified:
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
===================================================================
---
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
2011-07-05 22:46:29 UTC (rev 26037)
+++
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
2011-07-05 22:47:23 UTC (rev 26038)
@@ -9,7 +9,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
@@ -45,6 +44,7 @@
private final EquationCompiler compiler;
private boolean tableHasBooleanSelected;
private List<AttrNameAndVisibility> attrNamesAndVisibilities;
+ private Collection<CyRow> selectedRows = null;
public BrowserTableModel(final JTable table, final CyTable attrs, final
EquationCompiler compiler)
{
@@ -166,7 +166,9 @@
private CyRow mapRowIndexToRow(final int rowIndex) {
if (tableHasBooleanSelected) {
- final Set<CyRow> selectedRows =
attrs.getMatchingRows(CyNetwork.SELECTED, true);
+ if (selectedRows == null)
+ selectedRows =
attrs.getMatchingRows(CyNetwork.SELECTED, true);
+
int count = 0;
CyRow cyRow = null;
for (final CyRow selectedRow : selectedRows) {
@@ -195,7 +197,9 @@
int index = 0;
if (tableHasBooleanSelected) {
- final Set<CyRow> selectedRows =
attrs.getMatchingRows(CyNetwork.SELECTED, true);
+ if (selectedRows == null)
+ selectedRows =
attrs.getMatchingRows(CyNetwork.SELECTED, true);
+
for (final CyRow selectedRow : selectedRows) {
if (cyRow.get(primaryKey, primaryKeyType)
.equals(selectedRow.get(primaryKey,
primaryKeyType)))
@@ -220,6 +224,9 @@
private ValidatedObjectAndEditString
getValidatedObjectAndEditString(final CyRow row,
final String columnName)
{
+ if (row == null)
+ return null;
+
final Object raw = row.getRaw(columnName);
if (raw == null)
return null;
@@ -290,12 +297,14 @@
@Override
public void handleEvent(RowsCreatedEvent e) {
+ selectedRows = null;
fireTableDataChanged();
}
@Override
public void handleEvent(RowsSetEvent e) {
if (tableHasBooleanSelected) {
+ selectedRows = null;
boolean foundANonSelectedColumnName = false;
for (final RowSetRecord rowSet :
e.getPayloadCollection()) {
if
(!rowSet.getColumn().equals(CyNetwork.SELECTED)) {
@@ -317,6 +326,14 @@
private void handleRowValueUpdate(final CyRow row, final String
columnName, final Object newValue,
final Object newRawValue)
{
+ final int rowIndex = mapRowToRowIndex(row);
+ if (rowIndex == -1)
+ return;
+
+ final int columnIndex = mapColumnNameToColumnIndex(columnName);
+ if (columnIndex == -1)
+ return;
+
if (tableHasBooleanSelected &&
columnName.equals(CyNetwork.SELECTED)) {
/*
final boolean selected = (Boolean)newValue;
@@ -324,16 +341,9 @@
if (!selected && rowIndex == -1)
return;
*/
+ selectedRows = null;
fireTableDataChanged();
} else {
- final int rowIndex = mapRowToRowIndex(row);
- if (rowIndex == -1)
- return;
-
- final int columnIndex =
mapColumnNameToColumnIndex(columnName);
- if (columnIndex == -1)
- return;
-
final TableModelEvent event = new TableModelEvent(this,
rowIndex, rowIndex, columnIndex);
fireTableChanged(event);
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.