Search in sources :

Example 1 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class ColumnChooserUtilsTest method getVisibleColumnEntries.

@Test
public void getVisibleColumnEntries() throws Exception {
    DefaultGridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
    ColumnHideShowLayer columnHideShowLayer = gridLayer.getBodyLayer().getColumnHideShowLayer();
    ColumnHeaderLayer columnHeaderLayer = gridLayer.getColumnHeaderLayer();
    DataLayer columnHeaderDataLayer = (DataLayer) gridLayer.getColumnHeaderDataLayer();
    List<ColumnEntry> visibleEntries = ColumnChooserUtils.getVisibleColumnsEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
    // All columns shown
    assertEquals(RowDataListFixture.getPropertyNames().length, visibleEntries.size());
    // Hide a few columns
    gridLayer.getBodyLayer().getColumnHideShowLayer().hideColumnPositions(Arrays.asList(1, 2, 3));
    visibleEntries = ColumnChooserUtils.getVisibleColumnsEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
    assertEquals(RowDataListFixture.getPropertyNames().length - 3, visibleEntries.size());
    // Check the hidden entries
    List<ColumnEntry> hiddenEntries = ColumnChooserUtils.getHiddenColumnEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
    assertEquals(3, hiddenEntries.size());
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) ColumnHeaderLayerFixture.getDataLayer(org.eclipse.nebula.widgets.nattable.test.fixture.layer.ColumnHeaderLayerFixture.getDataLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Example 2 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class SelectionSearchStrategyTest method setUp.

@Before
public void setUp() {
    this.bodyDataProvider = new IDataProvider() {

        @Override
        public int getColumnCount() {
            return GridLayerFixture.bodyDataProvider.getColumnCount();
        }

        @Override
        public int getRowCount() {
            return GridLayerFixture.bodyDataProvider.getRowCount();
        }

        @Override
        public Object getDataValue(int columnIndex, int rowIndex) {
            if (columnIndex == 0 || columnIndex == 9) {
                return CELL_VALUE;
            }
            return GridLayerFixture.bodyDataProvider.getDataValue(columnIndex, rowIndex);
        }

        @Override
        public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
            throw new UnsupportedOperationException();
        }
    };
    this.gridLayer = new DefaultGridLayer(this.bodyDataProvider, GridLayerFixture.colHeaderDataProvider, GridLayerFixture.rowHeaderDataProvider, GridLayerFixture.cornerDataProvider);
    this.gridLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 1050, 250);
        }
    });
    this.gridLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.V_SCROLL | SWT.H_SCROLL)));
    this.selectionLayer = this.gridLayer.getBodyLayer().getSelectionLayer();
    this.configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(this.configRegistry);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) Shell(org.eclipse.swt.widgets.Shell) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) Rectangle(org.eclipse.swt.graphics.Rectangle) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Before(org.junit.Before)

Example 3 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method comboBoxShouldCommitWhenAValueIsSelectedByClickingOnIt.

@Test
public void comboBoxShouldCommitWhenAValueIsSelectedByClickingOnIt() throws Exception {
    if (SWTUtils.isRunningOnUnix()) {
        return;
    }
    DefaultGridLayer layerStack = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
    this.natTable = new NatTableFixture(layerStack, 1200, 300, false);
    // Enable editing
    this.natTable.enableEditingOnAllCells();
    // Calculate pixel value to click on
    int columnIndex = RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME);
    int columnPosition = columnIndex + ROW_HEADER_COLUMN_COUNT;
    int rowPosition = 0 + COLUMN_HEADER_ROW_COUNT;
    int startX = this.natTable.getStartXOfColumnPosition(columnPosition);
    int startY = this.natTable.getStartYOfRowPosition(1);
    // Register combo box for the publish flag column
    DataLayer bodyDataLayer = (DataLayer) layerStack.getBodyDataLayer();
    this.natTable.registerLabelOnColumn(bodyDataLayer, columnIndex, TEST_LABEL);
    registerComboBox(this.natTable.getConfigRegistry(), new ComboBoxPainter(), new ComboBoxCellEditor(Arrays.asList(new PricingTypeBean("MN"), new PricingTypeBean("AT"))));
    this.natTable.configure();
    // Original value
    assertTrue(this.natTable.getDataValueByPosition(columnPosition, rowPosition) instanceof PricingTypeBean);
    assertEquals("MN", this.natTable.getDataValueByPosition(columnPosition, rowPosition).toString());
    // Click - expand combo
    SWTUtils.leftClick(startX + 10, startY + 10, SWT.NONE, this.natTable);
    NatCombo combo = (NatCombo) this.natTable.getActiveCellEditor().getEditorControl();
    assertNotNull(combo);
    assertTrue(this.natTable.getActiveCellEditor().getCanonicalValue() instanceof PricingTypeBean);
    assertEquals("MN", this.natTable.getActiveCellEditor().getCanonicalValue().toString());
    assertTrue(ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue() instanceof PricingTypeBean);
    assertEquals("MN", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue().toString());
    // Click - expand select value 'Automatic'
    combo.select(1);
    SWTUtils.leftClickOnCombo(startX + 10, startY + 35, SWT.NONE, combo);
    assertTrue(this.natTable.getDataValueByPosition(columnPosition, rowPosition) instanceof PricingTypeBean);
    assertEquals("AT", this.natTable.getDataValueByPosition(columnPosition, rowPosition).toString());
    assertNull(this.natTable.getActiveCellEditor());
    assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
Also used : SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) NatCombo(org.eclipse.nebula.widgets.nattable.widget.NatCombo) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) ComboBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter) ComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor) PricingTypeBean(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Example 4 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class _4471_EditorTraversalExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "birthday", "married", "gender" };
    // 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("married", "Married");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("birthday", "Birthday");
    IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(10), new ExtendedReflectiveColumnPropertyAccessor<Person>(propertyNames));
    DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap));
    final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    final NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new EditorConfiguration());
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 5 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class _447_EditorExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "password", "description", "age", "money", "married", "gender", "birthday", "address.street", "address.city", "favouriteFood", "favouriteDrinks", "filename" };
    // 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("password", "Password");
    propertyToLabelMap.put("description", "Description");
    propertyToLabelMap.put("age", "Age");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("birthday", "Birthday");
    propertyToLabelMap.put("address.street", "Street");
    propertyToLabelMap.put("address.city", "City");
    propertyToLabelMap.put("favouriteFood", "Food");
    propertyToLabelMap.put("favouriteDrinks", "Drinks");
    propertyToLabelMap.put("filename", "Filename");
    IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), new ExtendedReflectiveColumnPropertyAccessor<ExtendedPersonWithAddress>(propertyNames));
    DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap));
    final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    final NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new EditorConfiguration());
    natTable.configure();
    new NatTableContentTooltip(natTable, GridRegion.BODY);
    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) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) NatTableContentTooltip(org.eclipse.nebula.widgets.nattable.tooltip.NatTableContentTooltip) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Aggregations

DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)29 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)17 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)17 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)16 HashMap (java.util.HashMap)11 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)10 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)10 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)9 ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)9 Test (org.junit.Test)8 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)7 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)7 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)5 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)4 ExtendedPersonWithAddress (org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress)4 ArrayList (java.util.ArrayList)3 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Before (org.junit.Before)3 ObservableElementList (ca.odell.glazedlists.ObservableElementList)2