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;
}
}
}
}
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);
}
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;
}
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());
}
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());
}
Aggregations