use of org.eclipse.nebula.widgets.nattable.tree.TreeLayer in project nebula.widgets.nattable by eclipse.
the class ConfigLabelProviderTest method testTreeLabels.
@Test
public void testTreeLabels() {
SelectionLayer selectionLayer = new SelectionLayer(this.bodyDataLayer);
TreeLayer treeLayer = new TreeLayer(selectionLayer, new TreeRowModel<Person>(new ITreeData<Person>() {
@Override
public String formatDataForDepth(int depth, Person object) {
return null;
}
@Override
public String formatDataForDepth(int depth, int index) {
return null;
}
@Override
public int getDepthOfData(Person object) {
return 0;
}
@Override
public int getDepthOfData(int index) {
return 0;
}
@Override
public Person getDataAtIndex(int index) {
return null;
}
@Override
public int indexOf(Person child) {
return 0;
}
@Override
public boolean hasChildren(Person object) {
return false;
}
@Override
public boolean hasChildren(int index) {
return false;
}
@Override
public List<Person> getChildren(Person object) {
return null;
}
@Override
public List<Person> getChildren(Person object, boolean fullDepth) {
return null;
}
@Override
public List<Person> getChildren(int index) {
return null;
}
@Override
public int getElementCount() {
return 0;
}
@Override
public boolean isValidIndex(int index) {
return false;
}
}));
Collection<String> labels = treeLayer.getProvidedLabels();
assertEquals(16, labels.size());
assertTrue(labels.contains(SelectionStyleLabels.SELECTION_ANCHOR_STYLE));
assertTrue(labels.contains(SelectionStyleLabels.SELECTION_ANCHOR_GRID_LINE_STYLE));
assertTrue(labels.contains(SelectionStyleLabels.COLUMN_FULLY_SELECTED_STYLE));
assertTrue(labels.contains(SelectionStyleLabels.ROW_FULLY_SELECTED_STYLE));
assertTrue(labels.contains(SelectionStyleLabels.FILL_HANDLE_CELL));
assertTrue(labels.contains(SelectionStyleLabels.FILL_HANDLE_REGION));
assertTrue(labels.contains(SelectionStyleLabels.COPY_BORDER_STYLE));
assertTrue(labels.contains(TreeLayer.TREE_COLUMN_CELL));
assertTrue(labels.contains(DefaultTreeLayerConfiguration.TREE_LEAF_CONFIG_TYPE));
assertTrue(labels.contains(DefaultTreeLayerConfiguration.TREE_COLLAPSED_CONFIG_TYPE));
assertTrue(labels.contains(DefaultTreeLayerConfiguration.TREE_EXPANDED_CONFIG_TYPE));
assertTrue(labels.contains(DefaultTreeLayerConfiguration.TREE_DEPTH_CONFIG_TYPE + "0"));
assertTrue(labels.contains(DefaultTreeLayerConfiguration.TREE_DEPTH_CONFIG_TYPE + "1"));
assertTrue(labels.contains(DefaultTreeLayerConfiguration.TREE_DEPTH_CONFIG_TYPE + "2"));
assertTrue(labels.contains(DefaultTreeLayerConfiguration.TREE_DEPTH_CONFIG_TYPE + "3"));
assertTrue(labels.contains(DefaultTreeLayerConfiguration.TREE_DEPTH_CONFIG_TYPE + "4"));
}
use of org.eclipse.nebula.widgets.nattable.tree.TreeLayer in project nebula.widgets.nattable by eclipse.
the class TreeGridExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, DefaultComparator.getInstance());
// Underlying data source
createDatums();
EventList<Datum> eventList = GlazedLists.eventList(this.datums.values());
SortedList<Datum> sortedList = new SortedList<>(eventList, null);
String[] propertyNames = new String[] { "foo", "bar" };
IColumnPropertyAccessor<Datum> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
// Column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ISortModel sortModel = new GlazedListsSortModel<>(sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer);
final TreeList<Datum> treeList = new TreeList<>(sortedList, new DatumTreeFormat(sortModel), new DatumExpansionModel());
GlazedListTreeData<Datum> treeData = new GlazedListTreeData<>(treeList);
ListDataProvider<Datum> bodyDataProvider = new ListDataProvider<>(treeList, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
// GlazedListsEventLayer<Datum> glazedListsEventLayer =
// new GlazedListsEventLayer<Datum>(bodyDataLayer, treeList);
DetailGlazedListsEventLayer<Datum> glazedListsEventLayer = new DetailGlazedListsEventLayer<>(bodyDataLayer, treeList);
// Body layer
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(glazedListsEventLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(columnHideShowLayer);
// Switch the ITreeRowModel implementation between using native grid
// Hide/Show or GlazedList TreeList Hide/Show
// TreeLayer treeLayer = new TreeLayer(rowHideShowLayer, new
// TreeRowModel<Datum>(treeData), true);
TreeLayer treeLayer = new TreeLayer(rowHideShowLayer, new GlazedListTreeRowModel<>(treeData), false);
SelectionLayer selectionLayer = new SelectionLayer(treeLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
// Register labels
SortHeaderLayer<Datum> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, sortModel, false);
// Row header layer
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
// Corner layer
DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
CornerLayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, sortHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createRowHeaderMenu(NatTable natTable) {
return super.createRowHeaderMenu(natTable).withHideRowMenuItem().withShowAllRowsMenuItem();
}
});
natTable.addConfiguration(new DefaultTreeLayerConfiguration(treeLayer));
natTable.addConfiguration(new SingleClickSortConfiguration());
// Uncomment to see the native tree list printed to stout.
// printTree(treeList, treeData);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.tree.TreeLayer in project nebula.widgets.nattable by eclipse.
the class TreeGridWithCheckBoxFieldsExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, DefaultComparator.getInstance());
// Underlying data source
createDatums();
EventList<Datum> eventList = GlazedLists.eventList(this.datums.values());
SortedList<Datum> sortedList = new SortedList<>(eventList, null);
// TreeList <RowDataFixture> treeList = new
// TreeList<RowDataFixture>(eventList, new RowDataFixtureTreeFormat(),
// new RowDataFixtureExpansionModel());
String[] propertyNames = new String[] { "self", "bar" };
IColumnPropertyAccessor<Datum> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
// Column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ISortModel sortModel = new GlazedListsSortModel<>(sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer);
final TreeList<Datum> treeList = new TreeList<>(sortedList, new DatumTreeFormat(sortModel), new DatumExpansionModel());
GlazedListTreeData<Datum> treeData = new GlazedListTreeData<>(treeList);
ListDataProvider<Datum> bodyDataProvider = new ListDataProvider<>(treeList, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
// Handle update of CheckBoxField objects in column 0
bodyDataLayer.registerCommandHandler(new UpdateDataCommandHandler(bodyDataLayer) {
@Override
protected boolean doCommand(UpdateDataCommand command) {
int columnPosition = command.getColumnPosition();
int rowPosition = command.getRowPosition();
if (columnPosition == 0) {
Datum datum = (Datum) bodyDataLayer.getDataProvider().getDataValue(columnPosition, rowPosition);
datum.setOn((Boolean) command.getNewValue());
bodyDataLayer.fireLayerEvent(new CellVisualChangeEvent(bodyDataLayer, columnPosition, rowPosition));
return true;
} else {
return super.doCommand(command);
}
}
});
// Body layer
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
// Switch the ITreeRowModel implementation between using native grid
// Hide/Show or GlazedList TreeList Hide/Show
// TreeLayer treeLayer = new TreeLayer(selectionLayer, new
// TreeRowModel<Datum>(treeData), true);
final TreeLayer treeLayer = new TreeLayer(selectionLayer, new GlazedListTreeRowModel<>(treeData));
ViewportLayer viewportLayer = new ViewportLayer(treeLayer);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
// Register labels
SortHeaderLayer<Datum> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, sortModel, false);
// Row header layer
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
// Corner layer
DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
CornerLayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, sortHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new SingleClickSortConfiguration());
// Uncomment to see the native tree list printed to stout.
// printTree(treeList, treeData);
columnHeaderDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
final ColumnHeaderCheckBoxPainter columnHeaderCheckBoxPainter = new ColumnHeaderCheckBoxPainter(bodyDataLayer) {
@Override
protected Boolean convertDataType(ILayerCell cell, IConfigRegistry configRegistry) {
Datum dataValue = (Datum) cell.getDataValue();
return dataValue.isOn();
}
};
final ICellPainter checkBoxPainter = new TreeCheckBoxPainter() {
@Override
protected CheckBoxStateEnum getCheckBoxState(ILayerCell cell) {
Datum dataValue = (Datum) cell.getDataValue();
return dataValue.getCheckBoxState();
}
};
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
// Column header
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BeveledBorderDecorator(new CellPainterDecorator(new SortableHeaderTextPainter(), CellEdgeEnum.LEFT, columnHeaderCheckBoxPainter)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 0);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(new CellPainterDecorator(new TextPainter() {
@Override
protected String convertDataType(ILayerCell cell, IConfigRegistry configRegistry) {
Datum dataValue = (Datum) cell.getDataValue();
return dataValue.getName();
}
}, CellEdgeEnum.LEFT, checkBoxPainter)), DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor() {
@Override
public void setCanonicalValue(Object canonicalValue) {
Datum value = (Datum) canonicalValue;
super.setCanonicalValue(value.isOn());
}
}, DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
}
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstSingleClickBinding(new CellPainterMouseEventMatcher(GridRegion.COLUMN_HEADER, MouseEventMatcher.LEFT_BUTTON, columnHeaderCheckBoxPainter), new ToggleCheckBoxColumnAction(columnHeaderCheckBoxPainter, bodyDataLayer));
uiBindingRegistry.registerFirstSingleClickBinding(new CellPainterMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON, checkBoxPainter), new MouseEditAction());
uiBindingRegistry.registerFirstMouseDragMode(new CellPainterMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON, checkBoxPainter), new CellEditDragMode());
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.tree.TreeLayer in project nebula.widgets.nattable by eclipse.
the class _200_Group_by method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(1, false));
// Underlying data source
EventList<RowDataFixture> eventList = GlazedLists.eventList(RowDataListFixture.getList(200));
String[] propertyNames = RowDataListFixture.getPropertyNames();
Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
IColumnPropertyAccessor<RowDataFixture> reflectiveColumnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
GroupByModel groupByModel = new GroupByModel();
// Summary
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, new SummationGroupBySummaryProvider<>(reflectiveColumnPropertyAccessor), DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.LOT_SIZE_PROP_NAME));
GroupByDataLayer<RowDataFixture> bodyDataLayer = new GroupByDataLayer<>(groupByModel, eventList, reflectiveColumnPropertyAccessor, configRegistry);
// Body layer
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
TreeLayer treeLayer = new TreeLayer(selectionLayer, bodyDataLayer.getTreeRowModel());
FreezeLayer freeze = new FreezeLayer(treeLayer);
ViewportLayer viewportLayer = new ViewportLayer(treeLayer);
CompositeFreezeLayer compFreeze = new CompositeFreezeLayer(freeze, viewportLayer, selectionLayer);
// Column header layer
final IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
final DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, compFreeze, selectionLayer);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
// Register labels
labelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.RATING_PROP_NAME), "CUSTOM_COMPARATOR_LABEL");
// Row header layer
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataLayer.getDataProvider());
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, compFreeze, selectionLayer);
// Corner layer
DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
CornerLayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(compFreeze, columnHeaderLayer, rowHeaderLayer, cornerLayer, false);
CompositeLayer compositeGridLayer = new CompositeLayer(1, 2);
final GroupByHeaderLayer groupByHeaderLayer = new GroupByHeaderLayer(groupByModel, gridLayer, columnHeaderDataProvider);
compositeGridLayer.setChildLayer(GroupByHeaderLayer.GROUP_BY_REGION, groupByHeaderLayer, 0, 0);
compositeGridLayer.setChildLayer("Grid", gridLayer, 0, 1);
NatTable natTable = new NatTable(comp, compositeGridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new GroupByHeaderMenuConfiguration(natTable, groupByHeaderLayer));
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new DebugMenuConfiguration(natTable));
natTable.setConfigRegistry(configRegistry);
natTable.configure();
natTable.setLayoutData(new GridData(GridData.FILL_BOTH));
Button button = new Button(comp, SWT.NONE);
button.setText("Toggle Group By Header");
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
groupByHeaderLayer.setVisible(!groupByHeaderLayer.isVisible());
}
});
return comp;
}
Aggregations