All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.mapway.ui.client.mvc.BaseAbstractModule Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package cn.mapway.ui.client.mvc;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.ksyzt.gwt.client.common.MessageComposite;

/**
 * 模块基类.
 *
 * @author zhangjianshe
 */
public abstract class BaseAbstractModule extends MessageComposite implements IModule {


    private IModule mParentModule;
    private ModuleParameter mParameter;

    /**
     * Instantiates a new Base abstract module.
     */
    public BaseAbstractModule() {
    }


    private final static ModuleFactory FACTORY = GWT.create(ModuleFactory.class);

    /**
     * 模块工厂
     *
     * @return module factory
     */
    public static ModuleFactory getModuleFactory() {
        return FACTORY;
    }

    @Override
    public boolean initialize(IModule parentModule, ModuleParameter parameter) {
        if (parameter == null) {
            mParameter = new ModuleParameter();
        } else {
            mParameter = parameter;
        }
        mParentModule = parentModule;
        return true;
    }

    @Override
    public void unInitialize() {

    }


    @Override
    public boolean updateTools(Widget... tools) {
        if (mParentModule != null) {
            return mParentModule.updateTools(tools);
        }
        return false;
    }

    @Override
    public boolean appendTools(Widget tools) {
        if (mParentModule != null) {
            return mParentModule.appendTools(tools);

        }
        return false;
    }

    @Override
    public boolean appendTools(Widget[] tools) {
        if (mParentModule != null) {
            return mParentModule.appendTools(tools);

        }
        return false;
    }

    @Override
    public IModule getParentModule() {
        return mParentModule;
    }

    @Override
    public ModuleInfo getModuleInfo() {
        return getModuleFactory().findModuleInfo(getModuleCode());
    }

    /**
     * 获取模块代码
     *
     * @return module code
     */
    public abstract String getModuleCode();

    /**
     * Init module widget.
     *
     * @param w the w
     */
    public void initModuleWidget(Widget w) {
        initWidget(w);
    }

    @Override
    public Widget getRootWidget() {
        return this;
    }

    private List getModuleStack(IModule module) {

        List modules = new ArrayList();
        IModule p = module;
        while (p != null) {
            modules.add(p);
            p = p.getParentModule();
        }
        return modules;
    }

    /**
     * Gets module path.
     *
     * @param module the module
     * @return the module path
     */
    public List getModulePath(IModule module) {

        List r = new ArrayList();

        List modules = getModuleStack(module);

        for (IModule m : modules) {
            ModuleInfo info = m.getModuleInfo();
            SwitchModuleData d = new SwitchModuleData(info.code, info.hash);
            d.setParameters(m.getParameters());
            r.add(0, d);
        }
        return r;
    }

    @Override
    public ModuleParameter getParameters() {
        return mParameter;
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy