private static boolean isProxy(Class clazz) { try { if(BindableProxyFactory.getBindableProxy(clazz) != null) { return true; } } catch (Exception ex) { // Non proxyable class. } return false; } }
private Object convertToProxy(Object element) { if (BindableProxyFactory.isBindableType(element)) { element = BindableProxyFactory.getBindableProxy(element); final BindableProxyAgent<?> agent = ((BindableProxy<?>) element).getBindableProxyAgent(); if (!elementChangeHandlers.containsKey(agent)) { // Register a property change handler on the element to fire a change // event for the list when the element changes PropertyChangeHandler<Object> handler = new PropertyChangeHandler<Object>() { @Override public void onPropertyChange(PropertyChangeEvent<Object> event) { final int index = list.indexOf(event.getSource()); final List<M> source = new ArrayList<M>(list); if (index == -1) return; // yikes! we do this to alter the source list (otherwise the change event won't get fired). source.add(null); for (BindableListChangeHandler<M> handler : handlers) { handler.onItemChanged(source, index, (M) event.getSource()); } } }; unsubscribeHandlesByHandler.put(handler, agent.addPropertyChangeHandler(handler)); elementChangeHandlers.put(agent, handler); } } return element; }
/** * Returns a proxy for a newly created model instance of the provided type. Changes to the proxy's * state will result in updates on the component given the corresponding property was bound. * * @param bindableType * the bindable type * @return proxy that can be used in place of the model instance. */ @SuppressWarnings("unchecked") public static <T> T getBindableProxy(Class<T> bindableType) { final BindableProxyProvider proxyProvider = getBindableProxyProvider(bindableType); final BindableProxy<?> proxy = proxyProvider.getBindableProxy(); if (proxy == null) { throw new RuntimeException("No proxy instance provided for bindable type: " + bindableType.getName()); } return (T) proxy; }
private boolean isAllowedToClone(Object value) { return Objects.nonNull(value) && (isSimpleValue(value) || BindableProxyFactory.isBindableType(value)); }
/** * Unbinds the property with the given name. * * @param binding * the name of the model property to unbind, must not be null. */ public void unbind(final Binding binding) { final String property = binding.getProperty(); validatePropertyExpr(property); final int dotPos = property.indexOf("."); if (dotPos > 0) { final String bindableProperty = property.substring(0, dotPos); final DataBinder binder = binders.get(bindableProperty); if (binder != null) { final BindableProxyAgent<T> nestedAgent = ((BindableProxy<T>) binder.getModel()).getBindableProxyAgent(); final Collection<Binding> nestedBindings = nestedAgent.bindings.get(property.substring(dotPos + 1)); for (final Binding nestedBinding : nestedBindings.toArray(new Binding[nestedBindings.size()])) { if (binding.getComponent() == nestedBinding.getComponent()) { nestedAgent.unbind(nestedBinding); } } } } binding.removeHandlers(); bindings.remove(property, binding); if (bindings.isEmpty()) { BindableProxyFactory.removeCachedProxyForModel(target); } }
when(propertyAdapter.getId(booleanProperty3)).thenReturn(booleanId); when(propertyAdapter.getId(bindableProperty)).thenReturn(bindablePropertyId); BindableProxyFactory.addBindableProxy(bindablePropertyValue.getClass(), mock(BindableProxyProvider.class)); when(bindablePropertyValue.unwrap()).thenReturn(bindableClonedValue); when(bindablePropertyValue.deepUnwrap()).thenReturn(bindableClonedValue);
private void removeElementChangeHandler(Object element) { if (!BindableProxyFactory.isBindableType(element)) { return; } final BindableProxyAgent<?> agent= ((BindableProxy<?>) element).getBindableProxyAgent(); removeElementChangeHandler(agent); }
/** * Unbinds the property with the given name. * * @param binding * the name of the model property to unbind, must not be null. */ public void unbind(final Binding binding) { final String property = binding.getProperty(); validatePropertyExpr(property); final int dotPos = property.indexOf("."); if (dotPos > 0) { final String bindableProperty = property.substring(0, dotPos); final DataBinder binder = binders.get(bindableProperty); if (binder != null) { final BindableProxyAgent<T> nestedAgent = ((BindableProxy<T>) binder.getModel()).getBindableProxyAgent(); final Collection<Binding> nestedBindings = nestedAgent.bindings.get(property.substring(dotPos + 1)); for (final Binding nestedBinding : nestedBindings.toArray(new Binding[nestedBindings.size()])) { if (binding.getComponent() == nestedBinding.getComponent()) { nestedAgent.unbind(nestedBinding); } } } } binding.removeHandlers(); bindings.remove(property, binding); if (bindings.isEmpty()) { BindableProxyFactory.removeCachedProxyForModel(target); } }
/** * Returns a proxy for a newly created model instance of the provided type. Changes to the proxy's * state will result in updates on the widget given the corresponding property was bound. * * @param bindableType * The fully qualified name of the bindable type * @return proxy that can be used in place of the model instance. */ public static BindableProxy<?> getBindableProxy(String bindableType) { final Class<?> bindableClass = bindableTypes.get(bindableType); return (BindableProxy<?>) getBindableProxy(bindableClass); }
private Object convertToProxy(Object element) { if (BindableProxyFactory.isBindableType(element)) { element = BindableProxyFactory.getBindableProxy(element); final BindableProxyAgent<?> agent = ((BindableProxy<?>) element).getBindableProxyAgent(); if (!elementChangeHandlers.containsKey(agent)) { // Register a property change handler on the element to fire a change // event for the list when the element changes PropertyChangeHandler<Object> handler = new PropertyChangeHandler<Object>() { @Override public void onPropertyChange(PropertyChangeEvent<Object> event) { final int index = list.indexOf(event.getSource()); final List<M> source = new ArrayList<M>(list); if (index == -1) return; // yikes! we do this to alter the source list (otherwise the change event won't get fired). source.add(null); for (BindableListChangeHandler<M> handler : handlers) { handler.onItemChanged(source, index, (M) event.getSource()); } } }; unsubscribeHandlesByHandler.put(handler, agent.addPropertyChangeHandler(handler)); elementChangeHandlers.put(agent, handler); } } return element; }
private void removeElementChangeHandler(Object element) { if (!BindableProxyFactory.isBindableType(element)) { return; } final BindableProxyAgent<?> agent= ((BindableProxy<?>) element).getBindableProxyAgent(); removeElementChangeHandler(agent); }
/** * Returns a proxy for a newly created model instance of the provided type. Changes to the proxy's * state will result in updates on the component given the corresponding property was bound. * * @param bindableType * the bindable type * @return proxy that can be used in place of the model instance. */ @SuppressWarnings("unchecked") public static <T> T getBindableProxy(Class<T> bindableType) { final BindableProxyProvider proxyProvider = getBindableProxyProvider(bindableType); final BindableProxy<?> proxy = proxyProvider.getBindableProxy(); if (proxy == null) { throw new RuntimeException("No proxy instance provided for bindable type: " + bindableType.getName()); } return (T) proxy; }
/** * Returns a proxy for a newly created model instance of the provided type. Changes to the proxy's * state will result in updates on the widget given the corresponding property was bound. * * @param bindableType * The fully qualified name of the bindable type * @return proxy that can be used in place of the model instance. */ public static BindableProxy<?> getBindableProxy(String bindableType) { final Class<?> bindableClass = bindableTypes.get(bindableType); return (BindableProxy<?>) getBindableProxy(bindableClass); }
/** * Returns a new proxy for the provided model instance. Changes to the proxy's state will result * in updates on the widget given the corresponding property was bound. * * @param <T> * the bindable type * @param model * The model instance to proxy, must not be null. * @return proxy that can be used in place of the model instance. */ @SuppressWarnings("unchecked") public static <T> T getBindableProxy(T model) { Assert.notNull(model); if (model instanceof BindableProxy) return model; BindableProxy<?> proxy = proxies.get(model); if (proxy == null) { final Class<? extends Object> modelClass = (model instanceof List ? List.class : model.getClass()); final BindableProxyProvider proxyProvider = getBindableProxyProvider(modelClass); proxy = proxyProvider.getBindableProxy(model); if (proxy == null) { throw new RuntimeException("No proxy instance provided for bindable type: " + modelClass.getName()); } proxies.put(model, proxy); } return (T) proxy; }
/** * Creates a {@link DataBinder} for the provided model instance. * * @param model * The instance of a {@link Bindable} type, must not be null. */ private DataBinder(final T model) { this.proxy = BindableProxyFactory.getBindableProxy(Assert.notNull(model)); }
/** * Returns a new proxy for the provided model instance. Changes to the proxy's state will result * in updates on the widget given the corresponding property was bound. * * @param <T> * the bindable type * @param model * The model instance to proxy, must not be null. * @return proxy that can be used in place of the model instance. */ @SuppressWarnings("unchecked") public static <T> T getBindableProxy(T model) { Assert.notNull(model); if (model instanceof BindableProxy) return model; BindableProxy<?> proxy = proxies.get(model); if (proxy == null) { final Class<? extends Object> modelClass = (model instanceof List ? List.class : model.getClass()); final BindableProxyProvider proxyProvider = getBindableProxyProvider(modelClass); proxy = proxyProvider.getBindableProxy(model); if (proxy == null) { throw new RuntimeException("No proxy instance provided for bindable type: " + modelClass.getName()); } proxies.put(model, proxy); } return (T) proxy; }
/** * Creates a {@link DataBinder} for a new model instance of the provided type * (see {@link #forType(Class)}). * * @param modelType * The bindable type, must not be null. */ private DataBinder(final Class<T> modelType) { this.proxy = BindableProxyFactory.getBindableProxy(Assert.notNull(modelType)); }
/** * Creates a {@link DataBinder} for the provided model instance. * * @param model * The instance of a {@link Bindable} type, must not be null. */ private DataBinder(final T model) { this.proxy = BindableProxyFactory.getBindableProxy(Assert.notNull(model)); }
/** * Creates a {@link DataBinder} for the provided model instance. * * @param model * The instance of a {@link Bindable} type, must not be null. */ private DataBinder(final T model) { this.proxy = BindableProxyFactory.getBindableProxy(Assert.notNull(model)); }
private void ensureProxied() { if (!(proxy instanceof BindableProxy<?>)) { proxy = BindableProxyFactory.getBindableProxy(Assert.notNull(proxy)); } }