use of com.haulmont.cuba.gui.components.data.ValueSource in project cuba by cuba-platform.
the class AbstractComponentGenerationStrategy method createLookupField.
protected Component createLookupField(ComponentGenerationContext context, CategoryAttribute categoryAttribute) {
LookupField lookupField = uiComponents.create(LookupField.class);
ValueSource valueSource = context.getValueSource();
if (valueSource instanceof ContainerValueSource) {
setOptionsLoader(categoryAttribute, lookupField, (ContainerValueSource) valueSource);
}
setValueSource(lookupField, context);
setValidators(lookupField, context);
return lookupField;
}
use of com.haulmont.cuba.gui.components.data.ValueSource in project cuba by cuba-platform.
the class ReadOnlyScreensSupport method isEditableConsideringDataBinding.
protected boolean isEditableConsideringDataBinding(Component component, boolean editable) {
boolean shouldBeEditable = true;
if (component instanceof HasValueSource && ((HasValueSource) component).getValueSource() != null) {
ValueSource valueSource = ((HasValueSource) component).getValueSource();
shouldBeEditable = !valueSource.isReadOnly();
if (valueSource instanceof EntityValueSource && ((EntityValueSource) valueSource).isDataModelSecurityEnabled()) {
MetaPropertyPath metaPropertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath();
if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !security.isEntityAttrReadPermitted(metaPropertyPath)) {
shouldBeEditable = false;
}
}
}
return editable && shouldBeEditable;
}
use of com.haulmont.cuba.gui.components.data.ValueSource in project cuba by cuba-platform.
the class DateFieldLoader method getJavaType.
protected Class getJavaType(DateField resultComponent) {
ValueSource valueSource = resultComponent.getValueSource();
if (valueSource instanceof EntityValueSource) {
MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
return metaProperty.getRange().asDatatype().getJavaClass();
}
Datatype datatype = resultComponent.getDatatype();
return datatype == null ? Date.class : datatype.getJavaClass();
}
use of com.haulmont.cuba.gui.components.data.ValueSource in project cuba by cuba-platform.
the class ClearAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
// remove entity if it is a composition
Object value = pickerField.getValue();
ValueSource valueSource = pickerField.getValueSource();
if (value != null && !value.equals(pickerField.getEmptyValue()) && valueSource instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
Entity entity = (Entity) pickerField.getValue();
if (entityValueSource.getMetaPropertyPath() != null && entityValueSource.getMetaPropertyPath().getMetaProperty().getType() == MetaProperty.Type.COMPOSITION) {
FrameOwner screen = pickerField.getFrame().getFrameOwner();
DataContext dataContext = UiControllerUtils.getScreenData(screen).getDataContext();
dataContext.remove(entity);
}
}
// Set the value as if the user had set it
pickerField.setValueFromUser(pickerField.getEmptyValue());
}
use of com.haulmont.cuba.gui.components.data.ValueSource in project cuba by cuba-platform.
the class DynamicAttributesPanel method generateFieldComponent.
protected Component generateFieldComponent(DynamicAttributesMetaProperty property) {
CategoryAttribute attribute = property.getAttribute();
ValueSource valueSource = new ContainerValueSource<>(instanceContainer, property.getName());
ComponentGenerationContext componentGenerationContext = new ComponentGenerationContext(instanceContainer.getEntityMetaClass(), property.getName());
componentGenerationContext.setValueSource(valueSource);
Component formField;
if (Boolean.TRUE.equals(attribute.getIsCollection())) {
formField = dynamicAttributeComponentsGenerator.generateComponent(valueSource, attribute);
} else {
formField = uiComponentsGenerator.generate(componentGenerationContext);
}
return formField;
}
Aggregations