Search in sources :

Example 1 with TableTypeUpdate

use of CCDD.CcddConstants.TableTypeUpdate in project CCDD by nasa.

the class CcddTableTypeHandler method updateTableTypes.

/**
 ********************************************************************************************
 * Check if the specified table types are new or match an existing one. If new then add the
 * table type. If the table type name matches then compare the type definitions to ensure the
 * two are the same (ignoring the column descriptions)
 *
 * @param tableTypeDefinitions
 *            list of table type definitions
 *
 * @param fieldHandler
 *            reference to a data field handler
 *
 * @return null if all of the table types are created or match existing ones; the name of the
 *         table type that matches an existing one but the type definitions differ
 ********************************************************************************************
 */
protected String updateTableTypes(List<TableTypeDefinition> tableTypeDefinitions, CcddFieldHandler fieldHandler) {
    boolean isNewStruct = false;
    String badType = null;
    isNewField = false;
    // Step through each table type definition
    for (TableTypeDefinition tableTypeDefn : tableTypeDefinitions) {
        // Determine if the table type is new or matches an existing one with the same name
        TableTypeUpdate typeUpdate = updateTableTypes(tableTypeDefn, fieldHandler);
        // Check if the type name matches an existing one but the type definition differs
        if (typeUpdate == TableTypeUpdate.MISMATCH) {
            // Store the type name that mismatched and stop processing the table type
            // definitions
            badType = tableTypeDefn.getTypeName();
            break;
        }
        // Check if the table type is new and represents a structure
        if (typeUpdate == TableTypeUpdate.NEW && getTypeDefinition(tableTypeDefn.getTypeName()).isStructure()) {
            // Set the flag to indicate a structure table type was added
            isNewStruct = true;
        }
    }
    // Clear the table type definitions since they have been incorporated
    tableTypeDefinitions.clear();
    // Check if no mismatches occurred
    if (badType == null) {
        // Check if the deleted type represents a structure
        if (isNewStruct) {
            // Update the database functions that collect structure table members and
            // structure-defining column data
            dbControl.createStructureColumnFunctions();
        }
        // Check if the number of rate columns changed due to the type update
        if (ccddMain.getRateParameterHandler().setRateInformation()) {
            // Store the rate parameters in the project database
            dbTable.storeRateParameters(ccddMain.getMainFrame());
        }
        // Check if a data field was created for a table type
        if (isNewField) {
            // Store the data field table with the additional fields
            dbTable.storeInformationTable(InternalTable.FIELDS, fieldHandler.getFieldDefinitions(), null, ccddMain.getMainFrame());
        }
    }
    return badType;
}
Also used : TableTypeDefinition(CCDD.CcddClassesDataTable.TableTypeDefinition) TableTypeUpdate(CCDD.CcddConstants.TableTypeUpdate)

Example 2 with TableTypeUpdate

use of CCDD.CcddConstants.TableTypeUpdate in project CCDD by nasa.

the class CcddTableTypeHandler method updateTableTypes.

/**
 ********************************************************************************************
 * Check if specified table type is new or matches an existing one. If new then add the table
 * type. If the table type name matches then compare the type definitions to ensure the two are
 * the same (ignoring the column descriptions)
 *
 * @param tableTypeDefn
 *            table type definition
 *
 * @param fieldHandler
 *            reference to a data field handler
 *
 * @return TableTypeUpdate.NEW if the table type is new, TableTypeUpdate.MATCH if the table
 *         type matches an existing one, or TableTypeUpdate.MISMATCH if the table type name
 *         matches an existing one but the type definition differs
 ********************************************************************************************
 */
