Homogeneous level values ​​in a tree algorithm

Consider a tree with three levels: L1, L2, L3 (but this is only a special case, for the convenience of questions, there are no restrictions on the number of levels and children at each level).

Each level contains a key and a value (for example, [string, integer]).

Algorithm . If direct children have the same value, then these values ​​are not displayed at the child level, but at the parent level. Only leaves can make a difference; parents simply present data depending on the contents of the sheet .

My solution : I changed my mind. I need a generic solution excluding JFace LabelProviders. I move the tree in order and save the values ​​on the map. I would prefer to save only entries that are not null (i.e. the level has something to display). Performance is critical.

    Case 1 Case 2 Case 3
-------------- -------------- --------------  
L1 | 1 L1 | - L1 | -
| - L2 | - | - L2 | 1 | - L2 | -
| | - L3 | - | | - L3 | - | | - L3 | 1
| + - L3 | - | + - L3 | - | + - L3 | 2
+ - L2 | - + - L2 | 2 + - L2 | -
    | - L3 | - | - L3 | - | - L3 | 1
    + - L3 | - + - L3 | - + - L3 | 2

: , . , getColumnText(Object element, int columnsIndex), element - L1/L2/L3, columnIndex .

. , element, / , , conicide. , element. , , . reaaaaaallllllyyyy , .

: , ( getColumnText). ? , , "" ? a >

+4
2

D, .

, node n. Value(n) :

  • n node, .
  • , n c0, c1, .., c(k-1).
  • firstChildValue = Value(c0).
  • int i = 1, i <= k-1, , :
    • firstChildValue == Value(ci) .
    • firstChildValue != Value(ci): firstChildValue null, c1, .., c{i-1} D firstChildValue. ci, .., c{k-1} Value(ci) D . null, n .
  • firstChildValue, .

, Value(root) root , Value(root) .

, , , node .

E: @GGrec , . , .

+2

, . . , , ILabelProvider ITreeContentProvider:

  • SummarizingLabelProvider , , , .

  • IgnoreDetailsLabelProvider , .

SummarizingLabelProvider#getText(element)

( ): , , ( ). ILabelProvider ITreeContentProvider .

IgnoreDetailsLabelProvider#getText(element)

null, . ILabelProvider ITreeContentProvider .

:

ILabelProvider lp1 = // original label provider
ILabelProvider lp2 = new SummarizingLabelProvider(contentProvider, lp1);
ILabelProvider lp3 = new IgnoreDetailsLabelProvider(contentProvider, lp2);

treeViewer.setLabelProvider(lp3);

SummarizingLabelProvider. getText(element) element . , Map, . , , !

IgnoreDetailsLabelProvider SummarizingLabelProvider getText, .

+1

All Articles