Search in sources :

Example 6 with DeleteEntitiesModel

use of org.adempiere.util.DeleteEntitiesModel 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 7 with DeleteEntitiesModel

use of org.adempiere.util.DeleteEntitiesModel in project adempiere by adempiere.

the class DeleteEntityControler method loadChilds.

/**
	 * Load Child from tableName
	 * @param currentNode
	 */
public void loadChilds(DeleteEntitiesModel currentNode, Object rootNode) {
    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.getTableName()))
        return;
    //	
    String sql = "SELECT t.AD_Table_ID, 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') " + "AND t.AD_Table_ID <> ? " + "AND (" + "		(c.ColumnName = ? AND c.IsKey='N' AND c.ColumnSQL IS NULL) " + "		OR EXISTS(SELECT 1 " + "					FROM AD_Ref_Table r " + "					WHERE r.AD_Reference_ID = c.AD_Reference_Value_ID " + "					AND r.AD_Table_ID = ?)" + ") " + "ORDER BY t.LoadSeq DESC";
    //	Query to DB
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    //	
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, currentNode.getTableId());
        pstmt.setString(2, currentNode.getKeyColumnForTable());
        pstmt.setInt(3, currentNode.getTableId());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String isMandatory = rs.getString("IsMandatory");
            DeleteEntitiesModel data = new DeleteEntitiesModel(currentNode.getClientId(), rs.getInt("AD_Table_ID"), rs.getString("TableName"), rs.getString("ColumnName"), (isMandatory != null && isMandatory.equals("Y")), currentNode);
            //	Get Count
            int count = data.getCount();
            //	
            if (count > 0) {
                log.log(Level.FINE, "Adding node: " + data.getTableName() + "." + data.getJoinColumn());
                addToNode(data, rootNode);
            } else {
                log.log(Level.FINE, "No records:" + data.getTableName());
            }
        }
    //
    } catch (SQLException e) {
        log.log(Level.INFO, sql);
        throw new AdempiereException("Couldn't load child tables", e);
    } finally {
        DB.close(rs, pstmt);
    }
}
Also used : SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) DeleteEntitiesModel(org.adempiere.util.DeleteEntitiesModel) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) HashSet(java.util.HashSet)

Example 8 with DeleteEntitiesModel

use of org.adempiere.util.DeleteEntitiesModel 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)

Example 9 with DeleteEntitiesModel

use of org.adempiere.util.DeleteEntitiesModel in project adempiere by adempiere.

the class VDeleteEntity method loadView.

/**
	 * Load View
	 * @param clientId
	 * @param tableId
	 */
private void loadView() {
    //	
    mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    confirmPanel.getOKButton().setEnabled(false);
    //
    DeleteEntitiesModel data = new DeleteEntitiesModel(getClientId(), getTableId());
    //	
    rootNode = new DefaultMutableTreeNode(data);
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    model.setRoot(rootNode);
    createNodes(rootNode);
    tree.expandRow(0);
    //
    confirmPanel.getOKButton().setEnabled(true);
    mainPanel.setCursor(Cursor.getDefaultCursor());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DeleteEntitiesModel(org.adempiere.util.DeleteEntitiesModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Aggregations

DeleteEntitiesModel (org.adempiere.util.DeleteEntitiesModel)9 Treeitem (org.zkoss.zul.Treeitem)5 SQLException (java.sql.SQLException)4 AdempiereException (org.adempiere.exceptions.AdempiereException)4 Treechildren (org.zkoss.zul.Treechildren)4 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 List (java.util.List)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 Stack (java.util.Stack)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 MTable (org.compiere.model.MTable)1 Trx (org.compiere.util.Trx)1