<commit_before>/**
 * Tree logic based on http://www.adobe.com/devnet/flex/quickstart/working_with_tree/src/TreeKeepOpen/index.html
 */

package org.arisgames.editor.view
{

import flash.events.MouseEvent;
import flash.geom.Point;
import mx.collections.ArrayCollection;
import mx.containers.Panel;
import mx.containers.VBox;
import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.Image;
import mx.controls.Menu;
import mx.controls.TextInput;
import mx.effects.Glow;
import mx.events.DragEvent;
import mx.events.DynamicEvent;
import mx.events.FlexEvent;
import mx.events.ListEvent;
import mx.events.MenuEvent;
import mx.managers.DragManager;
import mx.rpc.Responder;
import org.arisgames.editor.components.PaletteTree;
import org.arisgames.editor.data.arisserver.Item;
import org.arisgames.editor.data.arisserver.Media;
import org.arisgames.editor.data.arisserver.NPC;
import org.arisgames.editor.data.arisserver.Node;
import org.arisgames.editor.data.businessobjects.ObjectPaletteItemBO;
import org.arisgames.editor.models.GameModel;
import org.arisgames.editor.services.AppServices;
import org.arisgames.editor.util.AppConstants;
import org.arisgames.editor.util.AppDynamicEventManager;
import org.arisgames.editor.util.AppUtils;

public class GameEditorObjectPaletteView extends VBox
{
    [Bindable] public var objectPalette:Panel;
    [Bindable] public var addObjectButton:Button;
    [Bindable] public var addFolderButton:Button;
	[Bindable] public var editQuestsButton:Button;
	[Bindable] public var editDialogButton:Button;
	[Bindable] public var editGoogleMapButton:Button;
    [Bindable] public var trashIcon:Image;
    [Bindable] public var glowImage:Glow;

    // Object Palette Tree Objects
    [Bindable] public var paletteTree:PaletteTree;
    [Bindable] public var open:Object = new Object();
    [Bindable] public var refreshData:Boolean = false;
    [Bindable] public var treeModel:ArrayCollection;
    [Bindable] public var provider:String = "treeModel";

    /**
     * Constructor
     */
    public function GameEditorObjectPaletteView()
    {
        super();
        this.addEventListener(FlexEvent.CREATION_COMPLETE, onComplete);

        // Setup Tree Data
        trace("This is the treeModel being glued to the GameModel.  The size is currently: '" + GameModel.getInstance().game.gameObjects.length + "'");
        treeModel = GameModel.getInstance().game.gameObjects;
    }

    private function onComplete(event:FlexEvent): void
    {
        addObjectButton.addEventListener(MouseEvent.CLICK, addObjectButtonOnClick);
        addFolderButton.addEventListener(MouseEvent.CLICK, addFolderButtonOnClick);
		editQuestsButton.addEventListener(MouseEvent.CLICK, editQuestsButtonOnClick);
		editDialogButton.addEventListener(MouseEvent.CLICK, editDialogButtonOnClick);
        paletteTree.addEventListener(ListEvent.ITEM_EDIT_END, handlePaletteObjectDataEditFinished);
        AppDynamicEventManager.getInstance().addEventListener(AppConstants.APPLICATIONDYNAMICEVENT_REDRAWOBJECTPALETTE, handleRedrawTreeEvent);
    }

    private function handlePaletteObjectDataEditFinished(evt:ListEvent):void
    {
        trace("handlePaletteObjectDataEditFinished called...");

        // Ben's Crazy Idea To Capture Newly Edited Data Starts Here
        var ti:TextInput = paletteTree.itemEditorInstance as TextInput;
        trace("Hopefully new value = '" + ti.text + "'");
        // Ben's Crazy Idea To Capture Newly Edited Data Ends Here

        var index:Number = evt.rowIndex;
        var obj:ObjectPaletteItemBO = treeModel.getItemAt(index) as ObjectPaletteItemBO;
        trace("index = '" + index + "'; game id = '" + GameModel.getInstance().game.gameId + "'; object type = '" + obj.objectType + "'");

        if (obj.objectType == AppConstants.CONTENTTYPE_CHARACTER_DATABASE)
        {
                trace("It's a character...");
                var npc:NPC = new NPC();
                npc.npcId = obj.objectId;
                npc.name = ti.text;
                AppServices.getInstance().saveCharacter(GameModel.getInstance().game.gameId, npc, new Responder(handleSaveItem, handleFault));
        }
        else if (obj.objectType == AppConstants.CONTENTTYPE_ITEM_DATABASE)
        {
                trace("It's an item...");
                var it:Item = new Item();
                it.itemId = obj.objectId;
                it.name = ti.text;
                AppServices.getInstance().saveItem(GameModel.getInstance().game.gameId, it, new Responder(handleSaveItem, handleFault));
        }
        else if (obj.objectType == AppConstants.CONTENTTYPE_PAGE_DATABASE)
        {
                trace("It's a page...");
                var node:Node = new Node();
                node.nodeId = obj.objectId;
                node.title = ti.text;
                AppServices.getInstance().savePage(GameModel.getInstance().game.gameId, node, new Responder(handleSavePage, handleFault));
        }
        else if (obj.isFolder())
        {
            trace("It's a folder, with ID = '" + obj.id + "'");
            obj.name = ti.text;
            AppServices.getInstance().saveFolder(GameModel.getInstance().game.gameId, obj, new Responder(handleSaveFolder, handleFault));
        }
        else
        {
            trace("No germane Content Type found, so this palette object was NOT saved!!!!!");
        }

        trace("handlePaletteObjectDataEditFinished finished.");
    }

    private function addObjectButtonOnClick(evt:MouseEvent):void
    {
        var pt:Point = new Point();
        var myMenu:Menu;

        var myMenuData:Array = [{label: AppConstants.CONTENTTYPE_CHARACTER, type: "normal"}, {label: AppConstants.CONTENTTYPE_ITEM, type: "normal"}, {label: AppConstants.CONTENTTYPE_PAGE, type: "normal"}];

        myMenu = Menu.createMenu(objectPalette, myMenuData, false);
        myMenu.addEventListener("itemClick", menuHandler);

        // Calculate position of Menu in Application's coordinates.
        pt.x = addObjectButton.x;
        pt.y = addObjectButton.y;
        pt = addObjectButton.localToGlobal(pt);

        myMenu.show(pt.x + 30, pt.y - 50); // WB Magic number values here, play around with them as needed
    }

    private function addFolderButtonOnClick(evt:MouseEvent):void
    {
        trace("addFolderButtonOnClick() started...");
        var o:ObjectPaletteItemBO = new ObjectPaletteItemBO(true);
        o.id = 0;
        o.name = "New Folder " + new Date();
        this.addObjectPaletteItem(o);
    }
	
	private function editQuestsButtonOnClick(evt:MouseEvent):void 
	{
		trace("editQuestsButtonOnClick() started... ");
		var de:DynamicEvent = new DynamicEvent(AppConstants.DYNAMICEVENT_OPENQUESTSMAP);
		AppDynamicEventManager.getInstance().dispatchEvent(de);
	}
	
	private function editDialogButtonOnClick(evt:MouseEvent):void
	{
		trace("editDialogButtonOnClick() started... ");
	}

    private function menuHandler(event:MenuEvent):void
    {
        trace("menu handler is called; label = '" + event.label + "'");
        var stuff:String = event.label;
        if (AppConstants.CONTENTTYPE_CHARACTER == stuff)
        {
            trace("add a character to the object palette...");
            var o:ObjectPaletteItemBO = new ObjectPaletteItemBO(false);
            o.name = "Unnamed Character";
            o.objectType = AppConstants.CONTENTTYPE_CHARACTER_DATABASE;
            o.iconMediaId = AppConstants.DEFAULT_ICON_MEDIA_ID_NPC;
            this.addObjectPaletteItem(o);
        }
        else if (AppConstants.CONTENTTYPE_ITEM == stuff)
        {
            trace("add an item to the object palette...");
            var i:ObjectPaletteItemBO = new ObjectPaletteItemBO(false);
            i.name = "Unnamed Item";
            i.objectType = AppConstants.CONTENTTYPE_ITEM_DATABASE;
            i.iconMediaId = AppConstants.DEFAULT_ICON_MEDIA_ID_ITEM;
            this.addObjectPaletteItem(i);
        }
        else if (AppConstants.CONTENTTYPE_PAGE == stuff)
        {
            trace("add a page to the object palette...");
            var p:ObjectPaletteItemBO = new ObjectPaletteItemBO(false);
            p.name = "Unnamed Plaque";
            p.objectType = AppConstants.CONTENTTYPE_PAGE_DATABASE;
            p.iconMediaId = AppConstants.DEFAULT_ICON_MEDIA_ID_PLAQUE;
            this.addObjectPaletteItem(p);
        }
        trace("Done with menuHandler.");
    }

    public function addObjectPaletteItem(item:ObjectPaletteItemBO):void
    {
        trace("Started addObjectPaletteItem() with item's object type = '" + item.objectType + "'");
        AppUtils.printPaletteObjectDataModel();

        // Save To Database
        if (item.objectType == AppConstants.CONTENTTYPE_CHARACTER_DATABASE)
        {
            var npc:NPC = new NPC();
            npc.npcId = 0;
            npc.name = item.name;
            npc.iconMediaId = item.iconMediaId;
            AppServices.getInstance().saveCharacter(GameModel.getInstance().game.gameId, npc, new Responder(handleCreateCharacter, handleFault));
            trace("Just finished calling saveCharacter() for name = '" + item.name + "'.");
        }
        else if (item.objectType == AppConstants.CONTENTTYPE_ITEM_DATABASE)
        {
            var it:Item = new Item();
            it.itemId = 0;
            it.name = item.name;
            it.iconMediaId = item.iconMediaId;
            AppServices.getInstance().saveItem(GameModel.getInstance().game.gameId, it, new Responder(handleCreateItem, handleFault));
            trace("Just finished calling saveItem() for name = '" + item.name + "'.");
        }
        else if (item.objectType == AppConstants.CONTENTTYPE_PAGE_DATABASE)
        {
            var node:Node = new Node();
            node.nodeId = 0;
            node.title = item.name;
            node.iconMediaId = item.iconMediaId;
            AppServices.getInstance().savePage(GameModel.getInstance().game.gameId, node, new Responder(handleCreatePage, handleFault));
            trace("Just finished calling savePage() for name = '" + item.name + "'.");
        }
        else if (item.isFolder())
        {
            trace("Item is a folder, so do initial save of it here.")
            AppServices.getInstance().saveFolder(GameModel.getInstance().game.gameId, item, new Responder(handleSaveFolder, handleFault));
        }
        else
        {
            trace("***** addObjectPaletteItem DID NOT SAVE core data! *****");
        }
        trace("Done with save to database.  Item ID = '" + item.objectId + "'");

        if (item.isFolder())
        {
            treeModel.addItemAt(item, 0);
        }
        else
        {
            treeModel.addItem(item);
        }
        trace("tree data model updated....");
        AppUtils.printPaletteObjectDataModel();

        open = paletteTree.openItems;
        refreshData = true;
        trace("End of addObjectPaletteItem()");
    }

    private function handleRedrawTreeEvent(evt:DynamicEvent):void
    {
        trace("In handleRefreshTreeEvent...");
        refreshData = true;
        this.renderTree();
        trace("Done in handleRefreshTreeEvent.");
    }

    public function renderTree():void
    {
//        trace("renderTree() called...");
        if (refreshData)
        {
            trace("refreshData is true, so going to refresh the data on the tree.");
            AppUtils.printPaletteObjectDataModel();
            // Refresh Tree on update.
            paletteTree.invalidateList();
            refreshData = false;
            paletteTree.openItems = open;
            // Validate and update properties
            // of the Tree and redraw it if necessary.
            paletteTree.validateNow();
        }
//        trace("renderTree() done.");
    }

    public function trashDragEnterHandler(evt:DragEvent):void
    {
        // Get the drop target component from the event object.
        var dropTarget:Image = evt.currentTarget as Image;

        trace("Drag Source = '" + evt.dragSource + "'");

        var itemsArray:Array = evt.dragSource.dataForFormat('treeItems') as Array;
        trace("itemsArray created with size = '" + itemsArray.length + "'");

        var it:ObjectPaletteItemBO = itemsArray[0];
        trace("Object: Id = '" + it.id +"'; is Folder? = '" + it.isFolder() + "'; Name = '" + it.name + "'");

        // If folder check all items in data model to see if any point to it before allowing deletion.
        var okDrop:Boolean = true;
        if (it.isFolder())
        {
            trace("Dragged Object is a folder, so check to see if it's got any children before allowing deletion.")
            if (it.children.length > 0)
            {
                trace("This folder has childre, so can't allow it to be deleted.");
                okDrop = false;
            }
        }

        if (okDrop)
        {
            // Trick to make effect happen
            trashIcon.visible = false;
            trashIcon.visible = true;

            // Accept the drop.
            DragManager.acceptDragDrop(dropTarget);
        }
        else
        {
            Alert.show("This folder has items in it and can't be deleted until they are first removed.  Please do so and then try deleting the folder again.", "Can't Delete Folder Yet");
        }
    }

    public function trashDragExitHandler(evt:DragEvent):void
    {
        // Stop Effect And Reset Trash Bin To Original State
        glowImage.end();<commit_msg>edited the addNewItem/Plaque/Character popup-menu for location;<commit_after>/**
 * Tree logic based on http://www.adobe.com/devnet/flex/quickstart/working_with_tree/src/TreeKeepOpen/index.html
 */

package org.arisgames.editor.view
{

import flash.events.MouseEvent;
import flash.geom.Point;
import mx.collections.ArrayCollection;
import mx.containers.Panel;
import mx.containers.VBox;
import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.Image;
import mx.controls.Menu;
import mx.controls.TextInput;
import mx.effects.Glow;
import mx.events.DragEvent;
import mx.events.DynamicEvent;
import mx.events.FlexEvent;
import mx.events.ListEvent;
import mx.events.MenuEvent;
import mx.managers.DragManager;
import mx.rpc.Responder;
import org.arisgames.editor.components.PaletteTree;
import org.arisgames.editor.data.arisserver.Item;
import org.arisgames.editor.data.arisserver.Media;
import org.arisgames.editor.data.arisserver.NPC;
import org.arisgames.editor.data.arisserver.Node;
import org.arisgames.editor.data.businessobjects.ObjectPaletteItemBO;
import org.arisgames.editor.models.GameModel;
import org.arisgames.editor.services.AppServices;
import org.arisgames.editor.util.AppConstants;
import org.arisgames.editor.util.AppDynamicEventManager;
import org.arisgames.editor.util.AppUtils;

public class GameEditorObjectPaletteView extends VBox
{
    [Bindable] public var objectPalette:Panel;
    [Bindable] public var addObjectButton:Button;
    [Bindable] public var addFolderButton:Button;
	[Bindable] public var editQuestsButton:Button;
	[Bindable] public var editDialogButton:Button;
	[Bindable] public var editGoogleMapButton:Button;
    [Bindable] public var trashIcon:Image;
    [Bindable] public var glowImage:Glow;

    // Object Palette Tree Objects
    [Bindable] public var paletteTree:PaletteTree;
    [Bindable] public var open:Object = new Object();
    [Bindable] public var refreshData:Boolean = false;
    [Bindable] public var treeModel:ArrayCollection;
    [Bindable] public var provider:String = "treeModel";

    /**
     * Constructor
     */
    public function GameEditorObjectPaletteView()
    {
        super();
        this.addEventListener(FlexEvent.CREATION_COMPLETE, onComplete);

        // Setup Tree Data
        trace("This is the treeModel being glued to the GameModel.  The size is currently: '" + GameModel.getInstance().game.gameObjects.length + "'");
        treeModel = GameModel.getInstance().game.gameObjects;
    }

    private function onComplete(event:FlexEvent): void
    {
        addObjectButton.addEventListener(MouseEvent.CLICK, addObjectButtonOnClick);
        addFolderButton.addEventListener(MouseEvent.CLICK, addFolderButtonOnClick);
		editQuestsButton.addEventListener(MouseEvent.CLICK, editQuestsButtonOnClick);
		editDialogButton.addEventListener(MouseEvent.CLICK, editDialogButtonOnClick);
        paletteTree.addEventListener(ListEvent.ITEM_EDIT_END, handlePaletteObjectDataEditFinished);
        AppDynamicEventManager.getInstance().addEventListener(AppConstants.APPLICATIONDYNAMICEVENT_REDRAWOBJECTPALETTE, handleRedrawTreeEvent);
    }

    private function handlePaletteObjectDataEditFinished(evt:ListEvent):void
    {
        trace("handlePaletteObjectDataEditFinished called...");

        // Ben's Crazy Idea To Capture Newly Edited Data Starts Here
        var ti:TextInput = paletteTree.itemEditorInstance as TextInput;
        trace("Hopefully new value = '" + ti.text + "'");
        // Ben's Crazy Idea To Capture Newly Edited Data Ends Here

        var index:Number = evt.rowIndex;
        var obj:ObjectPaletteItemBO = treeModel.getItemAt(index) as ObjectPaletteItemBO;
        trace("index = '" + index + "'; game id = '" + GameModel.getInstance().game.gameId + "'; object type = '" + obj.objectType + "'");

        if (obj.objectType == AppConstants.CONTENTTYPE_CHARACTER_DATABASE)
        {
                trace("It's a character...");
                var npc:NPC = new NPC();
                npc.npcId = obj.objectId;
                npc.name = ti.text;
                AppServices.getInstance().saveCharacter(GameModel.getInstance().game.gameId, npc, new Responder(handleSaveItem, handleFault));
        }
        else if (obj.objectType == AppConstants.CONTENTTYPE_ITEM_DATABASE)
        {
                trace("It's an item...");
                var it:Item = new Item();
                it.itemId = obj.objectId;
                it.name = ti.text;
                AppServices.getInstance().saveItem(GameModel.getInstance().game.gameId, it, new Responder(handleSaveItem, handleFault));
        }
        else if (obj.objectType == AppConstants.CONTENTTYPE_PAGE_DATABASE)
        {
                trace("It's a page...");
                var node:Node = new Node();
                node.nodeId = obj.objectId;
                node.title = ti.text;
                AppServices.getInstance().savePage(GameModel.getInstance().game.gameId, node, new Responder(handleSavePage, handleFault));
        }
        else if (obj.isFolder())
        {
            trace("It's a folder, with ID = '" + obj.id + "'");
            obj.name = ti.text;
            AppServices.getInstance().saveFolder(GameModel.getInstance().game.gameId, obj, new Responder(handleSaveFolder, handleFault));
        }
        else
        {
            trace("No germane Content Type found, so this palette object was NOT saved!!!!!");
        }

        trace("handlePaletteObjectDataEditFinished finished.");
    }

    private function addObjectButtonOnClick(evt:MouseEvent):void
    {
        var pt:Point = new Point();
        var myMenu:Menu;

        var myMenuData:Array = [{label: AppConstants.CONTENTTYPE_CHARACTER, type: "normal"}, {label: AppConstants.CONTENTTYPE_ITEM, type: "normal"}, {label: AppConstants.CONTENTTYPE_PAGE, type: "normal"}];

        myMenu = Menu.createMenu(objectPalette, myMenuData, false);
        myMenu.addEventListener("itemClick", menuHandler);

        // Calculate position of Menu in Application's coordinates.
        pt.x = addObjectButton.x;
        pt.y = addObjectButton.y;
        pt = addObjectButton.localToGlobal(pt);

        myMenu.show(pt.x + 0, pt.y - 66); // WB Magic number values here, play around with them as needed
    }

    private function addFolderButtonOnClick(evt:MouseEvent):void
    {
        trace("addFolderButtonOnClick() started...");
        var o:ObjectPaletteItemBO = new ObjectPaletteItemBO(true);
        o.id = 0;
        o.name = "New Folder " + new Date();
        this.addObjectPaletteItem(o);
    }
	
	private function editQuestsButtonOnClick(evt:MouseEvent):void 
	{
		trace("editQuestsButtonOnClick() started... ");
		var de:DynamicEvent = new DynamicEvent(AppConstants.DYNAMICEVENT_OPENQUESTSMAP);
		AppDynamicEventManager.getInstance().dispatchEvent(de);
	}
	
	private function editDialogButtonOnClick(evt:MouseEvent):void
	{
		trace("editDialogButtonOnClick() started... ");
	}

    private function menuHandler(event:MenuEvent):void
    {
        trace("menu handler is called; label = '" + event.label + "'");
        var stuff:String = event.label;
        if (AppConstants.CONTENTTYPE_CHARACTER == stuff)
        {
            trace("add a character to the object palette...");
            var o:ObjectPaletteItemBO = new ObjectPaletteItemBO(false);
            o.name = "Unnamed Character";
            o.objectType = AppConstants.CONTENTTYPE_CHARACTER_DATABASE;
            o.iconMediaId = AppConstants.DEFAULT_ICON_MEDIA_ID_NPC;
            this.addObjectPaletteItem(o);
        }
        else if (AppConstants.CONTENTTYPE_ITEM == stuff)
        {
            trace("add an item to the object palette...");
            var i:ObjectPaletteItemBO = new ObjectPaletteItemBO(false);
            i.name = "Unnamed Item";
            i.objectType = AppConstants.CONTENTTYPE_ITEM_DATABASE;
            i.iconMediaId = AppConstants.DEFAULT_ICON_MEDIA_ID_ITEM;
            this.addObjectPaletteItem(i);
        }
        else if (AppConstants.CONTENTTYPE_PAGE == stuff)
        {
            trace("add a page to the object palette...");
            var p:ObjectPaletteItemBO = new ObjectPaletteItemBO(false);
            p.name = "Unnamed Plaque";
            p.objectType = AppConstants.CONTENTTYPE_PAGE_DATABASE;
            p.iconMediaId = AppConstants.DEFAULT_ICON_MEDIA_ID_PLAQUE;
            this.addObjectPaletteItem(p);
        }
        trace("Done with menuHandler.");
    }

    public function addObjectPaletteItem(item:ObjectPaletteItemBO):void
    {
        trace("Started addObjectPaletteItem() with item's object type = '" + item.objectType + "'");
        AppUtils.printPaletteObjectDataModel();

        // Save To Database
        if (item.objectType == AppConstants.CONTENTTYPE_CHARACTER_DATABASE)
        {
            var npc:NPC = new NPC();
            npc.npcId = 0;
            npc.name = item.name;
            npc.iconMediaId = item.iconMediaId;
            AppServices.getInstance().saveCharacter(GameModel.getInstance().game.gameId, npc, new Responder(handleCreateCharacter, handleFault));
            trace("Just finished calling saveCharacter() for name = '" + item.name + "'.");
        }
        else if (item.objectType == AppConstants.CONTENTTYPE_ITEM_DATABASE)
        {
            var it:Item = new Item();
            it.itemId = 0;
            it.name = item.name;
            it.iconMediaId = item.iconMediaId;
            AppServices.getInstance().saveItem(GameModel.getInstance().game.gameId, it, new Responder(handleCreateItem, handleFault));
            trace("Just finished calling saveItem() for name = '" + item.name + "'.");
        }
        else if (item.objectType == AppConstants.CONTENTTYPE_PAGE_DATABASE)
        {
            var node:Node = new Node();
            node.nodeId = 0;
            node.title = item.name;
            node.iconMediaId = item.iconMediaId;
            AppServices.getInstance().savePage(GameModel.getInstance().game.gameId, node, new Responder(handleCreatePage, handleFault));
            trace("Just finished calling savePage() for name = '" + item.name + "'.");
        }
        else if (item.isFolder())
        {
            trace("Item is a folder, so do initial save of it here.")
            AppServices.getInstance().saveFolder(GameModel.getInstance().game.gameId, item, new Responder(handleSaveFolder, handleFault));
        }
        else
        {
            trace("***** addObjectPaletteItem DID NOT SAVE core data! *****");
        }
        trace("Done with save to database.  Item ID = '" + item.objectId + "'");

        if (item.isFolder())
        {
            treeModel.addItemAt(item, 0);
        }
        else
        {
            treeModel.addItem(item);
        }
        trace("tree data model updated....");
        AppUtils.printPaletteObjectDataModel();

        open = paletteTree.openItems;
        refreshData = true;
        trace("End of addObjectPaletteItem()");
    }

    private function handleRedrawTreeEvent(evt:DynamicEvent):void
    {
        trace("In handleRefreshTreeEvent...");
        refreshData = true;
        this.renderTree();
        trace("Done in handleRefreshTreeEvent.");
    }

    public function renderTree():void
    {
//        trace("renderTree() called...");
        if (refreshData)
        {
            trace("refreshData is true, so going to refresh the data on the tree.");
            AppUtils.printPaletteObjectDataModel();
            // Refresh Tree on update.
            paletteTree.invalidateList();
            refreshData = false;
            paletteTree.openItems = open;
            // Validate and update properties
            // of the Tree and redraw it if necessary.
            paletteTree.validateNow();
        }
//        trace("renderTree() done.");
    }

    public function trashDragEnterHandler(evt:DragEvent):void
    {
        // Get the drop target component from the event object.
        var dropTarget:Image = evt.currentTarget as Image;

        trace("Drag Source = '" + evt.dragSource + "'");

        var itemsArray:Array = evt.dragSource.dataForFormat('treeItems') as Array;
        trace("itemsArray created with size = '" + itemsArray.length + "'");

        var it:ObjectPaletteItemBO = itemsArray[0];
        trace("Object: Id = '" + it.id +"'; is Folder? = '" + it.isFolder() + "'; Name = '" + it.name + "'");

        // If folder check all items in data model to see if any point to it before allowing deletion.
        var okDrop:Boolean = true;
        if (it.isFolder())
        {
            trace("Dragged Object is a folder, so check to see if it's got any children before allowing deletion.")
            if (it.children.length > 0)
            {
                trace("This folder has children, so can't allow it to be deleted.");
                okDrop = false;
            }
        }

        if (okDrop)
        {
            // Trick to make effect happen
            trashIcon.visible = false;
            trashIcon.visible = true;

            // Accept the drop.
            DragManager.acceptDragDrop(dropTarget);
        }
        else
        {
            Alert.show("This folder has items in it and can't be deleted until they are first removed.  Please do so and then try deleting the folder again.", "Can't Delete Folder Yet");
        }
    }

    public function trashDragExitHandler(evt:DragEvent):void
    {
        // Stop Effect And Reset Trash Bin To Original State
        glowImage.end();
{'fraction_non_alphanumeric': 0.10790725326991676, 'fraction_numerical': 0.000780321046373365, 'mean_word_length': 2.6139384987243184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4743202', 'n_tokens_mistral': 7633, 'n_tokens_neox': 7431, 'n_words': 1682}