protected void setParentField(Entity item, String parentProperty, Entity parent) { if (parentProperty != null && parent != null && item != null) item.setValue(parentProperty, parent); }
protected void setField(Entity bean, String field, Object value) throws IllegalAccessException, InvocationTargetException, IntrospectionException { bean.setValue(field, value); }
@Override public void setAllDay(boolean isAllDay) { entity.setValue(provider.getIsAllDayProperty(), isAllDay); }
@Override public void setStart(Date start) { entity.setValue(provider.getStartDateProperty(), start); }
@Override public void accept(String caption) { datasource.getItem().setValue(fieldName, caption); } }
@Override public void setStyleName(String styleName) { entity.setValue(provider.getStyleNameProperty(), styleName); }
@Override public void setEnd(Date end) { entity.setValue(provider.getEndDateProperty(), end); }
@Override public void setCaption(String caption) { entity.setValue(provider.getCaptionProperty(), caption); }
protected void setInitialValuesToItem(Entity item) { Map<String, Object> values = getInitialValues(); if (values != null) { for (Map.Entry<String, Object> entry : values.entrySet()) { item.setValue(entry.getKey(), entry.getValue()); } } if (initialValuesSupplier != null) { Map<String, Object> supplierValues = initialValuesSupplier.get(); if (supplierValues != null) { for (Map.Entry<String, Object> entry : supplierValues.entrySet()) { item.setValue(entry.getKey(), entry.getValue()); } } } }
@Override public void setDescription(String description) { entity.setValue(provider.getDescriptionProperty(), description); }
protected void updateMasterCollection(MetaProperty metaProperty, @Nullable Collection<V> newCollection) { if (newCollection == null) { getMaster().getItem().setValue(metaProperty.getName(), null); } else { Collection<V> masterCollection; if (List.class.isAssignableFrom(metaProperty.getJavaType())) { masterCollection = new ArrayList(newCollection); } else { masterCollection = new LinkedHashSet(newCollection); } getMaster().getItem().setValue(metaProperty.getName(), masterCollection); } }
protected void setFullName(String displayedName) { if (datasource != null) { datasource.getItem().setValue("name", displayedName); } else if (window != null) { Field field = (Field) window.getComponentNN("name"); field.setValue(displayedName); } else { fieldGroup.setFieldValue("name", displayedName); } }
/** * Creates new entity instance from {@link com.haulmont.cuba.core.global.EntityLoadInfo} * and reset fields values */ protected Entity createEmptyInstance(EntityLoadInfo loadInfo) throws IllegalAccessException, InstantiationException { MetaClass metaClass = loadInfo.getMetaClass(); Entity instance = metadata.create(metaClass); for (MetaProperty metaProperty : metaClass.getProperties()) { if (!metaProperty.isReadOnly()) instance.setValue(metaProperty.getName(), null); } return instance; }
/** * Creates new entity instance from {@link com.haulmont.cuba.core.global.EntityLoadInfo} * and reset fields values */ protected Entity createEmptyInstance(EntityLoadInfo loadInfo) throws IllegalAccessException, InstantiationException { MetaClass metaClass = loadInfo.getMetaClass(); Entity instance = metadata.create(metaClass); for (MetaProperty metaProperty : metaClass.getProperties()) { if (!metaProperty.isReadOnly()) instance.setValue(metaProperty.getName(), null); } return instance; }
/** * Tries to initialize entity fields included in entity name pattern by default values * * @param entity instance */ protected void initNamePatternFields(Entity entity) { Collection<MetaProperty> properties = metadata.getTools().getNamePatternProperties(entity.getMetaClass()); for (MetaProperty property : properties) { if (entity.getValue(property.getName()) == null && property.getType() == MetaProperty.Type.DATATYPE) { try { entity.setValue(property.getName(), property.getJavaType().newInstance()); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Unable to set value of name pattern field", e); } } } }
protected void createEmbedded(Entity entity) { MetaClass metaClass = getClassNN(entity.getClass()); for (MetaProperty property : metaClass.getProperties()) { if (property.getRange().isClass() && tools.isEmbedded(property)) { EmbeddedParameters embeddedParameters = property.getAnnotatedElement().getAnnotation(EmbeddedParameters.class); if (embeddedParameters != null && !embeddedParameters.nullAllowed()) { MetaClass embeddableMetaClass = property.getRange().asClass(); Entity embeddableEntity = create(embeddableMetaClass); entity.setValue(property.getName(), embeddableEntity); } } } }
protected <E extends Entity> void initializeNestedEntity(E entity, Nested container) { InstanceContainer masterContainer = container.getMaster(); String property = container.getProperty(); MetaClass masterMetaClass = masterContainer.getEntityMetaClass(); MetaProperty metaProperty = masterMetaClass.getPropertyNN(property); MetaProperty inverseProp = metaProperty.getInverse(); if (inverseProp != null) { Class<?> inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain()); Class<?> containerEntityClass = extendedEntities.getEffectiveClass(((CollectionContainer) container).getEntityMetaClass()); if (inversePropClass.isAssignableFrom(containerEntityClass)) { entity.setValue(inverseProp.getName(), masterContainer.getItem()); } } }
protected void setReferenceNull(Entity entity, MetaProperty property) { Range range = property.getRange(); if (metadata.getTools().isOwningSide(property) && !range.getCardinality().isMany()) { if (PersistenceHelper.isLoaded(entity, property.getName())) { entity.setValue(property.getName(), null); } else { hardSetReferenceNull(entity, property); } } }
private void loadOne(EntityCrossDataStoreProperty entityCrossDataStoreProperty) { Entity entity = entityCrossDataStoreProperty.entity; CrossDataStoreProperty aProp = entityCrossDataStoreProperty.crossProp; Object id = entity.getValue(aProp.relatedPropertyName); LoadContext<Entity> loadContext = new LoadContext<>(aProp.property.getRange().asClass()); loadContext.setId(id); if (aProp.viewProperty.getView() != null) loadContext.setView(aProp.viewProperty.getView()); loadContext.setJoinTransaction(joinTransaction); Entity relatedEntity = dataManager.load(loadContext); entity.setValue(aProp.property.getName(), relatedEntity); }
protected Entity initEntity() { EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource(); Entity entity = AppBeans.get(Metadata.class).create( entityValueSource.getMetaPropertyPath().getMetaProperty().getRange().asClass()); Entity ownerEntity = entityValueSource.getItem(); MetaProperty inverseProp = entityValueSource.getMetaPropertyPath().getMetaProperty().getInverse(); if (inverseProp != null) { entity.setValue(inverseProp.getName(), ownerEntity); } return entity; }