use of com.haulmont.cuba.gui.components.Component.Editable 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);
}
}
}
Aggregations