/*
 *  Initiative - A role playing utility to track turns
 *  Copyright (C) 2002 Devon D Jones
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  The author of this program grants you the ability to use this code
 *  in conjunction with code that is covered under the Open Gaming License
 *
 */
package org.evilsoft.gaming.Init;

import org.openide.actions.*;
import org.openide.cookies.*;
import org.openide.filesystems.FileObject;
import org.openide.loaders.*;
import org.openide.nodes.*;
import org.openide.util.HelpCtx;
import org.openide.TopManager;
import org.openide.NotifyDescriptor;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

/** Represents a Tutorial object in the Repository.
 *
 * @author  devon
 */
public class InitiativeDataObject extends MultiDataObject {
    public Document character;
    public InitiativeDataObject(FileObject pf, InitiativeDataLoader loader) throws DataObjectExistsException {
        super(pf, loader);
        init();
    }
    
    private void init() {
        TopManager tm = TopManager.getDefault();
        CookieSet cookies = getCookieSet();
        cookies.add(new InitiativeOpenSupport(this));
        
        try {
          FileObject fo = getPrimaryFile();
          SAXBuilder SB = new SAXBuilder();
          character = SB.build(fo.getInputStream());
        }
        catch(Exception e) {
            tm.notifyException(e);
        }

        // blank out the cookie set for this data object:
        // Add whatever capabilities you need, e.g.:
        /*
        cookies.add (new ExecSupport (getPrimaryEntry ()));
        // See Editor Support template in Editor API:
        cookies.add (new TutorialEditorSupport (this));
        cookies.add (new CompilerSupport.Compile (getPrimaryEntry ()));
        cookies.add (new CompilerSupport.Build (getPrimaryEntry ()));
        cookies.add (new CompilerSupport.Clean (getPrimaryEntry ()));
        cookies.add (new OpenCookie () {
                public void open () {
                    // do something...but usually you want to use OpenSupport instead
                }
            });
         */
    }
    
    public HelpCtx getHelpCtx() {
        return HelpCtx.DEFAULT_HELP;
        // If you add context help, change to:
        // return new HelpCtx (TutorialDataObject.class);
    }
    
    protected Node createNodeDelegate() {
        return new InitiativeDataNode(this);
    }
    
    /* If you made an Editor Support you will want to add these methods:
     
    final void addSaveCookie (SaveCookie save) {
        getCookieSet ().add (save);
    }
     
    final void removeSaveCookie (SaveCookie save) {
        getCookieSet ().remove (save);
    }
     
     */
    
}
