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);
}
}
}
}
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);
}
}
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);
}
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());
}
Aggregations