/** * Binds an event of this view model to an action of a menu item in its layout. * * @param menuId The id of the target menu item. * @param eventType The event arg class to bind. * @param action The action of the target menu item. * @return The created binding. */ @Override protected Binding bindAction(int menuId, Class<? extends EventArg> eventType, String action) { Preconditions.checkArgument( ThreadUtil.isUiThread(), "MenuViewModel.bindAction can only be called from the UI thread"); Preconditions.checkNotNull(eventType); Preconditions.checkNotNull(action); MenuItem targetItem = menu.findItem(menuId); ComponentAdapter adapter = ComponentAdapter.get(targetItem); Binding binding = Binding.bindAction(adapter, this, eventType, action); return binding; }
/** * Bind a property of this view model to a property of a menu item in its layout. * * @param property The property of the view model * @param menuId The id of the target menu item. * @param menuProperty The property of the target menu item. * @param valueConverter The value converter to use for conversion. * @param bindMode The bind mode to use. * @return The created binding. */ @Override protected final Binding bindProperty( String property, int menuId, String menuProperty, ValueConverter valueConverter, BindMode bindMode) { Preconditions.checkArgument( ThreadUtil.isUiThread(), "MenuViewModel.bindProperty can only be called from the UI thread"); Preconditions.checkNotNull(property); Preconditions.checkNotNull(menuProperty); Preconditions.checkNotNull(valueConverter); Preconditions.checkNotNull(bindMode); MenuItem targetItem = menu.findItem(menuId); ComponentAdapter adapter = ComponentAdapter.get(targetItem); Binding binding = Binding.bindProperty(this, property, adapter, menuProperty, valueConverter, bindMode); return binding; }