@SuppressWarnings("unchecked") private <T> T maybeUnwrapBindable(T object) { if (object instanceof BindableProxy) { object = (T) ((BindableProxy<T>) object).deepUnwrap(); } return object; } }
private static <T> void deepCloneProxyProperty(BindableProxy<T> proxy, String propertyName, PropertyType type) { Object value = proxy.get(propertyName); if(type.isList() && value != null) { value = doDeepCloneList((List)value); } else { value = doDeepClone(value); } proxy.set(propertyName, value); }
@SuppressWarnings("unchecked") private BindableProxyAgent<T> getAgent() { ensureProxied(); return ((BindableProxy<T>) this.proxy).getBindableProxyAgent(); }
if (proxy.get(bindableProperty) == null) { binder = DataBinder.forType(propertyTypes.get(bindableProperty).getType()); binder = DataBinder.forModel(proxy.get(bindableProperty)); else if (proxy.get(bindableProperty) != null) { binder.setModel(proxy.get(bindableProperty), initialState, true); proxy.set(bindableProperty, binder.getModel()); knownValues.put(bindableProperty, binder.getModel()); ((BindableProxy<?>) binder.getModel()).getBindableProxyAgent().createNestedBinder(property.substring(property.indexOf('.')+1), initialState);
/** * Copies the values of all properties to be able to compare them in case they * change outside a setter method. */ void copyValues() { for (final String property : propertyTypes.keySet()) { if (!"this".equals(property)) { knownValues.put(property, proxy.get(property)); } } }
@SuppressWarnings("unchecked") private void unwrapProxy() { if (proxy instanceof BindableProxy<?>) { proxy = (T) ((BindableProxy<T>) proxy).unwrap(); } }
private Binding createBinding(final Object component, final String property, final Converter converter, final Supplier<Map<Class<? extends GwtEvent>, HandlerRegistration>> handlerRegistrar) { final Binding binding = new Binding(property, component, converter, handlerRegistrar.get()); bindings.put(property, binding); if (propertyTypes.get(property).isList()) { if ("this".equals(property) && proxy instanceof BindableListWrapper) { addHandlersForBindableListWrapper("this", (BindableListWrapper) proxy); } else { proxy.set(property, ensureBoundListIsProxied(property)); } } return binding; }
if (proxy.get(bindableProperty) == null) { binder = DataBinder.forType(propertyTypes.get(bindableProperty).getType()); binder = DataBinder.forModel(proxy.get(bindableProperty)); else if (proxy.get(bindableProperty) != null) { binder.setModel(proxy.get(bindableProperty), initialState, true); proxy.set(bindableProperty, binder.getModel()); knownValues.put(bindableProperty, binder.getModel()); ((BindableProxy<?>) binder.getModel()).getBindableProxyAgent().createNestedBinder(property.substring(property.indexOf('.')+1), initialState);
/** * Copies the values of all properties to be able to compare them in case they * change outside a setter method. */ void copyValues() { for (final String property : propertyTypes.keySet()) { if (!"this".equals(property)) { knownValues.put(property, proxy.get(property)); } } }
@SuppressWarnings("unchecked") private void unwrapProxy() { if (proxy instanceof BindableProxy<?>) { proxy = (T) ((BindableProxy<T>) proxy).unwrap(); } }
private Binding createBinding(final Object component, final String property, final Converter converter, final Supplier<Map<Class<? extends GwtEvent>, HandlerRegistration>> handlerRegistrar) { final Binding binding = new Binding(property, component, converter, handlerRegistrar.get()); bindings.put(property, binding); if (propertyTypes.get(property).isList()) { if ("this".equals(property) && proxy instanceof BindableListWrapper) { addHandlersForBindableListWrapper("this", (BindableListWrapper) proxy); } else { proxy.set(property, ensureBoundListIsProxied(property)); } } return binding; }
private FieldDefinition unwrap(FieldDefinition fieldDefinition) { if (fieldDefinition instanceof BindableProxy) { return ((BindableProxy<FieldDefinition>) fieldDefinition).deepUnwrap(); } return fieldDefinition; }
/** * Updates all bound widgets if necessary (if a bound property's value has * changed). This method is invoked in case a bound property changed outside * the property's write method (when using a non accessor method). */ void updateWidgetsAndFireEvents() { for (final String property : propertyTypes.keySet()) { final Object knownValue = knownValues.get(property); final Object actualValue = proxy.get(property); if ((knownValue == null && actualValue != null) || (knownValue != null && !knownValue.equals(actualValue))) { final DataBinder nestedBinder = binders.get(property); if (nestedBinder != null) { nestedBinder.setModel(actualValue, StateSync.FROM_MODEL, true); proxy.set(property, nestedBinder.getModel()); } updateWidgetsAndFireEvent(true, property, knownValue, actualValue); } } }
@SuppressWarnings("unchecked") private BindableProxyAgent<T> getAgent() { ensureProxied(); return ((BindableProxy<T>) this.proxy).getBindableProxyAgent(); }
/** * Ensures that the given list property is wrapped in a * {@link BindableListWrapper}, so changes to the list become observable. * * @param property * the name of the list property * * @return a new the wrapped (proxied) list or the provided list if already * proxied */ private List ensureBoundListIsProxied(final String property) { final List oldList = (List) proxy.get(property); final List newList = ensureBoundListIsProxied(property, oldList); if (oldList != newList) updateWidgetsAndFireEvent(true, property, proxy.get(property), newList); return newList; }
@SuppressWarnings("unchecked") private void unwrapProxy() { if (proxy instanceof BindableProxy<?>) { proxy = (T) ((BindableProxy<T>) proxy).unwrap(); } }
private void trySettingModelProperty(final String property, final Converter converter, final Object uiValue, final Object newValue) { try { proxy.set(property, newValue); } catch (final Throwable t) { if (newValue == null && isCausedByNullOrUndefined(t)) { /* * Don't fail here because likely this is an error from trying to unbox a null value to a primitive. * XXX Maybe we should check for boxed types before trying to set the property. */ logger.warn("Encountered a null while trying to set the property [" + property + "] to [" + newValue + "].", t); } else { throw new RuntimeException("Error while setting property [" + property + "] to [" + newValue + "] converted from [" + uiValue + "] with converter [" + converter.getComponentType().getName() + " -> " + converter.getModelType().getName() + "].", t); } } }
@Override public Map<String, Object> deepUnwrap() { final Map<String, Object> clone = new HashMap<>(); agent.target.forEach((k,v) -> clone.put(k, (v instanceof BindableProxy ? ((BindableProxy<?>) v).deepUnwrap() : v))); return clone; }
/** * Updates all bound widgets if necessary (if a bound property's value has * changed). This method is invoked in case a bound property changed outside * the property's write method (when using a non accessor method). */ void updateWidgetsAndFireEvents() { for (final String property : propertyTypes.keySet()) { final Object knownValue = knownValues.get(property); final Object actualValue = proxy.get(property); if ((knownValue == null && actualValue != null) || (knownValue != null && !knownValue.equals(actualValue))) { final DataBinder nestedBinder = binders.get(property); if (nestedBinder != null) { nestedBinder.setModel(actualValue, StateSync.FROM_MODEL, true); proxy.set(property, nestedBinder.getModel()); } updateWidgetsAndFireEvent(true, property, knownValue, actualValue); } } }
@SuppressWarnings("unchecked") private BindableProxyAgent<T> getAgent() { ensureProxied(); return ((BindableProxy<T>) this.proxy).getBindableProxyAgent(); }