Search in sources :

Example 1 with TableColumn

use of org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn in project nebula.widgets.nattable by eclipse.

the class NatTableBuilder method configureEditing.

protected void configureEditing() {
    for (int colIndex = 0; colIndex < columns.length; colIndex++) {
        TableColumn column = columns[colIndex];
        if (column.isEditable) {
            IEditor editor = column.editor;
            // Column label has been registered already
            String columnLabel = BODY_COLUMN_LABEL_PREFIX + colIndex;
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, editor.getEditableRule(), DisplayMode.EDIT, columnLabel);
            configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, editor.getValidator(), DisplayMode.EDIT, columnLabel);
            switch(editor.getType()) {
                case CHECKBOX:
                    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, columnLabel);
                    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, columnLabel);
                    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, editor.getCellEditor(), DisplayMode.NORMAL, columnLabel);
                    break;
                case COMBO:
                    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new ComboBoxPainter(), DisplayMode.NORMAL, columnLabel);
                    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, editor.getCellEditor(), DisplayMode.NORMAL, columnLabel);
                    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, editor.getCellEditor(), DisplayMode.EDIT, columnLabel);
                    break;
                case TEXT:
                    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor());
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : IEditor(org.eclipse.nebula.widgets.nattable.extension.builder.model.IEditor) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) ComboBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) TableColumn(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn)

Example 2 with TableColumn

use of org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn in project nebula.widgets.nattable by eclipse.

the class NatTableBuilder method configureFiltering.

protected void configureFiltering() {
    if (!tableModel.enableFilterRow) {
        return;
    }
    for (int colIndex = 0; colIndex < columns.length; colIndex++) {
        String filterRowLabel = FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + colIndex;
        TableColumn column = columns[colIndex];
        configRegistry.registerConfigAttribute(FilterRowConfigAttributes.FILTER_COMPARATOR, column.comparator, DisplayMode.NORMAL, filterRowLabel);
        configRegistry.registerConfigAttribute(FilterRowConfigAttributes.FILTER_DISPLAY_CONVERTER, column.filterRowDisplayConverter, DisplayMode.NORMAL, filterRowLabel);
        configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, column.filterRowEditor.getCellEditor(), DisplayMode.NORMAL, filterRowLabel);
    }
    // Filter row style
    Style style = new Style();
    style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, tableStyle.filterRowBGColor);
    style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, tableStyle.filterRowFGColor);
    style.setAttributeValue(CellStyleAttributes.FONT, tableStyle.filterRowFont);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
}
Also used : ColumnStyle(org.eclipse.nebula.widgets.nattable.extension.builder.model.ColumnStyle) TableStyle(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableStyle) Style(org.eclipse.nebula.widgets.nattable.style.Style) TableColumn(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn)

Example 3 with TableColumn

use of org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn 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 TableColumn

use of org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn 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 TableColumn

use of org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn 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

TableColumn (org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn)5 ColumnCategoriesModel (org.eclipse.nebula.widgets.nattable.columnCategories.ColumnCategoriesModel)3 Node (org.eclipse.nebula.widgets.nattable.columnCategories.Node)3 Test (org.junit.Test)2 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 DefaultBooleanDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter)1 TextCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor)1 ColumnStyle (org.eclipse.nebula.widgets.nattable.extension.builder.model.ColumnStyle)1 IEditor (org.eclipse.nebula.widgets.nattable.extension.builder.model.IEditor)1 TableStyle (org.eclipse.nebula.widgets.nattable.extension.builder.model.TableStyle)1 CheckBoxPainter (org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter)1 ComboBoxPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter)1 Style (org.eclipse.nebula.widgets.nattable.style.Style)1