Example usage for org.apache.wicket.markup.html.panel Panel setEnabled

List of usage examples for org.apache.wicket.markup.html.panel Panel setEnabled

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.panel Panel setEnabled.

Prototype

public final Component setEnabled(final boolean enabled) 

Source Link

Document

Sets whether this component is enabled.

Usage

From source file:gr.interamerican.wicket.markup.html.panel.crud.picker.CrudPickerPanel.java

License:Open Source License

@SuppressWarnings({ "serial", "nls", "unchecked" })
@Override/* ww  w  .  j a v  a2s  . co m*/
protected void init() {
    super.init();

    beanClass = (Class<B>) getDefinition().getBeanModel().getObject().getClass();

    IModel<String> deleteLabel = StringResourceUtils.getResourceModel(WellKnownResourceIds.CPP_DELETE_BTN_LABEL,
            this, getDefinition().getDeleteLabelModel(), "Delete");
    IModel<String> newLabel = StringResourceUtils.getResourceModel(WellKnownResourceIds.CPP_NEW_BTN_LABEL, this,
            getDefinition().getNewLabelModel(), "New");
    IModel<String> editLabel = StringResourceUtils.getResourceModel(WellKnownResourceIds.CPP_EDIT_BTN_LABEL,
            this, getDefinition().getEditLabelModel(), "Edit");
    IModel<String> viewLabel = StringResourceUtils.getResourceModel(WellKnownResourceIds.CPP_VIEW_BTN_LABEL,
            this, getDefinition().getViewLabelModel(), "View");

    CallbackAction deleteAction = getDefinition().getDeleteAction();
    CallbackAction updateAction = getDefinition().getUpdateAction();
    CallbackAction saveAction = getDefinition().getSaveAction();

    /*
     * We will set the caller of the Edit/New/Delete actions as this panel.
     * We will not allow the SingleBeanPanel to set itself as the caller of
     * the Edit/Delete actions, because we need to be able to hide it in case
     * of a DataException and still show the feedback message. 
     */
    if (deleteAction != null) {
        deleteAction.setCaller(this);
    }
    if (updateAction != null) {
        updateAction.setCaller(this);
    }
    if (saveAction != null) {
        saveAction.setCaller(this);
    }

    /*
     * 1. Retrieve the currently selected item from the radioGroup model.
     * 2. Set this item as the model object of the beanModel of this definition
     * 3. If a deleteValidator is supplied, check against it. If it does not pass
     *    stop the form processing here.
     * 3. Clients of this panel that have supplied the beanModel, may retrieve
     *    the item to be deleted from it.
     * 4. After the deleteAction provided by the client has been performed, the
     *    EditAction will repaint the results table.
     */
    deleteButton = new CallbackAjaxButton(DELETE_BUTTON_ID, deleteLabel,
            new RefreshTableAction(new DeleteItemAction(deleteAction)), getFeedBackPanel()) {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (!ServicePanelUtils.authorizedByFlag(getDefinition().getDeleteActionFlag())) {
                target.add(feedBackPanel);
                CrudPickerPanel.this.error(getDefinition().getDeleteActionFlag().getDownMessage());
                return;
            }
            B selection = radioGroup.getModelObject();
            if (selection == null) {
                return;
            }
            getDefinition().getBeanModel().setObject(selection);
            AjaxEnabledCondition<B> deleteValidator = getDefinition().getDeleteValidator();
            if (deleteValidator != null && !deleteValidator.check(selection, target)) {
                return;
            }
            super.onSubmit(target, form);
        }
    };
    if (getDefinition().getRequestConfirmOnDelete()) {
        AttributeModifier deleteConfirmation = new JavascriptEventConfirmation("onclick", "Are you sure?");
        deleteButton.add(deleteConfirmation);
    }
    ServicePanelUtils.disableButton(getDefinition(), getDefinition().getDeleteActionFlag(), deleteButton);

    /*
     * 1. Retrieve the currently selected item from the radioGroup model.
     * 2. Copy the item, we do not want to add unsaved changes to our models.
     * 3. (optional) Read the selected item from the persistence layer.
     * 4. Set this item as the model object of the beanModel of this definition
     * 5. Create a new SingleBeanPanel. In the definition of this panel, put
     *    the beanModel, as well as the updateAction received from the client
     *    of the CrudPickerPanel wrapped in an EditItemAction that repaints
     *    the results table.
     */
    editButton = new AjaxButton(EDIT_BUTTON_ID, editLabel) {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (!ServicePanelUtils.authorizedByFlag(getDefinition().getUpdateActionFlag())) {
                target.add(feedBackPanel);
                CrudPickerPanel.this.error(getDefinition().getUpdateActionFlag().getDownMessage());
                return;
            }
            B selection = radioGroup.getModelObject();
            if (selection == null) {
                return;
            }
            AjaxEnabledCondition<B> preEditValidator = getDefinition().getPreEditValidator();
            if (preEditValidator != null && !preEditValidator.check(selection, target)) {
                return;
            }

            /*
             * When copying we do not update the definition list. The point
             * is to leave it intact. If the  update succeeds the updated
             * instance will be properly replaced. If not, the original instance
             * will still be on the list.
             */
            selection = copyBean(selection);
            getDefinition().getBeanModel().setObject(selection);

            /*
             * the instance might be changed here, so we resynch
             */
            if (getDefinition().getReadBeforeEdit()) {
                B updatedSelection = selection;
                updatedSelection = readBean();
                resynchDefinition(selection, updatedSelection);
            }

            AjaxEnabledCondition<B> formValidator = getDefinition().getUpdateValidator();
            SingleBeanPanelDef<B> sbpDef = createSingleBeanPanelDef(
                    new RefreshTableAction(new EditItemAction(getDefinition().getUpdateAction())),
                    formValidator, PanelCreatorMode.EDIT);
            Panel replacement = new BeanPanel(sbpDef);
            checkSingleBeanPanelButtonsState(replacement);
            beanPanel.replaceWith(replacement);
            beanPanel = replacement;
            beanPanel.setVisible(true);
            target.add(CrudPickerPanel.this);
        }
    };

    ServicePanelUtils.disableButton(getDefinition(), getDefinition().getUpdateActionFlag(), editButton);

    /*
     * 1. Retrieve the currently selected item from the radioGroup model.
     * 2. (optional) Read the selected item from the persistence layer.
     * 3. Set this item as the model object of the beanModel of this definition
     * 4. Create a new SingleBeanPanel. In the definition of this panel, put
     *    the beanModel and a null beanAction. Also, disable the fields panel.
     *    
     * TODO: handle text areas here, so that users do not have to do custom
     *       bean panel disabling in order to add a 'readonly' attribute mod
     *       to TextAreas
     */
    viewButton = new AjaxButton(VIEW_BUTTON_ID, viewLabel) {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            B selection = radioGroup.getModelObject();
            if (selection == null) {
                return;
            }
            if (getDefinition().getReadBeforeEdit()) {
                getDefinition().getBeanModel().setObject(selection);
                selection = readBean();
            }
            getDefinition().getBeanModel().setObject(selection);
            Panel replacement = new BeanPanel(createSingleBeanPanelDef(null, null, PanelCreatorMode.VIEW));
            checkSingleBeanPanelButtonsState(replacement);
            beanPanel.replaceWith(replacement);
            beanPanel = replacement;
            if (!getDefinition().getCustomSingleBeanPanelDisabling()) {
                Form<B> sbpForm = (Form<B>) beanPanel.get(SingleBeanPanel.FORM_ID);
                Panel sbpFieldsPanel = (Panel) sbpForm.get(SingleBeanPanel.FORM_FIELDS_PANEL_ID);
                sbpFieldsPanel.setEnabled(false);
            }
            beanPanel.setVisible(true);
            target.add(CrudPickerPanel.this);
        }
    };

    /*
     * 1. Create a new bean instance and set it as the model object of the beanModel.
     * 2. Create a new SingleBeanPanel. In the definition of this panel, put
     *    the beanModel, as well as the saveAction received from the client
     *    of the CrudPickerPanel wrapped in an NewItemAction that repaints
     *    the results table.
     */
    newButton = new AjaxButton(NEW_BUTTON_ID, newLabel) {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (!ServicePanelUtils.authorizedByFlag(getDefinition().getSaveActionFlag())) {
                target.add(feedBackPanel);
                CrudPickerPanel.this.error(getDefinition().getSaveActionFlag().getDownMessage());
                return;
            }
            getDefinition().getBeanModel().setObject(newBean());
            AjaxEnabledCondition<B> formValidator = getDefinition().getSaveValidator();
            SingleBeanPanelDef<B> sbpDef = createSingleBeanPanelDef(
                    new RefreshTableAction(new NewItemAction(getDefinition().getSaveAction())), formValidator,
                    PanelCreatorMode.CREATE);
            Panel replacement = new BeanPanel(sbpDef);
            checkSingleBeanPanelButtonsState(replacement);
            beanPanel.replaceWith(replacement);
            beanPanel = replacement;
            beanPanel.setVisible(true);
            target.add(CrudPickerPanel.this);
        }
    };

    ServicePanelUtils.disableButton(getDefinition(), getDefinition().getSaveActionFlag(), newButton);

    beanPanel = new EmptyPanel(NEW_OR_EDIT_PANEL_ID);

    if (getDefinition().getSingleBeanFormContainsFileUpload()) {
        tableForm.setMultiPart(true);
        tableForm.add(new AttributeModifier("enctype", new Model<String>("multipart/form-data")));
    }
}

