/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.naoth.rc;

import java.lang.reflect.ParameterizedType;
import javax.swing.JPanel;

/**
 * This class is in fact a dialog loader. This is used to wrap 
 * dialog into plugins.
 * @author Heinrich Mellmann
 * @param <T> 
 */
public class DialogPlugin<T extends AbstractDialog>
    implements Dialog
{
    private T instance = null;

    private Class getInstanceClass()
    {
        return ((Class)((ParameterizedType)this.getClass().
   getGenericSuperclass()).getActualTypeArguments()[0]);
    }//end getInstanceClass

    private T create()
    {
        if(instance == null)
        {
            try {
                instance = (T)(getInstanceClass().newInstance());
                instance.init();
            }catch(Exception ex){}
        }
        return instance;
    }

    @Override
    public String getDisplayName() { 
        return getInstanceClass().getSimpleName(); 
    }

    @Override
    public void dispose() {
        if(instance != null)
        {
            instance.dispose();
        }
    }//end dispose

    @Override
    public void destroy() {
        dispose();
        instance = null;
    }//end dispose
    
    
    @Override
    public JPanel getPanel() {
        return create().getPanel();
    }
}//end DialogPlugin
@@ -841,17 +841,194 @@
 tion ex)
-%7B
+%0A            %7B%0A                System.err.println(%22Could not load the dialog %22 + getInstanceClass().getSimpleName());%0A                ex.printStackTrace(System.err);%0A            
 %7D%0A      

print the exception if a dialog could not be loaded