Search in sources :

Example 16 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation 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)

Example 17 with FieldInformation

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

the class CcddDbTableCommandHandler method modifyFieldsCommand.

/**
 ********************************************************************************************
 * Build the command for updating the data field definitions table for the specified data
 * table, table type, or group
 *
 * @param ownerName
 *            name of the table, including the path if this table represents a structure, table
 *            type, or group to which the field(s) belong
 *
 * @param fieldInformation
 *            field information; null to delete the fields for the specified table/table
 *            type/group
 *
 * @return Command for updating the table/table type/group fields in the data field table
 ********************************************************************************************
 */
private String modifyFieldsCommand(String ownerName, List<FieldInformation> fieldInformation) {
    // Build the command to delete the existing field definitions for the specified table/group
    StringBuilder command = new StringBuilder("DELETE FROM " + InternalTable.FIELDS.getTableName() + " WHERE " + FieldsColumn.OWNER_NAME.getColumnName() + " = '" + ownerName + "'; ");
    // Check if any fields exist
    if (fieldInformation != null && !fieldInformation.isEmpty()) {
        // Append the command to insert the field definitions
        command.append("INSERT INTO " + InternalTable.FIELDS.getTableName() + " VALUES ");
        // Step through each of the table's field definitions
        for (FieldInformation fieldInfo : fieldInformation) {
            // Add the command to insert the field information
            command.append("('" + ownerName + "', " + delimitText(fieldInfo.getFieldName()) + ", " + delimitText(fieldInfo.getDescription()) + ", " + fieldInfo.getSize() + ", " + delimitText(fieldInfo.getInputType().getInputName()) + ", " + String.valueOf(fieldInfo.isRequired()) + ", " + delimitText(fieldInfo.getApplicabilityType().getApplicabilityName()) + ", " + delimitText(fieldInfo.getValue()) + "), ");
        }
        command = CcddUtilities.removeTrailer(command, ", ").append("; ");
    }
    return command.toString();
}
Also used : FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 18 with FieldInformation

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

the class CcddAssignMessageIDDialog method assignTableMessageIDs.

/**
 ********************************************************************************************
 * Assign message ID values to the structure, command, or other table type message ID columns
 * and data fields
 *
 * @param tabInfo
 *            message ID tab information reference
 *
 * @param tables
 *            list of structure, command, or other tables, with paths
 *
 * @param fieldInformation
 *            list of data field information
 *
 * @return true if a message ID value changed
 ********************************************************************************************
 */
