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.core.web.component.customfieldcategory.form.SearchForm.java

License:Open Source License

/**
 * initialize Custom Filed Types.//from   w ww.j a v  a  2s  . co m
 */
private void initCustomFieldTypeDdc() {
    Long sessionModuleId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
    ArkModule arkModule = iArkCommonService.getArkModuleById(sessionModuleId);
    java.util.Collection<CustomFieldType> customFieldTypeCollection = iArkCommonService
            .getCustomFieldTypes(arkModule);
    ;
    ChoiceRenderer customfieldTypeRenderer = new ChoiceRenderer(Constants.CUSTOM_FIELD_TYPE_NAME,
            Constants.CUSTOM_FIELD_TYPE_ID);
    customFieldTypeDdc = new DropDownChoice<CustomFieldType>(
            Constants.FIELDVO_CUSTOMFIELDCATEGORY_CUSTOM_FIELD_TYPE, (List) customFieldTypeCollection,
            customfieldTypeRenderer);
    customFieldTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            cpModel.getObject().getCustomFieldCategory()
                    .setCustomFieldType(customFieldTypeDdc.getModelObject());
            Collection<CustomFieldCategory> customFieldCategoryCollection = getParentCategoryCollectionFromModel();
            categoryPanel.remove(parentCategoryDdc);
            ChoiceRenderer customfieldCategoryRenderer = new ChoiceRenderer(Constants.CUSTOMFIELDCATEGORY_NAME,
                    Constants.CUSTOMFIELDCATEGORY_ID);
            parentCategoryDdc = new DropDownChoice<CustomFieldCategory>(
                    Constants.FIELDVO_CUSTOMFIELDCATEGORY_PARENTCATEGORY, (List) customFieldCategoryCollection,
                    customfieldCategoryRenderer);
            parentCategoryDdc.setOutputMarkupId(true);
            categoryPanel.add(parentCategoryDdc);
            target.add(parentCategoryDdc);
            target.add(categoryPanel);
        }
    });

}

From source file:au.org.theark.core.web.component.customfieldcategory.form.SearchForm.java

License:Open Source License

@Override
protected void onSearch(AjaxRequestTarget target) {
    target.add(feedbackPanel);
    final Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    // Get a list of all Fields for the Study in context
    Study study = iArkCommonService.getStudy(sessionStudyId);
    getModelObject().getCustomFieldCategory().setStudy(study);

    long count = iArkCommonService.getCustomFieldCategoryCount(getModelObject().getCustomFieldCategory());
    if (count <= 0L) {
        this.info("No records match the specified criteria.");
        target.add(feedbackPanel);/*w w w  . ja  va 2s . co m*/
    }

    arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true);// Make the WebMarkupContainer that houses the search results visible
    target.add(arkCrudContainerVO.getSearchResultPanelContainer());
}

From source file:au.org.theark.core.web.component.customfieldcategory.form.SearchForm.java

License:Open Source License

@Override
protected void onNew(AjaxRequestTarget target) {
    target.add(feedbackPanel);
    // Instead of having to reset the criteria, we just copy the criteria across
    CustomFieldCategory cf = getModelObject().getCustomFieldCategory();
    CompoundPropertyModel<CustomFieldCategoryVO> newModel = new CompoundPropertyModel<CustomFieldCategoryVO>(
            new CustomFieldCategoryVO());
    CustomFieldCategory newCF = newModel.getObject().getCustomFieldCategory();
    // Copy all the customField attributes across from the SearchForm
    newCF.setStudy(cf.getStudy());/*  www  .  j a va2s .  c om*/
    newCF.setArkFunction(cf.getArkFunction());
    newCF.setName(cf.getName());
    //newCF.setFieldType(cf.getFieldType());
    newCF.setDescription(cf.getDescription());
    /* 
     * NB: Do NOT copy unitType across because it is a Textfield on the SearchForm.
     * If you copy this through, then DetailForm will have transient error during onSave(..).
     * Also, if the user chooses fieldType==DATE, this and unitType is not a valid combination
     * (but unitTypeDdc will be disabled, so the user can't make it null for it to be valid).
     */
    //newCF.setMinValue(cf.getMinValue());
    //newCF.setMaxValue(cf.getMaxValue());
    newCF.setOrderNumber(cf.getOrderNumber());
    newCF.setParentCategory(cf.getParentCategory());
    //newModel.getObject().setUseCustomFieldCategoryDisplay(getModelObject().isUseCustomFieldCategoryDisplay());

    DetailPanel detailPanel = new DetailPanel("detailPanel", feedbackPanel, newModel, arkCrudContainerVO);
    arkCrudContainerVO.getDetailPanelContainer().addOrReplace(detailPanel);

    // Reset model's CF object (do NOT replace the CustomFieldVO in the model)
    cf = new CustomFieldCategory();
    cf.setStudy(newCF.getStudy());
    cf.setArkFunction(newCF.getArkFunction());
    getModelObject().setCustomFieldCategory(cf);

    preProcessDetailPanel(target);
}

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

License:Open Source License

private WebMarkupContainer buildLinkWMC(final Item<CustomFieldCategory> item) {

    WebMarkupContainer customfieldCategoryLinkWMC = new WebMarkupContainer("customfieldCategoryLinkWMC",
            item.getModel());/*  w w w.  ja  v  a  2s .c  o m*/
    ArkBusyAjaxLink link = new ArkBusyAjaxLink(Constants.CUSTOMFIELDCATEGORY_NAME) {
        @Override
        public void onClick(AjaxRequestTarget target) {
            // Sets the selected object into the model
            CustomFieldCategory cf = (CustomFieldCategory) (getParent().getDefaultModelObject());
            CompoundPropertyModel<CustomFieldCategoryVO> newModel = new CompoundPropertyModel<CustomFieldCategoryVO>(
                    new CustomFieldCategoryVO());
            newModel.getObject().setCustomFieldCategory(cf);
            //newModel.getObject().setUseCustomFieldCategoryDisplay(cpModel.getObject().isUseCustomFieldCategoryDisplay());

            DetailPanel detailPanel = new DetailPanel("detailPanel", feedbackPanel, newModel,
                    arkCrudContainerVO);
            arkCrudContainerVO.getDetailPanelContainer().addOrReplace(detailPanel);
            ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, arkCrudContainerVO);
            //Added on 2016-05-26 to stop showing the previous feed back message when deleting or updating in the form.
            //This will clear the feedback message.
            Session.get().cleanupFeedbackMessages();
            target.add(feedbackPanel);

        }
    };

    // Add the label for the link
    CustomFieldCategory category = item.getModelObject();
    //Label nameLinkLabel = new Label("nameLbl", category.getName());
    Label nameLinkLabel = new Label("nameLbl", CustomFieldCategoryOrderingHelper.getInstance()
            .preTextDecider(category).concat(category.getName()));
    link.add(nameLinkLabel);
    customfieldCategoryLinkWMC.add(link);
    return customfieldCategoryLinkWMC;
}

From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep2.java

License:Open Source License

@Override
public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {

    //root acording to the field and category 

    File temp = containerForm.getModelObject().getTempFile();

    if (temp != null && temp.exists()) {
        InputStream inputStream = null;
        try {//from  w w  w  .java2  s .  c  om
            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();
            }
            inputStream = new BufferedInputStream(new FileInputStream(temp));
            // Field upload
            if (containerForm.getModelObject().getUpload().getUploadLevel().getName()
                    .equalsIgnoreCase(Constants.UPLOAD_LEVEL_FIELD)) {
                CustomFieldImportValidator fieldvalidator = new CustomFieldImportValidator(iArkCommonService,
                        containerForm.getModelObject());
                validationMessages = fieldvalidator.validateCustomDataMatrixFileFormat(inputStream, fileFormat,
                        delimChar);
            }
            //Categoty upload
            else if (containerForm.getModelObject().getUpload().getUploadLevel().getName()
                    .equalsIgnoreCase(Constants.UPLOAD_LEVEL_CATEGORY)) {
                CustomFieldCategoryImportValidator categoryValidator = new CustomFieldCategoryImportValidator(
                        iArkCommonService, containerForm.getModelObject());
                validationMessages = categoryValidator.validateCustomDataMatrixFileFormat(inputStream,
                        fileFormat, delimChar);
            }
            inputStream.close();
            inputStream = null;
            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);
            }
            // Show file data
            FileUpload fileUpload = containerForm.getModelObject().getFileUpload();
            inputStream = new BufferedInputStream(new FileInputStream(temp));
            ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView",
                    inputStream, fileFormat, delimChar, fileUpload, iArkCommonService
                            .getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue(),
                    containerForm.getModelObject().getUpload().getUploadType());
            inputStream.close();
            inputStream = null;
            arkExcelWorkSheetAsGrid.setOutputMarkupId(true);
            form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
            form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid);
            target.add(form.getWizardPanelFormContainer());
        }
        // TODO: Shouldn't catch NPEs because we should be checking for NULL in the first place (inherited from old code)
        catch (NullPointerException npe) {
            log.error("NullPointer " + npe.getMessage());
            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 (IOException ioe) {
            log.error("IOException " + ioe.getMessage());
            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) {
            log.error("FileFormatException " + ffe.getMessage());
            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());
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    log.error("Unable to close inputStream: " + e.getMessage());
                }
            }
        }
    } else {
        // Stop progress because of missing temp file
        error("Unexpected erorr: Can not proceed due to missing temporary file.");
        form.getNextButton().setEnabled(false);
    }
}

