package com.braintree.customersupportbackoffice.editor;

import com.hybris.cockpitng.editor.defaulttext.DefaultTextEditor;
import com.hybris.cockpitng.editors.EditorContext;
import com.hybris.cockpitng.editors.EditorListener;
import de.hybris.platform.core.model.BraintreeACHConfigurationModel;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.ext.Disable;

public class BrainTreeACHConfigurationStringEditor extends DefaultTextEditor {

    private static final String PARENT_OBJECT = "parentObject";

    @Override
    public void render(Component parent, EditorContext<String> context, EditorListener<String> listener) {
        callParentRender(parent, context, listener);
        disableConfig(parent, context);
    }

    protected void disableConfig(Component parent, EditorContext<String> context) {
        BraintreeACHConfigurationModel braintreeACHConfigurationModel =
                (BraintreeACHConfigurationModel) context.getParameter(PARENT_OBJECT);
        if (!braintreeACHConfigurationModel.isEnabled()) {
            Disable disable = (Disable) parent.getFirstChild();
            disable.setDisabled(true);
        }
    }

    protected void callParentRender(Component parent, EditorContext<String> context, EditorListener<String> listener) { super.render(parent, context, listener); }
}
