Example usage for org.apache.wicket.ajax AjaxRequestTarget add

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget add

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget add.

Prototype

void add(Component... components);

Source Link

Document

Adds components to the list of components to be rendered.

Usage

From source file:au.org.theark.lims.web.component.biospecimencustomdata.form.CustomDataEditorForm.java

License:Open Source License

public void onEditSave(AjaxRequestTarget target, Form<?> form) {
    List<BiospecimenCustomFieldData> errorList = iLimsService
            .createOrUpdateBiospecimenCustomFieldData(cpModel.getObject().getCustomFieldDataList());
    if (errorList.size() > 0) {
        for (BiospecimenCustomFieldData biospecimenCustomFieldData : errorList) {
            CustomField cf = biospecimenCustomFieldData.getCustomFieldDisplay().getCustomField();
            String fieldType = cf.getFieldType().getName();
            if (fieldType.equals(au.org.theark.core.web.component.customfield.Constants.DATE_FIELD_TYPE_NAME)) {
                this.error("Unable to save this data: " + cf.getFieldLabel() + " = "
                        + biospecimenCustomFieldData.getDateDataValue());
            } else {
                this.error("Unable to save this data: " + cf.getFieldLabel() + " = "
                        + biospecimenCustomFieldData.getTextDataValue());
            }//from  w ww.  j a  v  a  2  s.  c o  m
        }
    } else {
        this.info("Successfully saved all edits");
    }
    /*
     * Need to update the dataView, which forces a refresh of the model objects from backend. This is because deleted fields still remain in the
     * model, and are stale objects if we try to use them for future saves.
     */
    target.add(dataViewWMC);
    target.add(feedbackPanel);
}

From source file:au.org.theark.lims.web.component.biospecimenuidtemplate.form.DetailForm.java

License:Open Source License

public void initialiseDetailForm() {
    idTxtFld = new TextField<Long>("id");

    initStudyDdc();//from w  w w. j  a v  a  2 s  .c  om
    biospecimenUidPrefixTxtFld = new TextField<String>("biospecimenUidPrefix");
    biospecimenUidPrefixTxtFld.add(new AjaxFormComponentUpdatingBehavior("onChange") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(biospecimenUidExampleLbl);
        }
    });

    initBiospecimenUidTokenDdc();
    initBiospecimenUidPadCharDdc();

    biospecimenUidExampleLbl = new Label("biospecimenUid.example", biospecimenUidExampleModel);
    biospecimenUidExampleLbl.setOutputMarkupId(true);

    addDetailFormComponents();
    attachValidators();
}

From source file:au.org.theark.lims.web.component.biospecimenuidtemplate.form.DetailForm.java

License:Open Source License

private void initBiospecimenUidTokenDdc() {
    List<BiospecimenUidToken> biospecimenUidTokens = new ArrayList<BiospecimenUidToken>(0);
    biospecimenUidTokens = iLimsAdminService.getBiospecimenUidTokens();
    ChoiceRenderer<BiospecimenUidToken> choiceRenderer = new ChoiceRenderer<BiospecimenUidToken>(Constants.NAME,
            Constants.ID);//from w  ww.  j a va2s.  c  o m
    biospecimenUidTokenDdc = new DropDownChoice<BiospecimenUidToken>("biospecimenUidToken",
            biospecimenUidTokens, choiceRenderer);
    biospecimenUidTokenDdc.add(new AjaxFormComponentUpdatingBehavior("onChange") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(biospecimenUidExampleLbl);
        }
    });
    biospecimenUidTokenDdc.setNullValid(true);
}

From source file:au.org.theark.lims.web.component.biospecimenuidtemplate.form.DetailForm.java

License:Open Source License

private void initBiospecimenUidPadCharDdc() {
    List<BiospecimenUidPadChar> biospecimenUidPadChars = new ArrayList<BiospecimenUidPadChar>(0);
    biospecimenUidPadChars = iLimsAdminService.getBiospecimenUidPadChars();
    ChoiceRenderer<BiospecimenUidPadChar> choiceRenderer = new ChoiceRenderer<BiospecimenUidPadChar>(
            Constants.NAME, Constants.ID);
    biospecimenUidPadCharDdc = new DropDownChoice<BiospecimenUidPadChar>("biospecimenUidPadChar",
            biospecimenUidPadChars, choiceRenderer);
    biospecimenUidPadCharDdc.add(new AjaxFormComponentUpdatingBehavior("onChange") {

        private static final long serialVersionUID = 1L;

        @Override/* www.j a  va2  s .  c  o  m*/
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(biospecimenUidExampleLbl);
        }
    });
}

From source file:au.org.theark.lims.web.component.biospecimenuidtemplate.form.DetailForm.java

License:Open Source License

@Override
protected void onSave(Form<BiospecimenUidTemplate> containerForm, AjaxRequestTarget target) {
    if (isNew()) {
        iLimsAdminService.createBiospecimenUidTemplate(containerForm.getModelObject());
    } else {//from  w  w w .j a va2s.c  o  m
        iLimsAdminService.updateBiospecimenUidTemplate(containerForm.getModelObject());
    }
    this.info("BiospecimenUID template was created/updated successfully.");
    onSavePostProcess(target);
    target.add(feedBackPanel);
}

From source file:au.org.theark.lims.web.component.biospecimenuidtemplate.form.SearchForm.java

License:Open Source License

@Override
protected void onSearch(AjaxRequestTarget target) {
    target.add(feedbackPanel);
    long count = iLimsAdminService.getBiospecimenUidTemplateCount(getModelObject());
    if (count == 0L) {
        this.info("There are no records that matched your query. Please modify your filter");
        target.add(feedbackPanel);/*from  www .ja v a 2  s .  co m*/
    }

    arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true);
    target.add(arkCrudContainerVO.getSearchResultPanelContainer());
}

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

License:Open Source License

private AjaxLink<String> buildLink(final BiospecimenUidTemplate BiospecimenUidTemplate) {
    ArkBusyAjaxLink<String> link = new ArkBusyAjaxLink<String>("link") {

        private static final long serialVersionUID = 1L;

        @Override/*from ww  w. j av  a 2s.c o  m*/
        public void onClick(AjaxRequestTarget target) {
            BiospecimenUidTemplate BiospecimenUidTemplateFromDb = iLimsAdminService
                    .searchBiospecimenUidTemplate(BiospecimenUidTemplate);
            containerForm.setModelObject(BiospecimenUidTemplateFromDb);
            ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, arkCrudContainerVo);
            // Refresh base container form to remove any feedBack messages
            target.add(containerForm);
        }
    };

    // Add the label for the link
    Label linkLabel = new Label("id", BiospecimenUidTemplate.getId().toString());
    link.add(linkLabel);
    return link;
}

From source file:au.org.theark.lims.web.component.biospecimenupload.BiospecimenUploadStep2.java

License:Open Source License

@Override
public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    try {/*w  ww. j a  v  a  2  s  . c  om*/
        InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream();
        FileUpload fileUpload = containerForm.getModelObject().getFileUpload();
        String uploadType = containerForm.getModelObject().getUploadType();
        log.info("so what is the upload type =" + uploadType);

        String filename = containerForm.getModelObject().getFileUpload().getClientFileName();
        String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase();
        char delimChar = containerForm.getModelObject().getUpload().getDelimiterType().getDelimiterCharacter();

        // Only allow csv, txt or xls
        if (!(fileFormat.equalsIgnoreCase("CSV") || fileFormat.equalsIgnoreCase("TXT")
                || fileFormat.equalsIgnoreCase("XLS"))) {
            throw new FileFormatException();
        }
        BioCollectionSpecimenUploadValidator bioCollectionSpecimenUploadValidator = new BioCollectionSpecimenUploadValidator(
                containerForm.getModelObject().getUpload().getStudy(), iArkCommonService, iLimsService,
                iInventoryService);
        if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOCOLLECTION)) {
            validationMessages = bioCollectionSpecimenUploadValidator.validateLimsFileFormatAndHeaderDetail(
                    containerForm.getModelObject(), au.org.theark.core.Constants.BIOCOLLECTION_TEMPLATE_HEADER);
        } else if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOSPECIMEN_INVENTARY)) {
            validationMessages = bioCollectionSpecimenUploadValidator.validateLimsFileFormatAndHeaderDetail(
                    containerForm.getModelObject(),
                    au.org.theark.core.Constants.BIOSPECIMEN_INVENTORY_TEMPLATE_HEADER);
        } else if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOSPECIMEN)) {
            validationMessages = bioCollectionSpecimenUploadValidator.validateLimsFileFormatAndHeaderDetail(
                    containerForm.getModelObject(), au.org.theark.core.Constants.BIOSPECIMEN_TEMPLATE_HEADER);
        }

        containerForm.getModelObject().setValidationMessages(validationMessages);
        validationMessage = containerForm.getModelObject().getValidationMessagesAsString();
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));

        ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView", inputStream,
                fileFormat, delimChar, fileUpload, iArkCommonService
                        .getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue());
        arkExcelWorkSheetAsGrid.setOutputMarkupId(true);
        WebMarkupContainer wizardDataGridKeyContainer = new WebMarkupContainer("wizardDataGridKeyContainer");
        wizardDataGridKeyContainer.setVisible(false);
        wizardDataGridKeyContainer.setOutputMarkupId(true);
        form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
        form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid);
        form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
        form.getWizardPanelFormContainer().addOrReplace(wizardDataGridKeyContainer);
        target.add(form.getWizardPanelFormContainer());

        containerForm.getModelObject().setValidationMessages(validationMessages);
        validationMessage = containerForm.getModelObject().getValidationMessagesAsString();
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));

        if (validationMessage != null && validationMessage.length() > 0) {

            this.containerForm.getModelObject().getUpload()
                    .setUploadStatus(iArkCommonService.getUploadStatusFor(
                            au.org.theark.lims.web.Constants.UPLOAD_STATUS_OF_ERROR_IN_FILE_VALIDATION));
            this.containerForm.getModelObject().getUpload().setFilename(filename);//have to reset this because the container has the file name...luckily it never changes 
            iArkCommonService.updateUpload(this.containerForm.getModelObject().getUpload());

            form.getNextButton().setEnabled(false);
            target.add(form.getWizardButtonContainer());
            downloadValMsgButton = new ArkDownloadAjaxButton("downloadValMsg", "ValidationMessage",
                    validationMessage, "txt") {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    this.error("Unexpected Error: Download request could not be processed");
                }

            };
            addOrReplace(downloadValMsgButton);
            target.add(downloadValMsgButton);
        }
    } catch (IOException e) {
        validationMessage = "Error attempting to display the file. Please check the file and try again.";
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
    } catch (FileFormatException ffe) {
        validationMessage = "Error uploading file. You can only upload files of type: CSV (comma separated values), TXT (text), or XLS (Microsoft Excel file)";
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
    }
}

From source file:au.org.theark.lims.web.component.biospecimenupload.BiospecimenUploadStep3.java

License:Open Source License

private void initialiseDetailForm() {
    setValidationMessage(containerForm.getModelObject().getValidationMessagesAsString());
    addOrReplace(new MultiLineLabel("multiLineLabel", getValidationMessage()));
    add(downloadValMsgButton);//from   w w w . j  a  va 2 s  . com

    updateExistingDataContainer = new WebMarkupContainer("updateExistingDataContainer");
    updateExistingDataContainer.setOutputMarkupId(true);
    updateChkBox = new CheckBox("updateChkBox");
    updateChkBox.setVisible(true);

    updateChkBox.add(new AjaxFormComponentUpdatingBehavior("onChange") {

        private static final long serialVersionUID = -4514605801401294450L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (containerForm.getModelObject().getUpdateChkBox()) {
                wizardForm.getNextButton().setEnabled(true);
            } else {
                wizardForm.getNextButton().setEnabled(false);
            }
            target.add(wizardForm.getWizardButtonContainer());
        }
    });

    updateExistingDataContainer.add(updateChkBox);
    add(updateExistingDataContainer);
}

From source file:au.org.theark.lims.web.component.biospecimenupload.BiospecimenUploadStep3.java

License:Open Source License

@Override
public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    try {/*  w  w  w  . ja v a 2s. c  o  m*/
        String filename = containerForm.getModelObject().getFileUpload().getClientFileName();
        String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase();
        char delimiterChar = containerForm.getModelObject().getUpload().getDelimiterType()
                .getDelimiterCharacter();
        InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream();
        String uploadType = containerForm.getModelObject().getUploadType();

        BioCollectionSpecimenUploadValidator biospecimenUploadValidator = new BioCollectionSpecimenUploadValidator(
                containerForm.getModelObject().getUpload().getStudy(), iArkCommonService, iLimsService,
                iInventoryService);
        log.info("upload type ---=" + uploadType);

        if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOCOLLECTION)) {
            validationMessages = biospecimenUploadValidator
                    .validateBiocollectionFileData(containerForm.getModelObject());
        } else if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOSPECIMEN_INVENTARY)) {
            validationMessages = biospecimenUploadValidator
                    .validateBiospecimenInvetoryFileData(containerForm.getModelObject());
        } else if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOSPECIMEN)) {
            validationMessages = biospecimenUploadValidator
                    .validateBiospecimenFileData(containerForm.getModelObject());
        }
        this.containerForm.getModelObject().setValidationMessages(validationMessages);
        validationMessage = containerForm.getModelObject().getValidationMessagesAsString();
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));

        HashSet<Integer> insertRows = new HashSet<Integer>();
        HashSet<Integer> updateRows = new HashSet<Integer>();
        HashSet<ArkGridCell> errorCells = new HashSet<ArkGridCell>();

        insertRows = biospecimenUploadValidator.getInsertRows();
        updateRows = biospecimenUploadValidator.getUpdateRows();
        errorCells = biospecimenUploadValidator.getErrorCells();

        // Show file data (and key reference)
        ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView", inputStream,
                fileFormat, delimiterChar, containerForm.getModelObject().getFileUpload(), insertRows,
                updateRows, errorCells);
        arkExcelWorkSheetAsGrid.setOutputMarkupId(true);
        arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer().setVisible(true);
        form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
        form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid);

        // Repaint
        target.add(arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer());
        target.add(form.getWizardPanelFormContainer());

        if (updateRows.isEmpty()) {
            updateExistingDataContainer.setVisible(false);
            target.add(updateExistingDataContainer);
        }

        if (!errorCells.isEmpty()) {
            updateExistingDataContainer.setVisible(false);
            target.add(updateExistingDataContainer);
            form.getNextButton().setEnabled(false);
            target.add(form.getWizardButtonContainer());

            this.containerForm.getModelObject().getUpload()
                    .setUploadStatus(iArkCommonService.getUploadStatusFor(
                            au.org.theark.lims.web.Constants.UPLOAD_STATUS_OF_ERROR_IN_DATA_VALIDATION));
            this.containerForm.getModelObject().getUpload().setFilename(filename);//have to reset this because the container has the file name...luckily it never changes 
            iArkCommonService.updateUpload(this.containerForm.getModelObject().getUpload());
        } else {
            this.containerForm.getModelObject().getUpload().setUploadStatus(iArkCommonService
                    .getUploadStatusFor(au.org.theark.lims.web.Constants.UPLOAD_STATUS_OF_VALIDATED));
            this.containerForm.getModelObject().getUpload().setFilename(filename);//have to reset this because the container has the file name...luckily it never changes 
            iArkCommonService.updateUpload(this.containerForm.getModelObject().getUpload());
        }
    } catch (IOException e) {
        validationMessage = "Error attempting to display the file. Please check the file and try again.";
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
    }

    containerForm.getModelObject().setValidationMessages(validationMessages);
    validationMessage = containerForm.getModelObject().getValidationMessagesAsString();
    addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));

    if (validationMessage != null && validationMessage.length() > 0) {
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
        downloadValMsgButton = new ArkDownloadAjaxButton("downloadValMsg", "ValidationMessage",
                validationMessage, "txt") {

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

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                this.error("Unexpected Error: Download request could not be processed");
            }

        };
        addOrReplace(downloadValMsgButton);
        target.add(downloadValMsgButton);
    }
}