WelcomeTo
WelcomeTo

Reputation: 20581

How to disable all widgets inside Panel or inside Composite?

I have a composite widget, which contain many widgets (inside HorizontalPanel). How to disable all widgets inside HorizontalPanel or inside this composite? I can't find setEnabled() method in Composite or panels

Upvotes: 2

Views: 4117

Answers (3)

Nitin Jadhav
Nitin Jadhav

Reputation: 7306

getWidget() method of Composite class is protected, hence you cant access widgets inside composite from outside packages. Hence you can not get children widgets of Composite without subclassing Composite.

Upvotes: 1

Randy Miller
Randy Miller

Reputation: 81

I'm sure you've already figured it out, but if anyone else is curious, this will enable or disable all nested FocusWidgets:

private void enableAllChildren(boolean enable, Widget widget)
{
    if (widget instanceof HasWidgets)
    {
        Iterator<Widget> iter = ((HasWidgets)widget).iterator();
        while (iter.hasNext())
        {
            Widget nextWidget = iter.next();
            enableAllChildren(enable, nextWidget);
            if (nextWidget instanceof FocusWidget)
            {
                ((FocusWidget)nextWidget).setEnabled(enable);
            }
        }
    }
}

Upvotes: 3

jusio
jusio

Reputation: 9920

The only way to do it is to recursively get all children of the panel and call setEnabled(false) on each widget, which extends FocusWidget

Upvotes: 2

Related Questions