org.springframework.shell.table.SimpleVerticalAligner Java Examples

The following examples show how to use org.springframework.shell.table.SimpleVerticalAligner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DemoCommand.java    From ssh-shell-spring-boot with Apache License 2.0 6 votes vote down vote up
/**
 * Complex table example command
 *
 * @return principal
 */
@ShellMethod("Complex table command")
public String tableComplex() {
    return helper.renderTable(SimpleTable.builder()
            .column("col1")
            .column("col2")
            .column("col3")
            .column("col4")
            .line(Arrays.asList("line1 col1", "line1 col2", "line1 col3", "line1 col4"))
            .line(Arrays.asList("line2 col1", "line2 col2", "line2 col3", "line2 col4"))
            .line(Arrays.asList("line3 col1", "line3 col2", "line3 col3", "line3 col4"))
            .line(Arrays.asList("line4 col1", "line4 col2", "line4 col3", "line4 col4"))
            .line(Arrays.asList("line5 col1", "line5 col2", "line5 col3", "line5 col4"))
            .line(Arrays.asList("line6 col1", "line6 col2", "line6 col3", "line6 col4"))
            .headerAligner(SimpleHorizontalAligner.right)
            .lineAligner(SimpleHorizontalAligner.left)
            .lineAligner(SimpleVerticalAligner.bottom)
            .useFullBorder(false)
            .borderStyle(BorderStyle.fancy_heavy_double_dash)
            .tableBuilderListener(tableBuilder -> {
                tableBuilder.addInnerBorder(BorderStyle.fancy_light_double_dash);
                tableBuilder.addOutlineBorder(BorderStyle.fancy_double);
            }).build());
}
 
Example #2
Source File: DataFlowTables.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
/**
 * 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>
 */
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, " = ");
}
 
Example #3
Source File: RuntimeCommands.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@CliCommand(value = LIST_APPS, help = "List runtime apps")
public Table list(
		@CliOption(key = "summary", help = "whether to hide app instance details", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean summary,
		@CliOption(key = { "appId",
				"appIds" }, help = "app id(s) to display, also supports '<group>.*' pattern") String[] appIds) {

	Set<String> filter = null;
	if (appIds != null) {
		filter = new HashSet<>(Arrays.asList(appIds));
	}

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();
	if (!summary) {
		modelBuilder.addRow().addValue("App Id / Instance Id").addValue("Unit Status")
				.addValue("No. of Instances / Attributes");
	}
	else {
		modelBuilder.addRow().addValue("App Id").addValue("Unit Status").addValue("No. of Instances");
	}

	// In detailed mode, keep track of app vs instance lines, to use
	// a different border style later.
	List<Integer> splits = new ArrayList<>();
	int line = 1;
	// Optimise for the single app case, which is likely less resource intensive on
	// the server
	// than client side filtering
	Iterable<AppStatusResource> statuses;
	if (filter != null && filter.size() == 1 && !filter.iterator().next().endsWith(".*")) {
		statuses = Collections.singleton(runtimeOperations().status(filter.iterator().next()));
	}
	else {
		statuses = runtimeOperations().status();
	}
	for (AppStatusResource appStatusResource : statuses) {
		if (filter != null && !shouldRetain(filter, appStatusResource)) {
			continue;
		}
		modelBuilder.addRow().addValue(appStatusResource.getDeploymentId()).addValue(appStatusResource.getState())
				.addValue(appStatusResource.getInstances().getContent().size());
		splits.add(line);
		line++;
		if (!summary) {
			for (AppInstanceStatusResource appInstanceStatusResource : appStatusResource.getInstances()) {
				modelBuilder.addRow().addValue(appInstanceStatusResource.getInstanceId())
						.addValue(appInstanceStatusResource.getState())
						.addValue(appInstanceStatusResource.getAttributes());
				line++;
			}
		}
	}

	TableModel model = modelBuilder.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)
			// This will match the "number of instances" cells only
			.on(CellMatchers.ofType(Integer.class)).addAligner(SimpleHorizontalAligner.center);

	Tables.configureKeyValueRendering(builder, " = ");
	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());
		}
		else {
			builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP).fromRowColumn(i, 0).toRowColumn(i + 1,
					model.getColumnCount());
		}
	}

	return builder.build();
}
 
Example #4
Source File: TableUtils.java    From spring-cloud-skipper with Apache License 2.0 3 votes vote down vote up
/**
 * 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, " = ");
}
 
Example #5
Source File: DataFlowTables.java    From spring-cloud-dataflow with Apache License 2.0 3 votes vote down vote up
/**
 * 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, " = ");
}