private boolean assignTableMessageIDs(MsgTabInfo type, List<String> tables, List<FieldInformation> fieldInformation) {
    boolean isChanges = false;
    // Get the starting message ID and ID interval values
    int startID = Integer.decode(type.getStartFld().getText());
    int interval = Integer.valueOf(type.getIntervalFld().getText());
    // Step through each table type
    for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
        // Check if the tab information type and table type match the table type definition
        if ((type.getName().equals(TYPE_STRUCTURE) && typeDefn.isStructure()) || type.getName().equals(TYPE_COMMAND) && typeDefn.isCommand() || (type.getName().equals(TYPE_OTHER) && !typeDefn.isStructure() && !typeDefn.isCommand())) {
            // Get a list of the columns in this table type that are message IDs
            List<Integer> msgIDColumns = typeDefn.getColumnIndicesByInputType(InputDataType.MESSAGE_ID);
            // Check if the table type has any columns that are message IDs
            if (!msgIDColumns.isEmpty()) {
                // Step through each table
                for (String tablePath : tables) {
                    // Load the table's information from the project database
                    TableInformation tableInformation = dbTable.loadTableData(tablePath, false, false, false, CcddAssignMessageIDDialog.this);
                    // the current type definition
                    if (!tableInformation.isErrorFlag() && tableInformation.getType().equals(typeDefn.getName())) {
                        // Create a table editor handler, but without displaying the editor
                        // itself
                        CcddTableEditorHandler editor = new CcddTableEditorHandler(ccddMain, tableInformation, null);
                        // Check if the table arrays aren't expanded
                        if (!editor.isExpanded()) {
                            // Expand the table arrays
                            editor.showHideArrayMembers();
                        }
                        // Get the table's data (again if a name change occurred since changes
                        // were made)
                        Object[][] tableData = editor.getTable().getTableData(false);
                        // Step through each row in the table
                        for (int row = 0; row < editor.getTable().getModel().getRowCount(); row++) {
                            // Step through each column that contains message IDs
                            for (int idColumn : msgIDColumns) {
                                // values should be overwritten or if the cell is empty
                                if (editor.getTable().isCellEditable(editor.getTable().convertRowIndexToView(row), editor.getTable().convertColumnIndexToView(idColumn)) && !tableData[row][idColumn].toString().endsWith(PROTECTED_MSG_ID_IDENT) && (type.getOverwriteCbx().isSelected() || tableData[row][idColumn].toString().isEmpty())) {
                                    // Set the column message ID value to the next unused
                                    // message ID
                                    startID = getNextMessageID(startID, interval);
                                    tableData[row][idColumn] = formatMessageID(startID);
                                }
                            }
                        }
                        // Check if the a message ID in the table was changed
                        if (editor.getTable().isTableChanged(tableData)) {
                            // Load the updated array of data into the table
                            editor.getTable().loadDataArrayIntoTable(tableData, false);
                            // Build the table updates
                            editor.buildUpdates();
                            // Make the table modifications to the project database and to any
                            // open table editors
                            dbTable.modifyTableData(editor.getTableInformation(), editor.getAdditions(), editor.getModifications(), editor.getDeletions(), true, false, false, false, false, null, CcddAssignMessageIDDialog.this);
                        }
                    }
                }
            }
        }
    }
    // Step through each defined data field
    for (int index = 0; index < fieldInformation.size(); index++) {
        // Get the reference to the field information
        FieldInformation fieldInfo = fieldInformation.get(index);
        // blank
        if (fieldInfo.getInputType().equals(InputDataType.MESSAGE_ID) && tables.contains(fieldInfo.getOwnerName()) && !fieldInfo.getValue().endsWith(PROTECTED_MSG_ID_IDENT) && (type.getOverwriteCbx().isSelected() || fieldInfo.getValue().isEmpty())) {
            // Set the message ID data field value to the next unused message ID
            startID = getNextMessageID(startID, interval);
            fieldInfo.setValue(formatMessageID(startID));
            // the database. Step through each table editor dialog
            for (CcddTableEditorDialog editorDialog : ccddMain.getTableEditorDialogs()) {
                boolean isUpdate = false;
                // Step through each table editor in the editor dialog
                for (CcddTableEditorHandler editor : editorDialog.getTableEditors()) {
                    // Get the reference to the table's field handler
                    CcddFieldHandler editorFldHandler = editor.getTableInformation().getFieldHandler();
                    // to the new value
                    if (editorFldHandler.updateField(fieldInfo)) {
                        // Update the committed message ID value
                        editor.getCommittedTableInformation().getFieldHandler().updateField(fieldInfo);
                        // Update the editor data fields
                        editor.updateDataFields();
                        // Set the flag to indicate the table/field combination was located and
                        // stop searching
                        isUpdate = true;
                        break;
                    }
                }
                // Check if this table/field combination has been located
                if (isUpdate) {
                    // Stop searching
                    break;
                }
            }
            // Set the flag to indicate a message ID value is changed
            isChanges = true;
        }
    }
    return isChanges;
}
Also used : TableInformation(CCDD.CcddClassesDataTable.TableInformation) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 19 with FieldInformation

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

the class CcddApplicationSchedulerTableHandler method validateApplicationData.

/**
 ********************************************************************************************
 * Check all the stored application information for inconsistencies. Update or flag the
 * application for removal if any changes are found
 *
 * @return List of invalid applications
 ********************************************************************************************
 */
