Example usage for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel

List of usage examples for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel

Introduction

In this page you can find the example usage for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel.

Prototype

AbstractReadOnlyModel

Source Link

Usage

From source file:au.org.theark.report.web.component.viewReport.ReportSelectPanel.java

License:Open Source License

/**
 * // w  ww  . j  a va 2  s.co  m
 * @param iModel
 * @param searchContainer
 * @return
 */
public PageableListView<ReportTemplate> buildPageableListView(IModel iModel) {

    PageableListView<ReportTemplate> sitePageableListView = new PageableListView<ReportTemplate>("reportList",
            iModel,
            iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<ReportTemplate> item) {

            ReportTemplate reportTemplate = item.getModelObject();
            ArkModule module = reportTemplate.getModule();
            ArkFunction function = reportTemplate.getFunction();

            /* The report module */
            // TODO : will need to change to foreign key reference when new ARK security is implemented
            if (reportTemplate.getModule() != null) {
                // Add the study Component Key here
                item.add(new Label("reportTemplate.module.name", module.getName()));
            } else {
                item.add(new Label("reportTemplate.module.name", ""));
            }

            // Perform security check upon selection of the report
            Subject subject = SecurityUtils.getSubject();
            String ldapUserName = subject.getPrincipal().toString();
            boolean securityCheckOk = false;
            try {
                String userRole = iArkCommonService.getUserRole(ldapUserName, function, module,
                        reportSelectCPM.getObject().getStudy());
                if (iArkCommonService.isSuperAdministator(ldapUserName, function, module)) {
                    // Super-Admins can do anything
                    securityCheckOk = true;
                } else {
                    if (userRole != null) {
                        java.util.Collection<String> userRolePermission = iArkCommonService
                                .getArkRolePermission(function, userRole, module);
                        // Enforces that the arkRolePolicyTemplate contain a READ for this report function 
                        if (userRolePermission.contains(PermissionConstants.READ)) {
                            securityCheckOk = true;
                        }
                    }
                }
            } catch (EntityNotFoundException e) {
                // TODO I don't like this kind of code - if there isn't a record, we should just return NULL.
                // Only if it really is an error to not have a record, then we should throw an exception.
            }
            item.setVisible(securityCheckOk);

            /* Component Name Link */
            item.add(buildLink(reportTemplate));

            // TODO when displaying text escape any special characters
            /* Description */
            if (reportTemplate.getDescription() != null) {
                item.add(new Label("reportTemplate.description", reportTemplate.getDescription())
                        .setEscapeModelStrings(false));// the ID here must
                                                                                                                                        // match the ones in
                                                                                                                                        // mark-up
            } else {
                item.add(new Label("reportTemplate.description", ""));// the ID here must match the ones in mark-up
            }

            /* For the alternative stripes */
            item.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));

        }
    };
    return sitePageableListView;
}

From source file:au.org.theark.study.web.component.address.SearchResultListPanel.java

License:Open Source License

