Search in sources :

Example 1 with OneWayPropertyViewAttribute

use of org.robobinding.viewattribute.property.OneWayPropertyViewAttribute in project RoboBinding by RoboBinding.

the class ViewBindingObjectClassGen method defineSimpleOneWayPropertyClasses.

/**
	 * 
    	private static class ImageAlphaAttribute implements OneWayPropertyViewAttribute<ImageView, Integer> {
    		@Override
    		public void updateView(ImageView view, Integer newValue) {
    			view.setImageAlpha(newValue);
    		}
    	}
     *
	 */
public void defineSimpleOneWayPropertyClasses() {
    for (SimpleOneWayPropertyInfo propInfo : simpleOneWayPropertyInfoList) {
        JDefinedClass definedBindingAttributeClass = propInfo.defineBindingClass(new ClassDefinitionCallback() {

            @Override
            public JDefinedClass define(String typeName) {
                try {
                    return definedClass._class(JMod.PUBLIC | JMod.STATIC, typeName);
                } catch (JClassAlreadyExistsException e) {
                    throw new RuntimeException("Class '" + typeName + "' already exists", e);
                }
            }
        });
        AbstractJClass propertyClass = codeModel.ref(propInfo.propertyType());
        AbstractJClass oneWayPropertyInterface = codeModel.ref(OneWayPropertyViewAttribute.class).narrow(viewClass, propertyClass);
        definedBindingAttributeClass._implements(oneWayPropertyInterface);
        JMethod method = definedBindingAttributeClass.method(JMod.PUBLIC, codeModel.VOID, "updateView");
        method.annotate(Override.class);
        JVar viewParam = method.param(viewClass, "view");
        JVar newValueParam = method.param(propertyClass, "newValue");
        JBlock body = method.body();
        body.invoke(viewParam, propInfo.propertySetter()).arg(newValueParam);
    }
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) JDefinedClass(com.helger.jcodemodel.JDefinedClass) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) OneWayPropertyViewAttribute(org.robobinding.viewattribute.property.OneWayPropertyViewAttribute) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Aggregations

AbstractJClass (com.helger.jcodemodel.AbstractJClass)1 JBlock (com.helger.jcodemodel.JBlock)1 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)1 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1 JMethod (com.helger.jcodemodel.JMethod)1 JVar (com.helger.jcodemodel.JVar)1 OneWayPropertyViewAttribute (org.robobinding.viewattribute.property.OneWayPropertyViewAttribute)1