~~NOTRANS~~
~~Title: Replacing Standard Insert Method of NavigationTable~~
The NavigationTable has buttons for insert/update/delete and other standard functionality. You can replace standard functionality with your own methods, e.g., load a zip file and insert records parsed from the archive - instead of inserting a new, empty, record.
Here's an example screen (AddOns from VisionX):
{{:applications:addons.png?nolink|}}
If the user is pressing the + button beside the table, an open file dialog should appear, like this one:
{{:applications:addons_open.png?nolink|}}
After selecting a file, the file should be parsed and a new record with parsed information should be inserted in the table. The parsing will be done in a server-side method and the return value of the method will be inserted.
== How is This Possible? ==
First, configure the databook:
rdbAddOns.eventAfterInserting().addListener(this, "doCancelInsert");
public void doCancelInsert() throws ModelException
{
rdbAddOns.restoreSelectedRow();
}
Don't insert new records.
Configure the NavigationTable:
navAddOns = new NavigationTable();
navAddOns.setDataBook(rdbAddOns);
navAddOns.setEditVisible(false);
navAddOns.eventInsert().addListener(this, "doNewAddOn");
public void doNewAddOn() throws Throwable
{
getApplication().getLauncher().getFileHandle(this, "doInsertAddOn");
}
public void doInsertAddOn(IFileHandle pFileHandle) throws Throwable
{
String sName = (String)getConnection().callAction("parseZip", pFileHandle);
rdbAddOns.eventAfterInserting().setDispatchEventsEnabled(false);
try
{
rdbAddOns.insert(false);
rdbAddOns.setValue("NAME", sName);
}
finally
{
rdbAddOns.eventAfterInserting().setDispatchEventsEnabled(true);
}
rdbAddOns.saveSelectedRow();
}
It also would be possible to use a custom storage implementation and simply do a reload:
public void doInsertAddOn(IFileHandle pFileHandle) throws Throwable
{
String sObjName = rdbAddOns.getName();
getConnection().call(sObjName, "insertArchive", pFileHandle);
rdbAddOns.reload();
}
The storage implementation could load all AddOns from the filesystem and not from the database.