Professional Web Applications Themes

ContextMenu in AdvancedDataGrid Tree - Macromedia Flex General Discussion

Hi, I've had a search around but can't find any comments on this subject, so I hope I'm doing something silly here and everyone else can do this :-) I'm trying to create a contextmenu for my tree nodes in an advanceddatagrid. I have a treecolumn that is populated using a HierarchicalData object. Following an example that I found on this site which adds a checkbox to the tree, I created a custom class derived AdvancedDataGridGroupItemRenderer, overrode the set data function of my new class and assigned a new ContextMenu item to the renderer. I then hooked up the renderer ...

  1. #1

    Default ContextMenu in AdvancedDataGrid Tree

    Hi,

    I've had a search around but can't find any comments on this subject, so I
    hope I'm doing something silly here and everyone else can do this :-)

    I'm trying to create a contextmenu for my tree nodes in an advanceddatagrid. I
    have a treecolumn that is populated using a HierarchicalData object. Following
    an example that I found on this site which adds a checkbox to the tree, I
    created a custom class derived AdvancedDataGridGroupItemRenderer, overrode the
    set data function of my new class and assigned a new ContextMenu item to the
    renderer. I then hooked up the renderer class to the grid using
    myGrid.groupItemRenderer = new ClassFactory(MyCustomGroupItemRenderer).

    If I use the debugger I can see that my overridden 'set data' function is
    being called, and the context menu is then created, correctly populated with my
    child objects, and is attached to the renderer just fine. The problem is, when
    I right click on the nodes, nothing happens :-(

    If I use the same code to create a contextMenu, but attach it just once to the
    grid itself (myGrid.contextMenu = menuThatICreated) then that works, but
    obviously that menu is global to the grid, not specific for each tree node.

    Has anyone ever come across this problem before? If so, how did you fix it?
    Or, on the other hand, does anyone have context menus working for tree nodes in
    a grid?

    GavinCroy Guest

  2. #2

    Default Re: ContextMenu in AdvancedDataGrid Tree

    Still struggling with this issue, and I'm quite confused about it having just
    re-read the ContextMenu reference doentation. The doentation states that:

    In Flex, only top-level components in the application can have context menus.
    For example, if a DataGrid control is a child of a TabNavigator or VBox
    container, the DataGrid control cannot have its own context menu.
    However, I don't see this principle being applied, since I have another
    component which has a tab navigator, with a tree component embedded in a vbox
    which is acting as one of the panes in the navigator:

    Tab Navigator
    VBox
    Tree/
    /VBox
    /Tab Navigator

    I can quite happily attach context menus to the node in my tree in this case
    and it works just fine. The same is true in my problem with the advanced data
    grid problem mentioned above. I am rendering buttons in each of the cells in my
    grid, and these buttons all their own context menus (attached to their
    itemRenderers), which works just fine - it's only the tree column within the
    grid that I can't seem to get context menus working on the tree node.

    Is anyone able to shed some light on this?



    GavinCroy Guest

  3. #3

    Default Re: ContextMenu in AdvancedDataGrid Tree

    I'm also stuck on exactly the same issue. I'm not getting my custom context menus in advanced datagrid tree column.Could someone suggest me how to get this work?
    arajendr Guest

  4. #4

    Default Re: ContextMenu in AdvancedDataGrid Tree

    I recently had to deal with the contextMenu madness... and so this may help...

    You (GavinCroy) is right -- the doentation is wrong (at least as far as I
    understand it). And thank goodness. Because that would mean a single
    contextMenu for an entire view (each component) -- that would almost kill
    contextMenus ('cm' from here out). Each component has its own cm. And so
    whichever control has the focus, and the right click is performed, that
    component's cm is the one that is displayed. If a component does not have a cm
    assigned (its .contextMenu property = null), the parenting-component chain is
    checked, and the nearest ancestor with a cm assigned -- that is the cm that
    will be displayed.

    But items in a List (DataGrid, Tree, etc.) are not components. So they don't
    have cm's. What you have to do is change the respective cm depending upon the
    item that is selected within each component -- basically emulating a
    'state-change' for each component based upon it's selected item. This involves
    background code...

    Something like this...

    On Component ItemClick...
    --> Depending on item-clicked, determine state (and thus appropriate cm for
    the component)...
    --> set the component's cm for that 'state' (component.contextMenu =
    appropriateContextMenu)
    --> so next right-click will produce appropriate cm (which may be essentially,
    the particular item's cm)

    And that's basically it... and the appropriate cm may further depend upon the
    exact cell (row,col) with focus, not just the item (row).

    As far as using the itemRenderer to store a contextMenu, I've never tried
    that, and I'm not sure if you were reporting that that actually works (ie
    right-clicking on an item/cell produces the itemRenderer's cm). My guess is
    that it doesn't work. If it does, it probably "shouldn't", as the renderer is
    "meant" to be used as graphic layouter/presenter/template, rather than as a
    "component" itself... But note that an ItemEditor component, such as a
    'text-field' as a datagrid cell-editor, is an actual displayed component and so
    its context-menu will show up if it is active (shown/ in-use).

    Another way of doing this, is to actually have some sort of ItemDataSet and
    ItemData objects (rather than, say, raw XML or a raw array), each of which may
    store a contextMenu itself..., and so on the item-click, the main component can
    have it's contextmenu set to the itemData instances cm... (eg:
    mainComp.contextMenu = itemData.contextMenu)

    Hope that helps.




    Gnomann Guest

  5. #5

    Default Re: ContextMenu in AdvancedDataGrid Tree

    Gnomann,

    Thanks for the info! Glad to know I'm not going mad :grin;

    Ok, I can see how to use a work around based on your suggestions. Ideally I
    would use a mouseover event (if one exists) to set up the menu before the user
    clicks. Users will not always click on an item before right clicking, so that's
    the only way I can think of to set up the context menu before that right click
    happens.

    My other thought is to nest 'fake' components inside the tree, e.g. use a
    custom item renderer in the tree that uses a button with transparent skins
    placed over the item label, then see if a context menu on that component works
    as expected...

    Thanks for giving me some direction!

    GavinCroy Guest

  6. #6

    Default Re: ContextMenu in AdvancedDataGrid Tree

    Thanks to Gnomann for getting me thinking, I now have context menus working for
    my tree nodes in my advanced data grid. The approach I took was as follows:

    1. Create a custom item renderer for the tree items in the grid
    2. As each item has its data set, create the context menu for it
    3. Attach a mouse over event listener to the node's label item (I'll also do
    the same for its icon object) which sets the context menu of the parent grid to
    this item's context menu
    3. On mouse out remove the context menu from the parent grid (ultimately I'll
    probably need to restore some kind of default menu for the grid, I don't have
    the need for one at the moment.

    My Item renderer code is attached


    package
    {
    import flash.events.MouseEvent;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;

    import mx.controls.AdvancedDataGrid;
    import mx.controls.advancedDataGridClasses.AdvancedDataGr idGroupItemRenderer;
    import mx.controls.advancedDataGridClasses.AdvancedDataGr idListData;

    public class MyTreeRenderer extends AdvancedDataGridGroupItemRenderer
    {



    override public function set data(value:Object):void {
    super.data = value;


    var treeDataItem:AdvancedDataGridListData =
    AdvancedDataGridListData(listData);
    var item:XML = treeDataItem.item as XML;

    var treeNodeMenu:ContextMenu = new ContextMenu();
    var menuItem:ContextMenuItem = new ContextMenuItem("Menu item for
    "+ item.@name);
    treeNodeMenu.customItems.push(menuItem);



    this.label.addEventListener(MouseEvent.MOUSE_OVER,
    function():void
    {
    AdvancedDataGrid(treeDataItem.owner).contextMenu = treeNodeMenu;
    });

    this.label.addEventListener(MouseEvent.MOUSE_OUT,
    function():void
    {
    AdvancedDataGrid(treeDataItem.owner).contextMenu =
    null;
    });

    }
    }
    }

    GavinCroy Guest

Similar Threads

  1. AdvancedDataGrid Tree Branch id
    By Brent Wientjes in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 26th, 06:00 AM
  2. Hide flex ContextMenu
    By larcelarcen in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: April 25th, 08:39 PM
  3. Contextmenu Methods
    By udaykiran_sword@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 1
    Last Post: January 17th, 09:19 AM
  4. Adding contextmenu to IE Treeview Control
    By Ole Hanson in forum ASP.NET Building Controls
    Replies: 2
    Last Post: February 27th, 06:16 PM
  5. contextMenu.
    By Knight Miniatures webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: January 17th, 04:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139