Merge "Issue #1986 optimized table sorting" into omaha_13.4.1

Former-commit-id: edcd6c851c [formerly ed7005a317c7d5bca71370544d6f2f79e10e9dee]
Former-commit-id: 48d0829957
This commit is contained in:
Nate Jensen 2013-05-08 13:09:59 -05:00 committed by Gerrit Code Review
commit 2ab4ae9d16
5 changed files with 52 additions and 86 deletions

View file

@ -81,7 +81,7 @@ public abstract class FFMPTable extends Composite {
/** DR14406: For columns with more words */
protected static final int EXTRA_COLUMN_WIDTH = 28;
private static final String NAME = "Name";
protected String currentPfaf = null;
@ -401,23 +401,24 @@ public abstract class FFMPTable extends Composite {
break;
}
}
// Check if the sorted column is a column that will contain a filter.
// Check the gui config to see if colorCell is true. If false then do
// not apply filter
// Check if the sorted column is a column that will contain a
// filter. Check the gui config to see if colorCell is true. If
// false then do not apply filter
for (FFMPTableColumnXML xml : ffmpTableCols) {
if (xml.getColumnName().contains(sortedThreshCol.name())) {
if (ffmpConfig.isColorCell(sortedThreshCol)) {
// Only filter if colorCell is true
isAFilterCol = true;
filterNum = ffmpConfig.getFilterValue(sortedThreshCol);
reverseFilter = ffmpConfig.isReverseFilter(sortedThreshCol);
reverseFilter = ffmpConfig
.isReverseFilter(sortedThreshCol);
}
break;
}
}
}
table.removeAll();
if (tableData == null) {
@ -445,12 +446,12 @@ public abstract class FFMPTable extends Composite {
*/
if (!sortedColumnName.equalsIgnoreCase(NAME)) {
float dataVal = cellData[sortColIndex].getValueAsFloat();
// DR 14250 fix: any value not a number will be omitted
if (Float.isNaN(dataVal)) {
continue;
}
if (isAFilterCol) {
if (reverseFilter) {
if (dataVal > filterNum) {
@ -470,7 +471,7 @@ public abstract class FFMPTable extends Composite {
tableIndex = indexArray.indexOf(t);
}
}
/*
* VIRTUAL TABLE
*
@ -617,15 +618,13 @@ public abstract class FFMPTable extends Composite {
if (tableData == null) {
return;
}
String sortCol = (String) tc.getData();
int sortDir = getColumnAttributeData(sortCol).getSortDir();
int columnIndex = getColumnIndex(sortCol);
tableData.setSortColumnAndDirection(columnIndex, sortDir);
tableData.sortData();
tableData.sortData(columnIndex, sortDir);
FfmpTableConfigData ffmpTableCfgData = FfmpTableConfig.getInstance()
.getTableConfigData(this.siteKey);

View file

@ -19,7 +19,6 @@
**/
package com.raytheon.uf.viz.monitor.ffmp.ui.dialogs;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord.FIELDS;
@ -39,6 +38,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FFMPConfig.ThreshColNames;
* ------------ ---------- ----------- --------------------------
* Apr 6, 2009 lvenable Initial creation
* Apr 12, 2013 1902 mpduff Optimized the color assignments.
* May 7, 2013 1986 njensen Optimized sortBy
*
* </pre>
*
@ -205,30 +205,19 @@ public class FFMPTableCellData {
return this.hoverText;
}
/**
* Sort by method.
*
* @param direction
* Sort direction.
* @return Object that is a string or number.
*/
public Object sortByObject(int direction) {
if (cellText != null) {
return String.format("%-20S", cellText);
} else if (value.isNaN() == false) {
public float sortByNumber() {
if (!value.isNaN()) {
if (displayAsInt == true) {
return new Float(Math.round(value));
return (float) Math.round(value);
}
return new Float(value);
} else if (value.isNaN() == true) {
if (direction == SWT.DOWN) {
return Float.MAX_VALUE * -1.0f;
}
return Float.MAX_VALUE;
return value.floatValue();
} else {
// NaN is not displayed in the table when sorting by
// this column, so the value to return here is not especially
// important
return Float.NEGATIVE_INFINITY;
}
return "Unknown";
}
public String displayString() {

View file

@ -38,6 +38,7 @@ import com.raytheon.uf.viz.monitor.ui.dialogs.ISortColumn;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 7, 2009 lvenable Initial creation
* May 7, 2013 1986 njensen Optimized sortData()
*
* </pre>
*
@ -151,19 +152,6 @@ public class FFMPTableData implements ISortColumn {
return tableRows;
}
/**
* Set the sort column and direction.
*
* @param columnIndex
* Column index.
* @param direction
* Sort direction.
*/
public void setSortColumnAndDirection(int columnIndex, int direction) {
currentSortColumnIndex = columnIndex;
currentSortDirection = direction;
}
/**
* Get the sort column index.
*
@ -186,8 +174,21 @@ public class FFMPTableData implements ISortColumn {
/**
* Sort the table data.
*
* @param columnIndex
* the column to sort on
* @param direction
* the direction to sort by
*/
public void sortData() {
Collections.sort(tableRows);
public void sortData(int columnIndex, int direction) {
if (columnIndex != currentSortColumnIndex
|| direction != currentSortDirection) {
currentSortColumnIndex = columnIndex;
currentSortDirection = direction;
Collections.sort(tableRows);
if (getSortDirection() == SWT.DOWN) {
Collections.reverse(tableRows);
}
}
}
}

View file

@ -19,8 +19,6 @@
**/
package com.raytheon.uf.viz.monitor.ffmp.ui.dialogs;
import org.eclipse.swt.SWT;
import com.raytheon.uf.viz.monitor.ui.dialogs.ISortColumn;
/**
@ -34,6 +32,7 @@ import com.raytheon.uf.viz.monitor.ui.dialogs.ISortColumn;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 7, 2009 lvenable Initial creation
* May 7, 2013 1986 njensen Sped up compareTo()
*
* </pre>
*
@ -138,36 +137,16 @@ public class FFMPTableRowData implements Comparable<FFMPTableRowData> {
@Override
public int compareTo(FFMPTableRowData otherObj) {
int selectedIndex = sortCB.getSortColumn();
int direction = sortCB.getSortDirection();
int x = 0;
Object thisData = rowCells[selectedIndex].sortByObject(direction);
Object otherData = otherObj.rowCells[selectedIndex]
.sortByObject(direction);
if (thisData instanceof String) {
x = ((String) thisData).compareTo((String) otherData);
} else if (thisData instanceof Number) {
double thisNumber = (Float) thisData;
double otherNumber = (Float) otherData;
if (thisNumber < otherNumber) {
x = -1;
} else if (thisNumber > otherNumber) {
x = 1;
} else {
x = 0;
}
FFMPTableCellData selectedCell = rowCells[selectedIndex];
if (selectedCell.getCellText() != null) {
String thisText = selectedCell.getCellText();
String otherText = otherObj.rowCells[selectedIndex].getCellText();
return thisText.compareTo(otherText);
} else {
float thisFloat = selectedCell.sortByNumber();
float otherFloat = otherObj.rowCells[selectedIndex].sortByNumber();
return Float.compare(thisFloat, otherFloat);
}
if (direction == SWT.DOWN) {
if (x < 0) {
return 1;
} else if (x > 0) {
return -1;
}
}
return x;
}
}

View file

@ -77,6 +77,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FfmpTableConfigData;
* Apr 15, 2013 1911 dhladky Fixed forced FFG for centered aggregates.
* Apr 24, 2013 1946 mpduff Fixed FFFG value for ALL when an aggregate is forced
* Apr 26, 2013 1954 bsteffen Minor code cleanup throughout FFMP.
* May 7, 2013 1986 njensen Removed unnecessary sort
*
* </pre>
*
@ -98,12 +99,10 @@ public class FFMPDataGenerator {
private final Date paintRefTime;
private final Object centeredAggregationKey;
private final String huc;
private final double sliderTime;
private boolean isWorstCase = false;
@ -305,7 +304,6 @@ public class FFMPDataGenerator {
}
}
}
tData.sortData();
}
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
@ -583,7 +581,8 @@ public class FFMPDataGenerator {
forced = forceUtil.isForced();
}
if (!forcedPfafs.isEmpty() || !pfafList.isEmpty() && centeredAggregationKey == null) {
if (!forcedPfafs.isEmpty() || !pfafList.isEmpty()
&& centeredAggregationKey == null) {
FFMPBasinData basinData = guidRecords.get(guidType).getBasinData(
ALL);
guidance = basinData.getAverageGuidanceValue(pfafList, resource
@ -1014,7 +1013,6 @@ public class FFMPDataGenerator {
monitor.setQpeWindow(new FFMPTimeWindow(tableTime, qpeTime));
if (isWorstCase || (centeredAggregationKey != null)) {
// make sure that "ALL" is loaded
localHuc = ALL;