use of com.haulmont.cuba.gui.components.GridLayout in project jmix by jmix-framework.
the class FilterDelegateImpl method recursivelyCreateConditionsLayout.
protected void recursivelyCreateConditionsLayout(ConditionsFocusType conditionsFocusType, boolean initialFocusSet, List<Node<AbstractCondition>> nodes, ComponentContainer parentContainer, int level) {
FilterDataContext filterDataContext = new FilterDataContext(filter.getFrame());
List<Node<AbstractCondition>> visibleConditionNodes = fetchVisibleNodes(nodes);
if (visibleConditionNodes.isEmpty()) {
if (level == 0)
controlsLayout.setStyleName("filter-control-no-border");
return;
}
// note that this is not grid columns count, but number of conditions (label cell + value cell) in one row
int conditionsCount = getColumnsCount();
int row = 0;
int nextColumnStart = 0;
GridLayout grid = uiComponents.create(GridLayout.class);
grid.setStyleName("conditions-grid");
grid.setColumns(conditionsCount * 2);
// set expand ratio only for cells with param edit components
for (int i = 0; i < conditionsCount; i++) {
grid.setColumnExpandRatio(i * 2 + 1, 1);
}
grid.setRows(1);
grid.setSpacing(true);
grid.setWidth("100%");
ParamEditor firstParamEditor = null;
ParamEditor lastParamEditor = null;
boolean currentFocusSet = initialFocusSet;
RuntimeException entityParamInformationException = null;
for (int i = 0; i < visibleConditionNodes.size(); i++) {
Node<AbstractCondition> node = visibleConditionNodes.get(i);
final AbstractCondition condition = node.getData();
BoxLayout labelAndOperationCellContent = null;
Component paramEditComponentCellContent = null;
Component groupCellContent = null;
if (condition.isGroup()) {
groupCellContent = createGroupConditionBox(condition, node, conditionsFocusType, currentFocusSet, level);
level++;
} else {
if (condition.getParam().getJavaClass() != null) {
Pair<ParamEditor, RuntimeException> pair = createParamEditorWithChecks(condition, filterDataContext);
ParamEditor paramEditor = pair.getFirst();
addParamEditor(condition, paramEditor);
if (pair.getSecond() != null) {
entityParamInformationException = pair.getSecond();
}
if (firstParamEditor == null)
firstParamEditor = paramEditor;
lastParamEditor = paramEditor;
currentFocusSet = true;
labelAndOperationCellContent = paramEditor.getLabelAndOperationLayout();
paramEditComponentCellContent = paramEditor.getParamEditComponentLayout();
} else {
BoxLayout paramLayout = uiComponents.create(HBoxLayout.class);
paramLayout.setSpacing(true);
paramLayout.setMargin(false);
labelAndOperationCellContent = paramLayout;
}
}
// groupBox for group conditions must occupy the whole line in conditions grid
Integer conditionWidth = condition.isGroup() ? (Integer) conditionsCount : condition.getWidth();
int nextColumnEnd = nextColumnStart + conditionWidth - 1;
if (nextColumnEnd >= conditionsCount) {
// complete current row in grid with gaps if next cell will be on next row
completeGridRowWithGaps(grid, row, nextColumnStart, false);
// place cell to next row in grid
nextColumnStart = 0;
nextColumnEnd = conditionWidth - 1;
row++;
grid.setRows(row + 1);
}
if (groupCellContent != null) {
grid.add(groupCellContent, nextColumnStart * 2, row, nextColumnEnd * 2 + 1, row);
}
if (labelAndOperationCellContent != null) {
labelAndOperationCellContent.addStyleName("param-label-layout");
grid.add(labelAndOperationCellContent, nextColumnStart * 2, row, nextColumnStart * 2, row);
if (nextColumnStart != 0)
labelAndOperationCellContent.setMargin(false, false, false, true);
}
if (paramEditComponentCellContent != null) {
paramEditComponentCellContent.addStyleName("param-field-layout");
if (condition.getParam().getType() == Param.Type.UNARY) {
paramEditComponentCellContent.addStyleName("unary-param-type");
}
grid.add(paramEditComponentCellContent, nextColumnStart * 2 + 1, row, nextColumnEnd * 2 + 1, row);
}
nextColumnStart = nextColumnEnd + 1;
// add next row if necessary
if (i < visibleConditionNodes.size() - 1) {
if (nextColumnStart >= conditionsCount) {
nextColumnStart = 0;
row++;
grid.setRows(row + 1);
}
}
}
filterDataContext.loadAll();
if (!initialFocusSet) {
switch(conditionsFocusType) {
case FIRST:
if (firstParamEditor != null) {
paramEditComponentToFocus = firstParamEditor;
}
break;
case LAST:
if (lastParamEditor != null) {
paramEditComponentToFocus = lastParamEditor;
}
break;
default:
// no action
break;
}
}
// complete last row in grid with gaps
completeGridRowWithGaps(grid, row, nextColumnStart, true);
if (parentContainer != null) {
parentContainer.add(grid);
}
if (level == 0)
controlsLayout.setStyleName(getControlsLayoutStyleName());
if (entityParamInformationException != null) {
getDialogs().createExceptionDialog().withThrowable(entityParamInformationException).show();
}
}
Aggregations