Search in sources :

Example 1 with TableInformation

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

the class CcddTableEditorDialog method doTableModificationComplete.

/**
 ********************************************************************************************
 * Perform the steps needed following execution of a table modification. This includes closing
 * child table editors that are no longer valid and modifying child tables when a prototype
 * table is changed
 *
 * @param main
 *            reference to CcddMain
 *
 * @param dbTblCmdHndlr
 *            reference to CcddDbTableCommandHandler
 *
 * @param tableInfo
 *            table information
 *
 * @param modifications
 *            list of row update information
 *
 * @param deletions
 *            list of row deletion information
 *
 * @param forceUpdate
 *            true to make the changes to other tables; false to only make changes to tables
 *            other than the one in which the changes originally took place
 ********************************************************************************************
 */
protected static void doTableModificationComplete(CcddMain main, TableInformation tableInfo, List<TableModification> modifications, List<TableModification> deletions, boolean forceUpdate) {
    CcddDataTypeHandler dtHandler = main.getDataTypeHandler();
    CcddDbTableCommandHandler dbTblCmdHndlr = main.getDbTableCommandHandler();
    // Create a list to store the names of tables that are no longer valid
    List<String[]> invalidatedEditors = new ArrayList<String[]>();
    // Step through each row modification
    for (TableModification mod : modifications) {
        // type has been changed
        if (mod.getVariableColumn() != -1 && mod.getDataTypeColumn() != -1 && !dtHandler.isPrimitive(mod.getOriginalRowData()[mod.getDataTypeColumn()].toString()) && ((mod.getArraySizeColumn() != -1 && mod.getOriginalRowData()[mod.getArraySizeColumn()].toString().isEmpty() && !mod.getRowData()[mod.getArraySizeColumn()].toString().isEmpty()) || !mod.getOriginalRowData()[mod.getDataTypeColumn()].toString().equals(mod.getRowData()[mod.getDataTypeColumn()].toString()))) {
            // Add the pattern that matches the table editor tab names for the modified
            // structure. The pattern is [parent structure].__,[original structure data
            // type].[original structure variable name][,__]
            invalidatedEditors.add(new String[] { tableInfo.getPrototypeName(), mod.getOriginalRowData()[mod.getDataTypeColumn()].toString() + "." + mod.getOriginalRowData()[mod.getVariableColumn()].toString() });
        }
    }
    // Step through each row deletion
    for (TableModification del : deletions) {
        // Check if the original data type was for a structure
        if (del.getVariableColumn() != -1 && del.getDataTypeColumn() != -1 && !dtHandler.isPrimitive(del.getRowData()[del.getDataTypeColumn()].toString())) {
            // Add the pattern that matches the table editor tab names for the deleted
            // structure. The pattern is [parent structure].__,[structure data type].[structure
            // variable name][,__]
            invalidatedEditors.add(new String[] { tableInfo.getPrototypeName(), del.getRowData()[del.getDataTypeColumn()].toString() + "." + del.getRowData()[del.getVariableColumn()].toString() });
        }
    }
    // Close the invalid table editors
    dbTblCmdHndlr.closeDeletedTableEditors(invalidatedEditors, main.getMainFrame());
    // Update the tables with message names & IDs columns
    dbTblCmdHndlr.updateMessageIDNamesColumns(main.getMainFrame());
    // Step through the open editor dialogs
    for (CcddTableEditorDialog editorDialog : main.getTableEditorDialogs()) {
        // Step through each individual editor
        for (CcddTableEditorHandler editor : editorDialog.getTableEditors()) {
            // updated
            if (editor.getTableInformation().getPrototypeName().equals(tableInfo.getPrototypeName())) {
                // Flag that indicates true if a forced update is set (such as when a macro
                // name or value is changed), or if the updated table is a prototype and the
                // editor is for an instance table of the updated table
                boolean applyToChild = forceUpdate || (tableInfo.isPrototype() && !tableInfo.getTablePath().equals(editor.getTableInformation().getTablePath()));
                // Load the table from the database
                TableInformation updateInfo = main.getDbTableCommandHandler().loadTableData(editor.getTableInformation().getTablePath(), true, true, true, editorDialog);
                // Store the updates as the committed changes in the table (so that other
                // changes are recognized)
                editor.doTableUpdatesComplete(updateInfo, applyToChild);
            }
            // Check if the table's root structure status changed
            if (editor.getTableInformation().isRootStructure() != dbTblCmdHndlr.getRootStructures().contains(editor.getTableInformation().getTablePath())) {
                // Update the table's root structure status
                editor.getTableInformation().setRootStructure(!editor.getTableInformation().isRootStructure());
                // Rebuild the table's data fields based on the updated field information
                editor.createDataFieldPanel(false);
            }
            // Step through each row modification
            for (TableModification mod : modifications) {
                // this implies it could be a structure table reference
                if (mod.getVariableColumn() != -1 && mod.getDataTypeColumn() != -1) {
                    // Update the table names in the open editors
                    updateTableNames(main, mod.getOriginalRowData()[mod.getDataTypeColumn()].toString(), mod.getRowData()[mod.getDataTypeColumn()].toString(), mod.getOriginalRowData()[mod.getVariableColumn()].toString(), mod.getRowData()[mod.getVariableColumn()].toString(), editorDialog, editor);
                }
            }
        }
    }
    // Check if the data field editor table dialog is open
    if (main.getFieldTableEditor() != null && main.getFieldTableEditor().isShowing()) {
        // Update the data field editor table
        main.getFieldTableEditor().reloadDataFieldTable();
    }
}
Also used : ArrayList(java.util.ArrayList) TableModification(CCDD.CcddClassesDataTable.TableModification) TableInformation(CCDD.CcddClassesDataTable.TableInformation)

