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.ArkCRUDHelper.java

License:Open Source License

/**
 * While navigating from a result list(Search result list panel) into a Detail Panel this method must be invoked
 * by or within the onClick event handler.
 * @param target/* www  . j av a  2 s .c om*/
 * @param arkCrudContainerVO
 */
public static void preProcessDetailPanelOnSearchResults(AjaxRequestTarget target,
        ArkCrudContainerVO arkCrudContainerVO) {
    // this check is required to make the delete button enabled if the user has Delete permissions. If the user had navigated from New to Detail Form first, 
    // The delete button will be disabled. When he cancels out and then clicks on an existing record, even if the user had permissions the delete button will be disabled.
    //The earlier code had two containers to manage this so it was possible. Now this has to be done through this method.
    if (ArkPermissionHelper.isActionPermitted(Constants.DELETE)) {
        AjaxButton ajaxButton = (AjaxButton) arkCrudContainerVO.getEditButtonContainer().get("delete");
        if (ajaxButton != null) {
            ajaxButton.setEnabled(true);
            target.add(ajaxButton);
        }
    }

    arkCrudContainerVO.getDetailPanelContainer().setVisible(true);
    arkCrudContainerVO.getSearchResultPanelContainer().setVisible(false);
    arkCrudContainerVO.getSearchPanelContainer().setVisible(false);
    target.add(arkCrudContainerVO.getSearchPanelContainer());
    target.add(arkCrudContainerVO.getSearchResultPanelContainer());
    target.add(arkCrudContainerVO.getDetailPanelContainer());

}

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

License:Open Source License

/**
 * While navigating from a result list(Search result list panel) into a Detail Panel this method must be invoked
 * by or within the onClick event handler.
 * @param target/*from w  w w.  j  a  v  a  2s.com*/
 * @param arkCrudContainerVO
 */
public static void preProcessDetailPanelOnSearchResultsWhenTwoTypesForms(AjaxRequestTarget target,
        ArkCrudContainerVO arkCrudContainerVO, String type_one, String type_two) {
    // this check is required to make the delete button enabled if the user has Delete permissions. If the user had navigated from New to Detail Form first, 
    // The delete button will be disabled. When he cancels out and then clicks on an existing record, even if the user had permissions the delete button will be disabled.
    //The earlier code had two containers to manage this so it was possible. Now this has to be done through this method.
    if (ArkPermissionHelper.isActionPermitted(Constants.DELETE)) {
        AjaxButton ajaxButton = (AjaxButton) arkCrudContainerVO.getEditButtonContainer().get("delete");
        if (ajaxButton != null) {
            ajaxButton.setEnabled(true);
            target.add(ajaxButton);
        }
    }

    arkCrudContainerVO.getDetailPanelContainer().setVisible(true);
    arkCrudContainerVO.getSearchResultPanelContainer().setVisible(false);
    arkCrudContainerVO.getSearchPanelContainer().setVisible(false);
    arkCrudContainerVO.getDetailPanelContainer().get(type_one).setVisible(true);
    arkCrudContainerVO.getDetailPanelContainer().get(type_one).setOutputMarkupId(true);
    arkCrudContainerVO.getDetailPanelContainer().get(type_two).setVisible(false);
    arkCrudContainerVO.getDetailPanelContainer().get(type_two).setOutputMarkupId(true);
    //add to target.
    target.add(arkCrudContainerVO.getDetailPanelContainer().get(type_one));
    target.add(arkCrudContainerVO.getDetailPanelContainer().get(type_two));
    target.add(arkCrudContainerVO.getSearchPanelContainer());
    target.add(arkCrudContainerVO.getSearchResultPanelContainer());
    target.add(arkCrudContainerVO.getDetailPanelContainer());

}

From source file:au.org.theark.core.web.component.customfield.CustomFieldContainerPanel.java

License:Open Source License

protected WebMarkupContainer initialiseSearchResults() {
    SearchResultListPanel searchResultListPanel = new SearchResultListPanel("resultListPanel", cpModel,
            arkCrudContainerVO, feedBackPanel);

    // Data providor to paginate resultList
    customFieldProvider = new ArkDataProvider2<CustomField, CustomField>() {
        private static final long serialVersionUID = 1L;

        public int size() {
            return (int) iArkCommonService.getCustomFieldCount(criteriaModel.getObject());
        }// w ww  . j  a  v  a  2 s. com

        public Iterator<CustomField> iterator(int first, int count) {
            List<CustomField> listCustomFields = new ArrayList<CustomField>();
            if (isActionPermitted()) {
                listCustomFields = iArkCommonService.searchPageableCustomFields(criteriaModel.getObject(),
                        first, count);
            }
            return listCustomFields.iterator();
        }
    };
    // Set the criteria for the data provider
    customFieldProvider.setCriteriaModel(new PropertyModel<CustomField>(cpModel, "customField"));

    dataView = searchResultListPanel.buildDataView(customFieldProvider);
    dataView.setItemsPerPage(
            iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue());

    AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("navigator", dataView) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onAjaxEvent(AjaxRequestTarget target) {
            target.add(arkCrudContainerVO.getSearchResultPanelContainer());
        }
    };
    searchResultListPanel.add(pageNavigator);
    searchResultListPanel.add(dataView);
    arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultListPanel);
    return arkCrudContainerVO.getSearchResultPanelContainer();
}

