Skip to content

Commit

Permalink
feat: add range selection event ON_GRID_RANGE_SELECTION_CHANGED()
Browse files Browse the repository at this point in the history
  • Loading branch information
hyyan committed Jul 17, 2019
1 parent 713d789 commit 6f6213f
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 8 deletions.
21 changes: 21 additions & 0 deletions BBjGridExWidget.bbj
Expand Up @@ -43,6 +43,7 @@ use ::BBjGridExWidget/BBjGridExWidgetClientEvents.bbj::BBjGridExWidgetClientEven
use ::BBjGridExWidget/BBjGridExWidgetClientEvents.bbj::BBjGridExWidgetClientEventsContextMenu
use ::BBjGridExWidget/BBjGridExWidgetClientEvents.bbj::BBjGridExWidgetClientEventsCell
use ::BBjGridExWidget/BBjGridExWidgetClientEvents.bbj::BBjGridExWidgetClientEventsRowEditing
use ::BBjGridExWidget/BBjGridExWidgetClientEvents.bbj::BBjGridExWidgetClientEventsRangeSelection
rem /**
rem * The Grid Core Class.This class works as a columns manager and api provider.
rem * It contains a big number of methods and properties to configure the column from A..Z.
Expand Down Expand Up @@ -896,6 +897,14 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
methodret 5008
methodend
rem /**
rem * Constant value to define range selection event
rem *
rem * @return BBjNumber
rem */
method public static BBjNumber ON_GRID_RANGE_SELECTION_CHANGED()
methodret 5009
methodend
rem /**
rem * Alias for <i>ON_GRID_STATE_CHANGE()</i>
rem *
rem * @see ON_GRID_STATE_CHANGE()
Expand Down Expand Up @@ -1365,6 +1374,9 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
case "gw.cellDoubleClicked"
#onCellEvent(detail$,#ON_GRID_CELL_DOUBLE_CLICK())
break
case "gw.rangeSelection"
#onRangeSelectionChange(detail$)
break
case "gw.cellEditingStarted"
#onCellEvent(detail$,#ON_GRID_CELL_EDITING_STARTED())
break
Expand Down Expand Up @@ -3070,6 +3082,15 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
#fireEvent(type!, event!)
methodend
rem /**
rem * Handle Range Selections Event
rem *
rem * @see BBjGridExWidgetClientEventsRangeSelection
rem */
method private void onRangeSelectionChange(BBjString detail$)
event! = new BBjGridExWidgetClientEventsRangeSelection()
#fireEvent(#ON_GRID_RANGE_SELECTION_CHANGED(),event!)
methodend
rem /**
rem * On rows selections event
rem *
rem * Parse the json details coming from the client and fires new BBjGridExWidgetSelectRowEvent
Expand Down
10 changes: 9 additions & 1 deletion BBjGridExWidgetClientEvents.bbj
Expand Up @@ -88,4 +88,12 @@ class public BBjGridExWidgetClientEventsRowEditing
rem * The Row being edited
rem */
field public BBjGridExWidgetClientRowModel Row!
classend
classend

REM /**
REM * Cells range selection event
REM *
REM * @author Hyyan Abo Fakher
REM */
class public BBjGridExWidgetClientEventsRangeSelection
classend
129 changes: 129 additions & 0 deletions Demo/Enterprise/RangeSelectionDemo.bbj
@@ -0,0 +1,129 @@
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 com.basiscomponents.db.ResultSet
use com.basiscomponents.bc.SqlQueryBC
use java.sql.Types
use com.google.gson.JsonObject
use java.util.ArrayList
use java.util.Collections

? 'HIDE'

declare auto BBjTopLevelWindow wnd!
declare BBjGridExWidget grid!

wnd! = BBjAPI().openSysGui("X0").addWindow(10,10,800,600,"BBj Grid Ex Demo")
wnd!.setCallback(BBjAPI.ON_CLOSE,"byebye")
wnd!.setCallback(BBjAPI.ON_RESIZE,"resize")

static! = wnd!.addStaticText(100,-10,575,800,25,"Count : 0 - Sum : 0 - Min : 0 - Max : 0 - Average : 0" , $0000$ )
static!.setAlignment(static!.ALIGN_RIGHT)

grid! = new BBjGridExWidget(wnd!,101, 0 , 0 , 800 , 560)
grid!.setEnableRangeSelection(1)
grid!.setNavigationBehavior(grid!.GRID_NAVIGATION_BEHAVIOUR_NEXT_CELL())
grid!.setSuppressRowClickSelection(1)
grid!.setCallback(grid!.ON_GRID_RANGE_SELECTION_CHANGED(),"onRangeSelectionChange")

gosub main
process_events

main:
declare SqlQueryBC sbc!
declare ResultSet rs!

sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))
rs! = sbc!.retrieve("SELECT CDNUMBER , TITLE , MUSICTYPE,COST FROM CDINVENTORY")

grid!.setData(rs!)
return

onRangeSelectionChange:
rem array of ranges
ranges! = grid!.getRangeSelection()
IF (ranges!.size() = 0) THEN
return
ENDIF

rangesLength! = ranges!.size() - 1

sum! = 0
count! = 0
min! = 0
max! = 0
average! = 0
values! = new ArrayList()

rem we start by looping over all ranges
FOR rangeIndex! = 0 TO rangesLength!