@SuppressWarnings("unchecked")
public PageableListView<Address> buildPageableListView(IModel iModel) {

    PageableListView<Address> pageableListView = new PageableListView<Address>(Constants.ADDRESS_LIST, iModel,
            iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override/*from w  ww  . j  a v a2 s . c om*/
        protected void populateItem(final ListItem<Address> item) {

            Address address = item.getModelObject();
            item.add(buildLink(address));

            if (address.getCity() != null) {
                item.add(new Label("city", address.getCity()));
            } else {
                item.add(new Label("city", ""));
            }

            if (address.getState() != null && address.getState().getName() != null) {
                item.add(new Label("state.name", address.getState().getName()));//TODO things like this might almost need to be constants
            } else {
                item.add(new Label("state.name",
                        (address.getOtherState() != null && !address.getOtherState().isEmpty())
                                ? ("other: " + address.getOtherState())
                                : "not defined"));
            }

            if (address.getPostCode() != null) {
                item.add(new Label("postCode", address.getPostCode()));
            } else {
                item.add(new Label("postCode", ""));
            }

            if (address.getCountry() != null && address.getCountry().getName() != null) {
                item.add(new Label("country.name", address.getCountry().getName()));
            } else {
                item.add(new Label("country.name", ""));
            }

            if (address.getAddressType() != null && address.getAddressType().getName() != null) {
                item.add(new Label("addressType.name", address.getAddressType().getName()));
            } else {
                item.add(new Label("addressType.name", ""));
            }

            if (address.getDateReceived() != null) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                        au.org.theark.core.Constants.DD_MM_YYYY);
                String dateReceived = "";
                dateReceived = simpleDateFormat.format(address.getDateReceived());
                item.add(new Label("address.dateReceived", dateReceived));
            } else {
                item.add(new Label("address.dateReceived", ""));
            }

            if (address.getPreferredMailingAddress() != null && address.getPreferredMailingAddress() == true) {
                item.add(new ContextImage("address.preferredMailingAddress",
                        new Model<String>("images/icons/tick.png")));
            } else {
                item.add(new Label("address.preferredMailingAddress", ""));
            }

            item.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));

        }
    };
    return pageableListView;

}

From source file:au.org.theark.study.web.component.attachments.SearchResultListPanel.java

License:Open Source License

/**
 * /*from   w w w  .  ja  v a2  s . co m*/
 * @param iModel
 * @return the pageableListView of SubjectFile
 */
@SuppressWarnings("unchecked")
public PageableListView<SubjectFile> buildPageableListView(IModel iModel) {
    PageableListView<SubjectFile> sitePageableListView = new PageableListView<SubjectFile>(
            Constants.RESULT_LIST, iModel,
            arkCommonService.getUserConfig(Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<SubjectFile> item) {
            SubjectFile subjectFile = item.getModelObject();
            // The ID
            if (subjectFile.getId() != null) {
                // Add the id component here
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_ID,
                        subjectFile.getId().toString()));
            } else {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_ID, ""));
            }

            // The filename
            if (subjectFile.getFilename() != null) {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_FILENAME,
                        subjectFile.getFilename()));
            } else {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_FILENAME, ""));
            }

            // The study component
            if (subjectFile.getStudyComp() != null) {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_STUDY_COMP,
                        subjectFile.getStudyComp().getName()));
            } else {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_STUDY_COMP, ""));
            }

            // UserId
            if (subjectFile.getUserId() != null) {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_USER_ID,
                        subjectFile.getUserId()));
            } else {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_USER_ID, ""));
            }

            // Comments
            if (subjectFile.getComments() != null) {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_COMMENTS,
                        subjectFile.getComments()));
            } else {
                item.add(new Label(au.org.theark.study.web.Constants.SUBJECT_FILE_COMMENTS, ""));
            }

            // Download file button
            AjaxButton downloadButton = buildDownloadButton(subjectFile);
            item.add(downloadButton);

            // Delete file button
            item.add(buildDeleteButton(subjectFile, downloadButton));

            // For the alternative stripes
            item.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));
        }

    };
    return sitePageableListView;
}

From source file:au.org.theark.study.web.component.calendar.SearchResultListPanel.java

License:Open Source License

/**
 * // www .  ja v a2s .c o m
 * @param iModel
 * @param searchContainer
 * @return
 */
