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;
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations