/** * Parse Variable * * @param variable variable * @param po po * @return translated variable or if not found the original tag */ private String parseVariable(String variable, PO po) { int index = po.get_ColumnIndex(variable); if (index == -1) { StringBuilder msgreturn = new StringBuilder("@").append(variable).append("@"); return msgreturn.toString(); // keep for next } // MColumn col = MColumn.get(Env.getCtx(), po.get_TableName(), variable); Object value = null; if (col != null && col.isSecure()) { value = "********"; } else if (col.getAD_Reference_ID() == DisplayType.Date || col.getAD_Reference_ID() == DisplayType.DateTime || col.getAD_Reference_ID() == DisplayType.Time) { SimpleDateFormat sdf = DisplayType.getDateFormat(col.getAD_Reference_ID()); value = sdf.format(po.get_Value(index)); } else if (col.getAD_Reference_ID() == DisplayType.YesNo) { if (po.get_ValueAsBoolean(variable)) value = Msg.getMsg(Env.getCtx(), "Yes"); else value = Msg.getMsg(Env.getCtx(), "No"); } else { value = po.get_Value(index); } if (value == null) return ""; return value.toString(); } // translate
public static void updateTreeNode(PO po) { int nodeId = po.get_ID(); if (nodeId < 0) { return; // nothing to do, because our PO has no ID to match against a tree node } final int AD_Table_ID = po.get_Table_ID(); if (!MTree.hasTree(AD_Table_ID)) { return; } final String nodeTableName = MTree.getNodeTableName(AD_Table_ID); if (nodeTableName == null) { return; } // // services final IPOTreeSupportFactory treeSupportFactory = Services.get(IPOTreeSupportFactory.class); final String trxName = po.get_TrxName(); final IPOTreeSupport treeSupport = treeSupportFactory.get(po.get_TableName()); if (po.is_ValueChanged("IsSummary") && !po.get_ValueAsBoolean("IsSummary")) { // Move all its children to parent final List<MTreeNode> children = fetchNodes(AD_Table_ID, "Parent_ID=?", new Object[] {nodeId}, trxName); if (children.size() > 0) { throw new AdempiereException("TreeNodeHasChildren"); // TODO: translate } } if (treeSupport.isParentChanged(po)) { int parentId = treeSupport.getParent_ID(po); int oldParentId = treeSupport.getOldParent_ID(po); int seqNo = -1; // compute final String sql = "SELECT AD_Tree_ID, TreeType FROM AD_Tree WHERE AD_Table_ID=? AND AD_Client_ID=?"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trxName); DB.setParameters(pstmt, new Object[] {AD_Table_ID, po.getAD_Client_ID()}); rs = pstmt.executeQuery(); while (rs.next()) { int AD_Tree_ID = rs.getInt(COLUMNNAME_AD_Tree_ID); String treeType = rs.getString(COLUMNNAME_TreeType); updateNode( po, AD_Tree_ID, treeType, AD_Table_ID, nodeId, parentId, oldParentId, seqNo, trxName); } } catch (SQLException e) { throw new DBException(e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } } }