4 Replies Latest reply: Jan 31, 2013 4:57 AM by h0s RSS

    Create a row in treeTable via Drag&Drop

    h0s
      Hello,

      My application have a table (source) where user can drag a row and a treeTable (destination) where user drop the dragged row.

      I follow these samples :

      For the drag n drop : http://www.oracle.com/technetwork/developer-tools/adf/learnmore/101-drag-drop-table-tree-1661895.pdf

      For the createInsert operation : http://jobinesh.blogspot.fr/2010/05/crud-operations-on-tree-table.html

      I would like to detect the parentRow where the childRow is dropped. Actually it works if user select the parent row first, and then drag&drop. But there is no interest to have a drag&drop functionallity if user must click on the parent row first.

      I try someting like this but it's not good :

      in the dropHandler method :
        RichTreeTable arfTree = (RichTreeTable)dropEvent.getDropComponent();
      ...
      JUCtrlHierNodeBinding dropNode = (JUCtrlHierNodeBinding)arfTree.getRowData();
      ...
      getTreeTable().setRowKey(dropNode.getRowKey());  // where getTreeTable() is the binded TreeTable. Here is my problem. I don't know how to change the binded TreeTable rowKey. Exception oracle.jbo.Key cannot be cast to java.util.List is raised
      ...
      JSFUtil.executeOperation("#{bindings.createChildren}");
      and the rowIterator and RowKey of binded TreeTable are passed to an application module method like this :
          public RowIterator getSelectedNodeRowIterator() {
            if (getTreeTable() != null && getTreeTable().getSelectedRowKeys() != null) {
              for (Object opaqueFacesKey : getTreeTable().getSelectedRowKeys()) {
                  getTreeTable().setRowKey(opaqueFacesKey);
                  return ((JUCtrlHierNodeBinding)getTreeTable().getRowData()).getRowIterator();
              }
           }
           return null;
          }
      
          public Key getSelectedNodeRowKey() {
            if (getTreeTable() != null && getTreeTable().getSelectedRowKeys() != null) {
              for (Object opaqueFacesKey : getTreeTable().getSelectedRowKeys()) {
                  getTreeTable().setRowKey(opaqueFacesKey);
                  return ((JUCtrlHierNodeBinding)getTreeTable().getRowData()).getRowKey();
              }
            }
            return null;
          }
      method action published in pageDef :
      <methodAction id="createChildren" InstanceName="data.AppModuleDataControl.dataProvider"
                        DataControl="AppModuleDataControl" RequiresUpdateModel="true" Action="invokeMethod"
                        MethodName="createChildren" IsViewObjectMethod="false">
            <NamedData NDName="ri" NDValue="#{backingBeanScope.treeTableBean.selectedNodeRowIterator}"
                       NDType="oracle.jbo.RowIterator"/>
            <NamedData NDName="selectedNodeKey" NDValue="#{backingBeanScope.treeTableBean.selectedNodeRowKey}"
                       NDType="oracle.jbo.Key"/>
            <NamedData NDName="artVar1" NDValue="#{backingBeanScope.treeTableBean.dragArtVar1}" NDType="java.lang.String"/>
          </methodAction>
      Any help will be appreciated.
        • 1. Re: Create a row in treeTable via Drag&Drop
          Puthanampatti
          <af:dragSource actions="COPY" defaultAction="COPY"
          discriminant="fromSource">


          JUCtrlHierNodeBinding draggedSourceNode =
          JSFUtil.getDraggedRowNodeFromTreeTable(dropEvent,
          "fromSource");
          RowKeySet draggedRowKeySet =
          JSFUtil.getDraggedRowKeySetFromTreeTable(dropEvent,
          "fromSource");
          if (draggedRowKeySet != null && draggedRowKeySet.size() == 1) {
          List firstDraggedRowKey =
          (List)draggedRowKeySet.iterator().next();
          JUCtrlHierNodeBinding draggedRowNode =
          JSFUtil.getTreeNodeByKey(sourceTreeTable,
          firstDraggedRowKey);
          Row draggedRow = draggedRowNode.getRow();

          .........
          • 2. Re: Create a row in treeTable via Drag&Drop
            h0s
            Thanks for answer.

            But if I understand well, your code allow me to get the dragged row. What I want is to get the "dropped row". I mean, the row where the dragged row is dropped.
            • 3. Re: Create a row in treeTable via Drag&Drop
              Puthanampatti
              you mean the target table row (right hand side)..


              RowKeySet targetSelectedRowKeySet =
              targetTreeTable.getSelectedRowKeys();

              if (targetSelectedRowKeySet != null &&
              targetSelectedRowKeySet.size() == 1)
              {
              List selectedTargetRowKey =
              (List)targetSelectedRowKeySet.iterator().next();
              JUCtrlHierNodeBinding selectedTargetNode =
              JSFUtil.getTreeNodeByKey(targetTreeTable,
              selectedTargetRowKey);
              Row selectedTargetRow = selectedTargetNode.getRow();
              .........
              • 4. Re: Create a row in treeTable via Drag&Drop
                h0s
                Sorry for the late post. Your post help me to find the solution. Thank you!

                I was no clear in my question, but what I wanted was to change the SelectedRowKeys of my tree. The target node must become selected. Solution :
                RichTreeTable arfTree = (RichTreeTable)dropEvent.getDropComponent();
                List dropRowKey = (List)dropEvent.getDropSite();
                RowKeySet rks = arfTree.getSelectedRowKeys();
                rks.add(dropRowKey);
                arfTree.setSelectedRowKeys(rks);