Search in sources :

Example 1 with ColumnCategoriesModel

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");
}
Also used : ColumnCategoriesModel(org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel) Test(org.junit.Test)

Example 2 with ColumnCategoriesModel

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);
}
Also used : ColumnCategoriesModel(org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel) Node(org.eclipse.nebula.widgets.nattable.columnCategories.Node) Test(org.junit.Test)

Example 3 with ColumnCategoriesModel

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;
}
Also used : Node(org.eclipse.nebula.widgets.nattable.columnCategories.Node) TableColumn(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) ColumnCategoriesModel(org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel) List(java.util.List) LinkedList(java.util.LinkedList)

Example 4 with ColumnCategoriesModel

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());
}
Also used : ColumnCategoriesModel(org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel) Node(org.eclipse.nebula.widgets.nattable.columnCategories.Node) TableColumn(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn) Test(org.junit.Test)

Example 5 with ColumnCategoriesModel

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());
}
Also used : ColumnCategoriesModel(org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel) Node(org.eclipse.nebula.widgets.nattable.columnCategories.Node) TableColumn(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn) Test(org.junit.Test)

Aggregations

ColumnCategoriesModel (org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel)6 Node (org.eclipse.nebula.widgets.nattable.columnCategories.Node)4 Test (org.junit.Test)4 TableColumn (org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn)3 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ChooseColumnsFromCategoriesCommandHandler (org.eclipse.nebula.widgets.nattable.columnCategories.ChooseColumnsFromCategoriesCommandHandler)1 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)1