package Templates.API_Support.Actions_API;

import java.awt.event.ActionEvent;
import java.awt.Component;
import javax.swing.*;

import org.openide.awt.JMenuPlus;
import org.openide.util.*;
import org.openide.util.actions.Presenter;
import org.openide.util.actions.SystemAction;

/** Action which just holds a few other SystemAction's for grouping purposes.
 *
 * @author __USER__
 */
public class __Sample_grouping__Action extends SystemAction implements Presenter.Popup /*, Presenter.Menu, Presenter.Toolbar*/ {

    public void actionPerformed(ActionEvent ev) {
        // do nothing; should not be called
    }

    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("someProp", value);
    }
    */

    /** List of system actions to be displayed within this one's toolbar or submenu. */
    private static final SystemAction[] grouped() {
        return new SystemAction[] {
            SystemAction.get(MyFirstAction.class),
            SystemAction.get(MySecondAction.class),
            null, // separator
            SystemAction.get(MyThirdAction.class),
        };
    }

    public JMenuItem getPopupPresenter() {
        JMenu menu = new JMenu(getName());
        // Conventional not to set an icon here.
        SystemAction[] grouped = grouped();
        for (int i = 0; i < grouped.length; i++) {
            SystemAction action = grouped[i];
            if (action == null) {
                menu.addSeparator();
            } else if (action instanceof Presenter.Popup) {
                menu.add (((Presenter.Popup)action).getPopupPresenter());
            }
        }
        return menu;
    }

    // Rather than use this for menu or toolbar presenters, simpler to
    // just create subfolders in your XML layer:

    /*
    public JMenuItem getMenuPresenter() {
        // JMenuPlus reported to avoid a strange Windows-specific native code bug (null pData):
        JMenu menu = new JMenuPlus(getName());
        menu.setIcon(new ImageIcon(Utilities.loadImage(iconResource())));
        SystemAction[] grouped = grouped();
        for (int i = 0; i < grouped.length; i++) {
            SystemAction action = grouped[i];
            if (action == null) {
                menu.addSeparator();
            } else if (action instanceof Presenter.Menu) {
                menu.add(((Presenter.Menu)action).getMenuPresenter());
            }
        }
        return menu;
    }

    public Component getToolbarPresenter() {
        JToolBar toolbar = new JToolBar(getName());
        SystemAction[] grouped = grouped();
        for (int i = 0; i < grouped.length; i++) {
            SystemAction action = grouped[i];
            if (action == null) {
                toolbar.addSeparator();
            } else if (action instanceof Presenter.Toolbar) {
                toolbar.add(((Presenter.Toolbar)action).getToolbarPresenter());
            }
        }
        return toolbar;
    }
    */

}
