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

com.ksyzt.gwt.client.mainframe.MainFrame Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package com.ksyzt.gwt.client.mainframe;

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

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.ksyzt.gwt.client.common.MessageComposite;
import com.ksyzt.gwt.client.event.MessageEvent;
import com.ksyzt.gwt.client.event.MessageHandler;

// TODO: Auto-generated Javadoc

/**
 * 应用程序主框架.
 *
 * @author Administrator
 */
public class MainFrame extends MessageComposite {

    /**
     * The ui binder.
     */
    private static MainFrameUiBinder uiBinder = GWT
            .create(MainFrameUiBinder.class);

    /**
     * The Interface MainFrameUiBinder.
     */
    interface MainFrameUiBinder extends UiBinder {
    }

    /**
     * The m topbar handler.
     */
    private MessageHandler m_topbar_handler = new MessageHandler() {

        @Override
        public void onMessage(Object sender, Integer message, Object value) {
            if (message == MessageEvent.MESSAGE) {
                application.messageHandler.onMessage(sender, message, value);
            } else if (message == MessageEvent.ITEMCLICK) {
                ModuleData d = (ModuleData) value;
                switch_page(d);
            }
            if (message == MessageEvent.QUIT) {
                MessageEvent ev = new MessageEvent(message, 0);
                fireEvent(ev);
            }

        }
    };

    /**
     * 切换页面.
     *
     * @param d the d
     */
    protected void switch_page(ModuleData d) {

        if (d != null) {
            Widget page = d.getWidget();
            if (d.getWidget() == null) {
                page = d.createWidget();
            }
            if (current != page) {
                if (current != null) {
                    root.remove(current);
                }
                root.add(page);
                current = page;
            }
        }
    }

    /**
     * Instantiates a new main frame.
     */
    public MainFrame() {
        initWidget(uiBinder.createAndBindUi(this));
        topbar.addMessageHandler(m_topbar_handler);
        modules = new ArrayList();
    }

    /**
     * The topbar.
     */
    @UiField
    AppTopbar topbar;

    /**
     * The current.
     */
    Widget current;

    /**
     * The root.
     */
    @UiField
    DockLayoutPanel root;

    /**
     * The modules.
     */
    List modules;

    /**
     * The application.
     */
    AppData application;

    /**
     * Sets the application.
     *
     * @param app the new application
     */
    public void setApplication(AppData app) {
        application = app;
        topbar.initTop(application.user.realname, app.user.id);
    }

    /**
     * Adds the module factory.
     *
     * @param mf    the mf
     * @param props the props
     */
    public void addModuleFactory(IModuleFactory mf, ModuleProperties props) {

        ModuleData d = new ModuleData(application, mf, props);
        modules.add(d);
        topbar.addTab(d);
    }

    /**
     * Show module.
     *
     * @param index the index
     */
    public void showModule(int index) {
        if (index >= 0 && index < modules.size()) {
            switch_page(modules.get(index));
            topbar.setSelected(index);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy