Search in sources :

Example 11 with FieldInformation

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

the class CcddScriptDataAccessHandler method getProjectFields.

/**
 ********************************************************************************************
 * Get an array containing the data field information for the project
 *
 * @return Array containing the data field information for the project; an empty array if the
 *         project has no data fields. The array in is the format: field name, description,
 *         size, input type, required (true or false), applicability, value[,...]
 ********************************************************************************************
 */
public String[][] getProjectFields() {
    List<String[]> projectFields = new ArrayList<String[]>();
    // Build the project's data field information
    fieldHandler.buildFieldInformation(CcddFieldHandler.getFieldProjectName());
    // Step through each data field belonging to the project
    for (FieldInformation fieldInfo : fieldHandler.getFieldInformation()) {
        // Add the data field information to the list
        projectFields.add(new String[] { fieldInfo.getFieldName(), fieldInfo.getDescription(), Integer.toString(fieldInfo.getSize()), fieldInfo.getInputType().getInputName(), Boolean.toString(fieldInfo.isRequired()), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue() });
    }
    return projectFields.toArray(new String[0][0]);
}
Also used : ArrayList(java.util.ArrayList) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 12 with FieldInformation

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

the class CcddScriptDataAccessHandler method getDataFieldValue.

/**
 ********************************************************************************************
 * Get the contents of the data field for the specified table's specified data field
 *
 * @param ownerName
 *            name of the data field owner (table name, including the path if this table
 *            references a structure, group name, or table type name)
 *
 * @param fieldName
 *            data field name
 *
 * @return Data field value; returns a null if the owner name or field name is invalid
 ********************************************************************************************
 */
private String getDataFieldValue(String ownerName, String fieldName) {
    String fieldValue = null;
    // Get the reference to the data field information for the requested owner and field names
    FieldInformation fieldInfo = fieldHandler.getFieldInformationByName(ownerName, fieldName);
    // Check if a field for this owner exists
    if (fieldInfo != null) {
        // Get the field value
        fieldValue = fieldInfo.getValue();
        // Check if the data field contains a message ID
        if (fieldInfo.getInputType().equals(InputDataType.MESSAGE_ID)) {
            // Remove the auto-assignment protection flag, if present
            fieldValue = CcddMessageIDHandler.removeProtectionFlag(fieldValue);
        }
    }
    return fieldValue;
}
Also used : FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 13 with FieldInformation

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

the class CcddAssignMessageIDDialog method assignGroupMessageIDs.

/**
 ********************************************************************************************
 * Assign message ID values to the group data fields
 *
 * @param tabInfo
 *            message ID tab information reference
 *
 * @param fieldInformation
 *            list of data field information
 *
 * @return true if a message ID value changed
 ********************************************************************************************
 */
private boolean assignGroupMessageIDs(MsgTabInfo type, 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 defined data field
    for (int index = 0; index < fieldInformation.size(); index++) {
        // Get the reference to the field information
        FieldInformation fieldInfo = fieldInformation.get(index);
        // overwrite check box is selected or the field is blank
        if (fieldInfo.getInputType().equals(InputDataType.MESSAGE_ID) && fieldInfo.getOwnerName().startsWith(GROUP_DATA_FIELD_IDENT) && !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));
            // Set the flag to indicate a message ID value is changed
            isChanges = true;
        }
    }
    return isChanges;
}
Also used : FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 14 with FieldInformation

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

the class CcddCSVHandler method exportToFile.

/**
 ********************************************************************************************
 * Export the project in CSV format to the specified file
 *
 * @param exportFile
 *            reference to the user-specified output file
 *
 * @param tableNames
 *            array of table names to export
 *
 * @param replaceMacros
 *            true to replace any embedded macros with their corresponding values
 *
 * @param includeReservedMsgIDs
 *            true to include the contents of the reserved message ID table in the export file
 *
 * @param includeVariablePaths
 *            true to include the variable path for each variable in a structure table, both in
 *            application format and using the user-defined separator characters
 *
 * @param variableHandler
 *            variable handler class reference; null if includeVariablePaths is false
 *
 * @param separators
 *            string array containing the variable path separator character(s), show/hide data
 *            types flag ('true' or 'false'), and data type/variable name separator
 *            character(s); null if includeVariablePaths is false
 *
 * @param extraInfo
 *            unused
 *
 * @return true if an error occurred preventing exporting the project to the file
 ********************************************************************************************
 */
