Search in sources :

Example 1 with HasPresentations

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

the class ScreenSettings method saveSettings.

/**
 * Save settings of screen.
 *
 * @param screen   screen
 * @param settings settings
 */
public void saveSettings(Screen screen, Settings settings) {
    checkNotNullArgument(screen);
    checkNotNullArgument(settings);
    walkComponents(screen.getWindow(), (component, name) -> {
        if (component.getId() != null && component instanceof HasSettings) {
            log.trace("Saving settings for {} : {}", name, component);
            Element e = settings.get(name);
            boolean modified = ((HasSettings) component).saveSettings(e);
            if (component instanceof HasPresentations && ((HasPresentations) component).isUsePresentations()) {
                Object def = ((HasPresentations) component).getDefaultPresentationId();
                e.addAttribute("presentation", def != null ? def.toString() : "");
                Presentations presentations = ((HasPresentations) component).getPresentations();
                if (presentations != null) {
                    presentations.commit();
                }
            }
            if (modified) {
                settings.setModified(true);
            }
        }
    });
    settings.commit();
}
Also used : HasPresentations(com.haulmont.cuba.gui.components.HasPresentations) Element(org.dom4j.Element) HasSettings(com.haulmont.cuba.gui.components.HasSettings) Presentations(com.haulmont.cuba.gui.presentations.Presentations) HasPresentations(com.haulmont.cuba.gui.components.HasPresentations)

Example 2 with HasPresentations

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

the class ScreenSettings method applySettings.

/**
 * Apply settings for screen.
 *
 * @param screen   screen
 * @param settings settings
 */
public void applySettings(Screen screen, Settings settings) {
    checkNotNullArgument(screen);
    checkNotNullArgument(settings);
    walkComponents(screen.getWindow(), (component, name) -> {
        if (component.getId() != null && component instanceof HasSettings) {
            log.trace("Applying settings for {} : {} ", name, component);
            Element e = settings.get(name);
            ((HasSettings) component).applySettings(e);
            if (component instanceof HasPresentations && e.attributeValue("presentation") != null) {
                String def = e.attributeValue("presentation");
                if (!StringUtils.isEmpty(def)) {
                    UUID defaultId = UUID.fromString(def);
                    ((HasPresentations) component).applyPresentationAsDefault(defaultId);
                }
            }
        }
    });
}
Also used : HasPresentations(com.haulmont.cuba.gui.components.HasPresentations) Element(org.dom4j.Element) HasSettings(com.haulmont.cuba.gui.components.HasSettings) UUID(java.util.UUID)

Example 3 with HasPresentations

use of com.haulmont.cuba.gui.components.HasPresentations 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];
    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());
    WindowManager wm = App.getInstance().getWindowManager();
    Window window = wm.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) {
        SearchFolder searchFolder = (SearchFolder) folder;
        if (searchFolder.getPresentation() != null) {
            ((HasPresentations) filterComponent.getApplyTo()).applyPresentation(searchFolder.getPresentation().getId());
        }
    }
    if (window.getFrameOwner() instanceof LegacyFrame) {
        DsContext dsContext = ((LegacyFrame) window.getFrameOwner()).getDsContext();
        if (dsContext != null) {
            ((DsContextImplementation) dsContext).resumeSuspended();
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) HasPresentations(com.haulmont.cuba.gui.components.HasPresentations) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) DsContext(com.haulmont.cuba.gui.data.DsContext) 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) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) WindowManager(com.haulmont.cuba.gui.WindowManager) Filter(com.haulmont.cuba.gui.components.Filter)

Aggregations

HasPresentations (com.haulmont.cuba.gui.components.HasPresentations)3 HasSettings (com.haulmont.cuba.gui.components.HasSettings)2 Element (org.dom4j.Element)2 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 Filter (com.haulmont.cuba.gui.components.Filter)1 Window (com.haulmont.cuba.gui.components.Window)1 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)1 DsContext (com.haulmont.cuba.gui.data.DsContext)1 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)1 Presentations (com.haulmont.cuba.gui.presentations.Presentations)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)1 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1