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.lims.web.component.biospecimenupload.SearchResultListPanel.java

License:Open Source License

/**
 * //ww w  .java2s .co m
 * @param iModel
 * @return the pageableListView of Upload
 */
@SuppressWarnings("unchecked")
public PageableListView<Upload> buildPageableListView(IModel iModel) {
    PageableListView<Upload> sitePageableListView = new PageableListView<Upload>(Constants.RESULT_LIST, iModel,
            iArkCommonService.getUserConfig(Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<Upload> item) {
            Upload upload = item.getModelObject();

            // The ID
            if (upload.getId() != null) {
                // Add the id component here
                item.add(new Label(Constants.UPLOADVO_UPLOAD_ID, upload.getId().toString()));
            } else {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_ID, ""));
            }

            // / The filename
            if (upload.getFilename() != null) {
                // Add the id component here
                item.add(new Label(Constants.UPLOADVO_UPLOAD_FILENAME, upload.getFilename()));
            } else {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_FILENAME, ""));
            }

            // File Format
            if (upload.getFileFormat() != null) {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_FILE_FORMAT, upload.getFileFormat().getName()));
            } else {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_FILE_FORMAT, ""));
            }

            // UserId
            if (upload.getUserId() != null) {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_USER_ID, upload.getUserId()));
            } else {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_USER_ID, ""));
            }

            // Start time
            if (upload.getStartTime() != null) {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_START_TIME, upload.getStartTime().toString()));
            } else {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_START_TIME, ""));
            }

            // Finish time
            if (upload.getFinishTime() != null) {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_FINISH_TIME, upload.getFinishTime().toString()));
            } else {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_FINISH_TIME, ""));
            }

            if (upload.getUploadStatus() != null && upload.getUploadStatus().getShortMessage() != null) {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_UPLOAD_STATUS_NAME,
                        upload.getUploadStatus().getShortMessage()));
            } else {
                item.add(new Label(Constants.UPLOADVO_UPLOAD_UPLOAD_STATUS_NAME, ""));
            }

            // Download file link button
            item.add(buildDownloadButton(upload));

            // Download upload report button
            item.add(buildDownloadReportButton(upload));

            // Delete the upload file
            //            item.add(buildDeleteButton(upload));

            // 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.lims.web.component.biotransaction.BioTransactionListPanel.java

License:Open Source License

/**
 * //ww  w . j  ava2  s . com
 * @param iModel
 * @return the pageableListView of BioCollection
 */
