Search in sources :

Example 1 with HasSettingsPresentation

use of com.haulmont.cuba.settings.component.HasSettingsPresentation in project jmix by jmix-framework.

the class LegacyTableSettingsConverter method convertToComponentSettings.

@SuppressWarnings("unchecked")
@Override
public TableSettings convertToComponentSettings(Element settings) {
    TableSettings tableSettings = createSettings();
    tableSettings.setId(settings.attributeValue("name"));
    String textSelection = settings.attributeValue("textSelection");
    if (StringUtils.isNotBlank(textSelection)) {
        tableSettings.setTextSelection(Boolean.parseBoolean(textSelection));
    }
    String presentationId = settings.attributeValue("presentation");
    if (StringUtils.isNotBlank(presentationId) && tableSettings instanceof HasSettingsPresentation) {
        ((HasSettingsPresentation) tableSettings).setPresentationId(UuidProvider.fromString(presentationId));
    }
    Element columnsElem = settings.element("columns");
    if (columnsElem != null) {
        String sortProperty = columnsElem.attributeValue("sortProperty");
        if (StringUtils.isNotBlank(sortProperty)) {
            tableSettings.setSortProperty(sortProperty);
            String sortAscending = columnsElem.attributeValue("sortAscending");
            tableSettings.setSortAscending(Boolean.parseBoolean(sortAscending));
        }
        List<Element> columns = columnsElem.elements("columns");
        List<ColumnSettings> columnsSett = new ArrayList<>(columns.size());
        for (Element column : columns) {
            ColumnSettings columnSett = new ColumnSettings();
            columnSett.setId(column.attributeValue("id"));
            String width = column.attributeValue("width");
            if (StringUtils.isNotBlank(width)) {
                columnSett.setWidth(Integer.parseInt(width));
            }
            String visible = column.attributeValue("visible");
            if (StringUtils.isNotBlank(visible)) {
                columnSett.setVisible(Boolean.parseBoolean(visible));
            }
            columnsSett.add(columnSett);
        }
        tableSettings.setColumns(columnsSett);
    }
    return tableSettings;
}
Also used : CubaTableSettings(com.haulmont.cuba.settings.component.CubaTableSettings) TableSettings(io.jmix.ui.settings.component.TableSettings) HasSettingsPresentation(com.haulmont.cuba.settings.component.HasSettingsPresentation) ColumnSettings(io.jmix.ui.settings.component.TableSettings.ColumnSettings) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Example 2 with HasSettingsPresentation

use of com.haulmont.cuba.settings.component.HasSettingsPresentation in project jmix by jmix-framework.

the class LegacyTableSettingsConverter method copySettingsToElement.

protected void copySettingsToElement(TableSettings tableSettings, Element element) {
    element.addAttribute("name", tableSettings.getId());
    Boolean textSelection = tableSettings.getTextSelection();
    if (textSelection != null)
        element.addAttribute("textSelection", textSelection.toString());
    if (tableSettings instanceof HasSettingsPresentation) {
        UUID presentationId = ((HasSettingsPresentation) tableSettings).getPresentationId();
        if (presentationId != null) {
            element.addAttribute("presentation", presentationId.toString());
        }
    }
    List<ColumnSettings> columns = tableSettings.getColumns();
    if (columns != null) {
        Element columnsElem = element.addElement("columns");
        if (tableSettings.getSortProperty() != null) {
            columnsElem.addAttribute("sortProperty", tableSettings.getSortProperty());
            columnsElem.addAttribute("sortAscending", tableSettings.getSortAscending().toString());
        }
        for (ColumnSettings column : columns) {
            Element columnElem = columnsElem.addElement("columns");
            columnElem.addAttribute("id", column.getId());
            if (column.getWidth() != null) {
                columnElem.addAttribute("width", column.getWidth().toString());
            }
            if (column.getVisible() != null) {
                columnElem.addAttribute("visible", column.getVisible().toString());
            }
        }
    }
}
Also used : HasSettingsPresentation(com.haulmont.cuba.settings.component.HasSettingsPresentation) ColumnSettings(io.jmix.ui.settings.component.TableSettings.ColumnSettings) Element(org.dom4j.Element) UUID(java.util.UUID)

Aggregations

HasSettingsPresentation (com.haulmont.cuba.settings.component.HasSettingsPresentation)2 ColumnSettings (io.jmix.ui.settings.component.TableSettings.ColumnSettings)2 Element (org.dom4j.Element)2 CubaTableSettings (com.haulmont.cuba.settings.component.CubaTableSettings)1 TableSettings (io.jmix.ui.settings.component.TableSettings)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1