Search in sources :

Example 16 with GuiDevelopmentException

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

the class GridLayoutLoader method createSubComponents.

protected void createSubComponents(GridLayout gridLayout, Element element, int row) {
    LayoutLoader loader = new LayoutLoader(context, factory, layoutLoaderConfig);
    loader.setLocale(getLocale());
    loader.setMessagesPack(getMessagesPack());
    int col = 0;
    // noinspection unchecked
    for (Element subElement : (Collection<Element>) element.elements()) {
        ComponentLoader componentLoader = loader.createComponent(subElement);
        pendingLoadComponents.add(componentLoader);
        Component subComponent = componentLoader.getResultComponent();
        String colspan = subElement.attributeValue("colspan");
        String rowspan = subElement.attributeValue("rowspan");
        if (col >= spanMatrix.length) {
            Map<String, Object> params = new HashMap<>();
            params.put("Grid ID", gridLayout.getId());
            String rowId = element.attributeValue("id");
            if (StringUtils.isNotEmpty(rowId)) {
                params.put("Row ID", rowId);
            } else {
                params.put("Row Index", row);
            }
            throw new GuiDevelopmentException("Grid column count is less than number of components in grid row", context.getFullFrameId(), params);
        }
        while (spanMatrix[col][row]) {
            col++;
        }
        if (StringUtils.isEmpty(colspan) && StringUtils.isEmpty(rowspan)) {
            addSubComponent(gridLayout, subComponent, col, row, col, row);
        } else {
            int cspan = 1;
            int rspan = 1;
            if (StringUtils.isNotEmpty(colspan)) {
                cspan = Integer.parseInt(colspan);
                if (cspan < 1) {
                    throw new GuiDevelopmentException("GridLayout colspan can not be less than 1", context.getFullFrameId(), "colspan", cspan);
                }
                if (cspan == 1) {
                    LoggerFactory.getLogger(GridLayoutLoader.class).warn("Do not use colspan=\"1\", it will have no effect");
                }
            }
            if (StringUtils.isNotEmpty(rowspan)) {
                rspan = Integer.parseInt(rowspan);
                if (rspan < 1) {
                    throw new GuiDevelopmentException("GridLayout rowspan can not be less than 1", context.getFullFrameId(), "rowspan", rspan);
                }
                if (rspan == 1) {
                    LoggerFactory.getLogger(GridLayoutLoader.class).warn("Do not use rowspan=\"1\", it will have no effect");
                }
            }
            fillSpanMatrix(col, row, cspan, rspan);
            int endColumn = col + cspan - 1;
            int endRow = row + rspan - 1;
            addSubComponent(gridLayout, subComponent, col, row, endColumn, endRow);
        }
        col++;
    }
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Component(com.haulmont.cuba.gui.components.Component) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader)

Example 17 with GuiDevelopmentException

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

the class GroupTableLoader method loadColumns.

@Override
protected List<Table.Column> loadColumns(final Table component, Element columnsElement, CollectionDatasource ds) {
    List<Table.Column> columns = new ArrayList<>();
    Element groupElement = columnsElement.element("group");
    if (groupElement != null) {
        columns.addAll(super.loadColumns(component, groupElement, ds));
        final List<Object> groupProperties = new ArrayList<>(columns.size());
        for (Table.Column column : columns) {
            if (column.isCollapsed()) {
                String msg = String.format("Can't group by collapsed column: %s", column.getId());
                throw new GuiDevelopmentException(msg, context.getFullFrameId());
            }
            if (column.isGroupAllowed()) {
                groupProperties.add(column.getId());
            }
        }
        context.addPostInitTask((context1, window) -> ((GroupTable) component).groupBy(groupProperties.toArray()));
    }
    columns.addAll(super.loadColumns(component, columnsElement, ds));
    return columns;
}
Also used : GroupTable(com.haulmont.cuba.gui.components.GroupTable) Table(com.haulmont.cuba.gui.components.Table) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 18 with GuiDevelopmentException

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

the class ImageLoader method loadDatasource.

