protected CubaFieldGroupLayout createComponent() { return new CubaFieldGroupLayout(); }
@Override public int getColumns() { return component.getColumns(); }
@Override public float getColumnExpandRatio(int col) { return component.getColumnExpandRatio(col); }
@Override public void add(Component childComponent, int column, int row) { checkArgument(column >= 0 && column < this.component.getColumns(), "Illegal column number %s, available amount of columns is %s", column, this.component.getColumns()); List<Component> colFields = columnComponentMapping.get(column); checkArgument(row >= 0 && row <= colFields.size(), "Illegal row number %s, available amount of rows is %s", row, this.component.getRows()); addComponentInternal(childComponent, column, row); }
protected void reattachColumnFields(int colIndex) { for (int i = 0; i < component.getRows(); i++) { component.removeComponent(colIndex, i); } List<Component> columnFields = columnComponentMapping.get(colIndex); int insertRowIndex = 0; for (Component field : columnFields) { com.vaadin.ui.Component composition = WebComponentsHelper.getComposition(field); this.component.addComponent(composition, colIndex, insertRowIndex++); } }
@Override public void setColumns(int columns) { if (component.getColumns() != columns) { component.setColumns(columns); List<List<FieldConfig>> oldColumnFields = this.columnFieldMapping; this.columnFieldMapping = new ArrayList<>(); for (int i = 0; i < columns; i++) { if (i < oldColumnFields.size()) { columnFieldMapping.add(oldColumnFields.get(i)); } else { columnFieldMapping.add(new ArrayList<>()); } } } }
@Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); if (initial && columnFieldCaptionWidth != null) { int[] newColumnFieldCaptionWidth = new int[getColumns()]; for (Map.Entry<Integer, Integer> entry : columnFieldCaptionWidth.entrySet()) { int index = entry.getKey(); int width = entry.getValue(); if (index >= 0 && index < getColumns() && width > 0) { newColumnFieldCaptionWidth[index] = width; } } getState().columnFieldCaptionWidth = newColumnFieldCaptionWidth; } }
@Override public int getFieldCaptionWidth() { return component.getFixedCaptionWidth(); }
@Override public int getFieldCaptionWidth(int column) { return component.getFieldCaptionWidth(column); }
@Override public String getCaption() { if (wrapperAttached) { return wrapper.getCaption(); } else { return component.getCaption(); } }
@Override public void setBorderVisible(boolean borderVisible) { wrapper.setBorderVisible(borderVisible); if (component.getParent() != null && !wrapperAttached) { LoggerFactory.getLogger(WebFieldGroup.class) .warn("Unable to set border visible for FieldGroup after adding to component tree"); return; } if (borderVisible && !wrapperAttached) { wrapper.setContent(component); wrapperAttached = true; } }
@Override public void addField(FieldConfig fc, int colIndex, int rowIndex) { checkArgument(!fields.containsKey(fc.getId()), "Field '%s' is already registered", fc.getId()); checkArgument(this == ((FieldConfigImpl) fc).getOwner(), "Field does not belong to this FieldGroup"); if (colIndex < 0 || colIndex >= component.getColumns()) { throw new IllegalArgumentException(String.format("Illegal column number %s, available amount of columns is %s", colIndex, component.getColumns())); } List<FieldConfig> colFields = columnFieldMapping.get(colIndex); if (rowIndex < 0 || rowIndex > colFields.size()) { throw new IllegalArgumentException(String.format("Illegal row number %s, available amount of rows is %s", rowIndex, component.getRows())); } addFieldInternal(fc, colIndex, rowIndex); }
protected void reattachColumnFields(int colIndex) { for (int i = 0; i < component.getRows(); i++) { component.removeComponent(colIndex, i); } List<FieldConfig> columnFCs = columnFieldMapping.get(colIndex); int insertRowIndex = 0; for (FieldConfig fc : columnFCs) { if (fc.isBound()) { com.vaadin.ui.Component composition = WebComponentsHelper.getComposition(fc.getComponentNN()); component.addComponent(composition, colIndex, insertRowIndex); insertRowIndex++; } } }
@Override public void setColumns(int columns) { if (component.getColumns() != columns) { try { component.setColumns(columns); } catch (GridLayout.OutOfBoundsException e) { // Replace the default exception with something more meaningful throw new IllegalStateException("Can't shrink columns with components within them"); } List<List<Component>> oldColumnComponents = columnComponentMapping; columnComponentMapping = new ArrayList<>(); for (int i = 0; i < columns; i++) { if (i < oldColumnComponents.size()) { columnComponentMapping.add(oldColumnComponents.get(i)); } else { columnComponentMapping.add(new ArrayList<>()); } } } }
@Override public int getChildrenCaptionWidth() { return component.getFixedCaptionWidth(); }
@Override public int getChildrenCaptionWidth(int column) { return component.getFieldCaptionWidth(column); }
public void setLayout(Layout newLayout) { if (newLayout == null) { newLayout = new CubaFieldGroupLayout(); } if (newLayout instanceof CubaFieldGroupLayout) { super.setContent(newLayout); } else { throw new IllegalArgumentException("FieldGroup supports only CubaFieldGroupLayout"); } } }
@Override public int getColumns() { return component.getColumns(); }