use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.
the class RemoveAction method checkRemovePermission.
protected boolean checkRemovePermission() {
ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
MetaClass metaClass = containerDataUnit.getEntityMetaClass();
if (metaClass == null) {
return false;
}
boolean entityOpPermitted = security.isEntityOpPermitted(metaClass, EntityOp.DELETE);
if (!entityOpPermitted) {
return false;
}
if (containerDataUnit.getContainer() instanceof Nested) {
Nested nestedContainer = (Nested) containerDataUnit.getContainer();
MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
MetaProperty metaProperty = masterMetaClass.getPropertyNN(nestedContainer.getProperty());
boolean attrPermitted = security.isEntityAttrUpdatePermitted(masterMetaClass, metaProperty.getName());
if (!attrPermitted) {
return false;
}
}
return true;
}
use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.
the class LookupBuilderProcessor method handleSelectionWithContainer.
protected <E extends Entity> void handleSelectionWithContainer(LookupBuilder<E> builder, CollectionContainer<E> collectionDc, Collection<E> itemsFromLookup) {
if (itemsFromLookup.isEmpty()) {
return;
}
Collection<E> selectedItems = transform(itemsFromLookup, builder);
boolean initializeMasterReference = false;
Entity masterItem = null;
MetaProperty inverseMetaProperty = null;
// update holder reference if needed
if (collectionDc instanceof Nested) {
InstanceContainer masterDc = ((Nested) collectionDc).getMaster();
String property = ((Nested) collectionDc).getProperty();
masterItem = masterDc.getItem();
MetaProperty metaProperty = masterItem.getMetaClass().getPropertyNN(property);
inverseMetaProperty = metaProperty.getInverse();
if (inverseMetaProperty != null && !inverseMetaProperty.getRange().getCardinality().isMany()) {
Class<?> inversePropClass = extendedEntities.getEffectiveClass(inverseMetaProperty.getDomain());
Class<?> dcClass = extendedEntities.getEffectiveClass(collectionDc.getEntityMetaClass());
initializeMasterReference = inversePropClass.isAssignableFrom(dcClass);
}
}
DataContext dataContext = UiControllerUtils.getScreenData(builder.getOrigin()).getDataContext();
List<E> mergedItems = new ArrayList<>(selectedItems.size());
View viewForCollectionContainer = clientConfig.getReloadUnfetchedAttributesFromLookupScreens() && collectionDc.getEntityMetaClass() != null && metadataTools.isPersistent(collectionDc.getEntityMetaClass()) ? getViewForCollectionContainer(collectionDc, initializeMasterReference, inverseMetaProperty) : null;
for (E item : selectedItems) {
if (!collectionDc.containsItem(item.getId())) {
if (viewForCollectionContainer != null && !entityStates.isLoadedWithView(item, viewForCollectionContainer)) {
item = dataManager.reload(item, viewForCollectionContainer);
}
// track changes in the related instance
E mergedItem = dataContext.merge(item);
if (initializeMasterReference) {
// change reference, now it will be marked as modified
mergedItem.setValue(inverseMetaProperty.getName(), masterItem);
}
mergedItems.add(mergedItem);
}
}
collectionDc.getMutableItems().addAll(mergedItems);
}
use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.
the class LookupBuilderProcessor method getViewForCollectionContainer.
/**
* See {@link #getViewForField(HasValue)} javadoc.
*
* @return a view or null if the view cannot be evaluated
*/
@Nullable
protected <E extends Entity> View getViewForCollectionContainer(CollectionContainer<E> collectionDc, boolean initializeMasterReference, MetaProperty inverseMetaProperty) {
View view = null;
if (collectionDc instanceof Nested) {
InstanceContainer masterDc = ((Nested) collectionDc).getMaster();
View masterView = masterDc.getView();
if (masterView != null) {
String property = ((Nested) collectionDc).getProperty();
ViewProperty viewProperty = masterView.getProperty(property);
if (viewProperty != null) {
view = viewProperty.getView();
if (view != null && initializeMasterReference && inverseMetaProperty != null) {
view.addProperty(inverseMetaProperty.getName());
}
}
}
} else {
view = collectionDc.getView();
}
return view;
}
use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.
the class AddAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
return false;
}
ContainerDataUnit containerDataUnit = (ContainerDataUnit) target.getItems();
MetaClass metaClass = containerDataUnit.getEntityMetaClass();
if (metaClass == null) {
return false;
}
if (containerDataUnit.getContainer() instanceof Nested) {
Nested nestedContainer = (Nested) containerDataUnit.getContainer();
MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
MetaProperty metaProperty = masterMetaClass.getPropertyNN(nestedContainer.getProperty());
boolean attrPermitted = security.isEntityAttrUpdatePermitted(masterMetaClass, metaProperty.getName());
if (!attrPermitted) {
return false;
}
}
return super.isPermitted();
}
use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.
the class ExcludeAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
return false;
}
ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
MetaClass metaClass = containerDataUnit.getEntityMetaClass();
if (metaClass == null) {
return false;
}
if (containerDataUnit.getContainer() instanceof Nested) {
Nested nestedContainer = (Nested) containerDataUnit.getContainer();
MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
MetaProperty metaProperty = masterMetaClass.getPropertyNN(nestedContainer.getProperty());
boolean attrPermitted = security.isEntityAttrUpdatePermitted(masterMetaClass, metaProperty.getName());
if (!attrPermitted) {
return false;
}
}
return super.isPermitted();
}
Aggregations