public DataView<BioTransaction> buildDataView(ArkDataProvider2<LimsVO, BioTransaction> bioTransactionProvider) {

    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(au.org.theark.core.Constants.DD_MM_YYYY);

    DataView<BioTransaction> bioTransactionDataView = new DataView<BioTransaction>("bioTransactionList",
            bioTransactionProvider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<BioTransaction> item) {
            item.setOutputMarkupId(true);
            // DO NOT store the item.getModelObject! Checking it is ok...
            final BioTransaction bioTransaction = item.getModelObject();

            WebMarkupContainer rowDetailsWMC = new WebMarkupContainer("rowDetailsWMC", item.getModel());
            AjaxConfirmLink<BioTransaction> rowDeleteLink = new AjaxConfirmLink<BioTransaction>("rowDeleteLink",
                    new StringResourceModel("bioTransaction.confirmDelete", this, item.getModel()),
                    item.getModel()) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    BioTransaction bioTransaction = getModelObject();
                    iLimsService.deleteBioTransaction(bioTransaction);

                    // update biospecimen (qty avail)
                    Double qtyAvail = iLimsService.getQuantityAvailable(cpModel.getObject().getBiospecimen());
                    cpModel.getObject().getBiospecimen().setQuantity(qtyAvail);
                    try {
                        iLimsService.updateBiospecimen(cpModel.getObject());
                    } catch (ArkSystemException e) {
                        this.error(e.getMessage());
                    }

                    this.info("Successfully removed the transaction");
                    target.add(feedbackPanel);
                    target.add(dataViewListWMC); // repaint the list
                    target.add(dataViewListWMC.getParent().getParent()); // repaint the parent form
                }

            };
            rowDetailsWMC.add(rowDeleteLink);
            //            if ((bioTransaction.getStatus() != null) && (bioTransaction.getStatus().getName().equalsIgnoreCase(Constants.BIOTRANSACTION_STATUS_INITIAL_QUANTITY))) {
            //               // do not allow the initial quantity to be deleted
            //               rowDetailsWMC.setVisible(false);
            //            }

            idLbl = new Label("bioTransaction.id", bioTransaction.getId().toString());
            String dateOfTransaction = "";
            if (bioTransaction.getTransactionDate() != null) {
                dateOfTransaction = simpleDateFormat.format(bioTransaction.getTransactionDate());
            }
            transactionDateLbl = new Label("bioTransaction.transactionDate", dateOfTransaction);

            if (bioTransaction.getQuantity() == null) {
                quantityLbl = new Label("bioTransaction.quantity", "0");
            } else {
                quantityLbl = new Label("bioTransaction.quantity", bioTransaction.getQuantity().toString());
            }
            if (bioTransaction.getBiospecimen().getUnit() == null) {
                unitsLbl = new Label("bioTransaction.biospecimen.unit.name", "");
            } else {
                unitsLbl = new Label("bioTransaction.biospecimen.unit.name",
                        bioTransaction.getBiospecimen().getUnit().getName());
            }
            reasonLbl = new Label("bioTransaction.reason", bioTransaction.getReason());
            recorderLbl = new Label("bioTransaction.recorder", bioTransaction.getRecorder());
            if (bioTransaction.getStatus() == null) {
                statusLbl = new Label("bioTransaction.status.name", "");
            } else {
                statusLbl = new Label("bioTransaction.status.name", bioTransaction.getStatus().getName());
            }
            if (bioTransaction.getAccessRequest() == null) {
                requestLbl = new Label("bioTransaction.accessRequest.id", "");
            } else {
                requestLbl = new Label("bioTransaction.accessRequest.id",
                        bioTransaction.getAccessRequest().getId().toString());
            }

            item.add(idLbl);
            item.add(transactionDateLbl);

            if (bioTransaction.getQuantity() > 0) {
                quantityImage = new ContextImage("bioTransaction.quantityImage",
                        new Model<String>("images/icons/arrow_up.png"));
            } else {
                quantityImage = new ContextImage("bioTransaction.quantityImage",
                        new Model<String>("images/icons/arrow_down_red.png"));
            }

            item.add(quantityImage);
            item.add(quantityLbl);
            item.add(unitsLbl);
            item.add(reasonLbl);
            item.add(recorderLbl);
            item.add(statusLbl);
            item.add(requestLbl);
            item.add(rowDetailsWMC);

            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 bioTransactionDataView;
}

From source file:au.org.theark.lims.web.component.bioupload.SearchResultListPanel.java

License:Open Source License

/**
 * /*from w ww  .  j  av  a 2 s  . c o  m*/
 * @param iModel
 * @return the pageableListView of Upload
 */
@SuppressWarnings("unchecked")
public PageableListView<Upload> buildPageableListView(IModel iModel) {
    PageableListView<Upload> sitePageableListView = new PageableListView<Upload>(Constants.RESULT_LIST, iModel,
            iArkCommonService.getUserConfig(Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<Upload> item) {
            Upload upload = item.getModelObject();

            // The ID
            if (upload.getId() != null) {
                // Add the id component here
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_ID,
                        upload.getId().toString()));
            } else {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_ID, ""));
            }

            // / The filename
            if (upload.getFilename() != null) {
                // Add the id component here
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_FILENAME,
                        upload.getFilename()));
            } else {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_FILENAME, ""));
            }

            // File Format
            if (upload.getFileFormat() != null) {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_FILE_FORMAT,
                        upload.getFileFormat().getName()));
            } else {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_FILE_FORMAT, ""));
            }

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

            // Start time
            if (upload.getStartTime() != null) {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_START_TIME,
                        upload.getStartTime().toString()));
            } else {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_START_TIME, ""));
            }

            // Finish time
            if (upload.getFinishTime() != null) {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_FINISH_TIME,
                        upload.getFinishTime().toString()));
            } else {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_FINISH_TIME, ""));
            }

            // Finish time
            if (upload.getUploadStatus() != null && upload.getUploadStatus().getShortMessage() != null) {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_UPLOAD_STATUS_NAME,
                        upload.getUploadStatus().getShortMessage()));
            } else {
                item.add(new Label(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_UPLOAD_STATUS_NAME, ""));
            }

            // Download file link button
            item.add(buildDownloadButton(upload));

            // Download upload report button
            item.add(buildDownloadReportButton(upload));

            // Delete the upload file
            // item.add(buildDeleteButton(upload));

            // 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.lims.web.component.global.biospecimen.form.BiospecimenListForm.java

License:Open Source License

/**
 * //w ww. j a  va  2  s.c  om
 * @param iModel
 * @return the pageableListView of BioCollection
 */
public DataView<Biospecimen> buildDataView(ArkDataProvider2<LimsVO, Biospecimen> biospecimenProvider) {

    DataView<Biospecimen> biospecimenDataView = new DataView<Biospecimen>("biospecimenList",
            biospecimenProvider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<Biospecimen> item) {
            item.setOutputMarkupId(true);
            // DO NOT store the item.getModelObject! Checking it is ok...
            final Biospecimen biospecimen = item.getModelObject();

            WebMarkupContainer rowDetailsWMC = new WebMarkupContainer("rowDetailsWMC", item.getModel());
            ArkBusyAjaxLink listDetailsLink = new ArkBusyAjaxLink("listDetailsLink") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(new LimsVO());
                    try {
                        Biospecimen biospecimenFromDB = iLimsService.getBiospecimen(biospecimen.getId());
                        Study study = iArkCommonService.getStudy(biospecimenFromDB.getStudy().getId());
                        LinkSubjectStudy linkSubjectStudy = iArkCommonService.getSubjectByUID(
                                biospecimenFromDB.getLinkSubjectStudy().getSubjectUID(), study);
                        biospecimenFromDB.setStudy(study);
                        biospecimenFromDB.setLinkSubjectStudy(linkSubjectStudy);

                        setContextItems(target, linkSubjectStudy);

                        newModel.getObject().setLinkSubjectStudy(linkSubjectStudy);
                        newModel.getObject().setBiospecimen(biospecimenFromDB);
                        newModel.getObject().setBioCollection(biospecimenFromDB.getBioCollection());
                        newModel.getObject().setTreeModel(cpModel.getObject().getTreeModel());
                        showModalWindow(target, newModel);
                    } catch (EntityNotFoundException e) {
                        log.error(e.getMessage());
                    }
                }

            };

            idLblFld = new Label("biospecimen.id", String.valueOf(biospecimen.getId()));

            nameLblFld = new Label("biospecimen.biospecimenUid", biospecimen.getBiospecimenUid());
            listDetailsLink.add(nameLblFld);
            rowDetailsWMC.add(listDetailsLink);

            studyLblFld = new Label("biospecimen.study.name", biospecimen.getStudy().getName());
            subjectUidLblFld = new Label("biospecimen.linkSubjectStudy.subjectUid",
                    biospecimen.getLinkSubjectStudy().getSubjectUID());
            sampleTypeLblFld = new Label("biospecimen.sampleType.name", biospecimen.getSampleType().getName());
            collectionLblFld = new Label("biospecimen.bioCollection.biocollectionUid",
                    biospecimen.getBioCollection().getBiocollectionUid());

            biospecimen.setQuantity(iLimsService.getQuantityAvailable(biospecimen));
            if (biospecimen.getQuantity() == null) {
                quantityLblFld = new Label("biospecimen.quantity", "0");
            } else {
                quantityLblFld = new Label("biospecimen.quantity", biospecimen.getQuantity().toString());
            }
            if (biospecimen.getUnit() == null) {
                unitsLblFld = new Label("biospecimen.unit", "");
            } else {
                unitsLblFld = new Label("biospecimen.unit", biospecimen.getUnit().getName());
            }

            try {
                locationLbl = new Label("biospecimen.location", "view");
                locationLink = new ArkBusyAjaxLink("biospecimen.location.link") {

                    /**
                     * 
                     */
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(
                                new LimsVO());
                        newModel.getObject().getBiospecimen().setId(biospecimen.getId());
                        BiospecimenLocationVO biospecimenLocationVo;
                        try {
                            biospecimenLocationVo = iInventoryService.getBiospecimenLocation(biospecimen);
                            newModel.getObject().setBiospecimenLocationVO(biospecimenLocationVo);
                            BioLocationPanel bioLocationPanel = new BioLocationPanel("content", newModel) {
                                /**
                                 * 
                                 */
                                private static final long serialVersionUID = 1L;

                                @Override
                                public void refreshParentPanel(AjaxRequestTarget target) {
                                }
                            };
                            bioLocationPanel.getUnallocateButton().setVisible(false);
                            bioLocationPanel.add(new AttributeModifier("class", "detailsPanelBorder"));
                            // Set the modalWindow title and content
                            modalWindow.setTitle("Biospecimen Location Detail");
                            modalWindow.setContent(bioLocationPanel);
                            modalWindow.show(target);
                        } catch (ArkSystemException e) {
                            log.error(e.getMessage());
                        }
                    }
                };

                locationLink.add(locationLbl);

                BiospecimenLocationVO biospecimenLocationVo = iInventoryService
                        .getBiospecimenLocation(biospecimen);
                if (!biospecimenLocationVo.getIsAllocated()) {
                    locationLink.setVisible(false);
                }
            } catch (ArkSystemException e) {
                log.error(e.getMessage());
            }

            item.add(idLblFld);
            item.add(rowDetailsWMC);
            item.add(studyLblFld);
            item.add(subjectUidLblFld);
            item.add(sampleTypeLblFld);
            item.add(collectionLblFld);
            item.add(quantityLblFld);
            item.add(unitsLblFld);
            item.add(locationLink);

            if (biospecimen.getBarcoded()) {
                item.addOrReplace(
                        new ContextImage("biospecimen.barcoded", new Model<String>("images/icons/tick.png")));
            } else {
                item.addOrReplace(
                        new ContextImage("biospecimen.barcoded", new Model<String>("images/icons/cross.png")));
            }

            item.add(new AjaxButton("batchAliquot") {

                /**
                 * 
                 */
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isEnabled() {
                    return ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.NEW);
                }

                protected void onSubmit(AjaxRequestTarget target,
                        org.apache.wicket.markup.html.form.Form<?> form) {
                    onBatchAliquot(target, item.getModel());
                    target.add(feedbackPanel);
                };

                protected void onError(AjaxRequestTarget target,
                        org.apache.wicket.markup.html.form.Form<?> form) {
                    target.add(feedbackPanel);
                };

                public boolean isVisible() {
                    return (item.getModelObject().getQuantity() != null
                            && item.getModelObject().getQuantity() > 0);
                };

            }.setDefaultFormProcessing(false));

            item.add(new AjaxButton("allocateUnallocate") {
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isEnabled() {
                    return ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.EDIT);
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

                    BiospecimenLocationVO biospecimenLocationVo = null;
                    try {
                        biospecimenLocationVo = iInventoryService.getBiospecimenLocation(biospecimen);
                    } catch (ArkSystemException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    if (biospecimenLocationVo.getIsAllocated()) {
                        //unallocate
                        InvCell invCell = iInventoryService.getInvCellByBiospecimen(biospecimen);
                        invCell.setBiospecimen(null);
                        invCell.setStatus("Empty");
                        iInventoryService.updateInvCell(invCell);

                        try {
                            cpModel.getObject()
                                    .setBiospecimenLocationVO(iInventoryService.getInvCellLocation(invCell));
                            cpModel.getObject().getBiospecimenLocationVO().setIsAllocated(false);
                            cpModel.getObject().setInvCell(invCell);
                        } catch (ArkSystemException e) {
                        }
                    } else {
                        //cpModel.getObject().setBiospecimen(biospecimen);
                        CompoundPropertyModel<LimsVO> cpm = new CompoundPropertyModel<LimsVO>(new LimsVO());
                        cpm.getObject().setBiospecimen(biospecimen);
                        modalContentPanel = new BioModalAllocateDetailPanel("content", modalWindow, cpm);

                        // Set the modalWindow title and content
                        modalWindow.setTitle("Biospecimen Allocation");
                        modalWindow.setContent(modalContentPanel);
                        modalWindow.setWidthUnit("%");
                        modalWindow.setInitialWidth(70);
                        modalWindow.show(target);
                        //cpModel.getObject().setBiospecimen(new Biospecimen());
                        modalWindow.repaintComponent(BiospecimenListForm.this);

                    }
                    target.add(BiospecimenListForm.this);
                }

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                }

            }.setDefaultFormProcessing(false));

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() {

                private static final long serialVersionUID = 1L;

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

    };

    return biospecimenDataView;
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biocollection.form.BioCollectionListForm.java

