I’ve been having trouble getting the Tree View component to not collapse all the nodes when the .data property changes. In my application, I am keeping all the names/paths consistent but would like to change the icons of each item (can be a leaf or branch) in realtime (I have a view that handles returning a certain icon path based on a tag value in the sqlt_core table). The goal here is to use the tree to monitor digital inputs.
The programming behind changing the icon works fine, but when the data changes in the tree everything collapses. I came up with a workaround, but it’s not perfect. It ‘flickers’ to everything collapsed before re-expanding the appropriate nodes every time the datachange script runs. If I don’t use system.util.invokeLater(), the script will try to expand the rows when they are already expanded, and then collapse them all when the data refreshes.
I’ve essentially obtained the JTree component from the PMITreeView object using .getViewport().getView() and loop through all the rows to find those that are expanded (using JTree.isExpanded(row)).
The Java documentation I based this off of can be found here: http://docs.oracle.com/javase/6/docs/api/javax/swing/JTree.html
For all I know this could be a completely incorrect approach, and if anyone knows a better approach or a Java method/property of JTree that can prevent this from happening please let me know. Thanks in advance!
Here is the code that is 99% correct except for the ‘flickering’
if event.propertyName == 'data':
JTree = event.source.getViewport().getView()
rowCount = JTree.getRowCount()
expandedRows = 
for r in range(rowCount):
isExpanded = JTree.isExpanded(r)
def update(event=event, expandedRows=expandedRows, JTree=JTree):
for r in expandedRows:
Edit: I should also mention that for some reason there is no more flickering, but I wouldn’t be surprised if it started happening again. Something tells me there is a better way to do this.
First of all - nice work with what you did on your own. What you’ve done is really the best way to do it with what you’ve been given.
The “real” solution to this issue needs to come from us. The problem is that the tree gets the information for its tree model from a dataset, and so, whenever you want to update the tree you need to set the tree’s dataset. But the tree isn’t very smart about this, and considers a new dataset to potentially be an entirely new data model, and so replaces it’s existing data model. Hence the collapsing nodes.
What we should do as a feature enhancement to the tree is have the tree compare the old dataset to the new dataset row-by-row, and if the structure of the dataset is identical, simply update the existing model with any new text/color/images. This would preserve the users current selection/expansion.
I’ve put in a ticket to make this change, but I can’t quite say when it might make it in.
Carl, I posted somewhere else about the Tree View and asked for a selectable starting expansion level instead of it just assuming you want no expansion or full expansion. In other words, if you have four levels, and you want the tree to come up by default expanded to level 2, but level 3 and 4 collapsed, you could enter a 2 in an ExpansionLevel property, or something similar.
The ultimate would be to also have in the dataset, for each level in each path, a boolean bit that, if true, would show that level expanded, or collapsed if false. These could be stored in the table that the Tree View query is bound to. A user could expand just what he needs to see on the tree, and collapse the rest. When he closes the app, a Shutdown Intercept Client Event Script could save his current Tree View dataset back to the SQL table so that the next time he opens that window, the tree looks just as it did when he closed it.
I’m doing this with the Easy Chart Pens and Axes datasets that I have bound to SQL tables so the user doesn’t have to turn on or off pens or change colors every time he uses the Easy Chart. Options, options, options. We’re never happy with the ones we have, eh Carl?
Truer words were never spoken.
This change has been made for version 7.6.4.
I am using 8.1.0 and I am having the same issue. As soon as the Trees PROPS items is updated, then the tree collapse. Was this resolved and I am doing something wrong?
Is it resolved, If resolved then can you provide solution here,
I am using 8.1.15 and I am having the same issue..