0

I m trying to grasp the purpose of the following 3 concepts ( classes ) that are core functionalities in Idempiere/Adempiere.

Based on code description

I do understand that GridTab have the state of the model representing the ad_tab which is the ViewModel Part of any ad_table. simple said we will found the data bound to the ad_table.

First, for the GridField I believe is the model of the view, if I can abuse it is like the the DOM state: what do we have as fields, values of fields and events, I believe that is template view centric.

Dicovering this two ( if I m not mistaken in my analyses ) made me wonder. What do really the Ctx stands for? what state is it representing ?

The code is not commenting on this , can any body answer me?

Thanks .

2 Answers2

2

In iDempiere the context is a Properties object that is global to the whole application.

You can think about the context as a global set of variables that you can access from any point of the system.

The context variables can be viewed clicking on the iDempiere icon, then navigating to the Errors tab, and then clicking on the View button, you'll find there the variables after the line:

=== Context ===

Within the context you can find a lot of information:

  • Login variables: some of those starting with #, like #AD_Role_ID
  • Defaults: records that are marked as default, also starting with #, like #C_BP_Group_ID
  • Accounting related variables: those starting with $, like $C_Currency_ID
  • Global Preferences: starting with P like P|AutoCommit
  • Window Preferences: starting with P and a number, example P132|GL_Category_ID

And then, the context variables that you're interested in, the value of each field on the windows that are open:

  • Window fields: those starting with a number, like 1|DiscountSchema - this means the field DiscountSchema in the first window opened
  • Tab fields: those starting with two numbers, like 1|2|DatePromised - this means the field DatePromised in the third tab (the number 2, tabs are numbered from zero) of the first window opened (the number 1)

You can access those context variables using Env.getContext... methods, and you can also add and delete your own variables with methods Env.setContext...

CarlosRuiz
  • 366
  • 2
  • 3
2

The use and intent of Context in ADempiere is the same as described by Carlos except for the access. In the web you can access the context from the top right of the window as shown below.

A snip of the ADempiere User Interface showing the context link

Another example of how the context provides global state is in testing. Here is a snippet from a test setup class that initializes the context with the time and login information. The context can then be accessed by test classes performing integration tests with a database as if they were in actual use. The context here is limited to login information but it could be extended to include any other element of the context required for the tests.

@BeforeAll
public static void setUpBeforeClass() {
    
    today = TimeUtil.getDay(System.currentTimeMillis());
    ctx = Env.getCtx();
    ctx.setProperty("#AD_Org_ID", Integer.toString(AD_ORG_ID));
    ctx.setProperty("#AD_User_ID", Integer.toString(AD_USER_ID));
    ctx.setProperty("#AD_Client_ID", Integer.toString(AD_CLIENT_ID));
    ctx.setProperty("#Date", TimeUtil.getDay(System.currentTimeMillis()).toString());
    ctx.setProperty("#AD_Language", "en");

    Ini.setClient (IS_CLIENT);
    Ini.loadProperties(false);
    org.compiere.Adempiere.startup(IS_CLIENT);

    trxName = Trx.createTrxName("TestRun_" + randomString(4));
    trx = Trx.get(trxName, false);
    
    try {
        mainSavepoint = trx.setSavepoint("AllTests_" + randomString(4));
    } catch (SQLException e) {
        fail(e.getMessage());
    }

}

@AfterAll
public static void tearDownAfterClass() {

    try {
        tryToRollback(mainSavepoint);
        trx.close();
    }
    catch(SQLException e) {
        fail("Unable to rollback. " + e.getMessage());
        
    }
    finally {
        trx.close();
        trx = null;
        ctx = null;
    }
    
}
Michael McKay
  • 650
  • 4
  • 11