Trace: • Displaying Tables Without Database
IDataBook is required as data container(Model) for the use of tables. In most cases, RemoteDataBook is used to provide data from a database table. However, a table does not always exist in the database for which the data is displayed.
In this case, MemDataBook can be used, which is an IDataBook implementation that works with data in the main memory. No server connection is necessary, and there is no communication between client and server.
Example
We want to create a table that displays all Java system properties.
MemDataBook mdbSystem = new MemDataBook(); mdbSystem.setName("SYSTEM"); IRowDefinition rowdef = mdbSystem.getRowDefinition(); rowdef.addColumnDefinition(new ColumnDefinition("KEY")); rowdef.addColumnDefinition(new ColumnDefinition("VALUE")); rowdef.getColumnDefinition("KEY").setLabel("Parameter"); rowdef.getColumnDefinition("VALUE").setLabel("Value"); mdbSystem.open(); try { Properties props = System.getProperties(); for (Map.Entry<Object, Object> entry : props.entrySet()) { try { mdbSystem.insert(false); mdbSystem.setValue("KEY", entry.getKey()); mdbSystem.setValue("VALUE", entry.getValue()); } catch (SecurityException sec) { //nothing to be done } } } catch (SecurityException se) { //read only allowed properties //... //... }
MemDataBook has to be opened before it can be integrated. Before it is opened, the desired columns should be defined since, by default, there are no columns.
Columns are defined as follows:
rowdef.addColumnDefinition(new ColumnDefinition("KEY"));
Each IDataBook has an IRowDefinition for the administration of the available columns. A column is defined using ColumnDefinition, which at a minimum contains the column name and data type (text, number, date, etc.).