public PageableListView<StudyCalendar> buildPageableListView(IModel iModel) {

    PageableListView<StudyCalendar> sitePageableListView = new PageableListView<StudyCalendar>(
            "studyCalenderList", iModel,
            iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<StudyCalendar> item) {

            StudyCalendar studyCalendar = item.getModelObject();

            /* The Component ID */
            if (studyCalendar.getId() != null) {
                // Add the study Component Key here
                item.add(new Label("studyCalendar.id", studyCalendar.getId().toString()));
            } else {
                item.add(new Label("studyCalendar.id", ""));
            }
            /* Component Name Link */
            item.add(buildLink(studyCalendar));

            // TODO when displaying text escape any special characters
            /* Description */
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(au.org.theark.core.Constants.DD_MM_YYYY);
            String startDate = "";
            if (studyCalendar.getStartDate() != null) {
                startDate = simpleDateFormat.format(studyCalendar.getStartDate());
                item.add(new Label("studyCalendar.startDate", startDate));// the ID here must match the ones in mark-up
            } else {
                item.add(new Label("studyCalendar.startDate", startDate));// the ID here must match the ones in mark-up
            }

            String endDate = "";
            if (studyCalendar.getStartDate() != null) {
                endDate = simpleDateFormat.format(studyCalendar.getEndDate());
                item.add(new Label("studyCalendar.endDate", endDate));// the ID here must match the ones in mark-up
            } else {
                item.add(new Label("studyCalendar.endDate", endDate));// the ID here must match the ones in mark-up
            }

            /* For the alternative stripes */
            item.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));

        }
    };
    return sitePageableListView;
}

From source file:au.org.theark.study.web.component.consent.SearchResultListPanel.java

License:Open Source License

@SuppressWarnings("unchecked")
public PageableListView<Consent> buildPageableListView(IModel iModel) {

    PageableListView<Consent> pageableListView = new PageableListView<Consent>(Constants.CONSENT_LIST, iModel,
            iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override/*  w  w w  .  j a v a2 s. c  o  m*/
        protected void populateItem(final ListItem<Consent> item) {
            Consent consent = item.getModelObject();

            item.add(buildLink(consent));
            if (consent.getStudyComponentStatus() != null) {
                item.add(new Label("studyComponentStatus.name", consent.getStudyComponentStatus().getName()));
            } else {
                item.add(new Label("studyComponentStatus.name", " "));
            }

            if (consent.getConsentStatus() != null) {
                item.add(new Label("consentStatus.name", consent.getConsentStatus().getName()));
            } else {
                item.add(new Label("consentStatus.name", " "));
            }

            if (consent.getConsentType() != null) {
                item.add(new Label("consentType.name", consent.getConsentType().getName()));
            } else {
                item.add(new Label("consentType.name", ""));
            }

            if (consent.getConsentedBy() != null) {
                item.add(new Label("consentedBy", consent.getConsentedBy()));
            } else {
                item.add(new Label("consentedBy", ""));
            }

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(au.org.theark.core.Constants.DD_MM_YYYY);
            String consentDate = "";

            if (consent.getConsentDate() != null) {
                item.add(new Label("consentDate", simpleDateFormat.format(consent.getConsentDate())));
            } else {
                item.add(new Label("consentDate", consentDate));
            }

            item.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));
        }
    };
    return pageableListView;

}

From source file:au.org.theark.study.web.component.consenthistory.ConsentHistoryPanel.java

License:Open Source License

