Search in sources :

Example 1 with GlazedListsEventLayer

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer in project nebula.widgets.nattable by eclipse.

the class _602_GlazedListsSortingExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // 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");
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer as
    // underlying layer. But in this case using the ViewportLayer
    // directly as body layer is also working.
    EventList<Person> persons = GlazedLists.eventList(PersonService.getPersons(10));
    SortedList<Person> sortedList = new SortedList<>(persons, null);
    IColumnPropertyAccessor<Person> accessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    IDataProvider bodyDataProvider = new ListDataProvider<>(sortedList, accessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    GlazedListsEventLayer<Person> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, sortedList);
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(eventLayer);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    // add default column labels to the label stack
    // need to be done on the column header data layer, otherwise the label
    // stack does not contain the necessary labels at the time the
    // comparator is searched
    columnHeaderDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    ConfigRegistry configRegistry = new ConfigRegistry();
    // add the SortHeaderLayer to the column header layer stack
    // as we use GlazedLists, we use the GlazedListsSortModel which
    // delegates the sorting to the SortedList
    final SortHeaderLayer<Person> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(sortedList, accessor, configRegistry, columnHeaderDataLayer));
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, sortHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // override the default sort configuration and change the mouse bindings
    // to sort on a single click
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.addConfiguration(new DebugMenuConfiguration(natTable));
    // add some custom sort configurations regarding comparators
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // Register custom comparator for last name column
            // when sorting via last name, Simpson will always win
            configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new Comparator<String>() {

                @Override
                public int compare(String o1, String o2) {
                    // check the sort order
                    boolean sortDesc = sortHeaderLayer.getSortModel().getSortDirection(1).equals(SortDirectionEnum.DESC);
                    if ("Simpson".equals(o1) && !"Simpson".equals(o2)) {
                        return sortDesc ? 1 : -1;
                    } else if (!"Simpson".equals(o1) && "Simpson".equals(o2)) {
                        return sortDesc ? -1 : 1;
                    }
                    return o1.compareToIgnoreCase(o2);
                }
            }, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1);
            // Register null comparator to disable sorting for gender column
            configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new NullComparator(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
        }
    });
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) NullComparator(org.eclipse.nebula.widgets.nattable.config.NullComparator) SortedList(ca.odell.glazedlists.SortedList) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) NullComparator(org.eclipse.nebula.widgets.nattable.config.NullComparator) Comparator(java.util.Comparator) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) 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) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DebugMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) 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) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 2 with GlazedListsEventLayer

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer in project nebula.widgets.nattable by eclipse.

the class BlinkingGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    final String[] propertyNames = RowDataListFixture.getPropertyNames();
    final Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
    ConfigRegistry configRegistry = new ConfigRegistry();
    // Body
    LinkedList<BlinkingRowDataFixture> rowData = new LinkedList<>();
    EventList<BlinkingRowDataFixture> eventList = GlazedLists.eventList(rowData);
    ObservableElementList<BlinkingRowDataFixture> observableElementList = new ObservableElementList<>(eventList, GlazedLists.beanConnector(BlinkingRowDataFixture.class));
    IColumnPropertyAccessor<BlinkingRowDataFixture> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    this.bodyDataProvider = new ListDataProvider<>(observableElementList, columnPropertyAccessor);
    final DataLayer bodyLayer = new DataLayer(this.bodyDataProvider);
    GlazedListsEventLayer<BlinkingRowDataFixture> glazedListsEventLayer = new GlazedListsEventLayer<>(bodyLayer, observableElementList);
    BlinkLayer<BlinkingRowDataFixture> blinkingLayer = new BlinkLayer<>(glazedListsEventLayer, this.bodyDataProvider, new IRowIdAccessor<BlinkingRowDataFixture>() {

        @Override
        public Serializable getRowId(BlinkingRowDataFixture rowObject) {
            return rowObject.getSecurity_description();
        }
    }, columnPropertyAccessor, configRegistry);
    registerBlinkingConfigCells(configRegistry);
    insertRowData(glazedListsEventLayer, this.bodyDataProvider);
    // Column header
    final DefaultColumnHeaderDataProvider defaultColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    // Row header
    final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(this.bodyDataProvider);
    // Corner
    final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(defaultColumnHeaderDataProvider, rowHeaderDataProvider);
    // Grid
    GridLayer gridLayer = new DefaultGridLayer(blinkingLayer, new DefaultColumnHeaderDataLayer(defaultColumnHeaderDataProvider), new DefaultRowHeaderDataLayer(rowHeaderDataProvider), new DataLayer(cornerDataProvider));
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.configure();
    return natTable;
}
Also used : Serializable(java.io.Serializable) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ObservableElementList(ca.odell.glazedlists.ObservableElementList) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) 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) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) LinkedList(java.util.LinkedList) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) BlinkingRowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.BlinkingRowDataFixture) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) BlinkLayer(org.eclipse.nebula.widgets.nattable.blink.BlinkLayer)

