use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.
the class CcddTableEditorHandler method validateMinMaxContent.
/**
********************************************************************************************
* Validate changes to the command argument minimum and maximum value columns
*
* @param tableData
* list containing the table data row arrays
*
* @param row
* table model row index
*
* @param column
* table model column index
*
* @param newValueS
* new cell contents
*
* @param dataTypeColumn
* index of the data type column that governs the minimum and maximum values, model
* coordinates
*
* @param minColumn
* index of the minimum value column, model coordinates
*
* @param maxColumn
* index of the maximum value column, model coordinates
*
* @throws CCDDException
* If a value doesn't match the expected input type, a value is outside the
* possible range of the data type, or the maximum value is less than the minimum
* value
********************************************************************************************
*/
private void validateMinMaxContent(List<Object[]> tableData, int row, int column, String newValueS, int dataTypeColumn, int minColumn, int maxColumn) throws CCDDException {
// Get the data type
String dataType = tableData.get(row)[dataTypeColumn].toString();
// Check that the data type exists
if (newDataTypeHandler.isPrimitive(dataType)) {
String minVal = "";
String maxVal = "";
// Check if the command argument has minimum and maximum values
if (minColumn != -1 && maxColumn != -1) {
// Store the minimum and maximum cell contents
minVal = getExpandedValueAt(tableData, row, minColumn);
maxVal = getExpandedValueAt(tableData, row, maxColumn);
}
// Check if the data type is an unsigned integer
if (newDataTypeHandler.isUnsignedInt(dataType)) {
// Check if the value doesn't match the expected input type
if (!newValueS.matches(InputDataType.INT_NON_NEGATIVE.getInputMatch())) {
throw new CCDDException("Invalid input type for column '" + typeDefn.getColumnNamesUser()[column] + "'; input type '" + InputDataType.INT_NON_NEGATIVE.getInputName().toLowerCase() + "' expected");
}
// Convert the cell value to an integer
int value = Integer.valueOf(newValueS);
// this data type's size
if (value < (int) newDataTypeHandler.getMinimum(dataType) || value > (int) newDataTypeHandler.getMaximum(dataType)) {
throw new CCDDException("Input value out of range for column '" + typeDefn.getColumnNamesUser()[column] + "'; must be greater than " + newDataTypeHandler.getMinimum(dataType) + " and less than " + newDataTypeHandler.getMaximum(dataType));
}
// the maximum
if (!minVal.isEmpty() && !maxVal.isEmpty() && Integer.valueOf(minVal) > Integer.valueOf(maxVal)) {
throw new CCDDException("Invalid input value for column '" + typeDefn.getColumnNamesUser()[column] + "'; the minimum must be less than or equal to the maximum");
}
} else // accounted for above)
if (newDataTypeHandler.isInteger(dataType)) {
// Check if the value doesn't match the expected input type
if (!newValueS.matches(InputDataType.INTEGER.getInputMatch())) {
throw new CCDDException("Invalid input type for column '" + typeDefn.getColumnNamesUser()[column] + "'; input type '" + InputDataType.INTEGER.getInputName().toLowerCase() + "' expected");
}
// Convert the cell value to an integer
int value = Integer.valueOf(newValueS);
// data type's size
if (value < (int) newDataTypeHandler.getMinimum(dataType) || value > (int) newDataTypeHandler.getMaximum(dataType)) {
throw new CCDDException("Input value out of range for column '" + typeDefn.getColumnNamesUser()[column] + "'; must be greater than " + newDataTypeHandler.getMinimum(dataType) + " and less than " + newDataTypeHandler.getMaximum(dataType));
}
// the maximum
if (!minVal.isEmpty() && !maxVal.isEmpty() && Integer.valueOf(minVal) > Integer.valueOf(maxVal)) {
throw new CCDDException("Invalid input value for column '" + typeDefn.getColumnNamesUser()[column] + "'; the minimum must be less than or equal to the maximum");
}
} else // Check if the data type is a floating point
if (newDataTypeHandler.isFloat(dataType)) {
// Check if the value doesn't match the expected input type
if (!newValueS.matches(InputDataType.FLOAT.getInputMatch())) {
throw new CCDDException("Invalid input type for column '" + typeDefn.getColumnNamesUser()[column] + "'; input type '" + InputDataType.FLOAT.getInputName().toLowerCase() + "' expected");
}
// Convert the cell value to a floating point
double value = Double.valueOf(newValueS);
// data type's size
if (value < (double) newDataTypeHandler.getMinimum(dataType) || value > (double) newDataTypeHandler.getMaximum(dataType)) {
throw new CCDDException("Input value out of range for column '" + typeDefn.getColumnNamesUser()[column] + "'; must be greater than " + newDataTypeHandler.getMinimum(dataType) + " and less than " + newDataTypeHandler.getMaximum(dataType));
}
// the maximum
if (!minVal.isEmpty() && !maxVal.isEmpty() && Double.valueOf(minVal) > Double.valueOf(maxVal)) {
throw new CCDDException("Invalid input value for column '" + typeDefn.getColumnNamesUser()[column] + "'; the minimum must be less than or equal to the maximum");
}
}
}
}
use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.
the class CcddTableTypeEditorHandler method initialize.
/**
********************************************************************************************
* Create the table type editor
********************************************************************************************
*/
private void initialize() {
// Define the table type editor JTable
table = new CcddJTableHandler() {
/**
************************************************************************************
* Return true if the type data, description, or data field changes
************************************************************************************
*/
@Override
protected boolean isTableChanged(Object[][] data) {
// Update the field information with the current text field values
updateCurrentFieldValues(fieldHandler.getFieldInformation());
// Set the flag if the number of fields, field attributes, or field contents have
// changed
boolean isFieldChanged = CcddFieldHandler.isFieldChanged(fieldHandler.getFieldInformation(), committedInfo.getFieldInformation(), true);
return isFieldChanged || !committedDescription.equals(getDescription()) || super.isTableChanged(data);
}
/**
************************************************************************************
* Allow resizing of the specified columns
************************************************************************************
*/
@Override
protected boolean isColumnResizable(int column) {
return column == TableTypeEditorColumnInfo.NAME.ordinal() || column == TableTypeEditorColumnInfo.DESCRIPTION.ordinal() || column == TableTypeEditorColumnInfo.INPUT_TYPE.ordinal();
}
/**
************************************************************************************
* Allow multiple line display in the specified columns
************************************************************************************
*/
@Override
protected boolean isColumnMultiLine(int column) {
return column == TableTypeEditorColumnInfo.NAME.ordinal() || column == TableTypeEditorColumnInfo.DESCRIPTION.ordinal() || column == TableTypeEditorColumnInfo.INPUT_TYPE.ordinal();
}
/**
************************************************************************************
* Hide the the specified columns
************************************************************************************
*/
@Override
protected boolean isColumnHidden(int column) {
return column == TableTypeEditorColumnInfo.INDEX.ordinal() || (typeOfTable != TableTypeIndicator.IS_STRUCTURE && (column == TableTypeEditorColumnInfo.STRUCTURE_ALLOWED.ordinal() || column == TableTypeEditorColumnInfo.POINTER_ALLOWED.ordinal()));
}
/**
************************************************************************************
* Display the specified column(s) as check boxes
************************************************************************************
*/
@Override
protected boolean isColumnBoolean(int column) {
return column == TableTypeEditorColumnInfo.UNIQUE.ordinal() || column == TableTypeEditorColumnInfo.REQUIRED.ordinal() || column == TableTypeEditorColumnInfo.STRUCTURE_ALLOWED.ordinal() || column == TableTypeEditorColumnInfo.POINTER_ALLOWED.ordinal();
}
/**
************************************************************************************
* Override isCellEditable so that all columns can be edited
************************************************************************************
*/
@Override
public boolean isCellEditable(int row, int column) {
boolean isEditable = true;
// the table model exists, and if the table has at least one row
if (isDisplayable() && getModel() != null && getModel().getRowCount() != 0) {
// Create storage for the row of table data
Object[] rowData = new Object[getModel().getColumnCount()];
// Convert the view row and column indices to model coordinates
int modelRow = convertRowIndexToModel(row);
int modelColumn = convertColumnIndexToModel(column);
// Step through each column in the row
for (int index = 0; index < rowData.length; index++) {
// Store the column value into the row data array
rowData[index] = getModel().getValueAt(modelRow, index);
}
// Check if the cell is editable
isEditable = isDataAlterable(rowData, modelRow, modelColumn);
}
return isEditable;
}
/**
************************************************************************************
* Override isDataAlterable to determine which table data values can be changed
*
* @param rowData
* array containing the table row data
*
* @param row
* table row index in model coordinates
*
* @param column
* table column index in model coordinates
*
* @return true if the data value can be changed
************************************************************************************
*/
@Override
protected boolean isDataAlterable(Object[] rowData, int row, int column) {
// Set the flag to false if the column is one that doesn't allow changing the
// structure or pointer allowed property
boolean isAllowed = !(rowData[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].equals(InputDataType.VARIABLE.getInputName()) || rowData[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].equals(InputDataType.PRIM_AND_STRUCT.getInputName()) || rowData[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].equals(InputDataType.ARRAY_INDEX.getInputName()) || rowData[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].equals(InputDataType.BIT_LENGTH.getInputName()) || rowData[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].equals(InputDataType.ENUMERATION.getInputName()) || rowData[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].equals(InputDataType.RATE.getInputName()) || rowData[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].equals(InputDataType.VARIABLE_PATH.getInputName()));
// Allow editing if:
return // This is the column name or description column
column == TableTypeEditorColumnInfo.NAME.ordinal() || column == TableTypeEditorColumnInfo.DESCRIPTION.ordinal() || typeDefinition == null || // allows the structure allowed property to be changed
((column != TableTypeEditorColumnInfo.STRUCTURE_ALLOWED.ordinal() || isAllowed) && // type is one that allows the pointer allowed property to be changed
(column != TableTypeEditorColumnInfo.POINTER_ALLOWED.ordinal() || isAllowed));
}
/**
************************************************************************************
* 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) {
return convertColumnIndexToModel(column) != TableTypeEditorColumnInfo.INPUT_TYPE.ordinal();
}
/**
************************************************************************************
* Validate changes to the editable cells
*
* @param tableData
* list containing the table data row arrays
*
* @param row
* table model row index
*
* @param column
* table model column index
*
* @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 column name has been changed and if the name isn't blank
if (column == TableTypeEditorColumnInfo.NAME.ordinal() && !newValueS.isEmpty()) {
// Check if the column name matches a default name (case insensitive)
if (newValueS.equalsIgnoreCase(DefaultColumn.PRIMARY_KEY.getDbName()) || newValueS.equalsIgnoreCase(DefaultColumn.ROW_INDEX.getDbName())) {
throw new CCDDException("Column name '" + newValueS + "' already in use (hidden)");
}
// Set the flag to true if the table type represents a structure
boolean isStructure = typeDefinition.isStructure();
// Get the database form of the column name
String dbName = DefaultColumn.convertVisibleToDatabase(newValueS, InputDataType.getInputTypeByName(tableData.get(row)[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].toString()), isStructure);
// creating a duplicate
for (int otherRow = 0; otherRow < getRowCount(); otherRow++) {
// Check if this row isn't the one being edited,
if (otherRow != row) {
// insensitive)
if (newValueS.equalsIgnoreCase(tableData.get(otherRow)[column].toString())) {
throw new CCDDException("Column name '" + newValueS + "' already in use");
}
// the database form of the one being added
if (dbName.equalsIgnoreCase(DefaultColumn.convertVisibleToDatabase(tableData.get(otherRow)[TableTypeEditorColumnInfo.NAME.ordinal()].toString(), InputDataType.getInputTypeByName(tableData.get(otherRow)[TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()].toString()), isStructure))) {
throw new CCDDException("Column name '" + newValueS + "' already in use (database)");
}
}
}
} else // value
if ((column == TableTypeEditorColumnInfo.UNIQUE.ordinal() || column == TableTypeEditorColumnInfo.REQUIRED.ordinal()) && !newValue.equals(true) && !newValue.equals(false)) {
throw new CCDDException("Column '" + TableTypeEditorColumnInfo.getColumnNames()[column] + "' expects a boolean value");
} else // Check if this is the input type column
if (column == TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()) {
// Check if the input type is disabled
if (newValueS.startsWith(DISABLED_TEXT_COLOR)) {
throw new CCDDException();
}
// Check if the input type is invalid
if (InputDataType.getInputTypeByName(newValueS) == null) {
throw new CCDDException("Unknown input type '" + newValueS + "'");
}
// Get the table type (structure, command, or other) based on the column
// definition input types
TableTypeIndicator typeOfTableNew = getTypeOfTable();
// structure or command
if (typeOfTableNew != typeOfTable && typeOfTableNew != TableTypeIndicator.IS_OTHER) {
// Get the invalid input types, if any
String msg = getInvalidInputTypes(typeOfTableNew);
// the table type definition
if (!msg.isEmpty()) {
throw new CCDDException(msg);
}
}
}
} 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 && !ce.getMessage().isEmpty()) {
// Inform the user that the input value is invalid
new CcddDialogHandler().showMessageDialog(editorDialog, "<html><b>" + ce.getMessage(), "Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
}
// Restore the cell contents to its original value
tableData.get(row)[column] = oldValue;
table.getUndoManager().undoRemoveEdit();
}
return showMessage;
}
/**
************************************************************************************
* Load the table type 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
int totalWidth = setUpdatableCharacteristics(committedData, TableTypeEditorColumnInfo.getColumnNames(), null, TableTypeEditorColumnInfo.getToolTips(), true, true, true);
// Get the minimum width needed to display all columns, but no wider than the
// display
int width = Math.min(totalWidth + LAF_SCROLL_BAR_WIDTH, GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth());
// Check if this is the widest editor table in this tabbed editor dialog
if (editorDialog.getTableWidth() < width) {
// Set the initial and preferred editor size
editorDialog.setTableWidth(width);
editorDialog.setPreferredSize(new Dimension(width, editorDialog.getPreferredSize().height));
}
}
/**
************************************************************************************
* 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);
// highlight colors override the invalid highlight color
if (comp.getBackground() != ModifiableColorInfo.FOCUS_BACK.getColor() && comp.getBackground() != ModifiableColorInfo.SELECTED_BACK.getColor()) {
boolean found = true;
String value = table.getValueAt(row, column).toString();
// Check if the cell is required and is empty
if (TableTypeEditorColumnInfo.values()[table.convertColumnIndexToModel(column)].isRequired() && value.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 && comboBox != null) {
found = false;
// Step through each combo box item
for (int index = 0; index < comboBox.getItemCount() && !found; index++) {
// in case this item is displayed as disabled
if (CcddUtilities.removeHTMLTags(comboBox.getItemAt(index)).equals(value)) {
// Set the flag indicating that the cell value is valid and stop
// searching
found = true;
break;
}
}
}
// Check if the cell value is invalid
if (!found) {
// Change the cell's background color
comp.setBackground(ModifiableColorInfo.REQUIRED_BACK.getColor());
} else // Check if this cell is protected from changes
if (!isCellEditable(row, column)) {
// Change the cell's text and background colors
comp.setForeground(ModifiableColorInfo.PROTECTED_TEXT.getColor());
comp.setBackground(ModifiableColorInfo.PROTECTED_BACK.getColor());
} else // table type as a structure or command table
if (DefaultColumn.isTypeRequiredColumn((typeOfTable == TableTypeIndicator.IS_STRUCTURE ? TYPE_STRUCTURE : (typeOfTable == TableTypeIndicator.IS_COMMAND ? TYPE_COMMAND : TYPE_OTHER)), InputDataType.getInputTypeByName(table.getValueAt(row, inputTypeIndex).toString()))) {
// Change the cell's background color
comp.setBackground(ModifiableColorInfo.TYPE_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 TableTypeEditorColumnInfo.getEmptyRow();
}
/**
************************************************************************************
* Handle a change to the table's content
************************************************************************************
*/
@Override
protected void processTableContentChange() {
// Check if there are no duplicated input types that are defined as unique
if (!isBadType) {
// Get the table type based on the column definition input types
TableTypeIndicator typeOfTableNew = getTypeOfTable();
// Check if the table type changed to/from representing a structure
if (typeOfTableNew != typeOfTable) {
// Store the new table type
typeOfTable = typeOfTableNew;
// Show/hide the structure table type specific editor columns
table.updateHiddenColumns();
// Update the input type combo box item list, enabling and/or disabling
// items based on those currently in use
comboBox.setModel(new DefaultComboBoxModel<String>(getInputTypeNames()));
}
// Check if the table type represents a structure
if (typeOfTableNew == TableTypeIndicator.IS_STRUCTURE) {
// Step through each row (column definition) in the table
for (int row = 0; row < table.getModel().getRowCount(); row++) {
// Get the reference to the table model to shorten subsequent calls
UndoableTableModel tableModel = (UndoableTableModel) table.getModel();
// Get the column definition's input type
String inputType = tableModel.getValueAt(row, TableTypeEditorColumnInfo.INPUT_TYPE.ordinal()).toString();
// size, bit length, enumeration, or variable path
if (inputType.equals(InputDataType.VARIABLE.getInputName()) || inputType.equals(InputDataType.PRIM_AND_STRUCT.getInputName()) || inputType.equals(InputDataType.ARRAY_INDEX.getInputName()) || inputType.equals(InputDataType.BIT_LENGTH.getInputName()) || inputType.equals(InputDataType.ENUMERATION.getInputName()) || inputType.equals(InputDataType.VARIABLE_PATH.getInputName())) {
// Select the structure and pointer allowed check boxes since these
// columns always are valid for structure and pointer data types
tableModel.setValueAt(true, row, TableTypeEditorColumnInfo.STRUCTURE_ALLOWED.ordinal(), false);
tableModel.setValueAt(true, row, TableTypeEditorColumnInfo.POINTER_ALLOWED.ordinal(), false);
} else // Check if this is the rate column
if (inputType.equals(InputDataType.RATE.getInputName())) {
// Deselect the structure allowed and set the pointer allowed check
// boxes since a
// rate column isn't valid for a structure data type but is valid
// for a pointer data type
tableModel.setValueAt(false, row, TableTypeEditorColumnInfo.STRUCTURE_ALLOWED.ordinal(), false);
tableModel.setValueAt(true, row, TableTypeEditorColumnInfo.POINTER_ALLOWED.ordinal(), false);
}
}
}
// Update the change indicator for the table
editorDialog.updateChangeIndicator(CcddTableTypeEditorHandler.this);
}
// Reset the bad input type flag so that subsequent table type changes are
// processed
isBadType = false;
}
};
// Place the table into a scroll pane
JScrollPane scrollPane = new JScrollPane(table);
// Disable storage of edit operations during table creation
table.getUndoHandler().setAllowUndo(false);
// Set common table parameters and characteristics
table.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
table.getUndoHandler().setAllowUndo(true);
// Create a drop-down combo box to display the available table type input data types
setUpInputTypeColumn();
// Set the reference to the editor's data field handler in the undo handler so that data
// field value changes can be undone/redone correctly
table.getUndoHandler().setFieldHandler(fieldHandler);
// Set the undo/redo manager and handler for the description and data field values
setEditPanelUndo(table.getUndoManager(), table.getUndoHandler());
// Create the input field panel to contain the type editor
createDescAndDataFieldPanel(editorDialog, scrollPane, tableTypeName, committedDescription, fieldHandler);
// Set the JTable name so that table change events can be identified with this table
setTableTypeName(tableTypeName);
}
use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.
the class CcddWebDataAccessHandler method getCommandInformation.
/**
********************************************************************************************
* Get the information for each command matching the specified filters
*
* @param groupFilter
* group (or application) name. A table must belong to the specified group in order
* for its telemetered variables to be returned; blank to get all telemetered
* variables (regardless of group)
*
* @return JSON encoded string containing information for each command matching the specified
* filters
*
* @throws CCDDException
* If the supplied group name is unrecognized
********************************************************************************************
*/
@SuppressWarnings("unchecked")
private String getCommandInformation(String groupFilter) throws CCDDException {
JSONArray commandsJA = new JSONArray();
TypeDefinition typeDefn = null;
int commandNameIndex = -1;
int commandCodeIndex = -1;
int commandDescriptionIndex = -1;
List<AssociatedColumns> commandArguments = null;
List<String> groupTables = null;
// Table type name for the previous table type loaded
String lastType = "";
// Check if a group name filter is specified
if (!groupFilter.isEmpty()) {
// Create a group handler and extract the table names belonging to the group
CcddGroupHandler groupHandler = new CcddGroupHandler(ccddMain, null, ccddMain.getMainFrame());
GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupFilter);
// Check if the group doesn't exist
if (groupInfo == null) {
throw new CCDDException("unrecognized group name");
}
// Get the tables associated with the group
groupTables = groupInfo.getTablesAndAncestors();
}
// Step through each command table
for (String commandTable : dbTable.getPrototypeTablesOfType(TYPE_COMMAND)) {
// requested that the table is a member of the group
if (groupFilter.isEmpty() || groupTables.contains(commandTable)) {
// Get the information from the database for the specified table
TableInformation tableInfo = dbTable.loadTableData(commandTable, false, false, false, ccddMain.getMainFrame());
// Check if the table loaded successfully
if (!tableInfo.isErrorFlag()) {
// every table
if (!tableInfo.getType().equals(lastType)) {
String descColName;
commandDescriptionIndex = -1;
// Store the table type name
lastType = tableInfo.getType();
// Get the table's type definition
typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
// Get the command name column
commandNameIndex = typeDefn.getColumnIndexByUserName(typeDefn.getColumnNameByInputType(InputDataType.COMMAND_NAME));
// Get the command name column
commandCodeIndex = typeDefn.getColumnIndexByUserName(typeDefn.getColumnNameByInputType(InputDataType.COMMAND_CODE));
// Check if a command description column exists
if ((descColName = typeDefn.getColumnNameByInputType(InputDataType.DESCRIPTION)) != null) {
// Get the command description column
commandDescriptionIndex = typeDefn.getColumnIndexByUserName(descColName);
}
// Get the list containing command argument column indices for each
// argument grouping
commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
}
// values
if (!isReplaceMacro) {
// Replace all macros in the table
tableInfo.setData(ccddMain.getMacroHandler().replaceAllMacros(tableInfo.getData()));
}
// Step through each command in the command table
for (int row = 0; row < tableInfo.getData().length; row++) {
JSONObject commandJO = new JSONObject();
String cellValue;
// on this row is skipped
if (!(cellValue = tableInfo.getData()[row][commandNameIndex]).isEmpty()) {
JSONArray commandArgumentsJA = new JSONArray();
// Store the name of the command table from which this command is taken
commandJO.put("Command Table Name", commandTable);
// Store the command name in the JSON output
commandJO.put(typeDefn.getColumnNamesUser()[commandNameIndex], cellValue);
// Check if the command code is present
if (!(cellValue = tableInfo.getData()[row][commandCodeIndex]).isEmpty()) {
// Store the command code in the JSON output
commandJO.put(typeDefn.getColumnNamesUser()[commandCodeIndex], cellValue);
}
// Check if the command description is present
if (commandDescriptionIndex != -1 && !(cellValue = tableInfo.getData()[row][commandDescriptionIndex]).isEmpty()) {
// Store the command description in the JSON output
commandJO.put(typeDefn.getColumnNamesUser()[commandDescriptionIndex], cellValue);
}
// command row
for (AssociatedColumns cmdArgument : commandArguments) {
JSONObject commandArgumentJO = new JSONObject();
// all associated argument values are skipped
if (!(cellValue = tableInfo.getData()[row][cmdArgument.getName()]).isEmpty()) {
// Store the command argument name in the JSON output
commandArgumentJO.put(typeDefn.getColumnNamesUser()[cmdArgument.getName()], cellValue);
// Check if the command argument data type column has a value
if (!(cellValue = tableInfo.getData()[row][cmdArgument.getDataType()]).isEmpty()) {
// Store the data type in the JSON output
commandArgumentJO.put(typeDefn.getColumnNamesUser()[cmdArgument.getDataType()], cellValue);
}
// Check if the command argument array size column has a value
if (!(cellValue = tableInfo.getData()[row][cmdArgument.getArraySize()]).isEmpty()) {
// Store the array size in the JSON output
commandArgumentJO.put(typeDefn.getColumnNamesUser()[cmdArgument.getArraySize()], cellValue);
}
// Check if the command argument bit length column has a value
if (!(cellValue = tableInfo.getData()[row][cmdArgument.getBitLength()]).isEmpty()) {
// Store the bit length in the JSON output
commandArgumentJO.put(typeDefn.getColumnNamesUser()[cmdArgument.getBitLength()], cellValue);
}
// Check if the command argument enumeration column has a value
if (!(cellValue = tableInfo.getData()[row][cmdArgument.getEnumeration()]).isEmpty()) {
// Store the enumeration in the JSON output
commandArgumentJO.put(typeDefn.getColumnNamesUser()[cmdArgument.getEnumeration()], cellValue);
}
// Check if the command argument minimum column has a value
if (!(cellValue = tableInfo.getData()[row][cmdArgument.getMinimum()]).isEmpty()) {
// Store the minimum value in the JSON output
commandArgumentJO.put(typeDefn.getColumnNamesUser()[cmdArgument.getMinimum()], cellValue);
}
// Check if the command argument maximum column has a value
if (!(cellValue = tableInfo.getData()[row][cmdArgument.getMaximum()]).isEmpty()) {
// Store the maximum value in the JSON output
commandArgumentJO.put(typeDefn.getColumnNamesUser()[cmdArgument.getMaximum()], cellValue);
}
// argument
for (int otherArg : cmdArgument.getOther()) {
// Check if the other argument column has a value
if (!(cellValue = tableInfo.getData()[row][otherArg]).isEmpty()) {
// Store the value in the JSON output
commandArgumentJO.put(typeDefn.getColumnNamesUser()[otherArg], cellValue);
}
}
}
// Store the command arguments in the JSON array
commandArgumentsJA.add(commandArgumentJO);
}
// Check if the command has an argument
if (!commandArgumentsJA.isEmpty()) {
// Store the command arguments in the JSON output
commandJO.put("Arguments", commandArgumentsJA);
}
}
// Add the command to the JSON array
commandsJA.add(commandJO);
}
}
}
}
return commandsJA.toString();
}
use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.
the class CcddXTCEHandler method createEnumerationList.
/**
********************************************************************************************
* Build an enumeration list from the supplied enumeration string
*
* @param spaceSystem
* space system
*
* @param enumeration
* enumeration in the format <enum value><enum value separator><enum label>[<enum
* value separator>...][<enum pair separator>...]
*
* @return Enumeration list for the supplied enumeration string
********************************************************************************************
*/
private EnumerationList createEnumerationList(SpaceSystemType spaceSystem, String enumeration) {
EnumerationList enumList = factory.createEnumeratedDataTypeEnumerationList();
try {
// Get the character that separates the enumeration value from the associated label
String enumValSep = CcddUtilities.getEnumeratedValueSeparator(enumeration);
// Check if the value separator couldn't be located
if (enumValSep == null) {
throw new CCDDException("initial non-negative integer or " + "separator character between " + "enumeration value and text missing");
}
// Get the character that separates the enumerated pairs
String enumPairSep = CcddUtilities.getEnumerationPairSeparator(enumeration, enumValSep);
// Check if the enumerated pair separator couldn't be located
if (enumPairSep == null) {
throw new CCDDException("separator character between enumerated pairs missing");
}
// Divide the enumeration string into the separate enumeration definitions
String[] enumDefn = enumeration.split(Pattern.quote(enumPairSep));
// Step through each enumeration definition
for (int index = 0; index < enumDefn.length; index++) {
// Split the enumeration definition into the name and label components
String[] enumParts = enumDefn[index].split(Pattern.quote(enumValSep), 2);
// Create a new enumeration value type and add the enumerated name and value to the
// enumeration list
ValueEnumerationType valueEnum = factory.createValueEnumerationType();
valueEnum.setLabel(enumParts[1].trim());
valueEnum.setValue(BigInteger.valueOf(Integer.valueOf(enumParts[0].trim())));
enumList.getEnumeration().add(valueEnum);
}
} catch (CCDDException ce) {
// Inform the user that the enumeration format is invalid
new CcddDialogHandler().showMessageDialog(parent, "<html><b>Enumeration '" + enumeration + "' format invalid in table '" + spaceSystem.getName() + "'; " + ce.getMessage(), "Enumeration Error", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
}
return enumList;
}
use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.
the class CcddDbTableCommandHandler method loadTableData.
/**
********************************************************************************************
* Perform the database query to load the contents of a database table. The data is sorted in
* ascending numerical order based on the index (primary key) column
*
* @param tablePath
* table path in the format rootTable[,dataType1.variable1[,dataType2
* .variable2[,...]]]. The table path for a non-structure table is simply the root
* table name. For a structure table the root table is the top level structure table
* from which this table descends. The first data type/variable name pair is from
* the root table, with each succeeding pair coming from the next level down in the
* structure's hierarchy
*
* @param loadDescription
* true to load the table's description
*
* @param loadColumnOrder
* true to load the table's column order
*
* @param loadFieldInfo
* true to retrieve the data field information to include with the table
* information; false to not load the field information
*
* @param parent
* GUI component calling this method
*
* @return TableInformation class containing the table data from the database. If the error
* flag is set the an error occurred and the data is invalid
********************************************************************************************
*/
protected TableInformation loadTableData(String tablePath, boolean loadDescription, boolean loadColumnOrder, boolean loadFieldInfo, Component parent) {
// Create an empty table information class
TableInformation tableInfo = new TableInformation(tablePath);
// Strip the variable name, if present, from the table name
String tableName = tableInfo.getPrototypeName();
// Convert the table name to lower case. PostgreSQL ignores case; it's done here just to
// differentiate the table name from the database commands in the event log
String dbTableName = tableName.toLowerCase();
try {
// Check if the table doesn't exist in the database
if (!isTableExists(dbTableName, parent)) {
throw new CCDDException("table doesn't exist");
}
// Get the table comment
String[] comment = queryDataTableComment(tableName, parent);
// Get the table type definition for this table
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(comment[TableCommentIndex.TYPE.ordinal()]);
// Get a comma-separated list of the columns for this table's type
String columnNames = CcddUtilities.convertArrayToString(typeDefn.getColumnNamesDatabase());
// Get the table's row information for the specified columns. The table must have all
// of its table type's columns or else it fails to load
ResultSet rowData = dbCommand.executeDbQuery("SELECT " + columnNames + " FROM " + dbTableName + " ORDER BY " + DefaultColumn.ROW_INDEX.getDbName() + ";", parent);
// Create a list to contain the database table rows
List<String[]> dbRows = new ArrayList<String[]>();
// Step through each of the query results
while (rowData.next()) {
// Create an array to contain the column values
String[] columnValues = new String[typeDefn.getColumnCountDatabase()];
// Step through each column in the row
for (int column = 0; column < typeDefn.getColumnCountDatabase(); column++) {
// Add the column value to the array. Note that the first column's index in
// the database is 1, not 0
columnValues[column] = rowData.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
dbRows.add(columnValues);
}
rowData.close();
// Create the table information handler for this table
tableInfo = new TableInformation(comment[TableCommentIndex.TYPE.ordinal()], tablePath, dbRows.toArray(new String[0][0]), (loadColumnOrder ? queryColumnOrder(tablePath, comment[TableCommentIndex.TYPE.ordinal()], parent) : ""), (loadDescription ? queryTableDescription(tablePath, parent) : ""), rootStructures.contains(tablePath), (loadFieldInfo ? retrieveInformationTable(InternalTable.FIELDS, parent).toArray(new String[0][0]) : null));
// Get the index of the variable name and data type columns
int varNameIndex = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
int dataTypeIndex = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
// must be loaded
if (varNameIndex != -1 && dataTypeIndex != -1 && tablePath.contains(",")) {
// Get the column index for the variable path
int varPathIndex = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE_PATH);
// Check if the variable path column is present
if (varPathIndex != -1) {
// Step through each row in the table
for (int row = 0; row < tableInfo.getData().length; row++) {
// Blank the variable path. This prevents the child table from inheriting a
// user-defined variable path from the prototype
tableInfo.getData()[row][varPathIndex] = "";
}
}
// Place double back slashes before each square brace character in an array index
// so that the brackets are interpreted correctly in the query's regular expression
// comparisons
tablePath = tablePath.replaceAll("\\[(\\d+)\\]", "\\\\\\\\[$1\\\\\\\\]");
// Get the rows from the custom values table that match the specified parent table
// and variable path. These values replace those loaded for the prototype of this
// table
rowData = dbCommand.executeDbQuery("SELECT * FROM " + InternalTable.VALUES.getTableName() + " WHERE " + ValuesColumn.TABLE_PATH.getColumnName() + " ~ E'^" + tablePath + ",[^,]+$' AND " + ValuesColumn.COLUMN_NAME.getColumnName() + " != '';", parent);
// Step through each of the query results
while (rowData.next()) {
// Get the variable name that will have its value replaced
String variableName = rowData.getString(ValuesColumn.TABLE_PATH.getColumnName());
// Get the index of the last data type/variable name separator character (if
// present)
int varIndex = variableName.lastIndexOf(".");
// Check if a variable name exists
if (varIndex != -1) {
// Get the row index for the referenced variable
int row = typeDefn.getRowIndexByColumnValue(tableInfo.getData(), variableName.substring(varIndex + 1), varNameIndex);
// values table
if (row != -1 && tableInfo.getData()[row][dataTypeIndex].equals(variableName.subSequence(variableName.lastIndexOf(",") + 1, varIndex))) {
// Get the index of the column that will have its data replaced
int column = typeDefn.getColumnIndexByUserName(rowData.getString(ValuesColumn.COLUMN_NAME.getColumnName()));
// Check if the table contains the column
if (column != -1) {
// Replace the value in the table with the one from the custom
// values table
tableInfo.getData()[row][column] = rowData.getString(ValuesColumn.VALUE.getColumnName());
}
}
}
}
rowData.close();
}
} catch (SQLException | CCDDException se) {
// Inform the user that loading the table failed
eventLog.logFailEvent(parent, "Cannot load table '" + tableInfo.getProtoVariableName() + "'; cause '" + se.getMessage() + "'", "<html><b>Cannot load table '</b>" + tableInfo.getProtoVariableName() + "<b>'");
} catch (Exception e) {
// Display a dialog providing details on the unanticipated error
CcddUtilities.displayException(e, parent);
}
return tableInfo;
}
Aggregations