Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.cdlflex.ui.markup.html.repeater.data.table;
 
 import java.util.List;
 
Fluent interface for creating DataTable instances. The TableBuilder itself is a ITableSkeleton that can be used as an argument of DataTable constructors.

Parameters:
<T> The Model object type
<S> The type of the sorting parameter
 
 public class TableBuilder<T, S> implements ITableSkeleton<T, S> {
 
     private static final long serialVersionUID = 1L;
 
     private List<IColumn<T, S>> columns;
     private ISortableDataProvider<T, S> dataProvider;
     private Integer rowsPerPage;
 
     private List<Behaviorbehaviors;
 
     public TableBuilder() {
         this. = new ArrayList<>();
         this. = new ArrayList<>();
         this. = .;
     }

    
Adds behaviors that will be added to the table after construction.

Parameters:
behavior the behaviors to add
Returns:
this for chaining
 
     public TableBuilder<T, S> add(Behavior... behavior) {
         Collections.addAll(behavior);
         return this;
     }

    
Adds a behavior that will be added to the table after construction.

Parameters:
behavior the behavior to add
Returns:
this for chaining
 
     public TableBuilder<T, S> add(Behavior behavior) {
         .add(behavior);
         return this;
     }

    
Adds a column. Alias for #column(IColumn).

Parameters:
column the column to add
Returns:
this for chaining
 
     public TableBuilder<T, S> add(IColumn<T, S> column) {
         addColumn(column);
         return this;
     }

    
Adds a column.

Parameters:
column the column to add
Returns:
this for chaining
 
     public TableBuilder<T, S> column(IColumn<T, S> column) {
         addColumn(column);
         return this;
     }

    
Sets the rows per page displayed. Defaults to Integer.MAX_VALUE. Alias for #rows(Integer).

Parameters:
rows rows per page
Returns:
this for chaining
 
     public TableBuilder<T, S> set(Integer rows) {
         setRowsPerPage(rows);
        return this;
    }

    
Sets the data provider used. Alias for #data(ISortableDataProvider).

Parameters:
provider the data provider to use
Returns:
this for chaining
    public TableBuilder<T, S> set(ISortableDataProvider<T, S> provider) {
        setDataProvider(provider);
        return this;
    }

    
Sets the rows per page displayed. Defaults to Integer.MAX_VALUE.

Parameters:
rows rows per page
Returns:
this for chaining
    public TableBuilder<T, S> rows(Integer rows) {
        setRowsPerPage(rows);
        return this;
    }

    
Sets the data provider used.

Parameters:
provider the data provider to use
Returns:
this for chaining
    public TableBuilder<T, S> data(ISortableDataProvider<T, S> provider) {
        setDataProvider(provider);
        return this;
    }

    
Constructs a new SortableListDataProvider for the given list data and sets it as data provider.

Parameters:
data the data to use
Returns:
this for chaining
    @SuppressWarnings("unchecked")
    public TableBuilder<T, S> data(List<T> data) {
        return data(new SortableListDataProvider(data));
    }

    
Adds a column.

Parameters:
column the column to add
    public void addColumn(IColumn<T, S> column) {
        .add(column);
    }
    @Override
    public List<IColumn<T, S>> getColumns() {
        return ;
    }
    public void setColumns(List<IColumn<T, S>> columns) {
        this. = columns;
    }
    @Override
    public ISortableDataProvider<T, S> getDataProvider() {
        return ;
    }
    public void setDataProvider(ISortableDataProvider<T, S> dataProvider) {
        this. = dataProvider;
    }
    @Override
    public Integer getRowsPerPage() {
        return ;
    }
    public void setRowsPerPage(Integer rowsPerPage) {
        this. = rowsPerPage;
    }

    
Creates a new DataTable with the given id from the components fed to the TableBuilder.

Parameters:
id the component id
Returns:
a new DataTable instance
    public DataTable<T, S> create(String id) {
        return addBehaviors(createTable(idthis));
    }

    
Applies all collected behaviors by the table builder to the given component and returns it.

Parameters:
component the component to add the behaviors to
<C> the component type
Returns:
the component
    @SuppressWarnings("unchecked")
    protected <C extends Component> C addBehaviors(C component) {
        if (!.isEmpty()) {
            component.add(.toArray(new Behavior[.size()]));
        }
        return component;
    }

    
Factory method that can be overridden ins subclasses to create different instances.

Parameters:
id the component id
skeleton the table skeleton
Returns:
a new DataTable instance
    protected DataTable<T, S> createTable(String idITableSkeleton<T, S> skeleton) {
        return new DataTable<>(idskeleton);
    }
New to GrepCode? Check out our FAQ X