use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class EntityLogBrowser method fillAttributes.
protected void fillAttributes(String metaClassName, LoggedEntity item, boolean editable) {
clearAttributes();
setSelectAllCheckBox(false);
if (metaClassName != null) {
MetaClass metaClass = metadata.getExtendedEntities().getEffectiveMetaClass(metadata.getClassNN(metaClassName));
List<MetaProperty> metaProperties = new ArrayList<>(metaClass.getProperties());
selectAllCheckBox.setEditable(editable);
Set<LoggedAttribute> enabledAttr = null;
if (item != null)
enabledAttr = item.getAttributes();
for (MetaProperty property : metaProperties) {
if (allowLogProperty(property, null)) {
if (metadata.getTools().isEmbedded(property)) {
MetaClass embeddedMetaClass = property.getRange().asClass();
for (MetaProperty embeddedProperty : embeddedMetaClass.getProperties()) {
if (allowLogProperty(embeddedProperty, null)) {
addAttribute(enabledAttr, String.format("%s.%s", property.getName(), embeddedProperty.getName()), editable);
}
}
} else {
addAttribute(enabledAttr, property.getName(), editable);
}
}
}
Collection<CategoryAttribute> attributes = dynamicAttributes.getAttributesForMetaClass(metaClass);
if (attributes != null) {
for (CategoryAttribute categoryAttribute : attributes) {
MetaPropertyPath propertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, categoryAttribute);
MetaProperty property = propertyPath.getMetaProperty();
if (allowLogProperty(property, categoryAttribute)) {
addAttribute(enabledAttr, property.getName(), editable);
}
}
}
}
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class DesktopAbstractOptionsField method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
this.datasource = datasource;
if (datasource == null) {
setValue(null);
return;
}
MetaClass metaClass = datasource.getMetaClass();
resolveMetaPropertyPath(metaClass, property);
itemChangeListener = e -> {
if (updatingInstance)
return;
Object value = InstanceUtils.getValueEx(e.getItem(), metaPropertyPath.getPath());
updateComponent(value);
fireChangeListeners(value);
};
// noinspection unchecked
datasource.addItemChangeListener(new WeakItemChangeListener(datasource, itemChangeListener));
itemPropertyChangeListener = e -> {
if (updatingInstance)
return;
if (e.getProperty().equals(metaPropertyPath.toString())) {
updateComponent(e.getValue());
fireChangeListeners(e.getValue());
}
};
// noinspection unchecked
datasource.addItemPropertyChangeListener(new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener));
initRequired(metaPropertyPath);
if (metaProperty.getRange().isEnum()) {
Enumeration enumeration = metaProperty.getRange().asEnumeration();
@SuppressWarnings("unchecked") Class<Enum> javaClass = enumeration.getJavaClass();
setOptionsList(Arrays.asList(javaClass.getEnumConstants()));
setCaptionMode(CaptionMode.ITEM);
}
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) {
setOptionsMap(categoryAttribute.getLocalizedEnumerationMap());
}
}
if ((datasource.getState() == Datasource.State.VALID) && (datasource.getItem() != null)) {
Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
updateComponent(newValue);
fireChangeListeners(newValue);
}
if (metaProperty.isReadOnly()) {
setEditable(false);
}
handleFilteredAttributes(this, this.datasource, metaPropertyPath);
securityItemChangeListener = e -> handleFilteredAttributes(this, this.datasource, metaPropertyPath);
// noinspection unchecked
this.datasource.addItemChangeListener(new WeakItemChangeListener(this.datasource, securityItemChangeListener));
initBeanValidator();
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class BulkEditorWindow method getManagedFields.
protected List<ManagedField> getManagedFields(MetaClass metaClass) {
List<ManagedField> managedFields = new ArrayList<>();
// sort Fields
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (isManagedAttribute(metaClass, metaProperty)) {
String propertyCaption = messageTools.getPropertyCaption(metaClass, metaProperty.getName());
if (!metadataTools.isEmbedded(metaProperty)) {
managedFields.add(new ManagedField(metaProperty.getName(), metaProperty, propertyCaption, null));
} else {
List<ManagedField> nestedFields = getManagedFields(metaProperty, metaProperty.getName(), propertyCaption);
if (nestedFields.size() > 0) {
managedEmbeddedProperties.add(metaProperty.getName());
}
managedFields.addAll(nestedFields);
}
}
}
if (loadDynamicAttributes) {
List<CategoryAttribute> categoryAttributes = (List<CategoryAttribute>) dynamicAttributes.getAttributesForMetaClass(metaClass);
if (!categoryAttributes.isEmpty()) {
for (CategoryAttribute attribute : categoryAttributes) {
MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, attribute);
String propertyCaption = attribute.getLocaleName();
if (isManagedDynamicAttribute(metaClass, metaPropertyPath.getMetaProperty())) {
managedFields.add(new ManagedField(metaPropertyPath.getMetaProperty().getName(), metaPropertyPath.getMetaProperty(), propertyCaption, null));
}
}
}
}
return managedFields;
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class AttributeEditor method fillAttributeCode.
protected void fillAttributeCode() {
CategoryAttribute attribute = getItem();
if (StringUtils.isBlank(attribute.getCode()) && StringUtils.isNotBlank(attribute.getName())) {
String categoryName = StringUtils.EMPTY;
if (attribute.getCategory() != null) {
categoryName = StringUtils.defaultString(attribute.getCategory().getName());
}
attribute.setCode(StringUtils.deleteWhitespace(categoryName + attribute.getName()));
}
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class CategoryAttrsFrame method initMoveButtons.
protected void initMoveButtons() {
Action moveUpAction = new ItemTrackingAction("moveUp").withCaption("").withHandler(event -> {
Set<CategoryAttribute> selected = categoryAttrsTable.getSelected();
if (selected.isEmpty())
return;
CategoryAttribute currentAttr = selected.iterator().next();
UUID prevId = categoryAttrsDs.prevItemId(currentAttr.getId());
if (prevId == null)
return;
Integer tmp = currentAttr.getOrderNo();
CategoryAttribute prevAttr = categoryAttrsDs.getItemNN(prevId);
currentAttr.setOrderNo(prevAttr.getOrderNo());
prevAttr.setOrderNo(tmp);
sortTableByOrderNo();
});
((Button) getComponentNN("moveUp")).setAction(moveUpAction);
Action moveDownAction = new ItemTrackingAction("moveDown").withCaption("").withHandler(event -> {
Set<CategoryAttribute> selected = categoryAttrsTable.getSelected();
if (selected.isEmpty())
return;
CategoryAttribute currentAttr = selected.iterator().next();
UUID nextId = categoryAttrsDs.nextItemId(currentAttr.getId());
if (nextId == null)
return;
Integer tmp = currentAttr.getOrderNo();
CategoryAttribute nextAttr = categoryAttrsDs.getItemNN(nextId);
currentAttr.setOrderNo(nextAttr.getOrderNo());
nextAttr.setOrderNo(tmp);
sortTableByOrderNo();
});
((Button) getComponentNN("moveDown")).setAction(moveDownAction);
categoryAttrsTable.addAction(moveUpAction);
categoryAttrsTable.addAction(moveDownAction);
}
Aggregations