Page 1 of 1

--Custom linked cell editors (dropdown, picklist)

PostPosted: Fri Nov 27, 2015 11:30 pm
by Development@SIB


This article is outdated - please use our new system at

https://doc.sibvisions.com




With JVx, it's very easy to define dropdown list boxes, LOVs or picklists. JVx supports manual definition or automatic definition of dropdowns. If you want to use automatic dropdowns, read following:

Automatic List Boxes based on the DB Model.

If you want to define custom dropdowns, continue reading.

JVx offers different options, with or without database.


UIEnumCellEditor

The easiest solution is an UIEnumCellEditor

Code: Select all
UIEnumCellEditor cellEditor = new UIEnumCellEditor();
cellEditor.setAllowedValues(new String[] {"A", "B", "C", "D"});
cellEditor.setDisplayValues(new String[] {"Alpha", "Bravo", "Charlie", "Delta"});

The cell editor saves an allowed value and displays a display value.

After the definition, set the cell editor to the datatype of a specific column

Code: Select all
dataBook_or_row.getRowDefinition().getColumnDefinition("VALUE").
                                   getDataType().setCellEditor(cellEditor);

Use an IDataBook or IDataRow. An IDataBook is for example the MemDataBook or the RemoteDataBook. An IDataRow is for example the DataRow.

It's possible to create a DataRow from an existing IDataBook, e.g.

Code: Select all
IDataRow row = baseDataBook.createEmptyRow(new String[] {"LINK_ID", "LINK_VALUE"});

or to create a new DataRow

Code: Select all
RowDefinition rowdef = new RowDefinition();
rowdef.addColumnDefinition(new ColumnDefinition("LINK_ID", new BigDecimalDataType()));
rowdef.addColumnDefinition(new ColumnDefinition("LINK_VALUE"));

DataRow row = new DataRow(rowdef);


To use automatic translation, follow this instructions.


UILinkedCellEditor

If you need more flexibility, use an UILinkedCellEditor for your dropdowns. The UIEnumCellEditor maps a Value to one ID column, and displays the value column.

The UILinkedCellEditor shows one or more columns and maps multiple ID columns. The cell editor needs an IDataBook which contains the data. Use a MemDataBook or a RemoteDataBook. Our example uses a MemDataBook.

Code: Select all
RowDefinition rowdef = new RowDefinition();
rowdef.addColumnDefinition(new ColumnDefinition("ID", new BigDecimalDataType()));
rowdef.addColumnDefinition(new ColumnDefinition("VALUE"));

MemDataBook memBook = new MemDataBook(rowdef);
memBook.setName("memory");
memBook.open();

UILinkedCellEditor linkCellEditor = new UILinkedCellEditor();
linkCellEditor.setLinkReference(new ReferenceDefinition(
                      new String[] {"LINK_ID", "LINK_VALUE"},
                      memBook,
                      new String[] {"ID", "VALUE"}));

dataBook_or_row.getRowDefinition().getColumnDefinition("LINK_VALUE").
                                   getDataType().setCellEditor(cellEditor);

We map the ID to LINK_ID and VALUE to LINK_VALUE. The VALUE column will be shown in the dropdown. After selecting a value, the ID and VALUE will be written to LINK_ID and LINK_VALUE.

You can use the UILinkedCellEditor with a RemoteDataBook and read record from a remote storage, e.g. a database, a XML file, CSV file or any other datasource. You don't need a specific datasource if you use a MemDataBook.