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.study.web.component.attachments.form.SearchForm.java

License:Open Source License

@Override
protected void onNew(AjaxRequestTarget target) {
    target.add(feedbackPanel);
    getModelObject().getSubjectFile().setId(null);
    preProcessDetailPanel(target);//from  ww  w.  j  a  v  a2s  .  com
}

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

License:Open Source License

private AjaxButton buildDownloadButton(final SubjectFile subjectFile) {
    AjaxButton ajaxButton = new AjaxButton(au.org.theark.study.web.Constants.DOWNLOAD_FILE) {

        private static final long serialVersionUID = 1L;

        @Override/*from w  w  w . jav a2  s .co m*/
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // Attempt to download the Blob as an array of bytes
            byte[] data = null;
            try {

                //               data = subjectFile.getPayload();//.getBytes(1, (int) subjectFile.getPayload().length());

                Long studyId = subjectFile.getLinkSubjectStudy().getStudy().getId();
                String subjectUID = subjectFile.getLinkSubjectStudy().getSubjectUID();
                String fileId = subjectFile.getFileId();
                String checksum = subjectFile.getChecksum();

                data = arkCommonService.retriveArkFileAttachmentByteArray(studyId, subjectUID,
                        au.org.theark.study.web.Constants.ARK_SUBJECT_ATTACHEMENT_DIR, fileId, checksum);

                if (data != null) {
                    InputStream inputStream = new ByteArrayInputStream(data);
                    OutputStream outputStream;

                    final String tempDir = System.getProperty("java.io.tmpdir");
                    final java.io.File file = new File(tempDir, subjectFile.getFilename());
                    final String fileName = subjectFile.getFilename();
                    outputStream = new FileOutputStream(file);
                    IOUtils.copy(inputStream, outputStream);

                    IResourceStream resourceStream = new FileResourceStream(
                            new org.apache.wicket.util.file.File(file));
                    getRequestCycle().scheduleRequestHandlerAfterCurrent(
                            new ResourceStreamRequestHandler(resourceStream) {
                                @Override
                                public void respond(IRequestCycle requestCycle) {
                                    super.respond(requestCycle);
                                    Files.remove(file);
                                }
                            }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT));
                }
            } catch (ArkSystemException e) {
                this.error("Unexpected error: Download request could not be fulfilled.");
                log.error("ArkSystemException" + e.getMessage(), e);
            } catch (FileNotFoundException e) {
                this.error("Unexpected error: Download request could not be fulfilled.");
                log.error("FileNotFoundException" + e.getMessage(), e);
            } catch (IOException e) {
                this.error("Unexpected error: Download request could not be fulfilled.");
                log.error("IOException" + e.getMessage(), e);
            }

            target.add(arkCrudContainerVO.getSearchResultPanelContainer());
            target.add(containerForm);
        }

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

    ajaxButton.setVisible(true);
    ajaxButton.setDefaultFormProcessing(false);

    //if (subjectFile.getPayload() == null)
    //ajaxButton.setVisible(false);

    return ajaxButton;
}

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

License:Open Source License

private AjaxDeleteButton buildDeleteButton(final SubjectFile subjectFile, final AjaxButton downloadButton) {

    DeleteButton ajaxButton = new DeleteButton(subjectFile, SearchResultListPanel.this) {

        private static final long serialVersionUID = 1L;

        @Override/*from   ww w  . j  a  v a2 s. c  o m*/
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // Attempt to delete upload

            boolean success = false;
            if (subjectFile.getId() != null) {
                try {
                    studyService.delete(subjectFile);
                    success = true;
                } catch (ArkSystemException e) {
                    this.error("Unexpected error: Delete request could not be fulfilled.");
                    log.error("ArkSystemException" + e.getMessage(), e);
                } catch (EntityNotFoundException e) {
                    this.error("Unexpected error: Delete request could not be fulfilled.");
                    log.error("Ent not found" + e.getMessage(), e);
                }
            }

            if (success) {
                containerForm.info("Attachment " + subjectFile.getFilename() + " was deleted successfully.");
            }
            // Update the result panel
            // target.add(searchResultContainer);
            target.add(arkCrudContainerVO.getSearchResultPanelContainer());

            target.add(containerForm);
        }

        @Override
        public boolean isVisible() {
            SecurityManager securityManager = ThreadContext.getSecurityManager();
            Subject currentUser = SecurityUtils.getSubject();
            boolean flag = false;
            if (securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.DELETE)) {
                return flag = true;
            }

            return flag;
        }

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

    ajaxButton.setDefaultFormProcessing(false);
    return ajaxButton;
}

