use of ch.cyberduck.binding.foundation.NSAttributedString in project cyberduck by iterate-ch.
the class BrowserTableDataSource method objectValueForItem.
protected NSObject objectValueForItem(final Path item, final String identifier) {
if (null == item) {
return null;
}
if (log.isTraceEnabled()) {
log.trace("objectValueForItem:" + item.getAbsolute());
}
if (identifier.equals(BrowserColumn.icon.name())) {
return this.iconForPath(item);
}
final Item key = new Item(item, identifier);
// Query second level cache with view items
NSAttributedString value = attributed.get(key);
if (null != value) {
return value;
}
if (log.isTraceEnabled()) {
log.trace(String.format("Lookup failed for %s in cache", key));
}
if (identifier.equals(BrowserColumn.filename.name())) {
value = NSAttributedString.attributedStringWithAttributes(item.getName(), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.size.name())) {
value = NSAttributedString.attributedStringWithAttributes(sizeFormatter.format(item.attributes().getSize()), TableCellAttributes.browserFontRightAlignment());
} else if (identifier.equals(BrowserColumn.modified.name())) {
value = NSAttributedString.attributedStringWithAttributes(dateFormatter.getShortFormat(item.attributes().getModificationDate(), preferences.getBoolean("browser.date.natural")), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.owner.name())) {
value = NSAttributedString.attributedStringWithAttributes(StringUtils.isBlank(item.attributes().getOwner()) ? LocaleFactory.localizedString("Unknown") : item.attributes().getOwner(), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.group.name())) {
value = NSAttributedString.attributedStringWithAttributes(StringUtils.isBlank(item.attributes().getGroup()) ? LocaleFactory.localizedString("Unknown") : item.attributes().getGroup(), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.permission.name())) {
final Acl acl = item.attributes().getAcl();
if (!Acl.EMPTY.equals(acl)) {
final StringBuilder s = new StringBuilder();
for (Map.Entry<Acl.User, Set<Acl.Role>> entry : acl.entrySet()) {
s.append(String.format("%s%s:%s", s.length() == 0 ? StringUtils.EMPTY : ", ", entry.getKey().getDisplayName(), entry.getValue()));
}
value = NSAttributedString.attributedStringWithAttributes(s.toString(), TableCellAttributes.browserFontLeftAlignment());
} else {
final Permission permission = item.attributes().getPermission();
value = NSAttributedString.attributedStringWithAttributes(permission.toString(), TableCellAttributes.browserFontLeftAlignment());
}
} else if (identifier.equals(BrowserColumn.kind.name())) {
value = NSAttributedString.attributedStringWithAttributes(descriptor.getKind(item), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.extension.name())) {
value = NSAttributedString.attributedStringWithAttributes(item.isFile() ? StringUtils.isNotBlank(item.getExtension()) ? item.getExtension() : LocaleFactory.localizedString("None") : LocaleFactory.localizedString("None"), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.region.name())) {
value = NSAttributedString.attributedStringWithAttributes(StringUtils.isNotBlank(item.attributes().getRegion()) ? item.attributes().getRegion() : LocaleFactory.localizedString("Unknown"), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.version.name())) {
value = NSAttributedString.attributedStringWithAttributes(StringUtils.isNotBlank(item.attributes().getVersionId()) ? item.attributes().getVersionId() : LocaleFactory.localizedString("None"), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.checksum.name())) {
value = NSAttributedString.attributedStringWithAttributes(!Checksum.NONE.equals(item.attributes().getChecksum()) ? item.attributes().getChecksum().hash : StringUtils.isNotBlank(item.attributes().getETag()) ? item.attributes().getETag() : LocaleFactory.localizedString("None"), TableCellAttributes.browserFontLeftAlignment());
} else if (identifier.equals(BrowserColumn.storageclass.name())) {
value = NSAttributedString.attributedStringWithAttributes(StringUtils.isNotBlank(item.attributes().getStorageClass()) ? LocaleFactory.localizedString(item.attributes().getStorageClass(), "S3") : LocaleFactory.localizedString("None"), TableCellAttributes.browserFontLeftAlignment());
} else {
throw new IllegalArgumentException(String.format("Unknown identifier %s", identifier));
}
attributed.put(key, value);
return value;
}
Aggregations