123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559
"use strict";
modulum('TableWidget', ['TableWidgetBase'],
function(context, cls) {
cls.TableWidget = context.oo.Class(cls.TableWidgetBase, function($super) {
return {
__name: "TableWidget",
_stylingContext: "widget",
$static: {
defaultRowHeight: 24
},
_lastClickDate: null,
_lastClickTarget: null,
_currentColumn: 0,
_orderedColumns: null,
_addOnlyVisibleColumnsToDom: true,
_layoutDone: false,
_hasFooter: false,
_firstDisplay: true,
_needToUpdateVerticalScroll: false,
_requestSynchronizeHeadersHeight: false,
_rowBoundColumnWidget: null,
_defaultItemSelection: false,
_firstItemSelected: null,
_itemSelectionInProgress: false,
_itemSelectionHasChanged: false,
_itemSelectionElement: null,
_leftContainerElement: null,
_rightContainerElement: null,
_columnsContainerElement: null,
_leftColumnsContainer: null,
_rightColumnsContainer: null,
_columnsHeaders: null,
_leftColumnsHeaders: null,
_rightColumnsHeaders: null,
_columnsFooter: null,
_rightScrollAreaElement: null,
_leftScrollAreaElement: null,
_replacerElement: null,
_aggregateGlobalTextElement: null,
_scrollAreaNoUserScroll: false,
_rightScrollAreaNoUserScroll: false,
_scrollAreaResetScrollTopFromPrevious: false,
_frozenTable: false,
_leftFrozenColumns: 0,
_rightFrozenColumns: 0,
_previousScrollLeftValue: 0,
_previousScrollTopValue: 0,
lastSentOffset: null,
_dndItemEnabled: false,
_dndMode: null,
_dndMouseDragX: null,
_dndReorderingDragOverWidget: null,
_dndDraggedColumnWidget: null,
_noDrop: null,
_showGrid: null,
_headerAlignment: null,
_headerHidden: null,
_resizeFillsEmptySpace: false,
_columnResizeFillsEmptySpace: null,
constructor: function(opts) {
this._noDrop = {
"left": false,
"right": false,
"center": false
};
$super.constructor.call(this, opts);
},
_preventDefault: function(event) {
this._dndMouseDragX = event.clientX || event.screenX;
if (this._dndMode) {
event.preventCancelableDefault();
}
},
_whenParentActivated: function(opt) {
$super._whenParentActivated.call(this, opt);
var widgetActivated = opt.data.length > 0 && opt.data[0];
if (this.isChildOf(widgetActivated)) {
var contextScrollTop = this._previousScrollTopValue;
var contextScrollLeft = this._previousScrollLeftValue;
this.getScrollableArea().scrollTop = contextScrollTop;
this.getScrollableArea().scrollLeft = contextScrollLeft;
this.getColumnsHeaders().scrollLeft = contextScrollLeft;
if (this.hasFooter()) {
this.getColumnsFooter().scrollLeft = contextScrollLeft;
}
}
},
_initElement: function() {
$super._initElement.call(this);
this.setRowHeight(cls.TableWidget.defaultRowHeight);
this.getColumnsHeaders().on("dragover.TableWidget", this._preventDefault.bind(this));
this.getLeftColumnsHeaders().on("dragover.TableWidget", this._preventDefault.bind(this));
this.getRightColumnsHeaders().on("dragover.TableWidget", this._preventDefault.bind(this));
this.getLeftColumnsHeaders()
.on("drop.TableWidget", this._onHeaderDrop.bind(this))
.on("dragstart.TableWidget", this._onHeaderDragStart.bind(this))
.on("dragend.TableWidget", this._onHeaderDragEnd.bind(this))
.on("drag.TableWidget", this._onHeaderDrag.throttle(5).bind(this))
.on("dragover.TableWidget", this._onHeaderDragOver.bind(this))
.on("dragleave.TableWidget", this._onHeaderDragLeave.bind(this))
.onLongTouch('longTouch.TableWidget', this._onLongTouch.bind(this))
.onDoubleTap("TableWidget", this._onHeaderDoubleClick.bind(this));
this.getLeftColumnsContainer()
.onDoubleTap("TableWidget", this._onDoubleClick.bind(this));
this.getRightColumnsHeaders()
.on("drop.TableWidget", this._onHeaderDrop.bind(this))
.on("dragstart.TableWidget", this._onHeaderDragStart.bind(this))
.on("dragend.TableWidget", this._onHeaderDragEnd.bind(this))
.on("drag.TableWidget", this._onHeaderDrag.throttle(5).bind(this))
.on("dragover.TableWidget", this._onHeaderDragOver.bind(this))
.on("dragleave.TableWidget", this._onHeaderDragLeave.bind(this))
.onLongTouch('longTouch.TableWidget', this._onLongTouch.bind(this))
.onDoubleTap("TableWidget", this._onHeaderDoubleClick.bind(this));
this.getRightColumnsContainer()
.onDoubleTap("TableWidget", this._onDoubleClick.bind(this));
this.getColumnsHeaders()
.on("drop.TableWidget", this._onHeaderDrop.bind(this))
.on("dragstart.TableWidget", this._onHeaderDragStart.bind(this))
.on("dragend.TableWidget", this._onHeaderDragEnd.bind(this))
.on("drag.TableWidget", this._onHeaderDrag.throttle(5).bind(this))
.on("dragover.TableWidget", this._onHeaderDragOver.bind(this))
.on("dragleave.TableWidget", this._onHeaderDragLeave.bind(this))
.onLongTouch('longTouch.TableWidget', this._onLongTouch.bind(this))
.onDoubleTap("TableWidget", this._onHeaderDoubleClick.bind(this));
this.getColumnsContainer()
.onDoubleTap("TableWidget", this._onDoubleClick.bind(this));
this.getScrollableArea().on('scroll.TableWidget', this._onScroll.bind(this));
this.getLeftScrollableArea().on('scroll.TableWidget', this._onScrollOnLeftColumns.bind(this));
this.getRightScrollableArea().on('scroll.TableWidget', this._onScrollOnRightColumns.bind(this));
this.getElement()
.on("mousedown.TableWidget", this._onItemMouseDown.bind(this))
.on("mouseup.TableWidget", this._onItemMouseUp.bind(this))
.on("mouseleave.TableWidget", this._onItemMouseLeave.bind(this));
this.setStyle(".gbc_TableColumnsHeaders", {
"margin-right": window.scrollBarSize + "px"
});
this.setStyle(".gbc_TableColumnsFooter, .gbc_TableLeftColumnsFooter, .gbc_TableRightColumnsFooter", {
"margin-bottom": window.scrollBarSize + "px"
});
this._updateFooterWidth();
},
_initLayout: function() {
this._layoutInformation = new cls.LayoutInformation(this);
this._layoutInformation.shouldFillStack = true;
this._layoutEngine = new cls.TableLayoutEngine(this);
this._layoutEngine.onLayoutApplied(this._layoutApplied.bind(this));
this._layoutInformation.getStretched().setDefaultX(true);
this._layoutInformation.getStretched().setDefaultY(true);
var minPageSize = parseInt(context.ThemeService.getValue("gbc-TableWidget-min-page-size"), 10);
this._layoutEngine.setMinPageSize(isNaN(minPageSize) ? 1 : minPageSize);
var minWidth = parseInt(context.ThemeService.getValue("gbc-TableWidget-min-width"), 10);
this._layoutEngine.setMinWidth(isNaN(minWidth) ? 60 : minWidth);
},
resetMeasure: function() {
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
if (this.getLayoutEngine().invalidatePreferredSize) {
this.getLayoutEngine().invalidatePreferredSize();
}
},
destroy: function() {
this.getColumnsHeaders().off("dragover.TableWidget");
this.getLeftColumnsHeaders().off("dragover.TableWidget");
this.getRightColumnsHeaders().off("dragover.TableWidget");
this.getLeftColumnsHeaders().off("drop.TableWidget");
this.getLeftColumnsHeaders().off("dragstart.TableWidget");
this.getLeftColumnsHeaders().off("dragend.TableWidget");
this.getLeftColumnsHeaders().off("drag.TableWidget");
this.getLeftColumnsHeaders().off("dragover.TableWidget");
this.getLeftColumnsHeaders().off("dragleave.TableWidget");
this.getLeftColumnsHeaders().offLongTouch('longTouch.TableWidget');
this.getLeftColumnsHeaders().offDoubleTap("TableWidget");
this.getLeftColumnsContainer().offDoubleTap("TableWidget");
this.getRightColumnsHeaders().off("drop.TableWidget");
this.getRightColumnsHeaders().off("dragstart.TableWidget");
this.getRightColumnsHeaders().off("dragend.TableWidget");
this.getRightColumnsHeaders().off("drag.TableWidget");
this.getRightColumnsHeaders().off("dragover.TableWidget");
this.getRightColumnsHeaders().off("dragleave.TableWidget");
this.getRightColumnsHeaders().offLongTouch('longTouch.TableWidget');
this.getRightColumnsHeaders().offDoubleTap("TableWidget");
this.getRightColumnsContainer().offDoubleTap("TableWidget");
this.getColumnsHeaders().off("drop.TableWidget");
this.getColumnsHeaders().off("dragstart.TableWidget");
this.getColumnsHeaders().off("dragend.TableWidget");
this.getColumnsHeaders().off("drag.TableWidget");
this.getColumnsHeaders().off("dragover.TableWidget");
this.getColumnsHeaders().off("dragleave.TableWidget");
this.getColumnsHeaders().offLongTouch('longTouch.TableWidget');
this.getColumnsHeaders().offDoubleTap("TableWidget");
this.getColumnsContainer().offDoubleTap("TableWidget");
this.getScrollableArea().off('scroll.TableWidget');
this.getLeftScrollableArea().off('scroll.TableWidget');
this.getRightScrollableArea().off('scroll.TableWidget');
if (this._rowBoundColumnWidget) {
this._rowBoundColumnWidget.destroy();
this._rowBoundColumnWidget = null;
}
this.getElement().off("mousedown.TableWidget");
this.getElement().off("mouseup.TableWidget");
this.getElement().off("mousemove.TableWidget");
this.getElement().off("mouseleave.TableWidget");
if (this._dndItemEnabled) {
var columnsContainer = this.getColumnsContainer();
columnsContainer.off("dragstart.TableWidget");
columnsContainer.off("dragend.TableWidget");
columnsContainer.off("dragover.TableWidget");
columnsContainer.off("drop.TableWidget");
columnsContainer.off("dragleave.TableWidget");
columnsContainer.off("dragenter.TableWidget");
}
this._columnsHeaders = null;
this._leftContainerElement = null;
this._rightContainerElement = null;
this._columnsContainerElement = null;
this._leftColumnsContainer = null;
this._rightColumnsContainer = null;
this._leftColumnsHeaders = null;
this._rightColumnsHeaders = null;
this._columnsFooter = null;
this._leftColumnsFooter = null;
this._rightColumnsFooter = null;
this._rightScrollAreaElement = null;
this._leftScrollAreaElement = null;
this._aggregateGlobalTextElement = null;
this._orderedColumns = null;
this._lastClickDate = null;
this._lastClickTarget = null;
$super.destroy.call(this);
},
manageKeyDown: function(keyString, domKeyEvent, repeat) {
var keyProcessed = false;
if (this.isDisplayMode()) {
if (domKeyEvent) {
var key = cls.KeyboardApplicationService.keymap[domKeyEvent.which];
keyProcessed = true;
switch (key) {
case "down":
this.emit(context.constants.widgetEvents.keyArrowDown, domKeyEvent);
break;
case "up":
this.emit(context.constants.widgetEvents.keyArrowUp, domKeyEvent);
break;
case "left":
this.emit(context.constants.widgetEvents.keyArrowLeft, domKeyEvent);
break;
case "right":
this.emit(context.constants.widgetEvents.keyArrowRight, domKeyEvent);
break;
case "pageup":
this.emit(context.constants.widgetEvents.keyPageUp, domKeyEvent);
break;
case "pagedown":
this.emit(context.constants.widgetEvents.keyPageDown, domKeyEvent);
break;
case "home":
this.emit(context.constants.widgetEvents.keyHome, domKeyEvent);
break;
case "end":
this.emit(context.constants.widgetEvents.keyEnd, domKeyEvent);
break;
case "space":
this.emit(context.constants.widgetEvents.keySpace, domKeyEvent);
break;
default:
keyProcessed = false;
}
}
if (keyString === "ctrl+a" || keyString === "meta+a") {
this.emit(context.constants.widgetEvents.selectAll);
keyProcessed = true;
}
}
if (keyProcessed) {
return true;
} else {
return $super.manageKeyDown.call(this, keyString, domKeyEvent, repeat);
}
},
managePriorityKeyDown: function(keyString, domKeyEvent, repeat) {
var keyProcessed = false;
if (keyString === "ctrl+c" || keyString === "meta+c") {
if (this.hasItemsSelected()) {
this._copySelectionInClipboard();
keyProcessed = true;
} else if (this.isDisplayMode()) {
this.emit(context.constants.widgetEvents.copy);
keyProcessed = true;
}
}
if (keyProcessed) {
return true;
} else {
return $super.managePriorityKeyDown.call(this, keyString, domKeyEvent, repeat);
}
},
manageMouseClick: function(domEvent) {
if (!domEvent.target.parent("gbc_TableColumnWidget") || !this.isEnabled()) {
let ui = this.getUserInterfaceWidget();
if (ui && ui.getFocusedWidget().getTableWidgetBase() !== this) {
this.emit(context.constants.widgetEvents.requestFocus);
}
}
if (!this.isRowActionTriggerByDoubleClick()) {
this.emit(context.constants.widgetEvents.rowAction);
return false;
}
return true;
},
manageMouseDblClick: function(domEvent) {
var target = domEvent.target;
var isHeaderDblClick = target.isElementOrChildOf(this.getColumnsHeaders()) ||
target.isElementOrChildOf(this.getLeftColumnsHeaders()) || target.isElementOrChildOf(this.getRightColumnsHeaders());
if (isHeaderDblClick) {
this._onHeaderDoubleClick(domEvent);
return false;
}
var isColumnsContainerClick = target.isElementOrChildOf(this.getColumnsContainer()) ||
target.isElementOrChildOf(this.getLeftColumnsContainer()) || target.isElementOrChildOf(this.getRightColumnsContainer());
if (isColumnsContainerClick) {
this._onDoubleClick(domEvent);
return false;
}
return true;
},
setEnabled: function(enabled) {
if (this._enabled !== enabled) {
$super.setEnabled.call(this, enabled);
this._resetItemsSelection();
this.updateVerticalScroll(enabled);
}
},
setAriaSelection: function() {
},
setBackgroundColor: function(color) {
$super.setBackgroundColor.call(this, color);
this.setStyle('.gbc_TableColumnsHeaders, .gbc_TableLeftColumnsHeaders, .gbc_TableRightColumnsHeaders', {
"background-color": color && !this._ignoreBackgroundColor ? color : null
});
},
setFocus: function(fromMouse) {
if (this.isElementInDOM()) {
this.domFocus(fromMouse);
} else {
var uiWidget = this.getUserInterfaceWidget();
if (uiWidget) {
uiWidget.getElement().domFocus();
}
}
$super.setFocus.call(this, fromMouse);
},
resetLayout: function() {
$super.resetLayout.call(this);
this._layoutDone = false;
},
_layoutApplied: function() {
if (this.isElementInDOM()) {
if (!this._layoutDone) {
this._layoutDone = true;
this.updateFrozenColumns();
this.updateAllAggregate();
}
this._updateVisibleColumnsInDom(0);
if (this._needToUpdateVerticalScroll) {
this.updateVerticalScroll(true);
}
this._needToUpdateVerticalScroll = false;
if (this.hasLeftFrozenColumns() && this.getLeftScrollableArea().scrollTop !== this.getScrollableArea().scrollTop) {
this.setLeftScrollableAreaScrollTop(this.getScrollableArea().scrollTop, false);
}
if (this.hasRightFrozenColumns() && this.getRightScrollableArea().scrollTop !== this.getScrollableArea().scrollTop) {
this.setRightScrollableAreaScrollTop(this.getScrollableArea().scrollTop, false, false);
}
if (this._requestSynchronizeHeadersHeight) {
this._requestSynchronizeHeadersHeight = false;
this.synchronizeHeadersHeight();
}
this.autoSetLastColumnWidthToFillEmptySpace();
}
},
requestFocusFromWidget: function(widget, event) {
var isDoubleClick = (new Date() - this._lastClickDate) < 350 && (this._lastClickTarget === event.target);
this._lastClickDate = new Date();
this._lastClickTarget = event.target;
var mustSendFocusRequest = !this.hasVMFocus() || (event.type !== "click");
mustSendFocusRequest = mustSendFocusRequest || (this._itemSelectionHasChanged === false);
if (isDoubleClick) {
this._lastClickDate = null;
this._lastClickTarget = null;
mustSendFocusRequest = false;
}
if (mustSendFocusRequest) {
$super.requestFocusFromWidget.call(this, widget, event);
}
},
autoSetLastColumnWidthToFillEmptySpace: function() {
if (this._resizeFillsEmptySpace) {
var lastVisibleColumn = this.getLastOrderedColumn(true);
if (this._columnResizeFillsEmptySpace && this._columnResizeFillsEmptySpace !== lastVisibleColumn) {
this._columnResizeFillsEmptySpace.resetWidth();
this._columnResizeFillsEmptySpace.setSizable(true);
}
this._columnResizeFillsEmptySpace = lastVisibleColumn;
this._columnResizeFillsEmptySpace.resetWidth();
this._columnResizeFillsEmptySpace.setSizable(false);
var visibleColumnsWidth = this.getVisibleColumnsWidth();
var tableWidth = this.getDataAreaWidth();
var emptySpaceWidth = tableWidth - visibleColumnsWidth;
if (emptySpaceWidth >= 0) {
this._columnResizeFillsEmptySpace.setWidth(this._columnResizeFillsEmptySpace.getWidth() + emptySpaceWidth, true);
}
}
},
_updateVisibleColumnsInDom: function(offset) {
if (!this._addOnlyVisibleColumnsToDom) {
return;
}
var isLayouted = this._layoutInformation && this._layoutDone;
if (!isLayouted) {
return;
}
var isVisible = this.isElementInDOM() && this.isVisibleRecursively();
if (!isVisible) {
return;
}
offset = typeof offset !== 'undefined' ? offset : this.getScrollableArea().scrollLeft;
if (offset === 0 && this._previousScrollLeftValue > 0) {
this.getScrollableArea().scrollLeft = this._previousScrollLeftValue;
offset = this._previousScrollLeftValue;
}
var columns = this.getOrderedColumns();
var tableWidth = this._layoutInformation.getAllocated().getWidth();
var currentWidth = 0;
var extraVisibleColumnAttached = false;
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
if (col.isFrozen() === false && col.isHidden() === false) {
var colWidth = col.getWidth();
if (col.isCurrent()) {
col.attachItemsToDom();
}
else if (offset > (currentWidth + colWidth)) {
col.detachItemsFromDom();
}
else if ((currentWidth - offset) > tableWidth) {
if (extraVisibleColumnAttached) {
col.detachItemsFromDom();
} else {
extraVisibleColumnAttached = true;
col.attachItemsToDom();
}
} else {
col.attachItemsToDom();
}
currentWidth += colWidth;
} else {
if (col.isHidden()) {
col.detachItemsFromDom();
} else {
col.attachItemsToDom();
}
}
}
},
addChildWidget: function(widget, options) {
if (widget.isInstanceOf(cls.TableColumnWidget)) {
this._addChildTableColumn(widget, options);
} else if (widget.isInstanceOf(cls.ContextMenuWidget)) {
$super.addChildWidget.call(this, widget, options);
if (this._rowBoundColumnWidget === null) {
this._rowBoundColumnWidget = cls.WidgetFactory.createWidget("TableColumnRowBound", this.getBuildParameters());
this._addChildTableColumn(this._rowBoundColumnWidget, options);
}
this.setResizeFillsEmptySpace(true);
this._rowBoundColumnWidget.setHidden(false);
}
this.resetOrderedColumns();
this.updateFrozenColumns();
this._requestSynchronizeHeadersHeight = true;
},
_addChildTableColumn: function(columnWidget, options) {
columnWidget.setParentWidget(this, {
noLayoutInvalidation: true
});
this.getColumnsHeaders().appendChild(columnWidget.getTitleWidget().getElement());
columnWidget.setCurrentRow(this._currentRow);
columnWidget.setOrder(this.getColumns().length);
$super.addChildWidget.call(this, columnWidget, options);
},
removeChildWidget: function(widget) {
$super.removeChildWidget.call(this, widget);
if (widget.isInstanceOf(cls.ContextMenuWidget)) {
this.setResizeFillsEmptySpace(false);
if (this._rowBoundColumnWidget) {
this._rowBoundColumnWidget.setHidden(true);
}
}
this.resetOrderedColumns();
},
setSort: function(sortType, sortColumn) {
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
if (i === sortColumn) {
columns[i].getTitleWidget().setSortDecorator(sortType);
} else {
if (columns[i].getTitleWidget) {
columns[i].getTitleWidget().setSortDecorator("");
}
}
}
},
isTreeView: function() {
var firstColumn = this.getColumns()[0];
return firstColumn && firstColumn._isTreeView;
},
isCurrentRowVisible: function() {
return this._currentRow >= 0 && this._currentRow <= this._pageSize;
},
getColumns: function() {
return this.getChildren();
},
resetOrderedColumns: function() {
this._orderedColumns = null;
},
getOrderedColumns: function() {
var columns = this.getColumns();
if (this._orderedColumns === null || columns.length !== this._orderedColumns.length) {
var children = columns.slice();
children.sort(function(a, b) {
return a.getOrder() - b.getOrder();
});
this._orderedColumns = children;
}
return this._orderedColumns;
},
getLastOrderedColumn: function(visible) {
var columns = this.getOrderedColumns();
for (var i = columns.length - 1; i >= 0; i--) {
var currentColumn = columns[i];
if (!visible || !currentColumn.isHidden()) {
return currentColumn;
}
}
return null;
},
getVisibleColumnsWidth: function() {
var visibleColumnsWidth = 0;
var columns = this.getOrderedColumns();
for (var i = 0; i < columns.length; i++) {
var currentColumn = columns[i];
if (!currentColumn.isHidden()) {
visibleColumnsWidth += currentColumn.getWidth();
}
}
return visibleColumnsWidth;
},
setRowHeight: function(height) {
this._rowHeight = Math.round(height);
this.setStyle(" .gbc_TableColumnItemWidget", {
"height": this._rowHeight + "px"
});
this.setStyle(" .gbc_TableColumnItemWidget .gbc_TableItemImage", {
"width": this._rowHeight + "px",
"height": this._rowHeight + "px"
});
this.updateVerticalScroll(true);
},
setCurrentRow: function(row, ensureRowVisible) {
this._currentRow = row;
var columns = this.getColumns();
var scrollIntoView = (Boolean(ensureRowVisible) && this._layoutDone);
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
col.setCurrentRow(row);
}
if (scrollIntoView) {
this._scrollAreaNoUserScroll = true;
this._rightScrollAreaNoUserScroll = true;
this.getScrollableArea().scrollTop = (this._offset * this.getRowHeight());
}
},
setCurrentColumn: function(col) {
this._currentColumn = col;
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
if (columns[i].setCurrent) {
columns[i].setCurrent(i === col);
}
}
},
getCurrentColumn: function() {
return this._currentColumn;
},
getCurrentWidget: function() {
if (this.isCurrentRowVisible()) {
return this.getWidgetAt(this._currentColumn, this._currentRow);
}
return null;
},
getWidgetAt: function(column, row) {
return this.getColumns()[column].getWidgetAt(row);
},
setVisibleRows: function(visibleRows) {
if (this._visibleRows !== visibleRows) {
this._visibleRows = visibleRows;
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
var tableColumn = columns[i];
if (tableColumn.updateRowsVisibility) {
tableColumn.updateRowsVisibility();
}
}
}
},
setMultiRowSelectionEnabled: function(enable) {
this._element.toggleClass("multiRowSelection", Boolean(enable));
},
isMultiRowSelectionEnabled: function() {
return this._element.hasClass("multiRowSelection");
},
setRowSelected: function(row, selected) {
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
var tableColumn = columns[i];
tableColumn.setRowSelected(row, selected);
}
},
isRowSelected: function(row) {
var columns = this.getColumns();
if (columns.length) {
return columns[row].isRowSelected(row);
}
return false;
},
synchronizeHeadersHeight: function() {
if (this._frozenTable && this._layoutDone) {
var height = -1;
var leftHeight = -1;
var rightHeight = -1;
if (this.hasLeftFrozenColumns() || this.hasRightFrozenColumns()) {
this.getColumnsHeaders().addClass("g_TableMeasuring");
height = this.getColumnsHeaders().clientHeight;
this.getColumnsHeaders().removeClass("g_TableMeasuring");
}
if (this.hasLeftFrozenColumns()) {
this.getLeftColumnsHeaders().addClass("g_TableMeasuring");
leftHeight = this.getLeftColumnsHeaders().clientHeight;
this.getLeftColumnsHeaders().removeClass("g_TableMeasuring");
}
if (this.hasRightFrozenColumns()) {
this.getRightColumnsHeaders().addClass("g_TableMeasuring");
rightHeight = this.getRightColumnsHeaders().clientHeight;
this.getRightColumnsHeaders().removeClass("g_TableMeasuring");
}
var headerHeight = Math.max(height, leftHeight, rightHeight);
if (headerHeight > 0) {
this.setStyle(".gbc_TableColumnsHeaders", {
"height": headerHeight + "px"
});
if (this.hasLeftFrozenColumns()) {
this.setStyle(".gbc_TableLeftColumnsHeaders", {
"height": headerHeight + "px"
});
}
if (this.hasRightFrozenColumns()) {
this.setStyle(".gbc_TableRightColumnsHeaders", {
"height": headerHeight + "px"
});
}
}
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
}
},
buildExtraContextMenuActions: function(contextMenu) {
contextMenu.addAction("copyRow", i18next.t("gwc.contextMenu.copyRow"), null, "Ctrl+C", {
clickCallback: function() {
contextMenu.hide();
this._copyCurrentRowInClipboard();
}.bind(this)
}, true);
if (this.isMultiRowSelectionEnabled()) {
contextMenu.addAction("selectAll", i18next.t("gwc.contextMenu.selectAll"), "font:FontAwesome.ttf:f0ea", "Ctrl+A", {
clickCallback: function() {
contextMenu.hide();
this.emit(context.constants.widgetEvents.selectAll);
}.bind(this)
}, true);
}
},
flash: function() {
this.addClass("flash");
this._registerTimeout(function() {
this.removeClass("flash");
}.bind(this), 50);
},
autoFitAllColumns: function() {
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
var tc = columns[i];
tc.autoSetWidth();
}
},
fitToViewAllColumns: function() {
var columns = this.getColumns();
var totalAvail = this.getDataAreaWidth();
var totalCurrent = 0;
var tc = null,
i = 0;
for (i = 0; i < columns.length; i++) {
tc = columns[i];
if (!tc.isHidden()) {
if (tc.isSizable()) {
totalCurrent = totalCurrent + tc.getWidth();
} else {
totalAvail = totalAvail - tc.getWidth();
}
}
}
var newTotal = 0;
if (totalCurrent > 0) {
for (i = 0; i < columns.length; i++) {
tc = columns[i];
if (!tc.isHidden() && tc.isSizable()) {
var w = Math.round(tc.getWidth() * (totalAvail / totalCurrent));
newTotal = newTotal + w;
if (newTotal > totalAvail) {
w = w - (newTotal - totalAvail);
}
tc.setWidthFromUserInteraction(w);
}
}
}
},
setHasFooter: function(b) {
if (this._hasFooter !== b) {
this._hasFooter = b;
this.getColumnsFooter().toggleClass("hidden", !b);
if (b) {
this.updateAllAggregate();
}
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
}
},
hasFooter: function() {
return this._hasFooter;
},
updateAllAggregate: function() {
if (this.hasFooter() && this._layoutDone) {
this.resetOrderedColumns();
var columns = this.getOrderedColumns();
var firstAggregate = null;
var aggregateWidth = 0;
var frozenIndex = null;
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
if (frozenIndex === null) {
frozenIndex = col.getFrozenIndex();
}
var agg = col.getAggregateWidget();
if (col.getFrozenIndex() !== frozenIndex) {
frozenIndex = col.getFrozenIndex();
aggregateWidth = 0;
}
if (!col.isHidden()) {
aggregateWidth += col.getWidth();
if (agg) {
if (aggregateWidth) {
this.afterDomMutator(function(col, aggregateWidth) {
col.setAggregate(col.getAggregateWidget().getText(), aggregateWidth);
}.bind(this, col,
aggregateWidth));
}
aggregateWidth = 0;
if (!firstAggregate) {
firstAggregate = agg;
}
}
}
}
if (firstAggregate) {
this.getAggregateGlobalTextElement().remove();
firstAggregate.getElement().prependChild(this.getAggregateGlobalTextElement());
}
}
},
setAggregateGlobalText: function(text) {
if (!this._aggregateGlobalTextElement) {
this._aggregateGlobalTextElement = document.createElement("div");
this._aggregateGlobalTextElement.addClass("gbc_TableAggregateGlobalText");
}
this._aggregateGlobalTextElement.textContent = text;
},
isVerticalScrollAtEnd: function() {
var scrollArea = this.getScrollableArea();
return (scrollArea.scrollTop + scrollArea.clientHeight) === scrollArea.scrollHeight;
},
doScroll: function(value, delta, force) {
var isTableVisible = this.isVisibleRecursively();
if (isTableVisible) {
var top = value;
if (delta) {
top = (this.getScrollableArea().scrollTop + value);
}
if (this.hasRightFrozenColumns()) {
this.setRightScrollableAreaScrollTop(top, force);
} else {
this.setScrollableAreaScrollTop(top, force);
}
} else {
this._needToUpdateVerticalScroll = true;
}
},
doHorizontalScroll: function(direction) {
var scrollArea = this.getScrollableArea();
var scrollPos = scrollArea.scrollLeft;
var columns = this.getOrderedColumns();
var width = 0;
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
if (col.isFrozen() === false && col.isHidden() === false) {
var colWidth = col.getWidth();
var isScrollAtStartColumn = (Math.abs(scrollPos - width) <= 2);
var isScrollAtEndColumn = (Math.abs(scrollPos - (width + colWidth)) <= 2);
if ((isScrollAtStartColumn || scrollPos > width) && (isScrollAtEndColumn || scrollPos < width + colWidth)) {
if (isScrollAtStartColumn && direction === "right") {
scrollPos = width + colWidth;
direction = "left";
} else if (isScrollAtEndColumn && direction === "right") {
scrollPos = width + colWidth;
} else {
scrollArea.scrollLeft = direction === "right" ? width + colWidth : width;
break;
}
}
width += colWidth;
}
}
},
_onMouseWheel: function(event) {
if (this.isEnabled()) {
this.doScroll(event.deltaY, true, true);
}
},
_onScroll: function(event) {
var targetScrollTop = event.target.scrollTop;
var targetScrollLeft = event.target.scrollLeft;
if (this._previousScrollLeftValue !== targetScrollLeft) {
this._previousScrollLeftValue = targetScrollLeft;
this.afterDomMutator(function() {
if (this._throttleUpdateVisibleColumnsInDom) {
this._clearTimeout(this._throttleUpdateVisibleColumnsInDom);
}
this._throttleUpdateVisibleColumnsInDom = this._registerTimeout(function() {
this._throttleUpdateVisibleColumnsInDom = null;
this._scrollAreaNoUserScroll = true;
this._scrollAreaResetScrollTopFromPrevious = true;
this._updateVisibleColumnsInDom();
this.afterDomMutator(function() {
this.afterDomMutator(function() {
this._scrollAreaNoUserScroll = false;
this._scrollAreaResetScrollTopFromPrevious = false;
}.bind(this));
}.bind(this));
}.bind(this), 10);
}.bind(this));
var scrollLeft = this.getScrollableArea().scrollLeft;
this.getColumnsHeaders().scrollLeft = scrollLeft;
if (this.hasFooter()) {
this.getColumnsFooter().scrollLeft = scrollLeft;
}
}
this._resetItemsSelection();
if (this._scrollAreaNoUserScroll) {
this._scrollAreaNoUserScroll = false;
if (this._scrollAreaResetScrollTopFromPrevious) {
this._scrollAreaResetScrollTopFromPrevious = false;
this.getScrollableArea().scrollTop = this._previousScrollTopValue;
} else {
this._previousScrollTopValue = targetScrollTop;
}
return true;
}
if (this._previousScrollTopValue !== targetScrollTop) {
this._previousScrollTopValue = targetScrollTop;
this.afterDomMutator(function() {
if (!this.hasRightFrozenColumns()) {
this.emit(context.constants.widgetEvents.scroll, event, this.getRowHeight());
var scrollTop = this.getScrollableArea().scrollTop;
this.setLeftScrollableAreaScrollTop(scrollTop);
this.setRightScrollableAreaScrollTop(scrollTop);
}
}.bind(this));
}
},
_onScrollOnLeftColumns: function(event) {
this.afterDomMutator(function() {
if (event.target) {
this.getLeftColumnsHeaders().scrollLeft = event.target.scrollLeft;
if (this.hasFooter()) {
this.getLeftColumnsFooter().scrollLeft = event.target.scrollLeft;
}
}
}.bind(this));
},
_onScrollOnRightColumns: function(event) {
this.afterDomMutator(function() {
if (event.target) {
this.getRightColumnsHeaders().scrollLeft = event.target.scrollLeft;
if (this.hasFooter()) {
this.getRightColumnsFooter().scrollLeft = event.target.scrollLeft;
}
if (this.hasRightFrozenColumns()) {
this.emit(context.constants.widgetEvents.scroll, event, this.getRowHeight());
var scrollTop = event.target.scrollTop;
this.setLeftScrollableAreaScrollTop(scrollTop);
this.setScrollableAreaScrollTop(scrollTop);
}
}
}.bind(this));
if (this._rightScrollAreaNoUserScroll) {
this._rightScrollAreaNoUserScroll = false;
return true;
}
if (this.hasRightFrozenColumns()) {
this.afterDomMutator(function() {
if (event.target) {
this.emit(context.constants.widgetEvents.scroll, event, this.getRowHeight());
var scrollTop = event.target.scrollTop;
this.setLeftScrollableAreaScrollTop(scrollTop);
this.setScrollableAreaScrollTop(scrollTop);
}
}.bind(this));
}
},
setVerticalScroll: function(size, pageSize, offset, forceScroll) {
if (size !== null) {
this.setSize(size);
if (this._pageSize !== pageSize) {
this._pageSize = pageSize;
this._resetItemsSelection();
}
var top = offset * this.getRowHeight();
var rowCount = (size - offset + (this.isInputMode() ? 1 :
0));
var height = rowCount * this.getRowHeight() + (this.hasFooter() ? this.getColumnsFooter().clientHeight : 0);
if (size <
pageSize) {
height = Math.max(Math.floor(this.getDataAreaHeight() - 2),
height);
}
this.setStyle({
selector: ".gbc_TableColumnsContainer"
}, {
"margin-top": top + "px",
"height": height + "px"
});
if (this.hasLeftFrozenColumns()) {
this.setStyle({
preSelector: ".g_measured ",
selector: ".gbc_TableLeftColumnsContainer"
}, {
"margin-top": top + "px",
"height": height + "px"
});
}
if (this.hasRightFrozenColumns()) {
this.setStyle({
preSelector: ".g_measured ",
selector: ".gbc_TableRightColumnsContainer"
}, {
"margin-top": top + "px",
"height": height + "px"
});
}
if (this._layoutDone && (forceScroll || (this.lastSentOffset === null || this.lastSentOffset === offset) && offset !== this
._offset)) {
this._offset = offset;
this.afterDomMutator(function() {
this.doScroll(top, false);
}.bind(this));
}
this.lastSentOffset = null;
}
},
setScrollableAreaScrollTop: function(top, force, synchronizing) {
if (this.getScrollableArea().scrollTop !== top) {
this._scrollAreaNoUserScroll = !force;
this.getScrollableArea().scrollTop = top;
if (!synchronizing) {
this.setLeftScrollableAreaScrollTop(top, true);
this.setRightScrollableAreaScrollTop(top, false, true);
}
}
},
setLeftScrollableAreaScrollTop: function(top, synchronizing) {
if (this.getLeftScrollableArea().scrollTop !== top) {
this.getLeftScrollableArea().scrollTop = top;
if (!synchronizing) {
this.setScrollableAreaScrollTop(top, false, true);
this.setRightScrollableAreaScrollTop(top, false, true);
}
}
},
setRightScrollableAreaScrollTop: function(top, force, synchronizing) {
if (this.getRightScrollableArea().scrollTop !== top) {
this._rightScrollAreaNoUserScroll = !force;
this.getRightScrollableArea().scrollTop = top;
if (!synchronizing) {
this.setLeftScrollableAreaScrollTop(top, true);
this.setScrollableAreaScrollTop(top, false, true);
}
}
},
updateFrozenColumns: function() {
if (this._frozenTable) {
this._renderFrozenColumns();
this.getScrollableArea().off('wheel.TableWidget');
this.getLeftScrollableArea().off('wheel.TableWidget');
this.getRightScrollableArea().off('wheel.TableWidget');
if (this.hasLeftFrozenColumns()) {
this.getLeftScrollableArea().on('wheel.TableWidget', this._onMouseWheel.bind(this));
}
if (this.hasRightFrozenColumns()) {
this.getScrollableArea().on('wheel.TableWidget', this._onMouseWheel.bind(this));
this.setStyle(".gbc_TableColumnsHeaders", {
"margin-right": 0
});
this.setStyle(".gbc_TableRightColumnsHeaders", {
"margin-right": window.scrollBarSize + "px"
});
this.setStyle(".gbc_TableScrollArea", {
"overflow-y": "hidden"
});
} else {
this.setStyle(".gbc_TableRightColumnsHeaders", {
"margin-right": 0
});
this.setStyle(".gbc_TableColumnsHeaders", {
"margin-right": window.scrollBarSize + "px"
});
this.setStyle(".gbc_TableScrollArea", {
"overflow-y": "scroll"
});
}
this.getLeftContainer().toggleClass("hidden", !this.hasLeftFrozenColumns());
this.getRightContainer().toggleClass("hidden", !this.hasRightFrozenColumns());
this._updateFooterWidth();
this.updateVerticalScroll();
this.domAttributesMutator(function() {
this.afterDomMutator(function() {
var scrollTop = this.getScrollableArea().scrollTop;
this.setLeftScrollableAreaScrollTop(scrollTop);
this.setRightScrollableAreaScrollTop(scrollTop);
}.bind(this));
}.bind(this));
this.synchronizeHeadersHeight();
this.updateAllAggregate();
}
},
_updateFooterWidth: function() {
if (this.hasRightFrozenColumns()) {
this.setStyle(".gbc_TableRightColumnsFooter", {
"width": "calc(100% - " + window.scrollBarSize + "px)"
});
this.setStyle(".gbc_TableColumnsFooter", {
"width": "100%"
});
} else {
this.setStyle(".gbc_TableColumnsFooter", {
"width": "calc(100% - " + window.scrollBarSize + "px)"
});
this.setStyle(".gbc_TableRightColumnsFooter", {
"width": "100%"
});
}
},
hasLeftFrozenColumns: function() {
return (this._leftFrozenColumns > 0);
},
hasRightFrozenColumns: function() {
return (this._rightFrozenColumns > 0);
},
_renderFrozenColumns: function() {
if (this._frozenTable) {
var columns = this.getOrderedColumns();
for (var i = 0; i < columns.length; i++) {
var currentColumn = columns[i];
if (i < this._leftFrozenColumns) {
currentColumn._isLeftFrozen = true;
currentColumn._isRightFrozen = false;
this.getLeftColumnsContainer().appendChild(currentColumn.getElement());
this.getLeftColumnsHeaders().appendChild(currentColumn.getTitleWidget().getElement());
if (currentColumn._aggregate) {
this.getLeftColumnsFooter().appendChild(currentColumn._aggregate.getElement());
}
} else if (columns.length - i <= this._rightFrozenColumns) {
currentColumn._isRightFrozen = true;
currentColumn._isLeftFrozen = false;
this.getRightColumnsContainer().appendChild(currentColumn.getElement());
this.getRightColumnsHeaders().appendChild(currentColumn.getTitleWidget().getElement());
if (currentColumn._aggregate) {
this.getRightColumnsFooter().appendChild(currentColumn._aggregate.getElement());
}
} else {
currentColumn._isLeftFrozen = false;
currentColumn._isRightFrozen = false;
this.getColumnsContainer().appendChild(currentColumn.getElement());
this.getColumnsHeaders().appendChild(currentColumn.getTitleWidget().getElement());
if (currentColumn._aggregate) {
this.getColumnsFooter().appendChild(currentColumn._aggregate.getElement());
}
}
}
this._updateVisibleColumnsInDom();
}
},
isFrozenTable: function() {
return this._frozenTable;
},
setFrozenTable: function(frozen) {
if (this._frozenTable !== frozen) {
this._frozenTable = frozen;
this.updateFrozenColumns();
}
},
setLeftFrozenColumns: function(n) {
if (this._leftFrozenColumns !== n) {
this._leftFrozenColumns = n;
this.updateFrozenColumns();
}
},
setRightFrozenColumns: function(n) {
if (this._rightFrozenColumns !== n) {
this._rightFrozenColumns = n;
this.updateFrozenColumns();
}
},
getLeftFrozenColumns: function() {
return this._leftFrozenColumns;
},
getRightFrozenColumns: function() {
return this._rightFrozenColumns;
},
setHeaderHidden: function(hidden) {
if (this._headerHidden !== hidden) {
this._headerHidden = hidden;
this.getColumnsHeaders().toggleClass("hidden", Boolean(hidden));
this.getLeftColumnsHeaders().toggleClass("hidden", Boolean(hidden));
this.getRightColumnsHeaders().toggleClass("hidden", Boolean(hidden));
}
},
setShowGrid: function(showGrid) {
if (this._showGrid !== showGrid) {
this._showGrid = showGrid;
this._element.toggleClass("showGrid", Boolean(showGrid));
}
},
setHeaderAlignment: function(alignment) {
if (this._headerAlignment !== alignment) {
this._headerAlignment = alignment;
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
col.getTitleWidget().setTextAlign(alignment);
}
}
},
setHighlightColor: function(color) {
if (this._highlightColor !== color) {
this._highlightColor = color;
color = (color === null ? null : color + " !important");
this.setStyle({
selector: ":not(.disabled) .highlight .gbc_TableColumnItemWidget.currentRow",
appliesOnRoot: true
}, {
"background-color": color
});
}
},
setHighlightTextColor: function(color) {
if (this._highlightTextColor !== color) {
this._highlightTextColor = color;
this.setStyle({
selector: ":not(.disabled) .highlight .gbc_TableColumnItemWidget.currentRow",
appliesOnRoot: true
}, {
"color": color === null ? null : color + " !important",
"fill": color === null ? null : color + " !important"
});
}
},
updateHighlight: function() {
this.setCurrentRow(this._currentRow);
this.setCurrentColumn(this._currentColumn);
},
setResizeFillsEmptySpace: function(b) {
this._resizeFillsEmptySpace = b || this
.hasRowBound();
if (!this._resizeFillsEmptySpace) {
this._columnResizeFillsEmptySpace = null;
}
},
isResizeFillsEmptySpace: function() {
return this._resizeFillsEmptySpace;
},
_onHeaderDoubleClick: function(evt) {
if (evt.target.hasClass("resizer")) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (columnTitleWidget) {
columnTitleWidget.onResizerDoubleClick(evt);
}
}
},
_onHeaderDrop: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (columnTitleWidget) {
columnTitleWidget.onReorderingDrop(evt);
} else if (this._dndMode === "columnReordering") {
if (this._dndReorderingDragOverWidget === null) {
var orderedColumns = this.getOrderedColumns();
this._dndDraggedColumnWidget.getTitleWidget().reorderColumns(this._dndDraggedColumnWidget, orderedColumns[
orderedColumns.length - 1]);
}
}
},
_onHeaderDragStart: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (!columnTitleWidget) {
return;
}
if (evt.target.hasClass("resizer")) {
columnTitleWidget.onResizerDragStart(evt);
} else if (evt.target.hasClass("headerText")) {
columnTitleWidget.onReorderingDragStart(evt);
}
},
_onHeaderDragEnd: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (!columnTitleWidget || !evt.target.hasClass) {
return;
}
if (evt.target.hasClass("resizer")) {
columnTitleWidget.onResizerDragEnd(evt);
} else if (evt.target.hasClass("headerText")) {
columnTitleWidget.onReorderingDragEnd(evt);
}
},
_onHeaderDragOver: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (!columnTitleWidget) {
return;
}
columnTitleWidget.onReorderingDragOver(evt);
},
_onHeaderDragLeave: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (!columnTitleWidget) {
return;
}
columnTitleWidget.onReorderingDragLeave(evt);
},
_onHeaderDrag: function(evt) {
if (evt.target.hasClass && evt.target.hasClass("resizer")) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (columnTitleWidget) {
columnTitleWidget.onResizerDrag(evt);
}
}
},
setDefaultItemSelection: function(b) {
this._defaultItemSelection = b;
if (b === true) {
this.setDndItemEnabled(false);
}
},
_isEventAllowItemSelection: function(evt) {
return (this.isDisplayMode() && (evt.ctrlKey || evt.metaKey || this._defaultItemSelection)) || (this.isInputMode() && (
evt.ctrlKey ||
evt.metaKey || (this._defaultItemSelection &&
!this._enabled)));
},
hasItemsSelected: function() {
if (this._itemSelectionElement === null) {
return false;
}
return !(this._itemSelectionElement.hasClass("hidden"));
},
_resetItemsSelection: function() {
if (this._firstItemSelected !== null) {
this._itemSelectionInProgress = false;
this._firstItemSelected = null;
if (this._itemSelectionElement) {
this._itemSelectionElement.addClass("hidden");
}
this._setItemSelection(false);
}
},
_itemSelectionMouseMovePrevX: 0,
_itemSelectionMouseMovePrevY: 0,
_onItemMouseDown: function(evt) {
this._itemSelectionMouseMovePrevX = evt.screenX;
this._itemSelectionMouseMovePrevY = evt.screenY;
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
this._resetItemsSelection();
if (itemWidget && this._isEventAllowItemSelection(evt)) {
evt.stopPropagation();
evt.preventCancelableDefault();
if (this._itemSelectionElement === null) {
this._itemSelectionElement = document.createElement("span");
this._itemSelectionElement.addClass("gbc_TableItemSelectionArea");
this._itemSelectionElement.addClass("hidden");
this._element.appendChild(this._itemSelectionElement);
}
this._itemSelectionInProgress = true;
this._firstItemSelected = itemWidget;
this.getElement().on("mousemove.TableWidget", this._onItemMouseMove.bind(this));
this._temporaryEnabledDndOnItem(false, this._firstItemSelected);
}
},
_stopInProgressItemSelection: function(evt) {
this._itemSelectionInProgress = false;
if (this._isEventAllowItemSelection(evt)) {
this._temporaryEnabledDndOnItem(this._dndItemEnabled, this._firstItemSelected);
}
},
_onItemMouseUp: function(evt) {
this.getElement().off("mousemove.TableWidget");
this._itemSelectionMouseMovePrevX = 0;
this._itemSelectionMouseMovePrevY = 0;
this._stopInProgressItemSelection(evt);
},
_onItemMouseLeave: function(evt) {
this._stopInProgressItemSelection(evt);
},
_onItemMouseMove: function(evt) {
var movementX = (this._itemSelectionMouseMovePrevX ? evt.screenX - this._itemSelectionMouseMovePrevX : 0);
var movementY = (this._itemSelectionMouseMovePrevY ? evt.screenY - this._itemSelectionMouseMovePrevY : 0);
if (Math.abs(movementX) > 1 || Math.abs(movementY) > 1) {
if (this._itemSelectionInProgress && this._isEventAllowItemSelection(evt)) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
if (this._firstItemSelected !== null) {
this._setItemSelection(true, this._firstItemSelected, itemWidget);
}
}
}
}
this._itemSelectionMouseMovePrevX = evt.screenX;
this._itemSelectionMouseMovePrevY = evt.screenY;
},
_copySelectionInClipboard: function() {
var rows = [];
var rowIndex;
var orderedColumns = this.getOrderedColumns();
for (var i = 0; i < orderedColumns.length; i++) {
var col = orderedColumns[i];
rowIndex = 0;
for (var j = 0; j < col.getChildren().length; j++) {
var item = col.getChildren()[j];
if (item.isClientSelected()) {
var text = item.getChildren()[0].getClipboardValue() + "\t";
if (rows.length <= rowIndex) {
rows.push(text);
} else {
rows[rowIndex] += text;
}
rowIndex++;
}
}
}
for (i = 0; i < rows.length; ++i) {
rows[i] = rows[i].substring(0, rows[i].length - 1);
}
cls.ClipboardHelper.copyTo(rows.join("\r\n"), this._element);
},
_copyCurrentRowInClipboard: function() {
var row = "";
var orderedColumns = this.getOrderedColumns();
for (var i = 0; i < orderedColumns.length; i++) {
var col = orderedColumns[i];
if (!col.isHidden()) {
if (this._currentRow >= 0 && this._currentRow < col.getChildren().length) {
var item = col.getChildren()[this._currentRow];
row += item.getChildren()[0].getClipboardValue();
if (i < orderedColumns.length - 1) {
row += '\t';
}
}
}
}
cls.ClipboardHelper.copyTo(row, this._element);
},
_copyCurrentCellInClipboard: function() {
var cell = "";
var col = this.getColumns()[this._currentColumn];
if (this._currentRow >= 0 && this._currentRow < col.getChildren().length) {
var item = col.getChildren()[this._currentRow];
cell = item.getChildren()[0].getClipboardValue();
}
cls.ClipboardHelper.copyTo(cell, this._element);
},
_setItemSelection: function(b, startSelectedItem, endSelectedItem) {
var realStartRow = -1;
var realEndRow = -1;
var realStartCol = -1;
var realEndCol = -1;
this._itemSelectionHasChanged = false;
if (b && startSelectedItem && endSelectedItem) {
var startCol = startSelectedItem.getParentWidget().getOrderedColumnIndex();
var startRow = startSelectedItem.getItemIndex();
var endCol = !endSelectedItem ? startCol : endSelectedItem.getParentWidget().getOrderedColumnIndex();
var endRow = !endSelectedItem ? startRow : endSelectedItem.getItemIndex();
realStartRow = (startRow < endRow) ? startRow : endRow;
realEndRow = (startRow < endRow) ? endRow : startRow;
realStartCol = (startCol < endCol) ? startCol : endCol;
realEndCol = (startCol < endCol) ? endCol : startCol;
var mostLeftItem = (realStartCol === startCol) ? startSelectedItem : endSelectedItem;
var mostRightItem = (realStartCol === startCol) ? endSelectedItem : startSelectedItem;
var left = mostLeftItem.getElement().getBoundingClientRect().left;
var right = mostRightItem.getElement().getBoundingClientRect().right;
var mostTopItem = (realStartRow === startRow) ? startSelectedItem : endSelectedItem;
var mostBottomItem = (realStartRow === startRow) ? endSelectedItem : startSelectedItem;
var top = mostTopItem.getElement().getBoundingClientRect().top;
var bottom = mostBottomItem.getElement().getBoundingClientRect().bottom;
var tableTop = this.getElement().getBoundingClientRect().top;
var tableLeft = this.getElement().getBoundingClientRect().left;
this.setStyle(".gbc_TableItemSelectionArea", {
"left": (left - tableLeft) + "px",
"top": (top - tableTop) + "px",
"width": (right - left) + "px",
"height": (bottom - top) + "px"
});
this._itemSelectionElement.removeClass("hidden");
this._itemSelectionHasChanged = true;
}
for (var i = 0; i < this.getOrderedColumns().length; i++) {
var col = this.getOrderedColumns()[i];
for (var j = 0; j < col.getChildren().length; j++) {
var item = col.getChildren()[j];
var select = (b && i >= realStartCol && i <= realEndCol && j >= realStartRow && j <= realEndRow);
item.setClientSelected(select);
}
}
},
_temporaryEnabledDndOnItem: function(b, item) {
if (item) {
item.setDndEnabled(b);
if (b) {
this.getColumnsContainer().setAttribute("draggable", "true");
} else {
this.getColumnsContainer().removeAttribute("draggable");
}
}
},
setDndItemEnabled: function(b) {
if (b && this._defaultItemSelection) {
return;
}
if (this._dndItemEnabled !== b) {
this._dndItemEnabled = b;
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
columns[i].setDndItemEnabled(b);
}
var columnsContainer = this.getColumnsContainer();
if (b) {
columnsContainer.setAttribute("draggable", "true");
columnsContainer.on("dragstart.TableWidget", this._onItemDragStart.bind(this));
columnsContainer.on("dragend.TableWidget", this._onItemDragEnd.bind(this));
columnsContainer.on("dragover.TableWidget", this._onItemDragOver.bind(this));
columnsContainer.on("drop.TableWidget", this._onItemDrop.bind(this));
columnsContainer.on("dragleave.TableWidget", this._onItemDragLeave.bind(this));
columnsContainer.on("dragenter.TableWidget", this._onItemDragEnter.bind(this));
} else {
columnsContainer.removeAttribute("draggable");
columnsContainer.off("dragstart.TableWidget");
columnsContainer.off("dragend.TableWidget");
columnsContainer.off("dragover.TableWidget");
columnsContainer.off("drop.TableWidget");
columnsContainer.off("dragleave.TableWidget");
columnsContainer.off("dragenter.TableWidget");
}
}
},
_onItemDragStart: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragStart(evt);
}
},
_onItemDragEnd: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragEnd(evt);
}
},
_onItemDragOver: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragOver(evt);
} else {
if (evt.target.hasClass("gbc_TableAfterLastItemZone")) {
var columnWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnWidget");
columnWidget.onDragOverAfterLastItem(evt);
}
}
},
_onItemDrop: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDrop(evt);
} else {
if (evt.target.hasClass("gbc_TableAfterLastItemZone")) {
var columnWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnWidget");
columnWidget.onDropAfterLastItem(evt);
}
}
},
_onItemDragLeave: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragLeave(evt);
}
},
_onItemDragEnter: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragEnter(evt);
}
},
_onDoubleClick: function(evt) {
var columnWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnWidget");
if (!columnWidget) {
return;
}
if (this.isRowActionTriggerByDoubleClick()) {
this.emit(context.constants.widgetEvents.rowAction, columnWidget.getColumnIndex());
}
},
_onLongTouch: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (columnTitleWidget) {
columnTitleWidget.manageMouseRightClick(evt);
} else {
$super.manageMouseRightClick.call(this, evt);
}
},
getLeftContainer: function() {
if (!this._leftContainerElement) {
this._leftContainerElement = this._element.getElementsByClassName("gbc_TableLeftContainer")[0];
}
return this._leftContainerElement;
},
getRightContainer: function() {
if (!this._rightContainerElement) {
this._rightContainerElement = this._element.getElementsByClassName("gbc_TableRightContainer")[0];
}
return this._rightContainerElement;
},
getColumnsContainer: function() {
if (!this._columnsContainerElement) {
this._columnsContainerElement = this._element.getElementsByClassName("gbc_TableColumnsContainer")[0];
}
return this._columnsContainerElement;
},
getLeftColumnsContainer: function() {
if (!this._leftColumnsContainer) {
this._leftColumnsContainer = this._element.getElementsByClassName("gbc_TableLeftColumnsContainer")[0];
}
return this._leftColumnsContainer;
},
getRightColumnsContainer: function() {
if (!this._rightColumnsContainer) {
this._rightColumnsContainer = this._element.getElementsByClassName("gbc_TableRightColumnsContainer")[0];
}
return this._rightColumnsContainer;
},
getColumnsHeaders: function() {
if (!this._columnsHeaders) {
this._columnsHeaders = this._element.getElementsByClassName("gbc_TableColumnsHeaders")[0];
}
return this._columnsHeaders;
},
getLeftColumnsHeaders: function() {
if (!this._leftColumnsHeaders) {
this._leftColumnsHeaders = this._element.getElementsByClassName("gbc_TableLeftColumnsHeaders")[0];
}
return this._leftColumnsHeaders;
},
getRightColumnsHeaders: function() {
if (!this._rightColumnsHeaders) {
this._rightColumnsHeaders = this._element.getElementsByClassName("gbc_TableRightColumnsHeaders")[0];
}
return this._rightColumnsHeaders;
},
getColumnsFooter: function() {
if (!this._columnsFooter) {
this._columnsFooter = this.getElement().getElementsByClassName("gbc_TableColumnsFooter")[0];
}
return this._columnsFooter;
},
getLeftColumnsFooter: function() {
if (!this._leftColumnsFooter) {
this._leftColumnsFooter = this.getElement().getElementsByClassName("gbc_TableLeftColumnsFooter")[0];
}
return this._leftColumnsFooter;
},
getRightColumnsFooter: function() {
if (!this._rightColumnsFooter) {
this._rightColumnsFooter = this.getElement().getElementsByClassName("gbc_TableRightColumnsFooter")[0];
}
return this._rightColumnsFooter;
},
getScrollableArea: function() {
if (!this._scrollAreaElement) {
this._scrollAreaElement = this._element.getElementsByClassName("gbc_TableScrollArea")[0];
}
return this._scrollAreaElement;
},
getRightScrollableArea: function() {
if (!this._rightScrollAreaElement) {
this._rightScrollAreaElement = this._element.getElementsByClassName("gbc_TableRightScrollArea")[0];
}
return this._rightScrollAreaElement;
},
getLeftScrollableArea: function() {
if (!this._leftScrollAreaElement) {
this._leftScrollAreaElement = this._element.getElementsByClassName("gbc_TableLeftScrollArea")[0];
}
return this._leftScrollAreaElement;
},
getAggregateGlobalTextElement: function() {
return this._aggregateGlobalTextElement;
}
};
});
cls.WidgetFactory.registerBuilder('Table', cls.TableWidget);
});