Form S_194FTRE

LANSA

Form S_194FTRE
* ===================================================================;
*;
* Component : S_194FTRE;
* Type : Form;
* Ancestor : PRIM_FORM (Primitive Form);
*;
* Description : Manually Expand Tree View;
*;
* Full Description; This form is an example of:;
* 1) How to manually expand a tree view;
* 2) How to dynamically set the focus on a selected entry in a Tree View;
* 3) How to dynamically change an icon (image) asociated to a Tree View entry;
*;
* Disclaimer : The following material is supplied as sample material;
* only. No warranty concerning this material or its use;
* in any way whatsoever is expressed or implied.;
*;
* ===================================================================;
;
FUNCTION OPTIONS(*DIRECT);
BEGIN_COM HEIGHT(548) LAYOUTMANAGER(#ATLM_1) LEFT(315) TOP(134) WIDTH(567);
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATLM_1);
DEFINE_COM CLASS(#PRIM_TRVW) NAME(#TRVW_1) DISPLAYPOSITION(1) HEIGHT(494) LEFT(0) MANAGECHILDREN(True) PARENT(#COM_OWNER) TABPOSITION(1) TOP(0) WIDTH(439);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_1) ATTACHMENT(Center) MANAGE(#TRVW_1) PARENT(#ATLM_1);
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_1) DISPLAYPOSITION(1) KEYPOSITION(1) LEVEL(1) PARENT(#TRVW_1) SORTPOSITION(1) SOURCE(#DEPTDESC);
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_2) LEVEL(1) PARENT(#TRVW_1) SOURCE(#DEPTMENT) VISIBLE(False);
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_3) DISPLAYPOSITION(1) KEYPOSITION(1) LEVEL(2) PARENT(#TRVW_1) SORTPOSITION(1) SOURCE(#SECDESC);
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_4) LEVEL(2) PARENT(#TRVW_1) SOURCE(#SECTION) VISIBLE(False);
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_5) DISPLAYPOSITION(1) LEVEL(3) PARENT(#TRVW_1) SORTPOSITION(1) SOURCE(#FULLNAME);
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_6) KEYPOSITION(1) LEVEL(3) PARENT(#TRVW_1) SOURCE(#EMPNO) VISIBLE(False);
DEFINE_COM CLASS(#PRIM_PANL) NAME(#PANL_1) DISPLAYPOSITION(2) HEIGHT(494) LEFT(439) PARENT(#COM_OWNER) TABPOSITION(2) TABSTOP(False) TOP(0) WIDTH(120);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_2) ATTACHMENT(Right) MANAGE(#PANL_1) PARENT(#ATLM_1);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PB_COLLAPSE_ALL) CAPTION('&Collapse All') DISPLAYPOSITION(1) LEFT(8) PARENT(#PANL_1) TABPOSITION(1) TOP(8) WIDTH(105);
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(3) HEIGHT(27) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(3) TABSTOP(False) TOP(494) WIDTH(559);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_3) ATTACHMENT(Bottom) MANAGE(#STBR_1) PARENT(#ATLM_1);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PB_FIND) BUTTONDEFAULT(True) CAPTION('&Find') DISPLAYPOSITION(2) LEFT(8) PARENT(#PANL_1) TABPOSITION(4) TOP(288) WIDTH(105);
DEFINE_COM CLASS(#PRIM_RDBN) NAME(#RB_SURNAM) BUTTONCHECKED(True) CAPTION('Surname') DISPLAYPOSITION(1) LEFT(8) PARENT(#GPBX_1) TABPOSITION(1) TOP(24) WIDTH(80);
DEFINE_COM CLASS(#PRIM_RDBN) NAME(#RB_EMPNO) CAPTION('Employee No.') DISPLAYPOSITION(2) LEFT(8) PARENT(#GPBX_1) TABPOSITION(2) TOP(56) WIDTH(90);
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_1) CAPTION('Search Criteria') DISPLAYPOSITION(3) HEIGHT(105) LEFT(8) PARENT(#PANL_1) TABPOSITION(3) TABSTOP(False) TOP(152) WIDTH(105);
DEFINE_COM CLASS(#SURNAME.Visual) NAME(#S_SRCHVAL) CAPTION('Search Value') DISPLAYPOSITION(4) HEIGHT(41) LABELPOSITION(Top) LABELTYPE(Caption) LEFT(8) MARGINLEFT(0) MARGINTOP(19) PARENT(#PANL_1) TABPOSITION(2) TOP(88) WIDTH(105);
;
DEFINE FIELD(#W_DEPT) REFFLD(#DEPTMENT);
DEFINE FIELD(#W_SECT) REFFLD(#SECTION);
DEFINE FIELD(#W_EMPNO) REFFLD(#EMPNO);
;
DEFINE FIELD(#DEPT_wk) REFFLD(#DEPTMENT);
DEFINE FIELD(#SECT_wk) REFFLD(#SECTION);
DEFINE FIELD(#EMPN_wk) REFFLD(#EMPNO);
;
DEFINE FIELD(#SDESC_WK) REFFLD(#SECDESC);
DEFINE FIELD(#DDESC_WK) REFFLD(#DEPTDESC);
;
DEF_LIST NAME(#DPTSEC_WK) FIELDS(#DEPT_WK #SECT_WK) COUNTER(#LISTCOUNT) TYPE(*WORKING);
DEF_LIST NAME(#EMP_SELEC) FIELDS(#EMPN_WK #DEPTDESC #SECDESC) TYPE(*WORKING);
;
DEFINE FIELD(#IMAGE_SET) TYPE(*CHAR) LENGTH(3) DEFAULT(NO);
DEF_COND NAME(*EMP_DONE) COND('#image_set = YES');
;
DEF_COND NAME(*NO_CHILD) COND('#TRVW_1.currentITEM.HASCHILDREN *Ne YES');
;
EVTROUTINE HANDLING(#com_owner.CreateInstance);
* Set caption;
SET COM(#com_owner) CAPTION(*component_desc);
* Set tree view icons;
SET COM(#TVCL_1) IMAGE(#VI_FOLDCL) IMAGEEXPANDED(#VI_FOLDOP);
SET COM(#TVCL_3) IMAGE(#VI_SECTCL) IMAGEEXPANDED(#VI_SECTOP);
ENDROUTINE;
;
*;
* ===============================================================================;
* Populate first level of tree view (departments);
* ===============================================================================;
*;
EVTROUTINE HANDLING(#com_owner.Initialize) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
EXECUTE SUBROUTINE(GET_DEPTS);
ENDROUTINE;
;
*;
* ===============================================================================;
* Handle manual expansion of treeview level. This event is fired when;
* the user clicks on the + sign.;
* ===============================================================================;
*;
EVTROUTINE HANDLING(#TRVW_1.ItemExpanding) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
* Keep the current item level in a different variable.;
DEFINE FIELD(#CUR_LEVEL) TYPE(*DEC) LENGTH(2) DECIMALS(0);
CHANGE FIELD(#CUR_LEVEL) TO('#trvw_1.currentitem.level');
*;
CASE OF_FIELD(#CUR_LEVEL);
WHEN VALUE_IS('= 1');
* The Departments are defined in level 1. If the current item level is 1;
* it means the user has clicked on a plus sign next to a;
* Department. Execute the subroutine to get Sections for the selected Department.;
EXECUTE SUBROUTINE(GET_SECTS) WITH_PARMS(#DEPTMENT);
WHEN VALUE_IS('= 2');
* The Sections are defined in level 2. If the current item level is 2 it means the user has clicked on a plus sign next to a;
* Section. Execute the subroutine to get Employees for the "selected" Department and Section.;
EXECUTE SUBROUTINE(get_emps) WITH_PARMS(#DEPTMENT #SECTION);
ENDCASE;
ENDROUTINE;
;
*;
* ===============================================================================;
* Handle manual collapse of treeview level. This event is fired when the user;
* clicks on an individual Item to collapse it.;
* ===============================================================================;
*;
;
EVTROUTINE HANDLING(#TRVW_1.ItemCollapsed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
SET COM(#trvw_1.currentitem) HASCHILDREN(unknown);
ENDROUTINE;
;
*;
* ===============================================================================;
* Add Departments to the treeview. This routine selects departments and adds them;
* to the tree view. The Section file is looked at using the CHECK_FOR command to;
* determine whehter to enable or disable the + sign.;
* ===============================================================================;
*;
SUBROUTINE NAME(GET_DEPTS);
SELECT FIELDS(#TRVW_1) FROM_FILE(DEPTAB);
ADD_ENTRY TO_LIST(#TRVW_1);
* Check for children. If none, do not show "+";
CHECK_FOR IN_FILE(SECTAB) WITH_KEY(#DEPTMENT);
IF_STATUS IS(*NOTEQUALKEY);
* Disable "+";
SET COM(#TRVW_1.CURRENTITEM) HASCHILDREN(NO);
ENDIF;
ENDSELECT;
ENDROUTINE;
;
*;
* ===============================================================================;
* Add Sections to the treeview. This routine selects Sections and adds them to the;
* tree view. The Personel Master file is looked at using the CHECK_FOR command to;
* determine whehter to enable or disable the + sign;
* ===============================================================================;
*;
;
SUBROUTINE NAME(GET_SECTS) PARMS(#DEPTMENT);
SET COM(#TRVW_1.CURRENTITEM) HASCHILDREN(YES);
SELECT FIELDS(#TRVW_1) FROM_FILE(SECTAB) WITH_KEY(#DEPTMENT);
ADD_ENTRY TO_LIST(#trvw_1);
* Check for children. If none, do not show "+";
CHECK_FOR IN_FILE(PSLMST1) WITH_KEY(#DEPTMENT #SECTION);
IF_STATUS IS(*NOTEQUALKEY);
* Disable "+";
SET COM(#TRVW_1.CURRENTITEM) HASCHILDREN(NO);
ENDIF;
ENDSELECT;
ENDROUTINE;
;
*;
* ===============================================================================;
* Add employees to the treeview. Select the Employess and add them to the Tree View.;
* Use the TCONCAT bif to concatenate Surname, Given Name and Employee Number and;
* show as one string separated by commas.;
* ===============================================================================;
*;
SUBROUTINE NAME(GET_EMPS) PARMS(#DEPTMENT #SECTION);
SET COM(#TRVW_1.CURRENTITEM) HASCHILDREN(YES);
SELECT FIELDS(#GIVENAME #SURNAME #EMPNO) FROM_FILE(PSLMST1) WITH_KEY(#DEPTMENT #SECTION);
USE BUILTIN(TCONCAT) WITH_ARGS(#SURNAME ', ' #GIVENAME ', ' #EMPNO) TO_GET(#FULLNAME);
ADD_ENTRY TO_LIST(#TRVW_1);
SET COM(#TRVW_1.CURRENTITEM) HASCHILDREN(NO);
ENDSELECT;
ENDROUTINE;
;
*;
* ===============================================================================;
* Find Employee(s) depending on the Search Criteria. This event is fired when;
* the user clicks on the Find button.;
* ===============================================================================;
*;
EVTROUTINE HANDLING(#PB_FIND.Click);
* The EXP_ITMES list is used to store items to expand once tree has been built.;
DEF_LIST NAME(#EXP_ITEMS) FIELDS(#STD_NUM) TYPE(*WORKING);
CLR_LIST NAMED(#EXP_ITEMS);
;
* If the search criteria selected is by Employee Number, verify the requested;
* Employee exists, otherwise set the error for the search field on the form.;
;
IF COND('#rb_empno.ButtonChecked *EQ true');
CHANGE FIELD(#EMPNO) TO(#S_SRCHVAL);
CHECK_FOR IN_FILE(PSLMST) WITH_KEY(#EMPNO);
BEGINCHECK;
IF_STATUS IS_NOT(*EQUALKEY);
EXECUTE SUBROUTINE(RESET_IMG);
SET_ERROR FOR_FIELD(#S_SRCHVAL) MSGTXT('Employee does not exist');
ENDIF;
ENDCHECK;
ENDIF;
;
* If the search criteria selected is by Surname, do the following:;
* 1) Use the logical view PSLMST2 keyed by Surname to Select the Employees whose Surname;
* matches the selection criteria.;
* 2) Get the department and section descriptions for each of the employees. This is done so that;
* 3) Store each one of the employee numbers and the department and section descriptions they;
* belong to in the working list #EMP_SELEC. Later, this working list will be accessed for two;
* different reasons:;
* a) while processing the tree view list in the EXPAND subroutine, validate whether the employee;
* matches the criteria and hence should have red tick image set next to it.;
* b) in the subroutine FIND_EMPF, the list is sorted by department-section description. This will make;
* the order of the entries on the list equivalent as the order of the entries in the Tree View.;
* 4) Store unique Department and the Section codes in the working list DPTSEC_WK to.;
* later know what Departments and Sections to expand.;
* 5) Verify wether there exists any Employee matching the selection criteria by;
* interrogating whether the working list has any entries in it (#listcoutnt = 0).;
* If not, set the error and message for search value field.;
* 6) Sort the department/section working list.;
* 7) Read through the dept/sect list. For each entry, execute the FILL_EXPAND;
* subroutine to locate in the Tree View and store in the Expanded Itmes list;
* the entry number of the selected Department and Section.;
* 8) Execute the EXPAND subroutine to expand the selected Item(s);
;
CLR_LIST NAMED(#EMP_SELEC);
;
IF COND('#rb_surnam.ButtonChecked *EQ true ');
;
CLR_LIST NAMED(#DPTSEC_WK);
;
SELECT FIELDS(#SURNAME #DEPTMENT #SECTION #EMPNO) FROM_FILE(PSLMST2) WITH_KEY(#S_SRCHVAL) GENERIC(*YES);
CHANGE FIELD(#DEPT_WK) TO(#deptment);
CHANGE FIELD(#SECT_WK) TO(#section);
CHANGE FIELD(#EMPN_WK) TO(#empno);
FETCH FIELDS(#DEPTDESC) FROM_FILE(DEPTAB) WITH_KEY(#DEPTMENT);
FETCH FIELDS(#SECDESC) FROM_FILE(SECTAB) WITH_KEY(#DEPTMENT #SECTION);
ADD_ENTRY TO_LIST(#EMP_SELEC);
;
LOC_ENTRY IN_LIST(#DPTSEC_WK) WHERE('(#deptment = #dept_wk) and (#section = #sect_wk)');
IF_STATUS IS(*NORECORD);
ADD_ENTRY TO_LIST(#DPTSEC_WK);
ENDIF;
ENDSELECT;
;
BEGINCHECK;
IF COND('#listcount = 0');
EXECUTE SUBROUTINE(RESET_IMG);
SET_ERROR FOR_FIELD(#S_SRCHVAL) MSGTXT('Employee not found');
ENDIF;
ENDCHECK;
;
* Sort the working list in the same order as the Tree View;
SORT_LIST NAMED(#DPTSEC_WK) BY_FIELDS(#DEPT_WK #SECT_WK);
;
SELECTLIST NAMED(#DPTSEC_WK);
EXECUTE SUBROUTINE(FILL_EXPND) WITH_PARMS(#DEPT_WK #SECT_WK);
ENDSELECT;
EXECUTE SUBROUTINE(EXPAND);
;
ELSE;
;
* If the search criteria selected is by Employee Number, do the following:;
* 1) FETCH the Department and Section;
* 2) Execute the FILL_EXPAND subroutine to locate in the Tree View and store;
* in the Expanded Items list the entry number of the selected Department and;
* Section.;
* 3) Execute the EXPAND subroutine to expand the selected Item;
CHANGE FIELD(#IMAGE_SET) TO(*DEFAULT);
CHANGE FIELD(#W_EMPNO) TO(#S_SRCHVAL);
FETCH FIELDS(#DEPTMENT #SECTION) FROM_FILE(PSLMST) WITH_KEY(#W_EMPNO);
CHANGE FIELD(#EMPN_WK) TO(#empno);
ADD_ENTRY TO_LIST(#EMP_SELEC);
EXECUTE SUBROUTINE(FILL_EXPND) WITH_PARMS(#DEPTMENT #SECTION);
EXECUTE SUBROUTINE(EXPAND);
ENDIF;
;
ENDROUTINE;
;
*;
* ===============================================================================;
* Populate the expanded items working list. Read through the Tree View list and;
* compare the values for Department first and Section second passed to this;
* subroutine. When they match, add to the Items to be expanded list.;
* ===============================================================================;
*;
SUBROUTINE NAME(FILL_EXPND) PARMS((#W_DEPT *RECEIVED) (#W_SECT *RECEIVED));
* Find required Department entry and set position;
SELECTLIST NAMED(#TRVW_1);
CONTINUE IF('#DEPTMENT *NE #W_DEPT');
* When correct entry found, store entry number in list of items to expand;
CHANGE FIELD(#STD_NUM) TO(#TRVW_1.CURRENTITEM.ENTRY);
GET_ENTRY NUMBER(#STD_NUM);
ADD_ENTRY TO_LIST(#EXP_ITEMS);
LEAVE;
ENDSELECT;
;
* If department has no children, get section records for department;
IF COND(*No_Child);
EXECUTE SUBROUTINE(GET_SECTS) WITH_PARMS(#W_DEPT);
ENDIF;
;
* Find required section entry and set position;
SELECTLIST NAMED(#TRVW_1);
CONTINUE IF('(#DEPTMENT *NE #W_DEPT) OR (#SECTION *NE #W_SECT)');
* When correct entry found, store entry number in list of items to expand;
CHANGE FIELD(#STD_NUM) TO(#TRVW_1.CURRENTITEM.ENTRY);
GET_ENTRY NUMBER(#STD_NUM);
ADD_ENTRY TO_LIST(#EXP_ITEMS);
LEAVE;
ENDSELECT;
;
* If section has no children, read employee data;
IF COND(*No_Child);
EXECUTE SUBROUTINE(GET_EMPS) WITH_PARMS(#W_DEPT #W_SECT);
ENDIF;
ENDROUTINE;
;
*;
* ===============================================================================;
* First read through the list of Item to Expand, get the equivalent entry from;
* the Tree View list and set the expanded item's property to true.;
* Second, read through the Tree View list.;
*;
* If the selection criteria was Surname, attempt to locate the entry in the list;
* that stores the Employee numbers that matched the selection criteria (#EMP_SELEC).;
* If found, change the image to the red tick, otherwise reset it to blank.;
*;
* If the selection criteria was Employee Number, attempt to locate the entry in the list;
* that stores the Employee numbers that matched the selection criteria.;
* If found, change the image to the red tick, otherwise reset it to blank.;
* ===============================================================================;
*;
;
SUBROUTINE NAME(EXPAND);
* Expand department and section items above employee;
SELECTLIST NAMED(#EXP_ITEMS);
GET_ENTRY NUMBER(#STD_NUM) FROM_LIST(#TRVW_1);
SET COM(#TRVW_1.CURRENTITEM) EXPANDED(TRUE);
ENDSELECT;
;
IF COND('#rb_surnam.ButtonChecked *EQ true');
SELECTLIST NAMED(#TRVW_1);
CONTINUE IF('#trvw_1.currentitem.level *ne 3');
CHANGE FIELD(#EMPN_WK) TO(#empno);
LOC_ENTRY IN_LIST(#EMP_SELEC) WHERE('#empno = #empn_wk');
IF_STATUS IS(*OKAY);
SET COM(#TRVW_1.CURRENTITEM) IMAGE(#VI_CKIT);
ELSE;
EXECUTE SUBROUTINE(NULL_IMG);
ENDIF;
ENDSELECT;
EXECUTE SUBROUTINE(FIND_EMPF);
ELSE;
SELECTLIST NAMED(#TRVW_1);
CONTINUE IF('#trvw_1.currentitem.level *ne 3');
EXECUTE SUBROUTINE(NULL_IMG);
CONTINUE IF(*emp_done);
IF COND('#W_EMPNO *EQ #EMPNO');
EXECUTE SUBROUTINE(RESET_FOC);
CHANGE FIELD(#IMAGE_SET) TO(YES);
ENDIF;
ENDSELECT;
ENDIF;
ENDROUTINE;
;
*;
* ===============================================================================;
* Find the employee that should receive focus;
* ===============================================================================;
*;
SUBROUTINE NAME(FIND_EMPF);
* Position to logical first employee;
SORT_LIST NAMED(#EMP_SELEC) BY_FIELDS(#DEPTDESC #SECDESC);
GET_ENTRY NUMBER(1) FROM_LIST(#EMP_SELEC);
SELECTLIST NAMED(#trvw_1);
CONTINUE IF('#empno *ne #empn_wk');
EXECUTE SUBROUTINE(RESET_FOC);
LEAVE;
ENDSELECT;
ENDROUTINE;
;
;
*;
* ===============================================================================;
* Remove the red tick image next to the Employee;
* ===============================================================================;
*;
SUBROUTINE NAME(NULL_IMG);
SET COM(#TRVW_1.CURRENTITEM) IMAGE(*NULL);
ENDROUTINE;
;
*;
* ===============================================================================;
* Reset focus and red tick image to selected Employee (s);
* ===============================================================================;
*;
SUBROUTINE NAME(RESET_FOC);
SET COM(#TRVW_1.CURRENTITEM) IMAGE(#VI_CKIT);
SET COM(#TRVW_1.CURRENTITEM) FOCUS(TRUE) ENSUREVISIBLE(TRUE);
CHANGE FIELD(#STD_NUM) TO(#TRVW_1.FocusItem.Entry);
GET_ENTRY NUMBER(#STD_NUM) FROM_LIST(#TRVW_1);
ENDROUTINE;
;
*;
* ===============================================================================;
* When Employee not found, reset the image of prior selected Employees;
* ===============================================================================;
*;
SUBROUTINE NAME(RESET_IMG);
SELECTLIST NAMED(#TRVW_1);
CONTINUE IF('#trvw_1.currentitem.level *ne 3');
SET COM(#TRVW_1.CURRENTITEM) IMAGE(*NULL);
ENDSELECT;
ENDROUTINE;
* ===============================================================================;
* Collapse to top level only;
* ===============================================================================;
*;
EVTROUTINE HANDLING(#PB_COLLAPSE_ALL.Click);
SELECTLIST NAMED(#TRVW_1);
SET COM(#trvw_1.currentitem) EXPANDED(false) HASCHILDREN(UNKNOWN);
ENDSELECT;
ENDROUTINE;
;
END_COM