Best, all!
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 )
------------------------------------------------------------
Store Info
Store 1
Department 1
Department 2
Store 2
Department 1
Department 2
Department 3
Store 3
Department 1
Department 2
------------------------------------------------------------
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?.
Many thanks for your visit, Sir!
Kindly, Robert!