License text

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER 
 * Copyright  2008, 2010 Oracle and/or its affiliates.  All rights reserved. 
 * Use is subject to license terms.
 * 
 * This file is available and licensed under the following license:
 * 
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met: 
 * 
 *   * Redistributions of source code must retain the above copyright notice, 
 *     this list of conditions and the following disclaimer. 
 *
 *   * Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *
 *   * Neither the name of Oracle Corporation nor the names of its contributors 
 *     may be used to endorse or promote products derived from this software 
 *     without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

    

/*
* Controller.fx
 *
 * Created on Apr 27, 2009, 7:59:08 PM
 */

package projectmanager;
import javafx.scene.Node;
import javafx.scene.control.ToggleButton;

/**
 * Controller class that takes care of screen navigation. Screen navigation is
 * centralized and abstracted here and all the view classes rely on the
 * controller to proceed to the previous or next screen.
 *
 * This class also takes care of doing the necessary initializations when the user
 * navigates from one screen to the other.
 */
public class Controller {

    public var contents: Node;
    protected var dataHandler: DataHandler = new DataHandler;
    public var taskListView: TaskListView;
    public var taskView: TaskEditorView;
    public var projListView: ProjectListView;
    public var projView: ProjectEditorView;
    public var projectSpecific: Boolean = false;


    public function showDefaultScreen() {
        if (taskListView == null) {
            taskListView = TaskListView {
                controller: this
            };
        } else {
            taskListView.populateList(taskListView.buttonGroup.selectedToggle as ToggleButton);
        }
        contents = taskListView;
        taskListView.defControl.requestFocus();
    }
    public function showTasksList(projCat: String) {
            
        if (taskListView == null) {
            taskListView = TaskListView {
                controller: this
                projCat: projCat
            };
           taskListView.buttonGroup.selectedToggle = taskListView.allButton;
          // print(projCat);
           taskListView.populateList(taskListView.buttonGroup.selectedToggle as ToggleButton,projCat);
        } else {
           taskListView.projCat = projCat;
           taskListView.buttonGroup.selectedToggle = taskListView.allButton;
           taskListView.populateList(taskListView.buttonGroup.selectedToggle as ToggleButton,projCat);
        }
        contents = taskListView;
        taskListView.defControl.requestFocus();
        //projectSpecific = true;
    }

    public function showTaskDetails(taskDetails: TaskModel) {
        if (taskView == null) {
            taskView = TaskEditorView {
                task: taskDetails
                controller: this
            };
        } else {
            taskView.task = taskDetails;
        }
        contents = taskView;
        taskView.defControl.requestFocus();
    }

    public function showTaskDetailsWithProjectCategory(taskDetails: TaskModel,
            projCat: ProjectModel ) {
        if (taskView == null) {
            taskView = TaskEditorView {
                task: taskDetails
                controller: this
            };
        }
        contents = taskView;
        taskView.defControl.requestFocus();
    }

    public function showProjectDetails () {
        if (projListView == null) {
            projListView = ProjectListView {
                chooseProject: false
                controller: this
            };
        } else {
            projListView.chooseProject = false;
            projListView.populateList();
        }
        contents = projListView;
        projListView.defControl.requestFocus();
    }

    public function showProjectsList( projTask: TaskModel,
                                chooseProject: Boolean ) {
        if (projListView == null) {
            projListView = ProjectListView {
                chooseProject: true
                task: projTask
                controller: this
            }
        } else {
            projListView.chooseProject = true;
            projListView.task = projTask
        }
        contents = projListView;
        projListView.defControl.requestFocus();
    }

    public function showProjectCategoryDetails(cat: ProjectModel):Void {
        if(cat != null) {
            if (projView == null) {
                projView = ProjectEditorView {
                    projCat: cat
                    controller: this
                }
            } else {
                projView.projCat = cat;
            }
            contents = projView;
        } else {
            if (projView == null) {
                projView = ProjectEditorView {
                    controller: this
                    projCat: null
                }
            } else {
                projView.projCat = null;
                projView.initializeProject(cat != null);
            }
            contents = projView;
        }
        projView.defControl.requestFocus();
    }
}