use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class OrmCacheSupport method evictMasterEntity.
/**
* Evicts an entity from cache if it has the given entity as an element of collection.
*
* @param entity which is being updated and can potentially be an element of a collection
* @param changes changes in the entity. Null when creating and removing the entity.
*/
public void evictMasterEntity(BaseGenericIdEntity entity, @Nullable EntityAttributeChanges changes) {
MetaClass metaClass = metadata.getClassNN(entity.getClass());
for (MetaProperty property : metaClass.getProperties()) {
if (!property.getRange().isClass() || property.getRange().getCardinality().isMany())
continue;
MetaProperty inverseProp = property.getInverse();
if (inverseProp == null || !inverseProp.getRange().getCardinality().isMany())
continue;
// the inverse property is a collection
if (metadata.getTools().isCacheable(property.getRange().asClass())) {
if (changes != null) {
for (String attributeName : changes.getOwnAttributes()) {
if (property.getName().equals(attributeName)) {
evictEntity(changes.getOldValue(attributeName));
break;
}
}
} else {
Object masterEntity = entity.getValue(property.getName());
evictEntity(masterEntity);
}
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class DesktopPickerField method updateComponent.
protected void updateComponent(Object value) {
String text;
if (value == null) {
text = "";
} else {
if (value instanceof Instance) {
if (captionMode.equals(CaptionMode.ITEM)) {
text = ((Instance) value).getInstanceName();
} else {
Object propertyValue = ((Instance) value).getValue(captionProperty);
MetaClass valueClass = metadata.getClassNN(value.getClass());
MetaProperty property = valueClass.getProperty(captionProperty);
text = metadataTools.format(propertyValue, property);
}
} else {
text = value.toString();
}
}
impl.setValue(text);
prevTextValue = text;
updateMissingValueState();
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class DesktopTokenList method setLookup.
@Override
public void setLookup(boolean lookup) {
if (this.lookup != lookup) {
if (lookup) {
lookupAction = new PickerField.LookupAction(lookupPickerField) {
@Nonnull
@Override
protected Map<String, Object> prepareScreenParams() {
Map<String, Object> screenParams = super.prepareScreenParams();
if (isMultiSelect()) {
screenParams = new HashMap<>(screenParams);
WindowParams.MULTI_SELECT.set(screenParams, true);
// for backward compatibility
screenParams.put("multiSelect", "true");
}
return screenParams;
}
@SuppressWarnings("unchecked")
@Override
protected void handleLookupWindowSelection(Collection items) {
if (items.isEmpty()) {
return;
}
@SuppressWarnings("unchecked") Collection<Entity> selected = items;
CollectionDatasource optionsDatasource = lookupPickerField.getOptionsDatasource();
if (optionsDatasource != null && lookupPickerField.isRefreshOptionsOnLookupClose()) {
optionsDatasource.refresh();
if (datasource != null) {
for (Object obj : getDatasource().getItems()) {
Entity entity = (Entity) obj;
if (getOptionsDatasource().containsItem(entity.getId())) {
datasource.updateItem(getOptionsDatasource().getItem(entity.getId()));
}
}
}
}
// add all selected items to tokens
if (itemChangeHandler != null) {
for (Entity newItem : selected) {
itemChangeHandler.addItem(newItem);
}
} else if (datasource != null) {
// get master entity and inverse attribute in case of nested datasource
Entity masterEntity = getMasterEntity(datasource);
MetaProperty inverseProp = getInverseProperty(datasource);
for (Entity newItem : selected) {
if (!datasource.containsItem(newItem.getId())) {
// Initialize reference to master entity
if (inverseProp != null && isInitializeMasterReference(inverseProp)) {
newItem.setValue(inverseProp.getName(), masterEntity);
}
datasource.addItem(newItem);
}
}
}
afterSelect(items);
if (afterLookupSelectionHandler != null) {
afterLookupSelectionHandler.onSelect(items);
}
}
};
lookupPickerField.addAction(lookupAction);
if (getLookupScreen() != null) {
lookupAction.setLookupScreen(getLookupScreen());
}
lookupAction.setLookupScreenOpenType(lookupOpenMode);
lookupAction.setLookupScreenParams(lookupScreenParams);
lookupAction.setLookupScreenDialogParams(lookupScreenDialogParams);
} else {
lookupPickerField.removeAction(lookupAction);
}
lookupAction.setAfterLookupCloseHandler((window, actionId) -> {
if (afterLookupCloseHandler != null) {
afterLookupCloseHandler.onClose(window, actionId);
}
});
lookupAction.setAfterLookupSelectionHandler(items -> {
if (afterLookupSelectionHandler != null) {
afterLookupSelectionHandler.onSelect(items);
}
});
}
this.lookup = lookup;
rootPanel.refreshComponent();
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class DesktopTokenList method getInverseProperty.
@Nullable
protected MetaProperty getInverseProperty(CollectionDatasource datasource) {
if (datasource instanceof NestedDatasource) {
MetaProperty metaProperty = ((NestedDatasource) datasource).getProperty();
com.google.common.base.Preconditions.checkState(metaProperty != null);
return metaProperty.getInverse();
}
return null;
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class DesktopAbstractField method initRequired.
protected void initRequired(MetaPropertyPath metaPropertyPath) {
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
boolean newRequired = metaProperty.isMandatory();
Object notNullUiComponent = metaProperty.getAnnotations().get(NotNull.class.getName() + "_notnull_ui_component");
if (Boolean.TRUE.equals(notNullUiComponent)) {
newRequired = true;
}
setRequired(newRequired);
if (StringUtils.isEmpty(getRequiredMessage())) {
MessageTools messageTools = AppBeans.get(MessageTools.NAME);
setRequiredMessage(messageTools.getDefaultRequiredMessage(metaPropertyPath.getMetaClass(), metaPropertyPath.toString()));
}
}
Aggregations