ADempiere Multiple Record Action Field

From ADempiere
Revision as of 02:25, 29 April 2009 by Ivanceras (Talk) (The Callout Rules)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.

This is a documentation showing about my feature request for ADempiere Multiple Record Action Field [1] [2] which nobody ever responded, and due to that I made the changes all by myself (T T). Anyways I just thought I am too ambigous, So now I will explain.

ADempiere Multiple Record Action Field

  • Im just using here a generic window, with no purpose at all. It is up for you to figure out the possibilities

The Output

  • The below image is the window showing the Single Row View

Student single.png

  • Below, the window is viewed in Multi-Row View. Notice the fields situated at the Header(Upper part of the Window) and also the fields at the Footer( at the bottom part of the window)

Student multirow.png

  • When clicking on the "Select All" button, all the records will be marked as selected reflected by the checkbox under "Select" column. The callout logic will be explain later


  • When the "Unselect All" button will be clicked, all the records will cleared as unselected, in which all of the "Select" checkbox will unchecked.


  • User could do normal selection of the records by clicking on the "Select" checkbox in the same to other windows with checkbox

Normal select.png

  • Alternately, User could also use the "Invert Selection" button to invert the selection

Invert selection.png

  • I also created a sample button at the footer which will may do actions.


  • Note: Those fields mentioned above are not built-in fields. I just created them just for a sample, in fact that window is not meaningful nor usable.

Video Demo

The Table Definition

  • To achieve the sample window above, we need to define first the table

Table definition.png

  • The table is just like common tables, ( I have copied it from "M_Freight_Category" )
  • Aside from those standard column,I added 6 columns, in which they are the center of this discussion:
  1. select_all
  2. unselect_all
  3. invert_selection
  4. IsSelected
  5. doAction
  6. total_selected

  • Remember the "Select All" button above, this is where that button is derived, take note of the callout specified, which will be created later

Table column select all.png

  • Of course this is the "Unselect All" button, again take notice of the callout specified

Table column unselect all.png

  • This one is for the "Invert Selection" button, so with its callout script

Table column invert selection.png

  • This column is just a predefined Element which I just reused. This will determine if the record is selected or not. This will be the subject for the callouts, which most of the sample callouts I have created will stir up this column.

Table column is selected.png

  • Notice that this column will not be shown when the window is viewed in Single-Row Presentation, since this in intended for Multi-Row View only, on the other hand, the other fields which are shown on the Header and Footer of the Window will only be visible when the window is viewed in Multi-Row Presentation, since it is what they are inteded ( to do actions on the Multiple Records Selected")

  • This is the button at the bottom of the page which we could relate it to buttons on common wizards window of some applications which does actions such as "Next, Finish, etc".

Table column doAction.png

  • This is a sample summary field which will display the summary of the records, in this case, the total record selected

Table column total selected.png

Creating new FieldGroupTypes

  • I added new FieldGroupTypes which are "Header - H" and "Footer - F"


  • I then create a FieldGroup "Header" of type "Header". We could use another name, but in any case the fields will still be shown in one area, and that is in the header since there are no other header area on the window
  • Fields that is specified to have this Field Group("Header") will be shown at the upper part of the window, just above any other fields, below the toolbar.

Fieldgroup header.png

  • Next is the "Footer" Field Group which is of type "Footer" also, the same way as "Header" field group, fields that are specified to "Footer" will be show at the bottom part of the window, just below all any other ordinary fields.


The Window Fields Definition

  • The here comes the window definition, as usual, aside from table, this will also defined the appearance, location and behaviour of the fields in the window

  • Below is the Field definition of my sample button "Select All". Take notice the Field Group which is "Header" in turn display it as the first button on the header area of the window. It is the first in the header area since it also observed the Field Order definition of the "Window Tab & Fields"

Window select all.png

  • Just as "Select All", the "Unselect All" is also defined as "Header" field Group, but with the addition that we specify that this field is "SameLine" which will align to the first field specified.
  • Note: if the "SameLine" is unchecked, this will cause the field to be created at the next line, just below the first field("Select All").

Window unselect all.png

  • In the same way as "Select All", this "Invert Selection" field is also of "Header" field Group, and "SameLine", hence, as you could observe, the three fields are lining up at the upper part of the window.

Window invert selection.png

  • Nothing differs from "IsSelected" field to other ordinary window. Just showing it here.

Window is selected.png

  • Next field is the "doAction" button field which is specified as "Footer" field group, causing it to be displayed at the lower part of the window.

Window footer.png

  • "Total Selected" field is defined in "Table and Column" as of type "String", causing it to be displayed as Text field in the lower part of the window since it is also specified as "Footer" Field Group.

Window total selected.png

The Callout Rules

  • I may have a made a sample of Callout using Callout classes, but I think it is too way harder than creating the callouts in the Rule Engine.
  • BTW, these Rule engine is a huge contribution from Carlos Luis and company, so with Victor. Thanks a lot to them!

  • So then, to continue, we have to make callouts for our "Multiple Record Action Fields", obviously it should operate on the records
  • Take note of the Value Search key, these are the values specified in "Table, Column & Fields" Callout.
  • The logic for selecting all the records is just to set all the "IsSelected" column to "Y"

Rule selectAll.png

  • Callout:
  • Here is the code for copy/paste:
int rowCount = A_Tab.getRowCount();
for(int i = 0; i< rowCount; i++){

  • As oppose to "Select All", "Unselect All" sets all "IsSelected" records to "N"

Rule UnselectAll.png

  • Callout:
  • Code:
int rowCount = A_Tab.getRowCount();
for(int i = 0; i< rowCount; i++){

  • For "Invert Selection", which check to see if the record is checked, and will set it to uncheck, else otherwise.

Rule InvertSelection.png

  • Callout:
  • Code:
int rowCount = A_Tab.getRowCount();
for(int i = 0; i< rowCount; i++){
   if(A_Tab.getValue(i,"IsSelected") ){

  • I have not created an interesting Callouts for this one, but for now, just be contented with this one. Or add yours to this wiki.

Rule DoAction.png

  • Callout:
  • Code:
javax.swing.JOptionPane.showMessageDialog(null,"Doing something in Callout!");
result = "Doing Something in Callout";

  • "Count Selected" callout is attached to the "IsSelected" column, which in turn displays the total number of selected columns to "total_records" field located at the bottom of the window. This is not accurate all the time for the moment( maybe because of "set active callouts" blah blah.. i dunno...). Hopefully soon this will be improved. Try to see the "Sample Output window" above and take notice of the figure at the "Total Selected" fields compared to the total number of selected records. You will see that it displays just as like a summary of the list and user actions.

Rule CountSelected.png

  • Callout:
  • Code:
int rowCount = A_Tab.getRowCount();
total = 0;
for(int i = 0; i< rowCount; i++){
   System.out.println(i+": "+A_Tab.getValue(i,"IsSelected")); 
   if( A_Tab.getValueAsBoolean(i,"IsSelected")){
System.out.println("total selected: "+total);
result = "";

The Patches

  • These are the patch files
  1. client/src/org/compiere/grid/GridController.patch
  2. base/src/org/compiere/model/GridTab.patch
  3. base/src/org/compiere/model/X_AD_FieldGroup.patch

  • New files
  1. client/src/org/compiere/grid/
  2. client/src/org/compiere/grid/
  3. client/src/org/compiere/grid/

  • Note: You may find that the codes I have written here seems to be odd, since this is my first time to code in Java for a real worl Application :o , but Im trying my best not to let it happen.

See also

Feel free to discuss about this --Ivanceras 12:27, 28 April 2009 (PDT)