Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2888

Nullpointer when inserting [i.e. moving] a node in a TreeTable (AbstactTree, treeNodesInserted)

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      A have a simple tree:

      root
      -c1
      --cc1
      -c2
      --cc2
      -c3

      I want to move c3 from parent root to parent c2. This works when the treenode c2 is not expanded, i.e. cc2 is not shown. When c2 is expanded, the action results in a nullPointerException in treeNodesInserted. The cause of the nullPointer is:

      parentItem.getChildren() <-- returns null, but in line 845 the parentItem.getChildren().add() is called, thus the nullPointer.

      Any hints?

      my piece of tree manipulation code:

      table.getTreeTable().modelChanging();

      DefaultTreeModel model = (DefaultTreeModel) table.getTreeTable().getDefaultModelObject();

      DefaultMutableTreeNode parent = (DefaultMutableTreeNode) myNode.getParent();

      // getIndexOfChild returns -1 if either of th nodes == null
      int myIndex = model.getIndexOfChild( parent, myNode );
      if ( myIndex < 1 ) // 0 or -1

      { return; }

      DefaultMutableTreeNode previousSibling = (DefaultMutableTreeNode) model.getChild( parent, myIndex - 1 );

      model.removeNodeFromParent( myNode );

      //insert the node as last
      model.insertNodeInto( myNode, previousSibling, model.getChildCount( previousSibling ) );

      table.getTreeTable().modelChanged();

      Attachments

        1. patch.txt
          5 kB
          Pedro Santos
        2. patch.txt
          6 kB
          Pedro Santos
        3. patch.txt
          11 kB
          Pedro Santos
        4. patch.txt
          7 kB
          Pedro Santos
        5. tree-quickstart.tar.gz
          19 kB
          Rob Audenaerde

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            pete Peter Ertl
            robau Rob Audenaerde
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment