/** * attach internal data-mediator-callback to target delegate * @param delegate mediator delegate * @param strict true if attach strictly * @return true if attach success. always return true if strict is false. */ public boolean attach(MediatorDelegate<T> delegate, boolean strict){ if(!strict){ delegate.getDataMediator().addDataMediatorCallback(mCallback); return true; }else { if (mState.containsMediatorDelegate(delegate)) { delegate.getDataMediator().addDataMediatorCallback(mCallback); return true; } } return false; } /**
/** * attach internal data-mediator-callback to target delegate * @param delegate mediator delegate * @param strict true if attach strictly * @return true if attach success. always return true if strict is false. */ public boolean attach(MediatorDelegate<T> delegate, boolean strict){ if(!strict){ delegate.getDataMediator().addDataMediatorCallback(mCallback); return true; }else { if (mState.containsMediatorDelegate(delegate)) { delegate.getDataMediator().addDataMediatorCallback(mCallback); return true; } } return false; } /**
@Override protected void onInit(Context context, Bundle savedInstanceState) { mBt_changeProperty.setText("click this to change property"); mBt_temp.setVisibility(View.GONE); //为数据模型创建 中介者。 mMediator = DataMediatorFactory.createDataMediator(Student.class); //添加属性callback mMediator.addDataMediatorCallback(new DataMediatorCallback<Student>() { @Override public void onPropertyValueChanged(Student data, Property prop, Object oldValue, Object newValue) { Logger.w("TestPropertyChangeActivity","onPropertyValueChanged","prop = " + prop.getName() + " ,oldValue = " + oldValue + " ,newValue = " + newValue); mTv_desc.setText(String.valueOf(newValue)); } }); mMediator.getDataProxy().setName("heaven7"); }
target.addDataMediatorCallback(inflateCallback);
target.addDataMediatorCallback(inflateCallback);
public static <T> void bindDouble(final DataMediator<T> mediator, TextView tv, final String propertyName){ DataMediatorCallbackImpl<T> callback = new DataMediatorCallbackImpl<>(tv, propertyName); TextWatcherAdapterImpl<T> watcher = new TextWatcherAdapterImpl<>(tv, mediator, propertyName); callback.attachWatcher(watcher); mediator.addDataMediatorCallback(callback); tv.addTextChangedListener(watcher); }
@Override protected void onInit(Context context, Bundle savedInstanceState) { mDm = DataMediatorFactory.createDataMediator(TestBind.class); // 这里直接用属性回调。也可以用binder.bind(String property, SparseArrayPropertyCallback<? super T> callback)方法 mDm.addDataMediatorCallback(DataMediatorCallback.createForSparse( TestBind.PROP_cityData2.getName(), new CallbackImpl())); }
/** * bind the property callback as Sparse({@linkplain com.heaven7.java.base.util.SparseArray}) * for target property. * @param property the property. like 'name' of student. * @param callback the property callback of sparse array. * @return this. * @see com.heaven7.java.base.util.SparseArray * @since 1.1.3 */ public Binder<T> bind(String property, SparseArrayPropertyCallback<? super T> callback){ DataMediatorCallback<T> temp = DataMediatorCallback.createForSparse(property, callback); if(callback instanceof Tagable){ Object tag = ((Tagable) callback).getTag(); put2Cache(tag, temp); } mMediator.addDataMediatorCallback(temp); return this; }
/** * bind the property callback as Sparse({@linkplain com.heaven7.java.base.util.SparseArray}) * for target property. * @param property the property. like 'name' of student. * @param callback the property callback of sparse array. * @return this. * @see com.heaven7.java.base.util.SparseArray * @since 1.1.3 */ public Binder<T> bind(String property, SparseArrayPropertyCallback<? super T> callback){ DataMediatorCallback<T> temp = DataMediatorCallback.createForSparse(property, callback); if(callback instanceof Tagable){ Object tag = ((Tagable) callback).getTag(); put2Cache(tag, temp); } mMediator.addDataMediatorCallback(temp); return this; }
/** * bind the property callback for target property. * @param property the property. like 'name' of student. * @param callback the property callback of binder * @return this. */ public Binder<T> bind(String property, BinderCallback<? super T> callback){ DataMediatorCallback<T> temp = DataMediatorCallback.create(property, callback); if(callback.getTag() != null){ put2Cache(callback.getTag(), temp); } mMediator.addDataMediatorCallback(temp); return this; } /**
private void setMutexValue(GroupProperty target, MediatorDelegate<T> md) { DataMediator<T> mediator = md.getDataMediator(); //before mutex we should just remove this callback for reduce unnecessary callback. mediator.removeDataMediatorCallback(mCallback); T proxy = mediator.getDataProxy(); Object value = ReflectUtils.getValue(target.prop, proxy); setMutexValue0(target, proxy, value); //restore mediator.addDataMediatorCallback(mCallback); }
/** * bind the property callback for target property. * @param property the property. like 'name' of student. * @param callback the property callback of binder * @return this. */ public Binder<T> bind(String property, BinderCallback<? super T> callback){ DataMediatorCallback<T> temp = DataMediatorCallback.create(property, callback); if(callback.getTag() != null){ put2Cache(callback.getTag(), temp); } mMediator.addDataMediatorCallback(temp); return this; } /**
private void setMutexValue(GroupProperty target, MediatorDelegate<T> md) { DataMediator<T> mediator = md.getDataMediator(); //before mutex we should just remove this callback for reduce unnecessary callback. mediator.removeDataMediatorCallback(mCallback); T proxy = mediator.getDataProxy(); Object value = ReflectUtils.getValue(target.prop, proxy); setMutexValue0(target, proxy, value); //restore mediator.addDataMediatorCallback(mCallback); }
public Object getData(String propertyChain){ final TreeInfo treeInfo = parse(propertyChain); DataMediator dm = treeInfo.resolve(root); //TODO dm.addDataMediatorCallback(new DataMediatorCallback() { @Override public void onPropertyValueChanged(Object data, Property prop, Object oldValue, Object newValue) { if(prop.getName().equals(treeInfo.lastSecondNode.prop)){ //virtual property // dm.getBaseMediator().dispatchValueChanged(prop, oldValue, newValue); } } }); return null; }
public Object getData(String propertyChain){ final TreeInfo treeInfo = parse(propertyChain); DataMediator dm = treeInfo.resolve(root); //TODO dm.addDataMediatorCallback(new DataMediatorCallback() { @Override public void onPropertyValueChanged(Object data, Property prop, Object oldValue, Object newValue) { if(prop.getName().equals(treeInfo.lastSecondNode.prop)){ //virtual property // dm.getBaseMediator().dispatchValueChanged(prop, oldValue, newValue); } } }); return null; }
private void testList1() { //@BindXXX("stus[0].name?") DataMediator<TestItem> dm = DataMediatorFactory.createDataMediator(TestItem.class); Student student = dm.getData().getTestItem_3().get(0); DataMediator<Student> dm_stu = DataMediatorFactory.createDataMediator(student); String stuPropName = "name"; dm_stu.addDataMediatorCallback(new DataMediatorCallback<Student>() { @Override public void onPropertyValueChanged(Student data, Property prop, Object oldValue, Object newValue) { if(prop.getName().equals(stuPropName)){ //virtual property dm.getBaseMediator().dispatchValueChanged(prop, oldValue, newValue); } } }); }
public TestListPropertyChange(){ mDm_flowitem = DataMediatorFactory.createDataMediator(FlowItem.class); mDm_flowitem.addDataMediatorCallback(DataMediatorCallback.create( FlowItem.PROP_desc.getName(), new ListPropertyCallbackImpl())); }
private void testSimple() { //@BindXXX("stu.name") DataMediator<TestItem> dm = DataMediatorFactory.createDataMediator(TestItem.class); DataMediator<Student> dm_stu = DataMediatorFactory.createDataMediator(dm.getData().getTestItem_1()); String stuPropName = "name"; dm_stu.addDataMediatorCallback(new DataMediatorCallback<Student>() { @Override public void onPropertyValueChanged(Student data, Property prop, Object oldValue, Object newValue) { if(prop.getName().equals(stuPropName)){ //virtual property dm.getBaseMediator().dispatchValueChanged(prop, oldValue, newValue); } } }); }
private void testList2() { //@BindXXX("stu.tags") DataMediator<TestItem> dm = DataMediatorFactory.createDataMediator(TestItem.class); DataMediator<Student> dm_stu = DataMediatorFactory.createDataMediator(dm.getData().getTestItem_1()); dm_stu.addDataMediatorCallback(DataMediatorCallback.create("tags", new ListPropertyCallback<Student>() { @Override public void onPropertyValueChanged(Student data, Property prop, Object oldValue, Object newValue) { } @Override public void onPropertyApplied(Student data, Property prop, Object value) { } @Override public void onAddPropertyValues(Student data, Property prop, Object newValue, Object addedValue) { } @Override public void onAddPropertyValuesWithIndex(Student data, Property prop, Object newValue, Object addedValue, int index) { } @Override public void onRemovePropertyValues(Student data, Property prop, Object newValue, Object removeValue) { } @Override public void onPropertyItemChanged(Student data, Property prop, Object oldItem, Object newItem, int index) { } })); }
dm_child.addDataMediatorCallback(callback); dm_child.getDataProxy().setTest_int(100);