Search in sources :

Example 26 with ColumnReorderLayer

use of org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer in project nebula.widgets.nattable by eclipse.

the class CompositeFreezeLayerTest method setup.

@Before
public void setup() {
    TestLayer dataLayer = new TestLayer(4, 4, "0:0;100 | 1:1;100 | 2:2;100 | 3:3;100", "0:0;40  | 1:1;40  | 2:2;40  | 3:3;40", "A0 | B0 | C0 | D0 \n" + "A1 | B1 | C1 | D1 \n" + "A2 | B2 | C2 | D2 \n" + "A3 | B3 | C3 | D3 \n");
    this.reorderLayer = new ColumnReorderLayer(dataLayer);
    this.hideShowLayer = new ColumnHideShowLayer(this.reorderLayer);
    this.selectionLayer = new SelectionLayer(this.hideShowLayer);
    this.viewportLayer = new ViewportLayer(this.selectionLayer);
    this.freezeLayer = new FreezeLayer(this.selectionLayer);
    this.compositeFreezeLayer = new CompositeFreezeLayer(this.freezeLayer, this.viewportLayer, this.selectionLayer);
    this.compositeFreezeLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 400, 160);
        }
    });
    this.compositeFreezeLayer.doCommand(new InitializeClientAreaCommandFixture());
}
Also used : InitializeClientAreaCommandFixture(org.eclipse.nebula.widgets.nattable.test.fixture.InitializeClientAreaCommandFixture) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) FreezeLayer(org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer) CompositeFreezeLayer(org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer) Rectangle(org.eclipse.swt.graphics.Rectangle) TestLayer(org.eclipse.nebula.widgets.nattable.test.fixture.TestLayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) CompositeFreezeLayer(org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) Before(org.junit.Before)

Example 27 with ColumnReorderLayer

use of org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer in project nebula.widgets.nattable by eclipse.

the class ColumnGroupExpandCollapseLayerTest method isFirstVisibleWithColumnsReordered.

@Test
public void isFirstVisibleWithColumnsReordered() throws Exception {
    // Original indexes : 0 1 2 3 4
    // Indexes reordered : 4 1 0 2 3
    ColumnReorderLayer reorderLayer = new ColumnReorderLayerFixture();
    this.underlyingLayer = new ColumnHideShowLayerFixture(reorderLayer);
    this.expandCollapseLayer = new ColumnGroupExpandCollapseLayer(this.underlyingLayer, this.model);
    this.model.clear();
    this.model.addColumnsIndexesToGroup(TEST_GROUP_NAME, 0, 2, 3);
    // Hide index 0
    this.underlyingLayer.hideColumnPositions(Arrays.asList(2));
    assertFalse(ColumnGroupUtils.isFirstVisibleColumnIndexInGroup(0, this.expandCollapseLayer, this.underlyingLayer, this.model));
    assertTrue(ColumnGroupUtils.isFirstVisibleColumnIndexInGroup(2, this.expandCollapseLayer, this.underlyingLayer, this.model));
    assertFalse(ColumnGroupUtils.isFirstVisibleColumnIndexInGroup(3, this.expandCollapseLayer, this.underlyingLayer, this.model));
}
Also used : ColumnHideShowLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.ColumnHideShowLayerFixture) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnReorderLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.ColumnReorderLayerFixture) ColumnGroupExpandCollapseLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupExpandCollapseLayer) Test(org.junit.Test)

Example 28 with ColumnReorderLayer

use of org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer in project nebula.widgets.nattable by eclipse.

the class ColumnStructuralChangeEventIntegrationTest method shouldUpdateReorderOnInsertAndDelete.

@Test
public void shouldUpdateReorderOnInsertAndDelete() {
    DefaultBodyLayerStack body = this.grid.getBodyLayer();
    ColumnReorderLayer reorderLayer = body.getColumnReorderLayer();
    body.doCommand(new ColumnReorderCommand(body, 3, 6));
    body.doCommand(new ColumnReorderCommand(body, 3, 5));
    assertEquals("[0, 1, 2, 5, 4, 3]", reorderLayer.getColumnIndexOrder().toString());
    this.provider.setColumnCount(7);
    this.grid.getBodyDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), 3));
    assertEquals("[0, 1, 2, 3, 6, 5, 4]", reorderLayer.getColumnIndexOrder().toString());
    this.provider.setColumnCount(6);
    this.grid.getBodyDataLayer().fireLayerEvent(new ColumnDeleteEvent(this.grid.getBodyDataLayer(), 3));
    assertEquals("[0, 1, 2, 5, 4, 3]", reorderLayer.getColumnIndexOrder().toString());
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 29 with ColumnReorderLayer

use of org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer in project nebula.widgets.nattable by eclipse.