@Override
public boolean exportToFile(FileEnvVar exportFile, String[] tableNames, boolean replaceMacros, boolean includeReservedMsgIDs, boolean includeVariablePaths, CcddVariableSizeAndConversionHandler variableHandler, String[] separators, Object... extraInfo) {
    boolean errorFlag = false;
    boolean addLineFeed = false;
    FileWriter fw = null;
    BufferedWriter bw = null;
    PrintWriter pw = null;
    try {
        List<String> referencedTableTypes = new ArrayList<String>();
        List<String> referencedDataTypes = new ArrayList<String>();
        List<String> referencedMacros = new ArrayList<String>();
        List<String[]> variablePaths = new ArrayList<String[]>();
        // Output the table data to the selected file. Multiple writers are needed in case
        // tables are appended to an existing file
        fw = new FileWriter(exportFile, true);
        bw = new BufferedWriter(fw);
        pw = new PrintWriter(bw);
        // Step through each table
        for (String tblName : tableNames) {
            // Get the information from the database for the specified table
            TableInformation tableInfo = ccddMain.getDbTableCommandHandler().loadTableData(tblName, true, false, true, parent);
            // Check if the table's data successfully loaded
            if (!tableInfo.isErrorFlag()) {
                // Output the file creation information (for the first pass only)
                pw.printf((!addLineFeed ? "# Created " + new Date().toString() + " : project = " + dbControl.getDatabaseName() + " : host = " + dbControl.getServer() + " : user = " + dbControl.getUser() + "\n" : "") + "\n");
                // Get the table type definition based on the type name
                TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
                // Check if this table type is not already output
                if (!referencedTableTypes.contains(tableInfo.getType())) {
                    // Add the table type to the list of those referenced
                    referencedTableTypes.add(tableInfo.getType());
                }
                // Get the visible column names based on the table's type
                String[] columnNames = typeDefn.getColumnNamesVisible();
                // Check if the flag is set that indicates macros should be replaced
                if (replaceMacros) {
                    // Replace all macro names with their corresponding values
                    tableInfo.setData(macroHandler.replaceAllMacros(tableInfo.getData()));
                }
                String systemName = fieldHandler.getFieldValue(tblName, InputDataType.SYSTEM_PATH);
                // Check if the system name exists
                if (systemName != null && !systemName.isEmpty()) {
                    // Store the system name
                    systemName = ",\"" + systemName + "\"";
                }
                // Output the table path (if applicable) and name, table type, and system name
                // (if provided)
                pw.printf(CSVTags.NAME_TYPE.getTag() + "\n%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(tableInfo.getTablePath(), tableInfo.getType(), systemName));
                // Check if the table has a description
                if (!tableInfo.getDescription().isEmpty()) {
                    // Output the table description tag and description
                    pw.printf(CSVTags.DESCRIPTION.getTag() + "\n%s\n", CcddUtilities.addEmbeddedQuotes(tableInfo.getDescription()));
                }
                // Output the column data tag and column names
                pw.printf(CSVTags.COLUMN_NAMES.getTag() + "\n%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(columnNames));
                // Step through each row in the table
                for (int row = 0; row < tableInfo.getData().length; row++) {
                    // Output the table row data, skipping the hidden columns
                    pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(Arrays.copyOfRange(tableInfo.getData()[row], NUM_HIDDEN_COLUMNS, tableInfo.getData()[row].length)));
                    // Step through each column in the row, skipping the hidden columns
                    for (int column = NUM_HIDDEN_COLUMNS; column < columnNames.length; column++) {
                        List<Integer> dataTypeColumns = new ArrayList<Integer>();
                        // Get the column indices for all columns that can contain a primitive
                        // data type
                        dataTypeColumns.addAll(typeDefn.getColumnIndicesByInputType(InputDataType.PRIM_AND_STRUCT));
                        dataTypeColumns.addAll(typeDefn.getColumnIndicesByInputType(InputDataType.PRIMITIVE));
                        // Step through each data type column
                        for (int dataTypeColumn : dataTypeColumns) {
                            // Get the value in the data type column
                            String dataTypeName = tableInfo.getData()[row][dataTypeColumn].toString();
                            // list
                            if (dataTypeHandler.isPrimitive(dataTypeName) && !referencedDataTypes.contains(dataTypeName)) {
                                // Add the data type name to the list of references data types
                                referencedDataTypes.add(dataTypeName);
                            }
                        }
                        // Get the names of the macros referenced in the cell and add them to
                        // the list
                        referencedMacros.addAll(macroHandler.getReferencedMacros(tableInfo.getData()[row][column].toString()));
                        // represents a structure
                        if (includeVariablePaths && typeDefn.isStructure()) {
                            // Get the variable path
                            String variablePath = tableInfo.getTablePath() + "," + tableInfo.getData()[row][typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT)] + "." + tableInfo.getData()[row][typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE)];
                            // Add the path, in both application and user-defined formats, to
                            // the list to be output
                            variablePaths.add(new String[] { variablePath, variableHandler.getFullVariableName(variablePath, separators[0], Boolean.parseBoolean(separators[1]), separators[2]) });
                        }
                    }
                }
                // Get the table's data field information
                List<FieldInformation> fieldInformation = tableInfo.getFieldHandler().getFieldInformation();
                // Check if the table contains any data fields
                if (!fieldInformation.isEmpty()) {
                    // Output the data field marker
                    pw.printf(CSVTags.DATA_FIELD.getTag() + "\n");
                    // Step through each data field
                    for (FieldInformation fieldInfo : fieldInformation) {
                        // Output the field information
                        pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(fieldInfo.getFieldName(), fieldInfo.getDescription(), Integer.toString(fieldInfo.getSize()), fieldInfo.getInputType().getInputName(), Boolean.toString(fieldInfo.isRequired()), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue()));
                    }
                }
                addLineFeed = true;
            }
        }
        // Check if any table types are referenced
        if (!referencedTableTypes.isEmpty()) {
            // Step through each referenced table type
            for (String tableType : referencedTableTypes) {
                // Get the table type definition based on the type name
                TypeDefinition tableTypeDefn = tableTypeHandler.getTypeDefinition(tableType);
                // Output the table type tag, and the type name and description
                pw.printf("\n" + CSVTags.TABLE_TYPE.getTag() + "\n%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(tableTypeDefn.getName(), tableTypeDefn.getDescription()));
                // key and row index columns
                for (int column = NUM_HIDDEN_COLUMNS; column < tableTypeDefn.getColumnCountDatabase(); column++) {
                    // Output the column definition
                    pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(tableTypeDefn.getColumnNamesUser()[column], tableTypeDefn.getColumnToolTips()[column], tableTypeDefn.getInputTypes()[column].getInputName(), tableTypeDefn.isRowValueUnique()[column].toString(), tableTypeDefn.isRequired()[column].toString(), tableTypeDefn.isStructureAllowed()[column].toString(), tableTypeDefn.isPointerAllowed()[column].toString()));
                }
                // Build the data field information for this table type
                fieldHandler.buildFieldInformation(CcddFieldHandler.getFieldTypeName(tableType));
                List<FieldInformation> fieldInformation = fieldHandler.getFieldInformation();
                // Check if the table type contains any data fields
                if (!fieldInformation.isEmpty()) {
                    // Output the data field marker
                    pw.printf(CSVTags.TABLE_TYPE_DATA_FIELD.getTag() + "\n");
                    // Step through each data field
                    for (FieldInformation fieldInfo : fieldInformation) {
                        // Output the field information
                        pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(fieldInfo.getFieldName(), fieldInfo.getDescription(), Integer.toString(fieldInfo.getSize()), fieldInfo.getInputType().getInputName(), Boolean.toString(fieldInfo.isRequired()), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue()));
                    }
                }
            }
        }
        // Check if any primitive data types are referenced
        if (!referencedDataTypes.isEmpty()) {
            // Output the data type marker
            pw.printf("\n" + CSVTags.DATA_TYPE.getTag() + "\n");
            // Step through each data type
            for (String[] dataType : dataTypeHandler.getDataTypeData()) {
                // Check if the data type is referenced in the table
                if (referencedDataTypes.contains(CcddDataTypeHandler.getDataTypeName(dataType))) {
                    // Output the data type definition
                    pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(dataType[DataTypesColumn.USER_NAME.ordinal()], dataType[DataTypesColumn.C_NAME.ordinal()], dataType[DataTypesColumn.SIZE.ordinal()], dataType[DataTypesColumn.BASE_TYPE.ordinal()]));
                }
            }
        }
        // Check if any macros are referenced
        if (!referencedMacros.isEmpty()) {
            // Output the macro marker
            pw.printf("\n" + CSVTags.MACRO.getTag() + "\n");
            // Step through each macro
            for (String[] macro : macroHandler.getMacroData()) {
                // Check if the macro is referenced in the table
                if (referencedMacros.contains(macro[MacrosColumn.MACRO_NAME.ordinal()])) {
                    // Output the macro definition
                    pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(macro[MacrosColumn.MACRO_NAME.ordinal()], macro[MacrosColumn.VALUE.ordinal()]));
                }
            }
        }
        // reserved message IDs defined
        if (includeReservedMsgIDs && !rsvMsgIDHandler.getReservedMsgIDData().isEmpty()) {
            // Output the reserved message ID marker
            pw.printf("\n" + CSVTags.RESERVED_MSG_IDS.getTag() + "\n");
            // Step through each reserved message ID
            for (String[] reservedMsgID : rsvMsgIDHandler.getReservedMsgIDData()) {
                // Output the reserved message ID definition
                pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(reservedMsgID[ReservedMsgIDsColumn.MSG_ID.ordinal()], reservedMsgID[ReservedMsgIDsColumn.DESCRIPTION.ordinal()]));
            }
        }
        // Check if variable paths are to be output and that any exist
        if (includeVariablePaths && !variablePaths.isEmpty()) {
            // Output the variable path marker
            pw.printf("\n" + CSVTags.VARIABLE_PATHS.getTag() + "\n");
            // Step through each variable path
            for (String[] variablePath : variablePaths) {
                // Output the variable path in application and user-defined formats
                pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(variablePath[0], variablePath[1]));
            }
        }
    } catch (IOException ioe) {
        // Inform the user that the data file cannot be written to
        new CcddDialogHandler().showMessageDialog(parent, "<html><b>Cannot write to export file '</b>" + exportFile.getAbsolutePath() + "<b>'", "File Error", JOptionPane.ERROR_MESSAGE, DialogOption.OK_OPTION);
        errorFlag = true;
    } catch (Exception e) {
        // Display a dialog providing details on the unanticipated error
        CcddUtilities.displayException(e, parent);
        errorFlag = true;
    } finally {
        // Check if the PrintWriter was opened
        if (pw != null) {
            // Close the file
            pw.close();
        }
        try {
            // Check if the BufferedWriter was opened
            if (bw != null) {
                // Close the file
                bw.close();
            }
            // Check if the FileWriter was opened
            if (fw != null) {
                // Close the file
                fw.close();
            }
        } catch (IOException ioe) {
            // Inform the user that the data file cannot be closed
            new CcddDialogHandler().showMessageDialog(parent, "<html><b>Cannot close export file '</b>" + exportFile.getAbsolutePath() + "<b>'", "File Warning", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
        }
    }
    return errorFlag;
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) CCDDException(CCDD.CcddClassesDataTable.CCDDException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) TableTypeDefinition(CCDD.CcddClassesDataTable.TableTypeDefinition) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) TableInformation(CCDD.CcddClassesDataTable.TableInformation) PrintWriter(java.io.PrintWriter) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 15 with FieldInformation

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

