use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class WebDataLoadCoordinator method configureAutomatically.
private void configureAutomatically(DataLoader loader, FrameOwner frameOwner) {
List<String> queryParameters = DataLoadersHelper.getQueryParameters(loader);
List<String> allParameters = new ArrayList<>(queryParameters);
allParameters.addAll(getConditionParameters(loader));
// add triggers on container/component events
for (String parameter : allParameters) {
if (parameter.startsWith(containerPrefix)) {
InstanceContainer container = UiControllerUtils.getScreenData(frameOwner).getContainer(parameter.substring(containerPrefix.length()));
addOnContainerItemChangedLoadTrigger(loader, container, parameter);
} else if (parameter.startsWith(componentPrefix)) {
String componentId = parameter.substring(componentPrefix.length());
Component component = frameOwner instanceof Screen ? ((Screen) frameOwner).getWindow().getComponentNN(componentId) : ((ScreenFragment) frameOwner).getFragment().getComponentNN(componentId);
LikeClause likeClause = findLikeClause(loader, parameter);
addOnComponentValueChangedLoadTrigger(loader, component, parameter, likeClause);
}
}
// if the loader has no parameters in query, add trigger on BeforeShowEvent/AttachEvent
if (queryParameters.isEmpty()) {
Class eventClass = frameOwner instanceof Screen ? Screen.BeforeShowEvent.class : ScreenFragment.AttachEvent.class;
addOnFrameOwnerEventLoadTrigger(loader, eventClass);
}
}
use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class DynamicAttributesGuiTools method getValueChangeEventListener.
/**
* Returns {@code ValueChangeEventListener} for dynamic attribute that has one or more dependent attributes.
* This listener recalculates values for all dependent dynamic attributes hierarchically. The listener uses
* {@code recalculationInProgress} ThreadLocal variable to avoid unnecessary calculation.
*/
@SuppressWarnings("unchecked")
public Consumer<HasValue.ValueChangeEvent> getValueChangeEventListener(final CategoryAttribute attribute) {
if (attribute.getConfiguration().getDependentAttributes() != null && !attribute.getConfiguration().getDependentAttributes().isEmpty()) {
return valueChangeEvent -> {
if (Boolean.TRUE.equals(recalculationInProgress.get())) {
return;
}
try {
recalculationInProgress.set(true);
com.haulmont.cuba.gui.components.Component component = valueChangeEvent.getComponent();
if (component instanceof HasValueSource) {
{
BaseGenericIdEntity entity = null;
String attributeCode = DynamicAttributesUtils.encodeAttributeCode(attribute.getCode());
if (((HasValueSource) component).getValueSource() instanceof ContainerValueSource) {
ContainerValueSource valueSource = (ContainerValueSource) ((HasValueSource) component).getValueSource();
InstanceContainer container = valueSource.getContainer();
if (container.getItem() instanceof BaseGenericIdEntity) {
entity = (BaseGenericIdEntity) container.getItem();
}
} else if (((HasValueSource) component).getValueSource() instanceof DatasourceValueSource) {
DatasourceValueSource valueSource = (DatasourceValueSource) ((HasValueSource) component).getValueSource();
if (valueSource.getItem() instanceof BaseGenericIdEntity) {
entity = (BaseGenericIdEntity) valueSource.getItem();
} else if (valueSource.getItem() instanceof DynamicAttributesEntity) {
entity = ((DynamicAttributesEntity) valueSource.getItem()).getMainItem();
}
}
entity.setValue(attributeCode, valueChangeEvent.getValue());
recalculationTools.recalculateDynamicAttributes(entity, attribute);
}
}
} finally {
recalculationInProgress.remove();
}
};
}
return null;
}
use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class TwinColumnLoader method loadOptionsContainer.
protected void loadOptionsContainer(TwinColumn component, 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);
}
// noinspection unchecked
component.setOptions(new ContainerOptions((CollectionContainer) container));
}
}
use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class WebTableFieldFactory method createField.
@SuppressWarnings("unchecked")
@Override
public com.vaadin.v7.ui.Field<?> createField(com.vaadin.v7.data.Container container, Object itemId, Object propertyId, Component uiContext) {
String fieldPropertyId = String.valueOf(propertyId);
Table.Column columnConf = webTable.getColumnsInternal().get(propertyId);
TableDataContainer tableDataContainer = (TableDataContainer) container;
Entity entity = (Entity) tableDataContainer.getInternalItem(itemId);
InstanceContainer instanceContainer = webTable.getInstanceContainer((E) entity);
com.haulmont.cuba.gui.components.Component columnComponent = createField(new ContainerValueSource(instanceContainer, fieldPropertyId), fieldPropertyId, columnConf.getXmlDescriptor());
if (columnComponent instanceof Field) {
Field cubaField = (Field) columnComponent;
Map<Table.Column, String> requiredColumns = webTable.getRequiredColumnsInternal();
if (requiredColumns != null && requiredColumns.containsKey(columnConf)) {
cubaField.setRequired(true);
cubaField.setRequiredMessage(requiredColumns.get(columnConf));
}
}
if (!(columnComponent instanceof CheckBox)) {
// todo get rid of concrete CheckBox class !
columnComponent.setWidthFull();
}
if (columnComponent instanceof BelongToFrame) {
BelongToFrame belongToFrame = (BelongToFrame) columnComponent;
if (belongToFrame.getFrame() == null) {
belongToFrame.setFrame(webTable.getFrame());
}
}
applyPermissions(columnComponent);
columnComponent.setParent(webTable);
Component componentImpl = getComponentImplementation(columnComponent);
if (componentImpl instanceof com.vaadin.v7.ui.Field) {
return (com.vaadin.v7.ui.Field<?>) componentImpl;
}
return new EditableColumnFieldWrapper(componentImpl, columnComponent);
}
use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class WebTableFieldFactory method findOptionsContainer.
@Nullable
protected CollectionContainer findOptionsContainer(Table.Column columnConf) {
String optDcName = columnConf.getXmlDescriptor() != null ? columnConf.getXmlDescriptor().attributeValue("optionsContainer") : null;
if (Strings.isNullOrEmpty(optDcName)) {
return null;
} else {
ScreenData screenData = UiControllerUtils.getScreenData(webTable.getFrame().getFrameOwner());
InstanceContainer container = screenData.getContainer(optDcName);
if (container instanceof CollectionContainer) {
return (CollectionContainer) container;
}
throw new IllegalStateException(String.format("'%s' is not an instance of CollectionContainer", optDcName));
}
}
Aggregations