private List<Variable> validateApplicationData() {
    List<Variable> removedApps = new ArrayList<Variable>();
    // Create a group tree
    CcddGroupTreeHandler groupTree = new CcddGroupTreeHandler(ccddMain, null, ccddMain.getMainFrame());
    // Get a list of the current group's names
    String[] groupNames = groupTree.getGroupHandler().getGroupNames(true);
    // Create a data field handler to interact with the groups' fields
    CcddFieldHandler fieldHandler = new CcddFieldHandler(ccddMain);
    // Step through each application
    for (Variable app : applications) {
        boolean isValid = false;
        // Step through the group names
        for (String name : groupNames) {
            // Check if the group's name matches the application's name
            if (app.getFullName().equals(name)) {
                // Get the group's information and set the data field handler to contain the
                // current group's information
                GroupInformation groupInfo = groupTree.getGroupHandler().getGroupInformationByName(name);
                fieldHandler.setFieldInformation(groupInfo.getFieldInformation());
                // Get the application data field owner name
                String application = CcddFieldHandler.getFieldGroupName(groupInfo.getName());
                // Get the application's schedule rate
                FieldInformation appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.SCHEDULE_RATE.getFieldName());
                // Check if the application's rate equals its field's rate
                if (Float.valueOf(appInfo.getValue()) == app.getRate()) {
                    ApplicationData appData = (ApplicationData) app;
                    // Set the applications's validity to true
                    isValid = true;
                    // Get the run time field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.EXECUTION_TIME.getFieldName());
                    // Check if the application's run time changed
                    if (appInfo != null && Integer.valueOf(appInfo.getValue()) != app.getSize()) {
                        // Update the run time to what the field has set
                        app.setSize(Integer.valueOf(appInfo.getValue()));
                    }
                    // Get the execution priority field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.PRIORITY.getFieldName());
                    // Check if the application's priority changed
                    if (appInfo != null && Integer.valueOf(appInfo.getValue()) != appData.getPriority()) {
                        // Update the application's priority
                        appData.setPriority(Integer.valueOf(appInfo.getValue()));
                    }
                    // Get the message rate field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.MESSAGE_RATE.getFieldName());
                    // Check if the application's message rate changed
                    if (appInfo != null && Integer.valueOf(appInfo.getValue()) != appData.getMessageRate()) {
                        // Update the application's message rate
                        appData.setMessageRate(Integer.valueOf(appInfo.getValue()));
                    }
                    // Get the wake-up name field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.WAKE_UP_NAME.getFieldName());
                    // Check if the application's wake-up name changed
                    if (appInfo != null && !appInfo.getValue().equals(appData.getWakeUpName())) {
                        // Update the application's wake-up name
                        appData.setWakeUpName(appInfo.getValue());
                    }
                    // Get the wake-up ID field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.WAKE_UP_ID.getFieldName());
                    // Check if the application's wake-up ID changed
                    if (appInfo != null && !appInfo.getValue().equals(appData.getWakeUpID())) {
                        // Update the application's wake-up ID
                        appData.setWakeUpID(appInfo.getValue());
                    }
                    // Get the HK send rate field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.HK_SEND_RATE.getFieldName());
                    // Check if the application's HK send rate changed
                    if (appInfo != null && Integer.valueOf(appInfo.getValue()) != appData.getHkSendRate()) {
                        // Update the application's HK send rate
                        appData.setHkSendRate(Integer.valueOf(appInfo.getValue()));
                    }
                    // Get the HK wake-up name field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.HK_WAKE_UP_NAME.getFieldName());
                    // Check if the application's HK wake-up name changed
                    if (appInfo != null && !appInfo.getValue().equals(appData.getHkWakeUpName())) {
                        // Update the application's HK wake-up name
                        appData.setHkWakeUpName(appInfo.getValue());
                    }
                    // Get the HK wake-up ID field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.HK_WAKE_UP_ID.getFieldName());
                    // Check if the application's HK wake-up ID changed
                    if (appInfo != null && !appInfo.getValue().equals(appData.getHkWakeUpID())) {
                        // Update the application's HK wake-up ID
                        appData.setHkWakeUpID(appInfo.getValue());
                    }
                    // Get the schedule group field information
                    appInfo = fieldHandler.getFieldInformationByName(application, DefaultApplicationField.SCH_GROUP.getFieldName());
                    // Check if the application's schedule group changed
                    if (appInfo != null && !appInfo.getValue().equals(appData.getSchGroup())) {
                        // Update the application's schedule group
                        appData.setSchGroup(appInfo.getValue());
                    }
                }
                break;
            }
        }
        // Check if the application is invalid
        if (!isValid) {
            // Add the application to the list of removed applications
            removedApps.add(app);
        }
    }
    return removedApps;
}
Also used : Variable(CCDD.CcddClassesDataTable.Variable) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) ArrayList(java.util.ArrayList) ApplicationData(CCDD.CcddClassesDataTable.ApplicationData) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 20 with FieldInformation

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

the class CcddApplicationSchedulerInput method getDataFieldValue.

/**
 ********************************************************************************************
 * Get the data field value for the specified application and field name
 *
 * @param applicationName
 *            application name
 *
 * @param appField
 *            application data field
 *
 * @return Application data field value for the specified application
 ********************************************************************************************
 */
private String getDataFieldValue(String applicationName, DefaultApplicationField appField) {
    // Initialize the value to the default
    String value = appField.getInitialValue();
    // slot has no applications assigned
    if (!applicationName.isEmpty()) {
        // Update the data field handler with this application's field information
        fieldHndlr.setFieldInformation(applicationTree.getGroupHandler().getGroupInformationByName(applicationName).getFieldInformation());
        // Get the information for the specified data field
        FieldInformation groupInfo = fieldHndlr.getFieldInformationByName(CcddFieldHandler.getFieldGroupName(applicationName), appField.getFieldName());
        // Check if the field exists and isn't empty
        if (groupInfo != null && !groupInfo.getValue().isEmpty()) {
            // Get the data field value
            value = groupInfo.getValue();
        }
    }
    return value;
}
Also used : 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