From source file:au.org.theark.study.web.component.calendar.form.DetailForm.java

License:Open Source License

@Override
protected void onSave(Form<StudyCalendarVo> containerForm, AjaxRequestTarget target) {

    target.add(arkCrudContainerVO.getDetailPanelContainer());

    Long studyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    study = iArkCommonService.getStudy(studyId);
    containerForm.getModelObject().getStudyCalendar().setStudy(study);

    if (containerForm.getModelObject().getStudyCalendar().getId() == null) {

        iStudyService.saveOrUpdate(containerForm.getModelObject());
        this.info("Study Calendar " + containerForm.getModelObject().getStudyCalendar().getName()
                + " was created successfully");
        processErrors(target);/*from  w w  w.  ja  v  a2  s.  c  o  m*/

    } else {

        iStudyService.saveOrUpdate(containerForm.getModelObject());
        this.info("Study Calendar " + containerForm.getModelObject().getStudyCalendar().getName()
                + " was updated successfully");
        processErrors(target);

    }

    onSavePostProcess(target);

}

From source file:au.org.theark.study.web.component.calendar.form.SearchForm.java

License:Open Source License

@Override
protected void onSearch(AjaxRequestTarget target) {

    target.add(feedbackPanel);

    List<StudyCalendar> resultList = studyService.searchStudyCalenderList(getModelObject().getStudyCalendar());

    if (resultList != null && resultList.size() == 0) {
        this.info("Study Component with the specified criteria does not exist in the system.");
        target.add(feedbackPanel);//from   w ww  . j  av a  2s.c  om
    }

    getModelObject().setStudyCalendarList(resultList);
    listView.removeAll();

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

}

From source file:au.org.theark.study.web.component.consent.form.DetailForm.java

License:Open Source License

