* determined that some alias may be available in addition. Add local alias
* (i.e. names without their scope) to the 'elementNames' row.
*/
int count = 0;
for (final GenericName alias : aliases) {
final GenericName scope = alias.scope().name();
final GenericName name = alias.tip();
final Object title;
if (scope != null) {
if (scopes!=null && !scopes.contains(scope.toString())) {
/*
* The user requested only a subset of alias (the 'scopes' argument),
* and the current alias is not a member of this subset. Continue the
* search to other alias.
*/
continue;
}
title = scope.toInternationalString().toString(locale);
} else {
title = count++;
}
/*
* The alias scope is used as the column's title. If the alias has no scope,
* then a sequencial number is used instead. Now check if the column already
* exists. If it exists, fetch its position. If it doesn't exist, inserts the
* new column at the end of existing columns.
*/
Integer position = titles.get(title);
if (position == null) {
position = titles.size();
titles.put(title, position);
}
/*
* Now stores the alias local name at the position we just determined above.
* Note that more than one value may exist for the same column. For example
* both "WGS 84" and "4326" may appear as EPSG alias (as EPSG name and EPSG
* identifier respectively), depending how the parameters given by the user
* were constructed.
*/
final int index = position.intValue();
if (index >= elementNames.length) {
elementNames = XArray.resize(elementNames, index+1);
}
final String oldName = elementNames[index];
final String newName = name.toInternationalString().toString(locale);
if (oldName==null || oldName.length()>newName.length()) {
/*
* Keep the shortest string, since it is often a code used
* for identification (e.g. EPSG code). It also help to fit
* the table in the window's width.
*/
elementNames[index] = newName;
}
}
}
/*
* Before to add the name and alias to the list, fetch the remarks (if any).
* They are stored in a separated list and will appear as the very last column.
*/
final InternationalString remarks = element.getRemarks();
if (remarks != null) {
if (descriptions == null) {
descriptions = new String[parameters.size()];
}
descriptions[names.size()] = remarks.toString(locale);
}
names.add(elementNames);
}
/*
* Trim the columns that duplicates the identifier column (#0). This is
* usually the case of the OGC column (usually #1), since we already use
* OGC name as the main identifier in most cases.
*/
final boolean[] hide = new boolean[titles.size()];
trim: for (int column=hide.length; --column>=1;) {
for (final String[] alias : names) {
if (alias.length > column) {
final String name = alias[column];
if (name!=null && !name.equals(alias[0])) {
// No need to looks at the next lines.
// Move to previous column.
continue trim;
}
}