1

I have a Tree structure on my swing UI. Each object in the Tree represents a element in the network. The elements in the network have alarms raised on it. Alarms (one or more) are represented in the UI with a bell image besides the network element. I use a Cache (TreeMap) to store the network elements with the name of the network element as the KEY and Alarms as Value. However, traversing the TreeMap is pretty in-efficient. The names of the network element are Strings. I would like to store the elements in a parent-child relation (like the real UI) and the STRING names fail to do that.

I would like to create a custom data-structure which would emulate my UI hierarchy. I would think that customising linked list would do the job for me. Is there any tried and tested data-structure which I can use? Any other opinions highly appreciated.

TheMonkWhoSoldHisCode
  • 2,182
  • 3
  • 26
  • 40
  • How about a class `Node` with members `T value` and `List> children`? Also see [this question](http://stackoverflow.com/q/3522454/1639625) – tobias_k Aug 10 '14 at 18:00
  • @tobias_k I was thinking on similar lines. The questions stems from the fact that this should be a every day scenario on UI applications. Isn't there something ready made (some library) which would help me , rather than I reinventing the wheel. – TheMonkWhoSoldHisCode Aug 10 '14 at 18:03
  • 1
    In this case, how about using Swing's [`TreeModel`](http://docs.oracle.com/javase/7/docs/api/javax/swing/tree/TreeModel.html)? Particularly if you need the tree only for the GUI anyway... – tobias_k Aug 10 '14 at 18:14
  • Also see [this tutorial](http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html)... – tobias_k Aug 10 '14 at 18:20
  • 2
    Isn't javax.swing.tree.DefaultTreeModel meant to provide the background for the JTree? And a subclass of it can handle any additional gimmicks you might require. – laune Aug 10 '14 at 18:21

1 Answers1

0

Use domain objects for your data structure ("model"), with classes like Site, Host, Application, NetworkLink etc. Then you can have methods like clearAlarms() and properties like getState() and getName().

eckes
  • 10,103
  • 1
  • 59
  • 71
  • that is a good idea. But there are hundreds of unique elements in the network. Also, its a legacy application, so I am afraid I would be allowed to add so many classes now. – TheMonkWhoSoldHisCode Aug 10 '14 at 18:08
  • 1
    Well, I guess you cant introduce another generic data stucture either then. You might be able to sell a rewrite, just think what you can gain from using a data model. A middle ground between your own domain objects and generic data structures would be something like [EMF](http://www.eclipse.org/modeling/emf/) which does come with DSL and tree views, graphical panes and schema workbench. – eckes Aug 10 '14 at 18:13