Search in sources :

Example 1 with ScreenSettings

use of io.jmix.ui.settings.ScreenSettings in project jmix by jmix-framework.

the class UiDataFilterSupport method saveFilterSettings.

protected void saveFilterSettings(ScreenSettingsFacet screenSettingsFacet, String filterId, FilterConfiguration configurationModel) {
    ScreenSettings settings = screenSettingsFacet.getSettings();
    if (settings == null) {
        throw new IllegalStateException("ScreenSettingsFacet is not attached to the frame");
    }
    FilterSettings filterSettings = settings.getSettingsOrCreate(filterId, FilterSettings.class);
    if (Objects.equals(filterSettings.getDefaultConfigurationId(), configurationModel.getConfigurationId()) && !configurationModel.getDefaultForMe()) {
        filterSettings.setDefaultConfigurationId(null);
    }
    if (configurationModel.getDefaultForMe()) {
        filterSettings.setDefaultConfigurationId(configurationModel.getConfigurationId());
    }
    settings.put(filterSettings);
}
Also used : ScreenSettings(io.jmix.ui.settings.ScreenSettings) FilterSettings(io.jmix.ui.settings.component.FilterSettings)

Example 2 with ScreenSettings

use of io.jmix.ui.settings.ScreenSettings in project jmix by jmix-framework.

the class ScreenSettingsFacetResolver method resolveLazyTabSelectEvent.

/**
 * Resolves applying settings and presentations for components in a lazy tab e.g. {@link TabSheet} or
 * {@link Accordion}.
 *
 * @param window     screen window
 * @param source     component source
 * @param components tab content
 */
public void resolveLazyTabSelectEvent(Window window, Component source, Collection<Component> components) {
    List<PresentationsFacet> presentationsFacet = window.getFacets().filter(facet -> facet instanceof PresentationsFacet).map(facet -> (PresentationsFacet) facet).collect(Collectors.toList());
    boolean isPresentationsAdded = presentationsFacet.size() > 0;
    Collection<Component> managedComponents = getManagedComponents(presentationsFacet, components);
    if (isPresentationsAdded) {
        for (Component component : managedComponents) {
            if (component instanceof HasTablePresentations) {
                ((HasTablePresentations) component).loadPresentations();
            }
        }
        if (presentationsManager != null) {
            presentationsManager.setupDefaultSettings(managedComponents);
        }
    }
    window.getFacets().forEach(facet -> {
        if (facet instanceof ScreenSettingsFacet) {
            ScreenSettingsFacet settingsFacet = (ScreenSettingsFacet) facet;
            Consumer<ScreenSettingsFacet.SettingsContext> applyHandler = settingsFacet.getApplySettingsDelegate();
            ScreenSettings settings = settingsFacet.getSettings();
            if (settings == null) {
                throw new IllegalStateException("ScreenSettingsFacet is not attached to the frame");
            }
            if (applyHandler != null) {
                applyHandler.accept(new ScreenSettingsFacet.SettingsContext(source, components, settings));
            } else {
                settingsFacet.applySettings(components);
            }
        }
    });
    if (isPresentationsAdded && presentationsManager != null) {
        presentationsManager.applyDefaultPresentation(managedComponents);
    }
}
Also used : Internal(io.jmix.core.annotation.Internal) Consumer(java.util.function.Consumer) ScreenSettings(io.jmix.ui.settings.ScreenSettings) java.util(java.util) PresentationsManager(io.jmix.ui.presentation.PresentationsManager) Autowired(org.springframework.beans.factory.annotation.Autowired) Screen(io.jmix.ui.screen.Screen) Collectors(java.util.stream.Collectors) PresentationsFacet(io.jmix.ui.presentation.facet.PresentationsFacet) io.jmix.ui.component(io.jmix.ui.component) PresentationsFacet(io.jmix.ui.presentation.facet.PresentationsFacet) ScreenSettings(io.jmix.ui.settings.ScreenSettings)

Example 3 with ScreenSettings

use of io.jmix.ui.settings.ScreenSettings in project jmix by jmix-framework.

the class FilterMakeDefaultAction method execute.

@Override
public void execute() {
    if (filter.getFrame() == null) {
        throw new IllegalStateException("Filter component is not attached to the Frame");
    }
    ScreenSettingsFacet screenSettingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
    if (screenSettingsFacet == null) {
        throw new IllegalStateException("The Frame does no contain ScreenSettingsFacet");
    }
    ScreenSettings settings = screenSettingsFacet.getSettings();
    if (settings == null) {
        throw new IllegalStateException("ScreenSettingsFacet is not attached to the frame");
    }
    FilterSettings filterSettings = new FilterSettings();
    filterSettings.setId(filter.getId());
    filterSettings.setDefaultConfigurationId(filter.getCurrentConfiguration().getId());
    settings.put(filterSettings);
}
Also used : ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) ScreenSettings(io.jmix.ui.settings.ScreenSettings) FilterSettings(io.jmix.ui.settings.component.FilterSettings)

Example 4 with ScreenSettings

use of io.jmix.ui.settings.ScreenSettings in project jmix by jmix-framework.

the class UiDataFilterSupport method isDefaultForMeFieldVisible.

protected boolean isDefaultForMeFieldVisible(Filter.Configuration currentConfiguration, FilterConfiguration configurationModel) {
    Frame filterFrame = currentConfiguration.getOwner().getFrame();
    if (currentConfiguration.getOwner().getId() != null && filterFrame != null) {
        ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filterFrame, ScreenSettingsFacet.class);
        if (settingsFacet != null) {
            ScreenSettings settings = settingsFacet.getSettings();
            if (settings != null) {
                settings.getSettings(currentConfiguration.getOwner().getId(), FilterSettings.class).ifPresent(filterSettings -> {
                    String defaultConfigurationId = filterSettings.getDefaultConfigurationId();
                    if (defaultConfigurationId != null) {
                        boolean defaultForMe = defaultConfigurationId.equals(configurationModel.getConfigurationId());
                        configurationModel.setDefaultForMe(defaultForMe);
                    }
                });
            }
            return true;
        }
    }
    return false;
}
Also used : Frame(io.jmix.ui.component.Frame) ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) ScreenSettings(io.jmix.ui.settings.ScreenSettings) FilterSettings(io.jmix.ui.settings.component.FilterSettings)

Aggregations

ScreenSettings (io.jmix.ui.settings.ScreenSettings)4 FilterSettings (io.jmix.ui.settings.component.FilterSettings)3 ScreenSettingsFacet (io.jmix.ui.settings.facet.ScreenSettingsFacet)2 Internal (io.jmix.core.annotation.Internal)1 io.jmix.ui.component (io.jmix.ui.component)1 Frame (io.jmix.ui.component.Frame)1 PresentationsManager (io.jmix.ui.presentation.PresentationsManager)1 PresentationsFacet (io.jmix.ui.presentation.facet.PresentationsFacet)1 Screen (io.jmix.ui.screen.Screen)1 java.util (java.util)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1