the class _5111_ColumnGroupingExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "address.street", "address.housenumber", "address.postalCode", "address.city", "age", "birthday", "money", "description", "favouriteFood", "favouriteDrinks" };
    // 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("address.street", "Street");
    propertyToLabelMap.put("address.housenumber", "Housenumber");
    propertyToLabelMap.put("address.postalCode", "Postalcode");
    propertyToLabelMap.put("address.city", "City");
    propertyToLabelMap.put("age", "Age");
    propertyToLabelMap.put("birthday", "Birthday");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("description", "Description");
    propertyToLabelMap.put("favouriteFood", "Food");
    propertyToLabelMap.put("favouriteDrinks", "Drinks");
    IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    ColumnGroupModel columnGroupModel = new ColumnGroupModel();
    // 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.
    IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), columnPropertyAccessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
    ColumnGroupReorderLayer columnGroupReorderLayer = new ColumnGroupReorderLayer(columnReorderLayer, columnGroupModel);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnGroupReorderLayer);
    ColumnGroupExpandCollapseLayer columnGroupExpandCollapseLayer = new ColumnGroupExpandCollapseLayer(columnHideShowLayer, columnGroupModel);
    final SelectionLayer selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer, selectionLayer, columnGroupModel);
    // configure the column groups
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Person", 0, 1, 2, 3);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Address", 4, 5, 6, 7);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Facts", 8, 9, 10);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Personal", 11, 12, 13);
    columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Person", 0, 1);
    columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Address", 4, 5, 6);
    columnGroupHeaderLayer.setGroupUnbreakable(1);
    // 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, columnGroupHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, columnGroupHeaderLayer, 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 manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
            PopupMenuBuilder builder = super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
            builder.withEnabledState(PopupMenuBuilder.HIDE_COLUMN_MENU_ITEM_ID, new VisibleColumnsRemaining(selectionLayer));
            return builder;
        }
    });
    // Column group header menu
    final Menu columnGroupHeaderMenu = new PopupMenuBuilder(natTable).withRenameColumnGroupMenuItem().withRemoveColumnGroupMenuItem().build();
    natTable.addConfiguration(new AbstractUiBindingConfiguration() {

        @Override
        public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
            uiBindingRegistry.registerFirstMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_GROUP_HEADER, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(columnGroupHeaderMenu));
        }
    });
    // enable this configuration to verify the automatic height calculation
    // when using vertical text painter
    // natTable.addConfiguration(new AbstractRegistryConfiguration() {
    // 
    // @Override
    // public void configureRegistry(IConfigRegistry configRegistry) {
    // ICellPainter cellPainter = new BeveledBorderDecorator(new
    // VerticalTextPainter(false, true, 5, true, true));
    // configRegistry.registerConfigAttribute(
    // CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL,
    // GridRegion.COLUMN_HEADER);
    // }
    // });
    // Register column chooser
    DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(selectionLayer, columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, columnGroupModel, false, true);
    viewportLayer.registerCommandHandler(columnChooserCommandHandler);
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) 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) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) PopupMenuAction(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) VisibleColumnsRemaining(org.eclipse.nebula.widgets.nattable.ui.menu.VisibleColumnsRemaining) UiBindingRegistry(org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry) MouseEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher) DisplayColumnChooserCommandHandler(org.eclipse.nebula.widgets.nattable.columnChooser.command.DisplayColumnChooserCommandHandler) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ColumnGroupReorderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupReorderLayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) AbstractUiBindingConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) 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) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnGroupExpandCollapseLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupExpandCollapseLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Example 30 with ColumnReorderLayer

use of org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer in project nebula.widgets.nattable by eclipse.

the class InvertedLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    DummyBodyDataProvider bodyDataProvider = new DummyBodyDataProvider(5, 10);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    bodyDataLayer.setDefaultRowHeight(100);
    SelectionLayer selectionLayer = new SelectionLayer(new ColumnHideShowLayer(new ColumnReorderLayer(bodyDataLayer)));
    InvertedLayer invertedLayer = new InvertedLayer(selectionLayer);
    ViewportLayer viewportLayer = new ViewportLayer(invertedLayer);
    DummyColumnHeaderDataProvider columnHeaderDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider);
    rowHeaderDataLayer.setDefaultColumnWidth(40);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    GridLayer compositeLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    return new NatTable(parent, compositeLayer);
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) InvertedLayer(org.eclipse.nebula.widgets.nattable.layer.InvertedLayer) 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) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)

Aggregations

ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)36 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)25 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)25 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)24 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)22 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)21 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)21 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)18 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)18 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)18 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)18 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)18 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)18 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)16 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)14 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)14 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)14 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)14 HashMap (java.util.HashMap)13 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)11