use of CCDD.CcddClassesDataTable.TableMembers in project CCDD by nasa.
the class CcddDbTableCommandHandler method getRootTables.
/**
********************************************************************************************
* Get the list of root (top level) tables
*
* @param structuresOnly
* true to only include structure tables; false to include tables of all types
*
* @param parent
* GUI component calling this method
*
* @return List of root tables; empty list if there are no root tables
********************************************************************************************
*/
protected List<String> getRootTables(boolean structuresOnly, Component parent) {
List<String> rootTables = new ArrayList<String>();
// Get the prototype tables and their member tables
List<TableMembers> tableMembers = loadTableMembers(TableMemberType.TABLES_ONLY, true, parent);
// Step through each table
for (TableMembers member : tableMembers) {
// included that the member is a structure table type
if (!structuresOnly || tableTypeHandler.getTypeDefinition(member.getTableType()).isStructure()) {
boolean isRootTable = true;
// Step through each table
for (TableMembers otherMember : tableMembers) {
// isn't referencing itself
if (otherMember.getDataTypes().contains(member.getTableName()) && !member.equals(otherMember)) {
// Clear the flag indicating this is a root table and stop searching
isRootTable = false;
break;
}
}
// Check if this is a root table
if (isRootTable) {
// Store the root table's name
rootTables.add(member.getTableName());
}
}
}
return rootTables;
}
use of CCDD.CcddClassesDataTable.TableMembers in project CCDD by nasa.
the class CcddDbTableCommandHandler method loadTableMembers.
/**
********************************************************************************************
* Create a list of all prototype tables with their child tables (prototypes and instances),
* and primitive variables (if specified). The table must contain all of the protected columns
* defined for a structure in order for its members to be determined. Non-structure tables are
* included in the returned list, but by definition have no members
*
* @param memberType
* Type of table members to load: TABLES_ONLY to exclude primitive variables or
* INCLUDE_PRIMITIVES to include tables and primitive variables
*
* @param sortByName
* true to return the table members in alphabetical order (e.g., for use in a tree);
* false to return the members sorted by row index (e.g., for use in determining the
* variable offsets in the structure)
*
* @param parent
* GUI component calling this method
*
* @return List containing the table member information. For structure tables the member tables
* are included, along with primitive variables (if specified), sorted by variable name
* or row index as specified
********************************************************************************************
*/
protected List<TableMembers> loadTableMembers(TableMemberType memberType, boolean sortByName, final Component parent) {
List<TableMembers> tableMembers = new ArrayList<TableMembers>();
try {
// Get the list of prototype tables in alphabetical order
String[] tableNames = queryTableList(parent);
// Get the comments for all data tables
String[][] comments = queryDataTableComments(parent);
// Get the table members of all structure tables by extracting the values from the
// table's data type and variable name columns, if present, sorted by variable name or
// table index. Non-structure tables and structure tables with no rows are skipped. The
// information returned by the PostgreSQL function also returns the bit length,
// rate(s), and enumeration(s) for each member; the enumeration information currently
// isn't used
ResultSet rowData = dbCommand.executeDbQuery("SELECT * FROM " + (sortByName ? "get_table_members_by_name();" : "get_table_members_by_index();"), parent);
// Create a list to contain the database table member data types, variable names, bit
// lengths, and rates
List<String> dataTypes;
List<String> variableNames;
List<String> bitLengths;
List<String[]> rates;
// Set the flag based on if any data was returned by the database query
boolean doLoop = rowData.next();
// Step through the query results
while (doLoop) {
// Initialize the data type, variable, bit length, rate(s), and enumeration(s)
// lists
dataTypes = new ArrayList<String>();
variableNames = new ArrayList<String>();
bitLengths = new ArrayList<String>();
rates = new ArrayList<String[]>();
// Get the table name for this query table row
String tableName = rowData.getString(1);
do {
// Get the data type, variable name, bit length, and rate(s) from this query
// row
String dataType = rowData.getString(2);
String variableName = rowData.getString(3);
String bitLength = rowData.getString(4);
String[] rate = rowData.getString(5).split(",", rateHandler.getNumRateColumns());
// included
if (dataType != null && !dataType.isEmpty() && variableName != null && !variableName.isEmpty() && (!dataTypeHandler.isPrimitive(dataType) || memberType == TableMemberType.INCLUDE_PRIMITIVES)) {
// Get the number of variable names in the list
int addIndex = variableNames.size();
// sorted by variable name
if (addIndex != 0 && sortByName) {
// Get the name of the last variable added to the list
String lastVarName = variableNames.get(addIndex - 1);
// array
if (ArrayVariable.isArrayMember(variableName) && ArrayVariable.isArrayMember(lastVarName) && ArrayVariable.removeArrayIndex(variableName).equals(ArrayVariable.removeArrayIndex(lastVarName))) {
// The PostgreSQL function that obtains the table members sorted by
// variable name treats array indices as strings, so array member
// [10] appears immediately after member [1] instead of after [9].
// This code section determines the position in the list where the
// current array member should be placed relative to those members
// already in the list, sorted numerically by array dimension
// value(s)
boolean notFound = true;
do {
// Compare the two array members numerically, by array
// dimension value(s)
int result = ArrayVariable.compareTo(variableName, variableNames.get(addIndex - 1));
// before the comparison array member
if (result < 0) {
// Decrement the variable insertion index
addIndex--;
} else // after the comparison array member
if (result > 0) {
// Set the flag indicating that the position of the current
// variable in the list is located and stop checking the
// dimension values
notFound = false;
}
} while (notFound && addIndex > 0);
// Continue to adjust the insertion index as long as the current
// variable's array indices places it prior to the that of the
// variable at the current insertion index. The test for addIndex >
// 0 accounts for the possibility that array members are missing in
// the table
}
}
// Add the data type, variable name, bit length, rate(s), and
// enumeration(s) to the lists for this table
dataTypes.add(addIndex, dataType);
variableNames.add(addIndex, variableName);
bitLengths.add(addIndex, bitLength);
rates.add(addIndex, rate);
}
// Go to the next row in the query results; set the flag to true if the row
// exists
doLoop = rowData.next();
// Continue to loop while rows exist to process in the query table and the
// table name for the new row remains the same
} while (doLoop && tableName.equals(rowData.getString(1)));
// Get the comment array for this table
String[] comment = getTableComment(tableName, comments);
// Add the table name, table type, and the table's member information to the
// members list
tableMembers.add(new TableMembers(comment[TableCommentIndex.NAME.ordinal()], comment[TableCommentIndex.TYPE.ordinal()], dataTypes, variableNames, bitLengths, rates));
}
rowData.close();
// Create storage for the tables not added above; i.e., for non-structure tables and
// for structure tables containing no rows
List<TableMembers> newMembers = new ArrayList<TableMembers>();
// Step through the table names
for (String tableName : tableNames) {
boolean isFound = false;
// Step through the structure table members
for (TableMembers member : tableMembers) {
// Check if the table name matches the one in the member list
if (tableName.equals(member.getTableName())) {
// Set the flag to indicate this table is already in the member list and
// stop searching
isFound = true;
break;
}
}
// Check if the table is not already in the member list
if (!isFound) {
// Get the comment array for this table
String[] comment = getTableComment(tableName.toLowerCase(), comments);
// Add the table to the member list with empty data type, variable name, bit
// length, and rate lists
newMembers.add(new TableMembers(tableName, comment[TableCommentIndex.TYPE.ordinal()], new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String[]>()));
}
}
// Add the new members to the member list. The list now contains a reference to all
// tables
tableMembers.addAll(newMembers);
// Sort the table members by table name in ascending order
Collections.sort(tableMembers, new Comparator<TableMembers>() {
/**
********************************************************************************
* Compare the table names of two member definitions. Force lower case to eliminate
* case differences in the comparison
********************************************************************************
*/
@Override
public int compare(TableMembers mem1, TableMembers mem2) {
return mem1.getTableName().toLowerCase().compareTo(mem2.getTableName().toLowerCase());
}
});
} catch (SQLException se) {
// Inform the user that loading the table members failed
eventLog.logFailEvent(parent, "Cannot load table members; cause '" + se.getMessage() + "'", "<html><b>Cannot load table members");
tableMembers = null;
} catch (Exception e) {
// Display a dialog providing details on the unanticipated error
CcddUtilities.displayException(e, parent);
}
return tableMembers;
}
use of CCDD.CcddClassesDataTable.TableMembers in project CCDD by nasa.
the class CcddTableTreeHandler method buildNodes.
/**
********************************************************************************************
* Build the table tree nodes. This is a recursive method. In order to prevent an infinite
* loop, a check is made for a child node that exists in its own path; if found the recursion
* is terminated for that node
*
* @param thisMember
* TableMember class
*
* @param parentNode
* current working node for the table tree
*
* @param childNode
* new child node to add to the working node
********************************************************************************************
*/
private void buildNodes(TableMembers thisMember, ToolTipTreeNode parentNode, ToolTipTreeNode childNode) {
// Step through each node in the parent's path
for (TreeNode node : parentNode.getPath()) {
if (((ToolTipTreeNode) node).getLevel() >= getHeaderNodeLevel()) {
// Check if the child is in the path
if (((ToolTipTreeNode) node).getUserObject().toString().equals(childNode.getUserObject().toString())) {
// Store the name of the recursively referenced node
recursionTable = childNode.getUserObject().toString();
break;
}
}
}
// Check that a recursion error wasn't found; this prevents an infinite loop from occurring
if (recursionTable == null) {
// Add the child node to its parent
parentNode.add(childNode);
// Get the parent table and variable path for this variable
String fullTablePath = getFullVariablePath(childNode.getPath());
// Step through each table/variable referenced by the table member
for (int memIndex = 0; memIndex < thisMember.getDataTypes().size(); memIndex++) {
// Check if this data type is a primitive
if (dataTypeHandler.isPrimitive(thisMember.getDataTypes().get(memIndex))) {
String tablePath = fullTablePath;
// Set to true if the variable has a path (i.e., this is not a prototype's
// variable)
boolean isChildVariable = tablePath.contains(",");
// Check if the variable has a path
if (isChildVariable) {
// Add the data type and variable name to the variable path
tablePath += "," + thisMember.getDataTypes().get(memIndex) + "." + thisMember.getVariableNames().get(memIndex);
}
String rate = null;
// Check if a rate filter is in effect
if (rateFilter != null) {
// Get the rate value for this variable. Use the prototype's value if the
// variable doesn't have a specific rate assigned
int index = rateValues.indexOf(tablePath);
rate = isChildVariable && index != -1 ? rateValues.get(index)[2] : thisMember.getRates().get(memIndex)[rateIndex];
}
// specified rate filter
if (rateFilter == null || rate.equals(rateFilter)) {
// Get the full variable name in the form
// data_type.variable_name[:bit_length]
String variable = thisMember.getFullVariableNameWithBits(memIndex);
// the variable, using its full path and name, is not in the exclusion list
if (excludedVariables == null || !excludedVariables.contains(tablePath)) {
// Add the primitive as a node to this child node
childNode.add(new ToolTipTreeNode(variable, ""));
} else // The variable is in the exclusion list
{
// Add the variable with the node text grayed out
childNode.add(new ToolTipTreeNode(DISABLED_TEXT_COLOR + variable, ""));
}
}
} else // Data type is not a primitive, it's a structure
{
// Step through the other tables
for (TableMembers member : tableMembers) {
// Check if the table is a member of the target table
if (thisMember.getDataTypes().get(memIndex).equals(member.getTableName())) {
// Build the node name from the prototype and variable names
String nodeName = thisMember.getDataTypes().get(memIndex) + "." + thisMember.getVariableNames().get(memIndex);
// Get the variable name path to this node
String tablePath = fullTablePath + "," + nodeName;
// Add this table to the current table's node. The node name is in the
// format 'dataType.variableName<[arrayIndex]>'. If a specific
// description exists for the table then use it for the tool tip text;
// otherwise use the prototype's description
buildNodes(member, childNode, new ToolTipTreeNode(nodeName, getTableDescription(tablePath, thisMember.getDataTypes().get(memIndex))));
}
}
}
}
// (variables)
if ((treeType == STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES) && childNode.getChildCount() == 0) {
// Remove the node
parentNode.remove(childNode);
}
}
}
use of CCDD.CcddClassesDataTable.TableMembers in project CCDD by nasa.
the class CcddTableTreeHandler method addByType.
/**
********************************************************************************************
* Add tables to the specified prototype and instance nodes based on table type
*
* @param nameList
* list of table names belonging to the filtered selection; null if no filtering
*
* @param protoNode
* parent node for the prototype nodes
*
* @param instNode
* parent node for the instance nodes
*
* @param groupInfo
* reference to the group information is filtering also by group; null if not
* filtering by group
*
* @param parent
* GUI component calling this method
********************************************************************************************
*/
private void addByType(ToolTipTreeNode protoNode, ToolTipTreeNode instNode, GroupInformation groupInfo, Component parent) {
// Step through each table type
for (String type : tableTypeHandler.getTypes()) {
List<String> tables = new ArrayList<String>();
// Step through each table
for (TableMembers member : tableMembers) {
// it belongs to the current group
if (type.equals(member.getTableType()) && (groupInfo == null || groupInfo.getTableMembers().contains(member.getTableName()))) {
// Add the table name to the list for this type
tables.add(member.getTableName());
}
}
// Create nodes for the type and add them to the prototype and instance nodes
ToolTipTreeNode protoTypeNode = new ToolTipTreeNode(type, getDescriptions ? tableTypeHandler.getTypeDefinition(type).getDescription() : null);
ToolTipTreeNode instTypeNode = new ToolTipTreeNode(type, getDescriptions ? tableTypeHandler.getTypeDefinition(type).getDescription() : null);
instNode.add(instTypeNode);
protoNode.add(protoTypeNode);
// Build the prototype and instance nodes filtered by type (and group, if applicable)
buildTopLevelNodes(tables, instTypeNode, protoTypeNode, parent);
}
}
use of CCDD.CcddClassesDataTable.TableMembers in project CCDD by nasa.
the class CcddTableTreeHandler method buildTopLevelNodes.
/**
********************************************************************************************
* Build the top-level nodes for the table tree (based on the selected filters)
*
* @param nameList
* list of table names belonging to the filtered selection; null if no filtering
*
* @param instNode
* parent node for the top-level nodes
*
* @param protoNode
* parent node for the prototype nodes
*
* @param parent
* GUI component calling this method
********************************************************************************************
*/
private void buildTopLevelNodes(List<String> nameList, ToolTipTreeNode instNode, ToolTipTreeNode protoNode, Component parent) {
// haven't already been loaded
if (getDescriptions && tableDescriptions == null) {
// Get an array containing the tables and their variable paths, if any, for those
// tables with descriptions
tableDescriptions = dbTable.queryTableDescriptions(parent);
}
// Step through each table
for (TableMembers member : tableMembers) {
// structure type tables for a tree showing structure instances with primitives
if ((nameList == null || nameList.contains(member.getTableName())) && ((treeType != STRUCTURES_WITH_PRIMITIVES && treeType != INSTANCE_STRUCTURES_WITH_PRIMITIVES && treeType != INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES) || tableTypeHandler.getTypeDefinition(member.getTableType()).isStructure())) {
// prototype nodes are excluded if it is)
if (treeType != STRUCTURES_WITH_PRIMITIVES) {
// Add the table to the prototype node
protoNode.add(new ToolTipTreeNode(member.getTableName(), getTableDescription(member.getTableName(), "")));
}
boolean isParent = true;
// Step through each table
for (TableMembers otherMember : tableMembers) {
// is a member of the group
if (otherMember.getDataTypes().contains(member.getTableName()) && !member.equals(otherMember) && (!isByGroup || (nameList != null && nameList.contains(otherMember.getTableName())))) {
// Clear the flag indicating this is a parent table and stop searching
isParent = false;
break;
}
}
// the prototype node
if (isParent || treeType == STRUCTURES_WITH_PRIMITIVES) {
recursionTable = null;
// Build the nodes in the tree for this table and its member tables
buildNodes(member, (!isParent && treeType == STRUCTURES_WITH_PRIMITIVES ? protoNode : instNode), new ToolTipTreeNode(member.getTableName(), getTableDescription(member.getTableName(), "")));
// suppressed
if (recursionTable != null && !isSilent) {
// Inform the user that the table has a recursive reference
new CcddDialogHandler().showMessageDialog(parent, "<html><b>Table '</b>" + member.getTableName() + "<b>' contains a recursive reference to '</b>" + recursionTable + "<b>'", "Table Reference", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
}
}
}
}
}
Aggregations