pl.fhframework.model.forms.Table Maven / Gradle / Ivy
package pl.fhframework.model.forms;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import pl.fhframework.BindingResult;
import pl.fhframework.annotations.*;
import pl.fhframework.binding.*;
import pl.fhframework.core.FhBindingException;
import pl.fhframework.core.FhException;
import pl.fhframework.core.forms.IHasBoundableLabel;
import pl.fhframework.core.logging.FhLogger;
import pl.fhframework.core.util.CollectionsUtils;
import pl.fhframework.events.IEventSource;
import pl.fhframework.events.IEventSourceContainer;
import pl.fhframework.helper.AutowireHelper;
import pl.fhframework.model.dto.ElementChanges;
import pl.fhframework.model.dto.InMessageEventData;
import pl.fhframework.model.dto.ValueChange;
import pl.fhframework.model.forms.attribute.HorizontalAlign;
import pl.fhframework.model.forms.attribute.RowHeight;
import pl.fhframework.model.forms.attribute.TableGrid;
import pl.fhframework.model.forms.attribute.TableStripes;
import pl.fhframework.model.forms.csv.CsvService;
import pl.fhframework.model.forms.designer.BindingExpressionDesignerPreviewProvider;
import pl.fhframework.model.forms.designer.IDesignerEventListener;
import pl.fhframework.model.forms.table.LowLevelRowMetadata;
import pl.fhframework.model.forms.table.RowIteratorMetadata;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static pl.fhframework.annotations.DesignerXMLProperty.PropertyFunctionalArea.*;
/**
* Table is component which describes and operates on tabular data. Table consists of TableRow and
* Column components, handles user actions as well as binds model data to its elements.
* Attributes:
*
* collection
- table model
* selected
- selected row
* iterator
- bind variable used in Column components
* onRowClick
- server side action executed when table row is chosen
*
* Example
* {@code
* rowList::= class Car {id, name}
*
*
*
*
}
*/
@TemplateControl(tagName = "fh-table")
@Control(parents = {Tab.class, GroupingComponent.class, Row.class, Form.class, Repeater.class}, invalidParents = {Table.class}, canBeDesigned = true)
@DocumentedComponent(category = DocumentedComponent.Category.TABLE_AND_TREE, documentationExample = true,value = "Table that allows to arrange data like text, images, links, other tables, etc. into rows and columns of cells.", icon = "fa fa-table")
public class Table extends Repeater implements ITabular, IChangeableByClient, IEventSourceContainer, IRowNumberOffsetSupplier, Boundable, CompactLayout, IDesignerEventListener, IHasBoundableLabel {
protected static final String LABEL_ATTR = "label";
@Autowired
@JsonIgnore
private CsvService csvService;
@Getter
@Setter
@XMLProperty
@DocumentedComponentAttribute(defaultValue = "false", value = "Determines if multiselect is enabled in table. If multiselect is set to true, selectedElement has to be set to Collection.")
@DesignerXMLProperty(functionalArea = SPECIFIC, priority = 10)
private boolean multiselect;
@Getter
@Setter
@XMLProperty
@DocumentedComponentAttribute(defaultValue = "false", value = "Determines if horizontal scrolling is enabled in table.")
@DesignerXMLProperty(functionalArea = LOOK_AND_STYLE, priority = 68)
private boolean horizontalScrolling;
@Getter
@Setter
@XMLProperty
@DocumentedComponentAttribute(value = "Allows row selection using checkbox. Works only if multiselect is also enabled.")
@DesignerXMLProperty(functionalArea = SPECIFIC, priority = 5)
private boolean selectionCheckboxes;
@Getter
@Setter
@XMLProperty(defaultValue = "true")
@DocumentedComponentAttribute(defaultValue = "true", value = "Turns on/off table header checkbox to select/unselect all rows. Works only with 'selectionCheckboxes' option trun on.")
@DesignerXMLProperty(functionalArea = SPECIFIC, priority = 10)
private boolean selectAllChceckbox = true;
@Getter
@Setter
@XMLProperty
@DocumentedComponentAttribute(value = "Enables row selection feature.")
@DesignerXMLProperty(functionalArea = SPECIFIC, priority = 15)
private boolean selectable;
@Getter
@Setter
@XMLProperty
@DocumentedComponentAttribute(value = "Enables fixed headers when scrolling. Works only if table height is set.")
@DesignerXMLProperty(functionalArea = SPECIFIC, priority = 15)
private boolean fixedHeader;
@Getter
@Setter
@XMLProperty
@DocumentedComponentAttribute(defaultValue = "false", value = "Enables export table data to CSV file feature.")
@DesignerXMLProperty(functionalArea = SPECIFIC, priority = 15)
private boolean csvExport;
@JsonIgnore
@Getter
@Setter
@TwoWayBinding
@XMLProperty(SELECTED)
@DocumentedComponentAttribute(boundable = true, value = "Selected table row")
@DesignerXMLProperty(functionalArea = CONTENT, priority = 11, bindingOnly = true)
private ModelBinding selectedElementBinding;
@Getter
// @JsonView(IWithSubelements.class)
protected List