package kiyut.alkitab.modules.downloader.actions;

import javax.swing.SwingUtilities;
import org.crosswire.bibledesktop.book.install.InternetWarning;
import org.crosswire.bibledesktop.book.install.SitesPane;
import org.crosswire.jsword.util.WebWarning;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction;
import org.openide.windows.WindowManager;

/**
 * Action that will open downloader panel.
 * It delegates into org.crosswire.bibledesktop.book.install.SitesPane
 * 
 */
public class DownloaderAction extends CallableSystemAction {

    @Override
    public void performAction() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                if (WebWarning.instance().isShown()) {
                    int choide = InternetWarning.showDialog(WindowManager.getDefault().getMainWindow(), "?");
                    if (choide != InternetWarning.GRANTED) {
                        return;
                    }
                }
                
                SitesPane sitesPane = new SitesPane();
                sitesPane.showInDialog(WindowManager.getDefault().getMainWindow());
            } 
        });
    }

    @Override
    public String getName() {
        return NbBundle.getMessage(DownloaderAction.class, "CTL_DownloaderAction");
    }

    /* @Override
    protected String iconResource() {
        return NbBundle.getMessage(NewViewAction.class, "ICON_DownloaderAction");
    } */
    
    @Override
    public HelpCtx getHelpCtx() {
        return HelpCtx.DEFAULT_HELP;
    }

    @Override
    protected boolean asynchronous() {
        return false;
    }
}
