public Collection<Phone> getPhones() { IWContext iwc = getIwc(); if (!iwc.isLoggedOn()) { return Collections.emptyList(); } User user = iwc.getCurrentUser(); @SuppressWarnings("unchecked") Collection<Phone> phones = user.getPhones(); if (ListUtil.isEmpty(phones)) { return Collections.emptyList(); } return phones; }
public Table getPupilTable(IWContext iwc, User pupil) { // *** Search Table *** START - the uppermost table Table table = new Table(); table.setWidth("100%"); table.setBorder(0); table.setCellpadding(2); table.setCellspacing(0); this.transGIF.setHeight("1"); this.transGIF.setWidth("1"); int row = 1; int col = 1; // add empty space row table.add(this.transGIF, col++, row); table.add(this.transGIF, col++, row); table.add(this.transGIF, col++, row); table.add(this.transGIF, col++, row); table.add(this.transGIF, col++, row); // Set COLUMN WIDTH for column 1 to 5 table.setWidth(1, row, "100"); // table.setWidth(2, row, "70"); // table.setWidth(3, row, "70"); // table.setWidth(4, row, "70"); // table.setWidth(5, row, "104"); row++; col = 1; // *** HEADING Pupil *** Text pupilTxt = new Text(localize(KEY_PUPIL_HEADING, "Pupil")); pupilTxt.setFontStyle(STYLE_UNDERLINED_SMALL_HEADER); table.add(pupilTxt, col++, row); table.setRowHeight(row, "20"); table.setRowVerticalAlignment(row, Table.VERTICAL_ALIGN_BOTTOM); row++; col = 1; // empty space row table.add(this.transGIF, col, row); table.setRowHeight(row, "5"); col = 1; row++; // Personal Id Number table.add(getSmallHeader(localize(KEY_PERSONAL_ID_LABEL, "Personal id: ")), col++, row); if (pupil != null) { table.add(getSmallText(pupil.getPersonalID()), col++, row); } row++; col = 1; // Last Name table.add(getSmallHeader(localize(KEY_LAST_NAME_LABEL, "Last name: ")), col++, row); Table nameTable = new Table(); col = 1; nameTable.setCellpadding(0); nameTable.setCellspacing(0); if (pupil != null) { nameTable.add(getSmallText(pupil.getLastName()), col++, 1); } // First Name nameTable.add(getSmallHeader(localize(KEY_FIRST_NAME_LABEL, "First name: ")), col++, 1); if (pupil != null) { nameTable.add(getSmallText(pupil.getFirstName()), col++, 1); } nameTable.setWidth(1, 1, "100"); nameTable.setWidth(2, 1, "100"); nameTable.setWidth(3, 1, "100"); table.add(nameTable, 2, row); table.mergeCells(2, row, 5, row); row++; col = 1; // Address and Phone table.add(getSmallHeader(localize(KEY_ADDRESS_LABEL, "Address: ")), col++, row); row++; col = 1; table.add(getSmallHeader(localize(KEY_PHONE_LABEL, "Phone: ")), col++, row); if (pupil != null) { try { // pupil address Address address = getUserBusiness(iwc).getUsersMainAddress(pupil); StringBuffer aBuf = new StringBuffer(address.getStreetAddress()); aBuf.append(", "); aBuf.append(address.getPostalCode().getPostalAddress()); row--; table.add(getSmallText(aBuf.toString()), col, row); row++; // Get pupil phones Collection phones = pupil.getPhones(); int i = 0; int phonesSize = phones.size(); StringBuffer pBuf = new StringBuffer(); for (Iterator iter = phones.iterator(); iter.hasNext(); i++) { Phone phone = (Phone) iter.next(); pBuf.append(phone.getNumber()); if (i < phonesSize - 1) { pBuf.append(", "); } } pBuf.append(" "); table.add(getSmallText(pBuf.toString()), col, row); } catch (Exception e) { e.printStackTrace(); } } row++; col = 1; return table; }