Search in sources :

Example 1 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadFormatter.

protected Formatter loadFormatter(Element element) {
    final Element formatterElement = element.element("formatter");
    if (formatterElement != null) {
        final String className = formatterElement.attributeValue("class");
        if (StringUtils.isEmpty(className)) {
            throw new GuiDevelopmentException("Formatter's attribute 'class' is not specified", context.getCurrentFrameId());
        }
        Class<?> aClass = scripting.loadClass(className);
        if (aClass == null) {
            throw new GuiDevelopmentException(String.format("Class %s is not found", className), context.getFullFrameId());
        }
        try {
            final Constructor<?> constructor = aClass.getConstructor(Element.class);
            try {
                return (Formatter) constructor.newInstance(formatterElement);
            } catch (Throwable e) {
                throw new GuiDevelopmentException("Unable to instatiate class " + className + ": " + e.toString(), context.getFullFrameId());
            }
        } catch (NoSuchMethodException e) {
            try {
                return (Formatter) aClass.newInstance();
            } catch (Exception e1) {
                throw new GuiDevelopmentException("Unable to instatiate class " + className + ": " + e1.toString(), context.getFullFrameId());
            }
        }
    } else {
        return null;
    }
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 2 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadShortcutFromFQNConfig.

protected String loadShortcutFromFQNConfig(String shortcut) {
    if (shortcut.contains("#")) {
        String[] splittedShortcut = shortcut.split("#");
        if (splittedShortcut.length != 2) {
            String message = "An error occurred while loading shortcut: incorrect format of shortcut.";
            throw new GuiDevelopmentException(message, context.getFullFrameId());
        }
        String fqnConfigName = splittedShortcut[0].substring(2);
        String methodName = splittedShortcut[1].substring(0, splittedShortcut[1].length() - 1);
        // noinspection unchecked
        Class<Config> configClass = (Class<Config>) scripting.loadClass(fqnConfigName);
        if (configClass != null) {
            Config config = configuration.getConfig(configClass);
            try {
                String shortcutValue = (String) MethodUtils.invokeMethod(config, methodName, null);
                if (StringUtils.isNotEmpty(shortcutValue)) {
                    return shortcutValue;
                }
            } catch (NoSuchMethodException e) {
                String message = String.format("An error occurred while loading shortcut: " + "can't find method \"%s\" in \"%s\"", methodName, fqnConfigName);
                throw new GuiDevelopmentException(message, context.getFullFrameId());
            } catch (IllegalAccessException | InvocationTargetException e) {
                String message = String.format("An error occurred while loading shortcut: " + "can't invoke method \"%s\" in \"%s\"", methodName, fqnConfigName);
                throw new GuiDevelopmentException(message, context.getFullFrameId());
            }
        } else {
            String message = String.format("An error occurred while loading shortcut: " + "can't find config interface \"%s\"", fqnConfigName);
            throw new GuiDevelopmentException(message, context.getFullFrameId());
        }
    }
    return null;
}
Also used : Config(com.haulmont.cuba.core.config.Config) LayoutLoaderConfig(com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig) ClientConfig(com.haulmont.cuba.client.ClientConfig) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) MetaClass(com.haulmont.chile.core.model.MetaClass) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadDeclarativeActionDefault.

protected Action loadDeclarativeActionDefault(Component.ActionsHolder actionsHolder, Element element) {
    String id = element.attributeValue("id");
    if (id == null) {
        Element component = element;
        for (int i = 0; i < 2; i++) {
            if (component.getParent() != null)
                component = component.getParent();
            else
                throw new GuiDevelopmentException("No action ID provided", context.getFullFrameId());
        }
        throw new GuiDevelopmentException("No action ID provided", context.getFullFrameId(), "Component ID", component.attributeValue("id"));
    }
    String trackSelection = element.attributeValue("trackSelection");
    String shortcut = StringUtils.trimToNull(element.attributeValue("shortcut"));
    shortcut = loadShortcut(shortcut);
    if (Boolean.parseBoolean(trackSelection)) {
        DeclarativeTrackingAction action = new DeclarativeTrackingAction(id, loadResourceString(element.attributeValue("caption")), loadResourceString(element.attributeValue("description")), getIconPath(element.attributeValue("icon")), element.attributeValue("enable"), element.attributeValue("visible"), element.attributeValue("invoke"), shortcut, actionsHolder);
        loadActionConstraint(action, element);
        return action;
    } else {
        return new DeclarativeAction(id, loadResourceString(element.attributeValue("caption")), loadResourceString(element.attributeValue("description")), getIconPath(element.attributeValue("icon")), element.attributeValue("enable"), element.attributeValue("visible"), element.attributeValue("invoke"), shortcut, actionsHolder);
    }
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) DeclarativeTrackingAction(com.haulmont.cuba.gui.xml.DeclarativeTrackingAction) DeclarativeAction(com.haulmont.cuba.gui.xml.DeclarativeAction)

Example 4 with GuiDevelopmentException

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

the class AbstractComponentLoader method getLoader.

protected ComponentLoader getLoader(Element element, Class<? extends ComponentLoader> loaderClass) {
    ComponentLoader loader;
    try {
        Constructor<? extends ComponentLoader> constructor = loaderClass.getConstructor();
        loader = constructor.newInstance();
        loader.setLocale(locale);
        loader.setMessagesPack(messagesPack);
        loader.setContext(context);
        loader.setLayoutLoaderConfig(layoutLoaderConfig);
        loader.setFactory(factory);
        loader.setElement(element);
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
        throw new GuiDevelopmentException("Loader instatiation error: " + e, context.getFullFrameId());
    }
    return loader;
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader)

Example 5 with GuiDevelopmentException

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

the class AbstractDatasourceComponentLoader method loadDatasource.

protected void loadDatasource(DatasourceComponent 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)

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