use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration in project nebula.widgets.nattable by eclipse.
the class _6035_ExcelLikeFilterRowCustomTypesExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// create a new ConfigRegistry which will be needed for GlazedLists
// handling
ConfigRegistry configRegistry = new ConfigRegistry();
String[] propertyNames = { "name", "age", "money", "gender", "city" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("name", "Name");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("city", "City");
IColumnPropertyAccessor<MyRowObject> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
BodyLayerStack<MyRowObject> bodyLayerStack = new BodyLayerStack<>(createMyRowObjects(50), columnPropertyAccessor);
// add a label accumulator to be able to register converter
bodyLayerStack.getBodyDataLayer().setConfigLabelAccumulator(new ColumnLabelAccumulator());
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// example on how to configure a different icon if a filter is applied
ComboBoxFilterRowHeaderComposite<MyRowObject> filterRowHeaderLayer = new ComboBoxFilterRowHeaderComposite<>(bodyLayerStack.getFilterList(), bodyLayerStack.getBodyDataLayer(), bodyLayerStack.getSortedList(), columnPropertyAccessor, columnHeaderLayer, columnHeaderDataProvider, configRegistry, false);
final IComboBoxDataProvider comboBoxDataProvider = filterRowHeaderLayer.getComboBoxDataProvider();
filterRowHeaderLayer.addConfiguration(new ComboBoxFilterRowConfiguration() {
{
this.cellEditor = new FilterRowComboBoxCellEditor(comboBoxDataProvider, 5);
this.filterIconPainter = new ComboBoxFilterIconPainter(comboBoxDataProvider, GUIHelper.getImage("filter"), null);
}
});
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
NatTable natTable = new NatTable(parent, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the
// DefaultNatTableStyleConfiguration and the ConfigRegistry manually
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new MyRowObjectTableConfiguration());
natTable.addConfiguration(new FilterRowConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withStateManagerMenuItemProvider();
}
});
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
}
});
natTable.configure();
natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration in project nebula.widgets.nattable by eclipse.
the class PercentageSizingDataLayerExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite simplePanel = new Composite(panel, SWT.NONE);
simplePanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(simplePanel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(buttonPanel);
final DummyModifiableBodyDataProvider dataProvider = new DummyModifiableBodyDataProvider(3, 2);
// example for percentage calculation with default sizing
// all columns will be same size while the NatTable itself will have
// 100%
final DataLayer n1DataLayer = new DataLayer(dataProvider);
n1DataLayer.setColumnPercentageSizing(true);
n1DataLayer.setRowPercentageSizing(true);
ViewportLayer layer = new ViewportLayer(new SelectionLayer(n1DataLayer));
layer.setRegionName(GridRegion.BODY);
final NatTable n1 = new NatTable(simplePanel, layer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(n1);
// example for fixed percentage sizing
// ensure that the sum of column sizes is not greater than 100
final DataLayer n2DataLayer = new DataLayer(dataProvider);
n2DataLayer.setColumnWidthPercentageByPosition(0, 25);
n2DataLayer.setColumnWidthPercentageByPosition(1, 25);
n2DataLayer.setColumnWidthPercentageByPosition(2, 50);
layer = new ViewportLayer(new SelectionLayer(n2DataLayer));
layer.setRegionName(GridRegion.BODY);
final NatTable n2 = new NatTable(simplePanel, layer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(n2);
// example for mixed percentage sizing
// configure not every column with the exact percentage value, this way
// the columns for which
// no exact values are set will use the remaining space
final DataLayer n3DataLayer = new DataLayer(dataProvider);
n3DataLayer.setColumnPercentageSizing(true);
n3DataLayer.setColumnWidthPercentageByPosition(0, 40);
n3DataLayer.setColumnWidthPercentageByPosition(2, 40);
layer = new ViewportLayer(new SelectionLayer(n3DataLayer));
layer.setRegionName(GridRegion.BODY);
final NatTable n3 = new NatTable(simplePanel, layer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(n3);
// example for mixed fixed/percentage sizing
// configure not every column with the exact percentage value, this way
// the columns for which
// no exact values are set will use the remaining space
final DataLayer mixDataLayer = new DataLayer(dataProvider);
mixDataLayer.setColumnPercentageSizing(true);
mixDataLayer.setColumnPercentageSizing(0, false);
mixDataLayer.setColumnPercentageSizing(1, false);
mixDataLayer.setColumnWidthByPosition(0, 100);
mixDataLayer.setColumnWidthByPosition(1, 100);
layer = new ViewportLayer(new SelectionLayer(mixDataLayer));
layer.setRegionName(GridRegion.BODY);
final NatTable mix = new NatTable(simplePanel, layer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(mix);
// example for percentage calculation with default sizing in a grid
// all columns will be same size while the NatTable itself will have
// 100%
DummyGridLayerStack gridLayer = new DummyGridLayerStack(dataProvider);
final DataLayer n4DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
n4DataLayer.setColumnPercentageSizing(true);
n4DataLayer.setRowPercentageSizing(true);
final NatTable n4 = new NatTable(gridPanel, gridLayer, false);
n4.addConfiguration(new DefaultNatTableStyleConfiguration());
n4.addConfiguration(new HeaderMenuConfiguration(n4));
n4.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(n4);
// example for fixed percentage sizing in a grid
// ensure that the sum of column sizes is not greater than 100
gridLayer = new DummyGridLayerStack(dataProvider);
final DataLayer n5DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
n5DataLayer.setColumnWidthByPosition(0, 25);
n5DataLayer.setColumnWidthByPosition(1, 25);
n5DataLayer.setColumnWidthByPosition(2, 50);
n5DataLayer.setColumnPercentageSizing(true);
final NatTable n5 = new NatTable(gridPanel, gridLayer, false);
n5.addConfiguration(new DefaultNatTableStyleConfiguration());
n5.addConfiguration(new HeaderMenuConfiguration(n5));
n5.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(n5);
// example for mixed percentage sizing in a grid
// configure not every column with the exact percentage value, this way
// the columns for which
// no exact values are set will use the remaining space
gridLayer = new DummyGridLayerStack(dataProvider);
final DataLayer n6DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
n6DataLayer.setColumnWidthByPosition(0, 20);
n6DataLayer.setColumnWidthByPosition(2, 20);
n6DataLayer.setColumnPercentageSizing(true);
final NatTable n6 = new NatTable(gridPanel, gridLayer, false);
n6.addConfiguration(new DefaultNatTableStyleConfiguration());
n6.addConfiguration(new HeaderMenuConfiguration(n6));
n6.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(n6);
// example for mixed fixed/percentage sizing in a grid
// configure not every column with the exact percentage value, this way
// the columns for which
// no exact values are set will use the remaining space
gridLayer = new DummyGridLayerStack(dataProvider);
final DataLayer mixGridDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
mixGridDataLayer.setColumnPercentageSizing(true);
mixGridDataLayer.setColumnPercentageSizing(0, false);
mixGridDataLayer.setColumnPercentageSizing(1, false);
mixGridDataLayer.setColumnWidthByPosition(0, 100);
mixGridDataLayer.setColumnWidthByPosition(1, 100);
final NatTable mixGrid = new NatTable(gridPanel, gridLayer, false);
mixGrid.addConfiguration(new DefaultNatTableStyleConfiguration());
mixGrid.addConfiguration(new HeaderMenuConfiguration(mixGrid));
mixGrid.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(mixGrid);
Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
addColumnButton.setText("add column - no width");
addColumnButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
n1.refresh();
n2.refresh();
n3.refresh();
mix.refresh();
n4.refresh();
n5.refresh();
n6.refresh();
mixGrid.refresh();
}
});
Button addColumnButton2 = new Button(buttonPanel, SWT.PUSH);
addColumnButton2.setText("add column - 20 percent width");
addColumnButton2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
n1DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n2DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n3DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
mixDataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n4DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n5DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n6DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
mixGridDataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n1.refresh();
n2.refresh();
n3.refresh();
mix.refresh();
n4.refresh();
n5.refresh();
n6.refresh();
mixGrid.refresh();
}
});
return panel;
}
use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration 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.ui.menu.HeaderMenuConfiguration in project nebula.widgets.nattable by eclipse.
the class DynamicColumnHeaderHeightExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
IConfigRegistry configRegistry = new ConfigRegistry();
// Underlying data source
EventList<RowDataFixture> eventList = GlazedLists.eventList(RowDataListFixture.getList(200));
FilterList<RowDataFixture> filterList = new FilterList<>(eventList);
String[] propertyNames = RowDataListFixture.getPropertyNames();
Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
// Body
IColumnPropertyAccessor<RowDataFixture> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
ListDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(filterList, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnGroupBodyLayerStack bodyLayer = new ColumnGroupBodyLayerStack(bodyDataLayer, this.columnGroupModel);
ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(bodyLabelAccumulator);
bodyLabelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME), "PRICING_TYPE_PROP_NAME");
// Column header
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
this.columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(this.columnHeaderLayer, bodyLayer.getSelectionLayer(), this.columnGroupModel);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 1", 1, 2);
// calculate the height of the column header area dependent if column
// groups exist or not
columnGroupHeaderLayer.setCalculateHeight(true);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
final FilterRowHeaderComposite<RowDataFixture> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(filterList, columnPropertyAccessor, configRegistry), columnGroupHeaderLayer, columnHeaderDataProvider, configRegistry);
filterRowHeaderLayer.setFilterRowVisible(false);
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
// Register labels
labelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.RATING_PROP_NAME), "CUSTOM_COMPARATOR_LABEL");
// Row header
final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
// Corner
final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(bodyLayer, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
// Register create column group command handler
// Register column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(bodyLayer.getSelectionLayer(), bodyLayer.getColumnHideShowLayer(), this.columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, this.columnGroupModel);
bodyLayer.registerCommandHandler(columnChooserCommandHandler);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
}
});
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, new HSSFExcelExporter());
}
});
natTable.addConfiguration(new FilterRowCustomConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
// add button
Button button = new Button(parent, SWT.NONE);
button.setText("Switch FilterRow visibility");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
filterRowHeaderLayer.setFilterRowVisible(!filterRowHeaderLayer.isFilterRowVisible());
}
});
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration in project nebula.widgets.nattable by eclipse.
the class _6032_GlazedListsFilterCustomTypesExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// create a new ConfigRegistry which will be needed for GlazedLists
// handling
ConfigRegistry configRegistry = new ConfigRegistry();
String[] propertyNames = { "name", "age", "money", "gender", "city" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("name", "Name");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("city", "City");
IColumnPropertyAccessor<MyRowObject> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
BodyLayerStack<MyRowObject> bodyLayerStack = new BodyLayerStack<>(createMyRowObjects(50), columnPropertyAccessor);
// add a label accumulator to be able to register converter
bodyLayerStack.getBodyDataLayer().setConfigLabelAccumulator(new ColumnLabelAccumulator());
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
FilterRowHeaderComposite<MyRowObject> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), columnPropertyAccessor, configRegistry), columnHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
NatTable natTable = new NatTable(parent, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the
// DefaultNatTableStyleConfiguration and the ConfigRegistry manually
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add filter row configuration
natTable.addConfiguration(new FilterRowConfiguration());
natTable.addConfiguration(new MyRowObjectTableConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withStateManagerMenuItemProvider();
}
});
natTable.configure();
natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
return natTable;
}
Aggregations