use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.
the class RemoveOperation method commitIfNeeded.
protected void commitIfNeeded(Collection<? extends Entity> entitiesToRemove, CollectionContainer container, ScreenData screenData) {
List<? extends Entity> entitiesToCommit = entitiesToRemove.stream().filter(entity -> !entityStates.isNew(entity)).collect(Collectors.toList());
boolean needCommit = !entitiesToCommit.isEmpty();
if (container instanceof Nested) {
InstanceContainer masterContainer = ((Nested) container).getMaster();
String property = ((Nested) container).getProperty();
MetaClass masterMetaClass = masterContainer.getEntityMetaClass();
MetaProperty metaProperty = masterMetaClass.getPropertyNN(property);
needCommit = needCommit && (metaProperty.getType() != MetaProperty.Type.COMPOSITION);
}
if (needCommit) {
CommitContext commitContext = new CommitContext();
for (Entity entity : entitiesToCommit) {
commitContext.addInstanceToRemove(entity);
}
dataManager.commit(commitContext);
for (Entity entity : entitiesToRemove) {
screenData.getDataContext().evict(entity);
}
} else {
for (Entity entity : entitiesToRemove) {
screenData.getDataContext().remove(entity);
}
}
}
use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.
the class RemoveOperation method excludeItems.
@SuppressWarnings("unchecked")
protected <E extends Entity> void excludeItems(RemoveBuilder<E> builder, List<E> selectedItems) {
CollectionContainer<E> container = getCollectionContainer(builder);
if (!(container instanceof Nested)) {
throw new IllegalArgumentException("Exclude action supports only Nested containers");
}
InstanceContainer masterDc = ((Nested) container).getMaster();
String property = ((Nested) container).getProperty();
Entity masterItem = masterDc.getItem();
MetaProperty metaProperty = masterItem.getMetaClass().getPropertyNN(property);
MetaProperty inverseMetaProperty = metaProperty.getInverse();
if (inverseMetaProperty != null && !inverseMetaProperty.getRange().getCardinality().isMany()) {
Class inversePropClass = extendedEntities.getEffectiveClass(inverseMetaProperty.getDomain());
Class dcClass = extendedEntities.getEffectiveClass(container.getEntityMetaClass());
if (inversePropClass.isAssignableFrom(dcClass)) {
// update reference for One-To-Many
for (Entity item : selectedItems) {
item.setValue(inverseMetaProperty.getName(), null);
}
}
}
container.getMutableItems().removeAll(selectedItems);
focusListComponent(builder);
}
use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.
the class ValueBinder method bind.
public <V> ValueBinding<V> bind(HasValue<V> component, ValueSource<V> valueSource) {
if (valueSource instanceof BeanLocatorAware) {
((BeanLocatorAware) valueSource).setBeanLocator(beanLocator);
}
ValueBindingImpl<V> binding = new ValueBindingImpl<>(component, valueSource);
if (component instanceof Component.Editable) {
((Component.Editable) component).setEditable(!valueSource.isReadOnly());
}
if (valueSource instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueSource;
MetaPropertyPath metaPropertyPath = entityValueSource.getMetaPropertyPath();
if (component instanceof Field) {
initRequired((Field) component, metaPropertyPath);
initBeanValidator((Field<?>) component, metaPropertyPath);
}
if (entityValueSource.isDataModelSecurityEnabled()) {
if (component instanceof Component.Editable) {
MetaClass metaClass = entityValueSource.getEntityMetaClass();
boolean permittedIfEmbedded = true;
if (entityValueSource instanceof ContainerValueSource) {
InstanceContainer container = ((ContainerValueSource) entityValueSource).getContainer();
if (container instanceof Nested && metadataTools.isEmbeddable(metaClass)) {
String embeddedProperty = ((Nested) container).getProperty();
MetaClass masterMetaClass = ((Nested) container).getMaster().getEntityMetaClass();
permittedIfEmbedded = security.isEntityAttrUpdatePermitted(masterMetaClass, embeddedProperty);
}
if (permittedIfEmbedded && metaPropertyPath.length() > 1) {
for (MetaProperty property : metaPropertyPath.getMetaProperties()) {
if (metadataTools.isEmbedded(property) && !security.isEntityAttrUpdatePermitted(property.getDomain(), property.getName())) {
permittedIfEmbedded = false;
break;
}
}
}
}
if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !permittedIfEmbedded) {
((Component.Editable) component).setEditable(false);
}
}
if (!security.isEntityAttrReadPermitted(metaPropertyPath)) {
component.setVisible(false);
}
}
}
binding.bind();
return binding;
}
Aggregations