I have 2 TreeTables which uses non-persistant datasource.
TreeTable 1: (scopeTree)
Contains:
Chapters (chaptersDs) - Use chapter as parent to create sub-chapters and notes.
Subchapters (chaptersDs) - Can be used as parent to create sub-chapter and notes
Notes (NotesDs) - Cannot be a parent node. Cannot create any node from Notes.
Example:
---->Chapter 1
--------->Chapter 1
------------------->Notes 1
----->Chapter 2
------------->Notes 1
------------->Notes 2
------------->Chapter 1
--------------------> Notes 1
--------------------> Notes 2
I use non persistant datasourse WpsNode (WpsNodesDs) to display nodes in TreeTable1.
I use the following method to create chapters, subchapters and notes.
Chapter:
WpsNode sn = createWpsNode(null, new WpsNodeBuilder<>(Chapter.class)
.build(null, chapter, MESSAGE_PACK, ParamsMap.of(
"sortOrder", sortOrder.toString())), true);
wpsNodesDs.addItem(sn);
scopeTree.setSelected(sn);
Subchapter:
Integer sortOrder = scopeTree.getSingleSelected().getChildren().size();
createWpsNode(scopeTree.getSingleSelected(), new WpsNodeBuilder<>(Chapter.class)
.build(scopeTree.getSingleSelected(), subChapter, MESSAGE_PACK, ParamsMap.of(
"sortOrder", sortOrder.toString())), true);
Notes:
createWpsNode(scopeTree.getSingleSelected(), new WpsNodeBuilder<>(Notes.class)
.build(scopeTree.getSingleSelected(), notes, MESSAGE_PACK, null), true);
I am able to create, edit and delete nodes in a Treetable.
Now I have another TreeTable.
TreeTable 2: (defTree)
Contains:
DefChapters (defChaptersDs) - Use chapter as parent to create sub-chapters and notes.
DefSubchapters (defChaptersDs) - Can be used as parent to create sub-chapter and notes
DefNotes (defNotesDs) - Cannot be a parent node. Cannot create any node from Notes.
Example:
---->DefChapter 1
--------->DefChapter 1
------------------->DefNotes 1
----->DefChapter 2
------------->DefNotes 1
------------->DefNotes 2
------------->DefChapter 1
--------------------> DefNotes 1
--------------------> DefNotes 2
I would like to get all children and their children of DefChapter 1 in TreeTable2 and store it in TreeTable 1 by creating objects for Chapters.
I used a following method to store the selected DefChapter and all their children in an array list.
protected List<StandardEntity> createNode(WpsNode wpsNode) {
List<StandardEntity> entitiestomove = new ArrayList<>();
if (wpsNode != null && wpsNode.getObject() != null) {
entitiestomove.add(wpsNode.getObject());
wpsNode.getChildren().forEach(node -> entitiestomove.addAll(createNode(node)));
}
return entitiestomove;
}
Now I want them to be created in TreeTable 1 on the same order.
I used a following method, but it does not work well.
public void onBtnMoveChildrenClick() {
WpsNode node = scopeTree.getSingleSelected();
if(node!=null && node.getObject() instanceof Notes) {
btnMoveChildren.setEnabled(false);
} else {
btnMoveChildren.setEnabled(true);
WpsNode wpsNode = defTree.getSingleSelected();
List<StandardEntity> entitiestomove = createNode(wpsNode);
for(Object object : entitiestomove) {
if(object instanceof DefChapter) {
Chapter chapter = metadata.create(Chapter.class);
chapter.setName(((DefChapter) object).getName());
chapter.setSortOrder(((DefChapter) object).getSortOrder());
Integer sortOrder = scopeTree.getSingleSelected().getChildren().size();
createWpsNode(scopeTree.getSingleSelected(), new WpsNodeBuilder<>(Chapter.class)
.build(scopeTree.getSingleSelected(), chapter, MESSAGE_PACK, ParamsMap.of( "sortOrder", sortOrder.toString())), true);
}
else if
(object instanceof DefNotes) {
Notes notes= metadata.create(Notes.class);
notes.setName(((DefGuideline) object).getName());
notes.setSortOrder(((DefGuideline) object).getSortOrder());
createWpsNode(scopeTree.getSingleSelected(), new WpsNodeBuilder<>(Notes.class)
.build(scopeTree.getSingleSelected(), notes, MESSAGE_PACK, null), true);
}
I am not getting the exact order. Is there any better solution to this problem. Your inputs will be helpful.