private TableTypeUpdate updateTableTypes(TableTypeDefinition tableTypeDefn, CcddFieldHandler fieldHandler) {
    TableTypeUpdate typeUpdate = TableTypeUpdate.MATCH;
    // Get the type definition based on the type name
    TypeDefinition typeDefn = getTypeDefinition(tableTypeDefn.getTypeName());
    // Check if the table type doesn't already exist
    if (typeDefn == null) {
        // Set the flag indicating the table type is new
        typeUpdate = TableTypeUpdate.NEW;
        // Add the new table type
        createTypeDefinition(tableTypeDefn.getTypeName(), tableTypeDefn.getColumns().toArray(new Object[0][0]), tableTypeDefn.getDescription());
        // Check if a data field is associated with the new table type
        if (tableTypeDefn.getDataFields().size() != 0) {
            // Add the table type's data field definitions, if any, to the existing field
            // definitions
            fieldHandler.getFieldDefinitions().addAll(tableTypeDefn.getDataFields());
            fieldHandler.buildFieldInformation(null);
            isNewField = true;
        }
        // Check if the table type editor is open
        if (ccddMain.getTableTypeEditor() != null && ccddMain.getTableTypeEditor().isShowing()) {
            // Add the new table type tab to the editor
            ccddMain.getTableTypeEditor().addTypePanes(new String[] { tableTypeDefn.getTypeName() }, tableTypeDefn.getDataFields());
        }
    } else // A table type with this name already exists
    {
        // Add the table type with a different name and get a reference to it
        TypeDefinition altTypeDefn = createTypeDefinition(tableTypeDefn.getTypeName() + "_TEMP", tableTypeDefn.getColumns().toArray(new Object[0][0]), tableTypeDefn.getDescription());
        // Ignore the column description (tool tip text) when comparing
        if (!(CcddUtilities.isArraySetsEqual(typeDefn.getColumnNamesUser(), altTypeDefn.getColumnNamesUser()) && CcddUtilities.isArraySetsEqual(typeDefn.getInputTypes(), altTypeDefn.getInputTypes()) && CcddUtilities.isArraySetsEqual(typeDefn.isRowValueUnique(), altTypeDefn.isRowValueUnique()) && CcddUtilities.isArraySetsEqual(typeDefn.isRequired(), altTypeDefn.isRequired()) && CcddUtilities.isArraySetsEqual(typeDefn.isStructureAllowed(), altTypeDefn.isStructureAllowed()) && CcddUtilities.isArraySetsEqual(typeDefn.isPointerAllowed(), altTypeDefn.isPointerAllowed()))) {
            // Set the flag indicating a mismatch exists
            typeUpdate = TableTypeUpdate.MISMATCH;
        }
        // Step through each table type data field
        for (String[] dataField : tableTypeDefn.getDataFields()) {
            // Get the reference to the data field from the existing field information
            FieldInformation fieldInfo = fieldHandler.getFieldInformationByName(dataField[FieldsColumn.OWNER_NAME.ordinal()], dataField[FieldsColumn.FIELD_NAME.ordinal()]);
            // Check if this is a new field
            if (fieldInfo == null) {
                // Add the field
                fieldHandler.getFieldDefinitions().add(dataField);
                isNewField = true;
            } else // value don't match (the description and size are allowed to differ)
            if (!dataField[FieldsColumn.FIELD_TYPE.ordinal()].equals(fieldInfo.getInputType().getInputName()) || !dataField[FieldsColumn.FIELD_REQUIRED.ordinal()].equalsIgnoreCase(Boolean.toString(fieldInfo.isRequired())) || !dataField[FieldsColumn.FIELD_APPLICABILITY.ordinal()].equals(fieldInfo.getApplicabilityType().getApplicabilityName()) || !dataField[FieldsColumn.FIELD_VALUE.ordinal()].equals(fieldInfo.getValue())) {
                // Set the flag indicating a mismatch exists
                typeUpdate = TableTypeUpdate.MISMATCH;
                break;
            }
        }
        // Delete the added type definition
        getTypeDefinitions().remove(altTypeDefn);
    }
    return typeUpdate;
}
Also used : TableTypeUpdate(CCDD.CcddConstants.TableTypeUpdate) TableTypeDefinition(CCDD.CcddClassesDataTable.TableTypeDefinition) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Aggregations

TableTypeDefinition (CCDD.CcddClassesDataTable.TableTypeDefinition)2 TableTypeUpdate (CCDD.CcddConstants.TableTypeUpdate)2 FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)1