private void loadDiagram(Field field) {
    if (field != null) {

      if (logger.isDebugEnabled())
        logger.debug(
            String.format("draw field %s  status:%s", field.name, field.getSelectedStatus()));

      SvgScene scene = new SvgScene();
      scene.setZoom(owner.getZoomRate());

      _Object target = field.getTarget();
      if (target != null) {
        target.drawInternal(diagramPanel, scene, new Point(0, 0), getVM().getObjectRepository());

        diagramPanel.setScene(scene);
        Element background = scene.getDocument().getElementById("background");

        diagramPanel.addBackgroundPopupMenuListener((EventTarget) background);

        // use background node to capture mouse move event. otherwise
        // the
        // cursor could leave the object if you moving very fast.
        diagramPanel.addMouseMoveListener((EventTarget) background);
      } else {
        System.out.println("selected field is null");
      }
    }
  }
  private Field addChildObjectToTree(_Object obj) {

    // add to tree
    // int index = obj.getOwner().getChildIndex(obj);
    Field f = obj.getOwnerField();

    Element background = diagramPanel.getScene().getDocument().getElementById("background");
    SVGMatrix mat = ((SVGLocatable) background).getScreenCTM();
    Point screenPosition = diagramPanel.getPopupMenuPosition();

    SVGOMPoint elePosition = SVGUtils.screenToElement(mat, screenPosition);

    float startX = elePosition.getX() / (f.svgScale);
    float startY = elePosition.getY() / (f.svgScale);
    f.setStartPosition(startX, startY);

    treeModel.insertNodeInto(
        new DefaultMutableTreeNode(f),
        getSelectedTreeNode(),
        getSelectedTreeNode().getChildCount());

    reloadDiagram();
    return f;
  }
  private void createChildNodes(DefaultMutableTreeNode node, int depth) {
    if (depth == 0) return;

    Field field = (Field) node.getUserObject();
    _Object obj = field.getTarget();

    if (obj != null) {

      // create child nodes
      List<Field> fields = obj.getFields();
      for (int i = 0; i < fields.size(); i++) {
        Field childField = fields.get(i);
        // if (obj.owns(childField.target)) {

        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(childField);

        treeModel.insertNodeInto(childNode, node, node.getChildCount());
        // node.add(childNode);

        createChildNodes(childNode, depth - 1);
        // }
      }
    }
  }