use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class GridLayoutLoader method createSubComponents.
protected void createSubComponents(GridLayout gridLayout, Element element, int row) {
LayoutLoader loader = new LayoutLoader(context, factory, layoutLoaderConfig);
loader.setLocale(getLocale());
loader.setMessagesPack(getMessagesPack());
int col = 0;
// noinspection unchecked
for (Element subElement : (Collection<Element>) element.elements()) {
ComponentLoader componentLoader = loader.createComponent(subElement);
pendingLoadComponents.add(componentLoader);
Component subComponent = componentLoader.getResultComponent();
String colspan = subElement.attributeValue("colspan");
String rowspan = subElement.attributeValue("rowspan");
if (col >= spanMatrix.length) {
Map<String, Object> params = new HashMap<>();
params.put("Grid ID", gridLayout.getId());
String rowId = element.attributeValue("id");
if (StringUtils.isNotEmpty(rowId)) {
params.put("Row ID", rowId);
} else {
params.put("Row Index", row);
}
throw new GuiDevelopmentException("Grid column count is less than number of components in grid row", context.getFullFrameId(), params);
}
while (spanMatrix[col][row]) {
col++;
}
if (StringUtils.isEmpty(colspan) && StringUtils.isEmpty(rowspan)) {
addSubComponent(gridLayout, subComponent, col, row, col, row);
} else {
int cspan = 1;
int rspan = 1;
if (StringUtils.isNotEmpty(colspan)) {
cspan = Integer.parseInt(colspan);
if (cspan < 1) {
throw new GuiDevelopmentException("GridLayout colspan can not be less than 1", context.getFullFrameId(), "colspan", cspan);
}
if (cspan == 1) {
LoggerFactory.getLogger(GridLayoutLoader.class).warn("Do not use colspan=\"1\", it will have no effect");
}
}
if (StringUtils.isNotEmpty(rowspan)) {
rspan = Integer.parseInt(rowspan);
if (rspan < 1) {
throw new GuiDevelopmentException("GridLayout rowspan can not be less than 1", context.getFullFrameId(), "rowspan", rspan);
}
if (rspan == 1) {
LoggerFactory.getLogger(GridLayoutLoader.class).warn("Do not use rowspan=\"1\", it will have no effect");
}
}
fillSpanMatrix(col, row, cspan, rspan);
int endColumn = col + cspan - 1;
int endRow = row + rspan - 1;
addSubComponent(gridLayout, subComponent, col, row, endColumn, endRow);
}
col++;
}
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class GroupTableLoader method loadColumns.
@Override
protected List<Table.Column> loadColumns(final Table component, Element columnsElement, CollectionDatasource ds) {
List<Table.Column> columns = new ArrayList<>();
Element groupElement = columnsElement.element("group");
if (groupElement != null) {
columns.addAll(super.loadColumns(component, groupElement, ds));
final List<Object> groupProperties = new ArrayList<>(columns.size());
for (Table.Column column : columns) {
if (column.isCollapsed()) {
String msg = String.format("Can't group by collapsed column: %s", column.getId());
throw new GuiDevelopmentException(msg, context.getFullFrameId());
}
if (column.isGroupAllowed()) {
groupProperties.add(column.getId());
}
}
context.addPostInitTask((context1, window) -> ((GroupTable) component).groupBy(groupProperties.toArray()));
}
columns.addAll(super.loadColumns(component, columnsElement, ds));
return columns;
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class ImageLoader method loadDatasource.
protected void loadDatasource(Image 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);
}
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class LookupFieldLoader method loadNewOptionHandler.
protected void loadNewOptionHandler(final LookupField component, Element element) {
String newOptionAllowed = element.attributeValue("newOptionAllowed");
if (StringUtils.isNotEmpty(newOptionAllowed)) {
component.setNewOptionAllowed(Boolean.parseBoolean(newOptionAllowed));
}
String newOptionHandlerMethod = element.attributeValue("newOptionHandler");
if (StringUtils.isNotEmpty(newOptionHandlerMethod)) {
// todo artamonov use PostWrap task here
context.addPostInitTask((context1, window) -> {
Method newOptionHandler;
try {
Class<? extends Frame> windowClass = window.getClass();
newOptionHandler = windowClass.getMethod(newOptionHandlerMethod, LookupField.class, String.class);
} catch (NoSuchMethodException e) {
Map<String, Object> params = ParamsMap.of("LookupField Id", component.getId(), "Method name", newOptionHandlerMethod);
throw new GuiDevelopmentException("Unable to find new option handler method for lookup field", context1.getFullFrameId(), params);
}
component.setNewOptionHandler(caption -> {
try {
newOptionHandler.invoke(window, component, caption);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Unable to invoke new option handler", e);
}
});
});
}
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class SearchFieldLoader method loadComponent.
@Override
public void loadComponent() {
super.loadComponent();
SearchField searchField = (SearchField) resultComponent;
String minSearchStringLength = element.attributeValue("minSearchStringLength");
if (StringUtils.isNotEmpty(minSearchStringLength)) {
searchField.setMinSearchStringLength(Integer.parseInt(minSearchStringLength));
}
String modeString = element.attributeValue("mode");
if (StringUtils.isNotEmpty(modeString)) {
SearchField.Mode mode;
try {
mode = SearchField.Mode.valueOf(StringUtils.upperCase(modeString));
} catch (IllegalArgumentException e) {
throw new GuiDevelopmentException("Unable to parse mode for search", context.getFullFrameId(), "mode", modeString);
}
searchField.setMode(mode);
}
String escapeValueForLike = element.attributeValue("escapeValueForLike");
if (StringUtils.isNotEmpty(escapeValueForLike)) {
searchField.setEscapeValueForLike(Boolean.parseBoolean(escapeValueForLike));
}
}
Aggregations