Search in sources :

Example 1 with Filter

use of com.haulmont.cuba.gui.components.Filter in project cuba by cuba-platform.

the class FakeFilterSupport method createFakeFilter.

public Filter createFakeFilter() {
    if (filter != null) {
        return filter;
    }
    final Filter fakeFilter = AppBeans.get(ComponentsFactory.NAME, ComponentsFactory.class).createComponent(Filter.class);
    fakeFilter.setXmlDescriptor(Dom4j.readDocument("<filter/>").getRootElement());
    CollectionDatasourceImpl fakeDatasource = new CollectionDatasourceImpl();
    DsContextImpl fakeDsContext = new DsContextImpl(frame.getDsContext().getDataSupplier());
    FrameContextImpl fakeFrameContext = new FrameContextImpl(frame, Collections.<String, Object>emptyMap());
    fakeDsContext.setFrameContext(fakeFrameContext);
    fakeDatasource.setDsContext(fakeDsContext);
    // Attention: this query should match the logic in com.haulmont.reports.wizard.ReportingWizardBean.createJpqlDataSet()
    fakeDatasource.setQuery("select queryEntity from " + metaClass.getName() + " queryEntity");
    fakeDatasource.setMetaClass(metaClass);
    fakeFilter.setDatasource(fakeDatasource);
    fakeFilter.setFrame(this.frame);
    return fakeFilter;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Filter(com.haulmont.cuba.gui.components.Filter) FrameContextImpl(com.haulmont.cuba.gui.FrameContextImpl) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) DsContextImpl(com.haulmont.cuba.gui.data.impl.DsContextImpl)

Example 2 with Filter

use of com.haulmont.cuba.gui.components.Filter in project cuba by cuba-platform.

the class FoldersBean method openFolder.

@Override
public void openFolder(AbstractSearchFolder folder) {
    if (StringUtils.isBlank(folder.getFilterComponentId())) {
        log.warn("Unable to open folder: componentId is blank");
        return;
    }
    String[] strings = ValuePathHelper.parse(folder.getFilterComponentId());
    String screenId = strings[0];
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    WindowInfo windowInfo = windowConfig.getWindowInfo(screenId);
    Map<String, Object> params = new HashMap<>();
    WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
    WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
    if (!StringUtils.isBlank(folder.getTabName())) {
        WindowParams.DESCRIPTION.set(params, messages.getMainMessage(folder.getTabName()));
    } else {
        WindowParams.DESCRIPTION.set(params, messages.getMainMessage(folder.getName()));
    }
    WindowParams.FOLDER_ID.set(params, folder.getId());
    com.haulmont.cuba.gui.components.Window window = App.getInstance().getWindowManager().openWindow(windowInfo, OpenType.NEW_TAB, params);
    Filter filterComponent = null;
    if (strings.length > 1) {
        String filterComponentId = StringUtils.join(Arrays.copyOfRange(strings, 1, strings.length), '.');
        filterComponent = (Filter) window.getComponentNN(filterComponentId);
        FilterEntity filterEntity = metadata.create(FilterEntity.class);
        filterEntity.setFolder(folder);
        filterEntity.setComponentId(folder.getFilterComponentId());
        filterEntity.setName(folder.getLocName());
        filterEntity.setXml(folder.getFilterXml());
        filterEntity.setApplyDefault(BooleanUtils.isNotFalse(folder.getApplyDefault()));
        if (folder instanceof SearchFolder) {
            filterEntity.setIsSet(((SearchFolder) folder).getIsSet());
        }
        filterComponent.setFilterEntity(filterEntity);
        filterComponent.switchFilterMode(FilterDelegate.FilterMode.GENERIC_MODE);
    }
    if (filterComponent != null && folder instanceof SearchFolder) {
        final SearchFolder searchFolder = (SearchFolder) folder;
        if (searchFolder.getPresentation() != null) {
            ((com.haulmont.cuba.gui.components.Component.HasPresentations) filterComponent.getApplyTo()).applyPresentation(searchFolder.getPresentation().getId());
        }
    }
    ((DsContextImplementation) window.getDsContext()).resumeSuspended();
}
Also used : DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) HashMap(java.util.HashMap) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) Filter(com.haulmont.cuba.gui.components.Filter)

Example 3 with Filter

use of com.haulmont.cuba.gui.components.Filter in project cuba by cuba-platform.

the class RelatedEntitiesBean method openRelatedScreen.

@Override
public void openRelatedScreen(Collection<? extends Entity> selectedEntities, MetaClass metaClass, MetaProperty metaProperty, RelatedScreenDescriptor descriptor) {
    Preconditions.checkNotNullArgument(metaClass, "MetaClass can't be null");
    Preconditions.checkNotNullArgument(metaProperty, "MetaProperty can't be null");
    WindowManager windowManager = windowManagerProvider.get();
    if (!selectedEntities.isEmpty()) {
        Map<String, Object> params = new HashMap<>();
        WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
        WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
        if (descriptor != null && descriptor.getScreenParams() != null) {
            params.putAll(descriptor.getScreenParams());
        }
        String screen;
        if (descriptor != null && StringUtils.isNotEmpty(descriptor.getScreenId())) {
            screen = descriptor.getScreenId();
        } else {
            screen = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
        }
        if (StringUtils.isEmpty(screen)) {
            String message = String.format("Can't show related entities: passed screenId is null and " + "there is no default browse screen for %s", metaClass.getName());
            throw new IllegalStateException(message);
        }
        WindowManager.OpenType openType = WindowManager.OpenType.THIS_TAB;
        if (descriptor != null) {
            openType = descriptor.getOpenType();
        }
        Window window = windowManager.openWindow(windowConfig.getWindowInfo(screen), openType, params);
        boolean found = ComponentsHelper.walkComponents(window, screenComponent -> {
            if (!(screenComponent instanceof Filter)) {
                return false;
            } else {
                MetaClass actualMetaClass = ((Filter) screenComponent).getDatasource().getMetaClass();
                MetaClass relatedMetaClass = metaProperty.getRange().asClass();
                MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
                if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
                    MetaDataDescriptor metaDataDescriptor = new MetaDataDescriptor(metaClass, metaProperty);
                    applyFilter(((Filter) screenComponent), selectedEntities, descriptor, metaDataDescriptor);
                    return true;
                }
                return false;
            }
        });
        if (!found) {
            windowManager.showNotification(messages.getMainMessage("actions.Related.FilterNotFound"), Frame.NotificationType.WARNING);
        }
        ((DsContextImplementation) window.getDsContext()).resumeSuspended();
    } else {
        windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), Frame.NotificationType.HUMANIZED);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) MetaClass(com.haulmont.chile.core.model.MetaClass) Filter(com.haulmont.cuba.gui.components.Filter)

Aggregations

Filter (com.haulmont.cuba.gui.components.Filter)3 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)1 FrameContextImpl (com.haulmont.cuba.gui.FrameContextImpl)1 Window (com.haulmont.cuba.gui.components.Window)1 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)1 CollectionDatasourceImpl (com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl)1 DsContextImpl (com.haulmont.cuba.gui.data.impl.DsContextImpl)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)1 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)1 HashMap (java.util.HashMap)1