License:Open Source License

/**
 * /*from w w  w. jav  a  2s . c  om*/
 * @param iModel
 * @return the pageableListView of BioCollection
 */
public DataView<BioCollection> buildDataView(
        ArkDataProvider<BioCollection, ILimsService> bioCollectionProvider) {

    DataView<BioCollection> bioCollectionDataView = new DataView<BioCollection>("collectionList",
            bioCollectionProvider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<BioCollection> item) {
            item.setOutputMarkupId(true);
            // DO NOT store the item.getModelObject! Checking it is ok...
            final BioCollection bioCollection = item.getModelObject();

            WebMarkupContainer rowDetailsWMC = new WebMarkupContainer("rowDetailsWMC", item.getModel());
            ArkBusyAjaxLink listDetailsLink = new ArkBusyAjaxLink("listDetailsLink") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    BioCollection bc = (BioCollection) (getParent().getDefaultModelObject());
                    CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(new LimsVO());
                    newModel.getObject().getBioCollection().setId(bc.getId());
                    showModalWindow(target, newModel);
                }

            };

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

            idLblFld = new Label("bioCollection.id", String.valueOf(bioCollection.getId()));
            biocollectionLblFld = new Label("bioCollection.biocollectionUid",
                    bioCollection.getBiocollectionUid());
            nameLblFld = new Label("bioCollection.name", bioCollection.getName());
            listDetailsLink.add(biocollectionLblFld);
            rowDetailsWMC.add(listDetailsLink);

            if (bioCollection.getCollectionDate() != null) {
                collectionDateLblFld = new Label("bioCollection.collectionDate",
                        simpleDateFormat.format(bioCollection.getCollectionDate()));
            } else {
                collectionDateLblFld = new Label("bioCollection.collectionDate", "");
            }

            if (bioCollection.getSurgeryDate() != null) {
                new Label("bioCollection.surgeryDate", simpleDateFormat.format(bioCollection.getSurgeryDate()));
            } else {
                new Label("bioCollection.surgeryDate", "");
            }

            commentsLblFld = new Label("bioCollection.comments", bioCollection.getComments());

            item.add(idLblFld);
            item.add(rowDetailsWMC);
            item.add(nameLblFld);
            item.add(collectionDateLblFld);
            item.add(commentsLblFld);

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() {

                private static final long serialVersionUID = 1L;

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

    };

    return bioCollectionDataView;
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenListForm.java

License:Open Source License

/**
 * /*from   w w w  .j  a  v  a2 s  .c o m*/
 * @param iModel
 * @return the pageableListView of BioCollection
 */
public DataView<Biospecimen> buildDataView(ArkDataProvider2<LimsVO, Biospecimen> biospecimenProvider) {

    DataView<Biospecimen> biospecimenDataView = new DataView<Biospecimen>("biospecimenList",
            biospecimenProvider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<Biospecimen> item) {
            item.setOutputMarkupId(true);
            // DO NOT store the item.getModelObject! Checking it is ok...
            final Biospecimen biospecimen = item.getModelObject();

            WebMarkupContainer rowDetailsWMC = new WebMarkupContainer("rowDetailsWMC", item.getModel());
            ArkBusyAjaxLink listDetailsLink = new ArkBusyAjaxLink("listDetailsLink") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(new LimsVO());
                    try {
                        Biospecimen biospecimenFromDB = iLimsService.getBiospecimen(biospecimen.getId());
                        newModel.getObject().setBiospecimen(biospecimenFromDB);
                        newModel.getObject().setBioCollection(biospecimenFromDB.getBioCollection());
                        newModel.getObject().setTreeModel(cpModel.getObject().getTreeModel());
                        showModalWindow(target, newModel);
                    } catch (EntityNotFoundException e) {
                        log.error(e.getMessage());
                    }
                }
            };

            idLblFld = new Label("biospecimen.id", String.valueOf(biospecimen.getId()));

            nameLblFld = new Label("biospecimen.biospecimenUid", biospecimen.getBiospecimenUid());
            listDetailsLink.add(nameLblFld);
            rowDetailsWMC.add(listDetailsLink);

            studyLblFld = new Label("biospecimen.study.name", biospecimen.getStudy().getName());
            sampleTypeLblFld = new Label("biospecimen.sampleType.name", biospecimen.getSampleType().getName());
            collectionLblFld = new Label("biospecimen.bioCollection.biocollectionUid",
                    biospecimen.getBioCollection().getBiocollectionUid());
            commentsLblFld = new Label("biospecimen.comments", biospecimen.getComments());

            biospecimen.setQuantity(iLimsService.getQuantityAvailable(biospecimen));
            if (biospecimen.getQuantity() == null) {
                quantityLblFld = new Label("biospecimen.quantity", "0");
            } else {
                quantityLblFld = new Label("biospecimen.quantity", biospecimen.getQuantity().toString());
            }
            if (biospecimen.getUnit() == null) {
                unitsLblFld = new Label("biospecimen.unit", "");
            } else {
                unitsLblFld = new Label("biospecimen.unit", biospecimen.getUnit().getName());
            }

            try {
                locationLbl = new Label("biospecimen.location", "view");
                locationLink = new ArkBusyAjaxLink("biospecimen.location.link") {

                    /**
                     * 
                     */
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(
                                new LimsVO());
                        newModel.getObject().getBiospecimen().setId(biospecimen.getId());
                        BiospecimenLocationVO biospecimenLocationVo;
                        try {
                            biospecimenLocationVo = iInventoryService.getBiospecimenLocation(biospecimen);
                            newModel.getObject().setBiospecimenLocationVO(biospecimenLocationVo);
                            newModel.getObject().setTreeModel(cpModel.getObject().getTreeModel());
                            BioLocationPanel bioLocationPanel = new BioLocationPanel("content", newModel) {
                                /**
                                 * 
                                 */
                                private static final long serialVersionUID = 1L;

                                @Override
                                public void refreshParentPanel(AjaxRequestTarget target) {
                                }
                            };
                            bioLocationPanel.getUnallocateButton().setVisible(false);
                            bioLocationPanel.add(new AttributeModifier("class", "detailsPanelBorder"));
                            // Set the modalWindow title and content
                            modalWindow.setTitle("Biospecimen Location Detail");
                            modalWindow.setContent(bioLocationPanel);
                            modalWindow.show(target);
                        } catch (ArkSystemException e) {
                            log.error(e.getMessage());
                        }
                    }
                };

                locationLink.add(locationLbl);

                BiospecimenLocationVO biospecimenLocationVo = iInventoryService
                        .getBiospecimenLocation(biospecimen);
                if (!biospecimenLocationVo.getIsAllocated()) {
                    locationLink.setVisible(false);
                }
            } catch (ArkSystemException e) {
                log.error(e.getMessage());
            }

            item.add(idLblFld);
            item.add(rowDetailsWMC);
            item.add(studyLblFld);
            item.add(sampleTypeLblFld);
            item.add(collectionLblFld);
            //item.add(commentsLblFld);
            item.add(quantityLblFld);
            item.add(unitsLblFld);
            item.add(locationLink);

            if (biospecimen.getBarcoded()) {
                item.addOrReplace(
                        new ContextImage("biospecimen.barcoded", new Model<String>("images/icons/tick.png")));
            } else {
                item.addOrReplace(
                        new ContextImage("biospecimen.barcoded", new Model<String>("images/icons/cross.png")));
            }

            item.add(new AjaxButton("batchAliquot") {

                /**
                 * 
                 */
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isEnabled() {
                    return ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.NEW);
                }

                protected void onSubmit(AjaxRequestTarget target,
                        org.apache.wicket.markup.html.form.Form<?> form) {
                    onBatchAliquot(target, item.getModel());
                    target.add(feedbackPanel);
                };

                protected void onError(AjaxRequestTarget target,
                        org.apache.wicket.markup.html.form.Form<?> form) {
                    target.add(feedbackPanel);
                };

                public boolean isVisible() {
                    SecurityManager securityManager = ThreadContext.getSecurityManager();
                    Subject currentUser = SecurityUtils.getSubject();
                    boolean canCreate = ArkPermissionHelper.hasNewPermission(securityManager, currentUser);
                    boolean validQuantity = (item.getModelObject().getQuantity() != null
                            && item.getModelObject().getQuantity() > 0);
                    return (canCreate && validQuantity);
                };

            }.setDefaultFormProcessing(false));

            item.add(new AjaxButton("allocateUnallocate") {
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isEnabled() {
                    return ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.EDIT);
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

                    BiospecimenLocationVO biospecimenLocationVo = null;
                    try {
                        biospecimenLocationVo = iInventoryService.getBiospecimenLocation(biospecimen);
                    } catch (ArkSystemException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    if (biospecimenLocationVo.getIsAllocated()) {
                        //unallocate
                        InvCell invCell = iInventoryService.getInvCellByBiospecimen(biospecimen);
                        invCell.setBiospecimen(null);
                        invCell.setStatus("Empty");
                        iInventoryService.updateInvCell(invCell);

                        try {
                            cpModel.getObject()
                                    .setBiospecimenLocationVO(iInventoryService.getInvCellLocation(invCell));
                            cpModel.getObject().getBiospecimenLocationVO().setIsAllocated(false);
                            cpModel.getObject().setInvCell(invCell);
                        } catch (ArkSystemException e) {
                        }
                    } else {
                        //cpModel.getObject().setBiospecimen(biospecimen);
                        CompoundPropertyModel<LimsVO> cpm = new CompoundPropertyModel<LimsVO>(new LimsVO());
                        cpm.getObject().setBiospecimen(biospecimen);
                        modalContentPanel = new BioModalAllocateDetailPanel("content", modalWindow, cpm);

                        // Set the modalWindow title and content
                        modalWindow.setTitle("Biospecimen Allocation");
                        modalWindow.setContent(modalContentPanel);
                        modalWindow.setWidthUnit("%");
                        modalWindow.setInitialWidth(70);
                        modalWindow.show(target);
                        //cpModel.getObject().setBiospecimen(new Biospecimen());
                        modalWindow.repaintComponent(BiospecimenListForm.this);

                    }
                    target.add(BiospecimenListForm.this);
                }

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                }

            }.setDefaultFormProcessing(false).setOutputMarkupPlaceholderTag(true));

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() {

                private static final long serialVersionUID = 1L;

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

    };

    return biospecimenDataView;
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.LimsContainerPanel.java