@SuppressWarnings("unchecked")
public PageableListView<ConsentHistory> buildListView(IModel iModel) {
    PageableListView<ConsentHistory> listView = new PageableListView<ConsentHistory>("resultList", iModel,
            iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override/*from   w  w w  .j a va  2  s . co  m*/
        protected void populateItem(final ListItem<ConsentHistory> item) {
            ConsentHistory consentHistory = item.getModelObject();

            if (consentHistory.getTimestamp() != null) {
                item.add(new Label("timestamp", simpleDateTimeFormat.format(consentHistory.getTimestamp())));
            } else {
                item.add(new Label("timestamp"));
            }

            if (consentHistory.getStudyComponentStatus() != null) {
                item.add(new Label("studyComponentStatus", consentHistory.getStudyComponentStatus().getName()));
            } else {
                item.add(new Label("studyComponentStatus"));
            }

            if (consentHistory.getConsentStatus() != null) {
                item.add(new Label("consentStatus", consentHistory.getConsentStatus().getName()));
            } else {
                item.add(new Label("consentStatus"));
            }

            if (consentHistory.getConsentDate() != null) {
                item.add(new Label("consentDate", simpleDateFormat.format(consentHistory.getConsentDate())));
            } else {
                item.add(new Label("consentDate"));
            }

            if (consentHistory.getRequestedDate() != null) {
                item.add(
                        new Label("requestedDate", simpleDateFormat.format(consentHistory.getRequestedDate())));
            } else {
                item.add(new Label("requestedDate"));
            }

            if (consentHistory.getReceivedDate() != null) {
                item.add(new Label("receivedDate", simpleDateFormat.format(consentHistory.getReceivedDate())));
            } else {
                item.add(new Label("receivedDate"));
            }

            if (consentHistory.getCompletedDate() != null) {
                item.add(
                        new Label("completedDate", simpleDateFormat.format(consentHistory.getCompletedDate())));
            } else {
                item.add(new Label("completedDate"));
            }

            if (consentHistory.getConsentedBy() != null) {
                item.add(new Label("consentedBy", consentHistory.getConsentedBy()));
            } else {
                item.add(new Label("consentedBy"));
            }

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? Constants.EVEN : Constants.ODD;
                }
            }));
        }
    };
    return listView;
}

From source file:au.org.theark.study.web.component.consenthistory.LinkSubjectStudyConsentHistoryPanel.java

License:Open Source License

@SuppressWarnings("unchecked")
public PageableListView<LssConsentHistory> buildListView(IModel iModel) {
    PageableListView<LssConsentHistory> listView = new PageableListView<LssConsentHistory>("resultList", iModel,
            iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override/*ww w  .  ja  v a2s. c o m*/
        protected void populateItem(final ListItem<LssConsentHistory> item) {
            LssConsentHistory consentHistory = item.getModelObject();

            if (consentHistory.getTimestamp() != null) {
                item.add(new Label("timestamp", simpleDateFormat.format(consentHistory.getTimestamp())));
            } else {
                item.add(new Label("timestamp"));
            }

            if (consentHistory.getConsentDate() != null) {
                item.add(new Label("consentDate", simpleDateFormat.format(consentHistory.getConsentDate())));
            } else {
                item.add(new Label("consentDate"));
            }

            if (consentHistory.getConsentStatus() != null) {
                item.add(new Label("consentStatus", consentHistory.getConsentStatus().getName()));
            } else {
                item.add(new Label("consentStatus"));
            }

            if (consentHistory.getConsentType() != null) {
                item.add(new Label("consentType", consentHistory.getConsentType().getName()));
            } else {
                item.add(new Label("consentType"));
            }

            if (consentHistory.getConsentDownloaded() != null) {
                item.add(new Label("consentDownloaded", consentHistory.getConsentDownloaded().getName()));
            } else {
                item.add(new Label("consentDownloaded"));
            }

            if (consentHistory.getConsentToPassiveDataGathering() != null) {
                item.add(new Label("consentToPassiveDataGathering",
                        consentHistory.getConsentToPassiveDataGathering().getName()));
            } else {
                item.add(new Label("consentToPassiveDataGathering"));
            }

            if (consentHistory.getConsentToActiveContact() != null) {
                item.add(new Label("consentToActiveContact",
                        consentHistory.getConsentToActiveContact().getName()));
            } else {
                item.add(new Label("consentToActiveContact"));
            }

            if (consentHistory.getConsentToUseData() != null) {
                item.add(new Label("consentToUseData", consentHistory.getConsentToUseData().getName()));
            } else {
                item.add(new Label("consentToUseData"));
            }

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? Constants.EVEN : Constants.ODD;
                }
            }));
        }
    };
    return listView;
}

From source file:au.org.theark.study.web.component.contact.AddressListPanel.java

License:Open Source License

/**
 * Build the data view for display and navigate purposes.
 * /*from   w  ww  .j a v a  2 s. c  om*/
 * @param addressProvider
 * @return
 */