Example 2 with TableInformation

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

the class CcddTableEditorDialog method addTablePanes.

/**
 ********************************************************************************************
 * Add one or more table tabs to the editor dialog tabbed pane using the supplied table
 * information list and/or existing table editor tab contents
 *
 * @param tableInformation
 *            list containing information for each table
 *
 * @param editor
 *            reference to an existing table editor
 ********************************************************************************************
 */
protected void addTablePanes(List<TableInformation> tableInformation, CcddTableEditorHandler editor) {
    // Get the number of table editors already in the editor dialog
    int numExisting = tableEditors.size();
    // Check if a table editor is supplied
    if (editor != null) {
        // Add the editor to the list
        tableEditors.add(editor);
        // Create a tab for the editor
        tabbedPane.addTab(editor.getOwnerName(), null, editor.getFieldPanel(), editor.getTableToolTip());
        // Refresh the editor's change indicator, in case it's added while having unstored
        // changes
        updateChangeIndicator(editor);
    }
    // Check if table information is provided
    if (tableInformation != null) {
        // Step through the tables
        for (TableInformation tableInfo : tableInformation) {
            // Create an editor for this table and add it to the list of editors
            editor = new CcddTableEditorHandler(ccddMain, tableInfo, this);
            tableEditors.add(editor);
            // Create a tab for each table
            tabbedPane.addTab(editor.getOwnerName(), null, editor.getFieldPanel(), editor.getTableToolTip());
        }
    }
    // Check if only a single table was added
    if (tableEditors.size() - numExisting == 1) {
        // Select the tab for the newly opened table
        tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
    }
}
Also used : TableInformation(CCDD.CcddClassesDataTable.TableInformation)

Example 3 with TableInformation

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

the class CcddFileIOHandler method createTablesFromDefinitions.

/**
 ********************************************************************************************
 * Create one or more data tables from the supplied table definitions
 *
 * @param tableDefinitions
 *            list of table definitions for the table(s) to create
 *
 * @param replaceExisting
 *            true to replace a table that already exists in the database
 *
 * @param parent
 *            GUI component calling this method
 *
 * @throws CCDDException
 *             If the table path name is invalid or the table cannot be created from the table
 *             definition
 ********************************************************************************************
 */