public void initialiseDetailForm() {
    consentedBy = new TextField<String>(Constants.CONSENT_CONSENTED_BY);

    wmcPlain = new WebMarkupContainer(Constants.WMC_PLAIN);
    wmcPlain.setOutputMarkupPlaceholderTag(true);
    wmcPlain.setVisible(true);/*from   ww w  . ja v  a2  s. com*/

    wmcRequested = new WebMarkupContainer(Constants.WMC_REQUESTED);
    wmcRequested.setOutputMarkupPlaceholderTag(true);
    wmcRequested.setVisible(false);

    wmcRecieved = new WebMarkupContainer(Constants.WMC_RECIEVED);
    wmcRecieved.setOutputMarkupPlaceholderTag(true);
    wmcRecieved.setVisible(false);

    wmcCompleted = new WebMarkupContainer(Constants.WMC_COMPLETED);
    wmcCompleted.setOutputMarkupPlaceholderTag(true);
    wmcCompleted.setVisible(false);

    consentedDatePicker = new DateTextField(Constants.CONSENT_CONSENT_DATE,
            au.org.theark.core.Constants.DD_MM_YYYY);
    ArkDatePicker arkDatePicker = new ArkDatePicker();
    arkDatePicker.bind(consentedDatePicker);
    consentedDatePicker.add(arkDatePicker);

    consentRequestedDtf = new DateTextField(Constants.CONSENT_REQUESTED_DATE,
            au.org.theark.core.Constants.DD_MM_YYYY);
    ArkDatePicker requestedDatePicker = new ArkDatePicker();
    requestedDatePicker.bind(consentRequestedDtf);
    consentRequestedDtf.add(requestedDatePicker);
    wmcRequested.add(consentRequestedDtf);

    consentReceivedDtf = new DateTextField(Constants.CONSENT_RECEIVED_DATE,
            au.org.theark.core.Constants.DD_MM_YYYY);
    ArkDatePicker recievedDatePicker = new ArkDatePicker();
    recievedDatePicker.bind(consentReceivedDtf);
    consentReceivedDtf.add(recievedDatePicker);
    wmcRecieved.add(consentReceivedDtf);

    consentCompletedDtf = new DateTextField(Constants.CONSENT_COMPLETED_DATE,
            au.org.theark.core.Constants.DD_MM_YYYY);
    ArkDatePicker completedDatePicker = new ArkDatePicker();
    completedDatePicker.bind(consentCompletedDtf);
    consentCompletedDtf.add(completedDatePicker);
    wmcCompleted.add(consentCompletedDtf);

    commentTxtArea = new TextArea<String>(Constants.CONSENT_CONSENT_COMMENT);

    // fileSubjectFile for consent file payload (attached to filename key)
    fileUploadField = new FileUploadField(au.org.theark.study.web.Constants.SUBJECT_FILE_FILENAME);
    clearButton = new AjaxButton("clearButton") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            fileUploadField.clearInput();
            target.add(fileUploadField);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            fileUploadField.clearInput();
            target.add(fileUploadField);
        }
    };
    clearButton.add(new AttributeModifier("title", new Model<String>("Clear Attachment")));

    initStudyComponentChoice();
    initConsentTypeChoice();
    initConsentStatusChoice();
    initStudyComponentStatusChoice();
    initConsentDownloadChoice();
    initConsentHistoryPanel();

    addDetailFormComponents();
    attachValidators();

    historyButtonPanel = new HistoryButtonPanel(containerForm, arkCrudContainerVO.getEditButtonContainer(),
            arkCrudContainerVO.getDetailPanelFormContainer());
}

From source file:au.org.theark.study.web.component.consent.form.FormHelper.java

License:Open Source License

public void updateStudyCompStatusDates(AjaxRequestTarget target, String statusName, WebMarkupContainer wmcPlain,
        WebMarkupContainer wmcRequested, WebMarkupContainer wmcRecieved, WebMarkupContainer wmcCompleted) {

    if ((statusName.equalsIgnoreCase(Constants.STUDY_STATUS_RECEIVED))) {
        wmcRecieved.setVisible(true);/*from www.  j av  a 2s.c o  m*/
        wmcPlain.setVisible(false);
        wmcRequested.setVisible(false);
        wmcCompleted.setVisible(false);
        target.add(wmcPlain);
        target.add(wmcRecieved);
        target.add(wmcRequested);
        target.add(wmcCompleted);
    } else if ((statusName.equalsIgnoreCase(Constants.STUDY_STATUS_REQUESTED))) {

        wmcRequested.setVisible(true);
        wmcPlain.setVisible(false);
        wmcRecieved.setVisible(false);
        wmcCompleted.setVisible(false);
        target.add(wmcRecieved);
        target.add(wmcRequested);
        target.add(wmcPlain);
        target.add(wmcCompleted);
    } else if ((statusName.equalsIgnoreCase(Constants.STUDY_STATUS_COMPLETED))) {

        wmcCompleted.setVisible(true);
        wmcPlain.setVisible(false);
        wmcRecieved.setVisible(false);
        wmcRequested.setVisible(false);
        target.add(wmcCompleted);
        target.add(wmcRecieved);
        target.add(wmcRequested);
        target.add(wmcPlain);
    } else {
        setDatePickerDefaultMarkup(target, wmcPlain, wmcRequested, wmcRecieved, wmcCompleted);
    }

}

From source file:au.org.theark.study.web.component.consent.form.FormHelper.java

License:Open Source License

public void setDatePickerDefaultMarkup(AjaxRequestTarget target, WebMarkupContainer wmcPlain,
        WebMarkupContainer wmcRequested, WebMarkupContainer wmcRecieved, WebMarkupContainer wmcCompleted) {
    wmcPlain.setVisible(true);// w w  w . j a  va 2  s.  c o  m
    wmcRecieved.setVisible(false);
    wmcRequested.setVisible(false);
    wmcCompleted.setVisible(false);
    target.add(wmcCompleted);
    target.add(wmcRecieved);
    target.add(wmcRequested);
    target.add(wmcPlain);
}

