Package com.nexirius.ulc.application

Source Code of com.nexirius.ulc.application.ULCApplication

//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
package com.nexirius.ulc.application;

import com.nexirius.framework.datamodel.DataModel;
import com.nexirius.framework.datamodel.DataModelCommandVector;
import com.nexirius.framework.menu.MenuParser;
import com.nexirius.ulc.ulcviewer.ULCViewerCreator;
import com.nexirius.ulc.ulcviewer.ULCViewerFactory;
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ApplicationContext;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.util.ULCIcon;
import com.ulcjava.base.application.event.IWindowListener;
import com.ulcjava.base.application.event.WindowEvent;

public abstract class ULCApplication extends AbstractApplication {
    private ULCViewerFactory ulcViewerFactory;
    private ULCFrame mainFrame;
    private ULCBoxPane mainPanel;
    private DataModelCommandVector applicationCommands = null;

    protected void initialise() throws Exception {
//        DialogManager.setErrorAdaptor(this); TODO ULC
//        DialogManager.setAskAdaptor(this);  TODO ULC
        ULCDialogManager.init(this);
        preInit();
        createApplication();
        init();
        getMainFrame().setVisible(true);
        postInit();
    }

    private ULCFrame getMainFrame() {
        return mainFrame;
    }

    private void createApplication()
            throws Exception {
        applicationCommands = getApplicationModel().getMethods();
        createFrame();
        createMenu();
//        createStatusLine(); // TODO ULC
        getMainFrame().addWindowListener(new ApplicationWindowListener());
    }

    protected void createMenu() {
        ULCMenuCreator ulcMenuCreator = new ULCMenuCreator(getUlcFactory(), applicationCommands);

        try {
            MenuParser parser = new MenuParser(getApplicationName() + ".menu");

            parser.parse(ulcMenuCreator);
        } catch (Exception e) {
            e.printStackTrace()//TODO
        }

        getMainFrame().setMenuBar(ulcMenuCreator.getMenuBar());
    }

    protected void createFrame() {
        mainFrame = new ULCFrame(getApplicationTitle());
        ULCIcon icon = getApplicationIcon();

//        DialogManager.toplevelFrame = mainFrame;

        if (icon != null) {
            mainFrame.setIconImage(icon);
        }

        mainFrame.setDefaultCloseOperation(ULCFrame.DO_NOTHING_ON_CLOSE);

        mainPanel = new ULCBoxPane(true);
        mainFrame.add(ULCBoxPane.BOX_EXPAND_EXPAND, mainPanel);
    }

    public ULCIcon getApplicationIcon() {
        return getUlcFactory().getUlcIcon(getApplicationName());
    }

    public ULCViewerFactory getUlcFactory() {
        if (ulcViewerFactory == null) {
            ulcViewerFactory = ULCViewerFactory.getDefaultUlcInstance(getApplicationName());
        }

        return ulcViewerFactory;
    }

    public ULCBoxPane getMainULCPanel() {
        return mainPanel;
    }

    public ULCFrame getMainUlcFrame() {
        return mainFrame;
    }

    public boolean popupEdit(DataModel dataModel) {
        ULCViewerCreator ulcViewerCreator = null;
        try {
            ulcViewerCreator = getUlcFactory().getUlcViewerCreatorMap().getUlcViewerCreator(dataModel.getClass(), true);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return popupEdit(ulcViewerCreator, dataModel);
    }

    public boolean popupEdit(ULCViewerCreator viewerCreator, DataModel dataModel) {
        ULCDialogManager.instance().popup(dataModel);
        //TODO
        return true;
    }

    public void start() {
        try {
            initialise();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * @return the application title (is used as the the title of the main frame)
     */
    public String getApplicationTitle() {
        return getUlcFactory().getClientResource().getLabel(getApplicationName());
    }

    protected void preInit() {
    }

    protected void init() {
    }

    protected void postInit() {
    }

    protected void exit() {
        ApplicationContext.terminate();
    }

    public abstract String getApplicationName();

    public abstract DataModel getApplicationModel();

    private class ApplicationWindowListener implements IWindowListener {
        public void windowClosing(WindowEvent event) {
            exit();
        }
    }
}
TOP

Related Classes of com.nexirius.ulc.application.ULCApplication

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.