From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep3.java

License:Open Source License

private void initialiseDetailForm() {
    setValidationMessage(containerForm.getModelObject().getValidationMessagesAsString());
    addOrReplace(new MultiLineLabel("multiLineLabel", getValidationMessage()));

    add(downloadValMsgButton);/* ww w.  j ava  2 s.c  om*/

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

    containerForm.getModelObject().setUpdateChkBox(false);

    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.core.web.component.customfieldupload.CustomFieldUploadStep3.java

License:Open Source License

/**
 * //from  ww w .  j  a v  a 2  s .  c  o  m
 * @param form
 * @param target
 */
private void displayValidationMessagesAndButtons(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    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);
    }
}

From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep3.java

License:Open Source License

/**
 * /*from  w w w.ja  v a 2s  . c o m*/
 * @param form
 * @param target
 * @param fileFormat
 * @param delimChar
 * @param temp
 * @return
 * @throws FileNotFoundException
 * @throws IOException
 */
private InputStream setupExcellDisplayFormat(AbstractWizardForm<?> form, AjaxRequestTarget target,
        String fileFormat, char delimChar, File temp) throws FileNotFoundException, IOException {
    InputStream inputStream;
    HashSet<Integer> insertRows = new HashSet<Integer>();
    HashSet<Integer> updateRows = new HashSet<Integer>();
    HashSet<ArkGridCell> insertCells = new HashSet<ArkGridCell>();
    HashSet<ArkGridCell> updateCells = new HashSet<ArkGridCell>();
    HashSet<ArkGridCell> warningCells = new HashSet<ArkGridCell>();
    HashSet<ArkGridCell> errorCells = new HashSet<ArkGridCell>();

    insertRows = iCustomFieldValidator.getInsertRows();
    updateRows = iCustomFieldValidator.getUpdateRows();
    insertCells = iCustomFieldValidator.getInsertCells();
    updateCells = iCustomFieldValidator.getUpdateCells();
    warningCells = iCustomFieldValidator.getWarningCells();
    errorCells = iCustomFieldValidator.getErrorCells();

    // Show file data (and key reference)
    inputStream = new BufferedInputStream(new FileInputStream(temp));
    ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView", inputStream,
            fileFormat, delimChar, containerForm.getModelObject().getFileUpload(), insertRows, updateRows,
            insertCells, updateCells, warningCells, errorCells);
    inputStream.close();
    inputStream = null;
    arkExcelWorkSheetAsGrid.setOutputMarkupId(true);
    arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer().setVisible(true);
    form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
    form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid);

    // Repaint
    target.add(arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer());
    target.add(form.getWizardPanelFormContainer());
    if (updateCells.isEmpty()) {
        containerForm.getModelObject().setUpdateChkBox(true);
        updateExistingDataContainer.setVisible(false);
    } else {
        containerForm.getModelObject().setUpdateChkBox(false);
        updateExistingDataContainer.setVisible(true);
    }
    target.add(updateExistingDataContainer);
    if (!errorCells.isEmpty()) {
        updateExistingDataContainer.setVisible(false);
        target.add(updateExistingDataContainer);
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
    }
    return inputStream;
}

From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep4.java

License:Open Source License

@Override
public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    form.getArkExcelWorkSheetAsGrid().setVisible(false);
    target.add(form.getArkExcelWorkSheetAsGrid());
    File temp = containerForm.getModelObject().getTempFile();
    if (temp != null && temp.exists()) {
    } else {//from w ww.java  2s.c o  m
        // Stop progress because of missing temp file
        error("Unexpected error: Can not proceed due to missing temporary file.");
        form.getNextButton().setEnabled(false);
    }
}

From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep5.java

License:Open Source License

@Override
public void handleWizardState(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    if (this.containerForm.getModelObject().getValidationMessages() != null) {
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
    }//from www  . ja  v  a2s .  c o m
}