Search in sources :

Example 26 with ReflectiveColumnPropertyAccessor

use of org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor in project nebula.widgets.nattable by eclipse.

the class Get_and_set_selected_objects method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Person homer = new Person("Homer", "Simpson", "Sargeant", 1234567890L);
    Person smithers = new Person("Waylon", "Smithers", "Admiral", 6666666666L);
    Person bart = new Person("Bart", "Smithers", "General", 9125798342L);
    Person nelson = new Person("Nelson", "Muntz", "Private", 0000000001L);
    Person frink = new Person("John", "Frink", "Lieutenant", 3141592654L);
    List<Person> myList = new ArrayList<>();
    myList.add(homer);
    myList.add(smithers);
    myList.add(bart);
    myList.add(nelson);
    myList.add(frink);
    String[] propertyNames = { "firstName", "lastName", "rank", "serialNumber" };
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(myList, columnPropertyAccessor);
    DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames));
    NatTable natTable = new NatTable(parent, gridLayer);
    ISelectionProvider selectionProvider = new RowSelectionProvider<>(gridLayer.getBodyLayer().getSelectionLayer(), bodyDataProvider, // Provides rows where any cell in the row is selected
    false);
    selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            System.out.println("Selection changed:");
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            @SuppressWarnings("rawtypes") Iterator it = selection.iterator();
            while (it.hasNext()) {
                System.out.println("  " + it.next());
            }
        }
    });
    // Programmatically select a few rows
    selectionProvider.setSelection(new StructuredSelection(new Person[] { homer, smithers, nelson }));
    // I changed my mind. Select a few other rows
    selectionProvider.setSelection(new StructuredSelection(new Person[] { bart, frink }));
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RowSelectionProvider(org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Iterator(java.util.Iterator) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 27 with ReflectiveColumnPropertyAccessor

use of org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor 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);
}
Also used : ComboBoxFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterRowConfiguration) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.config.DefaultFilterRowConfiguration) DataLayerFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.DataLayerFixture) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) BeforeClass(org.junit.BeforeClass)

Example 28 with ReflectiveColumnPropertyAccessor

use of org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor in project nebula.widgets.nattable by eclipse.

the class DefaultGlazedListsStaticFilterStrategyTest method init.

@BeforeClass
public static void init() {
    // initialize the collection with a big amount of values
    filterList = new FilterList<>(GlazedLists.eventList(PersonService.getFixedPersons()));
    for (int i = 1; i < 1000; i++) {
        filterList.addAll(PersonService.getFixedPersons());
    }
    configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(configRegistry);
    new DefaultFilterRowConfiguration().configureRegistry(configRegistry);
    columnHeaderLayer = new DataLayerFixture(5, 2, 100, 50);
    filterStrategy = new DefaultGlazedListsStaticFilterStrategy<>(filterList, new ReflectiveColumnPropertyAccessor<Person>(personPropertyNames), configRegistry);
    dataProvider = new FilterRowDataProvider<>(filterStrategy, columnHeaderLayer, columnHeaderLayer.getDataProvider(), configRegistry);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.config.DefaultFilterRowConfiguration) DataLayerFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.DataLayerFixture) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) BeforeClass(org.junit.BeforeClass)

Example 29 with ReflectiveColumnPropertyAccessor

use of org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor 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;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FilterRowDataLayer(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnGroupBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.ColumnGroupBodyLayerStack) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) DisplayColumnChooserCommandHandler(org.eclipse.nebula.widgets.nattable.columnChooser.command.DisplayColumnChooserCommandHandler) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FilterList(ca.odell.glazedlists.FilterList) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ColumnGroupHeaderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupHeaderLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) HSSFExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter)

Example 30 with ReflectiveColumnPropertyAccessor

use of org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor in project nebula.widgets.nattable by eclipse.

the class Using_the_ListDataProvider method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    List<Person> myList = new ArrayList<>();
    myList.add(new Person("Homer", "Simpson", "Sargeant", 1234567890L));
    myList.add(new Person("Waylon", "Smithers", "Admiral", 6666666666L));
    myList.add(new Person("Bart", "Smithers", "General", 9125798342L));
    myList.add(new Person("Nelson", "Muntz", "Private", 0000000001L));
    myList.add(new Person("John", "Frink", "Lieutenant", 3141592654L));
    String[] propertyNames = { "firstName", "lastName", "rank", "serialNumber" };
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    IDataProvider listDataProvider = new ListDataProvider<>(myList, columnPropertyAccessor);
    ILayer layer = new DataLayer(listDataProvider);
    return new NatTable(parent, layer);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ArrayList(java.util.ArrayList) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)

Aggregations

ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)47 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)39 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)36 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)32 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)30 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)26 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)26 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)25 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)24 HashMap (java.util.HashMap)23 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)23 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)22 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)22 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)22 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)22 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)21 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)21 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)20 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)20 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)19