Search in sources :

Example 1 with DatasourceDataUnit

use of com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit in project cuba by cuba-platform.

the class WebFilterHelper method initTableFtsTooltips.

@Override
public void initTableFtsTooltips(ListComponent listComponent, MetaClass metaClass, String searchTerm) {
    FtsFilterHelper ftsFilterHelper;
    if (beanLocator.containsBean(FtsFilterHelper.NAME)) {
        ftsFilterHelper = beanLocator.get(FtsFilterHelper.class);
    } else {
        return;
    }
    if (listComponent instanceof Table) {
        Map<Object, String> tooltipsCache = new HashMap<>();
        Map<Object, String> metaClassesCache = new HashMap<>();
        listComponent.withUnwrapped(com.vaadin.v7.ui.Table.class, vTable -> vTable.setItemDescriptionGenerator((source, itemId, propertyId) -> {
            return tooltipsCache.computeIfAbsent(itemId, k -> {
                if (k instanceof GroupInfo) {
                    return "";
                }
                return ftsFilterHelper.buildTableTooltip(metaClassesCache.computeIfAbsent(itemId, id -> {
                    DataUnit dataUnit = listComponent.getItems();
                    Entity<?> entity = null;
                    if (dataUnit instanceof DatasourceDataUnit) {
                        // legacy GUI
                        entity = ((DatasourceDataUnit) dataUnit).getDatasource().getItem(id);
                    } else if (dataUnit instanceof ContainerDataUnit) {
                        entity = ((ContainerDataUnit) dataUnit).getContainer().getItem(id);
                    }
                    if (entity != null)
                        return entity.getMetaClass().getName();
                    return metaClass.getName();
                }), k, searchTerm);
            });
        }));
    } else if (listComponent instanceof DataGrid) {
        ((DataGrid) listComponent).setRowDescriptionProvider(o -> {
            if (o instanceof Entity) {
                Entity entity = (Entity) o;
                return ftsFilterHelper.buildTableTooltip(entity.getMetaClass().getName(), entity.getId(), searchTerm);
            } else {
                return null;
            }
        }, ContentMode.HTML);
    }
}
Also used : FtsFilterHelper(com.haulmont.cuba.gui.components.filter.FtsFilterHelper) java.util(java.util) GroupCondition(com.haulmont.cuba.gui.components.filter.condition.GroupCondition) DropLocation(com.vaadin.shared.ui.grid.DropLocation) Screen(com.haulmont.cuba.gui.screen.Screen) AppFolderEditWindow(com.haulmont.cuba.web.app.folders.AppFolderEditWindow) MetaClass(com.haulmont.chile.core.model.MetaClass) Inject(javax.inject.Inject) GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) Configuration(com.haulmont.cuba.core.global.Configuration) TreeGridDragSource(com.vaadin.ui.components.grid.TreeGridDragSource) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) AppUI(com.haulmont.cuba.web.AppUI) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Nullable(javax.annotation.Nullable) CubaTree(com.haulmont.cuba.web.widgets.CubaTree) Presentations(com.haulmont.cuba.gui.presentations.Presentations) DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) FoldersPane(com.haulmont.cuba.gui.components.mainwindow.FoldersPane) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) CubaTextField(com.haulmont.cuba.web.widgets.CubaTextField) TreeGridDropTarget(com.vaadin.ui.components.grid.TreeGridDropTarget) Folder(com.haulmont.cuba.core.entity.Folder) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper) UiControllerUtils.getHostScreen(com.haulmont.cuba.gui.screen.UiControllerUtils.getHostScreen) WebConfig(com.haulmont.cuba.web.WebConfig) DatasourceDataUnit(com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit) ShortcutListenerDelegate(com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate) Node(com.haulmont.bali.datastruct.Node) FolderEditWindow(com.haulmont.cuba.web.app.folders.FolderEditWindow) BeanLocator(com.haulmont.cuba.core.global.BeanLocator) CubaFoldersPane(com.haulmont.cuba.web.app.folders.CubaFoldersPane) UiComponents(com.haulmont.cuba.gui.UiComponents) DropMode(com.vaadin.shared.ui.grid.DropMode) Entity(com.haulmont.cuba.core.entity.Entity) Component(com.vaadin.ui.Component) Entity(com.haulmont.cuba.core.entity.Entity) GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) DatasourceDataUnit(com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit) DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) DatasourceDataUnit(com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) FtsFilterHelper(com.haulmont.cuba.gui.components.filter.FtsFilterHelper)

Example 2 with DatasourceDataUnit

use of com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit in project cuba by cuba-platform.

the class UiTestIds method getInferredTestId.

@Nullable
public static String getInferredTestId(DataUnit dataUnit, String suffix) {
    if (dataUnit instanceof ContainerDataUnit) {
        ContainerDataUnit dcDataUnit = (ContainerDataUnit) dataUnit;
        MetaClass entityMetaClass = dcDataUnit.getEntityMetaClass();
        return entityMetaClass.getName() + suffix;
    } else if (dataUnit instanceof DatasourceDataUnit) {
        DatasourceDataUnit dsDataUnit = (DatasourceDataUnit) dataUnit;
        MetaClass entityMetaClass = dsDataUnit.getDatasource().getMetaClass();
        return entityMetaClass.getName() + suffix;
    }
    return null;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) DatasourceDataUnit(com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) Nullable(javax.annotation.Nullable)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)2 ContainerDataUnit (com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)2 DatasourceDataUnit (com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit)2 Nullable (javax.annotation.Nullable)2 Node (com.haulmont.bali.datastruct.Node)1 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Folder (com.haulmont.cuba.core.entity.Folder)1 BeanLocator (com.haulmont.cuba.core.global.BeanLocator)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 UiComponents (com.haulmont.cuba.gui.UiComponents)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 DataUnit (com.haulmont.cuba.gui.components.data.DataUnit)1 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)1 FilterHelper (com.haulmont.cuba.gui.components.filter.FilterHelper)1 FtsFilterHelper (com.haulmont.cuba.gui.components.filter.FtsFilterHelper)1 AbstractCondition (com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)1 GroupCondition (com.haulmont.cuba.gui.components.filter.condition.GroupCondition)1 FoldersPane (com.haulmont.cuba.gui.components.mainwindow.FoldersPane)1 GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)1