The package is available only in Visual Prolog Commercial Edition.
The package represents the table editor, which uses grid custom control.
1. Overview
Purpose
Table editor custom control is a screen object for browsing and editing information structured as a rectangular table. Table editor is based on a Grid custom control. In addition to the Grid functionality Table editor have many high level functions like internal data storage, sorting, filtering, undo-redo, etc.
Sorts of cell information and tools to edit cell contents.
Each Table editor cell may display integer, real, long or text information. Clicking a mouse button user may open one of the listed bellow controls inside the cell in order to edit it's contents:
* edit control,
* listbutton control,
* listedit control,
* any custom control,
* no control .
The application may decide which control to open in certain cell dynamically (during runtime).
Multiple instances
One or more instances of the Table editor custom control may be created inside one or more windows or dialogs at the same time. Each copy may have it's own properties like:
* general properties of the Table editor (TABLEEDIT_PROPERTIES),
* individual column properties (TABLEEDIT_COLUMNPROPERTIES)
* style, font, number of columns and rows and it's own application defined callback function (or they may share one callback function if desirable.
Interaction between the Table editor and the application
The Table editor custom control have internal storage for data to be displayed.
The Table editor has two modes:
* nobuffering - all data are passed to table editor during initialization and stored internally.
* buffering - table editor has the internal bufer with limited size and asks for next potion of data when necessary using special callback function. Using table editor in this mode is recommended for browsing of big databases which cannot be stored internally.
Table editor uses Callback function to notify the application about user actions inside the Table editor. It's the applications responsibility to provide suitable reactions to the user actions and events handling. If an event or user action is not handled by the application, then the Table editor control provides default handling.
Code structure
The source code consists of TABLEED.DOM (domains declaration), TABLEED.PRE (predicates declaration) and TABLEED.PRO (including also TABMAIN.PRO, TABLEED1.PRO, TABLEED2.PRO, TABLEED3.PRO, TABLEED4.PRO) (implementation). "TEMPLATE" directory contains TABLEED.DOM, TABLEED.PRE, TABLEED.PRO templates.
Multilanguage support
File TABLEED.CL contains 3 sets of string constants for menu:
* in English,
* in Danish,
* in Russian.
Application programmer must declare one of the constants below before including file TABLEED.CON in order to select one of the languages:
language_english = 1
or
language_danish = 1
or
language_russian = 1
If the support for any other language is desirable, open TABLEED.CON and add one more section with constants string.
Integration of the Table editor tool with the application by templates
For integration of the Table editor tool with the application programmer should follow next steps:
1. Copy TABLEED.DOM, TABLEED.PRE, TABLEED.PRO templates to application directory.
2. Replace all occurrences of "TABLEED_DIR" string in TABLEED.DOM, TABLEED.PRE, TABLEED.PRO templates with actual path to the TABLEED tool files.
3. Copy GRID custom control templates to application directory.
4. Replace all occurrences of "GRID_DIR" string in GRID templates with actual path to the GRID tool files.
5. Replace "PROJECT" string in TABLEED.PRO and GRID.PRO templates with actual name of the project.
6. Include GRID.DOM and TABLEED.DOM into the <PROJECT>.INC.
7. Include TABLEED.PRE into the project modules operating with Table editor.
8. Declare one of the "language_xxx" constants in the <PROJECT>.INC.
9. Add GRID.PRO and TABLEED.PRO template files to the list of project
modules.
2. Using Table editor custom control in application
Integration of the Table editor custom control with the program
To use the Table editor custom control application programmer should follow next steps:
1. Register class for the Table editor custom controls on Task window e_Create
event:
task_win_eh(Win,e_Create(_),0):-
tb_project_toolbar_Create(Win),
tb_help_line_Create(Win),
msg_Create(100),
% REGISTER CLASS FOR THE TABLE EDITOR CUSTOM CONTROL
class_Create("tableed_class", tableed_class_handler),
!.
Destroy class on TaskWindow e_Destroy
event.
task_win_eh(_Win,e_Destroy(),0):-
% DESTROY CLASS FOR THE TABLE EDITOR CUSTOM CONTROL
class_Destroy("tableed_class"),fail.
2. Supply the class with the event handler. Normally class event handler looks like:tableed_class_handler(Win,e_Create(_),0):-!, % CALL tableedit_Init ON /*Put here predicates assigning*/ % E_CREATE EVENT /* init arguments values */ /* TableProperties = ... */ /* ColumnProperties = ... */ /* InputData = ... */ tableedit_Init(Win,TableProperies,ColumnProperties,InputData). tableed_class_handler(Win,EVENT,0):- % CALL tableedit_HandleEvent tableedit_HandleEvent(Win,EVENT). % ON ANY OTHER EVENTBuffering mode:
PREDICATES .... buffAnswerFunc : TABLEEDIT_ANSWERDATA_FUNC .... CLAUSES tableed_class_handler(Win,e_Create(_),0):-!, % CALL tableedit_Init ON /*Put here predicates assigning*/ % E_CREATE EVENT /* init arguments values */ /* TableProperties = [bufferingmode(buffering(buffAnswerFunc,BuffSize,Maxows)),...]*/ /* ColumnProperties = ... */ tableedit_Init(Win,TableProperies,ColumnProperties,[]). tableed_class_handler(Win,EVENT,0):- % CALL tableedit_HandleEvent tableedit_HandleEvent(Win,EVENT). % ON ANY OTHER EVENT /* Data Request for table editor in buffering mode*/ buffAnswerFunc(_Win,FromRow,ToRow,Data):- /* Put here predicate for get data from external database*/ getDataFromDatabase(FromRow,ToRow,Data), !.Note that data argument is empty for tableedit_Init predicate in buffering mode because special callback function is used here to retrieve data from database.
PREDICATES test_window_eh : EHANDLER . . . . . . . . . . . CLAUSES . . . . . . . . . . . %--- Top level window create --- Win = win_Create(w_TopLevel,RCT,"Table editor test",no_menu,ParentWin, win_Flags,test_window_eh,0), %--- Table editor custom control create on e_Create EVENT--- test_window_eh(Win,e_Create(_),0):- RCT = win_GetClientRect(Win), Wdef = wdef(wc_Custom,RCT,"",u_Pixels), WinDefList = [customctl(Wdef,tableed_class,tableed_id,[])], win_CreateDynControl(WinDefList,Win),!. . . . . . . . . . . .* Load a dialog containing Table editor custom control from the project resources using usual call to win_CreateResDialog. The dialog specified by idd_TableEditor_test_dialog resource identifier in the following example may contain one or more Grid custom controls:
win_CreateResDialog(Parent,wd_Modal,idd_TableEditor_test_dialog, dlg_TableEditor_test_eh,0),!.General (table) properties of the Table editor custom control.
TABLEEDIT_CONTROL_TYPE = edit; % edit control listbutton(SLIST); % listbutton control listedit(SLIST); % listedit control % custom control custom(STRING ClassName,CTL_FLAGS Ctl_Flags, GRID_PUT_CUSTOM_DATA, GRID_GET_CUSTOM_DATA)Default: edit control.
PREDICATES tab_Callback : TABLEEDIT_CALLBACK ... CLAUSES ... tab_Callback(_TableEditorWin,Event):- Event = modified(2,1,_,r(2.2)),!.* Forbid the setting of the row marker into first row (the marker not to appear):
... tab_Callback(_TableEditorWin,Event):- Event = action(row_marker_beg(1)),!.* Forbid the setting of the row marker into first row (the marker will be seted and cancelled):
... tab_Callback(_TableEditorWin,Event):- Event = marker(M,b_true), M =grid_row_marker([gl(1,1)]),!.Handling Table editor custom control callback function in buffering mode
/*
User is about to Change cell data by editing or "cut","paste" operation or application Change cell data by tableedit_SetData/6, tableedit_SetRowData/4,
tableedit_SetClipBoardData/6, tableedit_SetCellData/4
*/
tab_Callback(_TableEditorWin,Event):-
Event = modified(Row,Column,_OldValue,NewValue),!,
/* Put here predicate for set data to external database*/
setDataToDatabase(Row,Column,NewValue),
fail.
/*
The user inseted row by "Insert row" operation.
*/
tab_Callback(TableEditorWin,Event):-
Event = insert_row(Row,InsData),!,
/* Put here predicate for insert row to external database*/
insertRowToDatabase(Row,InsData),
/* Get old MaxRow from table editor*/
MaxRows = tableedit_MaxRows(TableEditorWin),
NewMaxRows = MaxRows + 1,
/* Set New MaxRow to table editor*/
tableedit_Buff_SetMaxRows(TableEditorWin,NewMaxRows),
fail.
/*
The user deleted row by "Delete row" operation.
*/
tab_Callback(_TableEditorWin,Event):-
Event = delete_row(Row,_DelData),!,
/* Put here predicate for delete row to external database*/
deleteRowFromDatabase(Row),
/* Get old MaxRow from table editor*/
MaxRows = tableedit_MaxRows(Win),
NewMaxRows = MaxRows - 1,
/* Set New MaxRow to table editor*/
tableedit_Buff_SetMaxRows(Win,NewMaxRows),
fail.
/*
For example, forbid choice of the "cut" operation from column 2.
*/
tab_Callback(_TableEditorWin,Event):-
Event = cut_beg(_FromRow,_ToRow,FromColumn,ToColumn),
Column = 2,
Column >= FromColumn, Column <= ToColumn,
!.
/*
User is coped, pasted or cuted data by "copy","pste","cut" operations.
For example, forbid the "copy","paste","cut" and notify, if row range is more than 300.
*/
tab_Callback(_TableEditorWin,Event):-
Event = copy(FromRow,ToRow,_FromColumn,_ToColumn),
RowLimit = 300,
ToRow - FromRow >= RowLimit,
dlg_Note("Area too large for copying"),
!.
tab_Callback(_TableEditorWin,Event):-
Event = paste(FromRow,ToRow,_FromColumn,_ToColumn),
RowLimit = 300,
ToRow - FromRow >= RowLimit,
dlg_Note("Area too large for pasting"),
!.
tab_Callback(_TableEditorWin,Event):-
Event = cut(FromRow,ToRow,_FromColumn,_ToColumn),
RowLimit = 300,
ToRow - FromRow >= RowLimit,
dlg_Note("Area too large for cuting"),
!.
/*
The user set filter by "Filter by selection","Filter excluding selection" or "Show all rows" operation.
*/
tab_Callback(_TableEditorWin,Event):-
Event = filter(Filterlist),!,
/* Put here predicate for handle filter for external database*/
handleFiltersForDatabase(Filterlist,NewMaxRows),
/*Set New MaxRow to table editor*/
tableedit_Buff_SetMaxRows(Win,NewMaxRows),
/* Reset Table editor data*/
tableedit_SetAllData(Win,[]),
fail.
/*
The user sorted data by "Sort ascending","Sort descending" operation.
*/
tab_Callback(_TableEditorWin,Event):-
Event = sort(Column,Sortmode),!,
/* Put here predicate for handle sorting for external database*/
handleSortForDatabase(Column,Sortmode),
/* Reset Table editor data*/
tableedit_SetAllData(Win,[]),
fail.
/*
The user change PictureNameId string, set picture for
PictureNameId.
*/
tab_Callback(_TableEditorWin,Event):-
Event = modified(Row,Column,_OldValue,NewValue),
% For example, column 4 is te_picture type
Column = 4,
NewValue = p(_,_,PictureNameId),
/* Put here predicate for get Picture by PictureNameId string*/
get_PictureByNameId(PictureNameId,Pic,Stretch),
NewValue1 = p(Pic,Stretch,PictureNameId),
/* Put here predicate for set data to external database*/
setDataToDatabase(Row,Column,NewValue1),!,
fail.
Callback messages.PREDICATES compareFunc : TABLEEDIT_COMPARE convertdata(TABLEEDIT_CELLDATA,STRING) ... CLAUSES ... compareFunc(_Win,Column,First,Second,equal):- Column = 3, convertdata(First,Str1), convertdata(Second,Str2), Str1 = Str2,!. compareFunc(_Win,Column,First,Second,less):- Column = 3, convertdata(First,Str1), convertdata(Second,Str2), dt_minstr_to_offset(Str1,"%DD-%MD-%YS",Offset1), dt_minstr_to_offset(Str2,"%DD-%MD-%YS",Offset2), Offset1 < Offset2,!. compareFunc(_,Column,_,_,more):- Column = 3,!.Compare function:
TABLEEDIT_COMPARE = (WINDOW TableEditWindow, INTEGER Column, TABLEEDIT_CELLDATA CellData1, TABLEEDIT_CELLDATA CellData2, TABLEEDIT_COMPARESTATUS Equal_More_Less) determ (i,i,i,i,o)
Examples
Next example shows initialisation of the Table editor with external callback function, consisting from three columns with data and titles.
The first column has a real type and "Real Data" title.
The second column has a string type and "String Data" title.
The third column has a string type, "Date" title and type of control is custom (in this case -
date custom control).
The other Table and Column properties have default values.
Nobuffering mode:
tableed_class_handler(TableEditorWindow,e_Create(_),0):-!,
...
tableedit_Init(TableEditorWindow,
[callback(tab_Callback)],
[
column([title("Real Data"), column_type(te_real),
column([title("String Data")]),
column([title("Date"), control(custom("date",[],date_put_string,date_get_string)),
alignment(grid_left_align)])
],
[
[r(1.0),s("1s"),sc("10-04-97",255)], %(255 - is red color)
[r(2.0),s("2s"),sc("11-04-97",255)],
[r(3.0),s("3s"),sc("12-04-97",255)],
[r(4.0),s("4s"),sc("13-04-97",255)],
[r(5.0),s("5s"),sc("14-04-97",255)],
[r(6.0),s("6s"),void],
[r(7.0),s("7s"),void]
]
),fail.
Buffering mode:
PREDICATES
....
buffAnswerFunc : TABLEEDIT_ANSWERDATA_FUNC
....
CLAUSES
tableed_class_handler(TableEditorWindow,e_Create(_),0):-!,
...
BuffSize = 30,
get_MaxRowsFromExternalDatabase(MaxRows),
...
tableedit_Init(TableEditorWindow,
[callback(tab_Callback), bufferingmode(buffering(buffAnswer,Buff,MaxRows))],
[
column([title("Real Data"), column_type(te_real),
column([title("String Data")]),
column([title("Date"), control(custom("date",[],date_put_string,date_get_string)),
alignment(grid_left_align)])
],
[]
),fail.
/* Data Request for table editor in buffering mode*/
buffAnswerFunc(_Win,FromRow,ToRow,Data):-
/* Get data from external database*/
getDataFromDatabase(FromRow,ToRow,Data),
!.