Search in sources :

Example 6 with Node

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");
    }
}
Also used : Node(org.eclipse.nebula.widgets.nattable.columnCategories.Node) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry)

Example 7 with Node

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;
}
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 8 with Node

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());
}
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 9 with Node

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());
}
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 10 with Node

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

Aggregations

Node (org.eclipse.nebula.widgets.nattable.columnCategories.Node)11 Test (org.junit.Test)7 ColumnCategoriesModel (org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel)4 TableColumn (org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn)3 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 Tree (org.eclipse.nebula.widgets.nattable.columnCategories.Tree)1 ColumnEntry (org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry)1 Before (org.junit.Before)1