package caltool.caldb;

import caltool.options.*;
import java.util.*;
import mvp.*;

/****
 *
 * The UserWorkSpace contains the active calendars upon which the user is
 * working.  It has the id of the current calendar tool user, the list of
 * active calendars, and an index indicating which calendar is currently
 * active.  It also contains a list of individualized user options, some of
 * which may be different than the global calendar options.
 *
 */
public class UserWorkSpace extends Model {

    /**
     * Construct this by constructing and intializing all components.
     */
    public UserWorkSpace() {
        super(null);
        uid = System.getProperty("user.name");
        calendars = new Vector();
        options = new UserOptions();
        currentIndex = -1;

        /*
         * For immediate testing, add an empty user calendar.
         */
        calendars.add(new UserCalendar(uid));
        currentIndex = 0;

    }

    /**
     * Return the currently active calendar.  This is the calendar that the
     * user has most recently selected for performing an operation on.  If
     * there is no active calendar, return null.  Note that the case of no
     * active calendar is allowed in the specs, since the user can close down
     * all calendar display windows if she chooses.
     */
    public UserCalendar getCurrent() {
        if (currentIndex == -1) {
            return null;
        }
        return (UserCalendar) calendars.get(currentIndex);
    }

    /*-*
     * Derived data fields.
     */

    /** Unique id of the current user */
    String uid;

    /** List of active calendars */
    protected Vector calendars;

    /** Specific options set for this workspace */
    UserOptions options;


    /*-*
     * Process data fields.
     */

    /** Index of currently active calendar */
    protected int currentIndex;

}