hackedteam/rcs-console

View on GitHub
src/it/ht/rcs/console/entities/view/EntitiesView.mxml

Summary

Maintainability
Test Coverage
<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:s="library://ns.adobe.com/flex/spark"
                    xmlns:mx="library://ns.adobe.com/flex/mx"
                    xmlns:view="it.ht.rcs.console.operations.view.*"
                    xmlns:operations="it.ht.rcs.console.operations.view.operations.*"
                    xmlns:entities="it.ht.rcs.console.entities.view.*"
                    width="100%"
                    height="100%"
                    creationComplete="init()"
                    addedToStage="onAddedToStage()"
                    removedFromStage="onRemovedFromStage()">

    <fx:Script>
        <![CDATA[
            import fr.kapit.visualizer.base.uicomponent.GenericGroup;

            import it.ht.rcs.console.entities.controller.EntityManager;
            import it.ht.rcs.console.entities.model.Entity;
            import it.ht.rcs.console.entities.view.EntitiesSection;
            import it.ht.rcs.console.events.DataLoadedEvent;
            import it.ht.rcs.console.events.RefreshEvent;
            import it.ht.rcs.console.monitor.controller.LicenseManager;
            import it.ht.rcs.console.push.PushController;
            import it.ht.rcs.console.push.PushEvent;

            import locale.R;

            import mx.collections.ArrayCollection;
            import mx.collections.ListCollectionView;
            import mx.core.FlexGlobals;
            import mx.managers.PopUpManager;

            [Bindable]
            public var section:EntitiesSection;

            [Bindable]
            public var selectedObjects:Vector.<Object>;

            [Bindable]
            public var entities:ArrayCollection=new ArrayCollection();

            //states
            private const LIST:String="list";
            private const TABLE:String="table";
            private const LINKMAP:String="linkmap";
            private const GEOMAP:String="geomap";

            private function onDoubleClick(event:MouseEvent):void
            {
                var item:*=event.currentTarget === list ? list.selectedItem : grid.selectedItem;
                if (item)
                    section.stateManager.manageItemSelection(item);

            }

            private function init():void
            {
                if (!LicenseManager.instance.intelligence)
                {
                    while (views.numChildren > 2)
                    {
                        views.removeChildAt(0) //remove link view and map view if not in License 
                    }

                }
                FlexGlobals.topLevelApplication.addEventListener(RefreshEvent.REFRESH, onRefresh);
                //PushController.instance.addEventListener(PushEvent.ENTITY, onEntityPush); 
            }

            private function onEntityPush(e:PushEvent):void
            {
                if (LicenseManager.instance.intelligence) //&& views.selectedIndex == 0)
                    //return;
                    EntityManager.instance.refresh();
                //onChangeView();
            }

            private function onRefresh(e:RefreshEvent):void
            {
                // if(LicenseManager.instance.intelligence  && views.selectedIndex == 0) 
                //return;
                //onChangeView();
            }

            private function onKeyUp(event:KeyboardEvent):void
            {

            }

            protected function onAddedToStage():void
            {
                trace("Entities View Added to Stage");

                FlexGlobals.topLevelApplication.addEventListener(RefreshEvent.REFRESH, onRefresh);
                EntityManager.instance.listenPush()
                PushController.instance.addEventListener(PushEvent.ENTITY, onEntityPush);
                EntityManager.instance.addEventListener(DataLoadedEvent.DATA_LOADED, onChangeView)
                EntityManager.instance.refresh();

                /*     if (linkMap)
                        linkMap.inited=false;
                    onChangeView(); */
                onChangeView()
            }

            protected function onRemovedFromStage():void
            {
                FlexGlobals.topLevelApplication.removeEventListener(RefreshEvent.REFRESH, onRefresh);
                EntityManager.instance.unlistenPush()
                PushController.instance.removeEventListener(PushEvent.ENTITY, onEntityPush);
                EntityManager.instance.removeEventListener(DataLoadedEvent.DATA_LOADED, onChangeView)

                if (linkMap)
                    linkMap.removeListeners();
                if (geoMap)
                    geoMap.removeListeners();

            }

            public function onChangeView(e:Event=null):void
            {
                trace("Entities >> CHANGE VIEW")
                if (geoMap)
                    geoMap.doStop();

                actionbar.selectedObject=null;
                actionbar.selectedObjects=null; //TODO > SYNC SELECTION


                var i:int;


                if (!LicenseManager.instance.intelligence)
                {
                    if (views.selectedIndex == 0) //list
                    {
                        actionbar.currentState=LIST;
                        list.selectedItem=null;
                        list.selectedItems=null;
                    }

                    if (views.selectedIndex == 1) //table
                    {
                        actionbar.currentState=TABLE;
                        grid.selectedItem=null;
                        grid.selectedItems=null;
                    }
                }

                else //License has intelligence
                {
                    if (section.stateManager.currentState == "allEntities" && (views.selectedIndex == 0 || views.selectedIndex == 1))
                    {

                        views.selectedIndex=2;

                    }

                    if (views.selectedIndex == 0) //links
                    {
                        if (geoMap)
                            geoMap.removeListeners();

                        section.stateManager.hideGroups=false;
                        section.stateManager.view.refresh();
                        section.stateManager.tableView.refresh();
                        actionbar.currentState=LINKMAP;
                        if (linkMap) //redundant TODO!!!!
                        {
                            linkMap.addListeners();
                            linkMap.entities=section.stateManager.tableView;
                            linkMap.draw();
                        }

                    }

                    else if (views.selectedIndex == 1) //geo map
                    {
                        section.stateManager.hideGroups=true;
                        section.stateManager.view.refresh();
                        section.stateManager.tableView.refresh();
                        actionbar.currentState=GEOMAP;

                        if (linkMap)
                            linkMap.removeListeners();
                        if (geoMap)
                        {
                            geoMap.addListeners();
                            geoMap.reset();
                            geoMap.entities=section.stateManager.tableView;
                            geoMap.refresh();
                        }
                    }

                    else if (views.selectedIndex == 2) //list
                    {
                        section.stateManager.hideGroups=true;
                        section.stateManager.view.refresh();
                        section.stateManager.tableView.refresh();
                        actionbar.currentState=LIST;
                        if (list)
                        {
                            list.selectedItem=null;
                            list.selectedItems=null;
                        }

                        if (linkMap)
                            linkMap.removeListeners();
                        if (geoMap)
                            geoMap.removeListeners();
                    }

                    if (views.selectedIndex == 3) //table
                    {
                        section.stateManager.hideGroups=true;
                        section.stateManager.view.refresh();
                        section.stateManager.tableView.refresh();
                        actionbar.currentState=TABLE;
                        if (grid)
                        {
                            grid.selectedItem=null;
                            grid.selectedItems=null;
                        }
                        if (linkMap)
                            linkMap.removeListeners();
                        if (geoMap)
                            geoMap.removeListeners();
                    }
                }
            }



            protected function onNewLink():void
            {
                EntityManager.instance.refresh()
                EntityManager.instance.addEventListener(DataLoadedEvent.DATA_LOADED, onDataLoaded)
            }

            private function onDataLoaded(e:DataLoadedEvent):void
            {
                EntityManager.instance.removeEventListener(DataLoadedEvent.DATA_LOADED, onDataLoaded)
                onChangeView()
            }

            protected function onLinkRemoved():void
            {
                EntityManager.instance.refresh()
                EntityManager.instance.addEventListener(DataLoadedEvent.DATA_LOADED, onDataLoaded)
            }

            protected function onLinkUpdated():void
            {
                EntityManager.instance.refresh()
                EntityManager.instance.addEventListener(DataLoadedEvent.DATA_LOADED, onDataLoaded)
            }

            protected function onGroupCreated(e:Event):void
            {
                trace("GROUP CREATED")
                //linkMap.graph.vis.selection=null
            }

            protected function onEntityMerged():void
            {
                EntityManager.instance.refresh()
                EntityManager.instance.addEventListener(DataLoadedEvent.DATA_LOADED, onDataLoaded)
            }


            protected function onEntityCreated():void
            {
                onChangeView()
            }

            protected function onEntityDeleted():void
            {
                onChangeView()
            }

            protected function onEntityUpdated():void
            {
                onChangeView()
            }

            protected function onGroup():void
            {
                //linkMap.graph.vis.groupElements({name: "group", type:"group"}, linkMap.graph.vis.selection)
                var popup:EntityForm=PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, EntityForm, true) as EntityForm;
                popup.graph=linkMap.graph
                popup.addEventListener(EntityForm.CLOSE, onGroupCreated)
                popup.operation=section.stateManager.selectedOperation;
                popup.entity=new Entity({name: "group", type: "group"});
                popup.currentState=EntityForm.CREATE;
                PopUpManager.centerPopUp(popup);

            }

            protected function onUnGroup():void
            {
                linkMap.graph.vis.unGroupElements(linkMap.graph.vis.selection);
                EntityManager.instance.removeItem(actionbar.selectedObject);
                linkMap.onSelectionChange();

            }

            protected function onExpandAll(event:Event):void
            {
                for each (var node:Object in linkMap.graph.vis.nodesMap)
                {
                    if (node is GenericGroup && !GenericGroup(node).isGroupExpanded && !GenericGroup(node).forceNoExpandGroupButton)
                        GenericGroup(node).isGroupExpanded=true
                }

            }

            protected function onCollapseAll(event:Event):void
            {
                for each (var node:Object in linkMap.graph.vis.nodesMap)
                {
                    if (node is GenericGroup && GenericGroup(node).isGroupExpanded && !GenericGroup(node).forceNoExpandGroupButton)
                        GenericGroup(node).isGroupExpanded=false
                }

            }
        ]]>
    </fx:Script>

    <entities:EntitiesActionBar section="{section}"
                                                            selectedObjects="{list.selectedItems}"
                                                            viewStack="{views}"
                                                            selectedObject="{list.selectedItem}"
                                                            entityUpdated="onEntityUpdated(); list.selectedItem=null"
                                                            entityCreated="onEntityCreated(); list.selectedItem=null"
                                                            entityDeleted="onEntityDeleted(); list.selectedItem=null"
                                                            entityMerged="onEntityMerged();   list.selectedItem=null"
                                                            group="onGroup()"
                                                            ungroup="onUnGroup()"
                                                            expandAll="onExpandAll(event)"
                                                            collapseAll="onCollapseAll(event)"
                                                            linkAdded="onNewLink()"
                                                            linkRemoved="onLinkRemoved()"
                                                            linkUpdated="onLinkUpdated()"
                                                            id="actionbar"/>


    <mx:ViewStack id="views"
                                width="100%"
                                height="100%"
                                creationPolicy="all"
                                change="onChangeView()"
                                creationComplete="onChangeView()">

        <s:NavigatorContent label="{R.get('LINK_MAP')}"
                                                hideEffect="{fadeOut}"
                                                icon="@Embed('/img/NEW/link16.png')"
                                                showEffect="{fadeIn}">


            <entities:LinkView section="{this.section}"
                                                 id="linkMap"
                                                 entities="{section.stateManager.tableView}"
                                                 actionbar="{actionbar}"/>

        </s:NavigatorContent>
        <s:NavigatorContent label="{R.get('POSITION_MAP')}"
                                                hideEffect="{fadeOut}"
                                                icon="@Embed('/img/NEW/position16.png')"
                                                showEffect="{fadeIn}">


            <entities:GeoMapView id="geoMap"
                                                     section="{this.section}"
                                                     actionbar="{actionbar}"
                                                     entities="{section.stateManager.tableView}"/>

        </s:NavigatorContent>

        <s:NavigatorContent label="{R.get('ICON_VIEW')}"
                                                hideEffect="{fadeOut}"
                                                icon="@Embed('/img/windows/icon.png')"
                                                showEffect="{fadeIn}">

            <s:HGroup width="100%"
                                height="100%"
                                gap="5">

                <view:BaseList id="list"
                                             dataProvider="{section.stateManager.view}"
                                             selectedItems="{grid.selectedItems}"
                                             doubleClick="onDoubleClick(event)"
                                             keyUp="onKeyUp(event)"
                                             allowMultipleSelection="true"
                                             section="{this.section}"/>

                <entities:EntityInfoPanel selectedItem="{list.selectedItem}"
                                                                    selectedItems="{list.selectedItems}"/>

            </s:HGroup>

        </s:NavigatorContent>
        <s:NavigatorContent label="{R.get('TABLE_VIEW')}"
                                                hideEffect="{fadeOut}"
                                                icon="@Embed('/img/windows/list.png')"
                                                showEffect="{fadeIn}">

            <entities:EntitiesGrid id="grid"
                                                         dataProvider="{section.stateManager.tableView}"
                                                         selectedItems="{list.selectedItems}"
                                                         doubleClick="onDoubleClick(event)"
                                                         keyUp="onKeyUp(event)"/>

        </s:NavigatorContent>


    </mx:ViewStack>

    <fx:Declarations>
        <s:Fade id="fadeIn"
                        alphaFrom="0"
                        alphaTo="1"
                        duration="150"/>
        <s:Fade id="fadeOut"
                        alphaFrom="1"
                        alphaTo="0"
                        duration="150"/>
    </fx:Declarations>

</s:VGroup>