Example 3 with GlazedListsEventLayer

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer 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;
}
Also used : HashMap(java.util.HashMap) DefaultPrintBindings(org.eclipse.nebula.widgets.nattable.print.config.DefaultPrintBindings) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) SortedList(ca.odell.glazedlists.SortedList) DefaultExportBindings(org.eclipse.nebula.widgets.nattable.export.config.DefaultExportBindings) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) ExportCommandHandler(org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) ComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) GridLayout(org.eclipse.swt.layout.GridLayout) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) PrintCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler) Composite(org.eclipse.swt.widgets.Composite) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FilterList(ca.odell.glazedlists.FilterList) RowSelectionProvider(org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 4 with GlazedListsEventLayer

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer 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();
}
Also used : GroupByDataLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByDataLayer) NatTableFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.NatTableFixture) ArrayList(java.util.ArrayList) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) IColumnAccessor(org.eclipse.nebula.widgets.nattable.data.IColumnAccessor) SummationSummaryProvider(org.eclipse.nebula.widgets.nattable.summaryrow.SummationSummaryProvider) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) FixedSummaryRowLayer(org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer) GroupByModel(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByModel) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) DefaultSummaryRowConfiguration(org.eclipse.nebula.widgets.nattable.summaryrow.DefaultSummaryRowConfiguration) Before(org.junit.Before)

Example 5 with GlazedListsEventLayer

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerGlazedListsTest method setup.

@Before
public void setup() {
    // de-normalize the object graph without parent structure objects
    List<HierarchicalWrapper> data = HierarchicalHelper.deNormalize(CarService.getInput(), false, CarService.PROPERTY_NAMES_COMPACT);
    EventList<HierarchicalWrapper> eventList = GlazedLists.eventList(data);
    TransformedList<HierarchicalWrapper, HierarchicalWrapper> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
    this.columnPropertyAccessor = new HierarchicalReflectiveColumnPropertyAccessor(CarService.PROPERTY_NAMES_COMPACT);
    this.sortedList = new SortedList<>(rowObjectsGlazedList, new HierarchicalWrapperComparator(this.columnPropertyAccessor, HierarchicalHelper.getLevelIndexMapping(CarService.PROPERTY_NAMES_COMPACT)));
    this.filterList = new FilterList<>(this.sortedList);
    this.bodyDataProvider = new ListDataProvider<>(this.filterList, this.columnPropertyAccessor);
    HierarchicalSpanningDataProvider spanningDataProvider = new HierarchicalSpanningDataProvider(this.bodyDataProvider, CarService.PROPERTY_NAMES_COMPACT);
    this.bodyDataLayer = new SpanningDataLayer(spanningDataProvider);
    // simply apply labels for every column by index
    this.bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    // layer for event handling of GlazedLists and PropertyChanges
    GlazedListsEventLayer<HierarchicalWrapper> glazedListsEventLayer = new GlazedListsEventLayer<>(this.bodyDataLayer, this.filterList);
    glazedListsEventLayer.setTestMode(true);
    this.selectionLayer = new SelectionLayer(glazedListsEventLayer);
    this.treeLayer = new HierarchicalTreeLayer(this.selectionLayer, this.filterList, CarService.PROPERTY_NAMES_COMPACT);
    // create a dummy config registry
    this.configRegistry = new ConfigRegistry();
    this.configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, DefaultComparator.getInstance());
    this.columnHeaderDataLayer = new DataLayer(new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES_COMPACT));
}
Also used : HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) HierarchicalWrapperComparator(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) HierarchicalReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalReflectiveColumnPropertyAccessor) HierarchicalSpanningDataProvider(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalSpanningDataProvider) HierarchicalTreeLayer(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer) Before(org.junit.Before)

Aggregations

ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)7 GlazedListsEventLayer (org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer)7 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)6 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)6 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)5 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)4 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)4 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)4 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4 SortedList (ca.odell.glazedlists.SortedList)3 HashMap (java.util.HashMap)3 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)3 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)3 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)3 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)3 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)3 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)3