Search in sources :

Example 51 with GuiDevelopmentException

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

the class RuntimePropertiesFrameLoader method loadComponent.

@Override
public void loadComponent() {
    if (resultComponent.getMessagesPack() == null) {
        resultComponent.setMessagesPack(messagesPack);
    }
    assignXmlDescriptor(resultComponent, element);
    loadVisible(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadAlign(resultComponent, element);
    loadHeight(resultComponent, element, ComponentsHelper.getComponentHeigth(resultComponent));
    loadWidth(resultComponent, element, ComponentsHelper.getComponentWidth(resultComponent));
    String src = element.attributeValue("src");
    if (src == null) {
        src = DEFAULT_DESCRIPTOR;
    }
    String runtimeDs = element.attributeValue("runtimeDs");
    if (StringUtils.isEmpty(runtimeDs)) {
        throw new GuiDevelopmentException("runtimePropsDatasource is not set for runtimeProperties component", context.getFullFrameId());
    }
    context.getParams().put("runtimeDs", runtimeDs);
    String categoriesDs = element.attributeValue("categoriesDs");
    if (StringUtils.isEmpty(categoriesDs)) {
        throw new GuiDevelopmentException("categoriesDs is not set for runtimeProperties component", context.getFullFrameId());
    }
    context.getParams().put("categoriesDs", categoriesDs);
    String rows = element.attributeValue("rows");
    context.getParams().put("rows", rows);
    String cols = element.attributeValue("cols");
    context.getParams().put("cols", cols);
    String fieldWidth = element.attributeValue("fieldWidth");
    context.getParams().put("fieldWidth", fieldWidth);
    String fieldCaptionWidth = element.attributeValue("fieldCaptionWidth");
    context.getParams().put("fieldCaptionWidth", fieldCaptionWidth);
    String screenPath = Objects.equals(src, DEFAULT_DESCRIPTOR) ? "runtimeProperties" : src;
    if (element.attributeValue("id") != null) {
        screenPath = element.attributeValue("id");
    }
    if (context.getFrame() != null) {
        String parentId = context.getFullFrameId();
        if (StringUtils.isNotEmpty(parentId)) {
            screenPath = parentId + "." + screenPath;
        }
    }
    StopWatch loadDescriptorWatch = new Slf4JStopWatch(screenPath + "#" + UIPerformanceLogger.LifeCycle.LOAD, LoggerFactory.getLogger(UIPerformanceLogger.class));
    loadDescriptorWatch.start();
    String currentFrameId = context.getCurrentFrameId();
    try {
        context.setCurrentFrameId(frameId);
        frameLoader.loadComponent();
    } finally {
        context.setCurrentFrameId(currentFrameId);
        loadDescriptorWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 52 with GuiDevelopmentException

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

the class SplitPanelLoader method loadMaxSplitPosition.

protected void loadMaxSplitPosition(SplitPanel resultComponent, Element element) {
    String maxSplitPosition = element.attributeValue("maxSplitPosition");
    if (!StringUtils.isEmpty(maxSplitPosition)) {
        int position;
        int unit;
        if (maxSplitPosition.endsWith("px")) {
            position = Integer.parseInt(maxSplitPosition.substring(0, maxSplitPosition.indexOf("px")));
            unit = Component.UNITS_PIXELS;
        } else if (maxSplitPosition.endsWith("%")) {
            position = Integer.parseInt(maxSplitPosition.substring(0, maxSplitPosition.indexOf("%")));
            unit = Component.UNITS_PERCENTAGE;
        } else {
            throw new GuiDevelopmentException("Unit of maxSplitPosition is not set", context.getFullFrameId());
        }
        resultComponent.setMaxSplitPosition(position, unit);
    }
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 53 with GuiDevelopmentException

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

the class SplitPanelLoader method loadMinSplitPosition.

protected void loadMinSplitPosition(SplitPanel resultComponent, Element element) {
    String minSplitPosition = element.attributeValue("minSplitPosition");
    if (!StringUtils.isEmpty(minSplitPosition)) {
        int position;
        int unit;
        if (minSplitPosition.endsWith("px")) {
            position = Integer.parseInt(minSplitPosition.substring(0, minSplitPosition.indexOf("px")));
            unit = Component.UNITS_PIXELS;
        } else if (minSplitPosition.endsWith("%")) {
            position = Integer.parseInt(minSplitPosition.substring(0, minSplitPosition.indexOf("%")));
            unit = Component.UNITS_PERCENTAGE;
        } else {
            throw new GuiDevelopmentException("Unit of minSplitPosition is not set", context.getFullFrameId());
        }
        resultComponent.setMinSplitPosition(position, unit);
    }
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 54 with GuiDevelopmentException

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

the class SuggestionFieldQueryLoader method loadQuery.

protected void loadQuery(SuggestionField suggestionField, Element element) {
    Element queryElement = element.element("query");
    if (queryElement != null) {
        final boolean escapeValue;
        String stringQuery = queryElement.getStringValue();
        String searchFormat = queryElement.attributeValue("searchStringFormat");
        String view = queryElement.attributeValue("view");
        String escapeValueForLike = queryElement.attributeValue("escapeValueForLike");
        if (StringUtils.isNotEmpty(escapeValueForLike)) {
            escapeValue = Boolean.valueOf(escapeValueForLike);
        } else {
            escapeValue = false;
        }
        String entityClassName = queryElement.attributeValue("entityClass");
        if (StringUtils.isNotEmpty(entityClassName)) {
            suggestionField.setSearchExecutor((searchString, searchParams) -> {
                DataSupplier supplier = suggestionField.getFrame().getDsContext().getDataSupplier();
                Class<Entity> entityClass = ReflectionHelper.getClass(entityClassName);
                if (escapeValue) {
                    searchString = QueryUtils.escapeForLike(searchString);
                }
                searchString = applySearchFormat(searchString, searchFormat);
                LoadContext loadContext = LoadContext.create(entityClass);
                if (StringUtils.isNotEmpty(view)) {
                    loadContext.setView(view);
                }
                loadContext.setQuery(LoadContext.createQuery(stringQuery).setParameter("searchString", searchString));
                // noinspection unchecked
                return supplier.loadList(loadContext);
            });
        } else {
            throw new GuiDevelopmentException(String.format("Field 'entityClass' is empty in component %s.", suggestionField.getId()), getContext().getFullFrameId());
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LoadContext(com.haulmont.cuba.core.global.LoadContext)

Example 55 with GuiDevelopmentException

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

the class WindowLoader method loadTimer.

protected void loadTimer(ComponentsFactory factory, final Window component, Element element) {
    Timer timer = factory.createTimer();
    timer.setXmlDescriptor(element);
    timer.setId(element.attributeValue("id"));
    String delay = element.attributeValue("delay");
    if (StringUtils.isEmpty(delay)) {
        throw new GuiDevelopmentException("Timer 'delay' can't be empty", context.getCurrentFrameId(), "Timer ID", timer.getId());
    }
    int value;
    try {
        value = Integer.parseInt(delay);
    } catch (NumberFormatException e) {
        throw new GuiDevelopmentException("Timer 'delay' must be numeric", context.getFullFrameId(), ParamsMap.of("Timer delay", delay, "Timer ID", timer.getId()));
    }
    if (value <= 0) {
        throw new GuiDevelopmentException("Timer 'delay' must be greater than 0", context.getFullFrameId(), "Timer ID", timer.getId());
    }
    timer.setDelay(value);
    timer.setRepeating(Boolean.parseBoolean(element.attributeValue("repeating")));
    String onTimer = element.attributeValue("onTimer");
    if (StringUtils.isNotEmpty(onTimer)) {
        String timerMethodName = onTimer;
        if (StringUtils.startsWith(onTimer, "invoke:")) {
            timerMethodName = StringUtils.substring(onTimer, "invoke:".length());
        }
        timerMethodName = StringUtils.trim(timerMethodName);
        addInitTimerMethodTask(timer, timerMethodName);
    }
    String autostart = element.attributeValue("autostart");
    if (StringUtils.isNotEmpty(autostart) && Boolean.parseBoolean(autostart)) {
        addAutoStartTimerTask(timer);
    }
    timer.setFrame(context.getFrame());
    component.addTimer(timer);
}
Also used : Timer(com.haulmont.cuba.gui.components.Timer) 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