License:Open Source License

private IModel<Set<Object>> newStateModel() {
    return new AbstractReadOnlyModel<Set<Object>>() {
        private static final long serialVersionUID = 1L;

        @Override/*from www  . j ava 2s .  c om*/
        public Set<Object> getObject() {
            return state;
        }

        @Override
        public void detach() {
            ((IDetachable) state).detach();
        }
    };
}

From source file:au.org.theark.lims.web.component.subjectlims.subject.SearchResultListPanel.java

License:Open Source License

public DataView<LinkSubjectStudy> buildDataView(ArkDataProvider2<LimsVO, LinkSubjectStudy> subjectProvider) {

    DataView<LinkSubjectStudy> linkSubjectStudyDataView = new DataView<LinkSubjectStudy>("subjectList",
            subjectProvider) {/*from ww w .j a  va 2s .  co m*/

        @Override
        protected void populateItem(final Item<LinkSubjectStudy> item) {
            LinkSubjectStudy subject = item.getModelObject();
            item.add(buildLink(item.getModelObject()));

            Label studyLbl = new Label("studyLbl", subject.getStudy().getName());
            item.add(studyLbl);

            StringBuffer sb = new StringBuffer();
            String firstName = subject.getPerson().getFirstName();
            String midName = subject.getPerson().getMiddleName();
            String lastName = subject.getPerson().getLastName();

            if (firstName != null) {
                sb.append(subject.getPerson().getFirstName());
                sb.append(" ");
            }
            if (midName != null) {
                sb.append(subject.getPerson().getMiddleName());
                sb.append(" ");
            }
            if (lastName != null) {
                sb.append(subject.getPerson().getLastName());
            }

            item.add(new Label(Constants.SUBJECT_FULL_NAME, sb.toString()));

            item.add(new Label("person.genderType.name", subject.getPerson().getGenderType().getName()));

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(au.org.theark.core.Constants.DD_MM_YYYY);
            String dateOfBirth = "";
            if (subject != null && subject.getPerson() != null
                    && subject.getPerson().getDateOfBirth() != null) {
                dateOfBirth = simpleDateFormat.format(subject.getPerson().getDateOfBirth());
                item.add(new Label("person.dateOfBirth", dateOfBirth));
            } else {
                item.add(new Label("person.dateOfBirth", ""));
            }

            item.add(
                    new Label("person.vitalStatus.statusName", subject.getPerson().getVitalStatus().getName()));

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

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() {
                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? Constants.EVEN : Constants.ODD;
                }
            }));
        }
    };
    return linkSubjectStudyDataView;
}

