Search in sources :

Example 41 with MetaPropertyPath

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

the class WebAbstractTable method createColumns.

protected Collection<MetaPropertyPath> createColumns(com.vaadin.data.Container ds) {
    @SuppressWarnings("unchecked") final Collection<MetaPropertyPath> properties = (Collection<MetaPropertyPath>) ds.getContainerPropertyIds();
    Window window = ComponentsHelper.getWindowImplementation(this);
    boolean isLookup = window instanceof Window.Lookup;
    for (MetaPropertyPath propertyPath : properties) {
        final Table.Column column = columns.get(propertyPath);
        if (column != null && !(editable && BooleanUtils.isTrue(column.isEditable()))) {
            final String isLink = column.getXmlDescriptor() == null ? null : column.getXmlDescriptor().attributeValue("link");
            if (propertyPath.getRange().isClass()) {
                if (!isLookup && StringUtils.isNotEmpty(isLink)) {
                    setClickListener(propertyPath.toString(), new LinkCellClickListener());
                }
            } else if (propertyPath.getRange().isDatatype()) {
                if (!isLookup && !StringUtils.isEmpty(isLink)) {
                    setClickListener(propertyPath.toString(), new LinkCellClickListener());
                } else if (editable && BooleanUtils.isTrue(column.isCalculatable())) {
                    addGeneratedColumn(propertyPath, new CalculatableColumnGenerator());
                } else {
                    if (column.getMaxTextLength() != null) {
                        addGeneratedColumn(propertyPath, new AbbreviatedColumnGenerator(column));
                        setClickListener(propertyPath.toString(), new AbbreviatedCellClickListener());
                    }
                }
            } else if (!propertyPath.getRange().isEnum()) {
                throw new UnsupportedOperationException();
            }
        }
    }
    return properties;
}
Also used : Window(com.haulmont.cuba.gui.components.Window) Table(com.haulmont.cuba.gui.components.Table) CubaEnhancedTable(com.haulmont.cuba.web.toolkit.ui.CubaEnhancedTable) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 42 with MetaPropertyPath

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

the class WebAbstractTable method checkAggregation.

