use of org.eclipse.nebula.widgets.nattable.columnCategories.Node in project nebula.widgets.nattable by eclipse.
the class ColumnCategoriesLabelProvider method getText.
@Override
public String getText(Object element) {
Node node = (Node) element;
switch(node.getType()) {
case CATEGORY:
return node.getData();
case COLUMN:
int index = Integer.parseInt(node.getData());
ColumnEntry columnEntry = ColumnChooserUtils.find(this.hiddenEntries, index);
if (ObjectUtils.isNull(columnEntry)) {
log.error(// $NON-NLS-1$ //$NON-NLS-2$
"Column index " + index + " is present " + // $NON-NLS-1$
"in the Column Categories model, " + // $NON-NLS-1$
"but not in the underlying data");
return String.valueOf(index);
}
return columnEntry.getLabel();
default:
// $NON-NLS-1$
return Messages.getString("Unknown");
}
}
use of org.eclipse.nebula.widgets.nattable.columnCategories.Node 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.Node 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.Node 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());
}
use of org.eclipse.nebula.widgets.nattable.columnCategories.Node in project nebula.widgets.nattable by eclipse.
the class TreeTest method findParent.
@Test
public void findParent() throws Exception {
Node found = this.tree.find("c");
Assert.assertNotNull(found);
Assert.assertEquals("R", found.getParent().getData());
found = this.tree.find("b3b");
Assert.assertEquals("b3", found.getParent().getData());
}
Aggregations