Announcement

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

    Treegrid Confirm when FolderDropHandler

    hi team,
    I want to ask user before drag and drop item from node to node. how is it possible ?

    I want something like this :
    Code:
    orgTreeGrid.addFolderDropHandler(new FolderDropHandler() {
    	@Override
    	public void onFolderDrop(final FolderDropEvent event) {
    	  try {
    		SC.ask("Warning ","Are you sure you want to move this item ?",
                               new BooleanCallback() {
    				@Override
    				public void execute(Boolean value) {
    				     if (value){ SC.say("OK.");										
                      		}else {
                                        event.cancel();		
                                    }
                                 }
                             });					
               } catch (Exception e) {
                       SC.say(e.toString());
                 }
               }
         });

    But this code doesn't work because ask method is asynchronous and event will complete not depend on the user's action : yes or no.


    My Env :
    1. SGWTEE 2.5 (Evaluation) - build Date - 2011-08-02
    2. GWT 2.3.0
    3. Firefox 5.


    __________________________
    Regards,
    Paata Lominadze

    #2
    Is it possible to make this ?

    I can't find any solution for it ...

    any hint will be appreciated.


    ________________________
    Regards,
    Paata Lominadze.

    Comment


      #3
      DataBoundComponent.transferSelectedData() can be used to do the equivalent of the builtin drag if you need to take some asynchronous action (like a confirmation) beforehand.

      Comment


        #4
        What if the nodes are in the same TreeGrid?

        Attempting to do something like the following does not work ....get the following message:

        com.smartgwt.client.core.JsObject$SGWT_WARN: 17:14:12.428:MUP3:WARN:TreeGrid:isc_GuiMapTreeGrid_0:transferSelectedData(): target parameter contains a pointer back to this grid - ignoring

        Code:
        final TreeGrid thisTreeGrid = this;
        
        addFolderDropHandler(new FolderDropHandler() {
            @Override
            public void onFolderDrop(final FolderDropEvent folderDropEvent) {
                StringBuilder sb = new StringBuilder("Are you sure you want to move the following element(s)?");
                sb.append("<ul>");
                for (TreeNode node : folderDropEvent.getNodes()) {
                    sb.append("<li>");
                    sb.append(node.getName());
                    sb.append("</li>");
                }
                sb.append("</ul>");
        
                BooleanCallback booleanCallback = new BooleanCallback() {
                    @Override
                    public void execute(Boolean aBoolean) {
                        if (aBoolean) {
                            transferSelectedData(thisTreeGrid, thisTreeGrid.getEventRow());
                        }
                    }
                };
        
                DialogWindow.confirm("Move Element(s)", sb.toString(), ImgConstants.CONTEXT_48 , booleanCallback, "Yes", "No");
                folderDropEvent.cancel();
            }
        });

        Comment


          #5
          Looks like transferSelectedData() won't cover that case. Another approach is just to cancel() the event, which stops the default behavior so you can implement the persistence operations yourself (which is just a few calls to updateData()/addData()).

          Comment


            #6
            Doing updateData does update the database, but it doesn't update the tree.
            InvalidateCache must be performed to see changes ....ideas why?

            Code:
            /* Move items */
            int targetTestCaseId = folderDropEvent.getFolder().getAttributeAsInt(IssueDataField.TEST_CASE_ID);
            for (TreeNode treeNode : folderDropEvent.getNodes()) {
                treeNode.setAttribute(IssueDataField.PARENT_ID, targetTestCaseId);
                updateData(treeNode);
            }

            Comment


              #7
              Do not directly modify the treeNode via setAttribute. Call updateData with a Record containing just the primary key and new fields. Otherwise, you have basically already updated locally cached data to reflect the change you are about to save, hence no change will be detected when the save succeeds.

              Also, see the FAQ on grids not updating for how to troubleshoot this in general.

              Comment

              Working...
              X