Search in sources :

Example 1 with Treechildren

use of org.zkoss.zul.Treechildren in project adempiere by adempiere.

the class WDelete method createNodes.

//  dynInit
private void createNodes(DeleteEntitiesModel tableData, Treechildren ItemChildren) {
    DeleteEntitiesModel currentNode = tableData;
    HashSet<String> tablesIgnored = new HashSet<String>(Arrays.asList(new String[] { "T_Report", "T_ReportStatement", "AD_Attribute_Value", "AD_PInstance_Log", "A_Valid_Asset_Combinations" }));
    if (tablesIgnored.contains(currentNode.tableName))
        return;
    String sql = "SELECT t.TableName, c.ColumnName, c.IsMandatory " + "FROM AD_Table t" + " INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) " + "WHERE t.IsView='N'" + " AND c.ColumnName NOT IN ('CreatedBy', 'UpdatedBy') " + // not the same table
    " AND t.TableName NOT IN ('C_TaxDeclarationAcct',?)" + " AND (" + //	#1 - direct
    "(c.ColumnName=? AND c.IsKey='N' AND c.ColumnSQL IS NULL)" + " OR " + //	Table Reference
    "c.AD_Reference_Value_ID IN " + "(SELECT rt.AD_Reference_ID FROM AD_Ref_Table rt" + " INNER JOIN AD_Table tt ON (rt.AD_Table_ID=tt.AD_Table_ID)" + //	#2
    " WHERE tt.TableName = ? ) " + ") " + "ORDER BY t.LoadSeq DESC";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String keyCol = currentNode.tableName + "_ID";
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setString(1, currentNode.tableName);
        pstmt.setString(2, keyCol);
        pstmt.setString(3, currentNode.tableName);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            DeleteEntitiesModel data = new DeleteEntitiesModel();
            data.mandatoryLink = "Y".equals(rs.getString(3));
            data.tableName = rs.getString(1);
            data.joinColumn = rs.getString(2);
            data.whereClause = " EXISTS (SELECT 1 FROM " + currentNode.tableName + " WHERE " + currentNode.tableName + "." + currentNode.tableName + // + currentNode.joinColumn 
            "_ID" + " = " + data.tableName + "." + data.joinColumn + " AND " + currentNode.whereClause + ") ";
            int count = data.getCount();
            if (count > 0) {
                Treeitem treeitem = new Treeitem();
                ItemChildren.appendChild(treeitem);
                treeitem.setLabel(data.tableName + "." + data.joinColumn);
                treeitem.setValue(data);
            } else
                log.log(Level.FINE, "No records:" + data.tableName);
        }
    } catch (SQLException e) {
        log.log(Level.INFO, sql);
        throw new AdempiereException("Couldn't load child tables", e);
    } finally {
        DB.close(rs, pstmt);
    }
    @SuppressWarnings("unchecked") Collection<Treeitem> collItemChild = (Collection<Treeitem>) ItemChildren.getItems();
    Iterator<Treeitem> it = collItemChild.iterator();
    while (it.hasNext()) {
        Treeitem node = (Treeitem) it.next();
        Treeitem rootOfNode = node.getParentItem();
        if (rootOfNode != null && rootOfNode.getParentItem() != null && rootOfNode.getParentItem().equals(node)) {
            log.log(Level.WARNING, "Loop detected, escaping.");
            break;
        } else if (((DeleteEntitiesModel) node.getValue()).mandatoryLink) {
            DeleteEntitiesModel itemTableData = (DeleteEntitiesModel) node.getValue();
            Treechildren nodeChild = new Treechildren();
            createNodes(itemTableData, nodeChild);
            if (nodeChild.getItemCount() != 0) {
                node.appendChild(nodeChild);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) DeleteEntitiesModel(org.adempiere.util.DeleteEntitiesModel) PreparedStatement(java.sql.PreparedStatement) Treeitem(org.zkoss.zul.Treeitem) AdempiereException(org.adempiere.exceptions.AdempiereException) ResultSet(java.sql.ResultSet) Treechildren(org.zkoss.zul.Treechildren) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 2 with Treechildren

use of org.zkoss.zul.Treechildren in project adempiere by adempiere.

the class WDelete method generateTree.

// ValueChange
private void generateTree(Object value, Integer clientID) {
    if (value == null)
        return;
    Integer selectedTableID = ((Integer) value).intValue();
    if (selectedTableID == 0 || clientId == null) {
        FDialog.error(form.getWindowNo(), "ParameterError", "Table or Client cannot be Null.");
        return;
    }
    MTable table = MTable.get(Env.getCtx(), selectedTableID);
    DeleteEntitiesModel data = new DeleteEntitiesModel();
    data.mandatoryLink = true;
    data.tableName = table.getTableName();
    data.joinColumn = table.getKeyColumns()[0];
    data.whereClause = " " + data.tableName + ".AD_Client_ID = " + clientId;
    if (table.getTableName().equals("AD_User")) {
        data.whereClause = data.whereClause + " AND NOT EXISTS (SELECT * FROM C_BPartner bp " + "WHERE AD_User.Link_BPartner_ID=bp.C_BPartner_ID " + "AND (bp.IsEmployee='Y' OR bp.IsSalesRep='Y'))";
    }
    tree.clear();
    if ((tree.getChildren()).size() > 1) {
        @SuppressWarnings("rawtypes") List treePreviousChild = tree.getChildren();
        tree.removeChild((Treechildren) treePreviousChild.get(1));
    }
    Treechildren rootTreeChild = new Treechildren();
    Treeitem rootTreeItem = new Treeitem();
    rootTreeItem.setValue(data);
    rootTreeItem.setLabel(data.tableName + "." + data.joinColumn);
    Treechildren rootTreeItemChild = new Treechildren();
    createNodes(data, rootTreeItemChild);
    rootTreeItem.appendChild(rootTreeItemChild);
    rootTreeChild.appendChild(rootTreeItem);
    tree.appendChild(rootTreeChild);
}
Also used : Treeitem(org.zkoss.zul.Treeitem) MTable(org.compiere.model.MTable) DeleteEntitiesModel(org.adempiere.util.DeleteEntitiesModel) Treechildren(org.zkoss.zul.Treechildren) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with Treechildren

use of org.zkoss.zul.Treechildren in project adempiere by adempiere.

the class WDeleteEntity method createNodes.

//  dynInit
/**
	 * Create Nodes
	 * @param root
	 */
private void createNodes(DeleteEntitiesModel currentNode, Treechildren root) {
    //	Load from parent
    loadChilds(currentNode, root);
    @SuppressWarnings("unchecked") Collection<Treeitem> collItemChild = (Collection<Treeitem>) root.getItems();
    Iterator<Treeitem> it = collItemChild.iterator();
    //	
    while (it.hasNext()) {
        Treeitem node = (Treeitem) it.next();
        Treeitem rootOfNode = node.getParentItem();
        if (rootOfNode != null && rootOfNode.getParentItem() != null && rootOfNode.getParentItem().equals(node)) {
            log.log(Level.WARNING, "Loop detected, escaping.");
            break;
        } else if (((DeleteEntitiesModel) node.getValue()).isMandatoryLink()) {
            DeleteEntitiesModel itemTableData = (DeleteEntitiesModel) node.getValue();
            Treechildren nodeChild = new Treechildren();
            createNodes(itemTableData, nodeChild);
            //	
            if (nodeChild.getItemCount() != 0) {
                node.appendChild(nodeChild);
            }
        }
    }
}
Also used : Treeitem(org.zkoss.zul.Treeitem) DeleteEntitiesModel(org.adempiere.util.DeleteEntitiesModel) Treechildren(org.zkoss.zul.Treechildren) Collection(java.util.Collection)

Example 4 with Treechildren

use of org.zkoss.zul.Treechildren in project adempiere by adempiere.

the class WDeleteEntity method addToNode.

@Override
public void addToNode(DeleteEntitiesModel data, Object rootNode) {
    Treeitem treeitem = new Treeitem();
    ((Treechildren) rootNode).appendChild(treeitem);
    treeitem.setLabel(data.toString());
    treeitem.setValue(data);
}
Also used : Treeitem(org.zkoss.zul.Treeitem) Treechildren(org.zkoss.zul.Treechildren)

Example 5 with Treechildren

use of org.zkoss.zul.Treechildren in project adempiere by adempiere.

the class WDeleteEntity method loadView.

/**
	 * Load View
	 * @param clientId
	 * @param tableId
	 */
private void loadView() {
    //	
    DeleteEntitiesModel data = new DeleteEntitiesModel(getClientId(), getTableId());
    //	
    tree.clear();
    if ((tree.getChildren()).size() > 1) {
        @SuppressWarnings("rawtypes") List treePreviousChild = tree.getChildren();
        tree.removeChild((Treechildren) treePreviousChild.get(1));
    }
    //	
    Treechildren rootTreeChild = new Treechildren();
    Treeitem rootTreeItem = new Treeitem();
    rootTreeItem.setValue(data);
    rootTreeItem.setLabel(data.toString());
    Treechildren rootTreeItemChild = new Treechildren();
    createNodes(data, rootTreeItemChild);
    rootTreeItem.appendChild(rootTreeItemChild);
    rootTreeChild.appendChild(rootTreeItem);
    tree.appendChild(rootTreeChild);
}
Also used : Treeitem(org.zkoss.zul.Treeitem) DeleteEntitiesModel(org.adempiere.util.DeleteEntitiesModel) Treechildren(org.zkoss.zul.Treechildren) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Treechildren (org.zkoss.zul.Treechildren)9 Treeitem (org.zkoss.zul.Treeitem)7 DeleteEntitiesModel (org.adempiere.util.DeleteEntitiesModel)4 List (java.util.List)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 MTable (org.compiere.model.MTable)1 MTreeNode (org.compiere.model.MTreeNode)1 Treecol (org.zkoss.zul.Treecol)1 Treecols (org.zkoss.zul.Treecols)1