use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testTwoLevelGroupSortSummary.
@Test
public void testTwoLevelGroupSortSummary() {
addSortingCapability();
addSummaryConfiguration();
// increase the money amount for all flanders to show that the sort
// order is related to the summary value and not the groupBy value
double value = 600.0d;
for (int i = 10; i < this.sortedList.size(); i++) {
if ((i - 10) % 2 == 0) {
value -= 100.0d;
}
this.sortedList.get(i).setMoney(value);
}
// groupBy lastname
this.groupByModel.addGroupByColumnIndex(1);
// groupBy firstname
this.groupByModel.addGroupByColumnIndex(0);
// 18 data rows + 2 GroupBy rows lastname + 8 data rows firstname
assertEquals(28, this.dataLayer.getRowCount());
// Flanders
int row = 0;
Object o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
LabelStack labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 1;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Maude", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 4;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Ned", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 7;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Rodd", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(600.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 10;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Todd", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(400.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
// Simpsons
row = 13;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 14;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Bart", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 18;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Homer", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 22;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Lisa", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 25;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Marge", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
// sort ascending by money
this.sortModel.sort(2, SortDirectionEnum.ASC, false);
// Simpsons
row = 0;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 1;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Lisa", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 4;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Marge", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 7;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Bart", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 11;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Homer", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
// Flanders
row = 15;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 16;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Todd", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(400.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 19;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Rodd", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(600.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 22;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Maude", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 25;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Ned", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
// sort descending by money
this.sortModel.sort(2, SortDirectionEnum.DESC, false);
// Flanders
row = 0;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 1;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Ned", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 4;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Maude", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 7;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Rodd", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(600.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 10;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Todd", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(400.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
// Simpsons
row = 13;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 14;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Homer", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 18;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Bart", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 22;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Marge", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
row = 25;
o = this.dataLayer.getTreeList().get(row);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Lisa", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
}
use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testConfigLabelsWithGroupingAndSummary.
@Test
public void testConfigLabelsWithGroupingAndSummary() {
// groupBy lastname
this.groupByModel.addGroupByColumnIndex(1);
// add summary configuration
addSummaryConfiguration();
for (int row = 0; row < this.dataLayer.getRowCount(); row++) {
for (int column = 0; column < this.dataLayer.getColumnCount(); column++) {
LabelStack stack = this.dataLayer.getConfigLabelsByPosition(column, row);
assertTrue("column label not found", stack.hasLabel(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column));
if (row == 0 || row == 9) {
// row 0 is groupBy for flanders, row 9 groupBy for simpsons
assertTrue("groupBy object label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT));
assertTrue("groupBy column label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column));
if (column == 2) {
assertTrue("groupBy summary label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
assertTrue("groupBy summary column label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
// respect the label order
assertEquals(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column, stack.getLabels().get(0));
assertEquals(GroupByDataLayer.GROUP_BY_SUMMARY, stack.getLabels().get(1));
assertEquals(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column, stack.getLabels().get(2));
assertEquals(GroupByDataLayer.GROUP_BY_OBJECT, stack.getLabels().get(3));
assertEquals(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column, stack.getLabels().get(4));
} else {
assertFalse("groupBy summary label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
assertFalse("groupBy summary column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
// respect the label order
assertEquals(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column, stack.getLabels().get(0));
assertEquals(GroupByDataLayer.GROUP_BY_OBJECT, stack.getLabels().get(1));
assertEquals(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column, stack.getLabels().get(2));
}
} else {
assertFalse("groupBy object label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT));
assertFalse("groupBy column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column));
assertFalse("groupBy summary label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
assertFalse("groupBy summary column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
}
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testConfigLabelsWithGroupingAndSummaryWithConditional.
@Test
public void testConfigLabelsWithGroupingAndSummaryWithConditional() {
// groupBy lastname
this.groupByModel.addGroupByColumnIndex(1);
// add summary configuration
addSummaryConfiguration();
// add conditional styling labels
addConditionalStyling();
for (int row = 0; row < this.dataLayer.getRowCount(); row++) {
for (int column = 0; column < this.dataLayer.getColumnCount(); column++) {
LabelStack stack = this.dataLayer.getConfigLabelsByPosition(column, row);
assertTrue("column label not found", stack.hasLabel(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column));
if (row == 0 || row == 9) {
// row 0 is groupBy for flanders, row 9 groupBy for simpsons
assertTrue("groupBy object label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT));
assertTrue("groupBy column label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column));
if (column == 2) {
assertTrue("groupBy summary label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
assertTrue("groupBy summary column label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
// should have conditional formatting
if (row == 9) {
// respect the label order
assertEquals(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column, stack.getLabels().get(0));
assertEquals(GroupByDataLayer.GROUP_BY_SUMMARY, stack.getLabels().get(1));
assertEquals(MY_LABEL, stack.getLabels().get(2));
assertEquals(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column, stack.getLabels().get(3));
assertEquals(GroupByDataLayer.GROUP_BY_OBJECT, stack.getLabels().get(4));
assertEquals(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column, stack.getLabels().get(5));
} else {
// respect the label order
assertEquals(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column, stack.getLabels().get(0));
assertEquals(GroupByDataLayer.GROUP_BY_SUMMARY, stack.getLabels().get(1));
assertEquals(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column, stack.getLabels().get(2));
assertEquals(GroupByDataLayer.GROUP_BY_OBJECT, stack.getLabels().get(3));
assertEquals(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column, stack.getLabels().get(4));
}
} else {
assertFalse("groupBy summary label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
assertFalse("groupBy summary column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
// respect the label order
assertEquals(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column, stack.getLabels().get(0));
assertEquals(GroupByDataLayer.GROUP_BY_OBJECT, stack.getLabels().get(1));
assertEquals(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column, stack.getLabels().get(2));
}
} else {
assertFalse("groupBy object label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT));
assertFalse("groupBy column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column));
assertFalse("groupBy summary label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
assertFalse("groupBy summary column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
}
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testConfigLabelsWithGrouping.
@Test
public void testConfigLabelsWithGrouping() {
// groupBy lastname
this.groupByModel.addGroupByColumnIndex(1);
for (int row = 0; row < this.dataLayer.getRowCount(); row++) {
for (int column = 0; column < this.dataLayer.getColumnCount(); column++) {
LabelStack stack = this.dataLayer.getConfigLabelsByPosition(column, row);
assertTrue("column label not found", stack.hasLabel(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column));
if (row == 0 || row == 9) {
// row 0 is groupBy for flanders, row 9 groupBy for simpsons
// there should be groupBy labels but no groupBySummary
// labels
assertTrue("groupBy object label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT));
assertTrue("groupBy column label not found", stack.hasLabel(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column));
// respect the label order
assertEquals(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column, stack.getLabels().get(0));
assertEquals(GroupByDataLayer.GROUP_BY_OBJECT, stack.getLabels().get(1));
assertEquals(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column, stack.getLabels().get(2));
} else {
assertFalse("groupBy object label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT));
assertFalse("groupBy column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column));
}
assertFalse("groupBy summary label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
assertFalse("groupBy summary column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class MultiCellEditDialogRunner method shouldOpenDefaultDialogWithoutIncrementDecrementBox.
public void shouldOpenDefaultDialogWithoutIncrementDecrementBox() {
CellFixture cell = new CellFixture();
cell.setBounds(new Rectangle(100, 100, 100, 20));
cell.setConfigLabels(new LabelStack("Cell_Edit"));
cell.setDataValue("123");
cell.setDisplayMode(DisplayMode.NORMAL);
TextCellEditor cellEditor = new TextCellEditor();
IDisplayConverter dataTypeConverter = new DisplayConverter() {
@Override
public Object canonicalToDisplayValue(Object canonicalValue) {
return canonicalValue;
}
@Override
public Object displayToCanonicalValue(Object displayValue) {
return displayValue;
}
};
final Character newValue = Character.valueOf('4');
IDataValidator dataValidator = new DataValidator() {
@Override
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
Assert.assertEquals(newValue, newValue);
return false;
}
};
Shell shell = new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL | SWT.RESIZE);
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, dataTypeConverter);
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, dataValidator);
final CellEditDialog dialog = new CellEditDialog(shell, newValue, cell, cellEditor, configRegistry);
if (!this.interactive) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
dialog.close();
}
}
});
}
dialog.open();
}
Aggregations