class MenuUtils {

    public static MenuItem buildItem(final IsWidget widget) {
        return new MenuFactory.CustomMenuBuilder() {
            @Override
            public void push(MenuFactory.CustomMenuBuilder element) {
            }

            @Override
            public MenuItem build() {
                return new BaseMenuCustom<Widget>() {
                    @Override
                    public Widget build() {
                        return widget.asWidget();
                    }

                    @Override
                    public boolean isEnabled() {
                        if (widget instanceof HasEnabledIsWidget) {
                            return ((HasEnabledIsWidget) widget).isEnabled();
                        } else {
                            return super.isEnabled();
                        }
                    }

                    @Override
                    public void setEnabled(boolean enabled) {
                        if (widget instanceof HasEnabledIsWidget) {
                            ((HasEnabledIsWidget) widget).setEnabled(enabled);
                        } else {
                            super.setEnabled(enabled);
                        }
                    }
                };
            }
        }.build();
    }

}