Skip to content

Commit fbc21a9

Browse files
committed
add example that highlight how selection work in tree
1 parent accdac8 commit fbc21a9

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/Toplo-Examples/ToSandBox.class.st

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,62 @@ ToSandBox class >> example_ClassHierarchiesWithMethods [
23892389
treeElement openInSpace
23902390
]
23912391

2392+
{ #category : #tree }
2393+
ToSandBox class >> example_ClassHierarchiesWithMethodsWithSelectedPath [
2394+
"For this example we created a new wrapper dealing with classes and methods at the same time, a new Node was also created (ToTreeSubAndMethNode) to apply a new skin (ToTreeNodeSubAndMethSkin) with new icons and a different background color for methods.
2395+
This variant adds a text field at the top that reflects the current selected path."
2396+
2397+
| pane pathField treeElement |
2398+
pane := ToPane vertical.
2399+
pane matchParent.
2400+
pane layout cellSpacing: 5.
2401+
2402+
pathField := ToTextField new.
2403+
pathField
2404+
hMatchParent;
2405+
wrappingMode: false;
2406+
placeholderString: 'Selected path';
2407+
text: 'No selection'.
2408+
2409+
treeElement := self classTree.
2410+
treeElement matchParent.
2411+
treeElement useScrollbar: true.
2412+
treeElement dataAccessor add: ProtoObject.
2413+
treeElement dataAccessor add: BlElement.
2414+
treeElement dataAccessor add: Collection.
2415+
treeElement dataAccessor add: String.
2416+
treeElement
2417+
addEventHandlerOn: ToListPrimarySelectionChangedEvent
2418+
do: [ :evt |
2419+
| currentWrapper labels selectedIndex selectedPath |
2420+
evt selectedIndexes
2421+
ifEmpty: [ pathField text: 'No selection' ]
2422+
ifNotEmpty: [
2423+
selectedIndex := evt selectedIndexes first.
2424+
selectedPath := (evt currentTarget dataSource pathOfIndex:
2425+
selectedIndex) asArray.
2426+
labels := OrderedCollection new.
2427+
currentWrapper := evt currentTarget dataSource at:
2428+
selectedIndex.
2429+
[ currentWrapper isNil ] whileFalse: [
2430+
labels addFirst: (currentWrapper dataItem isClass
2431+
ifTrue: [ currentWrapper dataItem name ]
2432+
ifFalse: [ currentWrapper dataItem printString ]).
2433+
currentWrapper := currentWrapper parentWrapper ].
2434+
pathField text: (String streamContents: [ :stream |
2435+
stream << selectedPath printString.
2436+
labels ifNotEmpty: [
2437+
stream << ' - '.
2438+
labels doWithIndex: [ :label :index |
2439+
index > 1 ifTrue: [ stream << ' > ' ].
2440+
stream << label ] ] ]) ] ].
2441+
2442+
pane addChild: pathField.
2443+
pane addChild: treeElement.
2444+
pane openInSpace.
2445+
^ pane
2446+
]
2447+
23922448
{ #category : #anchors }
23932449
ToSandBox class >> example_ClockWithAnchors [
23942450

0 commit comments

Comments
 (0)