Search in sources :

Example 1 with ColumnOverrideLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class ColumnReorderLayerTest method getConfigLabelsByPosition.

@Test
public void getConfigLabelsByPosition() throws Exception {
    DataLayer underlyingLayer = new DataLayerFixture();
    this.columnReorderLayer = new ColumnReorderLayer(underlyingLayer);
    ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(underlyingLayer);
    registerCellStyleAccumulators(underlyingLayer, columnLabelAccumulator);
    columnLabelAccumulator.registerColumnOverrides(4, "INDEX_4_LABEL");
    List<String> labelsForIndex4 = this.columnReorderLayer.getConfigLabelsByPosition(4, 0).getLabels();
    assertEquals(2, labelsForIndex4.size());
    assertEquals("INDEX_4_LABEL", labelsForIndex4.get(0));
    assertEquals("EVEN_BODY", labelsForIndex4.get(1));
    // 0 1 2 3 4 - see DataLayerFixture
    this.columnReorderLayer.reorderColumnPosition(0, 5);
    // Index: 1 2 3 4 0 Width: 100 35 100 80 150
    labelsForIndex4 = this.columnReorderLayer.getConfigLabelsByPosition(3, 0).getLabels();
    assertEquals(2, labelsForIndex4.size());
    assertEquals("INDEX_4_LABEL", labelsForIndex4.get(0));
    assertEquals("EVEN_BODY", labelsForIndex4.get(1));
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) BaseDataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) Test(org.junit.Test)

Example 2 with ColumnOverrideLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class SummaryRowIntegrationTest method defaultConfigLabelsAreAdded.

@Test
public void defaultConfigLabelsAreAdded() throws Exception {
    ColumnOverrideLabelAccumulator labelAcc = new ColumnOverrideLabelAccumulator(this.layerStackWithSummary);
    labelAcc.registerColumnOverrides(0, "myLabel");
    ((ViewportLayer) this.layerStackWithSummary).setConfigLabelAccumulator(labelAcc);
    LabelStack configLabels = this.natTable.getConfigLabelsByPosition(0, 4);
    List<String> labels = configLabels.getLabels();
    assertEquals(3, labels.size());
    assertEquals(SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 0, labels.get(0));
    assertEquals(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL, labels.get(1));
    assertEquals("myLabel", labels.get(2));
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) Test(org.junit.Test)

Example 3 with ColumnOverrideLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class TickUpdateCommandHandlerTest method registerCellStyleAccumulators.

private void registerCellStyleAccumulators(DataLayer bodyDataLayer) {
    AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
    this.columnLabelAccumulator = new ColumnOverrideLabelAccumulator(new DataLayerFixture());
    aggregrateConfigLabelAccumulator.add(this.columnLabelAccumulator, new AlternatingRowConfigLabelAccumulator());
    bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
}
Also used : DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) AlternatingRowConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.grid.cell.AlternatingRowConfigLabelAccumulator)

Example 4 with ColumnOverrideLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class NatTableFixture method getColumnLabelAccumulator.

private ColumnOverrideLabelAccumulator getColumnLabelAccumulator(DataLayer dataLayer) {
    if (this.columnLabelAccumulator == null) {
        this.columnLabelAccumulator = new ColumnOverrideLabelAccumulator(dataLayer);
        dataLayer.setConfigLabelAccumulator(this.columnLabelAccumulator);
    }
    return this.columnLabelAccumulator;
}
Also used : ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)

Example 5 with ColumnOverrideLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class _5016_DataChangeLayerExample 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");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    final List<Person> data = PersonService.getPersons(10);
    // create the body layer stack
    IDataProvider bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    // add a DataChangeLayer that tracks data changes but directly updates
    // the underlying data model
    DataChangeLayer dataChangeLayer = new DataChangeLayer(bodyDataLayer, new PointKeyHandler(), false);
    // we register a special command handler to perform custom changes on
    // save
    dataChangeLayer.registerCommandHandler(new SaveDataChangesCommandHandler(dataChangeLayer) {

        @Override
        public boolean doCommand(ILayer targetLayer, SaveDataChangesCommand command) {
            if (MessageDialog.openQuestion(parent.getShell(), "Save data", "Do you really want to save to database?")) {
                // you would implement the storage to database here
                System.out.println("We save the data to the database");
                return super.doCommand(targetLayer, command);
            }
            return true;
        }
    });
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(dataChangeLayer);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
    // create the row header layer stack
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 40, 20), viewportLayer, selectionLayer);
    // create the corner layer stack
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    // create the grid layer composed with the prior created layer stacks
    GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new EditorConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Discard changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new DiscardDataChangesCommand());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Save changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new SaveDataChangesCommand());
                        }
                    });
                }
            });
        }
    });
    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) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) 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) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) PointKeyHandler(org.eclipse.nebula.widgets.nattable.datachange.PointKeyHandler) DiscardDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) MenuItem(org.eclipse.swt.widgets.MenuItem) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) SaveDataChangesCommandHandler(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommandHandler) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) DataChangeLayer(org.eclipse.nebula.widgets.nattable.datachange.DataChangeLayer) 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) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) 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) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Aggregations

ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)38 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)28 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)28 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)26 HashMap (java.util.HashMap)18 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)16 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)14 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)12 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)12 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)11 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)11 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)9 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 Composite (org.eclipse.swt.widgets.Composite)9 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)8 Button (org.eclipse.swt.widgets.Button)8