use of com.haulmont.cuba.gui.components.data.HasValueSource in project cuba by cuba-platform.
the class LookupBuilderProcessor method getViewForField.
/**
* If the value for a component (e.g. {@link com.haulmont.cuba.gui.components.PickerField}) is selected from lookup screen then there may be cases
* when in entities in lookup screen some attributes required in the editor are not loaded.
* <p>
* The method evaluates the view that is used for the entity in the given {@code field}
*
* @return a view or null if the view cannot be evaluated
*/
@Nullable
protected <E extends Entity> View getViewForField(HasValue<E> field) {
if (field instanceof HasValueSource) {
ValueSource valueSource = ((HasValueSource) field).getValueSource();
if (valueSource instanceof ContainerValueSource) {
ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
InstanceContainer<E> container = containerValueSource.getContainer();
View view = container.getView();
if (view != null) {
MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
View curView = view;
for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
ViewProperty viewProperty = curView.getProperty(metaProperty.getName());
if (viewProperty != null) {
curView = viewProperty.getView();
}
if (curView == null)
break;
}
if (curView != view) {
return curView;
}
}
}
}
return null;
}
use of com.haulmont.cuba.gui.components.data.HasValueSource 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.HasValueSource in project cuba by cuba-platform.
the class AttributeAccessSupport method visitComponent.
protected void visitComponent(com.haulmont.cuba.gui.components.Component component, boolean reset) {
if (!(component instanceof HasValueSource)) {
return;
}
ValueSource valueSource = ((HasValueSource) component).getValueSource();
if (!(valueSource instanceof EntityValueSource)) {
return;
}
EntityValueSource entityValueSource = (EntityValueSource) valueSource;
MetaPropertyPath propertyPath = entityValueSource.getMetaPropertyPath();
if (valueSource.getState() != BindingState.ACTIVE || propertyPath == null) {
return;
}
if (reset) {
component.setVisible(security.isEntityAttrReadPermitted(entityValueSource.getEntityMetaClass(), propertyPath.toString()));
if (component instanceof Editable) {
((Editable) component).setEditable(security.isEntityAttrUpdatePermitted(entityValueSource.getEntityMetaClass(), propertyPath.toString()));
}
if (component instanceof Field) {
((Field) component).setRequired(propertyPath.getMetaProperty().isMandatory());
}
}
Entity item = entityValueSource.getItem();
ComponentState componentState = calculateComponentState(item, propertyPath);
if (metadataTools.isEmbeddable(item.getMetaClass()) && entityValueSource instanceof DatasourceValueSource) {
Datasource ds = ((DatasourceValueSource) entityValueSource).getDatasource();
if (ds instanceof EmbeddedDatasource) {
Datasource masterDs = ((EmbeddedDatasource) ds).getMaster();
item = masterDs.getItem();
componentState = calculateComponentState(item, metadataTools.resolveMetaPropertyPath(masterDs.getMetaClass(), ((EmbeddedDatasource) ds).getProperty().getName() + "." + propertyPath));
}
}
if (componentState.hidden) {
component.setVisible(false);
}
if (componentState.readOnly) {
if (component instanceof Editable) {
((Editable) component).setEditable(false);
}
}
if (component instanceof Field) {
if (componentState.required && ((Field) component).isEditable() && component.isVisibleRecursive()) {
((Field) component).setRequired(true);
}
}
}
use of com.haulmont.cuba.gui.components.data.HasValueSource in project cuba by cuba-platform.
the class WebTableFieldFactory method applyPermissions.
protected void applyPermissions(com.haulmont.cuba.gui.components.Component columnComponent) {
if (columnComponent instanceof HasValueSource && columnComponent instanceof com.haulmont.cuba.gui.components.Component.Editable) {
HasValueSource component = (HasValueSource) columnComponent;
MetaPropertyPath propertyPath = ((EntityValueSource) component.getValueSource()).getMetaPropertyPath();
if (propertyPath != null) {
com.haulmont.cuba.gui.components.Component.Editable editable = (com.haulmont.cuba.gui.components.Component.Editable) component;
editable.setEditable(editable.isEditable() && security.isEntityAttrUpdatePermitted(propertyPath));
}
}
}
Aggregations