From source file:org.apache.syncope.client.console.wizards.any.ConnObjectPanel.java

License:Apache License

/**
 * Get panel for attribute value (not remote status).
 *
 * @param id component id to be replaced with the fragment content.
 * @param attrTO remote attribute./*from   ww w .  ja  va 2s  .c  o m*/
 * @return fragment.
 */
private Panel getValuePanel(final String id, final String schemaName, final AttrTO attrTO) {
    Panel field;
    if (attrTO == null) {
        field = new AjaxTextFieldPanel(id, schemaName, new Model<String>());
    } else if (CollectionUtils.isEmpty(attrTO.getValues())) {
        field = new AjaxTextFieldPanel(id, schemaName, new Model<String>());
    } else if (ConnIdSpecialAttributeName.PASSWORD.equals(schemaName)) {
        field = new AjaxTextFieldPanel(id, schemaName, new Model<>("********"));
    } else if (attrTO.getValues().size() == 1) {
        field = new AjaxTextFieldPanel(id, schemaName, new Model<>(attrTO.getValues().get(0)));
    } else {
        field = new MultiFieldPanel.Builder<>(new ListModel<>(attrTO.getValues())).build(id, schemaName,
                new AjaxTextFieldPanel("panel", schemaName, new Model<String>()));
    }

    field.setEnabled(false);
    return field;
}