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

org.uqbar.arena.SimpleApplication Maven / Gradle / Ivy

There is a newer version: 3.6.3
Show newest version
package org.uqbar.arena;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.ConstructorUtils;
import org.uqbar.arena.windows.Window;
import org.uqbar.arena.windows.WindowOwner;
import org.uqbar.commons.utils.ReflectionUtils;
import org.uqbar.lacar.ui.model.ApplicationRunner;

/**
 * Simple app implementation to work with MainWindows.
 * We still need to have this and cannot create the app on-the-fly from the window itself
 * because we need to go through the {@link ApplicationRunner} first so it can perform
 * initialization tasks like setting jface realm and creating a display.
 * Otherwise the window tries to create a model object which could be using
 * some jfacedatabinding observables that won't get any Realm exploding
 * 
 * 
 * @author jfernandes
 */
public class SimpleApplication extends Application {
	private Class> classOfWindow;

	public SimpleApplication(Class> classOfWindow) {
		this.classOfWindow = classOfWindow;
	}

	@Override
	protected Window createMainWindow() {
		try {
			Constructor constructor = ConstructorUtils.getAccessibleConstructor(classOfWindow, WindowOwner.class);
			return (Window) constructor.newInstance(this);
		} catch (Exception e) {
			throw new ArenaException("La clase de la ventana debe tener un constructor con un unico parametro de tipo 'WindowOwner'", e);
		}
	}
	
	public static void start(Class> classOfWindow) {
		new SimpleApplication(classOfWindow).start();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy