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

License:Open Source License

public DataView<DiseaseVO> buildDataView(ArkDataProvider<DiseaseVO, IArkDiseaseService> diseaseProvider) {

    DataView<DiseaseVO> studyCompDataView = new DataView<DiseaseVO>("diseaseList", diseaseProvider) {

        @Override/*  ww w .  ja va  2s . c om*/
        protected void populateItem(final Item<DiseaseVO> item) {
            Disease disease = item.getModelObject().getDisease();
            item.add(new Label("disease.id", disease.getId().toString()));
            item.add(buildLink(item.getModelObject()));

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

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

License:Open Source License

public PageableListView<DiseaseVO> buildListView(IModel iModel) {

    PageableListView<DiseaseVO> listView = new PageableListView<DiseaseVO>("diseaseList", iModel,
            iArkCommonService.getUserConfig(Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        @Override/*from w w w.  j  a  va2s  .  co  m*/
        protected void populateItem(final ListItem<DiseaseVO> item) {
            Disease disease = item.getModelObject().getDisease();

            item.add(new Label("disease.id", disease.getId().toString()));
            item.add(buildLink(item.getModelObject()));

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

From source file:au.org.theark.disease.web.component.gene.SearchResultListPanel.java

License:Open Source License

public DataView<GeneVO> buildDataView(ArkDataProvider<GeneVO, IArkDiseaseService> diseaseProvider) {

    DataView<GeneVO> studyCompDataView = new DataView<GeneVO>("diseaseList", diseaseProvider) {

        @Override//  w w w.j av  a 2 s  .com
        protected void populateItem(final Item<GeneVO> item) {
            Gene gene = item.getModelObject().getGene();

            item.add(new Label("gene.id", gene.getId().toString()));

            item.add(buildLink(item.getModelObject()));

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

From source file:au.org.theark.disease.web.component.gene.SearchResultListPanel.java

License:Open Source License

public PageableListView<GeneVO> buildListView(IModel iModel) {

    PageableListView<GeneVO> listView = new PageableListView<GeneVO>("diseaseList", iModel,
            iArkCommonService.getUserConfig(Constants.CONFIG_ROWS_PER_PAGE).getIntValue()) {

        @Override//from   ww w.  ja  v a2  s .  c  om
        protected void populateItem(final ListItem<GeneVO> item) {

            Gene gene = item.getModelObject().getGene();

            item.add(new Label("gene.id", gene.getId().toString()));

            item.add(buildLink(item.getModelObject()));

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

From source file:au.org.theark.lims.web.component.barcodelabel.SearchResultsPanel.java

License:Open Source License

public DataView<BarcodeLabel> buildDataView(ArkDataProvider<BarcodeLabel, ILimsAdminService> dataProvider) {
    DataView<BarcodeLabel> dataView = new DataView<BarcodeLabel>("resultList", dataProvider) {

        private static final long serialVersionUID = 2981419595326128410L;

        @Override//  w  ww . ja  va2  s.  c  o m
        protected void populateItem(final Item<BarcodeLabel> item) {
            BarcodeLabel barcodeLabel = item.getModelObject();

            item.add(buildLink(barcodeLabel));

            if (barcodeLabel.getStudy() != null) {
                // the ID here must match the ones in mark-up
                item.add(new Label("study", barcodeLabel.getStudy().getName()));
            } else {
                item.add(new Label("study", ""));
            }

            if (barcodeLabel.getName() != null) {
                // the ID here must match the ones in mark-up
                item.add(new Label("name", barcodeLabel.getName()));
            } else {
                item.add(new Label("name", ""));
            }

            if (barcodeLabel.getBarcodePrinterName() != null) {
                // the ID here must match the ones in mark-up
                item.add(new Label("barcodePrinter", barcodeLabel.getBarcodePrinterName()));
            } else {
                item.add(new Label("barcodePrinter", ""));
            }

            if (barcodeLabel.getDescription() != null) {
                // the ID here must match the ones in mark-up
                item.add(new Label("description", barcodeLabel.getDescription()));
            } else {
                item.add(new Label("description", ""));
            }

            if (barcodeLabel.getVersion() != null) {
                item.add(new Label("version", barcodeLabel.getVersion().toString()));
            } else {
                item.add(new Label("version", ""));
            }

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

From source file:au.org.theark.lims.web.component.biospecimen.batchaliquot.form.BatchAliquotBiospecimenForm.java

License:Open Source License

/**
 * // ww  w .j  av a 2s .co  m
 * @return the listEditor of Biospecimens to aliquot
 */
public AbstractListEditor<Biospecimen> buildListEditor() {
    listEditor = new AbstractListEditor<Biospecimen>("aliquots",
            new PropertyModel(getModelObject(), "aliquots")) {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("serial")
        @Override
        protected void onPopulateItem(final ListItem<Biospecimen> item) {
            item.setOutputMarkupId(true);

            Biospecimen parentBiospecimen = BatchAliquotBiospecimenForm.this.getModelObject()
                    .getParentBiospecimen();
            try {
                PropertyUtils.copyProperties(item.getModelObject(), parentBiospecimen);
            } catch (IllegalAccessException e1) {
                log.error(e1.getMessage());
            } catch (InvocationTargetException e1) {
                log.error(e1.getMessage());
            } catch (NoSuchMethodException e1) {
                log.error(e1.getMessage());
            }

            if (copyBiospecimen) {
                item.getModelObject().setParent(parentBiospecimen);
                item.getModelObject().setParentUid(parentBiospecimen.getBiospecimenUid());
                item.getModelObject().setQuantity(biospecimenToCopy.getQuantity());
                item.getModelObject().setTreatmentType(biospecimenToCopy.getTreatmentType());
                item.getModelObject().setConcentration(biospecimenToCopy.getConcentration());
            } else {
                item.getModelObject().setParent(parentBiospecimen);
                item.getModelObject().setParentUid(parentBiospecimen.getBiospecimenUid());
                item.getModelObject().setQuantity(null);
                item.getModelObject().setConcentration(null);
            }

            biospecimenUidTxtFld = new TextField<String>("biospecimenUid",
                    new PropertyModel(item.getModelObject(), "biospecimenUid"));
            if (parentBiospecimen.getStudy().getAutoGenerateBiospecimenUid()) {
                biospecimenUidTxtFld.setEnabled(false);
                biospecimenUidTxtFld.setModelObject(Constants.AUTO_GENERATED);
            } else {
                biospecimenUidTxtFld.setEnabled(true);
                biospecimenUidTxtFld.setModelObject(null);
            }

            quantityTxtFld = new TextField<Double>("quantity",
                    new PropertyModel(item.getModelObject(), "quantity")) {
                private static final long serialVersionUID = 1L;

                @Override
                public <C> IConverter<C> getConverter(Class<C> type) {
                    DoubleConverter doubleConverter = new DoubleConverter();
                    NumberFormat numberFormat = NumberFormat.getInstance();
                    numberFormat.setMinimumFractionDigits(1);
                    doubleConverter.setNumberFormat(getLocale(), numberFormat);
                    return (IConverter<C>) doubleConverter;
                }
            };

            initTreatmentTypeDdc(item);
            concentrationTxtFld = new TextField<Number>("concentration",
                    new PropertyModel(item.getModelObject(), "concentration"));

            item.add(biospecimenUidTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    if (!item.getModelObject().getStudy().getAutoGenerateBiospecimenUid()) {
                        // Check BiospecimenUID is unique
                        String biospecimenUid = (getComponent().getDefaultModelObject().toString() != null
                                ? getComponent().getDefaultModelObject().toString()
                                : new String());
                        Biospecimen biospecimen = iLimsService.getBiospecimenByUid(biospecimenUid,
                                item.getModelObject().getStudy());
                        if (biospecimen != null && biospecimen.getId() != null) {
                            error("Biospecimen UID must be unique. Please try again.");
                            target.focusComponent(getComponent());
                        }
                    }
                    target.add(feedbackPanel);
                    biospecimenToCopy.setBiospecimenUid(getComponent().getDefaultModelObject().toString());
                }
            }));

            item.add(quantityTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    if (!totalQuantityLessThanParentQuantity()) {
                        target.focusComponent(getComponent());
                    }
                    target.add(feedbackPanel);
                    biospecimenToCopy.setQuantity((Double) getComponent().getDefaultModelObject());
                    item.getModelObject().setQuantity((Double) getComponent().getDefaultModelObject());
                }

                @Override
                protected void onError(AjaxRequestTarget target, RuntimeException e) {
                    target.add(feedbackPanel);
                }
            }));
            item.add(treatmentTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    biospecimenToCopy.setTreatmentType((TreatmentType) getComponent().getDefaultModelObject());
                    item.getModelObject()
                            .setTreatmentType((TreatmentType) getComponent().getDefaultModelObject());
                }
            }));
            item.add(concentrationTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    biospecimenToCopy.setConcentration((Double) getComponent().getDefaultModelObject());
                    item.getModelObject().setConcentration((Double) getComponent().getDefaultModelObject());
                }
            }));

            // Copy button allows entire row details to be copied
            item.add(new AjaxEditorButton(Constants.COPY) {
                private static final long serialVersionUID = 1L;

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

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    Biospecimen biospecimen = new Biospecimen();
                    copyBiospecimen = true;
                    try {
                        PropertyUtils.copyProperties(biospecimen, getItem().getModelObject());
                        PropertyUtils.copyProperties(biospecimenToCopy, getItem().getModelObject());
                        listEditor.addItem(biospecimen);
                        target.add(form);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                }
            }.setDefaultFormProcessing(false));

            item.add(new AjaxEditorButton(Constants.DELETE) {
                private static final long serialVersionUID = 1L;

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

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    listEditor.removeItem(item);
                    target.add(form);
                }
            }.setDefaultFormProcessing(false).setVisible(item.getIndex() > 0));

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

From source file:au.org.theark.lims.web.component.biospecimen.batchcreate.form.AutoGenBatchCreateBiospecimenForm.java

License:Open Source License

/**
 * /*from www.  j a  v  a  2 s  . com*/
 * @return the listEditor of BatchBiospecimen(s)
 */
public AbstractListEditor<BatchBiospecimenVO> buildListEditor() {
    listEditor = new AbstractListEditor<BatchBiospecimenVO>("batchBiospecimenList",
            new PropertyModel(this, "batchBiospecimenList")) {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("serial")
        @Override
        protected void onPopulateItem(final ListItem<BatchBiospecimenVO> item) {
            item.setOutputMarkupId(true);
            item.getModelObject().getBiospecimen()
                    .setLinkSubjectStudy(cpModel.getObject().getLinkSubjectStudy());
            item.getModelObject().getBiospecimen()
                    .setStudy(cpModel.getObject().getLinkSubjectStudy().getStudy());

            numberToCreateTxtFld = new TextField<Number>("numberToCreate",
                    new PropertyModel(item.getModelObject(), "numberToCreate"));

            initBioCollectionDdc(item);
            initSampleTypeDdc(item);

            sampleDateTxtFld = new DateTextField("biospecimen.sampleDate",
                    new PropertyModel(item.getModelObject(), "biospecimen.sampleDate"),
                    au.org.theark.core.Constants.DD_MM_YYYY);
            ArkDatePicker sampleDatePicker = new ArkDatePicker();
            sampleDatePicker.bind(sampleDateTxtFld);
            sampleDateTxtFld.add(sampleDatePicker);

            quantityTxtFld = new TextField<Double>("biospecimen.quantity",
                    new PropertyModel(item.getModelObject(), "biospecimen.quantity")) {
                private static final long serialVersionUID = 1L;

                @Override
                public <C> IConverter<C> getConverter(Class<C> type) {
                    DoubleConverter doubleConverter = new DoubleConverter();
                    NumberFormat numberFormat = NumberFormat.getInstance();
                    numberFormat.setMinimumFractionDigits(1);
                    doubleConverter.setNumberFormat(getLocale(), numberFormat);
                    return (IConverter<C>) doubleConverter;
                }
            };
            initUnitDdc(item);
            initTreatmentTypeDdc(item);
            concentrationTxtFld = new TextField<Number>("biospecimen.concentration",
                    new PropertyModel(item.getModelObject(), "biospecimen.concentration"));

            // Added onchange events to ensure model updated when any change made
            item.add(numberToCreateTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(bioCollectionDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(sampleTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(sampleDateTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(quantityTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(unitDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(treatmentTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(concentrationTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));

            // Copy button allows entire row details to be copied
            item.add(new AjaxEditorButton(Constants.COPY) {
                private static final long serialVersionUID = 1L;

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

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    BatchBiospecimenVO batchBiospecimenVo = new BatchBiospecimenVO();
                    try {
                        batchBiospecimenVo.setNumberToCreate(item.getModelObject().getNumberToCreate());
                        PropertyUtils.copyProperties(batchBiospecimenVo.getBiospecimen(),
                                item.getModelObject().getBiospecimen());
                        listEditor.addItem(batchBiospecimenVo);
                        target.add(form);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                }
            }.setDefaultFormProcessing(false));

            item.add(new AjaxEditorButton(Constants.DELETE) {
                private static final long serialVersionUID = 1L;

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

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    listEditor.removeItem(item);
                    target.add(form);
                }
            }.setDefaultFormProcessing(false).setVisible(item.getIndex() > 0));

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

From source file:au.org.theark.lims.web.component.biospecimen.batchcreate.form.ManualBatchCreateBiospecimenForm.java

License:Open Source License

/**
 * /*from www  .ja  v  a  2  s . c  o  m*/
 * @return the listEditor of BatchBiospecimen(s)
 */
public AbstractListEditor<BatchBiospecimenVO> buildListEditor() {
    listEditor = new AbstractListEditor<BatchBiospecimenVO>("batchBiospecimenList",
            new PropertyModel(this, "batchBiospecimenList")) {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("serial")
        @Override
        protected void onPopulateItem(final ListItem<BatchBiospecimenVO> item) {
            item.setOutputMarkupId(true);
            item.getModelObject().getBiospecimen()
                    .setLinkSubjectStudy(cpModel.getObject().getLinkSubjectStudy());
            item.getModelObject().getBiospecimen()
                    .setStudy(cpModel.getObject().getLinkSubjectStudy().getStudy());

            biospecimenUidTxtFld = new TextField<String>("biospecimen.biospecimenUid",
                    new PropertyModel(item.getModelObject(), "biospecimen.biospecimenUid"));

            initBioCollectionDdc(item);
            initSampleTypeDdc(item);

            sampleDateTxtFld = new DateTextField("biospecimen.sampleDate",
                    new PropertyModel(item.getModelObject(), "biospecimen.sampleDate"),
                    au.org.theark.core.Constants.DD_MM_YYYY);
            ArkDatePicker sampleDatePicker = new ArkDatePicker();
            sampleDatePicker.bind(sampleDateTxtFld);
            sampleDateTxtFld.add(sampleDatePicker);

            quantityTxtFld = new TextField<Double>("biospecimen.quantity",
                    new PropertyModel(item.getModelObject(), "biospecimen.quantity")) {
                private static final long serialVersionUID = 1L;

                @Override
                public <C> IConverter<C> getConverter(Class<C> type) {
                    DoubleConverter doubleConverter = new DoubleConverter();
                    NumberFormat numberFormat = NumberFormat.getInstance();
                    numberFormat.setMinimumFractionDigits(1);
                    doubleConverter.setNumberFormat(getLocale(), numberFormat);
                    return (IConverter<C>) doubleConverter;
                }
            };
            initUnitDdc(item);
            initTreatmentTypeDdc(item);

            concentrationTxtFld = new TextField<Number>("biospecimen.concentration",
                    new PropertyModel(item.getModelObject(), "biospecimen.concentration"));

            // Added onchange events to ensure model updated when any change made
            item.add(biospecimenUidTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    // Check BiospecimenUID is unique
                    String biospecimenUid = (getComponent().getDefaultModelObject().toString() != null
                            ? getComponent().getDefaultModelObject().toString()
                            : new String());
                    Biospecimen biospecimen = iLimsService.getBiospecimenByUid(biospecimenUid,
                            item.getModelObject().getBiospecimen().getStudy());
                    if (biospecimen != null && biospecimen.getId() != null) {
                        ManualBatchCreateBiospecimenForm.this
                                .error("Biospecimen UID must be unique. Please try again.");
                        target.focusComponent(getComponent());
                    }
                    target.add(feedbackPanel);
                }
            }));

            item.add(bioCollectionDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(sampleTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(sampleDateTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(quantityTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(unitDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(treatmentTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(concentrationTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));

            // Copy button allows entire row details to be copied
            item.add(new AjaxEditorButton(Constants.COPY) {
                private static final long serialVersionUID = 1L;

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

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    BatchBiospecimenVO batchBiospecimenVo = new BatchBiospecimenVO();
                    try {
                        PropertyUtils.copyProperties(batchBiospecimenVo.getBiospecimen(),
                                item.getModelObject().getBiospecimen());
                        batchBiospecimenVo.getBiospecimen().setBiospecimenUid(new String());
                        listEditor.addItem(batchBiospecimenVo);
                        target.add(form);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                }
            }.setDefaultFormProcessing(false));

            item.add(new AjaxEditorButton(Constants.DELETE) {
                private static final long serialVersionUID = 1L;

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

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    listEditor.removeItem(item);
                    target.add(form);
                }
            }.setDefaultFormProcessing(false).setVisible(item.getIndex() > 0));

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

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

License:Open Source License

/**
 * /*from  w  ww. j  a  v a2s. 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());
                        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().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.biospecimenuidtemplate.SearchResultsPanel.java

License:Open Source License

public DataView<BiospecimenUidTemplate> buildDataView(
        ArkDataProvider<BiospecimenUidTemplate, ILimsAdminService> dataProvider) {
    DataView<BiospecimenUidTemplate> dataView = new DataView<BiospecimenUidTemplate>("resultList",
            dataProvider) {/*www  . jav  a 2s .  com*/

        private static final long serialVersionUID = 2981419595326128410L;

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

            item.add(buildLink(biospecimenUidTemplate));
            item.add(new Label("study", biospecimenUidTemplate.getStudy().getName()));
            item.add(new Label("biospecimenUid.template", getBiospecimenUidExample(biospecimenUidTemplate)));
            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 dataView;
}