private DataView<Address> buildDataView(ArkDataProvider<Address, IStudyService> addressProvider) {

    DataView<Address> adressListDataView = new DataView<Address>("addressList", addressProvider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<Address> item) {

            Address address = item.getModelObject();
            item.add(buildLink(address));

            if (address.getCity() != null) {
                item.add(new Label("city", address.getCity()));
            } else {
                item.add(new Label("city", ""));
            }

            if (address.getState() != null && address.getState().getName() != null) {
                item.add(new Label("state.name", address.getState().getName()));// TODO things like this might almost need to be constants
            } else {
                item.add(new Label("state.name",
                        (address.getOtherState() != null && !address.getOtherState().isEmpty())
                                ? ("other: " + address.getOtherState())
                                : "not defined"));
            }

            if (address.getPostCode() != null) {
                item.add(new Label("postCode", address.getPostCode()));
            } else {
                item.add(new Label("postCode", ""));
            }

            if (address.getCountry() != null && address.getCountry().getName() != null) {
                item.add(new Label("country.name", address.getCountry().getName()));
            } else {
                item.add(new Label("country.name", ""));
            }

            if (address.getAddressType() != null && address.getAddressType().getName() != null) {
                item.add(new Label("addressType.name", address.getAddressType().getName()));
            } else {
                item.add(new Label("addressType.name", ""));
            }

            if (address.getDateReceived() != null) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                        au.org.theark.core.Constants.DD_MM_YYYY);
                String dateReceived = "";
                dateReceived = simpleDateFormat.format(address.getDateReceived());
                item.add(new Label("address.dateReceived", dateReceived));
            } else {
                item.add(new Label("address.dateReceived", ""));
            }

            if (address.getPreferredMailingAddress() != null && address.getPreferredMailingAddress() == true) {
                item.add(new ContextImage("address.preferredMailingAddress",
                        new Model<String>("images/icons/tick.png")));
            } else {
                item.add(new Label("address.preferredMailingAddress", ""));
            }

            item.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));

        }
    };

    return adressListDataView;
}

From source file:au.org.theark.study.web.component.contact.AddressListPanel.java

License:Open Source License

/**
 * Build the data view for export purposes with subject id.
 * /*from ww  w .  ja  v a  2 s  .c o m*/
 * @param addressProvider
 * @return
 */
private DataView<AddressSubjectVO> buildDataViewWithSubjectStudyID(
        ArkDataProvider<AddressSubjectVO, IStudyService> addressProvider) {

    DataView<AddressSubjectVO> addressListDataView = new DataView<AddressSubjectVO>("addressList",
            addressProvider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<AddressSubjectVO> item) {

            AddressSubjectVO addressSubjectVO = item.getModelObject();
            // item.add(buildLink(address));

            if (addressSubjectVO.getSubjectUID() != null) {
                item.add(new Label("subjectUID", addressSubjectVO.getSubjectUID()));
            } else {
                item.add(new Label("subjectUID", ""));
            }
            if (addressSubjectVO.getStreetAddress() != null) {
                item.add(new Label("streetAddress", addressSubjectVO.getStreetAddress()));
            } else {
                item.add(new Label("streetAddress", ""));
            }
            if (addressSubjectVO.getCity() != null) {
                item.add(new Label("city", addressSubjectVO.getCity()));
            } else {
                item.add(new Label("city", ""));
            }

            if (addressSubjectVO.getState() != null && addressSubjectVO.getState().getName() != null) {
                item.add(new Label("state.name", addressSubjectVO.getState().getName()));// TODO things like this might almost need to be constants
            } else {
                item.add(new Label("state.name",
                        (addressSubjectVO.getOtherState() != null
                                && !addressSubjectVO.getOtherState().isEmpty())
                                        ? ("other: " + addressSubjectVO.getOtherState())
                                        : "not defined"));
            }

            if (addressSubjectVO.getPostCode() != null) {
                item.add(new Label("postCode", addressSubjectVO.getPostCode()));
            } else {
                item.add(new Label("postCode", ""));
            }

            if (addressSubjectVO.getCountry() != null && addressSubjectVO.getCountry().getName() != null) {
                item.add(new Label("country.name", addressSubjectVO.getCountry().getName()));
            } else {
                item.add(new Label("country.name", ""));
            }

            if (addressSubjectVO.getAddressType() != null
                    && addressSubjectVO.getAddressType().getName() != null) {
                item.add(new Label("addressType.name", addressSubjectVO.getAddressType().getName()));
            } else {
                item.add(new Label("addressType.name", ""));
            }

            if (addressSubjectVO.getDateReceived() != null) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                        au.org.theark.core.Constants.DD_MM_YYYY);
                String dateReceived = "";
                dateReceived = simpleDateFormat.format(addressSubjectVO.getDateReceived());
                item.add(new Label("address.dateReceived", dateReceived));
            } else {
                item.add(new Label("address.dateReceived", ""));
            }

            if (addressSubjectVO.getPreferredMailingAddress() != null
                    && addressSubjectVO.getPreferredMailingAddress() == true) {
                item.add(new ContextImage("address.preferredMailingAddress",
                        new Model<String>("images/icons/tick.png")));
            } else {
                item.add(new Label("address.preferredMailingAddress", ""));
            }

            item.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));

        }
    };
    return addressListDataView;
}

