// city
city = uifactory.addTextElement("city", "mf.city", -1, (meta != null ? meta.getCity() : null), formLayout);
// publish date
FormLayoutContainer publicationDate = FormLayoutContainer.createHorizontalFormLayout("publicationDateLayout", getTranslator());
publicationDate.setLabel("mf.publishDate", null);
formLayout.add(publicationDate);
String[] pubDate = (meta != null ? meta.getPublicationDate() : new String[] { "", "" });
publicationMonth = uifactory.addTextElement("publicationMonth", "mf.month", 2, pubDate[1], publicationDate);
publicationMonth.setMaxLength(2);
publicationMonth.setDisplaySize(2);
publicationYear = uifactory.addTextElement("publicationYear", "mf.year", 4, pubDate[0], publicationDate);
publicationYear.setMaxLength(4);
publicationYear.setDisplaySize(4);
// number of pages
pages = uifactory.addTextElement("pages", "mf.pages", -1, (meta != null ? meta.getPages() : null), formLayout);
// language
language = uifactory.addTextElement("language", "mf.language", -1, (meta != null ? meta.getLanguage() : null), formLayout);
// url/link
url = uifactory.addTextElement("url", "mf.url", -1, (meta != null ? meta.getUrl() : null), formLayout);
/* static fields */
String sizeText, typeText;
if (item instanceof VFSLeaf) {
sizeText = StringHelper.formatMemory(((VFSLeaf) item).getSize());
typeText = FolderHelper.extractFileType(item.getName(), getLocale());
} else {
sizeText = "-";
typeText = translate("mf.type.directory");
}
// Targets to hide
metaFields = new HashSet<FormItem>();
metaFields.add(creator);
metaFields.add(publisher);
metaFields.add(source);
metaFields.add(city);
metaFields.add(publicationDate);
metaFields.add(pages);
metaFields.add(language);
metaFields.add(url);
if (!hasMetadata()) {
moreMetaDataLink = uifactory.addFormLink("mf.more.meta.link", formLayout, Link.LINK_CUSTOM_CSS);
moreMetaDataLink.setCustomEnabledLinkCSS("b_link_moreinfo");
setMetaFieldsVisible(false);
}
if (!isSubform) {
if(!meta.isDirectory()) {
Long lockedById = meta.getLockedBy();
//locked
String lockedTitle = getTranslator().translate("mf.locked");
String unlockedTitle = getTranslator().translate("mf.unlocked");
locked = uifactory.addRadiosHorizontal("locked","mf.locked",formLayout, new String[]{"lock","unlock"}, new String[]{lockedTitle, unlockedTitle});
if(meta.isLocked()) {
locked.select("lock", true);
} else {
locked.select("unlock", true);
}
locked.setEnabled(!MetaInfoHelper.isLocked(item, ureq));
//locked by
String lockedDetails = "";
if(lockedById != null) {
Identity lockedIdentity = meta.getLockedByIdentity();
String user = lockedIdentity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()) + " " +
lockedIdentity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale());
String date = "";
if (meta.getLockedDate() != null) {
date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, ureq.getLocale()).format(meta.getLockedDate());
}
lockedDetails = getTranslator().translate("mf.locked.description", new String[]{user, date});
} else {
lockedDetails = getTranslator().translate("mf.unlocked.description");
}
uifactory.addStaticTextElement("mf.lockedBy", lockedDetails, formLayout);
}
// username
uifactory.addStaticTextElement("mf.author", meta.getHTMLFormattedAuthor(), formLayout);
// filesize
uifactory.addStaticTextElement("mf.size", sizeText, formLayout);
// last modified date
uifactory.addStaticTextElement("mf.lastModified", StringHelper.formatLocaleDate(meta.getLastModified(), getLocale()), formLayout);
// file type
uifactory.addStaticTextElement("mf.type", typeText, formLayout);
uifactory.addStaticTextElement("mf.downloads", String.valueOf(meta.getDownloadCount()), formLayout);
}
if (!isSubform && meta.isDirectory()) {
// Don't show any meta data except title and comment if the item is
// a directory.
// Hide the metadata.
setMetaFieldsVisible(false);
if (moreMetaDataLink != null) moreMetaDataLink.setVisible(false);
}
// save and cancel buttons
if (!isSubform) {
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
formLayout.add(buttonLayout);
uifactory.addFormSubmitButton("submit", buttonLayout);
uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
}