Search in sources :

Example 21 with CCDDException

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

the class CcddDataTypeEditorDialog method createDataTypeTable.

/**
 ********************************************************************************************
 * Create the data type table
 *
 * @return Reference to the scroll pane in which the table is placed
 ********************************************************************************************
 */
private JScrollPane createDataTypeTable() {
    // Define the data type editor JTable
    dataTypeTable = new CcddJTableHandler(DefaultPrimitiveTypeInfo.values().length) {

        /**
         ************************************************************************************
         * Allow multiple line display in user name and C name columns
         ************************************************************************************
         */
        @Override
        protected boolean isColumnMultiLine(int column) {
            return column == DataTypeEditorColumnInfo.USER_NAME.ordinal() || column == DataTypeEditorColumnInfo.C_NAME.ordinal();
        }

        /**
         ************************************************************************************
         * Hide the specified column(s)
         ************************************************************************************
         */
        @Override
        protected boolean isColumnHidden(int column) {
            return column == DataTypeEditorColumnInfo.OID.ordinal();
        }

        /**
         ************************************************************************************
         * Override isCellEditable so that all columns can be edited
         ************************************************************************************
         */
        @Override
        public boolean isCellEditable(int row, int column) {
            return true;
        }

        /**
         ************************************************************************************
         * Allow pasting data into the data type cells
         ************************************************************************************
         */
        @Override
        protected boolean isDataAlterable(Object[] rowData, int row, int column) {
            return isCellEditable(convertRowIndexToView(row), convertColumnIndexToView(column));
        }

        /**
         ************************************************************************************
         * Override getCellEditor so that for a base data type column cell the base data type
         * combo box cell editor is returned; for all other cells return the normal cell editor
         *
         * @param row
         *            table view row number
         *
         * @param column
         *            table view column number
         *
         * @return The cell editor for the specified row and column
         ************************************************************************************
         */
        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            // Get the editor for this cell
            TableCellEditor cellEditor = super.getCellEditor(row, column);
            // Convert the row and column indices to the model coordinates
            int modelColumn = convertColumnIndexToModel(column);
            // column
            if (modelColumn == DataTypeEditorColumnInfo.BASE_TYPE.ordinal()) {
                // Select the combo box cell editor that displays the base data types
                cellEditor = baseTypeCellEditor;
            }
            return cellEditor;
        }

        /**
         ************************************************************************************
         * Validate changes to the editable cells
         *
         * @param tableData
         *            list containing the table data row arrays
         *
         * @param row
         *            table model row number
         *
         * @param column
         *            table model column number
         *
         * @param oldValue
         *            original cell contents
         *
         * @param newValue
         *            new cell contents
         *
         * @param showMessage
         *            true to display the invalid input dialog, if applicable
         *
         * @param isMultiple
         *            true if this is one of multiple cells to be entered and checked; false if
         *            only a single input is being entered
         *
         * @return Always returns false
         ************************************************************************************
         */
        @Override
        protected Boolean validateCellContent(List<Object[]> tableData, int row, int column, Object oldValue, Object newValue, Boolean showMessage, boolean isMultiple) {
            // Reset the flag that indicates the last edited cell's content is invalid
            setLastCellValid(true);
            // Create a string version of the old and new values
            String oldValueS = oldValue.toString();
            String newValueS = newValue.toString();
            try {
                // Check if the value isn't blank
                if (!newValueS.isEmpty()) {
                    // Check if the data type user name or C type has been changed
                    if (column == DataTypeEditorColumnInfo.USER_NAME.ordinal() || column == DataTypeEditorColumnInfo.C_NAME.ordinal()) {
                        // avoid creating a duplicate
                        for (int otherRow = 0; otherRow < getRowCount(); otherRow++) {
                            // type name matches the one being added (case insensitive)
                            if (otherRow != row && newValueS.equalsIgnoreCase(CcddDataTypeHandler.getDataTypeName(tableData.get(otherRow)[DataTypeEditorColumnInfo.USER_NAME.ordinal()].toString(), tableData.get(otherRow)[DataTypeEditorColumnInfo.C_NAME.ordinal()].toString()))) {
                                throw new CCDDException("Data type name already in use");
                            }
                        }
                        // Check if the data type user name has been changed
                        if (column == DataTypeEditorColumnInfo.USER_NAME.ordinal()) {
                            // input type
                            if (!newValueS.matches(InputDataType.ALPHANUMERIC.getInputMatch())) {
                                throw new CCDDException("Illegal character(s) in data type name");
                            }
                        } else // The data type C type has been changed
                        {
                            // Initialize the C type name matching regular expression
                            String match = InputDataType.ALPHANUMERIC_MULTI.getInputMatch();
                            // Check if the base data type is a pointer
                            if (tableData.get(row)[DataTypeEditorColumnInfo.BASE_TYPE.ordinal()].equals(BaseDataTypeInfo.POINTER.getName())) {
                                // asterisk
                                if (!newValueS.endsWith("*")) {
                                    // Append an asterisk to the C type name
                                    newValueS += "*";
                                    tableData.get(row)[column] = newValueS;
                                }
                                // Add the ending asterisk to the matching regular expression
                                match += "\\*+";
                            } else // Check if the base type is blank
                            if (tableData.get(row)[DataTypeEditorColumnInfo.BASE_TYPE.ordinal()].toString().isEmpty()) {
                                // Add the optional ending asterisk to the matching regular
                                // expression
                                match += "\\*?+";
                            }
                            // alphanumeric input type (with an asterisk if this is a pointer)
                            if (!newValueS.matches(match)) {
                                throw new CCDDException("Illegal character(s) in data type C type name");
                            }
                        }
                    } else // Check if this is the data type size column
                    if (column == DataTypeEditorColumnInfo.SIZE.ordinal()) {
                        // Check if the data type size is not a positive integer
                        if (!newValueS.matches(InputDataType.INT_POSITIVE.getInputMatch())) {
                            throw new CCDDException("Data type size must be a positive integer");
                        }
                        // Remove any unneeded characters and store the cleaned number
                        tableData.get(row)[column] = Integer.valueOf(newValueS.replaceAll(InputDataType.INT_POSITIVE.getInputMatch(), "$1"));
                    } else // Check if this is the data type base type column
                    if (column == DataTypeEditorColumnInfo.BASE_TYPE.ordinal()) {
                        // Get the C type name
                        String cType = tableData.get(row)[DataTypeEditorColumnInfo.C_NAME.ordinal()].toString();
                        // Check if the base type changed from a non-pointer to a pointer
                        if (newValueS.equals(BaseDataTypeInfo.POINTER.getName())) {
                            // an asterisk
                            if (!cType.isEmpty() && !cType.endsWith("*")) {
                                // Append an asterisk to the C type name
                                tableData.get(row)[DataTypeEditorColumnInfo.C_NAME.ordinal()] += "*";
                            }
                        } else // the base type had been empty
                        if (oldValueS.equals(BaseDataTypeInfo.POINTER.getName()) || oldValueS.isEmpty()) {
                            // Remove any asterisks from the C type name
                            tableData.get(row)[DataTypeEditorColumnInfo.C_NAME.ordinal()] = cType.replaceAll("\\*", "");
                        }
                    }
                    // a non-integer
                    if (!oldValueS.isEmpty() && ((column == DataTypeEditorColumnInfo.SIZE.ordinal() && Integer.valueOf(newValueS) < Integer.valueOf(oldValueS) && (tableData.get(row)[DataTypeEditorColumnInfo.BASE_TYPE.ordinal()].equals(BaseDataTypeInfo.SIGNED_INT.getName()) || tableData.get(row)[DataTypeEditorColumnInfo.BASE_TYPE.ordinal()].equals(BaseDataTypeInfo.UNSIGNED_INT.getName()))) || (column == DataTypeEditorColumnInfo.BASE_TYPE.ordinal() && (oldValueS.equals(BaseDataTypeInfo.SIGNED_INT.getName()) || oldValueS.equals(BaseDataTypeInfo.UNSIGNED_INT.getName())) && !(newValueS.equals(BaseDataTypeInfo.SIGNED_INT.getName()) || newValueS.equals(BaseDataTypeInfo.UNSIGNED_INT.getName()))))) {
                        // Get the data type's index
                        String index = tableData.get(row)[DataTypeEditorColumnInfo.OID.ordinal()].toString();
                        // Step through the committed data types
                        for (int commRow = 0; commRow < committedData.length; commRow++) {
                            // Check if the index matches that for the committed data type
                            if (index.equals(committedData[commRow][DataTypeEditorColumnInfo.OID.ordinal()])) {
                                List<String> tableNames = new ArrayList<String>();
                                // Get the data type name. Use the committed name (in place of
                                // the current name in the editor, in case it's been changed)
                                // since this is how the data type is referenced in the data
                                // tables
                                String dataTypeName = CcddDataTypeHandler.getDataTypeName(CcddUtilities.convertObjectToString(committedData[commRow]));
                                // prototype tables
                                for (String dataTypeRef : getDataTypeReferences(dataTypeName).getReferences()) {
                                    // Split the reference into table name, column name, table
                                    // type, and context
                                    String[] tblColDescAndCntxt = dataTypeRef.split(TABLE_DESCRIPTION_SEPARATOR, 4);
                                    String refComment = tblColDescAndCntxt[SearchResultsQueryColumn.COMMENT.ordinal()];
                                    // Extract the viewable name and type of the table, and the
                                    // name of the column containing the data type. Separate
                                    // the column string into the individual column values
                                    String[] refNameAndType = refComment.split(",");
                                    String[] refColumns = CcddUtilities.splitAndRemoveQuotes(tblColDescAndCntxt[SearchResultsQueryColumn.CONTEXT.ordinal()]);
                                    // Use the type and column to get the column's input data
                                    // type
                                    TypeDefinition typeDefn = ccddMain.getTableTypeHandler().getTypeDefinition(refNameAndType[1]);
                                    // Get the index of the bit length column, if present
                                    int bitLengthIndex = typeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH);
                                    // Check if the byte size changed
                                    if (column == DataTypeEditorColumnInfo.SIZE.ordinal()) {
                                        // have a conflict
                                        if (bitLengthIndex != -1 && !refColumns[bitLengthIndex].isEmpty() && Integer.valueOf(newValueS) * 8 < Integer.valueOf(refColumns[bitLengthIndex]) && !tableNames.contains(refNameAndType[0])) {
                                            // The bit length is now too large; add the
                                            // affected table name to the list
                                            tableNames.add(refNameAndType[0]);
                                        }
                                    } else // The base type changed
                                    {
                                        // to have a conflict
                                        if (bitLengthIndex != -1 && !refColumns[bitLengthIndex].isEmpty() && !tableNames.contains(refNameAndType[0])) {
                                            // A bit length is not valid with the new data
                                            // type; add the affected table name to the list
                                            tableNames.add(refNameAndType[0]);
                                        }
                                        // Get the enumeration column index(ices), if present
                                        List<Integer> enumerationIndices = typeDefn.getColumnIndicesByInputType(InputDataType.ENUMERATION);
                                        // Step through each enumeration column
                                        for (int enumIndex : enumerationIndices) {
                                            // already been found to have a conflict
                                            if (!refColumns[enumIndex].isEmpty() && !tableNames.contains(refNameAndType[0])) {
                                                // An enumeration is not valid with the new
                                                // data type; add the affected table name to
                                                // the list
                                                tableNames.add(refNameAndType[0]);
                                            }
                                        }
                                    }
                                }
                                // were found
                                if (!tableNames.isEmpty()) {
                                    // Check if the byte size changed
                                    if (column == DataTypeEditorColumnInfo.SIZE.ordinal()) {
                                        throw new CCDDException("Bit length exceeds the size of the data type in table(s) '</b>" + dbTable.getShortenedTableNames(tableNames.toArray(new String[0])) + "<b>'");
                                    } else // The base type changed
                                    {
                                        throw new CCDDException("Base data type inconsistent with data type usage in table(s) '</b>" + dbTable.getShortenedTableNames(tableNames.toArray(new String[0])) + "<b>'");
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            } catch (CCDDException ce) {
                // Set the flag that indicates the last edited cell's content is invalid
                setLastCellValid(false);
                // Check if the input error dialog should be displayed
                if (showMessage) {
                    // Inform the user that the input value is invalid
                    new CcddDialogHandler().showMessageDialog(CcddDataTypeEditorDialog.this, "<html><b>" + ce.getMessage(), "Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                }
                // Restore the cell contents to its original value and pop the edit from the
                // stack
                tableData.get(row)[column] = oldValue;
                dataTypeTable.getUndoManager().undoRemoveEdit();
            }
            return false;
        }

        /**
         ************************************************************************************
         * Load the table data types into the table and format the table cells
         ************************************************************************************
         */
        @Override
        protected void loadAndFormatData() {
            // Place the data into the table model along with the column names, set up the
            // editors and renderers for the table cells, set up the table grid lines, and
            // calculate the minimum width required to display the table information
            setUpdatableCharacteristics(committedData, DataTypeEditorColumnInfo.getColumnNames(), null, DataTypeEditorColumnInfo.getToolTips(), true, true, true);
        }

        /**
         ************************************************************************************
         * Override prepareRenderer to allow adjusting the background colors of table cells
         ************************************************************************************
         */
        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            JComponent comp = (JComponent) super.prepareRenderer(renderer, row, column);
            // invalid highlighting, if applicable)
            if (!(isFocusOwner() && isRowSelected(row) && (isColumnSelected(column) || !getColumnSelectionAllowed()))) {
                boolean found = true;
                // Convert the column to model coordinates
                int modelColumn = dataTypeTable.convertColumnIndexToModel(column);
                // Check if both the user name and C type columns are blank
                if ((modelColumn == DataTypeEditorColumnInfo.USER_NAME.ordinal() || modelColumn == DataTypeEditorColumnInfo.C_NAME.ordinal()) && dataTypeTable.getValueAt(row, DataTypeEditorColumnInfo.USER_NAME.ordinal()).toString().isEmpty() && dataTypeTable.getValueAt(row, DataTypeEditorColumnInfo.C_NAME.ordinal()).toString().isEmpty()) {
                    // Set the flag indicating that the cell value is invalid
                    found = false;
                } else // Check if the cell is required and is empty
                if (DataTypeEditorColumnInfo.values()[modelColumn].isRequired() && dataTypeTable.getValueAt(row, column).toString().isEmpty()) {
                    // Set the flag indicating that the cell value is invalid
                    found = false;
                }
                // Check if the cell value is invalid
                if (!found) {
                    // Change the cell's background color
                    comp.setBackground(ModifiableColorInfo.REQUIRED_BACK.getColor());
                }
            }
            return comp;
        }

        /**
         ************************************************************************************
         * Override the CcddJTableHandler method to produce an array containing empty values
         * for a new row in this table
         *
         * @return Array containing blank cell values for a new row
         ************************************************************************************
         */
        @Override
        protected Object[] getEmptyRow() {
            return DataTypeEditorColumnInfo.getEmptyRow();
        }

        /**
         ************************************************************************************
         * Handle a change to the table's content
         ************************************************************************************
         */
        @Override
        protected void processTableContentChange() {
            // Add or remove the change indicator based on whether any unstored changes exist
            setTitle(DIALOG_TITLE + (dataTypeTable.isTableChanged(committedData) ? "*" : ""));
            // Force the table to redraw so that changes to the cells are displayed
            repaint();
        }
    };
    // Place the table into a scroll pane
    JScrollPane scrollPane = new JScrollPane(dataTypeTable);
    // Disable storage of edit operations during creation of the table
    dataTypeTable.getUndoHandler().setAllowUndo(false);
    // Set common table parameters and characteristics
    dataTypeTable.setFixedCharacteristics(scrollPane, true, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, TableSelectionMode.SELECT_BY_CELL, false, ModifiableColorInfo.TABLE_BACK.getColor(), true, true, ModifiableFontInfo.DATA_TABLE_CELL.getFont(), true);
    // Re-enable storage of edit operations
    dataTypeTable.getUndoHandler().setAllowUndo(true);
    return scrollPane;
}
Also used : JScrollPane(javax.swing.JScrollPane) TableCellRenderer(javax.swing.table.TableCellRenderer) CCDDException(CCDD.CcddClassesDataTable.CCDDException) JComponent(javax.swing.JComponent) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) List(java.util.List) ArrayList(java.util.ArrayList) TableCellEditor(javax.swing.table.TableCellEditor) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 22 with CCDDException

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

the class CcddFieldEditorDialog method initialize.

/**
 ********************************************************************************************
 * Create the data field editor dialog
 *
 * @param minimumWidth
 *            minimum pixel width of the caller
 ********************************************************************************************
 */
private void initialize(final int minimumWidth) {
    // Store the field information
    currentData = fieldPnlHndlr.getFieldHandler().getFieldEditorDefinition();
    // Define the table data field editor JTable
    fieldTable = new CcddJTableHandler() {

        /**
         ************************************************************************************
         * Allow resizing of all columns except the Size, Required, and Applicability columns
         ************************************************************************************
         */
        @Override
        protected boolean isColumnResizable(int column) {
            return column != FieldEditorColumnInfo.REQUIRED.ordinal() && column != FieldEditorColumnInfo.SIZE.ordinal() && column != FieldEditorColumnInfo.APPLICABILITY.ordinal();
        }

        /**
         ************************************************************************************
         * Allow multiple line display in all but the Required, Size, and Applicability columns
         ************************************************************************************
         */
        @Override
        protected boolean isColumnMultiLine(int column) {
            return column != FieldEditorColumnInfo.REQUIRED.ordinal() && column != FieldEditorColumnInfo.SIZE.ordinal() && column != FieldEditorColumnInfo.APPLICABILITY.ordinal();
        }

        /**
         ************************************************************************************
         * Hide the specified column(s)
         ************************************************************************************
         */
        @Override
        protected boolean isColumnHidden(int column) {
            return column == FieldEditorColumnInfo.VALUE.ordinal() || (!includeApplicability && column == FieldEditorColumnInfo.APPLICABILITY.ordinal());
        }

        /**
         ************************************************************************************
         * Display the specified column(s) as check boxes
         ************************************************************************************
         */
        @Override
        protected boolean isColumnBoolean(int column) {
            return column == FieldEditorColumnInfo.REQUIRED.ordinal();
        }

        /**
         ************************************************************************************
         * Override isCellEditable so that all columns except the line separators and breaks
         * can be edited
         ************************************************************************************
         */
        @Override
        public boolean isCellEditable(int row, int column) {
            boolean isEditable = true;
            // Check that the table has rows
            if (fieldTable.getRowCount() != 0) {
                // Get the text in the input type column
                String cellValue = fieldTable.getValueAt(row, inputTypeIndex).toString();
                // Check if the row represents a separator or line break
                if (cellValue.equals(InputDataType.SEPARATOR.getInputName()) || cellValue.equals(InputDataType.BREAK.getInputName())) {
                    // Set the flag to indicate this cell is not editable
                    isEditable = false;
                }
            }
            return isEditable;
        }

        /**
         ************************************************************************************
         * Allow pasting data into the data field cells
         ************************************************************************************
         */
        @Override
        protected boolean isDataAlterable(Object[] rowData, int row, int column) {
            return isCellEditable(convertRowIndexToView(row), convertColumnIndexToView(column));
        }

        /**
         ************************************************************************************
         * Override the CcddJTableHandler method to prevent deleting the contents of the cell
         * at the specified row and column
         *
         * @param row
         *            table row index in view coordinates
         *
         * @param column
         *            table column index in view coordinates
         *
         * @return false if the cell contains a combo box; true otherwise
         ************************************************************************************
         */
        @Override
        protected boolean isCellBlankable(int row, int column) {
            // Convert the column index to model coordinates
            column = convertColumnIndexToModel(column);
            return column != FieldEditorColumnInfo.INPUT_TYPE.ordinal() && column != FieldEditorColumnInfo.APPLICABILITY.ordinal();
        }

        /**
         ************************************************************************************
         * Validate changes to the editable cells
         *
         * @param tableData
         *            list containing the table data row arrays
         *
         * @param row
         *            table model row number
         *
         * @param column
         *            table model column number
         *
         * @param oldValue
         *            original cell contents
         *
         * @param newValue
         *            new cell contents
         *
         * @param showMessage
         *            true to display the invalid input dialog, if applicable
         *
         * @param isMultiple
         *            true if this is one of multiple cells to be entered and checked; false if
         *            only a single input is being entered
         *
         * @return Always returns false
         ***********************************************************************************
         */
        @Override
        protected Boolean validateCellContent(List<Object[]> tableData, int row, int column, Object oldValue, Object newValue, Boolean showMessage, boolean isMultiple) {
            // Reset the flag that indicates the last edited cell's content is invalid
            setLastCellValid(true);
            // Create a string version of the new value
            String newValueS = newValue.toString();
            try {
                // Check if the field name has been changed and if the name isn't blank
                if (column == FieldEditorColumnInfo.NAME.ordinal() && !newValueS.isEmpty()) {
                    // creating a duplicate
                    for (int otherRow = 0; otherRow < getRowCount(); otherRow++) {
                        // matches the one being added (case insensitive)
                        if (otherRow != row && newValueS.equalsIgnoreCase(tableData.get(otherRow)[column].toString())) {
                            throw new CCDDException("Field name '" + newValueS + "' already in use");
                        }
                    }
                } else // Check if this is the field size column
                if (column == FieldEditorColumnInfo.SIZE.ordinal()) {
                    // Check if the field size is not a positive integer
                    if (!newValueS.matches(InputDataType.INT_POSITIVE.getInputMatch())) {
                        throw new CCDDException("Field size must be a positive integer");
                    }
                    // the interface unusable
                    if (Integer.valueOf(newValueS) > ModifiableSizeInfo.MAX_DATA_FIELD_CHAR_WIDTH.getSize()) {
                        throw new CCDDException("Field size must be less than or equal to " + ModifiableSizeInfo.MAX_DATA_FIELD_CHAR_WIDTH.getSize());
                    }
                    // Remove any unneeded characters and store the cleaned number
                    tableData.get(row)[column] = Integer.valueOf(newValueS.replaceAll(InputDataType.INT_POSITIVE.getInputMatch(), "$1"));
                }
            } catch (CCDDException ce) {
                // Set the flag that indicates the last edited cell's content is invalid
                setLastCellValid(false);
                // Check if the input error dialog should be displayed
                if (showMessage) {
                    // Inform the user that the input value is invalid
                    new CcddDialogHandler().showMessageDialog(CcddFieldEditorDialog.this, "<html><b>" + ce.getMessage(), "Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                }
                // Restore the column name to its original value and set the error message
                tableData.get(row)[column] = oldValue;
            }
            return false;
        }

        /**
         ************************************************************************************
         * Load the table data field definition values into the table and format the table
         * cells
         ************************************************************************************
         */
        @Override
        protected void loadAndFormatData() {
            // Place the data into the table model along with the column names, set up the
            // editors and renderers for the table cells, set up the table grid lines, and
            // calculate the minimum width required to display the table information
            setUpdatableCharacteristics(currentData, FieldEditorColumnInfo.getColumnNames(), null, FieldEditorColumnInfo.getToolTips(), true, true, true);
        }

        /**
         ************************************************************************************
         * Override prepareRenderer to allow adjusting the background colors of table cells
         ************************************************************************************
         */
        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            JComponent comp = (JComponent) super.prepareRenderer(renderer, row, column);
            // invalid highlighting, if applicable)
            if (!(isFocusOwner() && isRowSelected(row) && (isColumnSelected(column) || !getColumnSelectionAllowed()))) {
                boolean found = true;
                // Check if the cell is required and is empty
                if (FieldEditorColumnInfo.values()[fieldTable.convertColumnIndexToModel(column)].isRequired() && fieldTable.getValueAt(row, column).toString().isEmpty()) {
                    // Set the flag indicating that the cell value is invalid
                    found = false;
                } else // Check if this is the input type column
                if (column == inputTypeIndex && inputTypeCbox != null) {
                    found = false;
                    // Check if the type is a separator or line break
                    if (fieldTable.getValueAt(row, column).equals(InputDataType.SEPARATOR.getInputName()) || fieldTable.getValueAt(row, column).equals(InputDataType.BREAK.getInputName())) {
                        found = true;
                    } else // The type is not a separator or line break
                    {
                        // Step through each combo box item
                        for (int index = 0; index < inputTypeCbox.getItemCount() && !found; index++) {
                            // Check if the cell matches the combo box item
                            if (inputTypeCbox.getItemAt(index).equals(fieldTable.getValueAt(row, column).toString())) {
                                // Set the flag indicating that the cell value is valid
                                found = true;
                            }
                        }
                    }
                }
                // Check if the cell value is invalid
                if (!found) {
                    // Change the cell's background color
                    comp.setBackground(ModifiableColorInfo.REQUIRED_BACK.getColor());
                }
            }
            return comp;
        }

        /**
         ************************************************************************************
         * Override the CcddJTableHandler method to produce an array containing empty values
         * for a new row in this table
         *
         * @return Array containing blank cell values for a new row
         ************************************************************************************
         */
        @Override
        protected Object[] getEmptyRow() {
            return FieldEditorColumnInfo.getEmptyRow();
        }

        /**
         ************************************************************************************
         * Handle a change to the table's content
         ************************************************************************************
         */
        @Override
        protected void processTableContentChange() {
            // Add or remove the change indicator based on whether or not any unstored changes
            // exist
            setTitle(DIALOG_TITLE + ": " + ownerName + (fieldTable.isTableChanged(currentData) ? "*" : ""));
            // Force the table to redraw so that changes to the cells are displayed
            repaint();
        }
    };
    // Place the table into a scroll pane
    JScrollPane scrollPane = new JScrollPane(fieldTable);
    // Disable storage of edit operations during table creation
    fieldTable.getUndoHandler().setAllowUndo(false);
    // Set common table parameters and characteristics
    fieldTable.setFixedCharacteristics(scrollPane, true, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, TableSelectionMode.SELECT_BY_CELL, false, ModifiableColorInfo.TABLE_BACK.getColor(), true, true, ModifiableFontInfo.DATA_TABLE_CELL.getFont(), true);
    // Create a drop-down combo box to display the available field input data types
    setUpInputTypeColumn();
    // Create a drop-down combo box to display the available field applicability types
    setUpApplicabilityColumn();
    // Re-enable storage of edit operations
    fieldTable.getUndoHandler().setAllowUndo(true);
    // Define the editor panel to contain the table
    JPanel editorPanel = new JPanel();
    editorPanel.setLayout(new BoxLayout(editorPanel, BoxLayout.X_AXIS));
    editorPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
    editorPanel.add(scrollPane);
    // Set the initial layout manager characteristics
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0);
    // Create an outer panel to put the editor panel in (the border doesn't appear without
    // this)
    outerPanel = new JPanel(new GridBagLayout());
    outerPanel.add(editorPanel, gbc);
    outerPanel.setBorder(BorderFactory.createEmptyBorder());
    // Create the lower (button) panel
    JPanel buttonPnl = new JPanel();
    // Insert button
    btnInsertRow = CcddButtonPanelHandler.createButton("Ins Row", INSERT_ICON, KeyEvent.VK_I, "Insert a new row into the table");
    // Create a listener for the Insert Row button
    btnInsertRow.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Insert a new row into the table at the selected location
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fieldTable.insertEmptyRow(true);
        }
    });
    // Delete button
    btnDeleteRow = CcddButtonPanelHandler.createButton("Del Row", DELETE_ICON, KeyEvent.VK_D, "Delete the selected row(s) from the table");
    // Create a listener for the Delete row button
    btnDeleteRow.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Delete the selected row(s) from the table
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fieldTable.deleteRow(true);
        }
    });
    // Move Up button
    btnMoveUp = CcddButtonPanelHandler.createButton("Up", UP_ICON, KeyEvent.VK_U, "Move the selected row(s) up");
    // Create a listener for the Move Up button
    btnMoveUp.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Move the selected row(s) up in the table
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fieldTable.moveRowUp();
        }
    });
    // Move Down button
    btnMoveDown = CcddButtonPanelHandler.createButton("Down", DOWN_ICON, KeyEvent.VK_W, "Move the selected row(s) down");
    // Create a listener for the Move Down button
    btnMoveDown.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Move the selected row(s) down in the table
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fieldTable.moveRowDown();
        }
    });
    // Separator button
    btnSeparator = CcddButtonPanelHandler.createButton("Separator", SEPARATOR_ICON, KeyEvent.VK_S, "Insert a horizontal separator");
    // Create a listener for the Separator button
    btnSeparator.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Insert a line separator
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fieldTable.insertRow(true, TableInsertionPoint.SELECTION, new Object[] { InputDataType.SEPARATOR.getInputName(), "Line separator", 0, InputDataType.SEPARATOR.getInputName(), false, "", "" });
        }
    });
    // Break button
    btnBreak = CcddButtonPanelHandler.createButton("Break", BREAK_ICON, KeyEvent.VK_B, "Insert a line break");
    // Create a listener for the Move Down button
    btnBreak.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Insert a line break
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fieldTable.insertRow(true, TableInsertionPoint.SELECTION, new Object[] { InputDataType.BREAK.getInputName(), "Line break", 0, InputDataType.BREAK.getInputName(), false, "", "" });
        }
    });
    // Undo button
    btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit");
    // Create a listener for the Undo button
    btnUndo.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Undo the last cell edit
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fieldTable.getUndoManager().undo();
        }
    });
    // Redo button
    btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit");
    // Create a listener for the Redo button
    btnRedo.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Redo the last cell edit that was undone
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fieldTable.getUndoManager().redo();
        }
    });
    // Update the data fields button
    btnUpdate = CcddButtonPanelHandler.createButton("Update", STORE_ICON, KeyEvent.VK_U, "Update the table data field(s)");
    // Create a listener for the Update button
    btnUpdate.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Update the table data fields
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // valid (if a cell is being edited), and that there are changes to update
            if (!checkForMissingColumns() && fieldTable.isLastCellValid() && fieldTable.isTableChanged(currentData)) {
                // Rebuild the data field panel in the table editor using the current text
                // field contents
                recreateDataFieldPanel(minimumWidth);
            }
        }
    });
    // Close button
    btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the data field editor");
    // Create a listener for the Close button
    btnClose.addActionListener(new ValidateCellActionListener(fieldTable) {

        /**
         ************************************************************************************
         * Close the data field editor dialog
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            windowCloseButtonAction();
        }
    });
    // Add buttons in the order in which they'll appear (left to right, top to bottom)
    buttonPnl.add(btnInsertRow);
    buttonPnl.add(btnMoveUp);
    buttonPnl.add(btnSeparator);
    buttonPnl.add(btnUndo);
    buttonPnl.add(btnUpdate);
    buttonPnl.add(btnDeleteRow);
    buttonPnl.add(btnMoveDown);
    buttonPnl.add(btnBreak);
    buttonPnl.add(btnRedo);
    buttonPnl.add(btnClose);
    // Distribute the buttons across two rows
    setButtonRows(2);
    // Set the modal undo manager and table references in the keyboard handler while the data
    // field editor is active
    keyboardHandler.setModalDialogReference(fieldTable.getUndoManager(), fieldTable);
    // Display the table data field editor dialog
    showOptionsDialog(fieldPnlHndlr.getOwner(), outerPanel, buttonPnl, btnClose, DIALOG_TITLE + ": " + ownerName, true);
    // Clear the modal dialog references in the keyboard handler since the data field editor is
    // no longer active. The component that called this editor, if a modal dialog, must set
    // these parameters again once control is returned to it from this editor
    keyboardHandler.setModalDialogReference(null, null);
}
Also used : JScrollPane(javax.swing.JScrollPane) TableCellRenderer(javax.swing.table.TableCellRenderer) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) CCDDException(CCDD.CcddClassesDataTable.CCDDException) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) TableInsertionPoint(CCDD.CcddConstants.TableInsertionPoint) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 23 with CCDDException

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

the class CcddPatchHandler method updateAssociationsTable2.

/**
 ********************************************************************************************
 * Update the associations table to include a name column. Older versions of CCDD are not
 * compatible with the project database after applying this patch
 *
 * @throws CCDDException
 *             If the user elects to not install the patch or an error occurs while applying
 *             the patch
 ********************************************************************************************
 */
private void updateAssociationsTable2() throws CCDDException {
    CcddEventLogDialog eventLog = ccddMain.getSessionEventLog();
    CcddDbControlHandler dbControl = ccddMain.getDbControlHandler();
    try {
        CcddDbCommandHandler dbCommand = ccddMain.getDbCommandHandler();
        CcddDbTableCommandHandler dbTable = ccddMain.getDbTableCommandHandler();
        // Create lists to contain the old and new associations table items
        List<String[]> tableData = new ArrayList<String[]>();
        // Read the contents of the associations table
        ResultSet assnsData = dbCommand.executeDbQuery("SELECT * FROM " + InternalTable.ASSOCIATIONS.getTableName() + " ORDER BY OID;", ccddMain.getMainFrame());
        // Check if the patch hasn't already been applied
        if (assnsData.getMetaData().getColumnCount() == 3) {
            // Check if the user elects to not apply the patch
            if (new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>Apply patch to update the script " + "associations table?<br><br></b>" + "Incorporates a name column in the " + "script associations table.<br><b><i>Older " + "versions of CCDD will be incompatible " + "with this project database after " + "applying the patch", "Apply Patch #11132017", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) != OK_BUTTON) {
                assnsData.close();
                throw new CCDDException("user elected to not install patch (#1113017)");
            }
            // Step through each of the query results
            while (assnsData.next()) {
                // Create an array to contain the column values
                String[] columnValues = new String[4];
                // Step through each column in the row
                for (int column = 0; column < 3; column++) {
                    // Add the column value to the array. Note that the first column's index in
                    // the database is 1, not 0. Also, shift the old data over one column to
                    // make room for the name
                    columnValues[column + 1] = assnsData.getString(column + 1);
                    // Check if the value is null
                    if (columnValues[column] == null) {
                        // Replace the null with a blank
                        columnValues[column] = "";
                    }
                }
                // Add the row data to the list
                tableData.add(columnValues);
            }
            assnsData.close();
            // Check if there are any associations in the table
            if (tableData.size() != 0) {
                // Indicate in the log that the old data successfully loaded
                eventLog.logEvent(SUCCESS_MSG, InternalTable.ASSOCIATIONS.getTableName() + " retrieved");
            }
            // Back up the project database before applying the patch
            dbControl.backupDatabase(dbControl.getDatabaseName(), new FileEnvVar(ModifiablePathInfo.DATABASE_BACKUP_PATH.getPath() + File.separator + dbControl.getDatabaseName() + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()) + FileExtension.DBU.getExtension()));
            // Store the updated associations table
            dbTable.storeInformationTable(InternalTable.ASSOCIATIONS, tableData, null, ccddMain.getMainFrame());
            // Inform the user that updating the database associations table completed
            eventLog.logEvent(EventLogMessageType.SUCCESS_MSG, "Project '" + dbControl.getProjectName() + "' associations table conversion complete");
        }
    } catch (Exception e) {
        // Inform the user that converting the associations table failed
        eventLog.logFailEvent(ccddMain.getMainFrame(), "Cannot convert project '" + dbControl.getProjectName() + "' associations table to new format; cause '" + e.getMessage() + "'", "<html><b>Cannot convert project '" + dbControl.getProjectName() + "' associations table to new format " + "(project database will be closed)");
        throw new CCDDException();
    }
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) ArrayList(java.util.ArrayList) FileEnvVar(CCDD.CcddClassesComponent.FileEnvVar) CCDDException(CCDD.CcddClassesDataTable.CCDDException) ResultSet(java.sql.ResultSet) SimpleDateFormat(java.text.SimpleDateFormat)

Example 24 with CCDDException

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

the class CcddPatchHandler method updateDataBaseComment.

/**
 ********************************************************************************************
 * Update the project database comments to include the database name with capitalization and
 * special characters intact. The project database is first backed up to the file
 * <projectName>_<timeStamp>.dbu. The new format for the comment is <CCDD project identifier
 * string><lock status, 0 or 1>;<project name with capitalization intact>;<project
 * description>. Older versions of CCDD are compatible with the project database after applying
 * this patch
 *
 * @throws CCDDException
 *             If an error occurs while applying the patch
 ********************************************************************************************
 */
private void updateDataBaseComment() {
    CcddEventLogDialog eventLog = ccddMain.getSessionEventLog();
    CcddDbControlHandler dbControl = ccddMain.getDbControlHandler();
    try {
        CcddDbCommandHandler dbCommand = ccddMain.getDbCommandHandler();
        // Get the comment for the currently open database
        String comment = dbControl.getDatabaseComment(dbControl.getDatabaseName());
        // Divide the comment into the lock status, visible name, and description
        String[] nameAndDesc = comment.split(DATABASE_COMMENT_SEPARATOR, 3);
        // Check if the comment isn't in the new format
        if (nameAndDesc.length < 3 || !dbControl.getProjectName().equalsIgnoreCase(nameAndDesc[DatabaseComment.PROJECT_NAME.ordinal()])) {
            // Back up the project database before applying the patch
            dbControl.backupDatabase(dbControl.getDatabaseName(), new FileEnvVar(ModifiablePathInfo.DATABASE_BACKUP_PATH.getPath() + File.separator + dbControl.getDatabaseName() + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()) + FileExtension.DBU.getExtension()));
            // Update the project database comment to the new format
            dbCommand.executeDbCommand("COMMENT ON DATABASE " + dbControl.getDatabaseName() + " IS " + CcddDbTableCommandHandler.delimitText(CCDD_PROJECT_IDENTIFIER + comment.substring(0, 1) + DATABASE_COMMENT_SEPARATOR + dbControl.getProjectName() + DATABASE_COMMENT_SEPARATOR + nameAndDesc[0].substring(1)) + "; ", ccddMain.getMainFrame());
            // Inform the user that updating the database comment completed
            eventLog.logEvent(EventLogMessageType.SUCCESS_MSG, "Project '" + dbControl.getProjectName() + "' comment conversion complete");
        }
    } catch (Exception e) {
        // Inform the user that converting the database comments failed
        eventLog.logFailEvent(ccddMain.getMainFrame(), "Cannot convert project '" + dbControl.getProjectName() + "' comment to new format; cause '" + e.getMessage() + "'", "<html><b>Cannot convert project '" + dbControl.getProjectName() + "' comment to new format");
    }
}
Also used : FileEnvVar(CCDD.CcddClassesComponent.FileEnvVar) SimpleDateFormat(java.text.SimpleDateFormat) CCDDException(CCDD.CcddClassesDataTable.CCDDException)

