/*
 * Created on Jul 9, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

package zemplen;

import java.util.Locale;

import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.hibernate.cfg.Configuration;

import hibergui.hibernate.SessionManager;

/**
 * @author espakm
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class Main {
	
	public static Configuration cfg = new Configuration();

    public static void main(String[] args) {
    	System.out.println(System.getProperty("os.name"));
    	System.out.println(System.getProperty("os.arch"));
    	System.setSecurityManager(null);
    	Locale.setDefault(new Locale("hu", "HU"));
//        Locale.setDefault(new Locale("en"));

        try {
        	if (args.length > 0){
        		cfg = cfg.configure(args[0]);
        	}else
        		cfg = cfg.configure();
        	
        	MainWindow app_window = new MainWindow();
        	ConfigurationDialog dlgConn = new ConfigurationDialog(app_window, cfg);
        	dlgConn.setBlockOnOpen(true);
        	dlgConn.open();
        	if (dlgConn.getReturnCode() == Window.OK) {
        		cfg = dlgConn.cfg;
        		System.out.println("Main.main() 1");
        		SessionManager.initialize(cfg);
        		System.out.println("Main.main() 2");
        		app_window.setTitle(cfg.getProperty("connection.url"));
            	app_window.setBlockOnOpen(true);
            	app_window.open();
        	}
        }
        catch (Throwable exc) {
        	exc.printStackTrace();
        }
        finally {
        	SessionManager.instance().close();
//        	Display.getCurrent().dispose();
        }
    }
}