/* Created on 29/7/2007
 *
 * Copyright (c) 2007 Ephox Corporation.
 */
 
import com.ephox.editlive.*;
import com.ephox.editlive.common.*;
import javax.swing.JOptionPane;
 
/**
 * Class retrieves an instance of EditLive! through it's constructor. EventListener
 * is then registered with the EditLive! instance. Upon any event raised by
 * EditLive! the event is checked to see if it matches a custom menu created through
 * the advancedAPIPlugin.xml file specifying this class. If event matched custom menu, a Java swing dialog
 * appears.
 */
public class AdvancedAPIPlugin implements EventListener {
 
       ELJBean _bean;
 
    /** Constructor. Takes an instance of EditLive! and registeres an EventListener
     *
     * @param bean instance of EditLive! to be implemented in webpage
     */
       public AdvancedAPIPlugin(ELJBean bean) {
               _bean= bean;
               bean.addEditorEventListener(this);
       }
 
    /** raiseEvent method, called upon any EditLive! event. */
       public void raiseEvent(TextEvent e) {
               if (e.getActionCommand() == TextEvent.CUSTOM_ACTION) {
                       if (e.getExtraInt() == TextEvent.CustomAction.RAISE_EVENT) {
                               if (e.getExtraString().equals("displayDialog")) {
                                       e.setHandled(true);
 
                                       JOptionPane.showMessageDialog(null, "This dialog has been generated by the EditLive! Advanced APIs");
 
                                       _bean.insertHTMLAtCursor("<b>Advanced API Dialog Called</b>");
                               }
                       }
               }
       }
}