use of org.jowidgets.cap.ui.api.form.IBeanFormGroup in project jo-client-platform by jo-source.
the class BeanFormContentLayouter method layoutForm.
private void layoutForm(final IContainer formContainer, final IBeanFormControlFactory controlFactory) {
formContainer.setLayout(Toolkit.getLayoutFactoryProvider().cachedFillLayout());
final IComposite content = formContainer.add(BPF.composite());
content.setLayout(new MigLayoutDescriptor(getColumnsConstraints(layout), ""));
final List<boolean[]> globalGrid = new ArrayList<boolean[]>();
int row = 0;
final boolean showSeparators = layout.getGroups().size() > 1;
for (final IBeanFormGroup group : layout.getGroups()) {
final String label = group.getLabel();
final BeanFormGroupRendering rendering = group.getRendering();
row = getNextFreeRow(globalGrid);
final List<boolean[]> grid;
final IContainer container;
if (BeanFormGroupRendering.NONE.equals(rendering)) {
grid = globalGrid;
container = content;
} else if (BeanFormGroupRendering.SEPARATOR.equals(rendering)) {
final String baseConstraints = "growx, cell 0 " + row + " " + (3 * layout.getColumnCount()) + " 1";
setUsed(globalGrid, row, 0, 1, layout.getColumnCount());
if (label != null && !"".equals(label)) {
final String gapTop = (row > 0) ? "gaptop 27" : "";
final String gapBottom = "gapbottom 7";
final String cell = constraints(baseConstraints, gapTop, gapBottom);
content.add(Toolkit.getBluePrintFactory().textSeparator(label), cell);
} else if (row > 0 && showSeparators) {
final String cell = constraints(baseConstraints, "gaptop 17, gapbottom 17");
content.add(Toolkit.getBluePrintFactory().separator(), cell);
}
grid = globalGrid;
container = content;
} else if (BeanFormGroupRendering.BORDER.equals(rendering)) {
final String cell = "growx, cell 0 " + row + " " + (3 * layout.getColumnCount()) + " 1";
setUsed(globalGrid, row, 0, 1, layout.getColumnCount());
if (label != null && !"".equals(label)) {
container = content.add(Toolkit.getBluePrintFactory().composite(label), cell);
} else {
container = content.add(Toolkit.getBluePrintFactory().compositeWithBorder(), cell);
}
container.setLayout(new MigLayoutDescriptor(getColumnsConstraints(layout), ""));
grid = new ArrayList<boolean[]>();
} else {
throw new IllegalStateException("Unkown BeanFormGroupRendering '" + rendering + "'.");
}
// reset column index
int logicalColumn = 0;
row = getNextFreeRow(grid);
int currentRowHeight = 1;
for (final IBeanFormProperty property : group.getProperties()) {
final String propertyName = property.getPropertyName();
final ICustomWidgetCreator<? extends IControl> controlCreator = controlFactory.createControl(propertyName);
// only add to the layout if there is a control for this property
if (controlCreator == null) {
continue;
}
final int propertyColumnCount = property.getColumnCount();
final int propertyColumnSpan = property.getColumnSpan();
final int propertyRowCount = property.getRowCount();
final int propertyRowSpan = property.getRowSpan();
final Position nextGridPosition = getNextGridPosition(grid, row, logicalColumn, propertyColumnCount);
logicalColumn = nextGridPosition.getX();
row = nextGridPosition.getY();
setUsed(grid, row, logicalColumn, propertyRowCount, propertyColumnCount);
currentRowHeight = Math.max(currentRowHeight, propertyRowCount);
final String sizeGroupLabel = "sg lbl" + logicalColumn;
final String sizeGroupControl = "sgy r" + row + "ctrlspn" + propertyRowSpan;
final ICustomWidgetCreator<? extends IControl> validationLabelCreator = controlFactory.createPropertyValidationLabel(propertyName);
final int firstPropertyColumn = (3 * logicalColumn);
// add label
// CHECKSTYLE:OFF
// FinalLocalVariable check seems to be broken in some cases
String cell;
// CHECKSTYLE:ON
if (property.showLabel()) {
final AlignmentVertical labelAlignmentVertical = property.getLabelAlignmentVertical();
if (AlignmentVertical.TOP.equals(labelAlignmentVertical)) {
cell = "aligny top, cell " + firstPropertyColumn + " " + row;
} else if (AlignmentVertical.CENTER.equals(labelAlignmentVertical)) {
cell = "aligny center, cell " + firstPropertyColumn + " " + row + " 1 " + propertyRowSpan;
} else if (AlignmentVertical.BOTTOM.equals(labelAlignmentVertical)) {
cell = "aligny bottom, cell " + firstPropertyColumn + " " + (row + propertyRowSpan - 1);
} else {
throw new IllegalStateException("Unknown vertical alignment '" + labelAlignmentVertical + "'.");
}
final ICustomWidgetCreator<? extends IControl> labelCreator;
labelCreator = controlFactory.createLabel(propertyName, property.getLabelAlignmentHorizontal());
container.add(labelCreator, constraints(cell, sizeGroupLabel));
cell = "cell " + (firstPropertyColumn + 1) + " " + row + " " + (3 * propertyColumnSpan - 2) + " " + propertyRowSpan;
} else {
cell = "cell " + firstPropertyColumn + " " + row + " " + (3 * propertyColumnSpan - 1) + " " + propertyRowSpan;
}
container.add(controlCreator, constraints(cell, sizeGroupControl, getControlWidthConstraints(layout, logicalColumn), getHeightConstraints(property.getHeight()), "growx", "growy"));
// add validation label
if (validationLabelCreator != null) {
final int validationLabelMinWidth = property.getValidationLabelMinWidth();
container.add(validationLabelCreator, "w " + validationLabelMinWidth);
validationLabelGap = Math.max(validationLabelGap, validationLabelMinWidth);
}
logicalColumn = logicalColumn + propertyColumnCount;
}
}
}
Aggregations