protected void checkAggregation(AggregationInfo aggregationInfo) {
    MetaPropertyPath propertyPath = aggregationInfo.getPropertyPath();
    Class<?> javaType = propertyPath.getMetaProperty().getJavaType();
    Aggregation<?> aggregation = Aggregations.get(javaType);
    AggregationInfo.Type aggregationType = aggregationInfo.getType();
    if (aggregationType == AggregationInfo.Type.CUSTOM)
        return;
    if (aggregation != null && aggregation.getSupportedAggregationTypes().contains(aggregationType))
        return;
    String msg = String.format("Unable to aggregate column \"%s\" with data type %s with default aggregation strategy: %s", propertyPath, propertyPath.getRange(), aggregationInfo.getType());
    throw new IllegalArgumentException(msg);
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 43 with MetaPropertyPath

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

the class WebAbstractTable method saveSettings.

@Override
public boolean saveSettings(Element element) {
    if (!isSettingsEnabled()) {
        return false;
    }
    if (isUsePresentations()) {
        element.addAttribute("textSelection", String.valueOf(component.isTextSelectionEnabled()));
    }
    Element columnsElem = element.element("columns");
    if (columnsElem != null) {
        element.remove(columnsElem);
    }
    columnsElem = element.addElement("columns");
    Object[] visibleColumns = component.getVisibleColumns();
    for (Object column : visibleColumns) {
        Element colElem = columnsElem.addElement("columns");
        colElem.addAttribute("id", column.toString());
        int width = component.getColumnWidth(column);
        if (width > -1)
            colElem.addAttribute("width", String.valueOf(width));
        Boolean visible = !component.isColumnCollapsed(column);
        colElem.addAttribute("visible", visible.toString());
    }
    MetaPropertyPath sortProperty = (MetaPropertyPath) component.getSortContainerPropertyId();
    if (sortProperty != null) {
        Boolean sortAscending = component.isSortAscending();
        columnsElem.addAttribute("sortProperty", sortProperty.toString());
        columnsElem.addAttribute("sortAscending", sortAscending.toString());
    }
    return true;
}
Also used : Element(org.dom4j.Element) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 44 with MetaPropertyPath

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

the class WebAbstractTable method addColumn.

@Override
public void addColumn(Table.Column column) {
    checkNotNullArgument(column, "Column must be non null");
    Object columnId = column.getId();
    component.addContainerProperty(columnId, column.getType(), null);
    if (StringUtils.isNotBlank(column.getDescription())) {
        component.setColumnDescription(columnId, column.getDescription());
    }
    if (StringUtils.isNotBlank(column.getValueDescription())) {
        component.setAggregationDescription(columnId, column.getValueDescription());
    } else if (column.getAggregation() != null && column.getAggregation().getType() != AggregationInfo.Type.CUSTOM) {
        Messages messages = AppBeans.get(Messages.NAME);
        String aggregationTypeLabel;
        switch(column.getAggregation().getType()) {
            case AVG:
                aggregationTypeLabel = "aggreagtion.avg";
                break;
            case COUNT:
                aggregationTypeLabel = "aggreagtion.count";
                break;
            case SUM:
                aggregationTypeLabel = "aggreagtion.sum";
                break;
            case MIN:
                aggregationTypeLabel = "aggreagtion.min";
                break;
            case MAX:
                aggregationTypeLabel = "aggreagtion.max";
                break;
            default:
                throw new IllegalArgumentException(String.format("AggregationType %s is not supported", column.getAggregation().getType().toString()));
        }
        component.setAggregationDescription(columnId, messages.getMainMessage(aggregationTypeLabel));
    }
    if (!column.isSortable()) {
        component.setColumnSortable(columnId, column.isSortable());
    }
    columns.put(columnId, column);
    columnsOrder.add(column);
    if (column.getWidth() != null) {
        component.setColumnWidth(columnId, column.getWidth());
    }
    if (column.getAlignment() != null) {
        component.setColumnAlignment(columnId, WebComponentsHelper.convertColumnAlignment(column.getAlignment()));
    }
    final String caption = getColumnCaption(columnId, column);
    setColumnHeader(columnId, caption);
    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);
        }
    }
    if (columnId instanceof MetaPropertyPath) {
        PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
        MetaPropertyPath propertyPath = (MetaPropertyPath) columnId;
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
        String storeName = metadataTools.getStoreName(propertyMetaClass);
        if (metadataTools.isLob(metaProperty) && !persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
            component.setColumnSortable(columnId, false);
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter) Formatter(com.haulmont.cuba.gui.components.Formatter) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) MetaProperty(com.haulmont.chile.core.model.MetaProperty) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter)

Example 45 with MetaPropertyPath

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

the class WebDataGrid method applyColumnSettings.

