forked from BBj-Plugins/BBjGridExWidget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BBjGridExWidget.bbj
2420 lines (2275 loc) · 81.8 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.JsonPrimitive
use com.google.gson.JsonArray
use java.lang.Integer
use java.util.ArrayList
use java.util.HashMap
use ::BBjWidget/BBjWidget.bbj::BBjWidget
rem /**
rem * A Grid Widget Plugin for BBj
rem */
class public BBjGridExWidget extends BBjWidget
rem /**
rem * A map which keeps tracking selected and deselected rows
rem */
field public HashMap SelectedRowsMap! = new HashMap()
rem /**
rem * Ag Grid enterprise key
rem *
rem * @RequiresRefresh
rem */
field public static BBjString LicenseKey$
rem /**
rem * set the selection mode of the grid
rem *
rem * @see GRID_SELECT_ROW()
rem * @see GRID_SELECT_CELL()
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber SelectionMode! = #GRID_SELECT_ROW()
rem /**
rem * Allow selection of multiple cells or rows
rem * multiple: 1 allows multiple selection, 0 denies
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber MultipleSelection! = 0
rem /**
rem * When true, selection box will be show on the first column
rem * When false, no checkbox will be displayed
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber ShowSelectionCheckbox! = 0
rem /**
rem * When true, selection box will be show on group column
rem * When false, no checkbox will be displayed
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber ShowGroupSelectionCheckbox! = 0
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 *
rem * @RequiresRefresh
rem */
field public BBjNumber GroupSelectsChildren! = 1
rem /**
rem * Enable / Disable cell editing for the whole grid
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * This option can be overridden from the column attributes directly
rem *
rem * ex:
rem *
rem * <code>
rem * dr! = new DataRow()
rem * dr!.setFieldAttribute("DOUBLE","EDITABLE","1")
rem * </code>
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber Editable! = 0
rem /**
rem * Enable / Disable cell editing for the whole grid
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber SingleClickEdit! = 0
rem /**
rem * Define the edit type
rem *
rem * Set the default cell editor type
rem * default to GRID_TYPE_BASIC_STRING
rem *
rem * This option is used only in case the grid failed to detect the field's 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 *
rem * @RequiresRefresh
rem */
field public BBjString DefaultType$ = #GRID_TYPE_BASIC_STRING()
rem /**
rem * Define the edit behavior
rem *
rem * @see BBjGridExWidget.GRID_EDITTYPE_ROW
rem * @see BBjGridExWidget.GRID_EDITTYPE_CELL
rem *
rem * @RequiresRefresh
rem */
field public BBjString EditType$ = #GRID_EDITTYPE_CELL()
rem /**
rem * Set to true to enable Group Editing, otherwise by default, row groups cannot be edited.
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber GroupEdit! = 0
rem /**
rem * Enter Key Behavior
rem *
rem * @see BBjGridExWidget.GRID_ENTER_NEXT_CELL
rem * @see BBjGridExWidget.GRID_ENTER_STOP_EDITING
rem *
rem * @RequiresRefresh
rem */
field public BBjString EnterKeyBehavior$ = #GRID_ENTER_STOP_EDITING()
rem /**
rem * Allow filters in the grid
rem * 1 = enable
rem * 0 = disable
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber EnableFilter! = 0
rem /**
rem * Allow floating filters in the grid
rem * 1 = enable
rem * 0 = disable
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber EnableFloatingFilter! = 0
rem /**
rem * set the label for the group column if the grid is a tree-grid
rem * defaults to "Group"
rem *
rem * @RequiresRefresh
rem */
field public BBjString GroupColumnLabel$ = "Group"
rem /**
rem * Set the default grouping footer getter expression
rem *
rem * @RequiresRefresh
rem */
field public BBjString GroupColumnFooterGetter$ = "'Total' + x "
rem /**
rem * Enable/disable Suppress the number of items in a group
rem * 1 = enable
rem * 0 = disable
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber ShowGroupChildCount! = 0
rem /**
rem * Enable/disable aggregate by column via the GUI.
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * This option can be overridden from the column attributes directly
rem *
rem * ex:
rem *
rem * <code>
rem * dr! = new DataRow()
rem * dr!.setFieldAttribute("DOUBLE","ENABLE_VALUE","1")
rem * </code>
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber EnableValue! = 1
rem /**
rem * Enable/disable row group by column via the GUI
rem *
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * This option can be overridden from the column attributes directly
rem *
rem * ex:
rem *
rem * <code>
rem * dr! = new DataRow()
rem * dr!.setFieldAttribute("DOUBLE","ENABLE_ROW_GROUP","1")
rem * </code>
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber EnableRowGroup! = 1
rem /**
rem * Enable/disable pivot by column via the GUI.
rem *
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * This option can be overridden from the column attributes directly
rem *
rem * ex:
rem *
rem * <code>
rem * dr! = new DataRow()
rem * dr!.setFieldAttribute("DOUBLE","ENABLE_PIVOT","1")
rem * </code>
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber EnablePivot! = 0
rem /**
rem * Suppress Row Groups section.
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber SuppressRowGroups! = 0
rem /**
rem * suppress Values section
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber SuppressValues! = 1
rem /**
rem * suppress Column Labels (Pivot) section.
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber SuppressPivots! = 0
rem /**
rem * suppress Pivot Mode section.
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber SuppressPivotMode! = 0
rem /**
rem * suppress Side Buttons section.
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber SuppressSideButtons! = 0
rem /**
rem * suppress Column Filter section.
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber SuppressColumnFilter! = 0
rem /**
rem * suppress Select / Un-select all widget.
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber SuppressColumnSelectAll! = 0
rem /**
rem * suppress Expand / Collapse all widget.
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber SuppressColumnExpandAll! = 0
rem /**
rem * Enable/disable changes to group, pivot or values through the GUI
rem * This is useful if you want to show the user the group, pivot and values panel, so they can see what columns are used,
rem * but prevent them from making changes to the selection.
rem *
rem * 1 = enable editing
rem * 0 = disable edition
rem *
rem * @Enterprise
rem */
field public BBjNumber FunctionsReadOnly! = 0
rem /**
rem * Set group panel visiblity
rem *
rem * @see BBjGridExWidget.GRID_GROUPPANEL_SHOW_HIDDEN
rem * @see BBjGridExWidget.GRID_GROUPPANEL_SHOW_VISIBLE
rem * @see BBjGridExWidget.GRID_GROUPPANEL_SHOW_ONGROUPING
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjString RowGroupPanelShow$ = #GRID_GROUPPANEL_SHOW_ONGROUPING()
rem /**
rem * If using auto column, set to true to have each group in its own column separate column.
rem * eg if group by Country then Year, two auto columns will be created, one for country and
rem * one for year
rem *
rem * 1 = enable
rem * 0 = disable
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber GroupMultiAutoColumn! = 0
rem /**
rem * If grouping, set to true or false (default is false). If true, a group row will span all columns
rem * across the entire width of the table. If false, the cells will be rendered as normal and you will
rem * have the opportunity to include a grouping column (normally the first on the left) to show the
rem * group.
rem *
rem * 1 = enable
rem * 0 = disable
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber GroupUseEntireRow! = 0
rem /**
rem * If true then includes a 'grand' total across all groups
rem *
rem * 1 = enable
rem * 0 = disable
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber GroupIncludeFooter! = 0
rem /**
rem * If true then includes group totals within each group level
rem *
rem * 1 = enable
rem * 0 = disable
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjNumber GroupIncludeTotalFooter! = 0
rem /**
rem * The grid context menu
rem *
rem * @RequiresRefresh
rem * @Enterprise
rem */
field public BBjGridContextMenu ContextMenu! = new BBjGridDefaultContextMenu()
field private BBjString ID$
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 RowNodeId$ = "__ROW_INDEX"
field private BBjString ParentNodeId$
field private DataRow ColumnDefinition!
field public DataRow AttributesRecord!
field private DataRow AdditionalAttributes! = new DataRow()
field private BBjNumber Editing! = 0
field private HashMap ColumnGroups! = new HashMap()
field public static BBjNumber Debug=0
field private BBjString DataFingerprint$
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!, BBjNumber id!, BBjNumber x!, BBjNumber y!, BBjNumber w!, BBjNumber h!)
#super!.create(wnd!,id!,x!,y!,w!,h!)
methodend
rem /**
rem * The constructor that creates the widget in the ChildWindow
rem * @param BBjChildWindow wnd!: the child window in which to create the BBjGridExWidget
rem */
method public BBjGridExWidget(BBjChildWindow wnd!)
#super!.create(wnd!)
methodend
rem /**
rem * @Override
rem * This method is called whenever the widget needs to be rendered
rem * @param Boolean f_init!: if TRUE trem /**
rem *
rem * 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!
#ID$ = java.util.UUID.randomUUID().toString()
if (f_init!) then
lic!=System.getProperty("bbjgridexwidget.license")
if lic! <> null() and str(lic!) <> "" then
#setLicenseKey(lic!)
fi
html$="<html><body><script></script><div id='eventTransporterDiv' onClick='window.basisDispatchCustomEvent(event, event.payload)'></div><div id='" + str(#ID$) + "' style=""height: 100%"" class=""ag-theme-balham""></div></body></html>"
if (info(3,6)<>"5" and #Debug>0) then
call "BBjGridExWidget/util/EnableDebugger.bbj"
fi
htmlview! = #getCanvas().addHtmlView(101,0,0,#getCanvas().getWidth(),#getCanvas().getHeight(),"")
if (info(3,6)<>"5" and #Debug>0) then
url$ = htmlview!.getAttribute("remoteDebuggingURL")
if url$>"" then
BBjAPI().getThinClient().browse(url$)
fi
fi
REM if (htmlview!.getClientType() <> "Chromium" AND INFO(3,6)<>"5")
REM htmlview!.setText("<html><center>Error: Need the Chromium Engine in BBj 18.10 or later. Please check your BBj SAM coverage!</center></html>")
REM else
htmlview!.setCallback(BBjAPI.ON_PAGE_LOADED,#this!,"onLoad")
htmlview!.setCallback(BBjAPI.ON_NATIVE_JAVASCRIPT,#this!,"onNativeEvent")
htmlview!.setOpaque(0)
htmlview!.setText(html$)
REM fi
#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
method protected void injectScript(BBjString script$)
bui = INFO(3,6)="5"
if bui then #HTMLView!.injectScript(script$) else #HTMLView!.injectScript(script$ , 1) FI
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!)
rem ' only do this once
#HTMLView!.clearCallback(#HTMLView!.ON_PAGE_LOADED)
ch=unt
distBase$ = "BBjGridExWidget/js/dist"
rem include the grid
gridPath$ = iff(LEN(#LicenseKey$) > 0,distBase$ + "/ag-grid-enterprise.min.noStyle.js",distBase$ +"/ag-grid.min.noStyle.js")
open (ch)gridPath$
read record (ch,siz=5512000)script$
close (ch)
#injectScript(script$)
rem include locale files
locale! = stbl("!LOCALE")
locale$ = locale!.replaceAll("_","-")
dateJsLocalePath$ = distBase$ + "/../vendor/Datejs/build/date-" + locale$ + ".js"
isLocale = 0
ch=unt
open (ch,err=*next)dateJsLocalePath$;isLocale=1
if isLocale = 0 then
close (ch)
dateJsLocalePath$ = distBase$ + "/i18n/Datejs/" + locale$ + ".js"
open (ch,err=*next)dateJsLocalePath$
fi
read record (ch,siz=5512000)script$
close (ch)
#injectScript(script$)
ch=unt
open (ch) distBase$ + "/bbj-grid-widget.min.js"
read record (ch,siz=5512000)script$
close (ch)
#injectScript(script$)
#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 * 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 */
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$, "single")
break
case "grid-row-doubleclick"
#handleGridSelectRowEvent(detail$,"double")
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 "cellClicked"
#handleGridCellEditingEvent(detail$,#ON_GRID_CELL_CLICK())
break
case "cellDoubleClicked"
#handleGridCellEditingEvent(detail$,#ON_GRID_CELL_DOUBLE_CLICK())
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
case "contextmenu"
#handleGridContextmenuEvent(detail$)
break
swend
methodend
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!
if #AttributesRecord! <> NULL() AND rs! <> NULL() AND rs!.size() >0 then
rem TODO: use the new method of components as soon as implemented
rem https://github.com/BasisHub/components/issues/87
r1! = rs!.getItem(0)
ar! = #AttributesRecord!
it! = r1!.getFieldNames().iterator()
while it!.hasNext()
f$ = it!.next()
if ar!.contains(f$) then
r1!.setFieldAttributes(f$,ar!.getFieldAttributes(f$))
fi
wend
fi
if #ColumnDefinition! <> NULL() AND rs! <> NULL() AND rs!.size() >0 then
r1! = rs!.getItem(0)
ar! = #ColumnDefinition!
it! = r1!.getFieldNames().iterator()
while it!.hasNext()
f$ = it!.next()
if ar!.contains(f$) then
r1!.setFieldAttributes(f$,ar!.getFieldAttributes(f$))
fi
wend
fi
if rs! <> NULL() AND rs!.size()>0 then
it! = #AdditionalAttributes!.getFieldNames().iterator()
r1! = rs!.getItem(0)
while it!.hasNext()
f$=it!.next()
if r1!.contains(f$) then
r1!.setFieldAttributes(f$,#AdditionalAttributes!.getFieldAttributes(f$))
fi
wend
fi
rem if the data fed to the grid is the same as before, it's an update.
rem In this case we want to retain the setting of the columns
rem and the order and sizes
if (rs!.size() >0) then
r1! = rs!.getItem(0)
datafingerprint$ = r1!.getFieldNames().toString()
keep=0
if (datafingerprint$ = #DataFingerprint$) then
tmpstate!=#getColumnState()
fi
fi
#RS!.createIndex()
#TREE! = null()
#URL$=""
#SelectedRowsMap!.clear()
#performGridDataUpdate()
if (rs!.size() >0) then
if tmpstate!<>null() then
#setColumnState(tmpstate!)
fi
#DataFingerprint$ = datafingerprint$
fi
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 * Set new rows into the grid
rem *
rem * @param ResultSet: the com.basiscomponents.db.ResultSet with the data
rem */
method public void setRowsData(ResultSet rs!)
#RS! = rs!
if #AttributesRecord! <> NULL() AND rs! <> NULL() AND rs!.size() >0 then
rem TODO: use the new method of components as soon as implemented
rem https://github.com/BasisHub/components/issues/87
r1! = rs!.getItem(0)
ar! = #AttributesRecord!
it! = r1!.getFieldNames().iterator()
while it!.hasNext()
f$ = it!.next()
if ar!.contains(f$) then
r1!.setFieldAttributes(f$,ar!.getFieldAttributes(f$))
fi
wend
fi
if #ColumnDefinition! <> NULL() AND rs! <> NULL() AND rs!.size() >0 then
r1! = rs!.getItem(0)
ar! = #ColumnDefinition!
it! = r1!.getFieldNames().iterator()
while it!.hasNext()
f$ = it!.next()
if ar!.contains(f$) then
r1!.setFieldAttributes(f$,ar!.getFieldAttributes(f$))
fi
wend
fi
#RS!.createIndex()
#TREE! = null()
#URL$=""
#SelectedRowsMap!.clear()
data$=#RS!.toJson(BBjAPI.TRUE,"__ROW_INDEX")
#executeScript("gw_setRowsData(" + data$+ ")")
methodend
rem /**
rem * Update row data
rem *
rem * @param BBjNumber: row index
rem * @param DataRow: DataRow object which contains the update
rem */
method public void setRowData(BBjNumber index!,DataRow row!)
if #RS!.count() <> 0 then
#RS!.set(index!,row!)
parser! = new JsonParser()
#executeScript("gw_setRowData(" + parser!.parse(row!.toJson("__ROW_INDEX")).getAsJsonArray().get(0).toString() +")")
fi
methodend
rem /**
rem * Add new row
rem *
rem * @param BBjNumber: index insert index
rem * @param DataRow: DataRow object which contains the update
rem */
method public void addRow(BBjNumber index!,DataRow row!)
#RS!.add(index! , row!)
parser! = new JsonParser()
#executeScript("gw_addRows("+ str(index!) +",[" + parser!.parse(row!.toJson("__ROW_INDEX")).getAsJsonArray().get(0).toString() +"])")
methodend
rem /**
rem * Add new row
rem *
rem * @param DataRow: DataRow object which contains the update
rem */
method public void addRow(DataRow row!)
#RS!.add(row!)
parser! = new JsonParser()
#executeScript("gw_addRows(null,[" + parser!.parse(row!.toJson("__ROW_INDEX")).getAsJsonArray().get(0).toString() +"])")
methodend
rem /**
rem * Remove row from grid by index
rem *
rem * @param BBjNumber: row index
rem */
method public void removeRow(BBjNumber index!)
if #RS!.count() <> 0 then
if #RowNodeId$ <> "__ROW_INDEX" then
value! = #RS!.getItem(index!).getFieldAsString(#RowNodeId$)
else
value! = #RS!.getItem(index!).getRowKey()
fi
#RS!.remove(index!)
#executeScript("gw_removeRows(['" + str(value!) +"'])")
rem print #RS!.getItem(index!)
rem escape
fi
methodend
rem /**
rem * Clear row data (Empty the grid )
rem */
method public void clearRowsData()
#RS! = new ResultSet()
#RS!.createIndex()
#TREE! = null()
#URL$=""
#SelectedRowsMap!.clear()
#executeScript("gw_setRowsData([])")
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 * 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 * clear all columns
rem */
method public void clearColumnDefinitions()
#ColumnDefinition! = null()
methodend
rem /**
rem * set the font color of a column
rem *
rem * @param BBjString Field$: the field name of the column
rem * @param BBjColor color!: the color for the column
rem *
rem * @RequiresRefresh
rem */
method public void setColumnForeColor(BBjString Field$,BBjColor color!)
#ColumnDefinition!.setFieldAttribute(Field$,"FGCOLOR","#"+hta(chr(color!.getRed()))+hta(chr(color!.getGreen()))+hta(chr(color!.getBlue())),err=*next)
methodend
rem /**
rem * set the background color of a column
rem *
rem * @param BBjString Field$: the field name of the column
rem * @param BBjColor color!: the color for the column
rem *
rem * @RequiresRefresh
rem */
method public void setColumnBackColor(BBjString Field$,BBjColor color!)
#ColumnDefinition!.setFieldAttribute(Field$,"BGCOLOR","#"+hta(chr(color!.getRed()))+hta(chr(color!.getGreen()))+hta(chr(color!.getBlue())),err=*next)
methodend
rem /**
rem * set the mask of a column
rem *
rem * @param BBjString Field$: the field name of the column
rem * @param BBjString mask$: the (date or numeric) mask, BBj style, for display and editing
rem *
rem * @RequiresRefresh
rem */
method public void setColumnMask(BBjString Field$, BBjString mask$)
#ColumnDefinition!.setFieldAttribute(Field$,"MASK",mask$)
methodend
rem /**
rem * set the alignment of a column
rem * @param BBjString Field$: the field name of the column
rem * @param BBjNumber align: the column alignment
rem *
rem * valid alignments:
rem *
rem * @see GRID_ALIGN_LEFT()
rem * @see GRID_ALIGN_CENTER()
rem * @see GRID_ALIGN_RIGHT()
rem *
rem * @RequiresRefresh
rem */
method public void setColumnAlignment(BBjString Field$, BBjNumber align)
switch align
case BBjGrid.GRID_ALIGN_LEFT
#ColumnDefinition!.setFieldAttribute(Field$,"ALIGN","left",err=*next)
break
case BBjGrid.GRID_ALIGN_CENTER
#ColumnDefinition!.setFieldAttribute(Field$,"ALIGN","center",err=*next)
break
case BBjGrid.GRID_ALIGN_RIGHT
#ColumnDefinition!.setFieldAttribute(Field$,"ALIGN","right",err=*next)
break
swend
methodend
rem /**
rem * Apply columns state
rem *
rem * @param BBjGridExWidgetColumnState state! : the state object
rem */
method public void setColumnState(BBjGridExWidgetColumnState state!)
json_state$ = state!.getString()
#executeScript("gw_setState("+json_state$+")")
methodend
rem /**
rem * Get Column state
rem *
rem * @returns BBjGridExWidgetColumnState
rem */
method public BBjGridExWidgetColumnState getColumnState()
state! = new BBjGridExWidgetColumnState()
json_string$ = str(#HTMLView!.executeScript("gw_getState()"))
state!.setString(json_string$)
methodret state!
methodend
rem /**
rem * Add Style block
rem *
rem * @param selector$ : Css Selector
rem * @param rules! : Css Rules object as json object
rem */
method public void addStyle(BBjString selector$ , JsonObject rules! )
#executeScript("gw_setStyle('" + selector$ + "','" + rules!.toString() + "')")
methodend
rem /**
rem * Add Style block
rem *
rem * @param selector$ : Css Selector
rem * @param rules! : Css Rules object as string
rem */
method public void addStyle(BBjString selector$ , BBjString rules! )
#executeScript("gw_setStyle('" + selector$ + "','" + rules! + "')")
methodend
rem /**
rem * Remove Style Block
rem *
rem * @param selector$ : Css Selector
rem */
method public void removeStyle(BBjString selector$)
#executeScript("gw_removeStyle('" + selector$ + "')")
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 *
rem * @param BBJNumber x!: 1 enable , 0 disable
rem *
rem * @RequiresRefresh
rem */
method public void setGroupSelectsChildren(BBjNumber x!)
rem this only makes sense with mutli-selection switched on!
#setMultipleSelection(1)
#GroupSelectsChildren!=x!
methodend
rem /**
rem * Set the grid theme
rem *
rem * @param BBjString theme$
rem *
rem * @see BBjGridExWidget.getThemes()
rem */
method public void setTheme(BBjString theme$)
if pos(theme$="dark#fresh#blue#bootstrap#material#balham#balham-dark")>0 then
if info(3,6)="5" then
s$="$doc.getElementById('grid').className='ag-theme-"+theme$+"';"
else
s$="document.getElementById('grid').className='ag-theme-"+theme$+"';"
FI
#executeScript(s$)
FI
methodend
rem /**
rem * Get themes
rem *
rem * Get the grid supported themes
rem */
method public BBjVector getThemes()
v! = new BBjVector()
v!.addItem("balham")
v!.addItem("balham-dark")
v!.addItem("dark")
v!.addItem("fresh")
v!.addItem("blue")
v!.addItem("bootstrap")
v!.addItem("material")
methodret v!
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!)
#deselectAll()
script$="gw_selectAll(" + str(x!) + ");"
#executeScript(script$)
methodend
rem /**
rem * deselect all rows