use of com.haulmont.cuba.gui.model.InstanceContainer 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.InstanceContainer in project cuba by cuba-platform.
the class CalendarLoader method loadDataContainer.
@SuppressWarnings("unchecked")
protected void loadDataContainer(Calendar component, Element element) {
String containerId = element.attributeValue("dataContainer");
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
if (!(container instanceof CollectionContainer)) {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
component.setEventProvider(new ContainerCalendarEventProvider<>(((CollectionContainer) container)));
}
use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class AbstractComponentLoader method loadOptionsContainer.
protected Optional<CollectionContainer> loadOptionsContainer(Element element) {
String containerId = element.attributeValue("optionsContainer");
if (containerId != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
if (!(container instanceof CollectionContainer)) {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
return Optional.of((CollectionContainer) container);
}
return Optional.empty();
}
Aggregations