From source file:au.org.theark.study.web.component.consent.form.SearchForm.java

License:Open Source License

@Override
protected void onSearch(AjaxRequestTarget target) {
    target.add(feedbackPanel);
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID);
    // session/*from  ww  w . j av  a  2 s  .  co m*/
    Consent consent = getModelObject().getConsent();

    try {
        Study study = iArkCommonService.getStudy(sessionStudyId);
        // Person subject = studyService.getPerson(sessionPersonId);

        // consent.setSubject(subject);
        // TODO Replace the above line with a call to LinkSubjectStudy
        consent.setStudy(study);

        // Look up based on criteria via back end.
        // Collection<Consent> consentList = studyService.searchConsent(getModelObject().getConsent());
        LinkSubjectStudy subjectInContext = studyService.getSubjectLinkedToStudy(sessionPersonId, study);
        consent.setLinkSubjectStudy(subjectInContext);
        Collection<Consent> consentList = studyService.searchConsent(getModelObject());

        if (consentList != null && consentList.size() == 0) {
            this.info("There are no consents for the specified criteria.");
            target.add(feedbackPanel);
        }

        getModelObject().setConsentList(consentList);
        pageableListView.removeAll();

        arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true);
        target.add(arkCrudContainerVO.getSearchResultPanelContainer());
    } catch (EntityNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ArkSystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:au.org.theark.study.web.component.contact.ContactContainerPanel.java

License:Open Source License

/**
 * Switching the loaded panel according to the button click.
 * @param target// ww w . j  a v  a 2 s.  c o  m
 * @param type
 */
private void switchBetweenPanels(AjaxRequestTarget target, String type) {

    Component addressDetailPanelComp = arkCrudContainerVO.getDetailPanelContainer()
            .get(au.org.theark.study.web.Constants.ADDRESS_DETAIL_PANEL);
    addressDetailPanelComp.setOutputMarkupId(true);
    Component phoneDetailPanelComp = arkCrudContainerVO.getDetailPanelContainer()
            .get(au.org.theark.study.web.Constants.PHONE_DETAIL_PANEL);
    phoneDetailPanelComp.setOutputMarkupId(true);
    arkCrudContainerVO.getDetailPanelContainer().setVisible(true);
    arkCrudContainerVO.getDetailPanelContainer().setEnabled(true);
    arkCrudContainerVO.getDetailPanelFormContainer().setVisible(true);
    arkCrudContainerVO.getDetailPanelFormContainer().setEnabled(true);
    if (au.org.theark.study.web.Constants.PHONE_DETAIL_PANEL.equals(type)) {
        phoneDetailPanelComp.setVisible(true);
        addressDetailPanelComp.setVisible(false);
    } else if (au.org.theark.study.web.Constants.ADDRESS_DETAIL_PANEL.equals(type)) {
        phoneDetailPanelComp.setVisible(false);
        addressDetailPanelComp.setVisible(true);
    }
    arkCrudContainerVO.getSearchResultPanelContainer().setVisible(false);
    arkCrudContainerVO.getEditButtonContainer().setVisible(true);
    arkCrudContainerVO.getViewButtonContainer().setVisible(false);
    arkCrudContainerVO.getSearchPanelContainer().setVisible(false);
    target.add(arkCrudContainerVO.getDetailPanelContainer());
    target.add(arkCrudContainerVO.getDetailPanelFormContainer());
    target.add(addressDetailPanelComp);
    target.add(phoneDetailPanelComp);
    target.add(arkCrudContainerVO.getSearchResultPanelContainer());
    target.add(arkCrudContainerVO.getSearchPanelContainer());
    target.add(arkCrudContainerVO.getViewButtonContainer());
    target.add(arkCrudContainerVO.getEditButtonContainer());

}