From source file:au.org.theark.study.web.component.contact.PhoneListPanel.java

License:Open Source License

/**
 * Create a dataview for display and navigate purposes.
 * //from ww w  .j  a va  2s. c  o m
 * @param phoneProvider
 * @return
 */
private DataView<Phone> buildDataView(ArkDataProvider<Phone, IStudyService> phoneProvider) {

    DataView<Phone> phoneListDataView = new DataView<Phone>("phoneList", phoneProvider,
            iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<Phone> item) {

            Phone phone = item.getModelObject();
            item.add(buildLink(phone));
            if (phone.getId() != null) {
                item.add(new Label("id", phone.getId().toString()));
            } else {
                item.add(new Label("id", ""));
            }

            if (phone.getAreaCode() != null) {
                item.add(new Label("areaCode", phone.getAreaCode()));
            } else {
                item.add(new Label("areaCode", ""));
            }
            if (phone.getPhoneType() != null && phone.getPhoneType().getName() != null) {
                item.add(new Label("phoneType.name", phone.getPhoneType().getName()));
            } else {
                item.add(new Label("phoneType.name", ""));
            }
            if (phone.getPhoneStatus() != null && phone.getPhoneStatus().getName() != null) {
                item.add(new Label("phoneStatus.name", phone.getPhoneStatus().getName()));
            } else {
                item.add(new Label("phoneStatus.name", ""));
            }
            if (phone.getValidFrom() != null) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                        au.org.theark.core.Constants.DD_MM_YYYY);
                String dateValidFrom = "";
                dateValidFrom = simpleDateFormat.format(phone.getValidFrom());
                item.add(new Label("validFrom", dateValidFrom));
            } else {
                item.add(new Label("validFrom", ""));
            }
            if (phone.getValidTo() != null) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                        au.org.theark.core.Constants.DD_MM_YYYY);
                String dateValidTo = "";
                dateValidTo = simpleDateFormat.format(phone.getValidTo());
                item.add(new Label("validTo", dateValidTo));
            } else {
                item.add(new Label("validTo", ""));
            }
            if (phone.getPreferredPhoneNumber() != null && phone.getPreferredPhoneNumber() == true) {
                item.add(new ContextImage("phone.preferredPhoneNumber",
                        new Model<String>("images/icons/tick.png")));
            } else {
                item.add(new Label("phone.preferredPhoneNumber", ""));
            }

            item.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));
        }
    };
    return phoneListDataView;
}