@Override public String[] wrap(String[] original, int columnWidth) { List<String> result = new ArrayList<String>(); for (String line : original) { line = line.trim(); while (line.length() > columnWidth) { int cut = line.lastIndexOf(delimiter, columnWidth); if (cut == -1) { cut = columnWidth; } else if (cut + delimiter.length() <= columnWidth) { cut = cut + delimiter.length(); } result.add(rightPad(line.substring(0, cut), columnWidth)); line = line.substring(cut).trim(); } if (line.length() > 0) { result.add(rightPad(line, columnWidth)); } } return result.toArray(new String[result.size()]); }
/** * 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(); } }
.addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") : Arrays.asList("roles", "class", "username"); .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])); 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()));
.addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") : Arrays.asList("roles", "class", "username"); .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])); 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()));