Search in sources :

Example 46 with MetaPropertyPath

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

the class WebDataGrid method addInitialColumns.

protected void addInitialColumns(CollectionDatasource datasource) {
    if (this.columns.isEmpty()) {
        MessageTools messageTools = AppBeans.get(MessageTools.NAME);
        MetaClass metaClass = datasource.getMetaClass();
        Collection<MetaPropertyPath> paths = datasource.getView() != null ? // if a view is specified - use view properties
        metadataTools.getViewPropertyPaths(datasource.getView(), metaClass) : // otherwise use all properties from meta-class
        metadataTools.getPropertyPaths(metaClass);
        for (MetaPropertyPath metaPropertyPath : paths) {
            MetaProperty property = metaPropertyPath.getMetaProperty();
            if (!property.getRange().getCardinality().isMany() && !metadataTools.isSystem(property)) {
                String propertyName = property.getName();
                ColumnImpl column = new ColumnImpl(propertyName, metaPropertyPath, this);
                MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
                column.setCaption(messageTools.getPropertyCaption(propertyMetaClass, propertyName));
                addColumn(column);
            }
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 47 with MetaPropertyPath

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

Example 48 with MetaPropertyPath

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

the class DesktopAbstractTable method addColumn.

@Override
public void addColumn(Column column) {
    checkNotNullArgument(column, "Column must be non null");
    Object columnId = column.getId();
    columns.put(columnId, column);
    columnsOrder.add(column);
    if (tableModel != null) {
        tableModel.addColumn(column);
    }
    if (datasource != null && column.isEditable() && columnId instanceof MetaPropertyPath) {
        if (!editableColumns.contains(columnId)) {
            editableColumns.add((MetaPropertyPath) columnId);
        }
    }
    setColumnIdentifiers();
    refresh();
    column.setOwner(this);
    if (column.getFormatter() == null && columnId instanceof MetaPropertyPath) {
        MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
        if (Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
            final Formatter collectionFormatter = new CollectionFormatter();
            column.setFormatter(collectionFormatter);
        }
    }
}
Also used : CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter) Formatter(com.haulmont.cuba.gui.components.Formatter) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter)

Example 49 with MetaPropertyPath

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

the class DesktopAbstractTable method getColumnEditor.

protected TableCellEditor getColumnEditor(int column) {
    TableColumn tableColumn = impl.getColumnModel().getColumn(column);
    if (tableColumn.getIdentifier() instanceof Table.Column) {
        Table.Column columnConf = (Table.Column) tableColumn.getIdentifier();
        if (columnConf.getId() instanceof MetaPropertyPath && !(isEditable() && columnConf.isEditable()) && !getTableModel().isGeneratedColumn(columnConf)) {
            MetaPropertyPath propertyPath = (MetaPropertyPath) columnConf.getId();
            final CellProvider cellProvider = getCustomCellEditor(propertyPath);
            if (cellProvider != null) {
                return new CellProviderEditor(cellProvider);
            }
        }
    }
    return null;
}
Also used : JXTable(org.jdesktop.swingx.JXTable) FocusableTable(com.haulmont.cuba.desktop.sys.vcl.FocusableTable) TableColumn(javax.swing.table.TableColumn) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) TableColumn(javax.swing.table.TableColumn)

Example 50 with MetaPropertyPath

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

the class BulkEditorWindow method ensureEmbeddedPropertyCreated.

protected void ensureEmbeddedPropertyCreated(Entity item, String propertyPath) {
    if (!StringUtils.contains(propertyPath, ".")) {
        return;
    }
    MetaPropertyPath path = metaClass.getPropertyPath(propertyPath);
    if (path != null) {
        Entity currentItem = item;
        for (MetaProperty property : path.getMetaProperties()) {
            if (metadataTools.isEmbedded(property)) {
                Object currentItemValue = currentItem.getValue(property.getName());
                if (currentItemValue == null) {
                    Entity newItem = metadata.create(property.getRange().asClass());
                    currentItem.setValue(property.getName(), newItem);
                    currentItem = newItem;
                } else {
                    currentItem = (Entity) currentItemValue;
                }
            } else {
                break;
            }
        }
    }
}
Also used : BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) Entity(com.haulmont.cuba.core.entity.Entity) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

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