use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter in project nebula.widgets.nattable by eclipse.
the class EditorConfiguration method registerColumnSevenCheckbox.
/**
* The following will register a default CheckBoxCellEditor for the column
* that carries the married information.
* <p>
* To register a CheckBoxCellEditor, you need to
* <ol>
* <li>Register the editor</li>
* <li>Register the painter corresponding to that editor</li>
* <li>Register the needed converter</li>
* </ol>
*
* @param configRegistry
*/
private void registerColumnSevenCheckbox(IConfigRegistry configRegistry) {
// register a CheckBoxCellEditor for column three
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.EDIT, EditorExample.COLUMN_SEVEN_LABEL);
// if you want to use the CheckBoxCellEditor, you should also consider
// using the corresponding CheckBoxPainter to show the content like a
// checkbox in your NatTable
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, EditorExample.COLUMN_SEVEN_LABEL);
// using a CheckBoxCellEditor also needs a Boolean conversion to work
// correctly
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, EditorExample.COLUMN_SEVEN_LABEL);
}
use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter in project nebula.widgets.nattable by eclipse.
the class _801_VerticalCompositionWithFeaturesExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
ConfigRegistry configRegistry = new ConfigRegistry();
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
panel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(false, false).applyTo(buttonPanel);
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
List<Person> values = PersonService.getPersons(10);
final EventList<Person> eventList = GlazedLists.eventList(values);
TransformedList<Person, Person> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
// use the SortedList constructor with 'null' for the Comparator because
// the Comparator will be set by configuration
SortedList<Person> sortedList = new SortedList<>(rowObjectsGlazedList, null);
// wrap the SortedList with the FilterList
FilterList<Person> filterList = new FilterList<>(sortedList);
IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(filterList, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
GlazedListsEventLayer<Person> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, filterList);
final SelectionLayer selectionLayer = new SelectionLayer(eventLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// add sorting
SortHeaderLayer<Person> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer), false);
// add the filter row functionality
final FilterRowHeaderComposite<Person> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(filterList, columnPropertyAccessor, configRegistry), sortHeaderLayer, columnHeaderDataProvider, configRegistry);
// set the region labels to make default configurations work, e.g.
// editing, selection
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, filterRowHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
// add edit configurations
compositeLayer.addConfiguration(new DefaultEditConfiguration());
compositeLayer.addConfiguration(new DefaultEditBindings());
// add print support
compositeLayer.registerCommandHandler(new PrintCommandHandler(compositeLayer));
compositeLayer.addConfiguration(new DefaultPrintBindings());
// add excel export support
compositeLayer.registerCommandHandler(new ExportCommandHandler(compositeLayer));
compositeLayer.addConfiguration(new DefaultExportBindings());
final NatTable natTable = new NatTable(gridPanel, compositeLayer, false);
natTable.setConfigRegistry(configRegistry);
// adding this configuration adds the styles and the painters to use
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add sorting configuration
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
// birthday is never editable
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(Arrays.asList(Gender.FEMALE, Gender.MALE)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, getGenderBooleanConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(Arrays.asList(Boolean.TRUE, Boolean.FALSE)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
}
});
natTable.configure();
final RowSelectionProvider<Person> selectionProvider = new RowSelectionProvider<>(selectionLayer, bodyDataProvider, false);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Button button = new Button(buttonPanel, SWT.PUSH);
button.setText("Remove selected item");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// the NatTable context
if (natTable.getActiveCellEditor() != null) {
natTable.commitAndCloseActiveCellEditor();
}
Person item = (Person) ((IStructuredSelection) selectionProvider.getSelection()).getFirstElement();
eventList.remove(item);
}
});
return panel;
}
use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter 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.data.convert.DefaultBooleanDisplayConverter in project nebula.widgets.nattable by eclipse.
the class EditableGridExample method registerCheckBoxEditor.
private static void registerCheckBoxEditor(IConfigRegistry configRegistry, ICellPainter checkBoxCellPainter, ICellEditor checkBoxCellEditor) {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, checkBoxCellPainter, DisplayMode.NORMAL, CHECK_BOX_CONFIG_LABEL);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, CHECK_BOX_CONFIG_LABEL);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, checkBoxCellEditor, DisplayMode.NORMAL, CHECK_BOX_EDITOR_CONFIG_LABEL);
}
use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter in project nebula.widgets.nattable by eclipse.
the class EditTraversalStrategyUpDownTest method setUp.
@Before
public void setUp() {
// only use 10 columns to make the test cases easier
String[] propertyNames = Arrays.copyOfRange(RowDataListFixture.getPropertyNames(), 0, 10);
IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
this.dataLayer = new DataLayer(bodyDataProvider, 20, 20);
this.selectionLayer = new SelectionLayer(this.dataLayer);
this.viewportLayer = new ViewportLayer(this.selectionLayer);
this.viewportLayer.setRegionName(GridRegion.BODY);
this.viewportLayer.addConfiguration(new DefaultEditBindings());
this.viewportLayer.addConfiguration(new DefaultEditConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true, true));
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
}
});
this.natTable = new NatTableFixture(this.viewportLayer);
this.natTable.enableEditingOnAllCells();
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
// register non editable rows
this.overrider = new RowOverrideLabelAccumulator<>(bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {
@Override
public Serializable getRowId(RowDataFixture rowObject) {
return rowObject.getSecurity_id();
}
});
this.overrider.registerRowOverrides(2, NOT_EDITABLE);
this.overrider.registerRowOverrides(5, NOT_EDITABLE);
this.overrider.registerRowOverrides(6, NOT_EDITABLE);
this.overrider.registerRowOverrides(7, NOT_EDITABLE);
this.overrider.registerRowOverrides(8, NOT_EDITABLE);
this.overrider.registerRowOverrides(9, NOT_EDITABLE);
AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
accumulator.add(this.overrider);
accumulator.add(new ColumnLabelAccumulator());
this.dataLayer.setConfigLabelAccumulator(accumulator);
}
Aggregations