protected void loadDatasource(Image component, Element element) {
    final String datasource = element.attributeValue("datasource");
    if (!StringUtils.isEmpty(datasource)) {
        Datasource ds = context.getDsContext().get(datasource);
        if (ds == null) {
            throw new GuiDevelopmentException(String.format("Datasource '%s' is not defined", datasource), getContext().getFullFrameId(), "Component ID", component.getId());
        }
        String property = element.attributeValue("property");
        if (StringUtils.isEmpty(property)) {
            throw new GuiDevelopmentException(String.format("Can't set datasource '%s' for component '%s' because 'property' " + "attribute is not defined", datasource, component.getId()), context.getFullFrameId());
        }
        component.setDatasource(ds, property);
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 19 with GuiDevelopmentException

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

the class LookupFieldLoader method loadNewOptionHandler.

protected void loadNewOptionHandler(final LookupField component, Element element) {
    String newOptionAllowed = element.attributeValue("newOptionAllowed");
    if (StringUtils.isNotEmpty(newOptionAllowed)) {
        component.setNewOptionAllowed(Boolean.parseBoolean(newOptionAllowed));
    }
    String newOptionHandlerMethod = element.attributeValue("newOptionHandler");
    if (StringUtils.isNotEmpty(newOptionHandlerMethod)) {
        // todo artamonov use PostWrap task here
        context.addPostInitTask((context1, window) -> {
            Method newOptionHandler;
            try {
                Class<? extends Frame> windowClass = window.getClass();
                newOptionHandler = windowClass.getMethod(newOptionHandlerMethod, LookupField.class, String.class);
            } catch (NoSuchMethodException e) {
                Map<String, Object> params = ParamsMap.of("LookupField Id", component.getId(), "Method name", newOptionHandlerMethod);
                throw new GuiDevelopmentException("Unable to find new option handler method for lookup field", context1.getFullFrameId(), params);
            }
            component.setNewOptionHandler(caption -> {
                try {
                    newOptionHandler.invoke(window, component, caption);
                } catch (IllegalAccessException | InvocationTargetException e) {
                    throw new RuntimeException("Unable to invoke new option handler", e);
                }
            });
        });
    }
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LookupField(com.haulmont.cuba.gui.components.LookupField) Method(java.lang.reflect.Method) ParamsMap(com.haulmont.bali.util.ParamsMap) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with GuiDevelopmentException

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

the class SearchFieldLoader method loadComponent.

@Override
public void loadComponent() {
    super.loadComponent();
    SearchField searchField = (SearchField) resultComponent;
    String minSearchStringLength = element.attributeValue("minSearchStringLength");
    if (StringUtils.isNotEmpty(minSearchStringLength)) {
        searchField.setMinSearchStringLength(Integer.parseInt(minSearchStringLength));
    }
    String modeString = element.attributeValue("mode");
    if (StringUtils.isNotEmpty(modeString)) {
        SearchField.Mode mode;
        try {
            mode = SearchField.Mode.valueOf(StringUtils.upperCase(modeString));
        } catch (IllegalArgumentException e) {
            throw new GuiDevelopmentException("Unable to parse mode for search", context.getFullFrameId(), "mode", modeString);
        }
        searchField.setMode(mode);
    }
    String escapeValueForLike = element.attributeValue("escapeValueForLike");
    if (StringUtils.isNotEmpty(escapeValueForLike)) {
        searchField.setEscapeValueForLike(Boolean.parseBoolean(escapeValueForLike));
    }
}
Also used : SearchField(com.haulmont.cuba.gui.components.SearchField) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Aggregations

GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)55 Element (org.dom4j.Element)23 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 Component (com.haulmont.cuba.gui.components.Component)7 Datasource (com.haulmont.cuba.gui.data.Datasource)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 MetaClass (com.haulmont.chile.core.model.MetaClass)5 ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)3 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)3 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)3 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)3 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)3 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 Column (com.haulmont.cuba.gui.components.DataGrid.Column)2 ListComponent (com.haulmont.cuba.gui.components.ListComponent)2 DsContext (com.haulmont.cuba.gui.data.DsContext)2 ByteArrayDataProvider (com.haulmont.cuba.gui.export.ByteArrayDataProvider)2