private void createTablesFromDefinitions(List<TableDefinition> tableDefinitions, boolean replaceExisting, final Component parent) throws CCDDException {
    cancelImport = false;
    boolean prototypesOnly = true;
    List<String> skippedTables = new ArrayList<String>();
    // Get the list of all tables, including the paths for child structure tables
    CcddTableTreeHandler tableTree = new CcddTableTreeHandler(ccddMain, TableTreeType.TABLES, parent);
    List<String> allTables = tableTree.getTableTreePathList(null);
    // tables
    for (int loop = 1; loop <= 2 && !cancelImport; loop++) {
        // Step through each table definition
        for (TableDefinition tableDefn : tableDefinitions) {
            // Check if the table path/name format is valid
            if (!tableDefn.getName().matches(InputDataType.VARIABLE.getInputMatch() + "(?:$|(?:," + InputDataType.VARIABLE.getInputMatch() + "\\." + InputDataType.VARIABLE.getInputMatch() + ")+)")) {
                // Inform the user the table path/name isn't in the correct format
                throw new CCDDException("Invalid table path/name '</b>" + tableDefn.getName() + "<b>' format");
            }
            // Check if the table import was canceled by the user
            if (cancelImport) {
                // Add the table to the list of those skipped
                skippedTables.add(tableDefn.getName());
                continue;
            }
            // or if this is a child table and this is the second pass
            if (!tableDefn.getData().isEmpty() && (!tableDefn.getName().contains(",") != !prototypesOnly)) {
                // Get the table type definition for this table
                TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(tableDefn.getTypeName());
                // Get the number of table columns
                int numColumns = typeDefn.getColumnCountVisible();
                // Create the table information for the new table
                TableInformation tableInfo = new TableInformation(tableDefn.getTypeName(), tableDefn.getName(), new String[0][0], tableTypeHandler.getDefaultColumnOrder(tableDefn.getTypeName()), tableDefn.getDescription(), !tableDefn.getName().contains("."), tableDefn.getDataFields().toArray(new String[0][0]));
                // Check if the new table is not a prototype
                if (!tableInfo.isPrototype()) {
                    // Break the path into the individual structure variable references
                    String[] ancestors = tableInfo.getTablePath().split(",");
                    // table
                    for (int index = ancestors.length - 1; index >= 0 && !cancelImport; index--) {
                        // Split the ancestor into the data type (i.e., structure name) and
                        // variable name
                        String[] typeAndVar = ancestors[index].split("\\.");
                        // Check if the ancestor prototype table doesn't exist
                        if (!dbTable.isTableExists(typeAndVar[0].toLowerCase(), ccddMain.getMainFrame())) {
                            // Create the table information for the new prototype table
                            TableInformation ancestorInfo = new TableInformation(tableDefn.getTypeName(), typeAndVar[0], new String[0][0], tableTypeHandler.getDefaultColumnOrder(tableDefn.getTypeName()), "", true, tableDefn.getDataFields().toArray(new String[0][0]));
                            // Check if this is the child table and not one of its ancestors
                            if (index == ancestors.length - 1) {
                                // Create a list to store a copy of the cell data
                                List<String> protoData = new ArrayList<String>(tableDefn.getData());
                                // Step through each row of the cell data
                                for (int cellIndex = 0; cellIndex < tableDefn.getData().size(); cellIndex += numColumns) {
                                    // Step through each column in the row
                                    for (int colIndex = 0; colIndex < numColumns; colIndex++) {
                                        // type
                                        if (!DefaultColumn.isTypeRequiredColumn((typeDefn.isStructure() ? TYPE_STRUCTURE : (typeDefn.isCommand() ? TYPE_COMMAND : TYPE_OTHER)), typeDefn.getInputTypesVisible()[colIndex])) {
                                            // Replace the non-required column value with a
                                            // blank. The child's non-required values are
                                            // therefore not inherited from the prototype
                                            protoData.set(cellIndex + colIndex, "");
                                        }
                                    }
                                }
                                // the protected column data
                                if (!createImportedTable(ancestorInfo, protoData, numColumns, replaceExisting, "Cannot create prototype '" + ancestorInfo.getPrototypeName() + "' of child table", allTables, parent)) {
                                    // Add the skipped table to the list
                                    skippedTables.add(ancestorInfo.getTablePath());
                                }
                            } else // This is an ancestor of the child table
                            {
                                // Split the ancestor into the data type (i.e., structure name)
                                // and variable name
                                typeAndVar = ancestors[index + 1].split("\\.|$", -1);
                                // Add the variable reference to the new table
                                String[] rowData = new String[typeDefn.getColumnCountVisible()];
                                Arrays.fill(rowData, "");
                                rowData[typeDefn.getVisibleColumnIndexByUserName(typeDefn.getColumnNameByInputType(InputDataType.VARIABLE))] = typeAndVar[1];
                                rowData[typeDefn.getVisibleColumnIndexByUserName(typeDefn.getColumnNameByInputType(InputDataType.PRIM_AND_STRUCT))] = typeAndVar[0];
                                // the protected column data
                                if (!createImportedTable(ancestorInfo, Arrays.asList(rowData), numColumns, replaceExisting, "Cannot create prototype '" + ancestorInfo.getPrototypeName() + "' of child table's ancestor", allTables, parent)) {
                                    // Add the skipped table to the list
                                    skippedTables.add(ancestorInfo.getTablePath());
                                }
                            }
                        }
                    }
                    // Load the table's prototype data from the database and copy the
                    // prototype's data to the table
                    TableInformation protoInfo = dbTable.loadTableData(tableInfo.getPrototypeName(), false, false, false, ccddMain.getMainFrame());
                    tableInfo.setData(protoInfo.getData());
                }
                // Create a table from the imported information
                if (!createImportedTable(tableInfo, tableDefn.getData(), numColumns, replaceExisting, "Cannot create prototype '" + tableInfo.getPrototypeName() + "'", allTables, parent)) {
                    // Add the skipped table to the list
                    skippedTables.add(tableInfo.getTablePath());
                }
            }
        }
        prototypesOnly = false;
    }
    // Check if any tables were skipped
    if (!skippedTables.isEmpty()) {
        // Inform the user that one or more tables were not imported
        new CcddDialogHandler().showMessageDialog(parent, "<html><b>Table(s) not imported<br>'</b>" + dbTable.getShortenedTableNames(skippedTables.toArray(new String[0])) + "<b>';<br>table already exists", "Import Warning", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
    }
    // Store the table types
    dbTable.storeInformationTable(InternalTable.TABLE_TYPES, null, null, parent);
    // Store the data types
    dbTable.storeInformationTable(InternalTable.DATA_TYPES, CcddUtilities.removeArrayListColumn(dataTypeHandler.getDataTypeData(), DataTypesColumn.OID.ordinal()), null, parent);
    // Check if any macros are defined
    if (!macroHandler.getMacroData().isEmpty()) {
        // Store the macros in the database
        dbTable.storeInformationTable(InternalTable.MACROS, CcddUtilities.removeArrayListColumn(macroHandler.getMacroData(), MacrosColumn.OID.ordinal()), null, parent);
    }
    // Check if any reserved message IDs are defined
    if (!rsvMsgIDHandler.getReservedMsgIDData().isEmpty()) {
        // Store the reserved message IDs in the database
        dbTable.storeInformationTable(InternalTable.RESERVED_MSG_IDS, CcddUtilities.removeArrayListColumn(rsvMsgIDHandler.getReservedMsgIDData(), ReservedMsgIDsColumn.OID.ordinal()), null, parent);
    }
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) ArrayList(java.util.ArrayList) TableDefinition(CCDD.CcddClassesDataTable.TableDefinition) TableInformation(CCDD.CcddClassesDataTable.TableInformation) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Example 4 with TableInformation

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

Example 5 with TableInformation

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

the class CcddScriptDataAccessHandler method showData.

/**
 ********************************************************************************************
 * *** TODO INCLUDED FOR TESTING ***
 *
 * Display the table information for each associated table type
 ********************************************************************************************
 */
public void showData() {
    // Check if no table is associated with the script
    if (tableInformation == null || tableInformation.length == 0 || tableInformation[0].getType().isEmpty()) {
        System.out.println("No table data associated with this script");
    } else // A table is associated with the script
    {
        // Step through the information for each table type
        for (TableInformation tableInfo : tableInformation) {
            // Display the table's type
            System.out.println("Table data for type '" + tableInfo.getType() + "'");
            // Get the table's data
            String[][] data = tableInfo.getData();
            // Step through each row in the table
            for (int row = 0; row < data.length; row++) {
                // Display the row of table data
                System.out.println(row + ": " + Arrays.toString(data[row]));
            }
            System.out.println("");
        }
    }
}
Also used : TableInformation(CCDD.CcddClassesDataTable.TableInformation)

Aggregations

TableInformation (CCDD.CcddClassesDataTable.TableInformation)43 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)30 ArrayList (java.util.ArrayList)14 AssociatedColumns (CCDD.CcddClassesDataTable.AssociatedColumns)9 CCDDException (CCDD.CcddClassesDataTable.CCDDException)7 FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)3 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)2 TableModification (CCDD.CcddClassesDataTable.TableModification)2 SQLException (java.sql.SQLException)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)1 ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)1 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)1 TableTypeDefinition (CCDD.CcddClassesDataTable.TableTypeDefinition)1 DatabaseObject (CCDD.CcddConstants.DatabaseObject)1 UndoableTextField (CCDD.CcddUndoHandler.UndoableTextField)1 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1