Search in sources :

Example 1 with NatCombo

use of org.eclipse.nebula.widgets.nattable.widget.NatCombo 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 2 with NatCombo

use of org.eclipse.nebula.widgets.nattable.widget.NatCombo in project nebula.widgets.nattable by eclipse.

the class ComboBoxCellEditor method createEditorControl.

@Override
public NatCombo createEditorControl(Composite parent) {
    int style = SWT.NONE;
    if (!this.freeEdit) {
        style |= SWT.READ_ONLY;
    }
    if (this.multiselect) {
        style |= SWT.MULTI;
    }
    if (this.useCheckbox) {
        style |= SWT.CHECK;
    }
    final NatCombo combo = (this.iconImage == null) ? new NatCombo(parent, this.cellStyle, this.maxVisibleItems, style, this.showDropdownFilter) : new NatCombo(parent, this.cellStyle, this.maxVisibleItems, style, this.iconImage, this.showDropdownFilter);
    combo.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_IBEAM));
    if (this.multiselect) {
        combo.setMultiselectValueSeparator(this.multiselectValueSeparator);
        combo.setMultiselectTextBracket(this.multiselectTextPrefix, this.multiselectTextSuffix);
    }
    addNatComboListener(combo);
    return combo;
}
Also used : NatCombo(org.eclipse.nebula.widgets.nattable.widget.NatCombo) Cursor(org.eclipse.swt.graphics.Cursor)

Aggregations

NatCombo (org.eclipse.nebula.widgets.nattable.widget.NatCombo)2 PricingTypeBean (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean)1 ComboBoxCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor)1 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)1 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)1 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)1 ComboBoxPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter)1 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)1 Cursor (org.eclipse.swt.graphics.Cursor)1 Test (org.junit.Test)1