-
Notifications
You must be signed in to change notification settings - Fork 7
/
BBjGridExWidget.bbj
1491 lines (1208 loc) · 48.4 KB
/
BBjGridExWidget.bbj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use com.basiscomponents.db.ResultSet
use com.basiscomponents.db.DataRow
use com.basiscomponents.db.tree.DataTree
use java.sql.Types
use com.google.gson.Gson
use com.google.gson.JsonParser
use com.google.gson.JsonObject
use com.google.gson.JsonArray
use java.lang.Integer
use java.util.ArrayList
use java.util.HashMap
use ::BBjWidget/BBjWidget.bbj::BBjWidget
class public BBjGridExWidgetRow
field public BBjString Id!
field public BBjNumber ChildIndex!
field public BBjString ParentKey!
field public BBjNumber IsSelected!
field public JsonObject Data!
method public String toString()
methodret #Id!
methodend
method public DataRow asDataRow()
methodret DataRow.fromJson(#Data!.toString())
methodend
classend
class public BBjGridExWidgetSelectRowEvent
field public BBjVector ChangedRows! = new BBjVector()
field public BBjVector NewSelectedRows! = new BBjVector()
field public BBjVector NewDeselectedRows! = new BBjVector()
field public BBjVector SelectedRows! = new BBjVector()
rem /**
rem * Get the number of affected rows by the last event
rem *
rem * @return BBjNumber
rem */
method public BBjNumber getRowCount()
methodret #ChangedRows!.size()
methodend
rem /**
rem * Get the number of selected rows by the last event
rem *
rem * @return BBjNumber
rem */
method public BBjNumber getSelectedRowCount()
methodret #NewSelectedRows!.size()
methodend
rem /**
rem * Get the number of deselected rows by the last event
rem *
rem * @return BBjNumber
rem */
method public BBjNumber getDeselectedRowCount()
methodret #NewDeselectedRows!.size()
methodend
rem /**
rem * Get the ids of selected rows by the last event
rem *
rem * @return BBjVector
rem */
method public BBjVector getNewSelectedRows()
declare BBjVector ids!
ids! = new BBjVector()
selectedCount! = #getSelectedRowCount()
if selectedCount! > 0 then
for n = 0 to selectedCount! - 1 step 1
ids!.add(cast(BBjGridExWidgetRow,#NewSelectedRows!.getItem(n)).getId())
next n
fi
methodret ids!
methodend
rem /**
rem * Get the ids of deselected rows by the last event
rem *
rem * @return BBjNumber
rem */
method public BBjVector getNewDeselectedRows()
declare BBjVector ids!
ids! = new BBjVector()
deselectedCount! = #getDeselectedRowCount()
if deselectedCount! > 0 then
for n = 0 to deselectedCount! - 1 step 1
ids!.add(cast(BBjGridExWidgetRow,#NewDeselectedRows!.getItem(n)).getId())
next n
fi
methodret ids!
methodend
classend
class public BBjGridExWidgetDoubleClickRowEvent
field public BBjGridExWidgetRow Row!
classend
class public BBjGridWidgetCellEditingEvent
field public BBjGridExWidgetRow Row!
field public BBjString Column$
field public BBjString Value$
classend
class public BBjGridWidgetRowEditingEvent
field public BBjGridExWidgetRow Row!
classend
class public BBjGridExWidgetColumnState
field public BBjString String$
classend
rem /**
rem * A sample BBj Widget Implementation
rem */
class public BBjGridExWidget extends BBjWidget
field private BBjHtmlView HTMLView!
field private Boolean IsReady! = BBjAPI.FALSE
field private BBjVector backlog! = new BBjVector()
field private ResultSet RS!
field private BBjString URL$
field private DataTree TREE!
field private BBjString GroupColumnLabel$ = "Group"
field private BBjNumber SelectionMode
field private BBjNumber MultipleSelection
field private BBjNumber FitToGrid
field private BBjNumber EnableFilter
field private BBjNumber EnableFloatingFilter
field private BBjNumber GroupChildCount
field private BBjNumber groupSelectsChildren
field private BBjNumber showSelectionCheckbox
field private BBjString RowNodeId$
field private BBjString ParentNodeId$
field private DataRow ColumnDefinition!
field private HashMap SelectedRowsMap! = new HashMap()
field public static BBjString LicenseKey$
field private BBjNumber Editing! = 0
rem Enable/disable grid editing
field public BBjNumber Editable! = 0
rem Enable/disable grid single click editing
field public BBjNumber SingleClickEdit! = 0
rem Set the default column type
field public BBjString DefaultType$ = #GRID_TYPE_BASIC_STRING()
rem enable/disable group edit
field public BBjNumber GroupEdit! = 0
rem /**
rem * Define the edit type
rem *
rem * @see BBjGridExWidget.GRID_TYPE_BASIC_STRING
rem * @see BBjGridExWidget.GRID_TYPE_BASIC_TEXT
rem * @see BBjGridExWidget.GRID_TYPE_BASIC_NUMBER
rem * @see BBjGridExWidget.GRID_TYPE_BASIC_BOOLEAN
rem * @see BBjGridExWidget.GRID_TYPE_BASIC_DATE
rem * @see BBjGridExWidget.GRID_TYPE_BASIC_TIMESTAMP
rem * @see BBjGridExWidget.GRID_TYPE_BASIC_IMAGE
rem * @see BBjGridExWidget.GRID_TYPE_BASIC_IMAGE_FILTERABLE
rem */
field public BBjString EditType$ = ""
rem /**
rem * Enter Key Behavior
rem *
rem * @see BBjGridExWidget.GRID_ENTER_NEXT_CELL
rem * @see BBjGridExWidget.GRID_ENTER_STOP_EDITING
rem */
field public BBjString EnterKeyBehavior$ = ""
rem --------------------- constructors -------------------------------------
rem /**
rem * disabled default constructor
rem */
method private BBjGridExWidget()
methodend
rem /**
rem * The constructor that creates the widget on wnd!
rem * @param BBjWindow wnd!: parent window
rem * @param BBjInt id: the control ID
rem * @param BBjInt x: x-location
rem * @param BBjInt y: y-location
rem * @param BBjInt w: width
rem * @param BBjInt h: height
rem */
method public BBjGridExWidget(BBjWindow wnd!, BBjInt id!, BBjInt x!, BBjInt y!, BBjInt w!, BBjInt h!)
#super!.create(wnd!,id!,x!,y!,w!,h!)
methodend
rem ---------------------- methods from BBjWidget --------------------------------
rem /**
rem * @Override
rem * This method is called whenever the widget needs to be rendered
rem * @param Boolean f_init!: if TRUE the control is rendered for the first time so this method has to perform initial rendering
rem */
method public void redraw(Boolean f_init!)
declare BBjHtmlView htmlview!
if (f_init!) then
dummy$=stbl("!OPTIONS","JAVAFX_HTMLVIEW=true")
html$="<html><body><div id='eventTransporterDiv' onClick='gw_postEvent(event);'></div><div id=""grid"" style=""height: 100%"" class=""ag-theme-balham""></div></body></html>"
htmlview! = #getCanvas().addHtmlView(101,0,0,#getCanvas().getWidth(),#getCanvas().getHeight(),"")
htmlview!.setCallback(BBjAPI.ON_PAGE_LOADED,#this!,"onLoad")
htmlview!.setCallback(BBjAPI.ON_NATIVE_JAVASCRIPT,#this!,"onNativeEvent")
htmlview!.setOpaque(0)
htmlview!.setText(html$)
#HTMLView!=htmlview!
if INFO(3,6)<>"5" then
#HTMLView!.setLocation(-9,-9)
fi
fi
if INFO(3,6)="5" then
#HTMLView!.setSize(#getCanvas().getWidth(),#getCanvas().getHeight())
else
#HTMLView!.setSize(#getCanvas().getWidth()+16,#getCanvas().getHeight()+16)
fi
methodend
rem /**
rem * Optinally Suppress the number of items in a group
rem *
rem * @param BBjNumber status!: 0 to enable , 1 to disable
rem *
rem */
method public void setShowGroupChildCount(BBjNumber status!)
#GroupChildCount=status!
methodend
rem /**
rem * When true, selecting a group will have the impact of selecting all its children
rem * When false, then the group is selectable independently of the child nodes
rem */
method public void setGroupSelectsChildren(BBjNumber x!)
rem this only makes sense with mutli-selection switched on!
#setMultipleSelection(1)
#groupSelectsChildren=x!
methodend
rem /**
rem * When true, selection box will be show on the first column
rem * When false, no checkbox will be displayed
rem */
method public void setShowSelectionCheckbox(BBjNumber x!)
#showSelectionCheckbox=x!
methodend
rem /**
rem * set the selected row
rem */
method public void setSelectedRow(BBjNumber x!)
#deselectAll()
script$="gw_setSelectedRows([" + str(x!) + "]);"
#executeScript(script$)
methodend
rem /**
rem * set the selected row indices
rem */
method public void setSelectedRows(BBjVector x!)
#deselectAll()
script$="gw_setSelectedRows(["
it! = x!.iterator()
first=1
while it!.hasNext()
if first
first=0
else
script$=script$+","
fi
script$=script$+str(it!.next())
wend
script$=script$+"]);"
#executeScript(script$)
methodend
rem /**
rem * select all rows
rem */
method public void selectAll()
script$="gw_selectAll(0);"
#executeScript(script$)
methodend
rem /**
rem * select all rows
rem *
rem * @param BBJNumber x!: 0 select all , 1 select all filtered
rem */
method public void selectAll(BBjNumber x!)
script$="gw_selectAll(" + str(x!) + ");"
#executeScript(script$)
methodend
rem /**
rem * deselect all rows
rem */
method public void deselectAll()
script$="gw_deselectAll(0);"
#executeScript(script$)
methodend
rem /**
rem * deselect all rows
rem *
rem * @param BBJNumber x!: 0 deselect all , 1 deselect all filtered
rem */
method public void deselectAll(BBjNumber x!)
script$="gw_deselectAll(" + str(x!) + ");"
#executeScript(script$)
methodend
rem /**
rem * Expand all groups.
rem */
method public void expandAll()
script$="gw_expandAll();"
#executeScript(script$)
methodend
rem /**
rem * collapse all groups.
rem */
method public void collapseAll()
script$="gw_collapseAll();"
#executeScript(script$)
methodend
rem /**
rem * set visible row
rem *
rem * Ensures the row index is visible by vertically scrolling the grid.
rem * The valid values for positions are {'top', 'middle', 'bottom'}.
rem * If top, middle or bottom, the grid will scroll the row to place the row at top, middle or bottom
rem *
rem * @param BBjNumber index!: the row index
rem * @param BBjString position!: the scrolling poistion
rem *
rem * @see GRID_ROWPOS_TOP()
rem * @see GRID_ROWPOS_MIDDLE()
rem * @see GRID_ROWPOS_BOTTOM()
rem */
method public void setVisibleRow(BBjNumber index! , BBjString position!)
script$="gw_setVisibleRow(" + str(index!) + ",'" + str(position!) +"');"
#executeScript(script$)
methodend
rem /**
rem * set visible column
rem *
rem * Ensures the column is visible, scrolling the table if needed.
rem *
rem * @param BBJString columnid!: the column id
rem */
method public void setVisibleColumn(BBjString columnId!)
script$="gw_setVisibleColumn('" + columnId! + "');"
#executeScript(script$)
methodend
rem /**
rem * Event Handler for Native JavaScript Event (from the Grid)
rem * Determines and dispatches the actual event
rem *
rem * @param BBjNativeJavaScriptEvent ev!: the js event
rem *
rem */
method public void onNativeEvent ( BBjNativeJavaScriptEvent ev!)
map! = ev!.getEventMap()
type$ = map!.get("type")
detail$ = map!.get("detail")
switch type$
case "grid-row-select"
#handleGridSelectRowEvent(detail$)
break
case "grid-row-doubleclick"
#handleGridDoubleClickEvent(detail$)
break
case "cellEditingStarted"
#Editing! = 1
#handleGridCellEditingEvent(detail$,#ON_GRID_CELL_EDITING_STARTED())
break
case "cellEditingStopped"
#Editing! = 0
#handleGridCellEditingEvent(detail$,#ON_GRID_CELL_EDITING_STOPPED())
break
case "rowEditingStarted"
#Editing! = 1
#handleGridROWEditingEvent(detail$,#ON_GRID_ROW_EDITING_STARTED())
break
case "rowEditingStopped"
#Editing! = 0
#handleGridROWEditingEvent(detail$,#ON_GRID_ROW_EDITING_STOPPED())
break
swend
methodend
rem /**
rem * Handle Rows Selections Event
rem *
rem * Parse the json details coming from the client and fires new BBjGridExWidgetSelectRowEvent
rem *
rem * @see BBjGridExWidgetSelectRowEvent
rem */
method private void handleGridSelectRowEvent(BBjString detail$)
parser! = new JsonParser()
array! = parser!.parse(detail$).getAsJsonObject().get("0")
rows! = new BBjVector()
selected! = new BBjVector()
deselected! = new BBjVector()
it! = array!.iterator()
while (it!.hasNext())
next! = it!.next().getAsJsonObject()
row! = new BBjGridExWidgetRow()
row!.setId(next!.get("id").getAsString())
row!.setChildIndex(next!.get("childIndex").getAsInt())
row!.setParentKey(next!.get("parentKey").getAsString())
row!.setData(next!.get("data").getAsJsonObject())
row!.setIsSelected(iff(next!.get("selected").getAsString() = "true" , 1 , 0))
rows!.add( row!)
if row!.getIsSelected() = 1 then
selected!.add(row!)
#SelectedRowsMap!.put(row!.getId(),row!)
else
deselected!.add(row!)
#SelectedRowsMap!.remove(row!.getId())
fi
wend
event! = new BBjGridExWidgetSelectRowEvent()
event!.setChangedRows(rows!)
event!.setNewSelectedRows(selected!)
event!.setNewDeselectedRows(deselected!)
event!.setSelectedRows(#getSelectedRows())
#fireEvent(#ON_GRID_SELECT_ROW(),event!)
methodend
rem /**
rem * Handle Doucle click event
rem *
rem * Parse the json details coming from the client and fires new BBjGridExWidgetDoubleClickRowEvent
rem *
rem * @see BBjGridExWidgetDoubleClickRowEvent
rem */
method private void handleGridDoubleClickEvent(BBjString detail$)
parser! = new JsonParser()
array! = parser!.parse(detail$).getAsJsonObject().get("0")
next! = array!.iterator().next().getAsJsonObject()
row! = new BBjGridExWidgetRow()
row!.setId(next!.get("id").getAsString())
row!.setChildIndex(next!.get("childIndex").getAsInt())
row!.setParentKey(next!.get("parentKey").getAsString())
row!.setData(next!.get("data").getAsJsonObject())
row!.setIsSelected(iff(next!.get("selected").getAsString() = "true" , 1 , 0))
event! = new BBjGridExWidgetDoubleClickRowEvent()
event!.setRow(row!)
#fireEvent(#ON_GRID_DOUBLE_CLICK(), event!)
methodend
method private void handleGridCellEditingEvent(BBjString detail$ , BBjNumber type!)
parser! = new JsonParser()
array! = parser!.parse(detail$).getAsJsonObject().get("0")
next! = array!.iterator().next().getAsJsonObject()
rowAsJson! = next!.get("row").getAsJsonObject()
row! = new BBjGridExWidgetRow()
row!.setId(rowAsJson!.get("id").getAsString())
row!.setChildIndex(rowAsJson!.get("childIndex").getAsInt())
row!.setParentKey(rowAsJson!.get("parentKey").getAsString())
row!.setData(rowAsJson!.get("data").getAsJsonObject())
row!.setIsSelected(iff(rowAsJson!.get("selected").getAsString() = "true" , 1 , 0))
event! = new BBjGridWidgetCellEditingEvent()
event!.setRow(row!)
event!.setValue(next!.get("value").getAsString())
event!.setColumn(next!.get("column").getAsString())
#fireEvent(type!, event!)
methodend
method private void handleGridROWEditingEvent(BBjString detail$ , BBjNumber type!)
parser! = new JsonParser()
array! = parser!.parse(detail$).getAsJsonObject().get("0")
next! = array!.iterator().next().getAsJsonObject()
row! = new BBjGridExWidgetRow()
row!.setId(next!.get("id").getAsString())
row!.setChildIndex(next!.get("childIndex").getAsInt())
row!.setParentKey(next!.get("parentKey").getAsString())
row!.setData(next!.get("data").getAsJsonObject())
row!.setIsSelected(iff(next!.get("selected").getAsString() = "true" , 1 , 0))
event! = new BBjGridExWidgetDoubleClickRowEvent()
event!.setRow(row!)
#fireEvent(type!, event!)
methodend
method private void performGridDataUpdate()
if (! #IsReady!) methodret
gson! = new Gson()
if (#RS! <> null()) then
data$=#RS!.toJson()
cdef!= #getAgGridColumnDefinition(0)
else
if (#TREE! <> null()) then
data$=#TREE!.toJson()
cdef!= #getAgGridColumnDefinition(1)
fi
fi
option! = new JsonObject()
option!.addProperty("enableSorting",Boolean.valueOf(1))
option!.addProperty("animateRows",Boolean.valueOf(1))
option!.addProperty("enableColResize",Boolean.valueOf(1))
option!.addProperty("allowContextMenuWithControlKey",Boolean.valueOf(0))
option!.addProperty("enableFilter",Boolean.valueOf(iff(#EnableFilter = 1 , "true" ,"false")))
option!.addProperty("floatingFilter",Boolean.valueOf(iff(#EnableFloatingFilter = 1 , "true" ,"false")))
option!.addProperty("groupSelectsChildren",Boolean.valueOf(iff(#groupSelectsChildren = 1 , "true" ,"false")))
option!.addProperty("__getRowNodeId",#RowNodeId$)
option!.addProperty("__getParentNodeId",#ParentNodeId$)
option!.addProperty("editType",#getEditType())
option!.addProperty("singleClickEdit",#getSingleClickEdit())
option!.addProperty("enableGroupEdit",#getGroupEdit())
option!.addProperty("rowSelection",iff(#MultipleSelection = 1 , "multiple" ,"single"))
option!.addProperty("__enterKeyBehavior",#EnterKeyBehavior$)
option!.add("columnDefs",cdef!)
if (#SelectionMode = BBjGrid.GRID_SELECT_ROW) and #MultipleSelection = 0 then
option!.addProperty("__navigateToNextCell",1)
else
option!.addProperty("__navigateToNextCell",0)
fi
#HTMLView!.executeScript("gw_setData("+data$+","+gson!.toJson(option!)+",'" + #LicenseKey$ + "')")
methodend
method private JsonArray getAgGridColumnDefinition(BBjInt fGroup%)
declare DataRow cd!
cd! = #ColumnDefinition!
if cd! = null() or cd!.getFieldNames().size()=0 then
if #RS! <> null() and #RS!.size()>0 then
cd! = #RS!.get(0)
else
if #TREE! <> null() then
cd! = #TREE!.getFirstRecord()
fi
fi
fi
cdef! = new JsonArray()
first=1
if fGroup%>0 then
node! = new JsonObject()
node!.addProperty("headerName",#GroupColumnLabel$)
node!.addProperty("field","__node__name")
node!.addProperty("cellRenderer","agGroupCellRenderer")
node!.addProperty("pinned","left")
cellRendererParams! = new JsonObject()
cellRendererParams!.addProperty("suppressCount" ,Boolean.valueOf(iff(#GroupChildCount = 1 , "false" ,"true")))
cellRendererParams!.addProperty("checkbox" ,Boolean.valueOf(iff(#showSelectionCheckbox = 1 , "true" ,"false")))
node!.add("cellRendererParams",cellRendererParams!)
cdef!.add(node!)
first=0
fi
if cd! = null() or cd!.getFieldNames().size()=0 then
methodret cdef!
fi
f! = cd!.getFieldNames()
it! = f!.iterator()
while it!.hasNext()
f$=it!.next()
label$=""
label$=cd!.getFieldAttribute(f$,"LABEL",err=*next)
if label$="" then
label$=f$
fi
node! = new JsonObject()
node!.addProperty("headerName",label$)
node!.addProperty("field",f$)
pin$=""
pin$=cd!.getFieldAttribute(f$,"PINNED",err=*next)
if pin$>"" then
node!.addProperty("pinned",pin$)
fi
width$=""
width$=cd!.getFieldAttribute(f$,"WIDTH",err=*next)
if width$>"" then
node!.addProperty("width",num(width$))
fi
editable!= num(cd!.getFieldAttribute(f$,"EDITABLE",err=*next))
if editable! > 0 then
node!.addProperty("editable",1)
else
node!.addProperty("editable",#Editable!)
fi
if first then
node!.addProperty("checkboxSelection",Boolean.valueOf(iff(#showSelectionCheckbox = 1 , "true" ,"false")))
fi
type! = ""
type!= cd!.getFieldAttribute(f$,"TYPE",err=*next)
if type! <> "" then
node!.addProperty("type",type!)
else
switch cd!.getFieldType(f$)
case Types.INTEGER
case Types.DECIMAL
case Types.DOUBLE
case Types.NUMERIC
node!.addProperty("type",#GRID_TYPE_BASIC_NUMBER())
break
case Types.DATE
node!.addProperty("type",#GRID_TYPE_BASIC_DATE())
break
case Types.TIMESTAMP
node!.addProperty("type",#GRID_TYPE_BASIC_TIMESTAMP())
break
case Types.BOOLEAN
node!.addProperty("type",#GRID_TYPE_BASIC_BOOLEAN())
break
case default
node!.addProperty("type",#DefaultType$)
break
swend
fi
bgc$=""
bgc$=cd!.getFieldAttribute(f$,"BGCOLOR",err=*next)
fgc$=""
fgc$=cd!.getFieldAttribute(f$,"FGCOLOR",err=*next)
align$=""
align$=cd!.getFieldAttribute(f$,"ALIGN",err=*next)
f=0
if (bgc$>"" OR fgc$>"" or align$>"") then
cellStyleDefaults! = new JsonObject()
if (fgc$>"") then
cellStyleDefaults!.addProperty("FGCOLOR",fgc$)
f=1
fi
if bgc$>"" then
cellStyleDefaults!.addProperty("BGCOLOR",bgc$)
f=1
fi
if align$>"" then
cellStyleDefaults!.addProperty("ALIGN",align$)
f=1
fi
node!.add("cellStyleDefaults",cellStyleDefaults!)
fi
first = 0
cdef!.add(node!)
wend
methodret cdef!
methodend
rem /**
rem * callback method after initial load
rem * does last initialization work
rem *
rem * @param BBjEvent ev!: the onLoad event
rem */
method public void onLoad(BBjEvent ev!)
#HTMLView!.clearCallback(#HTMLView!.ON_PAGE_LOADED); rem ' only do this once
gridPath$ = iff(LEN(#LicenseKey$) > 0,"BBjGridExWidget/js/dist/ag-grid-enterprise.min.js","BBjGridExWidget/js/dist/ag-grid.min.js")
ch=unt
rem loading the patched ag-grid in BUI until they will have fixed their code for the getDocument method
if INFO(3,6)="5" then
open (ch)gridPath$
read record (ch,siz=5512000)script$
close (ch)
#HTMLView!.injectScript(script$)
#HTMLView!.injectScript(script$,1)
else
open (ch)gridPath$
read record (ch,siz=5512000)script$
close (ch)
#HTMLView!.injectScript(script$,1)
fi
ch=unt
open (ch)"BBjGridExWidget/js/dist/agc-basic-bundle.min.js"
read record (ch,siz=5512000)script$
close (ch)
#HTMLView!.injectScript(script$)
ch=unt
open (ch)"BBjGridExWidget/js/dist/bbj-grid-widget.min.js"
read record (ch,siz=5512000)script$
close (ch)
if INFO(3,6)="5" then
#HTMLView!.injectScript(script$)
#HTMLView!.injectScript(script$,1)
else
p_script! = script$
p_script! = p_script!.replaceAll("\$doc","document")
p_script! = p_script!.replaceAll("\$win","window")
#HTMLView!.injectScript(str(p_script!),1)
#HTMLView!.injectScript(str(p_script!))
fi
#IsReady! = BBjAPI.TRUE
if #RS! <> null() or #TREE! <> null() or #URL$>"" then
#performGridDataUpdate()
fi
it! = #backlog!.iterator()
while it!.hasNext()
s$=it!.next()
#HTMLView!.executeScript(s$)
wend
#backlog! = null()
methodend
rem /**
rem * experimental function that shows the developer console
rem * (only in GUI, for BUI it's a NOOP)
rem */
method public void showDeveloperConsole()
if (info(3,6)<>"5") then
#executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}")
fi
methodend
method private Object executeScript(BBjString s$)
if #IsReady! then
methodret #HTMLView!.executeScript(s$)
else
#backlog!.addItem(s$)
fi
methodret null()
methodend
method private void assertIsEnterprise(BBjString feature$)
if LEN(#LicenseKey$) <= 0 then
throw "(" + feature$ + ") is an ag-grid enterprise feature , please set a licence key to use this feature.", 256
fi
methodend
rem --------------------api methods--------------------------------
rem /**
rem * set the data into the grid
rem * @param ResultSet: the com.basiscomponents.db.ResultSet with the data
rem */
method public void setData( ResultSet rs!)
#RS! = rs!
#TREE! = null()
#URL$=""
#performGridDataUpdate()
methodend
rem /**
rem * set the data into the grid
rem * @param ResultSet: the com.basiscomponents.db.ResultSet with the data
rem * @param BBjString: field used to generate id
rem */
method public void setData( ResultSet rs! ,BBjString RowNodeId$)
#RowNodeId$ = RowNodeId$
#setData(rs!)
methodend
rem /**
rem * set the data into the grid, to create a tree grid
rem * @param DataTree: the com.basiscomponents.db.tree.DataTree with the data
rem * organized in hiearchy of ResultSets
rem * @see Demo/TreeDemo.bbj https://github.com/BasisHub/BBjGridExWidget/blob/master/Demo/TreeDemo.bbj
rem */
method public void setData( DataTree tree!)
#RS! = null()
#TREE! = tree!
#URL$=""
#performGridDataUpdate()
methodend
method public void setData( DataTree rs! ,BBjString RowNodeId$)
#RowNodeId$ = RowNodeId$
#setData(rs!)
methodend
method public void setData( DataTree rs! ,BBjString RowNodeId$ , BBjString ParentNodeId$)
#ParentNodeId$ = ParentNodeId$
#setData(rs! , RowNodeId$)
methodend
rem /**
rem * clear all columns
rem */
method public void clearColumnDefinitions()
#ColumnDefinition! = null()
methodend
rem /**
rem * add a column to the grid
rem * @param BBjString field$: the field name that matches the ResultSet
rem */
method public void addColumn(BBjString Field$)
#addColumn(Field$,Field$,12,0)
methodend
rem /**
rem * add a column to the grid
rem * @param BBjString field$: the field name that matches the ResultSet
rem * @param BBjString label$: the column header
rem */
method public void addColumn(BBjString Field$, BBjString Label$)
#addColumn(Field$,Label$, 12, 0)
methodend
rem /**
rem * add a column to the grid
rem * @param BBjString field$: the field name that matches the ResultSet
rem * @param BBjString label$: the column header
rem * @param BBjNumber Type!: the column Type (java.sql.Types)
rem * @see https://docs.oracle.com/javase/8/docs/api/java/sql/Types.html
rem *
rem */
method public void addColumn(BBjString Field$, BBjString Label$, BBjNumber Type!)
#addColumn(Field$,Label$, Type!, 0)
methodend
rem /**
rem * add a column to the grid
rem * @param BBjString field$: the field name that matches the ResultSet
rem * @param BBjString label$: the column header
rem * @param BBjNumber Type!: the column Type (java.sql.Types)
rem * @param BBjNumber Editable!: 1 = column is editable
rem * @see https://docs.oracle.com/javase/8/docs/api/java/sql/Types.html
rem *
rem */
method public void addColumn(BBjString Field$, BBjString Label$, BBjNumber Type!, BBjNumber Editable!)
if #ColumnDefinition! = null() then
#ColumnDefinition! = new DataRow()
fi
#ColumnDefinition!.setFieldValue(Field$,Type!,null())
#ColumnDefinition!.setFieldAttribute(Field$,"LABEL",Label$)
#ColumnDefinition!.setFieldAttribute(Field$,"EDITABLE",STR(Editable!))
methodend
rem /**
rem * pin a column of the grid to the left or the right margin
rem * @param BBjString field$: the field name of the column
rem * @param BBjString pin$: "right" or "left"
rem *
rem */
method public void pinColumn(BBjString Field$, BBjString pin$)
pin$=cvs(pin$,8)
if pin$="left" or pin$="right" then
#ColumnDefinition!.setFieldAttribute(Field$,"PINNED",pin$,err=*next)
else
#ColumnDefinition!.removeFieldAttribute(Field$,"PINNED",err=*next)
fi
script$="gw_pinColumn('" + Field$ + "','" + pin$ + "');"
#executeScript(script$)
methodend
rem /**
rem * set the grid to scroll horizontally or fit into the client area
rem * @param BBjNumber fit!: 1 = fit all columns into the width
rem *
rem */
method public void setFitToGrid(BBjNumber fit!)
#FitToGrid=fit!
ret! = #executeScript("gw_sizeColumnsToFit("+str(fit!)+")")
methodend
rem /**
rem * set the font color of a column
rem * @param BBjString Field$: the field name of the column