/** * {@inheritDoc} */ @Override public boolean isWritable() { boolean writable = super.isWritable(); if (accessor != null) { writable = writable && accessor.isWritable(); } if (getModelProvider() != null) { writable = writable && getModelProvider().getModel() != null; } return writable; }
/** * Since model provider is usually the parent connector for this kind of * connector, this method is overloaded to call the * {@code modelProviderChanged} method. * <p> * {@inheritDoc} */ @Override public void setParentConnector(ICompositeValueConnector parentConnector) { IModelProvider oldModelProvider = getModelProvider(); super.setParentConnector(parentConnector); modelProviderChanged(oldModelProvider); }
/** * Accesses the underlying model property and gets its value. * <p> * {@inheritDoc} */ @Override protected Object getConnecteeValue() { try { return accessor.getValue(getModelProvider().getModel()); } catch (IllegalAccessException ex) { throw new ConnectorBindingException(ex); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new ConnectorBindingException(ex.getCause()); } catch (NoSuchMethodException ex) { // this may be a normal behaviour in case of polymorphism. // don't throw any exception. // throw new ConnectorBindingException(ex); return null; } }
oldModelProvider.removeModelChangeListener(this); if (getModelProvider() != null) { getModelProvider().addModelChangeListener(this); newModel = getModelProvider().getModel(); modelChange(new ModelChangeEvent(getModelProvider(), oldModel, newModel));
/** * Accesses the underlying model property and sets its value. * <p> * {@inheritDoc} */ @Override protected void setConnecteeValue(Object aValue) { if (!ObjectUtils.equals(aValue, getConnecteeValue())) { try { accessor.setValue(getModelProvider().getModel(), aValue); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new ConnectorBindingException(ex); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new ConnectorBindingException(ex.getCause()); } } } }
private void recomputeAccessor(Object newModel) { if (isValueAccessedAsProperty() && getModelProvider() != null && accessorFactory != null && (accessor == null || !accessor.appliesTo(newModel))) { Class<?> modelType = null; try { if (newModel != null) { if (newModel instanceof IComponent) { modelType = ((IComponent) newModel).getComponentContract(); } else { modelType = newModel.getClass(); } } else { modelType = getModelProvider().getModelDescriptor().getModelType(); } accessor = accessorFactory.createPropertyAccessor(getId(), modelType); } catch (Exception ex) { LOG.error( "An error occurred when creating the accessor for the {} property on {} class.", getId(), modelType, ex); } if (accessor instanceof IModelDescriptorAware) { ((IModelDescriptorAware) accessor) .setModelDescriptor(getModelDescriptor()); } } }