Search in sources :

Example 1 with HasSettings

use of com.haulmont.cuba.gui.components.HasSettings 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 HasSettings

use of com.haulmont.cuba.gui.components.HasSettings 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)

Aggregations

HasPresentations (com.haulmont.cuba.gui.components.HasPresentations)2 HasSettings (com.haulmont.cuba.gui.components.HasSettings)2 Element (org.dom4j.Element)2 Presentations (com.haulmont.cuba.gui.presentations.Presentations)1 UUID (java.util.UUID)1