/*
 * AbstractTool.java
 *
 * Created on 8 novembre 2007, 15:55
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package fr.gouv.finances.cp.xemelios.tools;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URL;
import javax.swing.JFrame;

/**
 *
 * @author chm
 */
public abstract class AbstractTool {
    
    /**
     * Checks if the Plugin is running in or outside Xemelios.
     * @return true if Xemelios is running in the same JVM.
     */
    public static boolean isInXemelios() {
        URL url = AbstractTool.class.getClassLoader().getResource("fr/gouv/finances/cp/xemelios/ui/MainWindow.class");
        if(url!=null) {
            // la classe est dans le Class-Path
            // on essaie de la charger sans la referencer
            try {
                Class clazz = Class.forName("fr.gouv.finances.cp.xemelios.ui.MainWindow");
                Field fld = clazz.getDeclaredField("instance");
                if((fld.getModifiers() & Modifier.STATIC) >0) {
                    Object value = fld.get(null);
                    return (value!=null);
                }
            } catch(Throwable t) {}
        }
        return false;
    }
    
    public abstract void setParentWindow(JFrame parentWindow);
    public abstract void run();
}
