package kiyut.alkitab.windows;

import kiyut.alkitab.api.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.Action;
import kiyut.alkitab.actions.ViewSourceAction;
import org.openide.nodes.Node;
import org.openide.windows.TopComponent;

/**
 * <strong>Note:</strong> This is Netbeans Platform RCP specific API implementation
 * 
 */
public abstract class BookViewerTopComponent extends TopComponent {
    protected BookViewerNode bookViewerNode;
    
    public abstract BookViewer getBookViewer();
    
    public abstract void openURI(SwordURI uri);

    @Override
    public void componentActivated() {
        if (bookViewerNode != null) {
            setActivatedNodes(new Node[]{bookViewerNode});
        }
    }
    
    @Override
    public void componentClosed() {
        if (bookViewerNode != null) {
            bookViewerNode.closed();
        }
    }
    
    @Override
    public javax.swing.Action[] getActions() {
        Action[] actions = super.getActions();
        
        List<Action> actionList = new ArrayList<Action>(Arrays.asList(actions));
        
        // remove 
        actionList.remove(2); // separator
        actionList.remove(2); // save document
        actionList.remove(2); // clone document
        
        // add 
        actionList.add(null);  // separator
        actionList.add(new ViewSourceAction());
        
        return actionList.toArray(new Action[0]);
    }
}
