Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ContextMenu Items from server

    I have a listgrid with a contextMenu. I would like a Record's Contextual Menu, for instance, when i right click on :
    row1 -> menu{item1, item2}
    row2 -> menu{item3}
    row3 -> menu{item4, item 5, item6}
    etc...

    I attach a DataSource to the Menu with a POSTXML DataProtocol. I set up a Servlet I want it to send item1, item2 if end-user has right-clicked on row1, and so on...

    Any clue ?
    Last edited by enguerran; 17 Jun 2010, 01:45.

    #2
    Are you asking just generally how to go about this? Or there is something specific you have run in to? So far yes, your going about it the right way.

    Comment


      #3
      I would like the menu items to be refreshed (fetchData(with record-dependant Criteria)) each time the end-user right-click on a row/record, but i do not know how to do this.

      For instance, when end-user right-click on a record, depending of the record data, the program will show him some specific items in the contextMenu like "validate record" if the record state was "aproved", or "aprovate record" if the record state was "created", or "delete record" if the record was "draft"...

      Comment


        #4
        Assuming your datasource for your menu is all setup correctly, you can add a row context handler to your grid, immediately call filterData() on your menu passing in the Criteria you need, for example Criteria c = new Criteria(); c.addCriteria("rowNum", event.getRowNum()); or whatever exactly you need, then your servlet can send back a response with the correct records for the menu.

        Comment


          #5
          I'll try that and keep you in touch.

          [EDIT]

          Sadly, this solution is working only if the end-user rightclicks during 2 seconds, the time for the data to be fetched.
          If the enduser rightclicks as usual, the data is fetched but when he releases the right mouse button, there is no data, it is to early.
          If the enduser rightclicks during 2 secs, the data is fetched and when he releases the right mouse button, there is data and the menu is shown.

          I hope I am clear, thank you for your help.

          [EDIT]

          If fact, I would like the Contextual Menu to be contextual regarding the row not the grid. Is it possible ?

          [EDIT]

          My eyes is opening : addRowContextClickHandler.... Let's try that.
          Last edited by enguerran; 17 Jun 2010, 00:44.

          Comment


            #6
            Thank you, that's what I wanted :
            Code:
                        grid.addRowContextClickHandler(new RowContextClickHandler()
                        {
                            public void onRowContextClick(RowContextClickEvent event)
                            {
                                Menu contextMenu = ((ListGrid) event.getSource()).getContextMenu();
                                contextMenu.invalidateCache();
                                Criteria criteria = new Criteria();
                                criteria.addCriteria("rownum", event.getRowNum());
                                contextMenu.filterData(criteria);
                            }
                        });

            Comment


              #7
              When I add this block :
              Code:
                          grid.addRowContextClickHandler(new RowContextClickHandler()
                          {
                              public void onRowContextClick(RowContextClickEvent event)
                              {
                                  ListGrid listGrid = (ListGrid) event.getSource();
                                  Criteria criteria = new Criteria();
                                  for(ListGridRecord rec : listGrid.getSelection())
                                      criteria.addCriteria("id", rec.getAttribute("id"));
                                  listGrid.getContextMenu().filterData(criteria);
                              }
                          });
              This one is switched off...
              Code:
                      Menu contextMenu = new Menu();
                      contextMenu.setDataSource(MenuDS.getInstance(id));
                      
                      contextMenu.addItemClickHandler(new ItemClickHandler()
                      {
                          public void onItemClick(ItemClickEvent event)
                          {
                              MenuDS.execute(event);
                          }
                      });
              Does anyone know something about this?

              subsidiary question: How should the xml post response be written? Can I add a tag for click action? For instance, I wrote that:
              Code:
              <List>
                <menuItem>
                  <name>Show details</name>
                  <icon>ContextualMenu/show.png</icon>
                  <title>details</title>
                </menuItem>
                <menuItem>
                  <isSeparator>true</isSeparator>
                </menuItem>
                <menuItem>
                  <name>Assign to me</name>
                  <icon>ContextualMenu/assignToMe.png</icon>
                  <title>assignToMe</title>
                </menuItem>
              </List>

              Comment

              Working...
              X