use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddDbTableCommandHandler method modifyTableData.
/**
********************************************************************************************
* Add, modify, and/or delete data in a table. If the table is a prototype then its database
* table is altered; if the table is an instance then the changes are made to the custom values
* table
*
* @param tableInfo
* table information
*
* @param additions
* list of row addition information
*
* @param modifications
* list of row update information
*
* @param deletions
* list of row deletion information
*
* @param forceUpdate
* true to make the changes to other data tables; false to only make changes to
* tables other than the one in which the changes originally took place
*
* @param skipInternalTables
* true to not build and execute the commands to update the internal tables. This is
* used during a data type update where only the data type name has changed in order
* to speed up the operation
*
* @param updateDescription
* true to update the table description from the table information; false to not
* change the table description
*
* @param updateColumnOrder
* true to update the table column order from the table information; false to not
* change the table column order
*
* @param updateFieldInfo
* true to update the table data fields from the table information; false to not
* change the table data fields
*
* @param newDataTypeHandler
* data type handler with data type modifications. null (or a reference to the
* current data type handler) if the change does not originate from the data type
* editor
*
* @param parent
* reference to the GUI component over which any error dialogs should be centered
*
* @return true if an error occurs while updating the table
********************************************************************************************
*/
protected boolean modifyTableData(TableInformation tableInfo, List<TableModification> additions, List<TableModification> modifications, List<TableModification> deletions, boolean forceUpdate, boolean skipInternalTables, boolean updateDescription, boolean updateColumnOrder, boolean updateFieldInfo, CcddDataTypeHandler newDataTypeHandler, Component parent) {
boolean errorFlag = false;
try {
CcddTableTreeHandler tableTree = null;
ToolTipTreeNode orgTableNode = null;
updateLinks = false;
addLinkHandler = null;
isPathUpdate = false;
// Get the name of the table to modify and convert the table name to lower case.
// PostgreSQL automatically does this, so it's done here just to differentiate the
// table name from the database commands in the event log
String dbTableName = tableInfo.getPrototypeName().toLowerCase();
// Get the table type definition
TypeDefinition typeDefinition = tableTypeHandler.getTypeDefinition(tableInfo.getType());
// represents a structure
if (!skipInternalTables && typeDefinition.isStructure()) {
deletedArrayDefns = new ArrayList<String>();
// Create the table tree. Suppress any warning messages when creating this tree
tableTree = new CcddTableTreeHandler(ccddMain, TableTreeType.STRUCTURES_WITH_PRIMITIVES, true, parent);
// Check if the table is a prototype
if (tableInfo.isPrototype()) {
// Copy the table tree node for the prototype table. This preserves a copy of
// the table's variables before the changes are applied
orgTableNode = copyPrototypeTableTreeNode(tableInfo.getPrototypeName(), tableTree);
}
}
// Build the commands to add, modify, and delete table rows
String command = buildAdditionCommand(tableInfo, additions, dbTableName, typeDefinition, skipInternalTables) + buildModificationCommand(tableInfo, modifications, typeDefinition, newDataTypeHandler, tableTree, skipInternalTables) + buildDeletionCommand(tableInfo, deletions, dbTableName, typeDefinition, skipInternalTables);
// Get the table's description
String description = tableInfo.getDescription();
// for the prototype of this table
if (!tableInfo.isPrototype() && description.equals(queryTableDescription(tableInfo.getPrototypeName(), parent))) {
// Set the description to a blank since it inherits it from the prototype
description = "";
}
// Combine the table, data fields table, table description, and column order update
// commands
command += (updateFieldInfo ? modifyFieldsCommand(tableInfo.getTablePath(), tableInfo.getFieldHandler().getFieldInformation()) : "") + (updateDescription ? buildTableDescription(tableInfo.getTablePath(), description) : "") + (updateColumnOrder ? buildColumnOrder(tableInfo.getTablePath(), tableInfo.getColumnOrder()) : "");
// lists are empty)
if (!command.isEmpty()) {
// Execute the commands
dbCommand.executeDbUpdate(command, parent);
// Check if references in the internal tables are to be updated
if (!skipInternalTables && typeDefinition.isStructure()) {
// more variables to begin with
if (tableInfo.isPrototype() && tableInfo.getData().length > 0) {
// Build the command to delete bit-packed variable references in the links
// and telemetry scheduler tables that changed due to the table
// modifications
command = updateLinksAndTlmForPackingChange(orgTableNode, parent);
// Check if there are any bit-packed variable references to delete
if (!command.isEmpty()) {
// Delete invalid bit-packed variable references
dbCommand.executeDbUpdate(command, parent);
}
// Check if the link definitions changed
if (updateLinks) {
// Store the updated link definitions in the project database
storeInformationTable(InternalTable.LINKS, addLinkHandler.getLinkDefinitions(), null, parent);
}
}
// Execute the command to reset the rate for links that no longer contain any
// variables
dbCommand.executeDbQuery("SELECT reset_link_rate();", parent);
}
// Check if the table type is a structure
if (typeDefinition.isStructure()) {
// Update the list of root structure tables
rootStructures = getRootStructures(parent);
}
// Log that inserting data into the table succeeded
eventLog.logEvent(SUCCESS_MSG, "Table '" + tableInfo.getProtoVariableName() + "' data modified");
}
} catch (SQLException se) {
// Inform the user that updating the table failed
eventLog.logFailEvent(parent, "Cannot modify data in table '" + tableInfo.getProtoVariableName() + "'; cause '" + se.getMessage() + "'", "<html><b>Cannot modify data in table '</b>" + tableInfo.getProtoVariableName() + "<b>'");
errorFlag = true;
} catch (Exception e) {
// Display a dialog providing details on the unanticipated error
CcddUtilities.displayException(e, parent);
errorFlag = true;
}
// Check that no error occurred
if (!errorFlag) {
// type, array size, or bit length has changed
if (isPathUpdate) {
// Rebuild the variable paths and offsets lists
variableHandler.buildPathAndOffsetLists();
}
// Make changes to any open table editors
CcddTableEditorDialog.doTableModificationComplete(ccddMain, tableInfo, modifications, deletions, forceUpdate);
}
return errorFlag;
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddDbTableCommandHandler method updateLinksAndTlmForPackingChange.
/**
********************************************************************************************
* Build the commands to delete variable references in the links and telemetry scheduler tables
* that are no longer valid due to changes in bit-packing
*
* @param parent
* reference to the GUI component over which any error dialogs should be centered
*
* @return Commands to delete variable references in the links and telemetry scheduler tables
* that are no longer valid due to changes in bit-packing
********************************************************************************************
*/
private String updateLinksAndTlmForPackingChange(ToolTipTreeNode orgTableNode, Component parent) {
StringBuilder linksDelCmd = new StringBuilder("");
StringBuilder tlmDelCmd = new StringBuilder("");
List<String> removeMembers = new ArrayList<String>();
List<List<String>> updatedPacking = new ArrayList<List<String>>();
// Create the table tree after any changes have been applied
CcddTableTreeHandler tableTree = new CcddTableTreeHandler(ccddMain, TableTreeType.STRUCTURES_WITH_PRIMITIVES, parent);
// Get the tree node for the updated prototype table
ToolTipTreeNode updTableNode = tableTree.getNodeByNodeName(orgTableNode.getUserObject().toString());
// table then in no longer appears in the tree
if (updTableNode != null) {
// Step through each variable in the table as it exists after the updates
for (int childIndex = 0; childIndex < updTableNode.getChildCount(); childIndex++) {
// Get the indices of all variables bit-packed the variable at the current child
// index
BitPackNodeIndex nodeIndex = tableTree.getBitPackedVariables((ToolTipTreeNode) updTableNode.getChildAt(childIndex));
// Check if any variables are bit-packed with the current variable
if (nodeIndex.getFirstIndex() != nodeIndex.getLastIndex()) {
List<String> packMembers = new ArrayList<String>();
// Step through the bit-packed variables
for (int packIndex = nodeIndex.getFirstIndex(); packIndex <= nodeIndex.getLastIndex(); packIndex++) {
// Add the variable to the pack member list
packMembers.add(((ToolTipTreeNode) updTableNode.getChildAt(packIndex)).getUserObject().toString().replaceFirst(":\\d+", ""));
}
// Store the pack member list and the individual members
updatedPacking.add(packMembers);
removeMembers.addAll(packMembers);
// Adjust the child index to skip these bit-packed variables
childIndex = nodeIndex.getLastIndex();
}
}
}
// Step through each variable in the table as is existed prior to the updates
for (int childIndex = 0; childIndex < orgTableNode.getChildCount(); childIndex++) {
// Get the indices of all variables bit-packed the variable at the current child index
BitPackNodeIndex nodeIndex = tableTree.getBitPackedVariables((ToolTipTreeNode) orgTableNode.getChildAt(childIndex));
// Check if any variables are bit-packed with the current variable
if (nodeIndex.getFirstIndex() != nodeIndex.getLastIndex()) {
List<String> packMembers = new ArrayList<String>();
// Step through the bit-packed variables
for (int packIndex = nodeIndex.getFirstIndex(); packIndex <= nodeIndex.getLastIndex(); packIndex++) {
// Get the variable name minus the bit length
String variable = ((ToolTipTreeNode) orgTableNode.getChildAt(packIndex)).getUserObject().toString().replaceFirst(":\\d+", "");
packMembers.add(variable);
// Check if the individual member list doesn't already contain this variable
if (!removeMembers.contains(variable)) {
// Add the variable to the individual members list
removeMembers.add(variable);
}
}
// Step through the list of bit-packed variables in the updated table
for (List<String> updatedPackMembers : updatedPacking) {
// the updated table
if (CcddUtilities.isArraySetsEqual(packMembers.toArray(new String[0]), updatedPackMembers.toArray(new String[0]))) {
// Since the bit-packed variables are unchanged, delete them from the list
// of variables that are to be removed from the links and telemetry
// scheduler tables, and stop searching
removeMembers.removeAll(packMembers);
break;
}
}
// Adjust the child index to skip these bit-packed variables
childIndex = nodeIndex.getLastIndex();
}
}
// bit-packed, or packed with different variables)
for (String variable : removeMembers) {
// Get the path of the variable
String packPath = orgTableNode.getUserObject().toString() + "(?:\\\\.[^,]*)?," + CcddUtilities.escapePostgreSQLReservedChars(variable) + "(?::\\\\d+|$)";
// Delete the variable from the links and telemetry scheduler tables
deleteLinkPathRef("(?:^|[^,]*,)" + packPath, linksDelCmd);
deleteTlmPathRef("(?:[^,]+,)*" + packPath, tlmDelCmd);
}
return linksDelCmd.toString() + tlmDelCmd.toString();
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddDbTableCommandHandler method copyPrototypeTableTreeNode.
/**
********************************************************************************************
* Create a copy of the specified table's table tree node and immediate child nodes
*
* @param tableName
* table name
*
* @param tableTree
* CcddTableTreeHandler reference describing the table tree
*
* @return Copy of the specified table's table tree node and immediate child nodes (if any)
********************************************************************************************
*/
private ToolTipTreeNode copyPrototypeTableTreeNode(String tableName, CcddTableTreeHandler tableTree) {
// Create a new node for the copy
ToolTipTreeNode orgTableNode = new ToolTipTreeNode(tableName, "");
// Get prototype table's tree node. If the table has no variables then it doesn't appear in
// the table tree and this call returns null
ToolTipTreeNode tableNode = tableTree.getNodeByNodeName(tableName);
// Check if the table node exists
if (tableNode != null) {
// variables (data type and name)
for (int childIndex = 0; childIndex < tableNode.getChildCount(); childIndex++) {
// Copy the node (variable)
orgTableNode.add(new ToolTipTreeNode(((ToolTipTreeNode) tableNode.getChildAt(childIndex)).getUserObject().toString(), ""));
}
}
return orgTableNode;
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddCommonTreeHandler method getBitPackedVariables.
/**
********************************************************************************************
* Determine the node indices in the table tree that encompass a group of bit-packed variables
*
* @param node
* selected node for a (potentially) bit-packed variable
*
* @return NodeIndex object containing the node indices bounding the bit-packed variables
********************************************************************************************
*/
protected BitPackNodeIndex getBitPackedVariables(ToolTipTreeNode node) {
// Get the variable name from the node
String varName = removeExtraText(node.getUserObject().toString());
// Get the corresponding node in the variable tree
ToolTipTreeNode tblParent = (ToolTipTreeNode) node.getParent();
// Get this variable tree node's index in the variable tree relative to its parent node
int tblIndex = tblParent.getIndex(node);
int firstIndex = tblIndex;
int lastIndex = tblIndex;
// Check if the target variable has a bit length
if (varName.contains(":")) {
// Get the data type for this variable and calculate the number of bits it occupies
String dataType = varName.substring(0, varName.indexOf("."));
int dataTypeBitSize = dataTypeHandler.getSizeInBits(dataType);
// Set the current index in preparation for locating other variables packed with this
// one. Note that this can result is stepping backwards into another pack; this is
// accounted for further down
int curIndex = tblIndex - 1;
// data type are found
while (curIndex >= 0) {
// Get the variable name from the node
varName = removeExtraText(((ToolTipTreeNode) tblParent.getChildAt(curIndex)).getUserObject().toString());
// the target
if (!varName.contains(":") || !varName.startsWith(dataType + ".")) {
// Stop searching
break;
}
curIndex--;
}
// Adjust the index and save this as the starting index, and store its associated tree
// node index
curIndex++;
firstIndex = curIndex;
int bitCount = 0;
boolean isTargetInPack = false;
// variable's pack
while (curIndex < node.getSiblingCount()) {
// Get the variable name from the node
varName = removeExtraText(((ToolTipTreeNode) tblParent.getChildAt(curIndex)).getUserObject().toString());
// the target
if (!varName.contains(":") || !varName.startsWith(dataType + ".")) {
// Check if the target variable is a member of this packed group
if (curIndex == tblIndex) {
// Set the flag indicating this pack includes the target variable
isTargetInPack = true;
}
// Stop searching
break;
}
// Add the number of bits occupied by this variable to the running count
int bitLength = Integer.valueOf(macroHandler.getMacroExpansion(varName.substring(varName.indexOf(":") + 1)));
bitCount += bitLength;
// Check if the bit count rolled over the maximum allowed
if (bitCount > dataTypeBitSize) {
// Check if the target variable is included in the range of packed variables
if (isTargetInPack) {
// stop searching
break;
}
// Reset the bit count to the current row's value and store the row index for
// the first variable in the pack. This accounts for one or more bit-wise
// variables occurring immediately prior to the pack containing the target
bitCount = bitLength;
firstIndex = curIndex;
}
// Check if the target variable is a member of this packed group
if (curIndex == tblIndex) {
// Set the flag indicating this pack includes the target variable
isTargetInPack = true;
}
curIndex++;
}
// Store the last index in the pack. If the variable isn't bit-packed (i.e., has no bit
// length or has no other pack members) then the last index is the same as the first
// index
lastIndex = curIndex - (isTargetInPack ? 1 : 0);
}
return new BitPackNodeIndex(firstIndex, lastIndex, tblIndex);
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddCommonTreeHandler method getStringVariableMembers.
/**
********************************************************************************************
* Determine the node indices in the table tree that encompass the array members that represent
* the individual bytes of a string variable
*
* @param node
* selected node for a (potentially) bit-packed variable
*
* @return NodeIndex object containing the node indices bounding the string variable
********************************************************************************************
*/
protected BitPackNodeIndex getStringVariableMembers(ToolTipTreeNode node) {
// Get the target variable's data type and name from the node without the string size array
// index
String variableName = ArrayVariable.removeStringSize(removeExtraText(node.getUserObject().toString()));
// Get the corresponding node in the variable tree
ToolTipTreeNode tblParent = (ToolTipTreeNode) node.getParent();
// Get this variable tree node's index in the variable tree relative to its parent node
int tblIndex = tblParent.getIndex(node);
// Set the current index in preparation for locating other variables packed with this one
int curIndex = tblIndex - 1;
// the array members that make up the target string
while (curIndex >= 0) {
// Check if the variable at this node doesn't match the target variable
if (!variableName.equals(ArrayVariable.removeStringSize(removeExtraText(((ToolTipTreeNode) tblParent.getChildAt(curIndex)).getUserObject().toString())))) {
// Stop searching
break;
}
curIndex--;
}
// Adjust the index and save this as the starting index, and store its associated tree node
// index
curIndex++;
int firstIndex = curIndex;
// the target string
while (curIndex < node.getSiblingCount()) {
// Check if this variable at this node doesn't match the target variable
if (!variableName.equals(ArrayVariable.removeStringSize(removeExtraText(((ToolTipTreeNode) tblParent.getChildAt(curIndex)).getUserObject().toString())))) {
// Stop searching
break;
}
curIndex++;
}
// Store the last index in the pack. If the variable isn't bit-packed (i.e., has no bit
// length or has no other pack members) then the last index is the same as the first index
int lastIndex = curIndex - 1;
return new BitPackNodeIndex(firstIndex, lastIndex, tblIndex);
}
Aggregations