Example usage for org.apache.wicket.markup.html.form Form getParent

List of usage examples for org.apache.wicket.markup.html.form Form getParent

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form getParent.

Prototype

@Override
public final MarkupContainer getParent() 

Source Link

Document

Gets any parent container, or null if there is none.

Usage

From source file:au.org.theark.lims.web.component.biotransaction.form.BioTransactionListForm.java

License:Open Source License

private void initSaveButton() {
    saveButton = new ArkBusyAjaxButton("saveButton") {
        private static final long serialVersionUID = 1L;

        @Override/*from  w ww.  ja  v a  2  s. c o  m*/
        public boolean isVisible() {
            return true;
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // Set defaults
            //cpModel.getObject().getBioTransaction().setTransactionDate(new Date());
            cpModel.getObject().getBioTransaction()
                    .setRecorder(SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal().toString());

            Double qtyAvail = iLimsService.getQuantityAvailable(cpModel.getObject().getBiospecimen());
            Double txnQuantity = cpModel.getObject().getBioTransaction().getQuantity();

            if (txnQuantity == null) {
                error("Field 'Quantity' is required");
                target.add(feedbackPanel);
            } else if (cpModel.getObject().getBioTransaction().getStatus() == null) {
                error("Field 'Status' is required");
                target.add(feedbackPanel);
            } else {
                // Make quantity minus if positive and Aliquoted, Processed or   Delivered
                String status = cpModel.getObject().getBioTransaction().getStatus().getName();
                if (status != null
                        && (status.equalsIgnoreCase("Aliquoted") || status.equalsIgnoreCase("Processed")
                                || status.equalsIgnoreCase("Delivered"))
                        && txnQuantity != null && txnQuantity > 0) {
                    txnQuantity = (-1 * txnQuantity);
                    cpModel.getObject().getBioTransaction().setQuantity(txnQuantity);
                }

                // Check that quantity specified not greater than available
                if (txnQuantity < 0 && (Math.abs(txnQuantity) > (qtyAvail == null ? 0 : qtyAvail))) {
                    error("When aliquoting, processing or delivering, transaction quantity may not exceed total quantity available.");
                    target.add(feedbackPanel);
                } else {
                    cpModel.getObject().getBioTransaction()
                            .setUnit(cpModel.getObject().getBiospecimen().getUnit()); //TODO: Unit
                    iLimsService.createBioTransaction(cpModel.getObject());
                    info("Transaction saved successfully");

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

                    // refresh transaction form
                    BioTransaction bioTransaction = new BioTransaction();
                    bioTransaction.setBiospecimen(cpModel.getObject().getBiospecimen());
                    bioTransaction.setUnit(cpModel.getObject().getBiospecimen().getUnit()); //TODO: Unit
                    cpModel.getObject().setBioTransaction(bioTransaction);

                    target.add(form.getParent().getParent());
                    target.add(feedbackPanel);
                }
            }
        }

        //         @Override
        //         public boolean isEnabled() {
        //            Biospecimen b = cpModel.getObject().getBiospecimen();
        //            if(b==null){
        //               return false;
        //            }
        //            Double qa = iLimsService.getQuantityAvailable(b);
        //            return (qa != null && qa > 0);
        //         }

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

From source file:org.sakaiproject.sitestats.tool.wicket.components.useractivity.EventRefDetailsButtonPanel.java

License:Educational Community License

@Override
protected void onInitialize() {
    super.onInitialize();

    Form<Void> form = new Form<>("moreDetailsForm");
    SakaiAjaxButton button = new SakaiAjaxButton("moreDetailsButton", form) {
        @Override//from   w w  w.j a  v a  2s. c  om
        public void onSubmit(AjaxRequestTarget target, Form form) {
            if (target != null) {
                DetailedEvent de = EventRefDetailsButtonPanel.this.getModelObject();
                EventRefDetailsPanel panel = new EventRefDetailsPanel("details", de.getEventId(),
                        de.getEventRef(), siteID);
                panel.setOutputMarkupId(true);
                form.getParent().replace(panel);
                target.add(panel);
                setVisible(false);
                target.add(this);
                target.prependJavaScript(
                        String.format("$('#%s').closest('td').removeAttr('data-label');", getMarkupId()));
            }
        }
    };
    form.add(button);
    add(form);

    add(new WebMarkupContainer("details").setOutputMarkupPlaceholderTag(true));
}