the class CcddApplicationSchedulerInput method getAvailableRates.

/**
 ********************************************************************************************
 * Get an array of the available rates
 *
 * @return Array of rates
 ********************************************************************************************
 */
@Override
public String[] getAvailableRates() {
    // List of all the current rates
    List<String> rates = new ArrayList<String>();
    // Step through each application in the application tree
    for (GroupInformation appInfo : applicationTree.getGroupHandler().getGroupInformation()) {
        // Set the field handler to contain the current application's information
        fieldHndlr.setFieldInformation(appInfo.getFieldInformation());
        // Get the scheduler rate of the current application
        FieldInformation rateInfo = fieldHndlr.getFieldInformationByName(CcddFieldHandler.getFieldGroupName(appInfo.getName()), "Schedule Rate");
        // Check if the application had a schedule rate assigned
        if (rateInfo != null && !rates.contains(rateInfo.getValue())) {
            // Add the rate to the list of current rates
            rates.add(rateInfo.getValue());
        }
    }
    // Sort the list of rates from greatest to least
    Collections.sort(rates, Collections.reverseOrder(new Comparator<String>() {

        /**
         ************************************************************************************
         * Override the compare method to sort from greatest to least
         ************************************************************************************
         */
        @Override
        public int compare(String string1, String string2) {
            // Compare the integer value of the strings
            return Integer.valueOf(string1).compareTo(Integer.valueOf(string2));
        }
    }));
    return rates.toArray(new String[rates.size()]);
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) ArrayList(java.util.ArrayList) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation) Comparator(java.util.Comparator)

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