0

Hint: rebuilding a dynamic grid with dynamic headers

asked 2012-12-15 08:31:36 +0800

bbrand gravatar image bbrand
98 3

updated 2012-12-15 08:32:12 +0800

I have a grid where the contents fully depend on what the user selected elsewhere. Not only can the contents change but also the complete layout and headers of the grid. I was struggling to find a way to "clean out" the current contents of the grid before rebuilding as per the requirements of the user. After playing around for a while I came up with the following. This will "clean up" the grid and allow you to start afresh with defining new (aux)headers and columns. Comments welcome.

        Grid myGrid;
        ....
        List<Component> cList = myGrid.getChildren();
        ArrayList<Component> deleteList = new ArrayList();
        for (Component c : cList) {
            if (!c.getChildren().isEmpty()) { // == parent
                deleteList.add(c);
            }
        }
        for (Component c : deleteList) {
            myGrid.removeChild(c);
        }
        ....

The "trick" is that you should only remove parent components from the grid component as these also remove the children. If you attempt to do this in just one loop the List gets out of sync with what the Grid component actually contains. You might be trying to remove a child component that has already been deleted through the removal of the parent. Hence I identify the parents first and only remove them.
Is there an shorter version of this out there?

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2012-12-17 05:15:43 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Are you looking something this

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-12-15 08:31:36 +0800

Seen: 40 times

Last updated: Dec 17 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More