currentRange! = ranges!.get(rangeIndex!)

rows! = currentRange!.getRows()
rowsLength! = rows!.size() - 1

columns! = currentRange!.getColumns()
columnsLength! = columns!.size() - 1

count! = count! + (columns!.size() * rows!.size())

FOR rowIndex! = 0 TO rowsLength!

FOR columnsIndex! = 0 TO columnsLength!

column! = columns!.get(columnsIndex!)
type! = column!.getType()

SWITCH (type!)
case Types.INTEGER
case Types.DECIMAL
case Types.DOUBLE
case Types.NUMERIC

row! = rows!.get(rowIndex!).asDataRow()
value! = num(row!.getField(column!.getName()).getValue())
sum! = sum! + value!
values!.add(value!)

BREAK
CASE DEFAULT
BREAK
SWEND

NEXT columnsIndex!

NEXT rowIndex!

NEXT rangeIndex!

IF (values!.size() > 0) THEN
min! = Collections.min(values!)
max! = Collections.max(values!)
average! = sum! / values!.size()
ENDIF

static!.setText("Count : " + str(count!) + " - Sum : " + str(sum!) + " - Min : " + str(min!) + " - Max : " + str(max!) + " - Average : " + str(average!))
return

rem /**
rem * Listen to the BBjTopLevelWindow resize events 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
79 changes: 78 additions & 1 deletion client/dist/bbj-grid-widget.js

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion client/dist/bbj-grid-widget.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions client/dist/report.html

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions client/src/api/init.js
Expand Up @@ -13,6 +13,7 @@ import { gw_getDocument, gw_addGrid} from "./utilities";
import {
gw_onRowDoubleClicked,
gw_onSelectionChanged,
gw_onRangeSelectionChanged,
gw_onCellClickEvent,
gw_onCellEditingEvent,
gw_onRowEditingEvent,
Expand Down Expand Up @@ -86,8 +87,9 @@ function gw_parseOptions(options) {
getRowNodeId: data => gw_getRowNodeId(id, data) ,
getContextMenuItems: params => gw_getContextMenu(id, params) ,
"popupParent": gw_getDocument().body,
"onRowDoubleClicked": gw_debounce(gw_onRowDoubleClicked, debounceDuration),
"onSelectionChanged": gw_debounce(gw_onSelectionChanged, debounceDuration),
"onRowDoubleClicked": gw_debounce(gw_onRowDoubleClicked, debounceDuration) ,
"onSelectionChanged": gw_debounce(gw_onSelectionChanged, debounceDuration) ,
"onRangeSelectionChanged": gw_debounce(gw_onRangeSelectionChanged , debounceDuration) ,
"components": {
"BasicBooleansRenderer" : Basis.AgGridComponents.BasicBooleansRenderer,
"BasicBooleansEditor" : Basis.AgGridComponents.BasicBooleansEditor ,
Expand Down
5 changes: 4 additions & 1 deletion client/src/events/constants.js
Expand Up @@ -20,4 +20,7 @@ export const GW_EVENT_ROW_EDITING_STARTED = 5006;
export const GW_EVENT_ROW_EDITING_STOPPED = 5007;

// state constants
export const GW_EVENT_GRID_STATE_CHANGE = 5008;
export const GW_EVENT_GRID_STATE_CHANGE = 5008;

// range selection
export const GW_EVENT_RANGE_SELECTION_CHANGED = 5009;
4 changes: 3 additions & 1 deletion client/src/events/index.js
Expand Up @@ -9,7 +9,8 @@
import {
gw_onRowDoubleClicked,
gw_onSelectionChanged,
gw_onCellClickEvent
gw_onCellClickEvent,
gw_onRangeSelectionChanged
} from "./selections";

import {
Expand All @@ -28,6 +29,7 @@ import {
export {
gw_onRowDoubleClicked,
gw_onSelectionChanged,
gw_onRangeSelectionChanged,
gw_onCellClickEvent,
gw_onCellEditingEvent,
gw_onRowEditingEvent,
Expand Down
19 changes: 18 additions & 1 deletion client/src/events/selections.js
Expand Up @@ -12,7 +12,8 @@ import {
GW_EVENT_ROW_CLICK,
GW_EVENT_ROW_DOUBLE_CLICK,
GW_EVENT_CELL_CLICK,
GW_EVENT_CELL_DOUBLE_CLICK
GW_EVENT_CELL_DOUBLE_CLICK,
GW_EVENT_RANGE_SELECTION_CHANGED
} from "./constants";

const CELL_CLICKING_EVENTS_MAP = {
Expand Down Expand Up @@ -54,6 +55,22 @@ export function gw_onSelectionChanged(e) {
}, GW_EVENT_ROW_CLICK);
}

/**
* A handler for the grid `rangeSelectionChanged` event
*
* @param {Object} e
*
* @listens agGrid.rangeSelectionChanged
* @fires gw.rangeSelection
*/
export function gw_onRangeSelectionChanged(e) {
const context = e.api.gridOptionsWrapper.gridOptions.context;
gw_sendEvent(context, {
'type': 'gw.rangeSelection',
'detail': ''
}, GW_EVENT_RANGE_SELECTION_CHANGED);
}

/**
* A handler for the grid `cellClickEvent` & `cellDoubleClicked` event
*
Expand Down

0 comments on commit 6f6213f

Please sign in to comment.