Search in sources :

Example 31 with GuiDevelopmentException

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

the class DefaultExceptionHandler method createErrorInfo.

protected ErrorInfo createErrorInfo(Throwable exception) {
    UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
    Security security = AppBeans.get(Security.NAME);
    if (userSessionSource.getUserSession() == null || !security.isSpecificPermitted("cuba.gui.showExceptionDetails")) {
        return new ErrorInfo(getMessage("errorPane.title"), getMessage("exceptionDialog.contactAdmin"), null, null, null, null, null);
    }
    Throwable rootCause = ExceptionUtils.getRootCause(exception);
    if (rootCause == null)
        rootCause = exception;
    StringBuilder msg = new StringBuilder();
    if (rootCause instanceof RemoteException) {
        RemoteException re = (RemoteException) rootCause;
        if (!re.getCauses().isEmpty()) {
            RemoteException.Cause cause = re.getCauses().get(re.getCauses().size() - 1);
            if (cause.getThrowable() != null)
                rootCause = cause.getThrowable();
            else {
                // root cause is not supported by client
                String className = cause.getClassName();
                if (className != null && className.indexOf('.') > 0) {
                    className = className.substring(className.lastIndexOf('.') + 1);
                }
                msg.append(className).append(": ").append(cause.getMessage());
            }
        }
    }
    if (msg.length() == 0) {
        msg.append(rootCause.getClass().getSimpleName());
        if (!StringUtils.isBlank(rootCause.getMessage()))
            msg.append(": ").append(rootCause.getMessage());
        if (rootCause instanceof DevelopmentException) {
            Map<String, Object> params = new LinkedHashMap<>();
            if (rootCause instanceof GuiDevelopmentException) {
                GuiDevelopmentException guiDevException = (GuiDevelopmentException) rootCause;
                if (guiDevException.getFrameId() != null) {
                    params.put("Frame ID", guiDevException.getFrameId());
                    try {
                        WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
                        params.put("XML descriptor", windowConfig.getWindowInfo(guiDevException.getFrameId()).getTemplate());
                    } catch (Exception e) {
                        params.put("XML descriptor", "not found for " + guiDevException.getFrameId());
                    }
                }
            }
            params.putAll(((DevelopmentException) rootCause).getParams());
            if (!params.isEmpty()) {
                msg.append("\n\n");
                for (Map.Entry<String, Object> entry : params.entrySet()) {
                    msg.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
                }
            }
        }
    }
    return new ErrorInfo(getMessage("errorPane.title"), msg.toString(), null, null, rootCause, null, null);
}
Also used : ErrorInfo(org.jdesktop.swingx.error.ErrorInfo) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LinkedHashMap(java.util.LinkedHashMap) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 32 with GuiDevelopmentException

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

the class LayoutLoader method getLoader.

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

Example 33 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadValidator.

@SuppressWarnings("unchecked")
protected Field.Validator loadValidator(Element validatorElement) {
    final String className = validatorElement.attributeValue("class");
    final String scriptPath = validatorElement.attributeValue("script");
    final String script = validatorElement.getText();
    Field.Validator validator = null;
    if (StringUtils.isNotBlank(scriptPath) || StringUtils.isNotBlank(script)) {
        validator = new ScriptValidator(validatorElement, getMessagesPack());
    } else {
        Class aClass = scripting.loadClass(className);
        if (aClass == null)
            throw new GuiDevelopmentException("Class " + className + " is not found", context.getFullFrameId());
        if (!StringUtils.isBlank(getMessagesPack()))
            try {
                validator = (Field.Validator) ReflectionHelper.newInstance(aClass, validatorElement, getMessagesPack());
            } catch (NoSuchMethodException e) {
            // 
            }
        if (validator == null) {
            try {
                validator = (Field.Validator) ReflectionHelper.newInstance(aClass, validatorElement);
            } catch (NoSuchMethodException e) {
                try {
                    validator = (Field.Validator) ReflectionHelper.newInstance(aClass);
                } catch (NoSuchMethodException e1) {
                // 
                }
            }
        }
        if (validator == null) {
            throw new GuiDevelopmentException("Validator class " + aClass + " has no supported constructors", context.getFullFrameId());
        }
    }
    return validator;
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 34 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadPickerDeclarativeAction.

protected Action loadPickerDeclarativeAction(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 for " + element.getName(), context.getFullFrameId());
            }
        }
        throw new GuiDevelopmentException("No action ID provided for " + element.getName(), context.getFullFrameId(), "PickerField ID", component.attributeValue("id"));
    }
    if (StringUtils.isBlank(element.attributeValue("invoke"))) {
        // Try to create a standard picker action
        for (PickerField.ActionType type : PickerField.ActionType.values()) {
            if (type.getId().equals(id)) {
                Action action = type.createAction((PickerField) actionsHolder);
                if (type != PickerField.ActionType.LOOKUP && type != PickerField.ActionType.OPEN) {
                    return action;
                }
                String openTypeString = element.attributeValue("openType");
                if (openTypeString == null) {
                    return action;
                }
                WindowManager.OpenType openType;
                try {
                    openType = WindowManager.OpenType.valueOf(openTypeString);
                } catch (IllegalArgumentException e) {
                    throw new GuiDevelopmentException("Unknown open type: '" + openTypeString + "' for action: '" + id + "'", context.getFullFrameId());
                }
                if (action instanceof PickerField.LookupAction) {
                    ((PickerField.LookupAction) action).setLookupScreenOpenType(openType);
                } else if (action instanceof PickerField.OpenAction) {
                    ((PickerField.OpenAction) action).setEditScreenOpenType(openType);
                }
                return action;
            }
        }
    }
    return loadDeclarativeActionDefault(actionsHolder, element);
}
Also used : DeclarativeTrackingAction(com.haulmont.cuba.gui.xml.DeclarativeTrackingAction) DeclarativeAction(com.haulmont.cuba.gui.xml.DeclarativeAction) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) WindowManager(com.haulmont.cuba.gui.WindowManager)

Example 35 with GuiDevelopmentException

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

the class AbstractResourceViewLoader method loadFileResource.

protected boolean loadFileResource(ResourceView resultComponent, Element element) {
    Element fileResource = element.element("file");
    if (fileResource == null)
        return false;
    String filePath = fileResource.attributeValue("path");
    if (StringUtils.isEmpty(filePath)) {
        throw new GuiDevelopmentException("No path provided for the FileResource", context.getFullFrameId());
    }
    File file = new File(filePath);
    if (!file.exists()) {
        String msg = String.format("Can't load FileResource. File with given path does not exists: %s", filePath);
        throw new GuiDevelopmentException(msg, context.getFullFrameId());
    }
    FileResource resource = resultComponent.createResource(FileResource.class);
    resource.setFile(file);
    loadStreamSettings(resource, fileResource);
    resultComponent.setSource(resource);
    return true;
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) File(java.io.File)

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