Search in sources :

Example 1 with AbstractPresentationModelObject

use of org.robobinding.presentationmodel.AbstractPresentationModelObject in project RoboBinding by RoboBinding.

the class PresentationModelObjectLoader method load.

public AbstractPresentationModelObject load(Object presentationModel) {
    if (presentationModel instanceof HasPresentationModelChangeSupport) {
        Preconditions.checkNotNull(((HasPresentationModelChangeSupport) presentationModel).getPresentationModelChangeSupport(), "The PresentationModelChangeSupport from presentationModel.getPresentationModelChangeSupport() must not be null");
    }
    String presentationModelObjectClassName = getObjectClassName(presentationModel.getClass().getName());
    Class<?> presentationModelObjectType;
    try {
        presentationModelObjectType = Class.forName(presentationModelObjectClassName);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(MessageFormat.format("The source code for ''{0}'' is not generated. Is Java annotation processing(source code generation) correctly configured?", presentationModelObjectClassName));
    }
    try {
        return (AbstractPresentationModelObject) ConstructorUtils.invokeConstructor(presentationModelObjectType, presentationModel);
    } catch (NoSuchMethodException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (IllegalAccessException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (InvocationTargetException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (InstantiationException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    }
}
Also used : Bug(org.robobinding.Bug) AbstractPresentationModelObject(org.robobinding.presentationmodel.AbstractPresentationModelObject) HasPresentationModelChangeSupport(org.robobinding.presentationmodel.HasPresentationModelChangeSupport) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with AbstractPresentationModelObject

use of org.robobinding.presentationmodel.AbstractPresentationModelObject in project RoboBinding by RoboBinding.

the class DataSetAdapter method newView.

private View newView(int position, ViewGroup parent, DisplayType displayType) {
    BindableView bindableView;
    Object item = getItem(position);
    if (displayType == DisplayType.ITEM_LAYOUT) {
        int layoutId = itemLayoutSelector.selectLayout(getItemViewType(position));
        bindableView = itemLayoutBinder.inflate(parent, layoutId);
    } else {
        bindableView = dropdownLayoutBinder.inflate(parent, dropdownLayoutId);
    }
    View view = bindableView.getRootView();
    RefreshableItemPresentationModel itemPresentationModel = dataSetValueModel.newRefreshableItemPresentationModel(getItemViewType(position));
    itemPresentationModel.updateData(item, new ItemContext(view, position));
    bindableView.bindTo((AbstractPresentationModelObject) itemPresentationModel);
    ViewTag<RefreshableItemPresentationModel> viewTag = viewTags.tagFor(view);
    viewTag.set(itemPresentationModel);
    return view;
}
Also used : ItemContext(org.robobinding.itempresentationmodel.ItemContext) RefreshableItemPresentationModel(org.robobinding.itempresentationmodel.RefreshableItemPresentationModel) BindableView(org.robobinding.BindableView) AbstractPresentationModelObject(org.robobinding.presentationmodel.AbstractPresentationModelObject) BindableView(org.robobinding.BindableView) View(android.view.View)

Aggregations

AbstractPresentationModelObject (org.robobinding.presentationmodel.AbstractPresentationModelObject)2 View (android.view.View)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BindableView (org.robobinding.BindableView)1 Bug (org.robobinding.Bug)1 ItemContext (org.robobinding.itempresentationmodel.ItemContext)1 RefreshableItemPresentationModel (org.robobinding.itempresentationmodel.RefreshableItemPresentationModel)1 HasPresentationModelChangeSupport (org.robobinding.presentationmodel.HasPresentationModelChangeSupport)1