/*
 * __NAME__.java
 *
 * Created on __DATE__
 */

package Templates.API_Support.Window_System_API;

import java.awt.Dialog;
import javax.swing.SwingUtilities;

import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
import org.openide.WizardDescriptor;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction;

/** Start a wizard.
 *
 * @author __USER__
 */
public class __Sample_Wizard__Action extends CallableSystemAction {

    public void performAction() {
        final WizardDescriptor desc = new __NAME$Action$Descriptor$MyDescriptor__();
        final Dialog dlg = DialogDisplayer.getDefault().createDialog(desc);
        // The following assumes the wizard descriptor is modal:
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    dlg.show();
                }
            });
        } catch (Exception e) { // InterruptedException, InvocationTargetException
            ErrorManager.getDefault().notify(e);
            return;
        }
        if (desc.getValue() == WizardDescriptor.FINISH_OPTION) {
            // Do whatever it is you want to do here.
            System.out.println("User finished the wizard"); // NOI18N
        } else {
            System.out.println("User closed or cancelled the wizard"); // NOI18N
        }
        // If you are using a nonmodal wizard, try this instead:
        /*
        desc.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent ev) {
                if (WizardDescriptor.PROP_VALUE.equals(ev.getPropertyName())) {
                    desc.removePropertyChangeListener(this);
                    if (WizardDescriptor.FINISH_OPTION.equals(ev.getNewValue())) {
                        // Do whatever it is you want to do here.
                        // Remember you are in the Swing event thread here, so be careful!
                        // You might use RequestProcessor.getDefault().post(Runnable) if you
                        // plan to do something other than manipulate the GUI.
                        System.out.println("User finished the wizard"); // NOI18N
                    } else {
                        System.out.println("User closed or cancelled the wizard"); // NOI18N
                    }
                }
            }
        });
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                dlg.show();
            }
        });
        // The action will exit at this point.
        */
    }

    public String getName() {
        return NbBundle.getMessage(__NAME__.class, "LBL_Action");
    }

    protected String iconResource() {
        return "__PACKAGE_AND_NAME_SLASHES__Icon.gif";
    }

    public HelpCtx getHelpCtx() {
        return HelpCtx.DEFAULT_HELP;
        // If you will provide context help then use:
        // return new HelpCtx(__NAME__.class);
    }

    /** Perform extra initialization of this action's singleton.
     * PLEASE do not use constructors for this purpose!
    protected void initialize() {
	super.initialize();
	putProperty(Action.SHORT_DESCRIPTION, NbBundle.getMessage(__NAME__.class, "HINT_Action"));
    }
    */

}
