-
Notifications
You must be signed in to change notification settings - Fork 7
/
GxRenderers.bbj
317 lines (298 loc) · 10.2 KB
/
GxRenderers.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
rem /**
rem * The package contains the classes of all supported CellRenderer components
rem */
rem package GxRenderers
rem /**
rem * This file is part of the BBjGridExWidget plugin.
rem * (c) Basis Europe <eu@basis.cloud>
rem *
rem * For the full copyright and license information, please view the LICENSE
rem * file that was distributed with this source code.
rem */
use java.util.HashSet
use com.google.gson.Gson
use com.google.gson.JsonObject
use com.google.gson.JsonArray
use ::BBjGridExWidget/GxExpressions.bbj::GxExpressionInterface
use ::BBjGridExWidget/GxExpressions.bbj::GxExpression
use ::BBjGridExWidget/GxOptions.bbj::GxOptionsBoolean
REM /**
REM * GxRendererInterface
REM *
REM * @author Hyyan Abo Fakher
REM */
interface public GxRendererInterface
rem /**
rem * A constant which holds the client renderer real name
rem */
method public static BBjString getCellRendererName()
rem /**
rem * Convert the renderer definition to Json Object
rem *
rem * @return JsonObject The renderer as JsonObject
rem */
method public JsonObject getAsJsonObject()
rem /**
rem * Compare two cell renderers
rem *
rem * @param cellRenderer! - Another cell renderer instance to compare with
rem *
rem * @return bool - true when they are equal , false otherwise
rem */
method public boolean equals(GxRendererInterface cellRenderer!)
interfaceend
rem /**
rem * Compare two cell renderers components
rem *
rem * @author Hyyan Abo Fakher
rem */
class public GxCellRendererComparator
rem /**
rem * Compare two cell renderers
rem *
rem * @param one! - First cell renderer instance
rem * @param two! - Second cell renderer instance
rem *
rem * @return boolean true when they are equal , false otherwise
rem */
method public static boolean compare(GxRendererInterface one! , GxRendererInterface two!)
if(one!.getCellRendererName() <> two!.getCellRendererName())
methodret BBjAPI.FALSE
FI
methodret one!.getAsJsonObject().equals(two!.getAsJsonObject())
methodend
classend
rem /**
rem * Abstract implementation for GxRendererInterface
rem *
rem * @author Hyyan Abo Fakher
rem */
class public GxRendererAbstract implements GxRendererInterface
rem /**
rem * {@inheritDoc}
rem */
method public boolean equals(GxRendererInterface cellRenderer!)
methodret GxCellRendererComparator.compare(#this!,cellRenderer!)
methodend
classend
rem /**
rem * The class represents a boolean cell renderer
rem *
REM * @author Hyyan Abo Fakher
rem */
class public GxRendererBoolean extends GxOptionsBoolean implements GxRendererInterface
rem /**
rem * The value to use when when the component needs to render true values.
rem * in case it is null() then we use the first item in PossibleTrueValues!
rem */
field public BBjString TrueValue! = null()
rem /**
rem * The value to use when when the component needs to render false values.
rem * in case it is null() then we use the first item in PossibleFalseValues!
rem */
field public BBjString FalseValue! = null()
rem /**
rem * A special html string which uses the switch button to render true/false values
rem */
method public static BBjString SWITCH_RENDERER()
methodret "switch"
methodend
rem /**
rem * {@inheritDoc}
rem */
method public static BBjString getCellRendererName()
methodret "BooleanRenderer"
methodend
rem /**
rem * {@inheritDoc}
rem */
method public JsonObject getAsJsonObject()
declare JsonObject json!
json! = #super!.getAsJsonObject()
json!.addProperty("booleanTrueRenderValue",#getTrueValue(), err=*next)
json!.addProperty("booleanFalseRenderValue",#getFalseValue(), err=*next)
methodret json!
methodend
rem /**
rem * {@inheritDoc}
rem */
method public boolean equals(GxRendererInterface cellRenderer!)
methodret GxCellRendererComparator.compare(#this!,cellRenderer!)
methodend
classend
rem /**
rem * The class can render a custom html using lodash string templates.
rem *
rem * Inside the template you will have access to the <i>params</i> object
rem * which contains value, valueFormatted, ...
rem *
rem * Use This render if you want to render the data with a custom html.
rem *
rem * @see <a href="https://lodash.com/docs/4.17.15#template">Lodash Templates</a>
rem *
REM * @author Hyyan Abo Fakher
rem */
class public GxRendererCustomHTML extends GxRendererAbstract
rem /**
rem * String template which will be compiled in the client.<br>
rem * <pre>
rem * <code>
rem * <%= '<strong style=\'color:red\'>' + (params.valueFormatted || params.value) + '</strong>' %>
rem * </code>
rem * </pre>
rem */
field public BBjString Template! = null()
rem /**
rem * {@inheritDoc}
rem */
method public static BBjString getCellRendererName()
methodret "TemplateRenderer"
methodend
rem /**
rem * Construct new GxRendererCustomHTML
rem *
rem * @param BBjString template! The string template
rem *
rem * i.e
rem * <pre>
rem * <code>
rem * <%= '<strong style=\'color:red\'>' + (params.valueFormatted || '') + '</strong>' %>
rem * </code>
rem * </pre>
rem */
method public GxRendererCustomHTML(BBjString template!)
#Template! = template!
methodend
rem /**
rem * {@inheritDoc}
rem */
method public JsonObject getAsJsonObject()
declare JsonObject json!
json! = new JsonObject()
json!.addProperty("renderTemplate" , #getTemplate(),err=*next)
methodret json!
methodend
classend
rem /**
rem * The renderer can be used to display a list of images based on the cells values using a json object
rem *
REM * @author Hyyan Abo Fakher
rem */
class public GxRendererImageRenderer extends GxRendererAbstract
rem /**
rem * The image's width
rem */
field public BBjString Width! = null()
rem /**
rem * The image's height
rem */
field public BBjString Height! = null()
rem /**
rem * A json object
rem */
field public JsonObject List! = new JsonObject()
rem /**
rem * {@inheritDoc}
rem */
method public static BBjString getCellRendererName()
methodret "ImageRenderer"
methodend
rem /**
rem * Construct new GxRendererImageRenderer
rem *
rem * @param JsonObject list! The images list
rem */
method public GxRendererImageRenderer(JsonObject list!)
#List! = list!
methodend
rem /**
rem * {@inheritDoc}
rem */
method public JsonObject getAsJsonObject()
declare JsonObject json!
json! = new JsonObject()
json!.addProperty("imageRendererWidth" , #getWidth(),err=*next)
json!.addProperty("imageRendererHeight" , #getHeight(),err=*next)
json!. add("imageRendererList" , #getList(),err=*next)
methodret json!
methodend
classend
rem /**
rem * If you are grouping in the grid, then you will need to provide a group cell renderer as the group cell renderer is what provides the user with the expand and collapse functionality.
rem *
REM * @author Hyyan Abo Fakher
rem */
class public GxRendererGroupCellRenderer extends GxRendererAbstract
rem /**
rem * When true show row counts, hide otherwise
rem */
field public BBjNumber SuppressCount! = null()
rem /**
rem * When true disable double-click for expand, enable otherwise
rem */
field public BBjNumber SuppressDoubleClickExpand! = null()
rem /**
rem * When true enable checkbox selection, disable otherwise
rem */
field public BBjNumber Checkbox! = null()
rem /**
rem * Provide an inner renderer
rem */
field public GxRendererInterface InnerRenderer! = null()
rem /**
rem * Provide a footer value getter expression
rem */
field public GxExpressionInterface FooterValueGetterExpression! = null()
rem /**
rem * Construct new GxRendererGroupCellRenderer
rem *
rem * @param GxExpressionInterface footerValueGetterExpression! an expression
rem */
method public GxRendererGroupCellRenderer(GxExpressionInterface footerValueGetterExpression!)
#FooterValueGetterExpression! = footerValueGetterExpression!
methodend
rem /**
rem * Construct new GxRendererGroupCellRenderer
rem *
rem * @param BBjString footerValueGetterExpression! an expression
rem */
method public GxRendererGroupCellRenderer(BBjString footerValueGetterExpression!)
#setFooterValueGetterExpression(footerValueGetterExpression!)
methodend
rem /**
rem * Create a GxExpression from string and set it a footer value getter
rem *
rem * @param BBjString expression! Javascript expression
rem */
method public void setFooterValueGetterExpression(BBjString expression!)
#FooterValueGetterExpression! = new GxExpression(expression!)
methodend
rem /**
rem * {@inheritDoc}
rem */
method public static BBjString getCellRendererName()
methodret "agGroupCellRenderer"
methodend
rem /**
rem * {@inheritDoc}
rem */
method public JsonObject getAsJsonObject()
declare JsonObject json!
json! = new JsonObject()
json!.addProperty("suppressCount" , #getSuppressCount().booleanValue(),err=*next)
json!.addProperty("suppressDoubleClickExpand" , #getSuppressDoubleClickExpand().booleanValue(),err=*next)
json!.addProperty("checkbox" , #getCheckbox().booleanValue(),err=*next)
json!.addProperty("footerValueGetter" , #getFooterValueGetterExpression().toString(),err=*next)
if(#getInnerRenderer() <> null()) then
json!.addProperty("innerRenderer" , #getInnerRenderer().getCellRendererName(),err=*next)
declare JsonObject innerJson!
innerJson! = #getInnerRenderer().getAsJsonObject()
it! = innerJson!.entrySet().iterator()
WHILE (it!.hasNext())
next! = it!.next()
json!.addProperty(str(next!.getKey()) , str(next!.getValue()),err=*next)
WEND
FI
methodret json!
methodend
classend