Search in sources :

Example 51 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath 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;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 52 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class PropertyCondition method updateText.

@Override
protected void updateText() {
    Metadata metadata = AppBeans.get(Metadata.class);
    MetadataTools metadataTools = metadata.getTools();
    String nameToUse = name;
    boolean useCrossDataStoreRefId = false;
    String thisStore = metadataTools.getStoreName(datasource.getMetaClass());
    MetaPropertyPath propertyPath = datasource.getMetaClass().getPropertyPath(name);
    if (propertyPath != null) {
        String refIdProperty = metadataTools.getCrossDataStoreReferenceIdProperty(thisStore, propertyPath.getMetaProperty());
        if (refIdProperty != null) {
            useCrossDataStoreRefId = true;
            int lastdDot = nameToUse.lastIndexOf('.');
            if (lastdDot == -1) {
                nameToUse = refIdProperty;
            } else {
                nameToUse = nameToUse.substring(0, lastdDot + 1) + refIdProperty;
            }
        }
    }
    if (operator == Op.DATE_INTERVAL) {
        text = dateIntervalConditionToJpql(nameToUse);
        return;
    }
    StringBuilder sb = new StringBuilder();
    if (operator == Op.NOT_IN) {
        sb.append("((");
    }
    sb.append(entityAlias).append(".").append(nameToUse);
    if (Param.Type.ENTITY == param.getType() && !useCrossDataStoreRefId) {
        com.haulmont.chile.core.model.MetaClass metaClass = metadata.getClassNN(param.getJavaClass());
        String primaryKeyName = metadataTools.getPrimaryKeyName(metaClass);
        sb.append(".").append(primaryKeyName);
    }
    if (operator != Op.NOT_EMPTY)
        sb.append(" ").append(operator.forJpql());
    if (!operator.isUnary()) {
        sb.append(" :").append(param.getName());
        if (operator == Op.ENDS_WITH || operator == Op.STARTS_WITH || operator == Op.CONTAINS || operator == Op.DOES_NOT_CONTAIN) {
            sb.append(" ESCAPE '").append(QueryUtils.ESCAPE_CHARACTER).append("' ");
        }
        if (operator == Op.NOT_IN) {
            sb.append(") or (").append(entityAlias).append(".").append(nameToUse).append(" is null)) ");
        }
    }
    if (operator == Op.NOT_EMPTY) {
        sb.append(BooleanUtils.isTrue((Boolean) param.getValue()) ? " is not null" : " is null");
    }
    text = sb.toString();
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 53 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class PropertyConditionDescriptor method createCondition.

@Override
public AbstractCondition createCondition() {
    OpManager opManager = AppBeans.get(OpManager.class);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    PropertyCondition propertyCondition = new PropertyCondition(this, entityAlias);
    MetaPropertyPath propertyPath = datasourceMetaClass.getPropertyPath(name);
    if (propertyPath == null) {
        throw new IllegalStateException(String.format("Unable to find property '%s' in entity %s", name, datasourceMetaClass));
    }
    MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
    EnumSet<Op> ops = opManager.availableOps(propertyMetaClass, propertyPath.getMetaProperty());
    propertyCondition.setOperator(ops.iterator().next());
    return propertyCondition;
}
Also used : Op(com.haulmont.cuba.core.global.filter.Op) MetadataTools(com.haulmont.cuba.core.global.MetadataTools) PropertyCondition(com.haulmont.cuba.gui.components.filter.condition.PropertyCondition) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) OpManager(com.haulmont.cuba.core.global.filter.OpManager)

Example 54 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class PropertyOperationEditor method createComponent.

@Override
protected Component createComponent() {
    OpManager opManager = AppBeans.get(OpManager.class);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    componentsFactory = AppBeans.get(ComponentsFactory.class);
    popupButton = componentsFactory.createComponent(PopupButton.class);
    MetaClass metaClass = condition.getDatasource().getMetaClass();
    MetaPropertyPath propertyPath = metaClass.getPropertyPath(condition.getName());
    if (propertyPath == null) {
        throw new IllegalStateException(String.format("Unable to find property '%s' in entity %s", condition.getName(), metaClass));
    }
    MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
    for (Op op : opManager.availableOps(propertyMetaClass, propertyPath.getMetaProperty())) {
        OperatorChangeAction operatorChangeAction = new OperatorChangeAction(op);
        popupButton.addAction(operatorChangeAction);
    }
    popupButton.setCaption(condition.getOperator().getLocCaption());
    popupButton.setStyleName("condition-operation-button");
    return popupButton;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Op(com.haulmont.cuba.core.global.filter.Op) MetadataTools(com.haulmont.cuba.core.global.MetadataTools) PopupButton(com.haulmont.cuba.gui.components.PopupButton) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) OpManager(com.haulmont.cuba.core.global.filter.OpManager)

Example 55 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class AbstractTreeTableDatasource method createEntityNodeComparator.

protected Comparator<Node<T>> createEntityNodeComparator() {
    final MetaPropertyPath propertyPath = sortInfos[0].getPropertyPath();
    final boolean asc = Order.ASC.equals(sortInfos[0].getOrder());
    return new TreeTableNodeComparator<>(propertyPath, asc);
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Aggregations

MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)84 MetaClass (com.haulmont.chile.core.model.MetaClass)34 MetaProperty (com.haulmont.chile.core.model.MetaProperty)27 Element (org.dom4j.Element)16 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)11 Entity (com.haulmont.cuba.core.entity.Entity)9 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)9 Datasource (com.haulmont.cuba.gui.data.Datasource)6 Table (com.haulmont.cuba.gui.components.Table)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 Instance (com.haulmont.chile.core.model.Instance)3 Op (com.haulmont.cuba.core.global.filter.Op)3 FocusableTable (com.haulmont.cuba.desktop.sys.vcl.FocusableTable)3 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Formatter (com.haulmont.cuba.gui.components.Formatter)3 Window (com.haulmont.cuba.gui.components.Window)3 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)3 GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)3 java.util (java.util)3