Пример #1
0
  private PO createNode(int nodeId, int parentId) {
    final String nodeTableName = getNodeTableName();
    PO node = null;
    if (nodeTableName.equals(MTree_Node.Table_Name)) {
      MTree_Node n = new MTree_Node(this, nodeId);
      if (nodeId != ROOT_Node_ID) n.setParent_ID(parentId);
      node = n;
    } else if (nodeTableName.equals(MTree_NodeBP.Table_Name)) {
      MTree_NodeBP n = new MTree_NodeBP(this, nodeId);
      if (nodeId != ROOT_Node_ID) n.setParent_ID(parentId);
      node = n;
    } else if (nodeTableName.equals(MTree_NodePR.Table_Name)) {
      MTree_NodePR n = new MTree_NodePR(this, nodeId);
      if (nodeId != ROOT_Node_ID) n.setParent_ID(parentId);
      node = n;
    } else if (nodeTableName.equals(MTree_NodeMM.Table_Name)) {
      MTree_NodeMM n = new MTree_NodeMM(this, nodeId);
      if (nodeId != ROOT_Node_ID) n.setParent_ID(parentId);
      node = n;
    } else {
      throw new AdempiereException("No Table Model for " + nodeTableName);
    }

    node.saveEx();
    return node;
  }
Пример #2
0
  /**
   * Add Node to correct tree
   *
   * @param ctx cpntext
   * @param treeType tree type
   * @param Record_ID id
   * @param trxName transaction
   * @return true if node added
   */
  public static boolean addNode(Properties ctx, String treeType, int Record_ID, String trxName) {
    // TODO: Check & refactor this
    // Get Tree
    int AD_Tree_ID = 0;
    MClient client = MClient.get(ctx);
    I_AD_ClientInfo ci = client.getInfo();

    if (TREETYPE_Activity.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Activity_ID();
    else if (TREETYPE_BoM.equals(treeType))
      throw new IllegalArgumentException("BoM Trees not supported");
    else if (TREETYPE_BPartner.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_BPartner_ID();
    else if (TREETYPE_Campaign.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Campaign_ID();
    else if (TREETYPE_ElementValue.equals(treeType))
      throw new IllegalArgumentException("ElementValue cannot use this API");
    else if (TREETYPE_Menu.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Menu_ID();
    else if (TREETYPE_Organization.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Org_ID();
    else if (TREETYPE_Product.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Product_ID();
    else if (TREETYPE_ProductCategory.equals(treeType))
      throw new IllegalArgumentException("Product Category Trees not supported");
    else if (TREETYPE_Project.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Project_ID();
    else if (TREETYPE_SalesRegion.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_SalesRegion_ID();

    if (AD_Tree_ID == 0) throw new IllegalArgumentException("No Tree found");
    MTree_Base tree = MTree_Base.get(ctx, AD_Tree_ID, trxName);
    if (tree.get_ID() != AD_Tree_ID)
      throw new IllegalArgumentException("Tree found AD_Tree_ID=" + AD_Tree_ID);

    // Insert Tree in correct tree
    boolean saved = false;
    if (TREETYPE_Menu.equals(treeType)) {
      MTree_NodeMM node = new MTree_NodeMM(tree, Record_ID);
      saved = node.save();
    } else if (TREETYPE_BPartner.equals(treeType)) {
      MTree_NodeBP node = new MTree_NodeBP(tree, Record_ID);
      saved = node.save();
    } else if (TREETYPE_Product.equals(treeType)) {
      MTree_NodePR node = new MTree_NodePR(tree, Record_ID);
      saved = node.save();
    } else {
      MTree_Node node = new MTree_Node(tree, Record_ID);
      saved = node.save();
    }
    return saved;
  } // addNode