p:tree ajax loading nodes does not display the expand icon - ajax

I'm trying to ajax load the p:tree component. The idea is to mimic the tree of a windows file system. When I click the expand icon of a node, I make a call to a service which returns list of directories under that directory node. I then simply add these new directories as child nodes of the node which was expanded. I can successfully add child nodes to a node, however, I need to see the expand icon beside every new node being added. This is not happening for me. Any child nodes I add render without the expand icon and thus I am unable to go deeper into the tree.
Furthermore, it seems that PF tree component will only display the expand icon it the node has one or more children. However, in my case, I don't know whether a node will have children or not until that node is expanded.
The source code is available at the PimeFaces forum, I am opening this question in the hopes of getting a few more eyes looking at it.
http://forum.primefaces.org/viewtopic.php?f=3&t=34819

I have managed to find a workaround for this.
Everytime I add a new node anywhere on the tree, add a 'dummy' node to it. This will ensure that every new node added will get the expand icon beside. Now, when clicking the expand icon on a node, the backing bean will remove all children and add the real nodes.
There is probably a better way of doing this so I am open to other suggestions but for the time being this will do its job.

Related

Keeping currently selected node at top of treeview

I have a treeview (TVWDB) which has several node, children and grandchildren. Depending on the user these can be shown as just the parent node, or with the children or even grandchildren displayed.
The user steps through this using a button which advances down the tree at the level they have selected (ie if a child is selected then it will step through each child).
Im looking for a way that when the selected item drops down that node is shown at the top of the tree (if there are parents then it should actually be the parent node which is shown.
I keep looking at .Ensurevisible and Getvisible count but this seems to work on the 1st attempt but then start jumping around on each subsequent advance.

Source List collapsed on Start

I have configured a Source List as a sidebar on my app. Problem is when I run it all of the groups are collapsed. How do I fix this?
Yes, an outline view will start with its rows collapsed. (You can configure it to remember the last state, but that doesn't help for the first time and may not be what you want anyway. For example, if you change your program to add more groups.)
You need to add code to expand the rows you want expanded after the outline view has been populated. One place to do this would be in a window controller's -windowDidLoad method or an override of a view controller's -loadView method. Also, almost anywhere that you call -reloadData or -reloadItem:... with the root (nil) item.
If the only expandable rows in your source list are the groups — that is, there are only groups and one level of leaf nodes within the groups — then you can do [outlineView expandItem:nil expandChildren:YES] and that will expand all groups. Otherwise, you need to identify which specific items you want expanded and invoke -expandItem:... on each.

Cutting and pasting nodes in a TreeView control?

I'm looking to implement a cut and paste method to replace drag and drop in a TreeView control. Drag and drop no longer works in the TreeView, and I believe cut and paste will be easier for the people using it. In this TreeView, I will be working with cutting only the child nodes. This object has only parent and child nodes (parent being dates and child nodes being purchase orders.) I'm not sure if there is a cut property and/or paste property to use with treeview1.node.selected or whatever I need to use.
... upon clicking cut it copies the selected node to copynode. then remove the selected node.
so the node is stored in the copynode slot
This won't work as copynode is a reference to the thing you just removed (destroyed) so after removal copynode will point to Nothing.
Instead; when a cut event occurs store the key features of the cut node (text, key, icon index etc.) in to a module level user defined type (or delimited string/class/series of variables) and remove the node. You can then use this data as the basis to construct a new node when a paste event is raised.
(The cut/paste events are not bound to the windows clipboard, rather thay are your own inventions based upon a context menu/detection of ctrl+X/V)
im not sure how to check if the node has children when im pasting to it
if tv.SelectedItem.Children > 0 then
... got child nodes

d3.js : Highlight path upto root node on mouse event of a node

I have created a tree diagram based on http://i.stack.imgur.com/17hpU.jpg
I would like to add a feature which will highlight the path upto root node when any node is selected. As I am new and not know how to define a root as well as how to highlight the path. could someone give some useful links on how to achieve that?

datastructure behind browsing history

Im writing a QML file browser. Now, I want to implement a back and forward function. This function is similar to browser back and forward functionality. Example :
I start in "/home/text/folder1" and browse to "/home/text/folder1/src". Now I browse to "/home/text/folder1/src/java". If I press back twice, I should be at "/home/text/folder1", and I cannot press back anymore (the button should be grayed out or in some other way indicate that there are no more "previous" items to be shown).
I was thinking of implementing this via a double-linked list. However, I am having troubles understanding where I should insert new items to the list, and when I should do it.
Take the previous example :
If instead of pressing back twice, I press back only once (I am now in "/home/text/folder1/src"). If I suddenly go to "/home/text/folder2" , what now? How should my double linked list look now?
This is a datastructure question, and not implementation, so code is not required.
I think your idea using a doubly LinkedList is a good point to start. If you enter a new directory, you add the new item after the current item, discarding the tail of the linked list.
Assume we were in folders 1,2,3 (i.e. we have the list 1->2->[3], square brackets indicating current node). Now we go back twice, resulting in [1]->2->3 if we now go to a new folder 4, we obtain 1->[4], so we have discarded the 2->3 part.
I would have a stack, rather than a list. Every forward navigation puts a link on the stack; every time you go back, you remove the item from the stack.

Resources