Replacing standard insert method of NavigationTable

Information about development with ProjX.

Replacing standard insert method of NavigationTable

Postby Development@SIB » Wed Aug 10, 2016 2:52 pm

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):

addons.png
addons.png (24.41 KiB) Viewed 473 times


If the user presses the + Button beside the table, an Open file dialog should appear, like this one:

addons_open.png
addons_open.png (51.39 KiB) Viewed 473 times

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:

Code: Select all
rdbAddOns.eventAfterInserting().addListener(this, "doCancelInsert");

Code: Select all
public void doCancelInsert() throws ModelException
{
    rdbAddOns.restoreSelectedRow();
}

Don't insert new records.

Configure the NavigationTable:

Code: Select all
navAddOns = new NavigationTable();
navAddOns.setDataBook(rdbAddOns);
navAddOns.setEditVisible(false);
navAddOns.eventInsert().addListener(this, "doNewAddOn");

Code: Select all
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:

Code: Select all
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...
User avatar
Development@SIB
 
Posts: 310
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation