Search in sources :

Example 6 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddDbTableCommandHandler method modifyTableType.

/**
 ********************************************************************************************
 * Add, rename, or delete table type column names in the table definitions table and update the
 * existing tables of the specified type
 *
 * @param typeName
 *            table type name to modify
 *
 * @param fieldInformation
 *            data field information list
 *
 * @param overwriteFields
 *            true if the content of existing fields should be overwritten by the default
 *            values; false to not overwrite existing values
 *
 * @param additions
 *            list of new columns to add to the tables. Each list item is an array containing:
 *            [0] column name (user), [1] column input type
 *
 * @param modifications
 *            list of name changes of existing columns in the tables. Each list item is an
 *            array containing: [0] original column name (user), [1] new column name (user),
 *            [2] column input type
 *
 * @param deletions
 *            list of columns to remove from the tables. Each list item is an array containing:
 *            [0] column name (user), [1] column input type
 *
 * @param columnOrderChange
 *            true if the table type's column order changed
 *
 * @param originalDefn
 *            reference to the table type definition prior to making any changes; null if this
 *            is a new table type
 *
 * @param editorDialog
 *            reference to the table type editor dialog
 *
 * @param editor
 *            reference to the table type editor where the change(s) occurred
 ********************************************************************************************
 */
protected void modifyTableType(String typeName, List<FieldInformation> fieldInformation, boolean overwriteFields, List<String[]> additions, List<String[]> modifications, List<String[]> deletions, boolean columnOrderChange, TypeDefinition originalDefn, CcddTableTypeEditorDialog editorDialog, CcddTableTypeEditorHandler editor) {
    try {
        boolean errorFlag = false;
        String[] tableNames = null;
        String names = "";
        // Get the type definition based on the table type name
        TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(typeName);
        // Set the flags that indicates if the table type definition represents a structure
        // prior to and after making the updates
        boolean wasStructure = originalDefn != null ? originalDefn.isStructure() : false;
        boolean isStructure = typeDefn.isStructure();
        // Create the command to update the table definitions table
        StringBuilder command = new StringBuilder(storeTableTypesInfoTableCommand());
        // Check if this isn't a new table type
        if (originalDefn != null) {
            // Get an array containing all of the prototype tables of the specified type
            String[] protoTableNames = queryTablesOfTypeList(typeName, editorDialog);
            String columnOrder = "";
            // Check if the column order changed or if any columns were added or deleted
            if (columnOrderChange || !additions.isEmpty() || !deletions.isEmpty()) {
                // Step through each column in the table type
                for (int index = 0; index < typeDefn.getColumnNamesDatabase().length; index++) {
                    // Add the column index and a separator
                    columnOrder += index + ":";
                }
                // Remove the trailing separator
                columnOrder = CcddUtilities.removeTrailer(columnOrder, ":");
            }
            // Create a list to store the names of all tables of the specified type
            List<String> tableNamesList = new ArrayList<String>();
            // Build a table tree with all prototype and instance tables
            CcddTableTreeHandler tableTree = new CcddTableTreeHandler(ccddMain, TableTreeType.TABLES, editorDialog);
            // Step through each prototype table of the specified type
            for (String protoName : protoTableNames) {
                // Create a list of table path arrays for instances of this prototype table
                // name
                tableNamesList.addAll(tableTree.getTableTreePathList(protoName));
                // Get the database form of the table name
                String dbTable = protoName.toLowerCase();
                // Step through each addition
                for (String[] add : additions) {
                    // Get the input data type, and the column name in database form
                    InputDataType inputDataType = InputDataType.getInputTypeByName(add[1]);
                    String dbName = DefaultColumn.convertVisibleToDatabase(add[0], inputDataType, isStructure);
                    // Append the add command
                    command.append("ALTER TABLE " + dbTable + " ADD COLUMN " + dbName + " text DEFAULT ''; ");
                }
                // Step through each modification
                for (String[] mod : modifications) {
                    // Get the old and new column names in database form
                    String oldDbName = DefaultColumn.convertVisibleToDatabase(mod[0], InputDataType.getInputTypeByName(mod[2]), isStructure);
                    String newDbName = DefaultColumn.convertVisibleToDatabase(mod[1], InputDataType.getInputTypeByName(mod[3]), isStructure);
                    // Check if the database form of the name changed
                    if (!oldDbName.equals(newDbName)) {
                        // Append the modify command
                        command.append("ALTER TABLE " + dbTable + " RENAME COLUMN " + oldDbName + " TO " + newDbName + "; ");
                    }
                }
                // Step through each deletion
                for (String[] del : deletions) {
                    // Get the input data type, and the column name in database form
                    InputDataType inputDataType = InputDataType.getInputTypeByName(del[1]);
                    String dbName = DefaultColumn.convertVisibleToDatabase(del[0], inputDataType, isStructure);
                    // Append the delete command
                    command.append("ALTER TABLE " + dbTable + " DROP COLUMN " + dbName + "; ");
                }
                // Check if the column order changed
                if (columnOrder.length() != 0) {
                    // Replace the column order for all tables matching this table name. This
                    // resets the column order for all users
                    command.append("UPDATE " + InternalTable.ORDERS.getTableName() + " SET " + OrdersColumn.COLUMN_ORDER.getColumnName() + " = '" + columnOrder + "' WHERE " + OrdersColumn.TABLE_PATH.getColumnName() + " ~ E'^" + protoName + "(,|$)'; ");
                }
            }
            // exist
            if ((!modifications.isEmpty() || !deletions.isEmpty()) && protoTableNames.length != 0) {
                // ////////////////////////////////////////////////////////////////////////////
                // Build the sub-command required to detect references to tables of the
                // affected type in the custom values, links, and telemetry scheduler tables
                // ////////////////////////////////////////////////////////////////////////////
                StringBuilder valuesCmd = new StringBuilder("");
                StringBuilder linksCmd = new StringBuilder("");
                StringBuilder tlmSchCmd = new StringBuilder("");
                // Step through each prototype table of the specified type
                for (String protoName : protoTableNames) {
                    // Build the table name comparison command for the custom values table
                    valuesCmd.append(ValuesColumn.TABLE_PATH.getColumnName() + " ~ E'[^,]+," + protoName + "\\.[^,]+,[^,]+$' OR ");
                }
                // Remove the trailing 'OR' and prepend an 'AND' to complete the custom values
                // command
                valuesCmd = CcddUtilities.removeTrailer(valuesCmd, " OR ");
                valuesCmd.insert(0, " AND (");
                valuesCmd.append(")");
                // Check if the table type represents a structure
                if (isStructure && wasStructure) {
                    // Step through each prototype table of the specified type
                    for (String protoName : protoTableNames) {
                        // Build the table name comparison command for the links and telemetry
                        // scheduler tables
                        linksCmd.append(LinksColumn.MEMBER.getColumnName() + " ~ E'(?:" + protoName + ",|[^,]+," + protoName + "\\.[^,]+,[^,]+$)' OR ");
                        tlmSchCmd.append(TlmSchedulerColumn.MEMBER.getColumnName() + " ~ E'(?:" + tlmSchSeparator + protoName + ",|[^,]+," + protoName + "\\.[^,]+,[^,]+$)' OR ");
                    }
                    // Remove the trailing 'OR' and prepend an 'AND' to complete the links and
                    // telemetry scheduler table commands
                    linksCmd = CcddUtilities.removeTrailer(linksCmd, " OR ");
                    linksCmd.insert(0, " AND (");
                    linksCmd.append(")");
                    tlmSchCmd = CcddUtilities.removeTrailer(tlmSchCmd, " OR ");
                    tlmSchCmd.insert(0, " AND (");
                    tlmSchCmd.append(")");
                }
                // doing so
                if (!isStructure && wasStructure) {
                    boolean hasSharedRate = false;
                    // Step through each rate column in the table type definition
                    for (int column : originalDefn.getColumnIndicesByInputType(InputDataType.RATE)) {
                        // Get the rate column name (as seen by the user)
                        String rateName = originalDefn.getColumnNamesUser()[column];
                        // Check if this is the only table type using this rate column name
                        if (rateHandler.getRateInformationByRateName(rateName).getNumSharedTableTypes() == 1) {
                            // Delete all entries in the links and telemetry scheduler tables
                            // that reference this rate name
                            command.append(deleteAllLinkAndTlmRateRefs(rateName));
                        } else // The rate is shared with another table type
                        {
                            // Set the flag indicating the table type has a shared rate
                            hasSharedRate = true;
                        }
                    }
                    // the specific table references in these internal tables
                    if (hasSharedRate) {
                        // Remove all references to tables of the changed type in the links and
                        // telemetry scheduler tables
                        command.append(deleteLinkAndTlmRateRef(".+", linksCmd, tlmSchCmd));
                    }
                }
                // Step through each modification
                for (String[] mod : modifications) {
                    // Check if the column name changed
                    if (!mod[0].equals(mod[1])) {
                        // Append the modify command for the custom values table
                        command.append("UPDATE " + InternalTable.VALUES.getTableName() + " SET " + ValuesColumn.COLUMN_NAME.getColumnName() + " = '" + mod[1] + "' WHERE " + ValuesColumn.COLUMN_NAME.getColumnName() + " = '" + mod[0] + "'" + valuesCmd + "; ");
                    }
                    // was a rate
                    if (isStructure && wasStructure && mod[2].equals(InputDataType.RATE.getInputName())) {
                        // column
                        if (!mod[3].equals(InputDataType.RATE.getInputName())) {
                            // Check if the rate name is used by another structure table type
                            if (rateHandler.getRateInformationByRateName(mod[0]).getNumSharedTableTypes() > 1) {
                                // Remove all references to tables of the changed type in the
                                // links and telemetry scheduler tables
                                command.append(deleteLinkAndTlmRateRef(mod[0], linksCmd, tlmSchCmd));
                            } else // The rate name is unique to this table type
                            {
                                // Remove all references to the original rate column name in
                                // the links and telemetry scheduler tables
                                command.append(deleteAllLinkAndTlmRateRefs(mod[0]));
                            }
                        } else // Check if the rate column name changed
                        if (!mod[0].equals(mod[1])) {
                            // table type
                            if (rateHandler.getRateInformationByRateName(mod[0]).getNumSharedTableTypes() > 1) {
                                // Remove all references to tables of the changed type in the
                                // links and telemetry scheduler tables
                                command.append(deleteLinkAndTlmRateRef(mod[0], linksCmd, tlmSchCmd));
                            } else // type (i.e., the rate name is unique to this table type)
                            if (rateHandler.getRateInformationByRateName(mod[1]) == null) {
                                // Append the modify command for the links and telemetry
                                // scheduler table
                                command.append("UPDATE " + InternalTable.LINKS.getTableName() + " SET " + LinksColumn.RATE_NAME.getColumnName() + " = '" + mod[1] + "' WHERE " + LinksColumn.RATE_NAME.getColumnName() + " = '" + mod[0] + "'; UPDATE " + InternalTable.TLM_SCHEDULER.getTableName() + " SET " + TlmSchedulerColumn.RATE_NAME.getColumnName() + " = '" + mod[1] + "' WHERE " + TlmSchedulerColumn.RATE_NAME.getColumnName() + " = '" + mod[0] + "'; ");
                            } else // The new rate name is already in use
                            {
                                // Remove all references to the original rate column name in
                                // the links and telemetry scheduler tables
                                command.append(deleteAllLinkAndTlmRateRefs(mod[0]));
                            }
                        }
                    }
                }
                // Step through each deletion
                for (String[] del : deletions) {
                    // Append the delete command for the custom values table
                    command.append("DELETE FROM " + InternalTable.VALUES.getTableName() + " WHERE " + ValuesColumn.COLUMN_NAME.getColumnName() + " = '" + del[0] + "'" + valuesCmd + "; ");
                    // deleted
                    if (isStructure && wasStructure && del[1].equals(InputDataType.RATE.getInputName())) {
                        // Check if the rate name is used by another structure table type
                        if (rateHandler.getRateInformationByRateName(del[0]).getNumSharedTableTypes() > 1) {
                            // Remove all references to tables of the changed type in the links
                            // and telemetry scheduler tables
                            command.append(deleteLinkAndTlmRateRef(del[0], linksCmd, tlmSchCmd));
                        } else // The rate name is unique to this table type
                        {
                            // Remove all references to the original rate column name in the
                            // links and telemetry/scheduler tables
                            command.append(deleteAllLinkAndTlmRateRefs(del[0]));
                        }
                    }
                }
            }
            // Create a field handler to store the data field information
            CcddFieldHandler fieldHandler = new CcddFieldHandler(ccddMain, null, editorDialog);
            // Step through each table of the specified type
            for (String tableName : tableNamesList) {
                // Set the flag to indicate if the table is a root structure
                boolean isRootStruct = isStructure && rootStructures.contains(tableName);
                // Get the existing data fields for this table
                fieldHandler.buildFieldInformation(tableName);
                // Get the number of separator and line break fields
                int numSep = fieldHandler.getFieldTypeCount(InputDataType.SEPARATOR);
                int numBrk = fieldHandler.getFieldTypeCount(InputDataType.BREAK);
                int sepCount = 0;
                int brkCount = 0;
                boolean isChanges = false;
                // Step through the default data fields for this table type
                for (FieldInformation fieldInfo : fieldInformation) {
                    // Check if this is a separator
                    if (fieldInfo.getInputType().equals(InputDataType.SEPARATOR)) {
                        // Increment the separator counter
                        sepCount++;
                    } else // Check if this is a line break
                    if (fieldInfo.getInputType().equals(InputDataType.BREAK)) {
                        // Increment the line break counter
                        brkCount++;
                    }
                    // Check if the data field meets the criteria of a new field for this table
                    if ((// The table doesn't have this data field
                    (fieldHandler.getFieldInformationByName(tableName, fieldInfo.getFieldName()) == null)) && // this table
                    (!tableName.contains(".") || fieldHandler.isFieldApplicable(tableName, fieldInfo.getApplicabilityType().getApplicabilityName(), isRootStruct)) || // separator in the type editor exceeds the number already in the table
                    (fieldInfo.getInputType().equals(InputDataType.SEPARATOR) && sepCount > numSep) || (fieldInfo.getInputType().equals(InputDataType.BREAK) && brkCount > numBrk)) {
                        // Add the data field to the table and set the flag indicating a change
                        // has been made
                        fieldHandler.addField(tableName, fieldInfo.getFieldName(), fieldInfo.getDescription(), fieldInfo.getSize(), fieldInfo.getInputType().getInputName(), fieldInfo.isRequired(), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue());
                        isChanges = true;
                    } else // overwritten, and if the field value(s) changed
                    if (overwriteFields && fieldHandler.updateField(new FieldInformation(tableName, fieldInfo.getFieldName(), fieldInfo.getDescription(), fieldInfo.getSize(), fieldInfo.getInputType().getInputName(), fieldInfo.isRequired(), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue()))) {
                        // Set the flag indicating a change has been made
                        isChanges = true;
                    }
                }
                // Check if any fields were added
                if (isChanges) {
                    // Create the command to modify the table's data field entries
                    command.append(modifyFieldsCommand(tableName, fieldHandler.getFieldInformation()));
                }
            }
            // Convert the list of modified tables names to an array
            tableNames = tableNamesList.toArray(new String[0]);
            // Check if any table of this type exists
            if (tableNames.length != 0) {
                // Convert the array of tables names into a single string and shorten it if too
                // long
                names = " and table(s) '</b>" + getShortenedTableNames(tableNames) + "<b>'";
            }
            // Build the command to update the data fields table and the telemetry scheduler
            // table comment (rate parameters)
            command.append(modifyFieldsCommand(CcddFieldHandler.getFieldTypeName(typeName), fieldInformation));
        }
        try {
            // Execute the command to change the table type and any table's of this type
            dbCommand.executeDbCommand(command.toString(), editorDialog);
            // Check if the type changed from being a structure to not being a structure
            if (!isStructure && wasStructure) {
                // Update the list of root structure tables
                rootStructures = getRootStructures(editorDialog);
            }
            // Log that updating the table type succeeded
            eventLog.logEvent(SUCCESS_MSG, "Table type '" + typeName + "'" + CcddUtilities.removeHTMLTags(names) + " updated");
        } catch (SQLException se) {
            // Inform the user that updating the tables failed
            eventLog.logFailEvent(editorDialog, "Cannot update table type '" + typeName + "'" + CcddUtilities.removeHTMLTags(names) + "; cause '" + se.getMessage() + "'", "<html><b>Cannot update table type '</b>" + typeName + "<b>'" + names);
            errorFlag = true;
        }
        // structure
        if (!errorFlag && (isStructure || wasStructure)) {
            // Step through each column addition
            for (String[] add : additions) {
                // Check if the column is a rate column
                if (add[1].equals(InputDataType.RATE.getInputName())) {
                    // Add the rate column to the rate information
                    rateHandler.addRateInformation(add[0]);
                }
            }
            // Step through each column modification
            for (String[] mod : modifications) {
                // Check if the column changed from a rate column to not being a rate column
                if (mod[2].equals(InputDataType.RATE.getInputName()) && !mod[3].equals(InputDataType.RATE.getInputName())) {
                    // Delete the rate column from the rate information
                    rateHandler.deleteRateInformation(mod[2]);
                } else // Check if the column changed from not being a rate column to a rate column
                if (!mod[2].equals(InputDataType.RATE.getInputName()) && mod[3].equals(InputDataType.RATE.getInputName())) {
                    // Add the rate column to the rate information
                    rateHandler.addRateInformation(mod[3]);
                } else // changed)
                if (mod[3].equals(InputDataType.RATE.getInputName())) {
                    // Rename (or add if the rate column is shared with another table type) the
                    // rate column in the rate information
                    rateHandler.renameRateInformation(mod[0], mod[1]);
                }
            }
            // Step through each column deletion
            for (String[] del : deletions) {
                // Check if the column is a rate column
                if (del[1].equals(InputDataType.RATE.getInputName())) {
                    // Delete the rate column from the rate information
                    rateHandler.deleteRateInformation(del[0]);
                }
            }
            // Update the rate column information and store it in the project database
            rateHandler.setRateInformation();
            storeRateParameters(editorDialog);
            // Update the database functions that collect structure table members and
            // structure-defining column data
            dbControl.createStructureColumnFunctions();
        }
        // Perform the type modification clean-up steps
        editorDialog.doTypeModificationComplete(errorFlag, editor, tableNames);
    } catch (Exception e) {
        // Display a dialog providing details on the unanticipated error
        CcddUtilities.displayException(e, editorDialog);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) CCDDException(CCDD.CcddClassesDataTable.CCDDException) SQLException(java.sql.SQLException) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) InputDataType(CCDD.CcddConstants.InputDataType) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 7 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddFieldHandler method getFieldValue.

/**
 ********************************************************************************************
 * Get the value of the data field with the specified input type for the specified field owner
 *
 * @param fieldOwner
 *            field owner name
 *
 * @param inputType
 *            InputDataTYpe for which to search
 *
 * @return Value of the data field with the specified input type for the specified field owner;
 *         null if the owner doesn't have a data field of that type
 ********************************************************************************************
 */
protected String getFieldValue(String fieldOwner, InputDataType inputType) {
    String fieldValue = null;
    // Get a reference to the first field of the specified type
    FieldInformation fieldInfo = getFieldInformationByInputType(fieldOwner, inputType);
    // Check if a non-empty field of the specified type exists
    if (fieldInfo != null && !fieldInfo.getValue().isEmpty()) {
        // Store the field value
        fieldValue = fieldInfo.getValue();
    }
    return fieldValue;
}
Also used : FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 8 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddFileIOHandler method addImportedDataField.

/**
 ********************************************************************************************
 * Import one or more data fields into a table, appending them to any existing fields. If the
 * imported field already exists then the input flag determines if the existing or imported
 * field is used
 *
 * @param fieldHandler
 *            field handler reference
 *
 * @param tableDefn
 *            imported table definition
 *
 * @param ownerName
 *            data field owner name
 *
 * @param useExistingFields
 *            true to replace an existing data field with the imported ones if the field names
 *            match
 ********************************************************************************************
 */
private void addImportedDataField(CcddFieldHandler fieldHandler, TableDefinition tableDefn, String ownerName, boolean useExistingFields) {
    // can be removed if needed
    for (int index = tableDefn.getDataFields().size() - 1; index >= 0; index--) {
        // Get the reference to the data field definitions to shorten subsequent calls
        String[] fieldDefn = tableDefn.getDataFields().get(index);
        // Set the data field owner to the specified table (if importing entire tables this
        // isn't necessary, but is when importing into an existing table since the owner in the
        // import file may differ)
        fieldDefn[FieldsColumn.OWNER_NAME.ordinal()] = ownerName;
        // Get the reference to the data field based on the table name and field name
        FieldInformation fieldInfo = fieldHandler.getFieldInformationByName(fieldDefn[FieldsColumn.OWNER_NAME.ordinal()], fieldDefn[FieldsColumn.FIELD_NAME.ordinal()]);
        // Check if the data field already exists
        if (fieldInfo != null) {
            // Check if the original data field information supersedes the imported one
            if (useExistingFields) {
                // Remove the new data field definition
                tableDefn.getDataFields().remove(index);
            } else // The imported data field information replaces the original
            {
                // Remove the original data field definition
                fieldHandler.getFieldInformation().remove(fieldInfo);
            }
        }
    }
    // Combine the existing and imported data fields
    tableDefn.getDataFields().addAll(0, fieldHandler.getFieldDefinitionsFromInformation());
}
Also used : FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 9 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddGroupTreeHandler method adjustNodeText.

/**
 ********************************************************************************************
 * Set the node text color based on the currently selected schedule rate and the rate of the
 * group to which the node belongs: black for a match and gray for a mismatch
 *
 * @param startNode
 *            starting node for which to adjust the text and color
 ********************************************************************************************
 */
protected void adjustNodeText(ToolTipTreeNode startNode, List<String> excludes) {
    // Step through the node's children, if any
    for (Enumeration<?> element = startNode.preorderEnumeration(); element.hasMoreElements(); ) {
        // Get the node reference
        ToolTipTreeNode node = (ToolTipTreeNode) element.nextElement();
        // Get the tree level for this node
        int level = node.getLevel();
        // called when no nodes exist
        if (level > 0) {
            // Get the group name from the node. The group name is the second node in the path
            // for this node
            String groupName = removeExtraText(node.getPath()[1].toString());
            // Get the reference to the group's information
            GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupName);
            // Check that the node references a group
            if (groupInfo != null) {
                // Get the node name
                String nodeName = node.getUserObject().toString();
                // Set to true if the group in this path is not excluded (as evidenced by
                // having a HTML tag)
                boolean wasExcluded = nodeName.contains(DISABLED_TEXT_COLOR);
                // Remove any HTML tags or other extra text from the node name
                nodeName = removeExtraText(nodeName);
                // Get the reference to the schedule rate field information
                fieldHandler.setFieldInformation(groupInfo.getFieldInformation());
                FieldInformation rateInfo = fieldHandler.getFieldInformationByName(CcddFieldHandler.getFieldGroupName(groupName), DefaultApplicationField.SCHEDULE_RATE.getFieldName());
                // Set the flag indicating the group is excluded if it's in the exclusion list
                boolean isExcluded = rateInfo == null || rateInfo.getValue().isEmpty() || !scheduleRate.equals(rateInfo.getValue()) || excludes.contains(nodeName);
                // Check if the group's exclusion state has changed
                if (wasExcluded != isExcluded) {
                    // Reset the node name to indicate its inclusion/exclusion state. If
                    // excluded, prepend the HTML tag to gray out the name. Indicate that the
                    // node changed so that the tree redraws the name
                    node.setUserObject((isExcluded ? DISABLED_TEXT_COLOR : "") + nodeName);
                    ((DefaultTreeModel) getModel()).nodeChanged(node);
                }
            }
        }
    }
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 10 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddFieldTableEditorDialog method doDataFieldUpdatesComplete.

/**
 ********************************************************************************************
 * Perform the steps needed following execution of database table changes
 *
 * @param commandError
 *            false if the database commands successfully completed; true
 ********************************************************************************************
 */
protected void doDataFieldUpdatesComplete(boolean commandError) {
    // Check that no error occurred performing the database commands
    if (!commandError) {
        // Clear the cells selected for deletion
        selectedCells.clear();
        // Load the data field information into the data field editor table
        reloadDataFieldTable();
        // Step through the open editor dialogs
        for (CcddTableEditorDialog editorDialog : ccddMain.getTableEditorDialogs()) {
            // Step through each individual editor in this editor dialog
            for (CcddTableEditorHandler editor : editorDialog.getTableEditors()) {
                List<String> redrawnTables = new ArrayList<String>();
                TableInformation tableInfo = editor.getTableInformation();
                // Step through the data field deletions
                for (String[] del : fieldDeletions) {
                    // already had a deletion applied
                    if (del[0].equals(tableInfo.getTablePath()) && !redrawnTables.contains(del[0])) {
                        // Add the table's name and path to the list of updated tables. This is
                        // used to prevent updating the data fields for a table multiple times
                        redrawnTables.add(del[0]);
                        // Rebuild the table's data field information
                        tableInfo.getFieldHandler().setFieldDefinitions(dataFields);
                        tableInfo.getFieldHandler().buildFieldInformation(del[0]);
                        // Store the data field information in the committed information so
                        // that this value change is ignored when updating or closing the table
                        editor.getCommittedTableInformation().getFieldHandler().setFieldInformation(tableInfo.getFieldHandler().getFieldInformationCopy());
                        // Rebuild the table's editor panel which contains the data fields
                        editor.createDataFieldPanel(false);
                    }
                }
                // Step through the data field value modifications
                for (String[] mod : fieldModifications) {
                    // already been updated by having a deletion applied
                    if (mod[0].equals(tableInfo.getTablePath()) && !redrawnTables.contains(mod[0])) {
                        // Get the reference to the modified field
                        FieldInformation fieldInfo = tableInfo.getFieldHandler().getFieldInformationByName(mod[0], mod[1]);
                        // Update the field's value. Also update the value in the committed
                        // information so that this value change is ignored when updating or
                        // closing the table
                        fieldInfo.setValue(mod[2]);
                        editor.getCommittedTableInformation().getFieldHandler().getFieldInformationByName(mod[0], mod[1]).setValue(mod[2]);
                        // Check that this isn't a boolean input (check box) data field
                        if (fieldInfo.getInputType().getInputFormat() != InputTypeFormat.BOOLEAN) {
                            // Display the updated value in the text field
                            ((UndoableTextField) fieldInfo.getInputFld()).setText(mod[2]);
                        }
                    }
                }
            }
        }
        // Clear the undo/redo cell edits stack
        dataFieldTable.getUndoManager().discardAllEdits();
    }
}
Also used : ArrayList(java.util.ArrayList) TableInformation(CCDD.CcddClassesDataTable.TableInformation) UndoableTextField(CCDD.CcddUndoHandler.UndoableTextField) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Aggregations

FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)35 ArrayList (java.util.ArrayList)16 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)7 GridBagLayout (java.awt.GridBagLayout)4 Point (java.awt.Point)4 JPanel (javax.swing.JPanel)4 CCDDException (CCDD.CcddClassesDataTable.CCDDException)3 TableInformation (CCDD.CcddClassesDataTable.TableInformation)3 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)3 UndoableCheckBox (CCDD.CcddUndoHandler.UndoableCheckBox)3 TableTypeDefinition (CCDD.CcddClassesDataTable.TableTypeDefinition)2 Variable (CCDD.CcddClassesDataTable.Variable)2 DefaultApplicationField (CCDD.CcddConstants.DefaultApplicationField)2 InputDataType (CCDD.CcddConstants.InputDataType)2 UndoableTextField (CCDD.CcddUndoHandler.UndoableTextField)2 Component (java.awt.Component)2 GridBagConstraints (java.awt.GridBagConstraints)2 JComponent (javax.swing.JComponent)2 JLabel (javax.swing.JLabel)2 JTextArea (javax.swing.JTextArea)2