Simple TreeWidget implementation example
December 19, 2019 at 2:24amSimple TreeWidget implementation example
December 19, 2019 at 2:24amHi, I'm looking for a very simple example of a TreeWidget implementation, does anyone know a git repo that has one? I checked FileTreeWidget and OutlineViewWidget in theia repo but I'm don't understand how the content and labels are provided to the tree. I'm familiar to the JFace way with content and label providers, is it similar?
December 19, 2019 at 9:55am
We actually reworking this area right now: https://github.com/eclipse-theia/theia/pull/6475 in regards how labels are customized.
Usually you have to customize 3 parts:
- tree itself, something like
FileTree.resolveChildren
- it is a function which resolves child nodes for given. Before you should define your model btw, i.e. something likeFileNode
andDirNode
- before
name
,description
andicon
will be part of your nodes, but it is turned out to be expensive to store and compute for big models, so with https://github.com/eclipse-theia/theia/pull/6475 they are only computed on demand for visible nodes. One has to implementLableProviderContribution
for own tree model, look atFileTreeLabelProvider
in PR for example
- last part is a widget to have some custom rendering, look at
FileTreeWidget
for example
Everything should be bound together via child DI container, see
createFileTreeContainer
and how it is used. You can also explore createTreeContainer
to see what else can be customized for trees.December 20, 2019 at 12:39am
January 7, 2020 at 12:40am
Another question, can those tree implementations be reused outside of a
TreeWidget
? Like a dialog or having 2 tree side by side in a widget view.January 7, 2020 at 2:36pm
I found this a very good starting point for a tree view plugin https://github.com/eclipse/che-theia-samples/tree/master/samples/tree-view-sample-plugin
This may also help but I didnt try it
https://github.com/microsoft/vscode-extension-samples/tree/master/tree-view-sample
January 8, 2020 at 4:24am
second is VS Code extension, it cannot us widgets as well
January 9, 2020 at 3:45am
What's the correct way to set the root of the tree?
I tried something like this:
const members = [{name: "member 1",children: [{name: "child1",children: []},{name: "child2",children: []}]},/* ... more data */}] as FamilyMember[];this.model.root = {id: "family-tree-root",name: "Family Tree Root",children: members.map(member => FamilyMemberNode.toNode(member)),visible: true,parent: undefined} as CompositeTreeNode;
When I do that
FamilyTree.resolveChildren
is called for the root node, but nothing renders in the widgetI checked the model in
FamilyTreeWidget.renderTree
and it has the children correctly setdo
const members: FamilyMember[] = []
and if there is some compilation errors then you should fix itstrange that your nodes don't have id
that's how we create tree data in tests: https://github.com/eclipse-theia/theia/blob/014cf089495ae2be788bbc182d40e174ea5fe58f/packages/core/src/browser/tree/tree.spec.ts#L202
They do have ids
that pastebin contains all the file used
Can you spot anything wrong?