use of org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel in project nebula.widgets.nattable by eclipse.
the class ColumnCategoriesModelTest method rootCanOnlyBeSetOnce.
@Test
public void rootCanOnlyBeSetOnce() throws Exception {
boolean caughtEx = false;
try {
ColumnCategoriesModel model = new ColumnCategoriesModel();
model.addRootCategory("Root");
model.addRootCategory("Root");
} catch (Exception e) {
caughtEx = true;
assertEquals("Root has been set already. Clear using (clear()) to reset.", e.getMessage());
}
assertTrue(caughtEx);
this.model.clear();
this.model.addRootCategory("Root");
}
use of org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel in project nebula.widgets.nattable by eclipse.
the class ColumnCategoriesModelTest method rootMustBeTheFirstNodeSet.
@Test
public void rootMustBeTheFirstNodeSet() throws Exception {
boolean caughtEx = false;
try {
ColumnCategoriesModel model = new ColumnCategoriesModel();
model.addCategory(new Node("1"), "1a");
} catch (Exception e) {
caughtEx = true;
}
assertTrue(caughtEx);
}
use of org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel in project nebula.widgets.nattable by eclipse.
the class ColumnCategoriesModelAssembler method setupColumnCategories.
public static ColumnCategoriesModel setupColumnCategories(TableColumn[] columnProps) {
ColumnCategoriesModel model = new ColumnCategoriesModel();
Node rootNode = model.addRootCategory("Root");
Node all = model.addCategory(rootNode, "All");
Map<String, List<Integer>> columnCategoryToColumnIndexesMap = new LinkedHashMap<String, List<Integer>>();
List<Integer> indexesNotCategorized = new LinkedList<Integer>();
for (TableColumn tableColumn : columnProps) {
indexesNotCategorized.add(tableColumn.index);
}
for (int columnIndex = 0; columnIndex < columnProps.length; columnIndex++) {
String categoryName = columnProps[columnIndex].categoryName;
// Column if part of a category
if (categoryName != null) {
List<Integer> columnCategoryIndexes = columnCategoryToColumnIndexesMap.get(categoryName);
// Create an entry in the map for the category
if (columnCategoryIndexes == null) {
columnCategoryIndexes = new LinkedList<Integer>();
columnCategoryToColumnIndexesMap.put(categoryName, columnCategoryIndexes);
}
// Add to map
columnCategoryIndexes.add(columnIndex);
indexesNotCategorized.remove(Integer.valueOf(columnIndex));
}
}
// Transfer the map created to the category model
all.addChildColumnIndexes(ArrayUtil.asIntArray(indexesNotCategorized));
for (String columnGroupName : columnCategoryToColumnIndexesMap.keySet()) {
List<Integer> columnIndexes = columnCategoryToColumnIndexesMap.get(columnGroupName);
int[] intColumnIndexes = new int[columnIndexes.size()];
int i = 0;
for (Integer columnIndex : columnIndexes) {
intColumnIndexes[i] = columnIndex;
i++;
}
Node node = model.addCategory(all, columnGroupName);
node.addChildColumnIndexes(ArrayUtil.asIntArray(columnIndexes));
}
return model;
}
use of org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel in project nebula.widgets.nattable by eclipse.
the class ColumnCategoriesModelAssemblerTest method assembleModel.
@Test
public void assembleModel() throws Exception {
TableColumn[] columnProps = new TableColumn[] { new TableColumn(0, "a"), new TableColumn(1, "b").setCategory("C1"), new TableColumn(2, "c").setCategory("C1"), new TableColumn(3, "d").setCategory("C2"), new TableColumn(4, "e").setCategory("C3"), new TableColumn(5, "f") };
ColumnCategoriesModel model = ColumnCategoriesModelAssembler.setupColumnCategories(columnProps);
Node rootCategory = model.getRootCategory().getChildren().get(0);
Assert.assertEquals(5, rootCategory.getNumberOfChildren());
Node c1 = rootCategory.getChildren().get(2);
Assert.assertEquals("C1", c1.getData());
Assert.assertEquals(2, c1.getChildren().size());
Node c2 = rootCategory.getChildren().get(3);
Assert.assertEquals("C2", c2.getData());
Assert.assertEquals(1, c2.getChildren().size());
Node c3 = rootCategory.getChildren().get(4);
Assert.assertEquals("C3", c3.getData());
Assert.assertEquals(1, c3.getChildren().size());
}
use of org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel in project nebula.widgets.nattable by eclipse.
the class ColumnCategoriesModelAssemblerTest method assembleModelAddingAllToRoot.
@Test
public void assembleModelAddingAllToRoot() throws Exception {
TableColumn[] columnProps = new TableColumn[] { new TableColumn(0, "a"), new TableColumn(1, "b"), new TableColumn(2, "c"), new TableColumn(3, "d"), new TableColumn(4, "e"), new TableColumn(5, "f") };
ColumnCategoriesModel model = ColumnCategoriesModelAssembler.setupColumnCategories(columnProps);
Node rootCategory = model.getRootCategory().getChildren().get(0);
Assert.assertEquals(6, rootCategory.getNumberOfChildren());
}
Aggregations