private static boolean isProxy(Class clazz) { try { if(BindableProxyFactory.getBindableProxy(clazz) != null) { return true; } } catch (Exception ex) { // Non proxyable class. } return false; } }
/** * 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 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); }
/** * 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)); }
/** * 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)); }
private void ensureProxied() { if (!(proxy instanceof BindableProxy<?>)) { proxy = BindableProxyFactory.getBindableProxy(Assert.notNull(proxy)); } }
private void ensureProxied() { if (!(proxy instanceof BindableProxy<?>)) { proxy = BindableProxyFactory.getBindableProxy(Assert.notNull(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)); }
private void ensureProxied() { if (!(proxy instanceof BindableProxy<?>)) { proxy = BindableProxyFactory.getBindableProxy(Assert.notNull(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)); }
@Override public BindableProxy getProxyDefinition() { return BindableProxyFactory.getBindableProxy(field.getStandaloneClassName()); }
private Object cloneValue(Object value) { if (value == null || isSimpleValue(value)) { return value; } else { BindableProxy bindableProxy = (BindableProxy) BindableProxyFactory.getBindableProxy(value); return bindableProxy.deepUnwrap(); } } }
private static <T> BindableProxy<T> doDeepClone(T instance) { final BindableProxy<T> proxy; if(instance instanceof BindableProxy) { proxy = (BindableProxy<T>) instance; } else { proxy = (BindableProxy<T>) BindableProxyFactory.getBindableProxy(instance); } if(proxy != null) { proxy.getBeanProperties() .entrySet() .stream() .filter(entry -> isProxy(entry.getValue().getType())) .forEach(entry -> deepCloneProxyProperty(proxy, entry.getKey(), entry.getValue())); } return proxy; }
protected Object readPropertyValue(BindableProxy proxy, String fieldBinding) { if (fieldBinding.indexOf(".") != -1) { // Nested property int separatorPosition = fieldBinding.indexOf("."); String nestedModelName = fieldBinding.substring(0, separatorPosition); String property = fieldBinding.substring(separatorPosition + 1); Object nestedModel = proxy.get(nestedModelName); if (nestedModel == null) { return null; } return readPropertyValue((BindableProxy) BindableProxyFactory.getBindableProxy(nestedModel), property); } return proxy.get(fieldBinding); }
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 static PropertyType getPropertyType(final BindableProxy<?> proxy, final String property) { final BindableProxyAgent<?> agent = proxy.getBindableProxyAgent(); if (property.contains(".")) { final int firstDot = property.indexOf("."); final String topLevelProperty = property.substring(0, firstDot); final String childProperty = property.substring(firstDot+1); final PropertyType topLevelType = getPropertyType(proxy, topLevelProperty); final BindableProxy<?> topLevelProxy; if (topLevelType instanceof MapPropertyType) { topLevelProxy = (BindableProxy<?>) DataBinder.forMap(((MapPropertyType) topLevelType).getPropertyTypes()).getModel(); } else { topLevelProxy = BindableProxyFactory.getBindableProxy(topLevelType.getType().getName()); } return getPropertyType(topLevelProxy, childProperty); } else if (agent.propertyTypes.containsKey(property)) { return agent.propertyTypes.get(property); } else { final String type = proxy.getClass().getSuperclass().getSimpleName(); throw new NonExistingPropertyException(type, property); } }
private static PropertyType getPropertyType(final BindableProxy<?> proxy, final String property) { final BindableProxyAgent<?> agent = proxy.getBindableProxyAgent(); if (property.contains(".")) { final int firstDot = property.indexOf("."); final String topLevelProperty = property.substring(0, firstDot); final String childProperty = property.substring(firstDot+1); final PropertyType topLevelType = getPropertyType(proxy, topLevelProperty); final BindableProxy<?> topLevelProxy; if (topLevelType instanceof MapPropertyType) { topLevelProxy = (BindableProxy<?>) DataBinder.forMap(((MapPropertyType) topLevelType).getPropertyTypes()).getModel(); } else { topLevelProxy = BindableProxyFactory.getBindableProxy(topLevelType.getType().getName()); } return getPropertyType(topLevelProxy, childProperty); } else if (agent.propertyTypes.containsKey(property)) { return agent.propertyTypes.get(property); } else { final String type = proxy.getClass().getSuperclass().getSimpleName(); throw new NonExistingPropertyException(type, property); } }
private void doRender(final String domainObjectUUID, final Object domainObject, final Path diagramPath, final FieldChangeHandler changeHandler, final RenderMode renderMode) { final List<String> previousExpandedCollapses = new ArrayList<>(); if (renderer.isInitialized()) { // Collecting expanded collapses from current form to synchronize the new form collapses renderer.getCurrentForm().getFields() .stream() .filter(this::checkCollapsibleGroup) .filter(formField -> ((CollapsibleFormGroup) formField.getContainer()).isExpanded()) .map(FormField::getFieldName) .collect(Collectors.toCollection(() -> previousExpandedCollapses)); LOGGER.fine("Clearing previous form"); renderer.unBind(); } LOGGER.fine("Rendering a new form for element"); Collection<FormElementFilter> filters = FormFiltersProviderFactory.getFilterForDefinition(domainObjectUUID, domainObject); final BindableProxy<?> proxy = (BindableProxy<?>) BindableProxyFactory.getBindableProxy(domainObject); final StaticModelFormRenderingContext generatedCtx = modelGenerator.getContextForModel(proxy.deepUnwrap(), filters.stream().toArray(FormElementFilter[]::new)); final FormRenderingContext<?> pathAwareCtx = new PathAwareFormContext<>(generatedCtx, diagramPath); pathAwareCtx.setRenderMode(renderMode); renderer.render(pathAwareCtx); syncCollapses(previousExpandedCollapses); renderer.addFieldChangeHandler(changeHandler); }