From source file:au.org.theark.core.web.component.customfield.dataentry.AbstractCustomDataEditorForm.java

License:Open Source License

public void onEditCancel(AjaxRequestTarget target, Form<?> form) {
    target.add(feedbackPanel);
    dataViewWMC.setEnabled(true);//from www.j a va  2  s  .  c o m
    target.add(dataViewWMC);
    target.add(buttonsPanelWMC);
}

From source file:au.org.theark.core.web.component.customfield.dataentry.AbstractCustomDataEditorForm.java

License:Open Source License

public void onEditCancelError(AjaxRequestTarget target, Form<?> form) {
    this.info(// w w  w  .ja v  a  2s .c o  m
            "Error occurred with cancelling the edit.  If this persists, please contact your System Administrator.");
    target.add(feedbackPanel);
    log.error("Unknown error: Couldn't cancel the edit.");
}

From source file:au.org.theark.core.web.component.customfield.dataentry.AbstractCustomDataEditorForm.java

License:Open Source License

public void onEditSaveError(AjaxRequestTarget target, Form<?> form) {
    target.add(feedbackPanel);
}

From source file:au.org.theark.core.web.component.customfield.form.DetailForm.java

License:Open Source License

/**
 * initialize Field Types./*from  www.  j a va2s  .co  m*/
 */
private void initFieldTypeDdc() {
    List<FieldType> fieldTypeCollection = iArkCommonService.getFieldTypes();
    ChoiceRenderer fieldTypeRenderer = new ChoiceRenderer(Constants.FIELDTYPE_NAME, Constants.FIELDTYPE_ID);
    fieldTypeDdc = new DropDownChoice<FieldType>(Constants.FIELDVO_CUSTOMFIELD_FIELD_TYPE, fieldTypeCollection,
            fieldTypeRenderer) {
        @Override
        protected void onBeforeRender() {
            if (!isNew()) {
                // Disable fieldType if data exists for the field
                setEnabled(!cpModel.getObject().getCustomField().getCustomFieldHasData());
            }
            super.onBeforeRender();
        }
    };
    fieldTypeDdc.setOutputMarkupId(true);
    fieldTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            updateEncodedValueFld();
            updateUnitTypeDdc();
            initMinMaxValuePnls();
            target.add(minMaxValueEntryWMC);
            target.add(missingValueEntryWMC);
            target.add(defaultValueEntryWMC);
            target.add(fieldEncodedValuesTxtFld);
            if (panelCustomUnitTypeDropDown.isVisible())
                target.add(fieldUnitTypeDdc);
            //Add field unite type as text
            if (panelCustomUnitTypeText.isVisible())
                target.add(fieldUnitTypeTxtFld);
            target.add(fieldAllowMultiselectChkBox);
        }
    });
}

From source file:au.org.theark.core.web.component.customfield.form.DetailForm.java

License:Open Source License

/**
 * initialize custom field types.//from ww w  . java 2 s. co m
 */
private void initCustomFieldTypeDdc() {
    Long sessionModuleId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
    arkModule = iArkCommonService.getArkModuleById(sessionModuleId);
    List<CustomFieldType> customFieldTypeCollection = iArkCommonService.getCustomFieldTypes(arkModule);
    ChoiceRenderer fieldTypeRenderer = new ChoiceRenderer(Constants.FIELDTYPE_NAME, Constants.FIELDTYPE_ID);
    customFieldTypeDdc = new DropDownChoice<CustomFieldType>(Constants.FIELDVO_CUSTOMFIELD_CUSTOM_FIELD_TYPE,
            customFieldTypeCollection, fieldTypeRenderer) {
        @Override
        protected void onBeforeRender() {
            if (!isNew()) {
                // Disable customfieldType if data exists for the field
                setEnabled(!cpModel.getObject().getCustomField().getCustomFieldHasData());
            }
            super.onBeforeRender();
        }
    };
    customFieldTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            cpModel.getObject().getCustomField().setCustomFieldType(customFieldTypeDdc.getModelObject());
            Collection<CustomFieldCategory> customFieldCategoryCollection = getAvailableAllCategoryListInStudyByCustomFieldType();
            categoryPanel.remove(customeFieldCategoryDdc);
            ChoiceRenderer customfieldCategoryRenderer = new ChoiceRenderer(Constants.CUSTOMFIELDCATEGORY_NAME,
                    Constants.CUSTOMFIELDCATEGORY_ID);
            customeFieldCategoryDdc = new DropDownChoice<CustomFieldCategory>(
                    Constants.FIELDVO_CUSTOMFIELD_CUSTOEMFIELDCATEGORY, (List) customFieldCategoryCollection,
                    customfieldCategoryRenderer);
            customeFieldCategoryDdc.setOutputMarkupId(true);
            customeFieldCategoryDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    customFieldCategoryChangeEvent(target);
                }
            });
            customFieldCategoryChangeEvent(target);
            categoryPanel.add(customeFieldCategoryDdc);
            target.add(customeFieldCategoryDdc);
            target.add(categoryPanel);
        }
    });
}

From source file:au.org.theark.core.web.component.customfield.form.DetailForm.java

License:Open Source License

private void customFieldCategoryChangeEvent(AjaxRequestTarget target) {
    cpModel.getObject().getCustomField().setCustomFieldCategory(customeFieldCategoryDdc.getModelObject());
    orderNumberPanel.remove(customeFieldCategoryOrderNoTxtFld);
    customeFieldCategoryOrderNoTxtFld = new TextField<Long>(
            Constants.FIELDVO_CUSTOMFIELD_CUSTOEMFIELDCATEGORY_ORDERNUMBER);
    customeFieldCategoryOrderNoTxtFld.setOutputMarkupId(true);
    customeFieldCategoryOrderNoTxtFld.setEnabled(false);
    orderNumberPanel.add(customeFieldCategoryOrderNoTxtFld);
    target.add(customeFieldCategoryOrderNoTxtFld);
    target.add(orderNumberPanel);//from ww w  .  jav  a  2s.  co  m
}

From source file:au.org.theark.core.web.component.customfield.form.DetailForm.java

License:Open Source License

/**
 * Call this after the constructor is finished in detail panel.
 *///from w  ww .j  av  a2s  . c  o m
public void initialiseDetailForm() {
    fieldIdTxtFld = new TextField<String>(Constants.FIELDVO_CUSTOMFIELD_ID);
    fieldNameTxtFld = new TextField<String>(Constants.FIELDVO_CUSTOMFIELD_NAME);
    fieldNameTxtFld.add(new ArkDefaultFormFocusBehavior());
    fieldDescriptionTxtAreaFld = new TextArea<String>(Constants.FIELDVO_CUSTOMFIELD_DESCRIPTION);
    fieldLabelTxtAreaFld = new TextArea<String>(Constants.FIELDVO_CUSTOMFIELD_FIELD_LABEL);
    //fieldMissingValueTxtFld = new TextField<String>(Constants.FIELDVO_CUSTOMFIELD_MISSING_VALUE);
    fieldDisplayRequiredChkBox = new CheckBox(Constants.FIELDVO_CUSTOMFIELDDISPLAY_REQUIRED);
    fieldAllowMultiselectChkBox = new CheckBox(Constants.FIELDVO_CUSTOMFIELD_ALLOW_MULTISELECT) {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return (fieldEncodedValuesTxtFld.getModelObject() != null);
        }
    };

    if (getModelObject().isUseCustomFieldDisplay()) {
        // TODO: Have not implemented position support right now
        customFieldDisplayPositionPanel = new EmptyPanel("customFieldDisplayPositionPanel");
    } else {
        customFieldDisplayPositionPanel = new EmptyPanel("customFieldDisplayPositionPanel");
    }
    //customfield category order Number.
    customeFieldCategoryOrderNoTxtFld = new TextField<Long>(
            Constants.FIELDVO_CUSTOMFIELD_CUSTOEMFIELDCATEGORY_ORDERNUMBER);
    customeFieldCategoryOrderNoTxtFld.setOutputMarkupId(true);
    customeFieldCategoryOrderNoTxtFld.setEnabled(false);

    // Initialise Drop Down Choices
    initFieldTypeDdc();
    initCustomFieldTypeDdc();
    initCustomeFieldCategoryDdc();
    initUnitTypeDdc();

    // Min and Max Value panels rely on fieldTypeDdc being already established
    minMaxValueEntryWMC = new WebMarkupContainer("minMaxValueEntryWMC");
    minMaxValueEntryWMC.setOutputMarkupPlaceholderTag(true);
    missingValueEntryWMC = new WebMarkupContainer("missingValueEntryWMC");
    missingValueEntryWMC.setOutputMarkupPlaceholderTag(true);

    defaultValueEntryWMC = new WebMarkupContainer("defaultValueEntryWMC");
    defaultValueEntryWMC.setOutputMarkupPlaceholderTag(true);

    // unitType and encodedValues rely on fieldTypeDdc being already established
    fieldEncodedValuesTxtFld = new TextArea<String>(Constants.FIELDVO_CUSTOMFIELD_ENCODED_VALUES);
    fieldEncodedValuesTxtFld.setOutputMarkupId(true);
    fieldEncodedValuesTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(fieldAllowMultiselectChkBox);
        }
    });

    updateEncodedValueFld();
    updateUnitTypeDdc();

    // Have to Edit, before allowing delete
    deleteButton.setEnabled(false);

    //defaultValueTextArea = new TextArea<String>("customField.defaultValue");

    addDetailFormComponents();
    attachValidators();

    initMinMaxValuePnls();

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