--list-formatter-properties: optional column declared_in v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 15 Aug 2015 14:35:27 +0200
branchv_0
changeset 2160eb9aec16bf4
parent 215 42880d38ad3e
child 217 84bab99dda50
--list-formatter-properties: optional column declared_in

Usage:
sql-dk --list-formatter-properties tabular --list-formatter-properties xml --list-formatter-properties xhtml --list-formatter-properties tex --formatter xhtml --formatter-property InfoLister:print:declared_in true > formatter-properties.xhtml
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sat Aug 15 14:00:47 2015 +0200
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sat Aug 15 14:35:27 2015 +0200
     1.3 @@ -203,13 +203,20 @@
     1.4  		FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName);
     1.5  		try {
     1.6  
     1.7 -			ColumnsHeader header = constructHeader(
     1.8 -					new HeaderField("name", SQLType.VARCHAR),
     1.9 -					new HeaderField("type", SQLType.VARCHAR),
    1.10 -					new HeaderField("default", SQLType.VARCHAR),
    1.11 -					new HeaderField("description", SQLType.VARCHAR),
    1.12 -					new HeaderField("declared_in", SQLType.VARCHAR)
    1.13 -			);
    1.14 +			// currently only for debugging purposes
    1.15 +			// TODO: introduce --info-lister-property or generic filtering capability in printTable() ?
    1.16 +			boolean printDeclaredIn = options.getFormatterProperties().getBoolean("InfoLister:print:declared_in", false);
    1.17 +
    1.18 +			List<HeaderField> headerFields = new ArrayList<>();
    1.19 +			headerFields.add(new HeaderField("name", SQLType.VARCHAR));
    1.20 +			headerFields.add(new HeaderField("type", SQLType.VARCHAR));
    1.21 +			headerFields.add(new HeaderField("default", SQLType.VARCHAR));
    1.22 +			headerFields.add(new HeaderField("description", SQLType.VARCHAR));
    1.23 +			if (printDeclaredIn) {
    1.24 +				headerFields.add(new HeaderField("declared_in", SQLType.VARCHAR));
    1.25 +			}
    1.26 +
    1.27 +			ColumnsHeader header = constructHeader(headerFields.toArray(new HeaderField[0]));
    1.28  
    1.29  			Map<String, Object[]> data = new HashMap<>();
    1.30  			Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName());
    1.31 @@ -217,7 +224,7 @@
    1.32  			Collections.reverse(hierarchy);
    1.33  			hierarchy.stream().forEach((c) -> {
    1.34  				for (PropertyDeclaration p : getPropertyDeclarations(c)) {
    1.35 -					data.put(p.name(), propertyDeclarationToRow(p, c));
    1.36 +					data.put(p.name(), propertyDeclarationToRow(p, c, printDeclaredIn));
    1.37  				}
    1.38  			});
    1.39  
    1.40 @@ -230,14 +237,18 @@
    1.41  		}
    1.42  	}
    1.43  
    1.44 -	private static Object[] propertyDeclarationToRow(PropertyDeclaration p, Class formatterClass) {
    1.45 -		return new Object[]{
    1.46 -			p.name(),
    1.47 -			CommonProperties.getSimpleTypeName(p.type()),
    1.48 -			p.defaultValue(),
    1.49 -			p.description(),
    1.50 -			formatterClass.getName()
    1.51 -		};
    1.52 +	private static Object[] propertyDeclarationToRow(PropertyDeclaration p, Class formatterClass, boolean printDeclaredIn) {
    1.53 +		List list = new ArrayList();
    1.54 +
    1.55 +		list.add(p.name());
    1.56 +		list.add(CommonProperties.getSimpleTypeName(p.type()));
    1.57 +		list.add(p.defaultValue());
    1.58 +		list.add(p.description());
    1.59 +		if (printDeclaredIn) {
    1.60 +			list.add(formatterClass.getName());
    1.61 +		}
    1.62 +
    1.63 +		return list.toArray();
    1.64  	}
    1.65  
    1.66  	private void listTypes() throws FormatterException, ConfigurationException {