-
Notifications
You must be signed in to change notification settings - Fork 7
/
Datatypes.bbj
153 lines (133 loc) · 6.2 KB
/
Datatypes.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
rem /**
rem * This file is part of the BBjGridExWidget plugin.
rem * (c) Basis Europe <eu@basis.com>
rem *
rem * For the full copyright and license information, please view the LICENSE
rem * file that was distributed with this source code.
rem */
use ::BBjGridExWidget/BBjGridExWidget.bbj::BBjGridExWidget
use ::BBjGridExWidget/GxRenderers.bbj::GxRendererBoolean
use ::BBjGridExWidget/GxRenderers.bbj::GxRendererImageRenderer
use com.basiscomponents.db.ResultSet
use com.basiscomponents.db.DataRow
use com.google.gson.JsonObject
use java.sql.Types
? 'HIDE'
declare auto BBjTopLevelWindow wnd!
declare BBjGridExWidget grid!
wnd! = BBjAPI().openSysGui("X0").addWindow(10,10,800,600,"Data Types Demo")
wnd! .setCallback(BBjAPI.ON_CLOSE,"byebye")
wnd! .setCallback(BBjAPI.ON_RESIZE,"resize")
REM init the grid
grid! = new BBjGridExWidget(wnd!,100,0,0,800,600)
grid!.getOptions().setEnableFilter(1)
grid!.getOptions().getDefaultColumnDefinition().setFloatingFilter(1)
rem /**
rem * @see http://documentation.basis.com/BASISHelp/WebHelp/commands2/opts_variable.htm
rem * Set the default group and decimal separators for numbers masking.<br>
rem *
rem * The grid will pick up these settings and use them by default for numbers masking.
rem * You can also override these settings at the column level manually.
rem */
a$=opts
a$(3,1)=ior(a$(3,1),$02$)
a$(5,1)=","; rem set numbers group separator
a$(6,1)="."; rem set numbers decimal separator
setopts A$
gosub main
process_events
rem /**
rem * Retrieve the data from the database and configure the grid.
rem *
rem * The demo shows how grid!.setData() sets up the column components according to it type.
rem * For example, the DOUBLE column's type is double, this will enable the GxExpressionNumbersFormatter
rem * by default. Using the formatter you can configure the mask to use or define the group and the decimal
rem * separators for numbers.
rem * The same applies for other types, for example, the boolean columns will be configured automatically to have the
rem * GxRendererBoolean, where you can configure how true/false will be rendered
rem * inside the cell (switch, numbers, custom html strings, ...).
rem *
rem * If for some reason the default configured components don't meet your app needs, then you can configure them manually
rem * by column.
rem */
main:
declare ResultSet rs!
rs! = new ResultSet()
REM We generate random data rows and fill the ResultSet.
REM Each column has a supported SQL type.
REM @see https://docs.oracle.com/javase/8/docs/api/java/sql/Types.html
i=1
x=1234
for j=1 to 2
dr! = new DataRow()
dr!.setFieldValue("INTEGER",java.sql.Types.INTEGER,i)
dr!.setFieldValue("ICON",java.sql.Types.VARCHAR,"ID_"+STR(i))
dr!.setFieldValue("IMAGELIST",java.sql.Types.VARCHAR,STR(i-1))
dr!.setFieldValue("DOUBLE",java.sql.Types.DOUBLE,x)
dr!.setFieldValue("BOOLEAN 1",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("BOOLEAN 2",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("BOOLEAN 3",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("DATE",java.sql.Types.DATE,"1979-08-03")
dr!.setFieldValue("TIMESTAMP",java.sql.Types.TIMESTAMP,"1979-08-03 12:22:13.010")
rem in older version of basis components time was not supported
dr!.setFieldValue("TIME",java.sql.Types.TIME,"14:00:00")
rs!.addItem(dr!)
i = i+1
x = x*-i
dr! = new DataRow()
dr!.setFieldValue("INTEGER",java.sql.Types.INTEGER,i)
dr!.setFieldValue("ICON",java.sql.Types.VARCHAR,"ID_"+STR(i))
dr!.setFieldValue("IMAGELIST",java.sql.Types.VARCHAR,STR(i-1))
dr!.setFieldValue("DOUBLE",java.sql.Types.DOUBLE,x)
dr!.setFieldValue("BOOLEAN 1",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("BOOLEAN 2",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("BOOLEAN 3",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("DATE",java.sql.Types.DATE,"2020-03-03")
dr!.setFieldValue("TIMESTAMP",java.sql.Types.TIMESTAMP,"2020-03-03 13:00:00")
rem in older version of basis components time was not supported
dr!.setFieldValue("TIME",java.sql.Types.TIME,"13:00:00")
rs!.addItem(dr!)
i=i+1
x=x*-i
next
grid!.setData(rs!)
iconImage! = BBjGridExWidget.imageToBase64("BBjGridExWidget/Demo/assets/images/sampleicon.png")
spriteImage! = BBjAPI().getSysGui().getImageManager().loadImageFromFile("BBjGridExWidget/Demo/assets/images/imagelist.png")
jsonIcons! = new JsonObject()
jsonIcons! .addProperty("ID_1","https://raw.githubusercontent.com/google/material-design-icons/master/notification/1x_web/ic_airline_seat_individual_suite_black_36dp.png")
jsonIcons! .addProperty("ID_2","https://raw.githubusercontent.com/google/material-design-icons/master/notification/1x_web/ic_confirmation_number_black_36dp.png")
jsonIcons! .addProperty("ID_3","https://raw.githubusercontent.com/google/material-design-icons/master/notification/1x_web/ic_drive_eta_black_36dp.png")
jsonIcons! .addProperty("ID_4", iconImage!)
icon! = grid!.getColumn("ICON")
imageList! = grid!.getColumn("IMAGELIST")
double! = grid!.getColumn("DOUBLE")
boolean1! = grid!.getColumn("BOOLEAN 1")
boolean2! = grid!.getColumn("BOOLEAN 2")
boolean3! = grid!.getColumn("BOOLEAN 3")
date! = grid!.getColumn("DATE")
timestamp! = grid!.getColumn("TIMESTAMP")
time! = grid!.getColumn("TIME")
double!.getValueFormatterExpression().setMask("##,##0.00-")
boolean2!.getCellRenderer().setTrueValue(GxRendererBoolean.SWITCH_RENDERER())
boolean2!.getCellRenderer().setFalseValue(GxRendererBoolean.SWITCH_RENDERER())
boolean3!.getCellRenderer().setTrueValue(String.format("<img src='%s' height='40px' />" , iconImage!))
boolean3!.getCellRenderer().setFalseValue("NOPE!")
icon!.setCellRenderer(new GxRendererImageRenderer(jsonIcons!))
grid!.setColumnImageList(imageList!.getField(),spriteImage!)
grid!.setRowHeight(2 , 50)
return
rem /**
rem * Listen for the BBjTopLevelWindow resize event and
rem * resize the grid to fill the available space.
rem */
resize:
ev! = BBjAPI().getLastEvent()
w=ev!.getWidth()
h=ev!.getHeight()
grid!.setSize(w,h)
return
rem /**
rem * Close the demo
rem */
byebye:
bye