Search in sources :

Example 1 with EntityTableItems

use of io.jmix.ui.component.data.meta.EntityTableItems in project jmix by jmix-framework.

the class WebTable method getItemDatasource.

@SuppressWarnings("unchecked")
@Override
public Datasource getItemDatasource(Entity item) {
    if (fieldDatasources == null) {
        fieldDatasources = new WeakHashMap<>();
    }
    Object fieldDatasource = fieldDatasources.get(item);
    if (fieldDatasource instanceof Datasource) {
        return (Datasource) fieldDatasource;
    }
    EntityTableItems containerTableItems = (EntityTableItems) getItems();
    Datasource datasource = DsBuilder.create().setAllowCommit(false).setMetaClass(containerTableItems.getEntityMetaClass()).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setViewName(View.LOCAL).buildDatasource();
    ((DatasourceImplementation) datasource).valid();
    datasource.setItem(item);
    fieldDatasources.put(item, datasource);
    return datasource;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Example 2 with EntityTableItems

use of io.jmix.ui.component.data.meta.EntityTableItems in project jmix by jmix-framework.

the class WebGroupTable method getItemDatasource.

@SuppressWarnings("unchecked")
@Override
public Datasource getItemDatasource(Entity item) {
    if (fieldDatasources == null) {
        fieldDatasources = new WeakHashMap<>();
    }
    Object fieldDatasource = fieldDatasources.get(item);
    if (fieldDatasource instanceof Datasource) {
        return (Datasource) fieldDatasource;
    }
    EntityTableItems containerTableItems = (EntityTableItems) getItems();
    Datasource datasource = DsBuilder.create().setAllowCommit(false).setMetaClass(containerTableItems.getEntityMetaClass()).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setViewName(View.LOCAL).buildDatasource();
    ((DatasourceImplementation) datasource).valid();
    datasource.setItem(item);
    fieldDatasources.put(item, datasource);
    return datasource;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Example 3 with EntityTableItems

use of io.jmix.ui.component.data.meta.EntityTableItems in project jmix by jmix-framework.

the class WebTreeTable method getItemDatasource.

@SuppressWarnings("unchecked")
@Override
public Datasource getItemDatasource(Entity item) {
    if (fieldDatasources == null) {
        fieldDatasources = new WeakHashMap<>();
    }
    Object fieldDatasource = fieldDatasources.get(item);
    if (fieldDatasource instanceof Datasource) {
        return (Datasource) fieldDatasource;
    }
    EntityTableItems containerTableItems = (EntityTableItems) getItems();
    Datasource datasource = DsBuilder.create().setAllowCommit(false).setMetaClass(containerTableItems.getEntityMetaClass()).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setViewName(View.LOCAL).buildDatasource();
    ((DatasourceImplementation) datasource).valid();
    datasource.setItem(item);
    fieldDatasources.put(item, datasource);
    return datasource;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Example 4 with EntityTableItems

use of io.jmix.ui.component.data.meta.EntityTableItems in project jmix by jmix-framework.

the class GroupTableSettingsBinder method applyColumnSettings.

@Override
protected void applyColumnSettings(TableSettings tableSettings, Table table) {
    super.applyColumnSettings(tableSettings, table);
    GroupTableSettings groupTableSettings = (GroupTableSettings) tableSettings;
    List<String> groupProperties = groupTableSettings.getGroupProperties();
    if (groupProperties != null) {
        MetaClass metaClass = ((EntityTableItems) table.getItems()).getEntityMetaClass();
        List<MetaPropertyPath> properties = new ArrayList<>(groupProperties.size());
        for (String id : groupProperties) {
            MetaPropertyPath property = metadataTools.resolveMetaPropertyPathOrNull(metaClass, id);
            if (property != null) {
                properties.add(property);
            } else {
                log.warn("Ignored group property '{}'", id);
            }
        }
        ((GroupTable) table).groupBy(properties.toArray());
    } else {
        ((GroupTable) table).ungroup();
    }
}
Also used : GroupTable(io.jmix.ui.component.GroupTable) JmixGroupTable(io.jmix.ui.widget.JmixGroupTable) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) ArrayList(java.util.ArrayList) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) GroupTableSettings(io.jmix.ui.settings.component.GroupTableSettings)

Example 5 with EntityTableItems

use of io.jmix.ui.component.data.meta.EntityTableItems in project jmix by jmix-framework.

the class AbstractTable method tableSourceItemSetChanged.

@Override
public void tableSourceItemSetChanged(TableItems.ItemSetChangeEvent<E> event) {
    // replacement for collectionChangeSelectionListener
    // #PL-2035, reload selection from ds
    Set<Object> selectedItemIds = getSelectedItemIds();
    if (selectedItemIds == null) {
        selectedItemIds = Collections.emptySet();
    }
    Set<Object> newSelection = new LinkedHashSet<>();
    TableItems<E> tableItems = event.getSource();
    for (Object entityId : selectedItemIds) {
        if (tableItems.getItem(entityId) != null) {
            newSelection.add(entityId);
        }
    }
    if (tableItems.getState() == BindingState.ACTIVE && tableItems instanceof EntityTableItems) {
        EntityTableItems entityTableSource = (EntityTableItems) tableItems;
        if (entityTableSource.getSelectedItem() != null) {
            newSelection.add(EntityValues.getId(entityTableSource.getSelectedItem()));
        }
    }
    if (newSelection.isEmpty()) {
        setSelected((E) null);
    } else {
        setSelectedIds(newSelection);
    }
    refreshActionsState();
}
Also used : EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems)

Aggregations

EntityTableItems (io.jmix.ui.component.data.meta.EntityTableItems)11 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)6 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 Datasource (com.haulmont.cuba.gui.data.Datasource)3 DatasourceImplementation (com.haulmont.cuba.gui.data.impl.DatasourceImplementation)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 TableSettings (io.jmix.ui.settings.component.TableSettings)2 Nullable (javax.annotation.Nullable)2 com.vaadin.ui (com.vaadin.ui)1 AbstractComponent (com.vaadin.ui.AbstractComponent)1 Component (com.vaadin.ui.Component)1 FetchPlan (io.jmix.core.FetchPlan)1 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)1 GroupTable (io.jmix.ui.component.GroupTable)1 HasValueSource (io.jmix.ui.component.data.HasValueSource)1 TableItems (io.jmix.ui.component.data.TableItems)1 InstanceContainer (io.jmix.ui.model.InstanceContainer)1 GroupTableSettings (io.jmix.ui.settings.component.GroupTableSettings)1 JmixGroupTable (io.jmix.ui.widget.JmixGroupTable)1 ArrayList (java.util.ArrayList)1