Example 25 with CCDDException

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

the class CcddPatchHandler method updateTableTypesTable.

/**
 ********************************************************************************************
 * Update the internal table __types to the new name __table_types, delete the primitive_only
 * column, and add the structure allowed and pointer allowed columns. If successful, the
 * original table (__types) is renamed, preserving the original information and preventing
 * subsequent conversion attempts. The project database is first backed up to the file
 * <projectName>_<timeStamp>.dbu. Older versions of CCDD are not compatible with the project
 * database after applying this patch
 *
 * @throws CCDDException
 *             If the user elects to not install the patch or an error occurs while applying
 *             the patch
 ********************************************************************************************
 */
private void updateTableTypesTable() throws CCDDException {
    CcddDbTableCommandHandler dbTable = ccddMain.getDbTableCommandHandler();
    // Check if the old table exists
    if (dbTable.isTableExists("__types", ccddMain.getMainFrame())) {
        // Check if the user elects to not apply the patch
        if (new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>Apply patch to update the table types " + "table?<br><br></b>Creates the new " + "__table_types table from the old __types " + "table.<br><b><i>Older versions of CCDD " + "will be incompatible with this project " + "database after applying the patch", "Apply Patch #01262017", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) != OK_BUTTON) {
            throw new CCDDException("user elected to not install patch (#01262017)");
        }
        CcddDbControlHandler dbControl = ccddMain.getDbControlHandler();
        CcddDbCommandHandler dbCommand = ccddMain.getDbCommandHandler();
        CcddEventLogDialog eventLog = ccddMain.getSessionEventLog();
        CcddTableTypeHandler tableTypeHandler = ccddMain.getTableTypeHandler();
        try {
            // Back up the project database before applying the patch
            dbControl.backupDatabase(dbControl.getDatabaseName(), new FileEnvVar(ModifiablePathInfo.DATABASE_BACKUP_PATH.getPath() + File.separator + dbControl.getDatabaseName() + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()) + FileExtension.DBU.getExtension()));
            // Create lists to contain the old and new table types table items
            List<String[]> oldTableData = new ArrayList<String[]>();
            List<String[]> newTableData = new ArrayList<String[]>();
            // Read the contents of the old table types table
            ResultSet infoData = dbCommand.executeDbQuery("SELECT * FROM __types ORDER BY OID;", ccddMain.getMainFrame());
            // Step through each of the query results
            while (infoData.next()) {
                // Create an array to contain the column values
                String[] columnValues = new String[infoData.getMetaData().getColumnCount()];
                // Step through each column in the row
                for (int column = 0; column < infoData.getMetaData().getColumnCount(); column++) {
                    // Add the column value to the array. Note that the first column's index in
                    // the database is 1, not 0
                    columnValues[column] = infoData.getString(column + 1);
                    // Check if the value is null
                    if (columnValues[column] == null) {
                        // Replace the null with a blank
                        columnValues[column] = "";
                    }
                }
                // Add the row data to the list
                oldTableData.add(columnValues);
            }
            infoData.close();
            // Indicate in the log that the old data successfully loaded
            eventLog.logEvent(SUCCESS_MSG, "__types retrieved");
            // Step through the old table types column definitions
            for (String[] oldColumnDefn : oldTableData) {
                boolean isFound = false;
                // Create storage for the new column definition
                String[] newColumnDefn = new String[InternalTable.TABLE_TYPES.getNumColumns()];
                // Step through each of the old columns (the new table has one extra column)
                for (int index = 0; index < TableTypesColumn.values().length - 1; index++) {
                    // Copy the old columns definition to the new column definition
                    newColumnDefn[index] = oldColumnDefn[index];
                }
                // Get the default type definition for this table type name
                TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(oldColumnDefn[TableTypesColumn.TYPE_NAME.ordinal()]);
                // Check if the type exists in the default definitions
                if (typeDefn != null) {
                    // Get the index of the column
                    int column = typeDefn.getColumnIndexByDbName(oldColumnDefn[TableTypesColumn.COLUMN_NAME_DB.ordinal()]);
                    // Check if the column exists in the default type definition
                    if (column != -1) {
                        // Use the default definition to set the structure and pointer allowed
                        // flags
                        newColumnDefn[TableTypesColumn.STRUCTURE_ALLOWED.ordinal()] = typeDefn.isStructureAllowed()[column] ? "t" : "f";
                        newColumnDefn[TableTypesColumn.POINTER_ALLOWED.ordinal()] = typeDefn.isPointerAllowed()[column] ? "t" : "f";
                        isFound = true;
                    }
                }
                // Check if this column isn't in the default column definitions
                if (!isFound) {
                    // Assume that this column is valid for a structures and pointers
                    newColumnDefn[TableTypesColumn.STRUCTURE_ALLOWED.ordinal()] = "t";
                    newColumnDefn[TableTypesColumn.POINTER_ALLOWED.ordinal()] = "t";
                }
                // Add the column definition to the list
                newTableData.add(newColumnDefn);
            }
            // Delete the default column definitions
            tableTypeHandler.getTypeDefinitions().clear();
            // Step through the updated table types column definitions
            for (String[] newColumnDefn : newTableData) {
                // Get the type definition associated with this column
                TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(newColumnDefn[TableTypesColumn.TYPE_NAME.ordinal()]);
                // Check if the type is not defined
                if (typeDefn == null) {
                    // Create the type and add it to the list. THis creates the primary key and
                    // row index columns
                    typeDefn = tableTypeHandler.createTypeDefinition(newColumnDefn[TableTypesColumn.TYPE_NAME.ordinal()], new String[0][0], newColumnDefn[TableTypesColumn.COLUMN_DESCRIPTION.ordinal()]);
                }
                // these were created previously
                if (!newColumnDefn[TableTypesColumn.COLUMN_NAME_DB.ordinal()].equals(DefaultColumn.PRIMARY_KEY.getDbName()) && !newColumnDefn[TableTypesColumn.COLUMN_NAME_DB.ordinal()].equals(DefaultColumn.ROW_INDEX.getDbName())) {
                    // Add the column names, description, input type, and flags to the type
                    // definition
                    typeDefn.addColumn(Integer.parseInt(newColumnDefn[TableTypesColumn.INDEX.ordinal()].toString()), newColumnDefn[TableTypesColumn.COLUMN_NAME_DB.ordinal()].toString(), newColumnDefn[TableTypesColumn.COLUMN_NAME_VISIBLE.ordinal()].toString(), newColumnDefn[TableTypesColumn.COLUMN_DESCRIPTION.ordinal()].toString(), InputDataType.getInputTypeByName(newColumnDefn[TableTypesColumn.INPUT_TYPE.ordinal()].toString()), newColumnDefn[TableTypesColumn.ROW_VALUE_UNIQUE.ordinal()].equals("t") ? true : false, newColumnDefn[TableTypesColumn.COLUMN_REQUIRED.ordinal()].equals("t") ? true : false, newColumnDefn[TableTypesColumn.STRUCTURE_ALLOWED.ordinal()].equals("t") ? true : false, newColumnDefn[TableTypesColumn.POINTER_ALLOWED.ordinal()].equals("t") ? true : false);
                }
            }
            // Store the updated table type definitions in the project database and change the
            // old table types table name so that the conversion doesn't take place again
            dbCommand.executeDbCommand(dbTable.storeTableTypesInfoTableCommand() + "ALTER TABLE __types RENAME TO __types_backup;", ccddMain.getMainFrame());
            // Inform the user that converting the table types completed
            eventLog.logEvent(EventLogMessageType.SUCCESS_MSG, "Table types conversion complete");
            // Reopen the database
            dbControl.openDatabase(dbControl.getProjectName());
        } catch (Exception e) {
            // Inform the user that converting the table types table failed
            eventLog.logFailEvent(ccddMain.getMainFrame(), "Cannot convert table types table to new format; cause '" + e.getMessage() + "'", "<html><b>Cannot convert table types table to new " + "format (project database will be closed)");
            throw new CCDDException();
        }
    }
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) FileEnvVar(CCDD.CcddClassesComponent.FileEnvVar) ArrayList(java.util.ArrayList) CCDDException(CCDD.CcddClassesDataTable.CCDDException) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) ResultSet(java.sql.ResultSet) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

CCDDException (CCDD.CcddClassesDataTable.CCDDException)44 ArrayList (java.util.ArrayList)17 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)13 JSONObject (org.json.simple.JSONObject)12 FileEnvVar (CCDD.CcddClassesComponent.FileEnvVar)11 JSONArray (org.json.simple.JSONArray)11 JScrollPane (javax.swing.JScrollPane)10 JComponent (javax.swing.JComponent)9 Component (java.awt.Component)8 ParseException (org.json.simple.parser.ParseException)8 IOException (java.io.IOException)7 TableCellRenderer (javax.swing.table.TableCellRenderer)7 JSONParser (org.json.simple.parser.JSONParser)7 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)6 GridBagConstraints (java.awt.GridBagConstraints)6 GridBagLayout (java.awt.GridBagLayout)6 Insets (java.awt.Insets)6 JPanel (javax.swing.JPanel)6 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)5 TableInformation (CCDD.CcddClassesDataTable.TableInformation)5