Search in sources :

Example 41 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractTableLoader method loadTableData.

protected void loadTableData() {
    TableDataHolder holder = initTableDataHolder();
    if (!holder.isContainerLoaded() && holder.getMetaClass() == null) {
        throw new GuiDevelopmentException("Table doesn't have data binding", context, "Table ID", element.attributeValue("id"));
    }
    List<Table.Column> availableColumns;
    Element columnsElement = element.element("columns");
    if (columnsElement != null) {
        FetchPlan fetchPlan = holder.getFetchPlan();
        if (fetchPlan == null) {
            fetchPlan = getViewRepository().getFetchPlan(holder.getMetaClass(), FetchPlan.BASE);
        }
        availableColumns = loadColumns(resultComponent, columnsElement, holder.getMetaClass(), fetchPlan);
    } else {
        availableColumns = new ArrayList<>();
    }
    for (Table.Column column : availableColumns) {
        loadRequired(resultComponent, column);
    }
    setupDataContainer(holder);
    if (resultComponent.getItems() == null) {
        // noinspection unchecked
        resultComponent.setItems(createEmptyTableItems(holder.getMetaClass()));
    }
    for (Table.Column column : availableColumns) {
        if (column.getXmlDescriptor() != null) {
            String generatorMethod = column.getXmlDescriptor().attributeValue("generator");
            if (StringUtils.isNotEmpty(generatorMethod)) {
                // noinspection unchecked
                resultComponent.addGeneratedColumn(String.valueOf(column), applicationContext.getBean(DeclarativeColumnGenerator.class, resultComponent, generatorMethod));
            }
        }
    }
}
Also used : Table(io.jmix.ui.component.Table) DeclarativeColumnGenerator(io.jmix.ui.xml.DeclarativeColumnGenerator) Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 42 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class BrowserFrameLoader method loadSrcdocFile.

protected void loadSrcdocFile(BrowserFrame resultComponent, Element element) {
    String srcdocFile = element.attributeValue("srcdocFile");
    if (StringUtils.isNotEmpty(srcdocFile)) {
        if (StringUtils.isNotEmpty(resultComponent.getSrcdoc())) {
            throw new GuiDevelopmentException("'Srcdoc' and 'srcdocFile' cannot be used in the same time for BrowserFrame", context);
        }
        Resources resources = applicationContext.getBean(Resources.class);
        String resource = resources.getResourceAsString(srcdocFile);
        if (resource == null) {
            String msg = String.format("Can't load srcdocFile in BrowserFrame. The file with given path not found: %s", srcdocFile);
            throw new GuiDevelopmentException(msg, context);
        }
        resultComponent.setSrcdoc(resource);
    }
}
Also used : GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Resources(io.jmix.core.Resources)

Example 43 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class CalendarLoader method loadDataContainer.

@SuppressWarnings("unchecked")
protected void loadDataContainer(Calendar component, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (Strings.isNullOrEmpty(containerId)) {
        return;
    }
    FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
    ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
    InstanceContainer container = screenData.getContainer(containerId);
    if (!(container instanceof CollectionContainer)) {
        throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
    }
    component.setEventProvider(new ContainerCalendarEventProvider<>(((CollectionContainer) container)));
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 44 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class CalendarLoader method loadStartDate.

protected void loadStartDate(Calendar resultComponent, Element element) {
    String startDateAttribute = element.attributeValue("startDate");
    if (StringUtils.isNotEmpty(startDateAttribute)) {
        try {
            Date date = parseDateOrDateTime(startDateAttribute);
            Object startDate = convertToType(date, resultComponent.getDatatype().getJavaClass());
            resultComponent.setStartDate(startDate);
        } catch (ParseException e) {
            throw new GuiDevelopmentException("'startDate' parsing error for calendar: " + startDateAttribute, context, "Calendar ID", resultComponent.getId());
        }
    }
}
Also used : GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) ParseException(java.text.ParseException) Date(java.util.Date)

Example 45 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class TreeTableLoader method createContainerTableSource.

@SuppressWarnings("unchecked")
@Override
protected ContainerTableItems createContainerTableSource(CollectionContainer container) {
    Element rowsEl = element.element("rows");
    String hierarchyProperty = element.attributeValue("hierarchyProperty");
    if (hierarchyProperty == null && rowsEl != null) {
        hierarchyProperty = rowsEl.attributeValue("hierarchyProperty");
    }
    if (Strings.isNullOrEmpty(hierarchyProperty)) {
        throw new GuiDevelopmentException("TreeTable doesn't have 'hierarchyProperty' attribute", context, "TreeTable ID", element.attributeValue("id"));
    }
    String showOrphansAttr = element.attributeValue("showOrphans");
    boolean showOrphans = showOrphansAttr == null || Boolean.parseBoolean(showOrphansAttr);
    return new ContainerTreeTableItems(container, hierarchyProperty, showOrphans);
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) ContainerTreeTableItems(io.jmix.ui.component.data.table.ContainerTreeTableItems)

Aggregations

GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)106 Element (org.dom4j.Element)42 FrameOwner (io.jmix.ui.screen.FrameOwner)16 Component (io.jmix.ui.component.Component)13 InstanceContainer (io.jmix.ui.model.InstanceContainer)11 ScreenData (io.jmix.ui.model.ScreenData)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)9 MetaClass (io.jmix.core.metamodel.model.MetaClass)8 Action (io.jmix.ui.action.Action)7 BaseAction (io.jmix.ui.action.BaseAction)6 ParseException (java.text.ParseException)6 Date (java.util.Date)6 Nullable (javax.annotation.Nullable)6 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 ComponentLoader (io.jmix.ui.xml.layout.ComponentLoader)5 ArrayList (java.util.ArrayList)5 Datasource (com.haulmont.cuba.gui.data.Datasource)4 Formatter (io.jmix.ui.component.formatter.Formatter)4 JsonParser (com.google.gson.JsonParser)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3