PDA

View Full Version : Can't remove Tools from StartMenu



egotec
28 Jul 2010, 12:34 AM
Hello.

Can anyone help me removing all tool items from a menu.
I simply added them like this:

MenuItem tool = new MenuItem(CONSTANTS.admin());
menu.addTool(tool);

And just want to remove them. This code doesn't do it:

desktop.getStartMenu().removeAll();

There's no method like getTools() or removeAllTools()...

Even these code lines doen't remove the tools:

for (Component el : desktop.getTaskBar().getStartMenu().getItems()) {
desktop.getTaskBar().getStartMenu().remove(el);
}

Thanks.

Jonas Gehring

sven
28 Jul 2010, 12:42 AM
tools != items.

There is no buildin way to remove tools.

Keep a reference to the tool. Than do:


ComponentHelper.doDetach(tool);
if(tool.isRendered()){
tool.el().getParent().remove();
}

This is untested. You also need to clear the parent relationship

egotec
28 Jul 2010, 2:10 AM
thanks.

But this also doen't affect anything...

I tried this code:


ComponentHelper.doDetach(tool);
if (tool.isRendered()) {
tool.el().getParent().remove();
}
tool.removeFromParent();


hmm... I could work around this problem in my application, but maybe I need it later or others need it...

sven
28 Jul 2010, 2:14 AM
I just tested ti and it works very well after rendering.

egotec
28 Jul 2010, 2:39 AM
Now I found the mistake.
It only works, if the menu was opened at least one time.
But if I never opened the menu before I remove the tool, it doesn't work because the item was not rendered.

This works properly:

ComponentHelper.doDetach(tool);
if (!tool.isRendered()) {
tool.render(desktop.getStartMenu().getElement());
}
tool.el().getParent().remove();
tool.removeFromParent();

Thanks a lot.

(thread closed)