use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class OriginalEntityLoadInfo method create.
/**
* Create a new info instance.
* @param entity entity instance
* @return info instance
*/
public static OriginalEntityLoadInfo create(Entity entity) {
Objects.requireNonNull(entity, "entity is null");
Metadata metadata = AppBeans.get(Metadata.NAME);
MetaClass metaClass = metadata.getSession().getClassNN(entity.getClass());
MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalMetaClass(metaClass);
if (originalMetaClass != null) {
metaClass = originalMetaClass;
}
MetaProperty primaryKeyProperty = metadata.getTools().getPrimaryKeyProperty(metaClass);
boolean stringKey = primaryKeyProperty != null && primaryKeyProperty.getJavaType().equals(String.class);
return new OriginalEntityLoadInfo((UUID) entity.getId(), metaClass, stringKey);
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class RuntimePropertiesFrame method loadValidators.
protected void loadValidators(FieldGroup fieldGroup, FieldGroup.FieldConfig field) {
MetaPropertyPath metaPropertyPath = rds.getMetaClass().getPropertyPath(field.getProperty());
if (metaPropertyPath != null) {
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
Field.Validator validator = getValidator(metaProperty);
if (validator != null) {
field.addValidator(validator);
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class CreateAction method isPermitted.
/**
* Check permissions for Action
*/
@Override
protected boolean isPermitted() {
if (target == null || target.getDatasource() == null) {
return false;
}
CollectionDatasource ownerDatasource = target.getDatasource();
MetaClass metaClass = ownerDatasource.getMetaClass();
boolean createPermitted = security.isEntityOpPermitted(metaClass, EntityOp.CREATE);
if (!createPermitted) {
return false;
}
if (ownerDatasource instanceof PropertyDatasource) {
PropertyDatasource propertyDatasource = (PropertyDatasource) ownerDatasource;
MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass();
MetaProperty metaProperty = propertyDatasource.getProperty();
boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
if (!attrPermitted) {
return false;
}
}
return super.isPermitted();
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EditAction method actionPerform.
/**
* This method is invoked by the action owner component.
*
* @param component component invoking the action
*/
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null) {
if (!beforeActionPerformedHandler.beforeActionPerformed())
return;
}
final Set selected = target.getSelected();
if (selected.size() == 1) {
Datasource parentDs = null;
final CollectionDatasource datasource = target.getDatasource();
if (datasource instanceof PropertyDatasource) {
MetaProperty metaProperty = ((PropertyDatasource) datasource).getProperty();
if (metaProperty.getType().equals(MetaProperty.Type.COMPOSITION)) {
parentDs = datasource;
}
}
Map<String, Object> params = prepareWindowParams();
internalOpenEditor(datasource, datasource.getItem(), parentDs, params);
} else if (selected.size() > 1 && bulkEditorIntegration.isEnabled()) {
boolean isBulkEditorPermitted = userSession.isSpecificPermitted(BulkEditor.PERMISSION);
if (isBulkEditorPermitted) {
// if bulk editor integration enabled and permitted for user
Map<String, Object> params = ParamsMap.of("metaClass", target.getDatasource().getMetaClass(), "selected", selected, "exclude", bulkEditorIntegration.getExcludePropertiesRegex(), "fieldValidators", bulkEditorIntegration.getFieldValidators(), "modelValidators", bulkEditorIntegration.getModelValidators());
Window bulkEditor = target.getFrame().openWindow("bulkEditor", bulkEditorIntegration.getOpenType(), params);
bulkEditor.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
target.getDatasource().refresh();
}
target.requestFocus();
Consumer<BulkEditorCloseEvent> afterEditorCloseHandler = bulkEditorIntegration.getAfterEditorCloseHandler();
if (afterEditorCloseHandler != null) {
afterEditorCloseHandler.accept(new BulkEditorCloseEvent(this, bulkEditor, actionId));
}
});
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class ExcludeAction method doRemove.
@SuppressWarnings("unchecked")
@Override
protected void doRemove(Set<Entity> selected, boolean autocommit) {
@SuppressWarnings({ "unchecked" }) CollectionDatasource ds = target.getDatasource();
if (ds instanceof NestedDatasource) {
// Clear reference to master entity
Datasource masterDs = ((NestedDatasource) ds).getMaster();
MetaProperty metaProperty = ((NestedDatasource) ds).getProperty();
if (masterDs != null && metaProperty != null) {
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null) {
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
Class dsClass = extendedEntities.getEffectiveClass(ds.getMetaClass());
if (inversePropClass.isAssignableFrom(dsClass)) {
for (Entity item : selected) {
item.setValue(inverseProp.getName(), null);
}
}
}
}
}
for (Entity item : selected) {
ds.modifyItem(item);
ds.excludeItem(item);
}
if (autocommit && (ds.getCommitMode() != Datasource.CommitMode.PARENT)) {
try {
ds.commit();
} catch (RuntimeException e) {
ds.refresh();
throw e;
}
}
}
Aggregations