/** * Customize the given TableBuilder with the following common features (these choices * can always be overridden by applying later customizations) : * <ul> * <li>double border around the whole table and first row</li> * <li>vertical space (air) borders, single line separators between rows</li> * <li>first row is assumed to be a header and is centered horizontally and * vertically</li> * <li>cells containing Map values are rendered as {@literal key = value} lines, * trying to align on equal signs</li> * </ul> * * @param builder the table builder to use * @return the configured table builder */ public static TableBuilder applyStyle(TableBuilder builder) { builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .addHeaderBorder(BorderStyle.fancy_double).on(CellMatchers.row(0)) .addAligner(SimpleVerticalAligner.middle).addAligner(SimpleHorizontalAligner.center); return Tables.configureKeyValueRendering(builder, " = "); }
/** * Render a table with information about a list of metrics * * @param list a list of metrics * @return the table to use for displaying the list of metrics */ protected Table displayMetrics(PagedResources<MetricResource> list) { LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", String.format("%s name", kind)); TableModel model = new BeanListTableModel<>(list, headers); return DataFlowTables.applyStyle(new TableBuilder(model)).build(); }
/** * Set a border on the outline of the whole table, as well as around the first row. */ public TableBuilder addHeaderBorder(BorderStyle style) { this.addBorder(0, 0, 1, model.getColumnCount(), OUTLINE, style); return addOutlineBorder(style); }
/** * Customize the given TableBuilder with almost same way than * {@link #applyStyle(TableBuilder)} but do not use any header styling. * * @param builder the table builder to use * @return the configured table builder */ public static TableBuilder applyStyleNoHeader(TableBuilder builder) { builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft() .toBottomRight(); return Tables.configureKeyValueRendering(builder, " = "); } }
TableBuilder builder = new TableBuilder(modelBuilder.build()); builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER).fromTopLeft().toBottomRight() .on(CellMatchers.table()).addAligner(SimpleHorizontalAligner.center).on(CellMatchers.table()) .addAligner(SimpleVerticalAligner.middle); builder.on(CellMatchers.ofType(FeatureInfo.class)).addFormatter(new DataFlowTables.BeanWrapperFormatter(": ")) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") : Arrays.asList("roles", "class", "username"); builder.on(CellMatchers.ofType(SecurityInfo.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, excludes)) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); builder.on(CellMatchers.ofType(List.class)) .addFormatter(value -> ((List<String>) value).toArray(new String[0])); builder.on(CellMatchers.ofType(RuntimeEnvironmentDetails.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, Arrays.asList("class", "platformSpecificInfo"))) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); rowsWithThinSeparators.forEach(row -> builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP) .fromRowColumn(row, 0).toRowColumn(row + 1, builder.getModel().getColumnCount())); result.add(builder.build());
final TableBuilder builder = new TableBuilder(model); DataFlowTables.applyStyle(builder); builder.on(CellMatchers.column(0)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleHorizontalAligner.center) for (int i = 2; i < model.getRowCount(); i++) { if (splits.contains(i)) { builder.paintBorder(BorderStyle.fancy_light, BorderSpecification.TOP).fromRowColumn(i, 0).toRowColumn(i + 1, model.getColumnCount()); builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP).fromRowColumn(i, 0).toRowColumn(i + 1, model.getColumnCount()); return builder.build();
.addValue(option.getType() == null ? "<unknown>" : option.getType()); TableBuilder builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build())) .on(CellMatchers.table()).addSizer(new AbsoluteWidthSizeConstraints(30)).and(); result.add(builder.build());
private Table displayAggrCounter(AggregateCounterResource aggResource, final NumberFormat pattern) { LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("key", "TIME"); headers.put("value", "COUNT"); TableModel model = new BeanListTableModel<>(aggResource.getValues().entrySet(), headers); Table table = DataFlowTables.applyStyle(new TableBuilder(model)).on(CellMatchers.ofType(Long.class)) .addFormatter(value -> new String[] { pattern.format(value) }).addAligner(SimpleHorizontalAligner.right).build(); return table; }
public CellMatcherStub on(CellMatcher other) { return TableBuilder.this.on(other); }
public Table build() { return TableBuilder.this.build(); } }
/** * Set a border on the outline of the whole table, around the first row and draw vertical lines * around each column. */ public TableBuilder addHeaderAndVerticalsBorders(BorderStyle style) { this.addBorder(0, 0, 1, model.getColumnCount(), OUTLINE, style); this.addBorder(0, 0, model.getRowCount(), model.getColumnCount(), OUTLINE | INNER_VERTICAL, style); return this; }
TableBuilder builder = new TableBuilder(modelBuilder.build()); builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER).fromTopLeft().toBottomRight() .on(CellMatchers.table()).addAligner(SimpleHorizontalAligner.center).on(CellMatchers.table()) .addAligner(SimpleVerticalAligner.middle); builder.on(CellMatchers.ofType(FeatureInfo.class)).addFormatter(new DataFlowTables.BeanWrapperFormatter(": ")) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") : Arrays.asList("roles", "class", "username"); builder.on(CellMatchers.ofType(SecurityInfo.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, excludes)) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); builder.on(CellMatchers.ofType(List.class)) .addFormatter(value -> ((List<String>) value).toArray(new String[0])); builder.on(CellMatchers.ofType(RuntimeEnvironmentDetails.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, Arrays.asList("class", "platformSpecificInfo"))) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); rowsWithThinSeparators.forEach(row -> builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP) .fromRowColumn(row, 0).toRowColumn(row + 1, builder.getModel().getColumnCount())); result.add(builder.build());
final TableBuilder builder = new TableBuilder(model); DataFlowTables.applyStyle(builder); builder.on(CellMatchers.column(0)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleHorizontalAligner.center) for (int i = 2; i < model.getRowCount(); i++) { if (splits.contains(i)) { builder.paintBorder(BorderStyle.fancy_light, BorderSpecification.TOP).fromRowColumn(i, 0).toRowColumn(i + 1, model.getColumnCount()); builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP).fromRowColumn(i, 0).toRowColumn(i + 1, model.getColumnCount()); return builder.build();
.addValue(option.getType() == null ? "<unknown>" : option.getType()); TableBuilder builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build())) .on(CellMatchers.table()).addSizer(new AbsoluteWidthSizeConstraints(30)).and(); result.add(builder.build());
private Table displayAggrCounter(AggregateCounterResource aggResource, final NumberFormat pattern) { LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("key", "TIME"); headers.put("value", "COUNT"); TableModel model = new BeanListTableModel<>(aggResource.getValues().entrySet(), headers); Table table = DataFlowTables.applyStyle(new TableBuilder(model)).on(CellMatchers.ofType(Long.class)) .addFormatter(value -> new String[] { pattern.format(value) }).addAligner(SimpleHorizontalAligner.right).build(); return table; }
/** * Install all the necessary formatters, aligners, etc for key-value rendering of Maps. */ public static TableBuilder configureKeyValueRendering(TableBuilder builder, String delimiter) { return builder.on(CellMatchers.ofType(Map.class)) .addFormatter(new MapFormatter(delimiter)) .addAligner(new KeyValueHorizontalAligner(delimiter.trim())) .addSizer(new KeyValueSizeConstraints(delimiter)) .addWrapper(new KeyValueTextWrapper(delimiter)).and(); } }
/** * Set a border around each and every cell of the table. */ public TableBuilder addFullBorder(BorderStyle style) { this.addBorder(0, 0, model.getRowCount(), model.getColumnCount(), FULL, style); return this; }
/** * Render a table with information about a list of metrics * * @param list a list of metrics * @return the table to use for displaying the list of metrics */ protected Table displayMetrics(PagedResources<MetricResource> list) { LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", String.format("%s name", kind)); TableModel model = new BeanListTableModel<>(list, headers); return DataFlowTables.applyStyle(new TableBuilder(model)).build(); }
/** * Customize the given TableBuilder with the following common features (these choices * can always be overridden by applying later customizations) : * <ul> * <li>double border around the whole table and first row</li> * <li>vertical space (air) borders, single line separators between rows</li> * <li>first row is assumed to be a header and is centered horizontally and * vertically</li> * <li>cells containing Map values are rendered as {@literal key = value} lines, * trying to align on equal signs</li> * </ul> * * @param builder the table builder to use * @return the configured table builder */ public static TableBuilder applyStyle(TableBuilder builder) { builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .addHeaderBorder(BorderStyle.fancy_double).on(CellMatchers.row(0)) .addAligner(SimpleVerticalAligner.middle).addAligner(SimpleHorizontalAligner.center); return Tables.configureKeyValueRendering(builder, " = "); }