use of CCDD.CcddConstants.TableInsertionPoint in project CCDD by nasa.
the class CcddScriptManagerDialog method addAssociation.
/**
********************************************************************************************
* Add an association to the script associations list based on the script and table selections
*
* @param insertPoint
* insertion point for the added row into the associations table:
* TableInsertionPoint.START to insert as the first row in the table,
* TableInsertionPoint.SELECTION to insert below the currently selected row, or
* TableInsertionPoint.END to insert as the last row in the table
*
* @return true if the association inputs are valid and the association is successfully added
********************************************************************************************
*/
private boolean addAssociation(TableInsertionPoint insertPoint) {
boolean isAdded = false;
try {
List<String> members = new ArrayList<>();
// Check if the tree is filtered by group
if (tableTree.isFilteredByGroup()) {
// Step through each selected group
for (String group : tableTree.getSelectedGroups()) {
// Add the group to the list. Any table belonging to the group is deselected
members.add(GROUP_DATA_FIELD_IDENT + group);
}
}
// Remove any excess white space
nameFld.setText(nameFld.getText().trim());
descriptionFld.setText(descriptionFld.getText().trim());
// Check if the name field isn't blank
if (!nameFld.getText().isEmpty()) {
// Check if the association name does not match the alphanumeric input type
if (!nameFld.getText().matches(InputDataType.ALPHANUMERIC.getInputMatch())) {
throw new CCDDException("Illegal character(s) in association name");
}
// creating a duplicate
for (int row = 0; row < assnsTable.getRowCount(); row++) {
// matches the one being added (case insensitive)
if (nameFld.getText().equalsIgnoreCase(assnsTable.getValueAt(row, AssociationsTableColumnInfo.NAME.ordinal()).toString())) {
throw new CCDDException("Association name already in use");
}
}
}
// Add the selected table names, skipping child tables if an ancestor of the table is
// selected
members.addAll(tableTree.getSelectedTablesWithoutChildren());
// Get a file descriptor for the script file name
FileEnvVar scriptFile = new FileEnvVar(scriptFld.getText());
// Check that the script association already exists in the list
if (isAssociationExists(scriptFile.getAbsolutePathWithEnvVars(), members.toArray(new String[0]))) {
throw new CCDDException("An association with this script and table(s) " + "already exists in the script associations table");
}
// Create the script association strings
String assn = "";
// Step through each selected table/group in the tree
for (String member : members) {
// Add the table/group name to the script association
assn += member + ASSN_TABLE_SEPARATOR;
}
// Remove the trailing table separator
assn = CcddUtilities.removeTrailer(assn, ASSN_TABLE_SEPARATOR);
// Insert the new script association at the end of the associations table, then select
// it and scroll to it
assnsTable.insertRow(true, insertPoint, new Object[] { nameFld.getText(), descriptionFld.getText(), scriptFile.getAbsolutePathWithEnvVars(), CcddUtilities.highlightDataType(assn), (scriptFile.exists() ? AvailabilityType.AVAILABLE : AvailabilityType.SCRIPT_MISSING) });
isAdded = true;
} catch (CCDDException ce) {
// Inform the user that an input value is invalid
new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>" + ce.getMessage(), "Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
}
return isAdded;
}
use of CCDD.CcddConstants.TableInsertionPoint in project CCDD by nasa.
the class CcddJTableHandler method insertRow.
/**
********************************************************************************************
* Insert a row of data into the table at the selection point
*
* @param endEdit
* true to end the editing sequence at the end of the insert for undo/redo purposes
*
* @param insertionPoint
* START to insert the data as the new first row in the table; END to force
* insertion of the new data at the end of the table; SELECTION to insert the data
* below the currently selected row(s)
*
* @param data
* data with which to populate the inserted row; null to insert an empty row
********************************************************************************************
*/
protected void insertRow(boolean endEdit, TableInsertionPoint insertionPoint, Object[] data) {
int modelRow;
// Check if the end of the edit sequence should be flagged
if (endEdit) {
// Flag the end of the editing sequence for undo/redo purposes
undoManager.endEditSequence();
}
// Set the row index to the last row selected by the user (if any)
int viewRow = getSelectedRow() + getSelectedRowCount() - 1;
// Check if the new row is to be inserted at the start of the table
if (insertionPoint == TableInsertionPoint.START) {
// Insert the new row at the start of the table
modelRow = -1;
} else // Check if no row is selected or if the flag is set to add the row at the end of the table
if (viewRow < 0 || insertionPoint == TableInsertionPoint.END) {
// Insert the new row at the end of the table
modelRow = tableModel.getRowCount() - 1;
} else // One or more rows is selected
{
// Convert the row index to model coordinates
modelRow = convertRowIndexToModel(viewRow);
// Deselect the originally selected row(s)
removeRowSelectionInterval(getSelectedRow(), viewRow);
}
// Insert the data into a new row below the selected row, and select and scroll to the
// inserted row
setSelectedRow(insertRowData(modelRow, data));
// Check if the end of the edit sequence should be flagged
if (endEdit) {
// Flag the end of the editing sequence for undo/redo purposes
undoManager.endEditSequence();
}
}
Aggregations