use of io.jmix.ui.accesscontext.UiEntityAttributeContext in project jmix by jmix-framework.
the class RemoveAction method checkRemovePermission.
protected boolean checkRemovePermission() {
if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
return false;
}
ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
MetaClass metaClass = containerDataUnit.getEntityMetaClass();
if (metaClass == null) {
return false;
}
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isDeletePermitted()) {
return false;
}
if (containerDataUnit.getContainer() instanceof Nested) {
Nested nestedContainer = (Nested) containerDataUnit.getContainer();
MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
MetaProperty metaProperty = masterMetaClass.getProperty(nestedContainer.getProperty());
UiEntityAttributeContext entityAttributeContext = new UiEntityAttributeContext(masterMetaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(entityAttributeContext);
if (!entityAttributeContext.canModify()) {
return false;
}
}
return true;
}
use of io.jmix.ui.accesscontext.UiEntityAttributeContext in project jmix by jmix-framework.
the class BulkEditorWindow method isEntityAttributeModifyPermitted.
protected boolean isEntityAttributeModifyPermitted(MetaClass metaClass, MetaProperty metaProperty) {
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(attributeContext);
return attributeContext.canModify();
}
use of io.jmix.ui.accesscontext.UiEntityAttributeContext in project jmix by jmix-framework.
the class RelatedEntitiesImpl method isSuitableProperty.
protected boolean isSuitableProperty(MetaClass metaClass, MetaProperty metaProperty, @Nullable Pattern excludePattern) {
if (!metaProperty.getRange().isClass()) {
return false;
}
// check that entities are placed in the same data store
MetaClass propertyMetaClass = metaProperty.getRange().asClass();
String propertyStore = propertyMetaClass.getStore().getName();
String effectiveStore = metaClass.getStore().getName();
if (!Objects.equals(effectiveStore, propertyStore)) {
return false;
}
// apply security
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(attributeContext);
return entityContext.isViewPermitted() && attributeContext.canView() && (excludePattern == null || !excludePattern.matcher(metaProperty.getName()).matches());
}
use of io.jmix.ui.accesscontext.UiEntityAttributeContext in project jmix by jmix-framework.
the class EntityInspectorEditor method addTable.
/**
* Creates a table for the entities in ONE_TO_MANY or MANY_TO_MANY relation with the current one
*/
protected void addTable(InstanceContainer parent, MetaProperty childMeta) {
MetaClass meta = childMeta.getRange().asClass();
UiEntityContext entityContext = new UiEntityContext(meta);
accessManager.applyRegisteredConstraints(entityContext);
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(parent.getEntityMetaClass(), childMeta.getName());
accessManager.applyRegisteredConstraints(attributeContext);
// don't show empty table if the user don't have permissions on the attribute or the entity
if (!attributeContext.canView() || !entityContext.isViewPermitted()) {
return;
}
// vertical box for the table and its label
BoxLayout vbox = uiComponents.create(VBoxLayout.class);
vbox.setSizeFull();
Table entitiesTable = InspectorTableBuilder.from(getApplicationContext(), createTableContainer(parent, childMeta, meta)).withMaxTextLength(MAX_TEXT_LENGTH).withSystem(true).withButtons(table -> createButtonsPanel(table, childMeta)).build();
vbox.add(entitiesTable);
vbox.expand(entitiesTable);
vbox.setMargin(true);
TabSheet.Tab tab = tablesTabSheet.addTab(childMeta.toString(), vbox);
tab.setCaption(getPropertyCaption(parent.getEntityMetaClass(), childMeta));
}
use of io.jmix.ui.accesscontext.UiEntityAttributeContext in project jmix by jmix-framework.
the class AppSettingsGridLayoutBuilder method addRowToGrid.
protected void addRowToGrid(InstanceContainer container, GridLayout gridLayout, int currentRow, MetaProperty metaProperty) {
MetaClass metaClass = container.getEntityMetaClass();
Range range = metaProperty.getRange();
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(attributeContext);
if (!attributeContext.canView()) {
return;
}
if (range.isClass()) {
UiEntityContext entityContext = new UiEntityContext(range.asClass());
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isViewPermitted()) {
return;
}
}
// add label
Label fieldLabel = uiComponents.create(Label.class);
fieldLabel.setValue(getPropertyCaption(metaClass, metaProperty));
fieldLabel.setAlignment(io.jmix.ui.component.Component.Alignment.MIDDLE_LEFT);
gridLayout.add(fieldLabel, 0, currentRow + 1);
// current field
ValueSource valueSource = new ContainerValueSource<>(container, metaProperty.getName());
ComponentGenerationContext componentContext = new ComponentGenerationContext(metaClass, metaProperty.getName());
componentContext.setValueSource(valueSource);
gridLayout.add(createField(metaProperty, range, componentContext), 1, currentRow + 1);
// default value
ComponentGenerationContext componentContextForDefaultField = new ComponentGenerationContext(metaClass, metaProperty.getName());
ValueSource valueSourceForDefaultField = new ContainerValueSource<>(dataComponents.createInstanceContainer(metaClass.getJavaClass()), metaProperty.getName());
componentContextForDefaultField.setValueSource(valueSourceForDefaultField);
Field defaultValueField = createField(metaProperty, range, componentContextForDefaultField);
defaultValueField.setValue(appSettingsTools.getDefaultPropertyValue(metaClass.getJavaClass(), metaProperty.getName()));
defaultValueField.setEditable(false);
gridLayout.add(defaultValueField, 2, currentRow + 1);
}
Aggregations