final List<IColumn<AddressDO, String>> columns = createColumns(this, true);
dataTable = createDataTable(columns, "name", SortOrder.ASCENDING);
form.add(dataTable);
if (messagingSupported == true) {
final ContentMenuEntryPanel menuEntry = new ContentMenuEntryPanel(getNewContentMenuChildId(), new Link<Object>("link") {
@Override
public void onClick()
{
setResponsePage(SendSmsPage.class, new PageParameters());
};
}, getString("address.tooltip.writeSMS"));
addContentMenuEntry(menuEntry);
}
if (WebConfiguration.isDevelopmentMode() == true) {
// final Import vcards
final BookmarkablePageLink<AddressImportPage> importVCardsLink = new BookmarkablePageLink<AddressImportPage>(
ContentMenuEntryPanel.LINK_ID, AddressImportPage.class);
final ContentMenuEntryPanel importVCardsButton = new ContentMenuEntryPanel(getNewContentMenuChildId(), importVCardsLink,
getString("address.book.vCardImport")).setTooltip(getString("address.book.vCardImport.tooltip"));
addContentMenuEntry(importVCardsButton);
}
final ContentMenuEntryPanel exportMenu = new ContentMenuEntryPanel(getNewContentMenuChildId(), getString("export"));
addContentMenuEntry(exportMenu);
{
// Export vcards
final SubmitLink exportVCardsLink = new SubmitLink(ContentMenuEntryPanel.LINK_ID, form) {
@Override
public void onSubmit()
{
log.info("Exporting personal address book.");
final List<PersonalAddressDO> list = addressDao.getFavoriteVCards();
if (CollectionUtils.isEmpty(list) == true) {
form.addError("address.book.hasNoVCards");
return;
}
final String filename = "ProjectForge-PersonalAddressBook_" + DateHelper.getDateAsFilenameSuffix(new Date()) + ".vcf";
final StringWriter writer = new StringWriter();
addressDao.exportFavoriteVCards(writer, list);
DownloadUtils.setUTF8CharacterEncoding(getResponse());
DownloadUtils.setDownloadTarget(writer.toString().getBytes(), filename);
}
};
final ContentMenuEntryPanel exportVCardsButton = new ContentMenuEntryPanel(exportMenu.newSubMenuChildId(), exportVCardsLink,
getString("address.book.vCardExport")).setTooltip(getString("address.book.vCardExport.tooltip.title"),
getString("address.book.vCardExport.tooltip.content"));
exportMenu.addSubMenuEntry(exportVCardsButton);
}
{
// Excel export
final SubmitLink excelExportLink = new SubmitLink(ContentMenuEntryPanel.LINK_ID, form) {
@Override
public void onSubmit()
{
log.info("Exporting address list.");
final List<AddressDO> list = getList();
final byte[] xls = addressExport.export(list, personalAddressMap);
if (xls == null || xls.length == 0) {
form.addError("address.book.hasNoVCards");
return;
}
final String filename = "ProjectForge-AddressExport_" + DateHelper.getDateAsFilenameSuffix(new Date()) + ".xls";
DownloadUtils.setDownloadTarget(xls, filename);
}
};
final ContentMenuEntryPanel excelExportButton = new ContentMenuEntryPanel(exportMenu.newSubMenuChildId(), excelExportLink,
getString("address.book.export")).setTooltip(getString("address.book.export"), getString("address.book.export.tooltip"));
exportMenu.addSubMenuEntry(excelExportButton);
}
{
// Phone list export
final SubmitLink exportPhoneListLink = new SubmitLink(ContentMenuEntryPanel.LINK_ID, form) {
@Override
public void onSubmit()
{
log.info("Exporting phone list");
final List<PersonalAddressDO> list = addressDao.getFavoritePhoneEntries();
if (CollectionUtils.isEmpty(list) == true) {
form.addError("address.book.hasNoPhoneNumbers");
return;
}
final String filename = "ProjectForge-PersonalPhoneList_" + DateHelper.getDateAsFilenameSuffix(new Date()) + ".txt";
final StringWriter writer = new StringWriter();
addressDao.exportFavoritePhoneList(writer, list);
DownloadUtils.setUTF8CharacterEncoding(getResponse());
DownloadUtils.setDownloadTarget(writer.toString().getBytes(), filename);
}
};
final ContentMenuEntryPanel exportPhoneListButton = new ContentMenuEntryPanel(exportMenu.newSubMenuChildId(), exportPhoneListLink,
getString("address.book.exportFavoritePhoneList")).setTooltip(getString("address.book.exportFavoritePhoneList.tooltip.title"),
getString("address.book.exportFavoritePhoneList.tooltip.content"));
exportMenu.addSubMenuEntry(exportPhoneListButton);
}
{
final ContentMenuEntryPanel extendedMenu = contentMenuBarPanel.ensureAndAddExtendetMenuEntry();
// Apple script export
final SubmitLink appleScriptLink = new SubmitLink(ContentMenuEntryPanel.LINK_ID, form) {
@Override
public void onSubmit()
{
byte[] content = null;
final String file = APPLE_SCRIPT_DIR + APPLE_SCRIPT_FOR_ADDRESS_BOOK;
try {
final ClassLoader cLoader = this.getClass().getClassLoader();
final InputStream is = cLoader.getResourceAsStream(file);
if (is == null) {
log.error("Could not find script in resource path: '" + file + "'.");
}
content = IOUtils.toByteArray(is);
} catch (final IOException ex) {
log.error("Could not load script '" + file + "'." + ex.getMessage(), ex);
throw new RuntimeException(ex);
}
DownloadUtils.setDownloadTarget(content, APPLE_SCRIPT_FOR_ADDRESS_BOOK);
}
};
final ContentMenuEntryPanel appleScriptButton = new ContentMenuEntryPanel(extendedMenu.newSubMenuChildId(), appleScriptLink,
getString("address.book.export.appleScript4Notes")).setTooltip(getString("address.book.export.appleScript4Notes"),
getString("address.book.export.appleScript4Notes.tooltip"));
extendedMenu.addSubMenuEntry(appleScriptButton);
}
}