简体   繁体   English

Context 在 Idempiere/Adempiere 中的 GridField 和 GridTab 之间适合的位置

[英]Where do the Context fit between the GridField and the GridTab in Idempiere/Adempiere

I m trying to grasp the purpose of the following 3 concepts ( classes ) that are core functionalities in Idempiere/Adempiere.我试图掌握以下 3 个概念(类)的目的,它们是 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.我知道GridTab具有代表 ad_tab 的模型状态,它是任何 ad_table 的 ViewModel 部分。 simple said we will found the data bound to the ad_table.简单说我们会发现绑定到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.首先,对于GridField我相信它是视图的模型,如果我可以滥用它就像 DOM 状态:我们有什么作为字段、字段和事件的值,我相信这是以模板视图为中心的。

Dicovering this two ( if I m not mistaken in my analyses ) made me wonder.发现这两个(如果我在分析中没有弄错的话)让我感到疑惑。 What do really the Ctx stands for? Ctx 到底代表什么? what state is it representing ?它代表什么状态?

The code is not commenting on this , can any body answer me?代码没有对此发表评论,任何机构都可以回答我吗?

Thanks .谢谢 。

In iDempiere the context is a Properties object that is global to the whole application.在 iDempiere 中,上下文是整个应用程序全局的 Properties 对象。

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:可以通过单击 iDempiere 图标查看上下文变量,然后导航到“错误”选项卡,然后单击“查看”按钮,您将在该行之后找到变量:

=== Context ===

Within the context you can find a lot of information:在上下文中,您可以找到很多信息:

  • Login variables: some of those starting with #, like #AD_Role_ID登录变量:一些以 # 开头的变量,例如 #AD_Role_ID
  • Defaults: records that are marked as default, also starting with #, like #C_BP_Group_ID默认值:标记为默认值的记录,也以 # 开头,如 #C_BP_Group_ID
  • Accounting related variables: those starting with $, like $C_Currency_ID会计相关变量:以$开头的变量,如$C_Currency_ID
  • Global Preferences: starting with P like P|AutoCommit全局首选项:像 P|AutoCommit 一样以 P 开头
  • Window Preferences: starting with P and a number, example P132|GL_Category_ID窗口首选项:以 P 和数字开头,例如 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窗口字段:以数字开头的字段,例如 1|DiscountSchema - 这意味着打开的第一个窗口中的字段 DiscountSchema
  • 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)选项卡字段:以两个数字开头的字段,例如 1|2|DatePromised - 这意味着在打开的第一个窗口(数字 1)的第三个选项卡(数字 2,选项卡从零开始编号)中的字段 DatePromised

You can access those context variables using Env.getContext... methods, and you can also add and delete your own variables with methods Env.setContext...您可以使用 Env.getContext... 方法访问这些上下文变量,也可以使用 Env.setContext... 方法添加和删除您自己的变量。

The use and intent of Context in ADempiere is the same as described by Carlos except for the access. ADempiere 中 Context 的使用和意图与 Carlos 描述的相同,除了访问。 In the web you can access the context from the top right of the window as shown below.在 Web 中,您可以从窗口右上角访问上下文,如下所示。

显示上下文链接的 ADempiere 用户界面的片段

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;
    }
    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM