Thanks, Greg.

Yep, that seems to be fine now.
This came up as a result of some unit tests I am working on (and plan to
commit soon), so there may well be other similar questions to follow.

Chris

On 14 June 2011 20:01, Greg Brown <[email protected]> wrote:

> Yes, removing a menu bar item should work. The null parent check was
> missing, as was an override of Container#remove(int, int) that prevents a
> caller from removing a menu bar item without going through the items
> sequence. Good catch.
>
> I just checked in a fix - can you verify that it resolves the problem?
>
> Thanks,
> G
>
> On Jun 14, 2011, at 7:29 AM, Chris Bartlett wrote:
>
> > Am I right to think that it should be possible to remove a MenuBar.Item
> from
> > a MenuBar? Or is there something special about MenuBar.Items?
> > This simple test below throws because the MenuBar.Item's parent is set to
> > null when it is removed from the MenuBar.ItemSequence.
> >
> > If you compare the    MenuBar.Item#setParent(Container)     method with
> > Menu.Item#setParent(Container)    you will see that the MenuBar one
> doesn't
> > check for nulls, but the Menu one does.
> >
> http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java
> >
> http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java
> >
> > Changing
> > if (!(parent instanceof MenuBar)) {
> > to
> > if (parent != null && !(parent instanceof MenuBar)) {
> > seems to sort things out.
> >
> > Example
> > MenuBar menuBar = new MenuBar();
> > MenuBar.ItemSequence itemSequence = menuBar.getItems();
> > MenuBar.Item item = new MenuBar.Item("item");
> > itemSequence.add(item);
> > itemSequence.remove(item);
> >
> > Exception in thread "main" java.lang.IllegalArgumentException: Parent
> must
> > be an instance of org.apache.pivot.wtk.MenuBar
> > at org.apache.pivot.wtk.MenuBar$Item.setParent(MenuBar.java:76)
> > at org.apache.pivot.wtk.Container.remove(Container.java:198)
> > at org.apache.pivot.wtk.Container.remove(Container.java:172)
> > at org.apache.pivot.wtk.MenuBar$ItemSequence.remove(MenuBar.java:236)
> > at org.apache.pivot.wtk.MenuBar$ItemSequence.remove(MenuBar.java:222)
> > at pivot.testing.events.RemoveMenuBarItem.main(RemoveMenuBarItem.java:12)
> >
> > Chris
>
>

Reply via email to