use of org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter in project nebula.widgets.nattable by eclipse.
the class StyledColumnHeaderConfiguration method addNormalModeStyling.
private void addNormalModeStyling(IConfigRegistry configRegistry) {
Image bgImage = GUIHelper.getImageByURL("columnHeaderBg", getClass().getResource("column_header_bg.png"));
TextPainter txtPainter = new TextPainter(false, false);
ICellPainter bgImagePainter = new BackgroundImagePainter(txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));
SortableHeaderTextPainter headerPainter = new SortableHeaderTextPainter(bgImagePainter, false, true);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, headerPainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, headerPainter, DisplayMode.NORMAL, GridRegion.CORNER);
}
use of org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter in project nebula.widgets.nattable by eclipse.
the class ColumnHeaderConfiguration method addNormalModeStyling.
private void addNormalModeStyling(IConfigRegistry configRegistry) {
Style cellStyle = new Style();
cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, tableStyle.columnHeaderBGColor);
cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, tableStyle.columnHeaderFGColor);
cellStyle.setAttributeValue(CellStyleAttributes.FONT, tableStyle.columnHeaderFont);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridRegion.CORNER);
// Gradient painter
Image bgImage = tableStyle.columnHeaderBgImage;
if (ObjectUtils.isNotNull(bgImage)) {
TextPainter txtPainter = new TextPainter(false, false);
ICellPainter cellPainter = new BackgroundImagePainter(txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));
SortableHeaderTextPainter sortHeaderPainter = new SortableHeaderTextPainter(cellPainter, false, false);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.NORMAL, GridRegion.CORNER);
} else {
SortableHeaderTextPainter sortHeaderPainter = new SortableHeaderTextPainter(new BeveledBorderDecorator(new TextPainter()), false, false);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.NORMAL, GridRegion.CORNER);
}
}
use of org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter in project nebula.widgets.nattable by eclipse.
the class ColumnHeaderConfiguration method addSelectedModeStyling.
private void addSelectedModeStyling(IConfigRegistry configRegistry) {
Image selectedBgImage = tableStyle.columnHeaderSelectedBgImage;
ICellPainter sortHeaderPainter;
if (ObjectUtils.isNotNull(selectedBgImage)) {
TextPainter txtPainter = new TextPainter(false, false);
ICellPainter selectedCellPainter = new BackgroundImagePainter(txtPainter, selectedBgImage, GUIHelper.getColor(192, 192, 192));
sortHeaderPainter = new SortableHeaderTextPainter(selectedCellPainter, false, false);
} else {
sortHeaderPainter = new SortableHeaderTextPainter(new BeveledBorderDecorator(new TextPainter()), false, false);
}
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.SELECT, GridRegion.COLUMN_HEADER);
}
use of org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter in project nebula.widgets.nattable by eclipse.
the class StyledColumnHeaderConfiguration method addSelectedModeStyling.
private void addSelectedModeStyling(IConfigRegistry configRegistry) {
Image selectedBgImage = GUIHelper.getImageByURL("selectedColumnHeaderBg", getClass().getResource("selected_column_header_bg.png"));
TextPainter txtPainter = new TextPainter(false, false);
ICellPainter selectedCellPainter = new BackgroundImagePainter(txtPainter, selectedBgImage, GUIHelper.getColor(192, 192, 192));
// If sorting is enables we still want the sort icon to be drawn.
SortableHeaderTextPainter selectedHeaderPainter = new SortableHeaderTextPainter(selectedCellPainter, false, true);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, selectedHeaderPainter, DisplayMode.SELECT, GridRegion.COLUMN_HEADER);
}
use of org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter 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;
}
Aggregations