First of all I must say that this problem that I have encountered is of a very complex nature to me. I am terrible at explaining my problems here in english so have patience with me. Also forgive me if I don't have any code at the moment to post here to demonstrate the problem from that point of view. I have mainly only questions. And I am not
sure on my reasoning or logic.
With that said I have a project in which I have a JTree that is populated with parent nodes that has user objects which can contain user defined information about stores of different kind, like their respective type of branch, number of employees and their financial income per year and so on. The user inserts theese with the click of a button in a form in a JDialog. The information in the store info nodes are displayed in that fore mentioned form. The user can also insert child nodes to theese Store nodes and they are called Department nodes. So I have a JTree that consists of Store and Department - nodes.
I know how to traverse or loop though a JTree, insert and remove nodes from the model and I always reload the model after each such action. My problem is how to code a counter that let the user know at which store info node he or she is at. This counter should increment for every new store info node the user adds to the model and for every deletion of a store info node the counter should move back up.
Example of JTree - structure ( during insert - mode )
The user edits the names of the stores and departments in the form that is presented to him or her in add mode. My problem like my question is that I don't know how to write the counter that must be displayed in each Store node after the user have added one to the model of the JTree. If the user deletes Store 2 then I want the counter to remember that node 2 was deleted were three Store nodes in the JTree so it starts to count from 3 when the next Store node is inserted by the user. Can a helpful soul here push me in the right direction. I am completely stuck and time limited. I hope I have not been to complicated thoughout theese lines.
I should mention that I am looking in to the TreeModelListener interface and is experimenting around with the treeNodesInserted -and treeNodesRemoved - methods, would that be in the right direction?.
If I understand correctly, when the user enters Store information from the JDialog, it goes into the JTree with a name like "Store 7". Later the user gets to change the name to something more meaningful.
But you're having trouble generating the name "Store 7" and you think you need a counter to help you with that.
What I don't understand is, when the user puts the Store information into the JDialog, why can't that information include the store name? Then you don't need any counters and the user gets to input all of the data in the same place.
Probably I'm misunderstanding something.
As for the counter, if you really need it then my approach would be to put the counter into the node which is the parent of the nodes which need to have the numbers attached to them.