use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry 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.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class _804_GlazedListsEditorExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "password", "description", "age", "money", "married", "gender", "address.street", "address.city", "favouriteFood", "favouriteDrinks", "filename" };
// 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("password", "Password");
propertyToLabelMap.put("description", "Description");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("address.street", "Street");
propertyToLabelMap.put("address.city", "City");
propertyToLabelMap.put("favouriteFood", "Food");
propertyToLabelMap.put("favouriteDrinks", "Drinks");
propertyToLabelMap.put("filename", "Filename");
ConfigRegistry configRegistry = new ConfigRegistry();
GlazedListsGridEditorGridLayer<ExtendedPersonWithAddress> gridLayer = new GlazedListsGridEditorGridLayer<>(PersonService.getExtendedPersonsWithAddress(10), configRegistry, propertyNames, propertyToLabelMap);
final DataLayer bodyDataLayer = gridLayer.getBodyDataLayer();
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
final NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new EditorConfiguration());
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.configure();
new NatTableContentTooltip(natTable, GridRegion.BODY);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerSummaryRowConcurrencyTest method setup.
@Before
public void setup() {
List<Value> values = new ArrayList<Value>();
values.add(new Value(1));
values.add(new Value(2));
values.add(new Value(3));
values.add(new Value(4));
values.add(new Value(5));
values.add(new Value(6));
values.add(new Value(7));
values.add(new Value(8));
values.add(new Value(9));
values.add(new Value(10));
IColumnAccessor<Value> columnAccessor = new IColumnAccessor<Value>() {
@Override
public Object getDataValue(Value rowObject, int columnIndex) {
if (columnIndex % 2 == 0) {
try {
Thread.sleep(80);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return rowObject.value;
}
@Override
public void setDataValue(Value rowObject, int columnIndex, Object newValue) {
}
@Override
public int getColumnCount() {
return 10;
}
};
EventList<Value> eventList = GlazedLists.eventList(values);
TransformedList<Value, Value> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
ConfigRegistry configRegistry = new ConfigRegistry();
final GroupByDataLayer<Value> dataLayer = new GroupByDataLayer<Value>(new GroupByModel(), eventList, columnAccessor);
// DataLayer dataLayer = new DataLayer(dataProvider);
GlazedListsEventLayer<Value> glazedListsEventLayer = new GlazedListsEventLayer<Value>(dataLayer, rowObjectsGlazedList);
DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(glazedListsEventLayer);
this.summaryRowLayer = new FixedSummaryRowLayer(dataLayer, bodyLayerStack, configRegistry, false);
this.summaryRowLayer.setHorizontalCompositeDependency(false);
CompositeLayer composite = new CompositeLayer(1, 2);
composite.setChildLayer("SUMMARY", this.summaryRowLayer, 0, 0);
composite.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
NatTable natTable = new NatTableFixture(composite, false);
natTable.addConfiguration(new DefaultSummaryRowConfiguration() {
@Override
protected void addSummaryProviderConfig(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, new SummationSummaryProvider(dataLayer.getDataProvider(), false), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
}
});
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class StaticFilterGridExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
IConfigRegistry configRegistry = new ConfigRegistry();
StaticFilterExampleGridLayer underlyingLayer = new StaticFilterExampleGridLayer(configRegistry);
DataLayer bodyDataLayer = underlyingLayer.getBodyDataLayer();
IDataProvider dataProvider = underlyingLayer.getBodyDataProvider();
// NOTE: Register the accumulator on the body data layer.
// This ensures that the labels are bound to the column index and are
// unaffected by column order.
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
NatTable natTable = new NatTable(parent, underlyingLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
// natTable.addConfiguration(new DebugMenuConfiguration(natTable));
natTable.addConfiguration(new FilterRowCustomConfiguration());
natTable.addConfiguration(EditableGridExample.editableGridConfiguration(columnLabelAccumulator, dataProvider));
natTable.setConfigRegistry(configRegistry);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class ComboBoxGlazedListsFilterStrategyTest method init.
@BeforeClass
public static void init() {
// initialize the collection with a big amount of values
EventList<Person> baseCollection = GlazedLists.eventList(PersonService.getFixedPersons());
for (int i = 1; i < 1000; i++) {
baseCollection.addAll(PersonService.getFixedPersons());
}
filterList = new FilterList<>(GlazedLists.eventList(baseCollection));
configRegistry = new ConfigRegistry();
new DefaultNatTableStyleConfiguration().configureRegistry(configRegistry);
new DefaultFilterRowConfiguration().configureRegistry(configRegistry);
new ComboBoxFilterRowConfiguration().configureRegistry(configRegistry);
columnHeaderLayer = new DataLayerFixture(5, 2, 100, 50);
IColumnAccessor<Person> bodyDataColumnAccessor = new ReflectiveColumnPropertyAccessor<>(personPropertyNames);
comboBoxDataProvider = new GlazedListsFilterRowComboBoxDataProvider<>(new DataLayer(new ListDataProvider<>(filterList, bodyDataColumnAccessor)), baseCollection, bodyDataColumnAccessor);
filterStrategy = new ComboBoxGlazedListsFilterStrategy<>(comboBoxDataProvider, filterList, bodyDataColumnAccessor, configRegistry);
dataProvider = new FilterRowDataProvider<>(filterStrategy, columnHeaderLayer, columnHeaderLayer.getDataProvider(), configRegistry);
}
Aggregations