001package com.identityworksllc.iiq.common.table; 002 003import java.util.ArrayList; 004import java.util.Arrays; 005import java.util.List; 006 007/** 008 * A class implementing a variety of static cell options. These can be passed to 009 * a Cell constructed using {@link Cell#of(Object, CellOption...)} or to the builder 010 * in {@link Table#cell(Object, CellOption...)}. 011 */ 012public class CellOptions { 013 /** 014 * Modifies the given Cell to add the classes listed to the existing list 015 */ 016 public static CellOption addCssClasses(String... classes) { 017 if (classes != null) { 018 List<String> classList = new ArrayList<>(Arrays.asList(classes)); 019 return (cell) -> cell.getCssClasses().addAll(classList); 020 } else { 021 return (cell) -> { 022 }; 023 } 024 } 025 026 /** 027 * Modifies the given Cell to have a column span of the given value 028 * 029 * @param span The column span 030 */ 031 public static CellOption colspan(int span) { 032 return (cell) -> cell.setColspan(span); 033 } 034 035 /** 036 * Modifies the given cell to set it as a header (th vs td) 037 */ 038 public static CellOption header() { 039 return (cell) -> cell.setHeader(true); 040 } 041 042 /** 043 * Modifies the given cell to set it as an HTML value 044 */ 045 public static CellOption html() { 046 return (cell) -> cell.setHtml(true); 047 } 048 049 /** 050 * Modifies the given cell to set its rowspan 051 * 052 * @param span The row span value 053 */ 054 public static CellOption rowspan(int span) { 055 return (cell) -> cell.setRowspan(span); 056 } 057 058 /** 059 * Modifies the given Cell to replace the class list with the ones listed 060 */ 061 public static CellOption setCssClasses(String... classes) { 062 if (classes != null) { 063 List<String> classList = new ArrayList<>(Arrays.asList(classes)); 064 return (cell) -> cell.setCssClasses(classList); 065 } else { 066 return (cell) -> { 067 }; 068 } 069 } 070 071 /** 072 * Modifies the given cell to set its CSS style attribute 073 * 074 * @param style The CSS style string 075 */ 076 public static CellOption style(String style) { 077 return (cell) -> cell.setStyle(style); 078 } 079 080 /** 081 * Private utility constructor 082 */ 083 private CellOptions() { 084 085 } 086}