Usage of TreeField [message #1871571] |
Mon, 30 September 2024 07:36  |
Eclipse User |
|
|
|
Hello,
I am having trouble figuring out how to use the TreeField in ScoutClassic 24.1.
My use case is this:
I have a folder structure with two levels: some base folders and files in the folders. The form data for the tree is created on the Scout server and returned along with the full form data within the service call. Later I would like to dynamically load the file or file preview from a service and display it in the form. But for now it is only the tree with the file and folder names.
I believe I need to implement the
protected ITreeNode importTreeNodeData(ITreeNode parentNode, AbstractTreeFieldData treeData, TreeNodeData nodeData) {
return null;
}
in my inner Tree class. But my attempts so far have not been successful. The field remains empty.
I am considering using a table with only one visible column instead of the TreeField. But I would prefer the TreeField.
I would be very grateful for any advice.
Best
Nils
[Updated on: Mon, 30 September 2024 07:39] by Moderator
|
|
|
Re: Usage of TreeField [message #1871613 is a reply to message #1871571] |
Wed, 02 October 2024 09:22  |
Eclipse User |
|
|
|
There is not much type support for loading trees from a form data, at least not as much as for tables. You are on the right track, through. In your FormData, you can put any (serializable) data you need for each node. You can create a custom class that extends TreeNodeData for this. In the tree widget, you have to implement importTreeNodeData() to create custom tree nodes from this tree node data.
Something like this (untested):
public class Tree extends AbstractTree {
@Override
protected ITreeNode importTreeNodeData(ITreeNode parentNode, AbstractTreeFieldData treeData, TreeNodeData nodeData) {
if (nodeData instanceof MyTreeNodeData) {
MyTreeNodeData node = new MyTreeNode(((MyTreeNodeData) nodeData));
getTree().addChildNode(parentNode, node);
return node;
}
return super.importTreeNodeData(parentNode, treeData, nodeData);
}
@Override
public void importTreeData(AbstractTreeFieldData source) {
super.importTreeData(source);
getTree().expandAll(getRootNode());
}
}
...
protected static class P_MyTreeNode extends AbstractTreeNode {
private final MyTreeNodeData m_data;
public P_MyTreeNode(MyTreeNodeData data) {
super(false);
m_data = data;
callInitializer();
}
@Override
protected void initConfig() {
super.initConfig();
setLeaf(m_data.getChildNodes() == null || m_data.getChildNodes().isEmpty());
setEnabled(m_data.isValid());
}
public MyTreeNodeData getData() {
return m_data;
}
@Override
protected void execDecorateCell(Cell cell) {
String additionalInfo = m_data.isValid() ? "OK" : "NOK;
cell.setText(m_data.getDisplayText() + StringUtility.box(" [", additionalInfo, "]"));
}
}
Check out the example in the widgets app. Although it does not use form datas, it demonstrates adding and removing tree nodes dynamically. https://github.com/eclipse-scout/scout.docs/blob/releases/24.1/code/widgets/org.eclipse.scout.widgets.client/src/main/java/org/eclipse/scout/widgets/client/ui/forms/TreeFieldForm.java
Beat
|
|
|
Powered by
FUDForum. Page generated in 0.07169 seconds