Search in sources :

Example 6 with CheckBoxCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor in project nebula.widgets.nattable by eclipse.

the class EditorConfiguration method registerColumnEightCheckbox.

/**
 * The following will register a CheckBoxCellEditor with custom icons for
 * the column that carries the gender information. As a Gender is not a
 * Boolean, there need to be a special converter registered. Note that such
 * a converter needs to create a Boolean display value and create the
 * canonical value out of a Boolean value again.
 * <p>
 * To register a CheckBoxCellEditor, you need to
 * <ol>
 * <li>Register the editor</li>
 * <li>Register the painter corresponding to that editor</li>
 * <li>Register the needed converter</li>
 * </ol>
 *
 * @param configRegistry
 */
private void registerColumnEightCheckbox(IConfigRegistry configRegistry) {
    // register a CheckBoxCellEditor for column four
    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.EDIT, EditorExample.COLUMN_EIGHT_LABEL);
    // if you want to use the CheckBoxCellEditor, you should also consider
    // using the corresponding CheckBoxPainter to show the content like a
    // checkbox in your NatTable
    // in this case we use different icons to show how this works
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(GUIHelper.getImage("arrow_up"), GUIHelper.getImage("arrow_down")), DisplayMode.NORMAL, EditorExample.COLUMN_EIGHT_LABEL);
    // using a CheckBoxCellEditor also needs a Boolean conversion to work
    // correctly
    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, getGenderBooleanConverter(), DisplayMode.NORMAL, EditorExample.COLUMN_EIGHT_LABEL);
}
Also used : CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor)

Example 7 with CheckBoxCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor in project nebula.widgets.nattable by eclipse.

the class RowSelectionEditUtilsTest method testIsEditorSameWithMultiSelectionOneChangedEditor.

@Test
public void testIsEditorSameWithMultiSelectionOneChangedEditor() {
    this.selectionLayer.selectCell(1, 1, false, true);
    this.selectionLayer.selectCell(2, 2, false, true);
    this.selectionLayer.selectCell(3, 3, false, true);
    DataLayer bodyDataLayer = (DataLayer) this.gridLayerStack.getBodyDataLayer();
    this.natTable.registerLabelOnColumn(bodyDataLayer, 1, TEST_LABEL);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.EDIT, TEST_LABEL);
    // the result is true here because using the IRowSelectionModel the
    // anchor is used to determine the cells to edit
    assertTrue(EditUtils.isEditorSame(this.selectionLayer, this.natTable.getConfigRegistry()));
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor) Test(org.junit.Test)

Example 8 with CheckBoxCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor in project nebula.widgets.nattable by eclipse.

the class RowSelectionEditUtilsTest method testIsEditorSameWithSingleSelectionOneChangedEditor.

@Test
public void testIsEditorSameWithSingleSelectionOneChangedEditor() {
    DataLayer bodyDataLayer = (DataLayer) this.gridLayerStack.getBodyDataLayer();
    this.natTable.registerLabelOnColumn(bodyDataLayer, 1, TEST_LABEL);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.EDIT, TEST_LABEL);
    this.selectionLayer.selectCell(1, 1, false, false);
    assertTrue(EditUtils.isEditorSame(this.selectionLayer, this.natTable.getConfigRegistry()));
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor) Test(org.junit.Test)

Example 9 with CheckBoxCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method clickingOnTheCheckBoxMustToggleItsValue.

@Test
public void clickingOnTheCheckBoxMustToggleItsValue() throws Exception {
    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.PUBLISH_FLAG_PROP_NAME);
    int columnPosition = columnIndex + ROW_HEADER_COLUMN_COUNT;
    int startX = this.natTable.getStartXOfColumnPosition(columnPosition);
    int columnWidth = this.natTable.getColumnWidthByPosition(columnPosition);
    int startY = this.natTable.getStartYOfRowPosition(1);
    int rowHeight = this.natTable.getRowHeightByPosition(1);
    // Register check box for the publish flag column
    DataLayer bodyDataLayer = (DataLayer) layerStack.getBodyDataLayer();
    this.natTable.registerLabelOnColumn(bodyDataLayer, columnIndex, TEST_LABEL);
    registerCheckBoxEditor(this.natTable.getConfigRegistry(), new CheckBoxPainter(), new CheckBoxCellEditor());
    this.natTable.configure();
    // Value before click
    assertEquals(true, this.natTable.getDataValueByPosition(columnPosition, 1));
    // Click on the check box
    SWTUtils.leftClick(startX + (columnWidth / 2), startY + (rowHeight / 2), SWT.NONE, this.natTable);
    // Value After click
    assertEquals(false, this.natTable.getDataValueByPosition(columnPosition, 1));
}
Also used : SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Example 10 with CheckBoxCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor in project nebula.widgets.nattable by eclipse.

the class _424_NebulaRichTextIntegrationExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // set the directory to which the richtext resources should be unpacked
    System.setProperty(RichTextEditor.JAR_UNPACK_LOCATION_PROPERTY, System.getProperty("user.dir") + File.separator + RichTextEditor.class.getPackage().getName());
    String[] propertyNames = new String[] { "firstName", "lastName", "gender", "married", "description" };
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("description", "Description");
    IColumnAccessor<Person> columnAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    List<Person> persons = PersonService.getPersons(10);
    IDataProvider bodyDataProvider = new ListDataProvider<>(persons, columnAccessor);
    DefaultColumnHeaderDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, columnHeaderDataProvider);
    ((AbstractLayer) gridLayer.getBodyDataLayer()).setConfigLabelAccumulator(new ColumnLabelAccumulator());
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add custom painter and editor configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // configure converter
            MarkupDisplayConverter markupConverter = new MarkupDisplayConverter();
            markupConverter.registerMarkup("Simpson", "<em>", "</em>");
            markupConverter.registerMarkup("Smithers", "<span style=\"background-color:rgb(255, 0, 0)\"><strong><s><u>", "</u></s></strong></span>");
            // register markup display converter for normal displaymode
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, markupConverter, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1);
            // register default display converter for editing, so there is
            // no markup in the editor
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter(), DisplayMode.EDIT, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            // configure cell painter
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(new PaddingDecorator(new RichTextCellPainter(), 2, 5, 2, 5)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(new PaddingDecorator(new RichTextCellPainter(), 2, 5, 2, 5)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            // configure editing
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new RichTextCellEditor(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
        }
    });
    natTable.configure();
    natTable.setTheme(new ModernNatTableThemeConfiguration());
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) RichTextCellEditor(org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextCellEditor) AbstractLayer(org.eclipse.nebula.widgets.nattable.layer.AbstractLayer) HashMap(java.util.HashMap) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DefaultDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) RichTextEditor(org.eclipse.nebula.widgets.richtext.RichTextEditor) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) BackgroundPainter(org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) MarkupDisplayConverter(org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.MarkupDisplayConverter) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) RichTextCellPainter(org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextCellPainter) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) 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) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Aggregations

CheckBoxCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor)12 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)8 CheckBoxPainter (org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter)7 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)5 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)5 DefaultBooleanDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter)5 Test (org.junit.Test)5 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)4 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)4 HashMap (java.util.HashMap)3 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)3 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)3 ColumnLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 VisualRefreshCommand (org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand)2 ExtendedReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor)2 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)2