cancel
Showing results for 
Search instead for 
Did you mean: 

Selection in table with Master Column

Former Member
0 Kudos

Hi,

can anybody explain me how selection works in table with MasterColumn (TreeByNestingTableColumn)?

I've created a table with several columns and the "master" one behaves differently from others.

First of all, leaf elements of master column are not clickable (i.e. I don't receive notification "onLeadSelect" from the table, when user clicks in the cell of leaf element of the column). With expandable elements I receive loadchildren event and can react on selection.

I'm using TextView as cell editor, will try LinkToAction, may be it will resolve situation, but it's rather workaround as solution

Second, getLeadSelection doesn't work anymore for the table - it works with indexes of top level elements only.

However onLeadSelect action brings me selected row number, which I somehow should map to the tree.

I.e. when I get "25" as selected element, I recursively traverse context node to find 25th element. Which is rather slow operation as for any selection I have to reiterate whole structure and I hope that visual appearance is similar to context element order.

May be there is simplier ways to get selected element by its index in "flat" list?

And one another strange thing: first click on the table sends me onLeadSelect "0", but highlight points to the element user clicked - not necessary first one.

Context node is "single" selection, initLeadSelect=true,

selection = 0..1 (with 1..1 setTreeSelection doesn't work - method I want to use to be able to select a node in hierarchy on my own)

all quite similar to other tables I have, which works well. Just the problems with the table, where Master Column is used.

Thank you!

Best regards,

Nick

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

FYI: replaced TextView by LinkToAction as cell editor for Master Column. No reaction at all on clicking the underlined text. onAction event is not called

Former Member
0 Kudos

Nick,

Send me e-mail to vsilaev@gmail.com and I'll provide you an example that covers selection in master column.

Some people on this forum find it useful

VS

Former Member
0 Kudos

A small summary from what I got from Valery's example:

- Master Column cells are not clickable (expandable nodes are clickable, on onLoadChildren you may also programmatically react "as if on click" on the node).

Therefore it makes sense to put as less as possible information to the column - user may click any other cells in the table to make row selected)

- in onLeadSelect one can find selected element by applying loop:

IXXXElement selElement;

for (IXXXElement current = wdContext.currentXXXElement(); null != current; current = current.current<RecursionNode>Element()) {

selElement = current;

}

- if you want to select an item programmatically or there are several UI elements mapped to the hierarchical context (in case of Valery's example there were Tree and Table MasterColumn mapped to the same context node), you should care that selection in Table might become invisible (in Valery's example, if you select an element in Tree somewhere down, the table also gets the selection, but it's not visible - user should manually scroll the table to selection).

Valery's proposal was to perform reverse traverse from current element to root and summarize parent element indexes.

I'll let you know if would succeed with that.

Best regards,

Nick

Former Member
0 Kudos

>Valery's proposal was to perform reverse traverse from current element to root and summarize parent element indexes.

It seems to work:

in method, which sets selection I applied

...

// we need to know index of the element not in whole context, but in scope of table-relevant node

int index = getIndexInContext(selElement, wdContext.currentXXXElement());

IContextElement curContext = wdContext.currentContextElement();

int firstVisibleRow = curContext.getTableFirstVisibleRow();

int visibleRows = curContext.getTableVisibleRows();

if (index < firstVisibleRow || index > firstVisibleRow + visibleRows) {

curContext.setTableFirstVisibleRow(index);

}

...

and method getIndexInContext looks as:

private int getIndexInContext (IWDNodeElement element, IWDNodeElement root) {

int index = element.index();

if (element == root) {

return index;

}

IWDNodeElement parent = element.node().getParentElement();

if (parent == null) {

// do whatever you like here for error diagnostic

myMsgMgr.reportException("Internal Error: getIndexInContext - element is not under passed root", false);

return 0;

}

// +1 - every level adds 1 (otherwise indexes of first children of hierarchy will be 0)

return index + getIndexInContext(parent, root) + 1;

}

Best regards,

Nick

Answers (0)