
package com.sourcestream.plugin.idea.restclient;

import com.intellij.openapi.actionSystem.DataKeys;
import org.wiztools.restclient.ui.IdeaPlugin;

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

/**
 * Handles the tools menu action by displaying a popup menu of edit choices and processing the user's selection.
 */
public class HelpMenuAction extends BaseMenuAction
{
    private static final int VERTICAL_LOCATION = 75;

    /**
     * Constructs a new ToolsMenuAction object.
     */
    public HelpMenuAction()
    {
        popup = new JPopupMenu();

        JMenuItem item = new JMenuItem("About RESTClient");
        item.setActionCommand(IdeaPlugin.METHOD_ABOUT);
        item.addActionListener(this);
        popup.add(item);

        item = new JMenuItem("About Plugin");
        item.setActionCommand(IdeaPlugin.METHOD_ABOUT_PLUGIN);
        item.addActionListener(this);
        popup.add(item);
    }

    /**
     * Invoked when the user clicks on a popup menu item.
     *
     * @param event Popup menu click event
     */
    public void actionPerformed(ActionEvent event)
    {
        IdeaPlugin plugin = IdeaPlugin.getInstance(ideaEvent.getData(DataKeys.PROJECT));

        if (event.getActionCommand().equals(IdeaPlugin.METHOD_ABOUT))
        {
            plugin.showAboutDialog();
        }
        else if (event.getActionCommand().equals(IdeaPlugin.METHOD_ABOUT_PLUGIN))
        {
            plugin.showAboutPluginDialog();
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected int getVerticalLocation()
    {
        return VERTICAL_LOCATION;
    }
}
