package com.ecep.contract.controller.tab;

import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;

import com.ecep.contract.controller.BaseController;
import com.ecep.contract.util.UITools;

public abstract class AbstGenericTabSkin<C extends BaseController> implements TabSkin {
    private static final Logger logger = LoggerFactory.getLogger(AbstGenericTabSkin.class);
    /**
     * 控制器
     */
    protected C controller;

    public AbstGenericTabSkin(C controller) {
        this.controller = controller;
    }

    public <T> T getBean(Class<T> requiredType) throws BeansException {
        return controller.getCachedBean(requiredType);
    }

    public <T> T getCachedBean(Class<T> requiredType) throws BeansException {
        return controller.getCachedBean(requiredType);
    }

    protected void setStatus(String status) {
        controller.setStatus(status);
    }

    protected Locale getLocale() {
        return controller.getLocale();
    }

    @Override
    public void handleException(String message, Throwable ex) {
        if (controller != null) {
            controller.handleException(message, ex);
            return;
        }

        if (logger.isErrorEnabled()) {
            logger.error(message, ex);
        }
        UITools.showExceptionAndWait(message, ex);
    }

}
