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