AggList list = (AggList) e.getSource();
switch (e.getType()) {
case AGGS_ADDED:
try {
for (int i = e.getIndex(); i < list.getSize(); i++) {
UIAggregate newAgg = list.getAgg(i);
XulTreeRow newRow = (XulTreeRow) document.createElement("treerow");
XulTreeCell newCell = (XulTreeCell) document.createElement("treecell");
newCell.setValue(newAgg.getEnabled());
newRow.addCell(newCell);
newCell = (XulTreeCell) document.createElement("treecell");
newCell.setLabel(newAgg.isAlgoAgg() ? Messages.getString("agg_type_advisor") : Messages.getString("agg_type_custom"));
newRow.addCell(newCell);
newCell = (XulTreeCell) document.createElement("treecell");
newCell.setLabel(newAgg.getName());
newRow.addCell(newCell);
newCell = (XulTreeCell) document.createElement("treecell");
double rowCount = newAgg.estimateRowCount();
if (rowCount == 0) {
newCell.setLabel(ESTIMATE_UNKNOWN);
} else {
newCell.setLabel(format.format(rowCount));
}
newRow.addCell(newCell);
newCell = (XulTreeCell) document.createElement("treecell");
double space = newAgg.estimateSpace();
if (space == 0) {
newCell.setLabel(ESTIMATE_UNKNOWN);
} else {
newCell.setLabel(format.format(space));
}
newRow.addCell(newCell);
aggTable.addTreeRow(newRow);
}
changeInAggregates();
} catch (XulException xe) {
logger.error("Error adding new row to Agg table", xe);
}
break;
case AGG_ADDED:
try {
UIAggregate newAgg = list.getAgg(e.getIndex());
XulTreeRow newRow = (XulTreeRow) document.createElement("treerow");
XulTreeCell newCell = (XulTreeCell) document.createElement("treecell");
newCell.setValue(newAgg.getEnabled());
newRow.addCell(newCell);
newCell = (XulTreeCell) document.createElement("treecell");
newCell.setLabel(newAgg.isAlgoAgg() ? Messages.getString("agg_type_advisor") : Messages.getString("agg_type_custom"));
newRow.addCell(newCell);
newCell = (XulTreeCell) document.createElement("treecell");
newCell.setLabel(newAgg.getName());
newRow.addCell(newCell);
newCell = (XulTreeCell) document.createElement("treecell");
double rowCount = newAgg.estimateRowCount();
if (rowCount == 0) {
newCell.setLabel(ESTIMATE_UNKNOWN);
} else {
newCell.setLabel(format.format(rowCount));
}
newRow.addCell(newCell);
newCell = (XulTreeCell) document.createElement("treecell");
double space = newAgg.estimateSpace();
if (space == 0) {
newCell.setLabel(ESTIMATE_UNKNOWN);
} else {
newCell.setLabel(format.format(space));
}
newRow.addCell(newCell);
aggTable.addTreeRow(newRow);
changeInAggregates();
} catch (XulException xe) {
logger.error("Error adding new row to Agg table", xe);
}
break;
case AGGS_CLEARED:
aggTable.getRootChildren().removeAll();
aggModel.setThinAgg(null);
changeInAggregates();
break;
case AGG_REMOVED:
aggTable.removeTreeRows(new int[] { e.getIndex() });
aggTable.clearSelection();
int[] tableSelection = aggTable.getSelectedRows();
if (e.getIndex() < list.getSize()) {
//we're single selection
list.setSelectedIndex(e.getIndex());
}
//There's aready a selection listener on the table firing the same.
UIAggregate tempAgg = list.getSelectedValue();
aggModel.setThinAgg(list.getSelectedValue());
changeInAggregates();
break;
case SELECTION_CHANGED:
if (aggTable.getSelectedRows().length > 0) {
logger.info("Event index: " + e.getIndex() + " aggTable.selectedRow0: " + aggTable.getSelectedRows()[0]);
}
int[] rows = aggTable.getSelectedRows();
if (aggTable.getSelectedRows().length > 0 && e.getIndex() == aggTable.getSelectedRows()[0]) {
aggModel.setThinAgg(list.getSelectedValue());
}
//check to see if it's already selected, ignore if so
int[] curSelection = aggTable.getSelectedRows();
// if(curSelection.length > 0 && e.getIndex() == curSelection[0]){
// logger.debug("already selected row");
// break;
// }
logger.debug("selecting new row");
aggTable.setSelectedRows(new int[] { e.getIndex() });
aggModel.setThinAgg(list.getSelectedValue());
break;
case AGG_CHANGED:
logger.debug("agg list controller responding to AGG_CHANGED event from aggList");
int idx = e.getIndex();
UIAggregate agg = list.getAgg(idx);
aggTable.getRootChildren().getItem(idx).getRow().getCell(0).setValue(agg.getEnabled());
aggTable.getRootChildren().getItem(idx).getRow().getCell(1).setLabel(
agg.isAlgoAgg()
? Messages.getString("agg_type_advisor")
: Messages.getString("agg_type_custom")
);
aggTable.getRootChildren().getItem(idx).getRow().getCell(2).setLabel(agg.getName());
double rowCount = agg.estimateRowCount();
if (rowCount == 0) {
aggTable.getRootChildren().getItem(idx).getRow().getCell(3).setLabel(ESTIMATE_UNKNOWN);
} else {
aggTable.getRootChildren().getItem(idx).getRow().getCell(3).setLabel(format.format(rowCount));
}
double space = agg.estimateSpace();
if (space == 0) {
aggTable.getRootChildren().getItem(idx).getRow().getCell(4).setLabel(ESTIMATE_UNKNOWN);
} else {
aggTable.getRootChildren().getItem(idx).getRow().getCell(4).setLabel(format.format(space));
}