Issue : drag and drop from list control to tree control

Hi,
I was trying a drag and drop from list control to tree control. I have used some sample data to populate list and tree controls .
It is working fine . except one problem ..
Prob : when i drag an item to tree control .. it gets added .. now tree contains (X+1) data in list .. say X is the inital number of nodes in a tree node.
          now if i drag another item from list to last item in the tree node  .. i.e at X+1 index. .. it throws null pointer exception.
I am considerably new in flex programming . looking for help from experts ..
Below is my code :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                layout="horizontal"
                creationComplete="init()">
    <mx:Script>
        <![CDATA[
            import mx.controls.listClasses.IListItemRenderer;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.utils.ObjectUtil;
            import mx.collections.ICollectionView;
            import mx.core.UIComponent;
            import mx.managers.DragManager;
            import mx.events.DragEvent;
            import mx.controls.Alert;
            import mx.controls.Label;
            import mx.events.CloseEvent;
            private var homePath:String="/home/e311394/dndTest/";
            private var destPath:String="/home/e311394/dndDest/";
            private var eid:String="e311394";
            private var actn:String;
            [Bindable]
            private var cm:ContextMenu;
            private var cmi:ContextMenuItem;
            [Bindable]
            private var dp:ArrayCollection;
            private function init():void
                cmi=new ContextMenuItem("Remove");
                cmi.enabled=true;
                cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuItem_menuItemSelect);
                cm=new ContextMenu();
                cm.hideBuiltInItems();
                cm.customItems=[cmi];
                cm.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenuItem_menuSelect);
                list.contextMenu=cm;
            private function contextMenuItem_menuSelect(evt:ContextMenuEvent):void
                list.selectedIndex=lastRollOverIndex;
            private function contextMenuItem_menuItemSelect(evt:ContextMenuEvent):void
                var loclSelectedRow:Object=list.selectedItem;
                var lostrSelectedMenuItem:String;
                lostrSelectedMenuItem=evt.target.caption;
                if (loclSelectedRow != null)
                    var obj:Object=new Object()
                    obj.label=loclSelectedRow.label as String;
                        //Alert.show(obj.label);
                if (lostrSelectedMenuItem == "Remove")
                    if(loclSelectedRow!=null)
                    var pth:String=homePath.concat(loclSelectedRow.label);
                    //Alert.show(pth);
                    //FlexDnDRemoteService.process(eid,"delete",pth,"-"); 
                    var coll:ArrayCollection=list.dataProvider as ArrayCollection;
                    if (coll.contains(loclSelectedRow))
                        coll.removeItemAt(coll.getItemIndex(loclSelectedRow));
            public function onTreeDragEnter(event:DragEvent):void
                event.preventDefault();
                DragManager.acceptDragDrop(event.target as UIComponent);
                tree.showDropFeedback(event);
            protected function onTreeDragOver(event:DragEvent):void
                event.preventDefault();
                event.currentTarget.hideDropFeedback(event);
                try
                    var index:int=tree.calculateDropIndex(event);
                catch (e:Error)
                    DragManager.showFeedback(DragManager.NONE);
                    return;
                tree.selectedIndex=index;
                var draggedOverItem:Object=tree.selectedItem;
            public function onTreeDragExit(event:DragEvent):void
                event.preventDefault();
                tree.hideDropFeedback(event);
            private function showAlert():void
                Alert.yesLabel="Move";
                Alert.noLabel="Copy";
                Alert.buttonWidth=70;
                Alert.show("Copy / Move ?", "Confirm", Alert.YES | Alert.NO | Alert.CANCEL, this, alertListener, null, Alert.OK);
            private function alertListener(eventObj:CloseEvent):void
                var result:Boolean=false;
                if (eventObj.detail == Alert.CANCEL)
                    //Alert.show("CANCEL");
                    return;
                if (eventObj.detail == Alert.YES)
                    //Alert.show("YES");
                    result=true;
                else if (eventObj.detail == Alert.NO)
                    //Alert.show("NO");
                    result=false;
                var index:int=tree.calculateDropIndex(treedropevt);
                //Alert.show("Drop Pos" + index.toString());
                /* var treeList:ArrayCollection=tree.dataProvider as ArrayCollection;
                   Alert.show(" index"+index+"Length "+treeList.length);
                   if(index > treeList.length)
                   Alert.show("Returning");
                   return;
                var items:Array=new Array();
                if (treedropevt.dragSource.hasFormat("items"))
                    items=items.concat(treedropevt.dragSource.dataForFormat("items") as Array);
                var parentItem:Object;
                parentItem=getObjectTarget();
                /* if (tree.dataDescriptor.isBranch(tree.indexToItemRenderer(index).data))
                   parentItem=tree.indexToItemRenderer(index).data;
                   else
                   var dropParentPackage:Object = tree.mx_internal::_dropData.parent as Object;
                   Alert.show("HAck"+dropParentPackage.toString());
                   parentItem=tree.getParentItem(tree.indexToItemRenderer(index).data);
                   //Alert.show("Lenght "+ObjectUtil.getClassInfo(parentItem).properties.length);
                //Alert.show("Lenght "+ObjectUtil.getClassInfo(parentItem).properties.length);
                var position:int=0;
                /* if(ObjectUtil.getClassInfo(parentItem).properties.length==0)
                   Alert.show("Returning");
                   return;
                if (parentItem != null)
                    try
                        while (tree.indexToItemRenderer(index).data != parentItem)
                            //Alert.show(tree.indexToItemRenderer(index).data.toString());
                            if (index > 0)
                                index--;
                            //Alert.show("Insiade");
                            position++;
                    catch (e:Error)
                        Alert.show("Catch" + index.toString());
                        return;
                for each (var item:Object in items)
                    var obj:Object=new Object()
                    obj.label=item.label as String;
                    if (parentItem != null)
                        //Alert.show("ADDED");                       
                        tree.dataDescriptor.addChildAt(parentItem, obj, position++);                       
                    else
                        //Alert.show("PARENT NULL");
                        tree.dataDescriptor.addChildAt(tree.selectedItem, obj, position++);                       
                    var spth:String=homePath.concat(item.label);
                    //Alert.show(spth);   
                    var dpth:String=destPath.concat(item.label);
                    //Alert.show(dpth);
                    if (result == true)
                        removeItems();
                            //FlexDnDRemoteService.process(eid,"move",spth,dpth);
                    else
                        //FlexDnDRemoteService.process(eid,"copy",spth,dpth);
                    tree.validateNow();
            public function getObjectTarget():Object
                var dropData:Object=tree.mx_internal::_dropData as Object;
                if (dropData.parent != null)
                    return dropData.parent;
                else
                    // if there is not parent (root of the tree), I take the root directly
                    var renderer:IListItemRenderer=tree.indexToItemRenderer(0);
                    return renderer.data;
            public function removeItems():void
                //remove moved elements
                var items:Array=treedropevt.dragSource.dataForFormat("items") as Array;
                var coll:ArrayCollection=list.dataProvider as ArrayCollection;
                for each (var item:Object in items)
                    if (coll.contains(item))
                        coll.removeItemAt(coll.getItemIndex(item));
            private var treedropevt:DragEvent;
            public function onTreeDragDrop(event:DragEvent):void
                treedropevt=event;
                showAlert();
                event.preventDefault();
                tree.hideDropFeedback(event);
            public function resultHandler(event:ResultEvent):void
                Alert.show("Success", "Status");
            public function faultHandler(event:FaultEvent):void
                Alert.show(event.fault.faultString, "Failure");
        ]]>
    </mx:Script>
    <mx:ArrayCollection id="listDP">
        <mx:Object label="File1.dnd"/>
        <mx:Object label="File2.dnd"/>
        <mx:Object label="File3.dnd"/>
        <mx:Object label="File4.dnd"/>
        <mx:Object label="File5.dnd"/>
    </mx:ArrayCollection>
    <mx:Number id="lastRollOverIndex"/>
    <!--
         <mx:ArrayCollection id="treeDP">
         <mx:Object label="/home">
         <mx:children>
         <mx:Object label="dummy1.ks"/>
         <mx:Object label="dummy2.ks"/>
         <mx:Object label="e493126">
         <mx:children>
         <mx:ArrayCollection>
         <mx:Object label="/home/e493126/sample1.ks"/>
         </mx:ArrayCollection>
         </mx:children>
         </mx:Object>
         </mx:children>
         </mx:Object>
         </mx:ArrayCollection>
    -->
    <mx:ArrayCollection id="treeDP">
        <mx:Object label="/dndDest">
            <mx:children>
                <mx:ArrayCollection>
                    <mx:Object label="sample1.ks"/>
                    <mx:Object label="sample2.ks"/>
                    <mx:Object label="sample3.ks"/>
                    <mx:Object label="sample4.ks"/>
                    <mx:Object label="sample5.ks"/>
                    <mx:Object label="sample6.ks"/>
                </mx:ArrayCollection>
            </mx:children>
        </mx:Object>
    </mx:ArrayCollection>
    <mx:List id="list"
             itemRollOver="lastRollOverIndex = event.rowIndex"
             width="50%"
             dragEnabled="true"
             dataProvider="{listDP}"
             labelField="label"
             allowMultipleSelection="true"
             dragMoveEnabled="false">
    </mx:List>
    <mx:Tree id="tree"
             width="50%"            
             dragEnabled="true"            
             dataProvider="{treeDP}"            
             dragEnter="onTreeDragEnter(event)"
             dragOver="onTreeDragOver(event)"
             dragExit="onTreeDragExit(event)"
             dragDrop="onTreeDragDrop(event)"
             labelField="label"
             liveScrolling="true">
    </mx:Tree>
    <mx:RemoteObject id="FlexDnDRemoteService"
                     showBusyCursor="true"
                     destination="FlexDnD">
        <mx:method name="process"
                   result="resultHandler(event)"
                   fault="faultHandler(event)"/>
    </mx:RemoteObject>
</mx:Application>
Thanks,
Rajiv

Ya , i have searched and have used the same code.
But needed to customize few things like:
stop dnd in same tree
drop some item into a folder ..( onto it ) etc
have achieved the same .. but this issue ..
i think the tree dataprovider (contents internally is not being updated .. only the UI)
any suggestions ?
- Rajiv

Similar Messages

  • [svn:fx-trunk] 10876: Add support for drag-and-drop from Spark List to Spark List.

    Revision: 10876
    Author:   [email protected]
    Date:     2009-10-05 15:20:07 -0700 (Mon, 05 Oct 2009)
    Log Message:
    Add support for drag-and-drop from Spark List to Spark List.
    - List drop related handlers
    - LayoutBase APIs
    - VerticalLayout DND support
    Notes:
    - ListSkin is not final.
    - Drag-scrolling not yet implemented.
    QE notes: Only VerticalLayout works, HorizontalLayout still not implemented.
    Doc notes: None
    Bugs: None
    Reviewer: Deepa
    Tests run: checkintests
    Is noteworthy for integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/List.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/layouts/VerticalLayout.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/layouts/supportClasses/LayoutBase.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/ListSkin.mxml
        flex/sdk/trunk/frameworks/spark-manifest.xml
    Added Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/layouts/supportClasses/DropLocation.as

    Whoops, disregard my question - I just read the spec that indicates drag and drop is scheduled for later work.
    David

  • Cant drag and drop from file-roller to nautilus when using List View

    Hi, im using file-roller and i can only use drag and drop feature from file-roller when i use Icon View. If i select List View i cant drag and drop.
    Is that an expected behavior or its a bug? Is there a patch or work around? (File Roller 2.20.1 and Gnome 2.20.2)
    I think its a problem with file-roller cause in my other box, running ubuntu 7.10 i have the same problem, but i can drag and drop from ark even when using List View.
    Thx!

    Well, sorry for the double post, but after a little research i found this is a bug, actually a not yet implemented feature. There is a patch and probably its going to be merged in next version.
    Ill try to apply the patch myself, if it works could the maintainer Jan de Groot put it on the repository?
    Here is the bug: http://bugzilla.gnome.org/show_bug.cgi?id=171655
    Here is the patch: http://bugzilla.gnome.org/attachment.cg … ction=view
    Cya

  • Downloads dragged and dropped from Firefox download window into Outlook e-mail show as file location text.

    I have a user who normally can drag files from Firefox's Download window into an e-mail in Outlook and it creates an attachment of that file in the e-mail. However, lately, the dragged .pdf or whatever file only shows up as a text file location like:
    \\file:%Downloads%\randomfile.pdf
    It's not a link either, it's just the text.
    I've tried doing a repair of Outlook.
    I've uninstalled and reinstalled Firefox 19.
    I've tested dragging items from the desktop to the e-mail and it works fine.
    I can't drag and drop from the Downloads window to the desktop.
    I just wanted to add this user is using Windows XP Pro.

    I can confirm that this is an issue with the newest release of Firefox. I just upgraded my Firefox, which was previously 18.02 to 19.0 and now I'm getting the same error. It's a bug.

  • I can't drag and drop from photos 1.0 to desktop

    I can't drag and drop from photos 1.0 to desktop

    What happens if you double click on the thumbnail to view the photo in a larger size?  If you Control-click on the thumbnail and select "Show File" or "Show Original" (if it's been edited) are you taken to the folder where the original file is located an it highlighted?
    OT

  • How can we restrict the type of components that can be dragged and dropped from the sidekick CQ

    how can we restrict the type of components that can be dragged and dropped from the sidekick CQ

    Generally drop the components at parasys. The components allowed on the parsys is control via the design mode of the page.So restrict components at the design of the parsys. http://dev.day.com/docs/en/cq/current/wcm/working_with_cq_wcm/using_edit_designandpreviewm odes.html#Design%20Mode

  • I am trying to drag and drop one page of a .pdf into another .pdf in Acrobat Reader.  I used to be able to drag and drop from one .pdf to another.

    I am trying to drag and drop one page of a .pdf into another .pdf in Acrobat Reader.  I used to be able to drag and drop from one .pdf to another.

    If you could drag and drop pages before, it wasn't in Reader. You no doubt had Adobe Acrobat (Pro or Standard) which shouldn't be confused with Adobe Acrobat Reader. They recently added Acrobat to the name of Adobe Reader so the confusion about which product you had and/or have is understandable.

  • I can't drag and drop from a data CD I recorded

    I recently burned some audiobooks files (in mp3 format) as data cd's in Toast 8.0.1. When I go to reload them back onto my 20" 2 Ghz Dual Core Intel I can't drag and drop the files directly into any folder while using the columns view in a finder window. I can do it if I drag onto the music folder and let it spring open down to the level of the folder. I also can drag the mp3's into iTunes and then into the folder. This is not CD related since I used several diff brands.
    I constantly update, backup, repair permissions, and do other maintenance so everything is up to date. I have noticed this behavior just since I started to use the program called Audiobook Builder. I am (and have always used) a non-admin user account. When this started a few months ago it seemed to go away with a restart, permission repair, or a logout but now it seems permanant. I checked user permissions on my home folder - I have not added any software since adding Audiobook Builder. Any idea's? I read something about trashing a com.apple pref but didn't try that.
    I suspect Audiobook Builder since it changes the permissions and filetype to the iTunes Audiobook filetype but have not seen anyone reference this.
    wes

    dj_paige wrote:
    While the programming of course could be done, the idea of a function that performs on original unprocessed images seems to violate the whole idea of what Lightroom was designed to be. At least that's my opinion. Of course, the idea that Adobe should do this programming for a relatively small number of people (you're one of a very few people to ask for this, that I have read) seems to be something that isn't going to happen.
    I agree, I can't see much reason for drag-and-drop to drag the unprocessed image - in other words, an image that isn't the one that you see when you drag and drop.  I can see that just filling this forum with "why the heck does it do that????????" posts.  I could be wrong, but I suspect that Adobe won't do that. 
    But if you do want to drag-and-drop the original unprocessed image, you can do it very easily now.  Right click the image, choose "show in Explorer", and then drag-and-drop from Explorer. 

  • I can't drag and drop from windows explorer into my ipod on itunes. Any suggestions?

    Hi,
    I manage my music/podcast library on my Vista PC using windows explorer because I don't like how iTunes does it. Then today I can no longer drag and drop from explorer onto my iPod in iTunes all I get is a circle with a line through it meaning "iTunes says no." Any suggestions?
    Ta.

    You will need to Sync your iPad and all Music/Albums Selected will transfer over from iTunes..
    iOS: Syncing your data with iTunes
    http://support.apple.com/kb/HT1386

  • Drag and Drop from LR to other applications

    There was a thread going on D&D from LR to explorer.
    The other appliation problem I have is the apparent inability to drag and drop from lightroom into a file transfer window (e.g., file upload with SmugMug).
    The quick collection is an awesome way to organize a storyline of images from a shoot, select only the images needed, and prepare a shoot for upload. However, short of exporting to a folder first, is there a way to just drag and drop the file set from a LR view (filmstrip or thumbs) to another app? This would just be providing file handles, and I would be satisfied if it only grabbed the original images (pre-"develop").
    Anyone have any luck with this?
    -- Jeff

    No. And not likely anytime soon. Putting a Pointer/alias to SmugMug (if it is an uploader client app, not familiar with it) in the Export Actions Folder for Post Processing from Export is the best you can do at the monemt. To get LR rdits out of LR you have to Export. D&D just isn't going to do that for you.
    Don
    Don Ricklin, MacBook 1.83Ghz Duo 2 Core running 10.4.9 & Win XP, Pentax *ist D
    http://donricklin.blogspot.com/

  • Drag and drop from Lightroom into Premiere doesn't work in Windows

    I recently switched from OSX to Windows and noticed that in Windows, I'm unable to drag and drop from LIghtroom into Premiere. In OSX, it worked fine.
    I do this a lot because it's a time saver. I basically use lightroom to find the photo or video clip I need for my editing project and then just drag in right on to the Premiere timeline. Now I have to do the extra step in Lightroom of "show in explorer", then drag the file from explorer to Premiere. Not really a big deal but just curious why it works in OSX and not Windows.
    I'm running latest Windows 8.1, Lightroom 5.4, Camera Raw 8.4, and Premiere Pro CC 7.2.2 (33)
    -Pete

    Hi Pete,
    You can obtain scripts here:
    http://www.robcole.com/Rob/ProductsAndServices/MiscLrPlugins#MiscScripts
    You'll have to edit lua code to adapt for Premiere. Not that hard really (e.g. clone, then change the script name and path to executable..), but may be too intimidating for some folks. If you are one of those folks, go for the plugin instead - it's usable via GUI - no lua code - can probably accomplish the same thing.
    http://www.robcole.com/Rob/ProductsAndServices/OpenInWhateverLrPlugin
    Let me know (outside the forum please) if problems - thanks,
    Rob

  • Can't drag and drop from page view

    Can't drag and drop from page view to desktop even though plus icon shows up for duplicating the page.  On Mac 10.9.2 Acrobat XI. I don't want to extract through the menu and associated dialogues.  Its slow and cumbersome.

    Hi Peterbruce,
    Acrobat for Windows will let you select pages in the Pages panel and drag them to your desktop, but that isn't an option in Acrobat for Mac OS. You can drag thumbnails from the Pages panel in one doc, to the Pages panel in another, however.
    Best,
    Sara

  • Can't drag and drop from Address Book to Mail?

    Hi,
    I have always used Address Book to store my email contact information in SL. When I wanted to send an email, I would drag and drop from Address Book to the "To:" field in Mail and it would add the contact information to Mail. I upgraded to Lion, and now when I try this, the address icon moves like it should, the little green circle with the + in it appears when I hover over the field, but when I release it does not add the address to Mail. The drag and drop does not work at all, but it looks like it should. I have searched all around but have not found any information about this. Does anyone know what's up with this? How can I fix it? Thanks in advance.

    Are you dragging from the actual AddressBook application, or the Address icon you can add to the NewMail and Reply toolbars in Mail?  (It ought to be there by default, but isn't).
    Either should work, but if AB doesn't, try the icon method:

  • Can't Drag and Drop from Bridge/Folders anymore. Trashing Preferences didn't work

    My Indesign CS4 is acting up.
    I can no longer drag and drop from Bridge into my layouts, nor does it work from my PC folders to the layout.
    I tried accessing the two  preferences folder on my Vista as suggested here: http://indesignsecrets.com/rebuilding-indesign-preferences.php
    That didn't work and I don't think the rebuilt worked because the files didn't recreate itself, I had to bring the copies back in.
    Any idea what's going on and what to do?
    Thanks!!!
    Amy

    There are actually two files in the ID prefs set that usually need to be removed together when things act up. See Replace Your Preferences

  • How to drag and drop the af:inputNumberSpinbox in the control panel

    Hi,
    I am using jdev 11.1.1.4.0
    I need the component as <af:inputNumberSpinbox> . Create a data model and how to drag and drop as inputNumberSpinbox in the data control.
    normally drog and drop the particular attribute as inputText box only. I want <af:inputNumberSpinbox>.
    anythig want to change in the view object control hints itself. help me.
    Regards,
    ragupathi S.
    Edited by: Ragu on Jun 22, 2011 4:45 PM

    Hi,
    Can't you drop it as an inputText and then change it in the source to inputNumberSpinbox?
    Regards,
    Stijn.

Maybe you are looking for

  • Satellite A305D-S6848 - Upgrade from Vista to Windows 7 32bit

    I started the upgrading process, but it giving me a message that, I need to uninstall ATI CATALYST Install Manager, ATI Catalyst Control Center. My laptop is model A305D-S6848 Vista 32 bit. I don't know where to start to get that so can somebody poin

  • Procure to Pay in 30 days - Fixed price Implementation

    Just so readers are aware, Oracle have just announced a fixed price fixed scope implementation methodology for iprocurement (p2P). More information is available at http://www.oracle.com/start/procure2pay/intro.html?src=726402&Act=29 or www.e-vector.c

  • How to start new messages and replies using text format only?

    Hallo, I would like to start typing a new message in text format without the need to type every time the key option shift command T. The same, when I reply to a message I would like to use text only. I have played with the preferences but any of them

  • Database error -2146824582

    Hello, I write you because I have a problem to communicate between my "Access" database and my program on labview 2012 after a relocation of my department (from Swiss to France) (excuse me for my english language!!!!! I hope that you're understand) I

  • Thunderbird 31 Crashing @ secmod_LoadPKCS11Module and will not open. SOLVED Caused by "ActivClient" software

    details in crash reoprt: AvailablePageFile: 2309287936 AvailablePhysicalMemory: 785412096 AvailableVirtualMemory: 1986416640 BIOS_Manufacturer: Hewlett-Packard BlockedDllList: BreakpadReserveAddress: 30605312 BreakpadReserveSize: 41943040 BuildID: 20