From source file:au.org.theark.phenotypic.web.component.phenodatacategory.SearchResultListPanel.java

License:Open Source License

public DataView<PhenoDataSetCategory> buildDataView(
        ArkDataProvider2<PhenoDataSetCategory, PhenoDataSetCategory> subjectProvider) {

    DataView<PhenoDataSetCategory> phenoDataSetCategoryDataView = new DataView<PhenoDataSetCategory>(
            "phenoDataSetCategoryList", subjectProvider) {
        @Override//from  w w w.j a v a  2 s .  c  om
        protected void populateItem(final Item<PhenoDataSetCategory> item) {
            PhenoDataSetCategory category = item.getModelObject();
            //id
            if (category.getId() != null) {
                item.add(new Label(Constants.PHENODATASETCATEGORY_ID, category.getId().toString()));
            } else {
                item.add(new Label(Constants.PHENODATASETCATEGORY_ID, ""));
            }
            // Component Name Link
            item.add(buildLinkWMC(item));

            // Description
            if (category.getDescription() != null) {
                item.add(new Label(Constants.PHENODATASETCATEGORY_DESCRIPTION, category.getDescription()));
            } else {
                item.add(new Label(Constants.PHENODATASETCATEGORY_DESCRIPTION, ""));
            }
            /* For the alternative stripes */
            item.add(new AttributeModifier("class", new AbstractReadOnlyModel() {
                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));

        }
    };

    addToolbars(phenoDataSetCategoryDataView);

    return phenoDataSetCategoryDataView;
}

From source file:au.org.theark.phenotypic.web.component.phenodatadictionary.SearchResultListPanel.java

License:Open Source License

public DataView<PhenoDataSetField> buildDataView(
        ArkDataProvider2<PhenoDataSetField, PhenoDataSetField> subjectProvider) {

    DataView<PhenoDataSetField> phonoFieldDataView = new DataView<PhenoDataSetField>("phenoDataSetFieldLst",
            subjectProvider) {/*www.ja  va 2s.  c  om*/

        @Override
        protected void populateItem(final Item<PhenoDataSetField> item) {
            PhenoDataSetField field = item.getModelObject();

            if (field.getId() != null) {
                // Add the id component here
                item.add(new Label(Constants.PHENODATASET_ID, field.getId().toString()));
            } else {
                item.add(new Label(Constants.PHENODATASET_ID, ""));
            }
            // Component Name Link
            item.add(buildLinkWMC(item));
            // Field Type
            if (field.getFieldType() != null) {
                item.add(new Label(Constants.PHENODATASET_FIELD_TYPE, field.getFieldType().getName()));
            } else {
                item.add(new Label(Constants.PHENODATASET_FIELD_TYPE, ""));
            }
            // Field Label
            if (field.getFieldLabel() != null) {
                item.add(new Label(Constants.PHENODATASET_FIELD_LABEL, field.getFieldLabel()));
            } else {
                item.add(new Label(Constants.PHENODATASET_FIELD_LABEL, ""));
            }
            if (field.getDefaultValue() != null) {
                item.add(new Label(Constants.PHENODATASET_DEFAULT_VALUE, field.getDefaultValue()));
            } else {
                item.add(new Label(Constants.PHENODATASET_DEFAULT_VALUE, ""));
            }
            if (field.getMissingValue() != null) {
                item.add(new Label(Constants.PHENODATASET_MISSING_VALUE, field.getMissingValue()));
            } else {
                item.add(new Label(Constants.PHENODATASET_MISSING_VALUE, ""));
            }
            if (field.getRequired() != null && field.getRequired() == true) {
                item.add(new ContextImage(Constants.PHENODATASET_REQUIRED,
                        new Model<String>("images/icons/tick.png")));
            } else {
                item.add(new ContextImage(Constants.PHENODATASET_REQUIRED,
                        new Model<String>("images/icons/cross.png")));
            }

            /* For the alternative stripes */
            item.add(new AttributeModifier("class", new AbstractReadOnlyModel() {
                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? "even" : "odd";
                }
            }));

        }
    };

    addToolbars(phonoFieldDataView);

    return phonoFieldDataView;
}