protected void applyColumnSettings(Element element, Collection<Column> oldColumns) {
    final Element columnsElem = element.element("columns");
    List<Column> newColumns = new ArrayList<>();
    // add columns from saved settings
    for (Element colElem : Dom4j.elements(columnsElem, "columns")) {
        for (Column column : oldColumns) {
            if (column.getId().equals(colElem.attributeValue("id"))) {
                newColumns.add(column);
                String width = colElem.attributeValue("width");
                if (width != null) {
                    column.setWidth(Double.parseDouble(width));
                } else {
                    column.setWidthAuto();
                }
                String collapsed = colElem.attributeValue("collapsed");
                if (collapsed != null && component.isColumnReorderingAllowed()) {
                    column.setCollapsed(Boolean.parseBoolean(collapsed));
                }
                break;
            }
        }
    }
    // add columns not saved in settings (perhaps new)
    for (Column column : oldColumns) {
        if (!newColumns.contains(column)) {
            newColumns.add(column);
        }
    }
    // if the data grid contains only one column, always show it
    if (newColumns.size() == 1) {
        newColumns.get(0).setCollapsed(false);
    }
    List<Object> properties = newColumns.stream().map(column -> ((ColumnImpl) column).getColumnPropertyId()).collect(Collectors.toList());
    // We don't save settings for columns hidden by security permissions,
    // so we need to return them back to they initial positions
    columnsOrder = restoreColumnsOrder(newColumns);
    component.setColumnOrder(properties.toArray());
    if (isSortable()) {
        // apply sorting
        component.clearSortOrder();
        String sortPropertyName = columnsElem.attributeValue("sortProperty");
        if (!StringUtils.isEmpty(sortPropertyName)) {
            MetaPropertyPath sortProperty = datasource.getMetaClass().getPropertyPath(sortPropertyName);
            if (properties.contains(sortProperty) && sortProperty != null) {
                String sortDirection = columnsElem.attributeValue("sortDirection");
                if (StringUtils.isNotEmpty(sortDirection)) {
                    List<com.vaadin.data.sort.SortOrder> sortOrders = Collections.singletonList(new com.vaadin.data.sort.SortOrder(sortProperty, com.vaadin.shared.data.sort.SortDirection.valueOf(sortDirection)));
                    component.setSortOrder(sortOrders);
                }
            }
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Datasource(com.haulmont.cuba.gui.data.Datasource) Dom4j(com.haulmont.bali.util.Dom4j) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) IconResolver(com.haulmont.cuba.web.gui.icons.IconResolver) Window(com.haulmont.cuba.gui.components.Window) AppUI(com.haulmont.cuba.web.AppUI) MenuItem(com.vaadin.addon.contextmenu.MenuItem) EventRouter(com.haulmont.bali.events.EventRouter) SecuredActionsHolder(com.haulmont.cuba.gui.components.Component.SecuredActionsHolder) FormatterBasedConverter(com.haulmont.cuba.web.toolkit.ui.converters.FormatterBasedConverter) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyValueGenerator(com.vaadin.data.util.PropertyValueGenerator) App(com.haulmont.cuba.web.App) Collectors(java.util.stream.Collectors) ObjectToObjectConverter(com.haulmont.cuba.web.toolkit.ui.converters.ObjectToObjectConverter) PropertyChangeListener(java.beans.PropertyChangeListener) ComponentsHelper.findActionById(com.haulmont.cuba.gui.ComponentsHelper.findActionById) GeneratedPropertyContainer(com.vaadin.data.util.GeneratedPropertyContainer) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) ClientConfig(com.haulmont.cuba.client.ClientConfig) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) com.haulmont.cuba.web.gui.components.renderers(com.haulmont.cuba.web.gui.components.renderers) java.util(java.util) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter) GridContextMenuOpenListener(com.vaadin.addon.contextmenu.GridContextMenu.GridContextMenuOpenListener) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) CssLayout(com.vaadin.ui.CssLayout) MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionUtils(org.apache.commons.collections4.CollectionUtils) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Validator(com.vaadin.data.Validator) Field(com.haulmont.cuba.gui.components.Field) SortableDataGridIndexedCollectionDsWrapper(com.haulmont.cuba.web.gui.data.SortableDataGridIndexedCollectionDsWrapper) com.haulmont.cuba.gui.data.impl(com.haulmont.cuba.gui.data.impl) DataGridIndexedCollectionDsWrapper(com.haulmont.cuba.web.gui.data.DataGridIndexedCollectionDsWrapper) com.haulmont.cuba.web.toolkit.ui(com.haulmont.cuba.web.toolkit.ui) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) Nullable(javax.annotation.Nullable) Item(com.vaadin.data.Item) Formatter(com.haulmont.cuba.gui.components.Formatter) DataGridContainer(com.haulmont.cuba.web.toolkit.data.DataGridContainer) MetaProperty(com.haulmont.chile.core.model.MetaProperty) StringToObjectConverter(com.haulmont.cuba.web.toolkit.ui.converters.StringToObjectConverter) ErrorMessage(com.vaadin.server.ErrorMessage) Preconditions(com.haulmont.bali.util.Preconditions) HeightMode(com.vaadin.shared.ui.grid.HeightMode) ShortcutListener(com.vaadin.event.ShortcutListener) Menu(com.vaadin.addon.contextmenu.Menu) Element(org.dom4j.Element) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) YesNoIconConverter(com.haulmont.cuba.web.toolkit.ui.converters.YesNoIconConverter) Entity(com.haulmont.cuba.core.entity.Entity) com.vaadin.ui(com.vaadin.ui) Component(com.vaadin.ui.Component) Element(org.dom4j.Element) 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