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; }
/** * Construct a table with the given model. The table will use the following * strategies for all cells, unless overridden:<ul> * <li>{@link DefaultFormatter default formatting} using {@literal toString()}</li> * <li>{@link AutoSizeConstraints sizing strategy} trying to use the maximum space, resorting to splitting lines on * spaces</li> * <li>{@link DelimiterTextWrapper wrapping text} on space characters</li> * <li>{@link SimpleHorizontalAligner left aligning} text.</li> * </ul> */ public TableBuilder(TableModel model) { this.model = model; rows = model.getRowCount(); columns = model.getColumnCount(); formatters.put(CellMatchers.table(), new DefaultFormatter()); sizeConstraints.put(CellMatchers.table(), new AutoSizeConstraints()); wrappers.put(CellMatchers.table(), new DelimiterTextWrapper()); aligners.put(CellMatchers.table(), left); }
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")))
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) .on(CellMatchers.ofType(Integer.class)).addAligner(SimpleHorizontalAligner.center);
/** * 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, " = "); }
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")))
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) .on(CellMatchers.ofType(Integer.class)).addAligner(SimpleHorizontalAligner.center);
/** * 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, " = "); }
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; }
.on(CellMatchers.table()).addSizer(new AbsoluteWidthSizeConstraints(30)).and(); result.add(builder.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, " = "); }
@CliCommand(value = DISPLAY_COUNTER, help = "Display the value of a field value counter") public List<Object> display( @CliOption(key = { "", "name" }, help = "the name of the field value counter to display", mandatory = true, optionContext = "existing-field-value-counter disable-string-converter") String name, final @CliOption(key = "pattern", help = "the pattern used to format the values (see DecimalFormat)", mandatory = false, unspecifiedDefaultValue = NumberFormatConverter.DEFAULT) NumberFormat pattern) { FieldValueCounterResource counter = fvcOperations().retrieve(name); LinkedHashMap<String, Object> header = new LinkedHashMap<>(); header.put("key", "Value"); header.put("value", "Count"); TableModel model = new BeanListTableModel<>(counter.getValues().entrySet(), header); Table table = DataFlowTables.applyStyle(new TableBuilder(model)).on(CellMatchers.ofType(Double.class)) .addFormatter(new Formatter() { @Override public String[] format(Object value) { return new String[] { pattern.format(value) }; } }).addAligner(SimpleHorizontalAligner.right).build(); return Arrays.asList(String.format("Displaying values for field value counter '%s'", name), table); }
.on(CellMatchers.table()).addSizer(new AbsoluteWidthSizeConstraints(30)).and(); result.add(builder.build());
@CliCommand(value = DISPLAY_COUNTER, help = "Display the value of a field value counter") public List<Object> display( @CliOption(key = { "", "name" }, help = "the name of the field value counter to display", mandatory = true, optionContext = "existing-field-value-counter disable-string-converter") String name, final @CliOption(key = "pattern", help = "the pattern used to format the values (see DecimalFormat)", mandatory = false, unspecifiedDefaultValue = NumberFormatConverter.DEFAULT) NumberFormat pattern) { FieldValueCounterResource counter = fvcOperations().retrieve(name); LinkedHashMap<String, Object> header = new LinkedHashMap<>(); header.put("key", "Value"); header.put("value", "Count"); TableModel model = new BeanListTableModel<>(counter.getValues().entrySet(), header); Table table = DataFlowTables.applyStyle(new TableBuilder(model)).on(CellMatchers.ofType(Double.class)) .addFormatter(new Formatter() { @Override public String[] format(Object value) { return new String[] { pattern.format(value) }; } }).addAligner(SimpleHorizontalAligner.right).build(); return Arrays.asList(String.format("Displaying values for field value counter '%s'", name), table); }
.on(CellMatchers.table()).addSizer(new AbsoluteWidthSizeConstraints(30)).and(); result.add(builder.build());
/** * 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(); } }