use of CCDD.CcddConstants.FileExtension in project CCDD by nasa.
the class CcddTableManagerDialog method initialize.
/**
********************************************************************************************
* Create the table manager dialog. This is executed in a separate thread since it can take a
* noticeable amount time to complete, and by using a separate thread the GUI is allowed to
* continue to update. The GUI menu commands, however, are disabled until the telemetry
* scheduler initialization completes execution
********************************************************************************************
*/
private void initialize() {
// Build the table manager dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
boolean errorFlag = false;
JPanel dialogPnl;
FileExtension fileExtn;
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, 0, 0), 0, 0);
/**
************************************************************************************
* Build the table manager dialog
************************************************************************************
*/
@Override
protected void execute() {
isNodeSelectionChanging = false;
// Create an empty border
emptyBorder = BorderFactory.createEmptyBorder();
// Create a border for the input fields
border = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing()));
// Create dialog based on supplied dialog type
switch(dialogType) {
case NEW:
// Create a panel to contain the dialog components
dialogPnl = new JPanel(new GridBagLayout());
dialogPnl.setBorder(emptyBorder);
// types from which to choose
if (addRadioButtons(null, false, tableTypeHandler.getTypeInformation(), null, "Select table type", dialogPnl, gbc)) {
// Create the table creation dialog label and field, and add them to
// the dialog panel
addTableInputFields("Table name(s)", dialogPnl, true, gbc);
nameFld.setToolTipText(CcddUtilities.wrapText("Delimit multiple names using commas", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
} else // There are no table type available from which to choose
{
// Inform the user that no table type exists in the database
new CcddDialogHandler().showMessageDialog(caller, "<html><b>Project '" + dbControl.getDatabaseName() + "' has no table type defined", "New Table", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
errorFlag = true;
}
break;
case EDIT:
// Create a panel to contain the dialog components
dialogPnl = createSelectionPanel("Select table(s) to edit", gbc, TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, TableTreeType.TABLES);
// for editing
if (dialogPnl != null) {
// Add a listener to the table tree for mouse events
tableTree.addMouseListener(new MouseAdapter() {
/**
****************************************************************
* Handle mouse press events
****************************************************************
*/
@Override
public void mousePressed(MouseEvent me) {
// Check if the right mouse button is double clicked
if (me.getClickCount() == 2 && SwingUtilities.isRightMouseButton(me)) {
// Get the selected row in the tree
int rowIndex = tableTree.getClosestRowForLocation(me.getX(), me.getY());
// Check if a valid row was selected
if (rowIndex != -1) {
// Get the path for the selected row
TreePath path = tableTree.getPathForRow(rowIndex);
// Check if a table was selected
if (path.getPathCount() > tableTree.getHeaderNodeLevel()) {
// Load the selected table's data into a table
// editor and close this dialog
dbTable.loadTableDataInBackground(tableTree.getFullVariablePath(path.getPath()), callingEditorDialog);
closeDialog();
}
}
}
}
});
} else // There are no tables available for editing
{
errorFlag = true;
}
break;
case RENAME:
// Create a panel to contain the dialog components
dialogPnl = createSelectionPanel("Select a table to rename", gbc, TreeSelectionModel.SINGLE_TREE_SELECTION, TableTreeType.PROTOTYPE_TABLES);
// for renaming
if (dialogPnl != null) {
// Create the table renaming dialog label and field
addTableInputFields("New name", dialogPnl, false, gbc);
} else // There are no tables available for renaming
{
errorFlag = true;
}
break;
case COPY:
// Create a panel to contain the dialog components
dialogPnl = createSelectionPanel("Select a table to copy", gbc, TreeSelectionModel.SINGLE_TREE_SELECTION, TableTreeType.PROTOTYPE_TABLES);
// for copying
if (dialogPnl != null) {
// Create the table copying dialog label and field
addTableInputFields("Copy name", dialogPnl, false, gbc);
} else // There are no tables available for copying
{
errorFlag = true;
}
break;
case DELETE:
// Create a panel to contain the dialog components
dialogPnl = createSelectionPanel("Select table(s) to delete", gbc, TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, TableTreeType.PROTOTYPE_TABLES);
// available for deleting
if (dialogPnl == null) {
errorFlag = true;
}
break;
case IMPORT:
break;
case EXPORT_CSV:
case EXPORT_XTCE:
case EXPORT_EDS:
case EXPORT_JSON:
switch(dialogType) {
// Set the file extension based on the dialog type
case EXPORT_CSV:
fileExtn = FileExtension.CSV;
break;
case EXPORT_EDS:
fileExtn = FileExtension.EDS;
break;
case EXPORT_XTCE:
fileExtn = FileExtension.XTCE;
break;
case EXPORT_JSON:
fileExtn = FileExtension.JSON;
break;
default:
break;
}
// Create the export dialog
dialogPnl = createExportPanel(fileExtn, gbc);
// Check if the export panel doesn't exist
if (dialogPnl == null) {
errorFlag = true;
}
break;
}
}
/**
************************************************************************************
* Table manager dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Check that no error occurred creating the dialog
if (!errorFlag) {
// Display the dialog based on supplied dialog type
switch(dialogType) {
case NEW:
// Check if the Okay button was selected
if (showOptionsDialog(caller, dialogPnl, "New Table", DialogOption.CREATE_OPTION, true) == OK_BUTTON) {
// Create the table(s)
dbTable.createTableInBackground(tableNames, descriptionFld.getText(), getRadioButtonSelected(), CcddTableManagerDialog.this);
}
break;
case EDIT:
// Display the table selection dialog
if (showOptionsDialog(caller, dialogPnl, "Edit Table", DialogOption.OPEN_OPTION, true) == OK_BUTTON) {
// Get the list of selected tables, including children
List<String> tablePaths = tableTree.getSelectedTablesWithChildren();
// Load the selected table's data into a table editor
dbTable.loadTableDataInBackground(tablePaths.toArray(new String[0]), callingEditorDialog);
}
break;
case RENAME:
// Display the table renaming dialog
if (showOptionsDialog(caller, dialogPnl, "Rename Table", DialogOption.RENAME_OPTION, true) == OK_BUTTON) {
// Rename the table
dbTable.renameTable(tableTree.getSelectionPath().getLastPathComponent().toString(), nameFld.getText(), descriptionFld.getText(), CcddTableManagerDialog.this);
}
break;
case COPY:
// Display the table copying dialog
if (showOptionsDialog(caller, dialogPnl, "Copy Table", DialogOption.COPY_OPTION, true) == OK_BUTTON) {
// Copy the table
dbTable.copyTable(tableTree.getSelectionPath().getLastPathComponent().toString(), nameFld.getText(), descriptionFld.getText(), CcddTableManagerDialog.this);
}
break;
case DELETE:
// deletion dialog
if (showOptionsDialog(caller, dialogPnl, "Delete Table", DialogOption.DELETE_OPTION, true) == OK_BUTTON) {
// Create storage for the list of table names
List<String> tableNames = new ArrayList<String>();
invalidatedEditors = new ArrayList<String[]>();
// Step through each selected table in the tree
for (String path : tableTree.getSelectedTablesWithChildren()) {
// Add the table name to the list
tableNames.add(path);
// Add the pattern for the data type path of tables matching
// the deleted prototype table
invalidatedEditors.add(new String[] { path, null });
}
// Check if a table is selected
if (!tableNames.isEmpty()) {
// Delete the table(s)
dbTable.deleteTableInBackground(tableNames.toArray(new String[0]), CcddTableManagerDialog.this, caller);
}
}
break;
case IMPORT:
// Allow the user to select the data file path + name(s) from which to
// import, and the import options
FileEnvVar[] filePath = choosePathFile(ccddMain, caller, null, "export", new FileNameExtensionFilter[] { new FileNameExtensionFilter(FileExtension.CSV.getDescription(), FileExtension.CSV.getExtensionName()), new FileNameExtensionFilter(FileExtension.EDS.getDescription(), FileExtension.EDS.getExtensionName()), new FileNameExtensionFilter(FileExtension.JSON.getDescription(), FileExtension.JSON.getExtensionName()), new FileNameExtensionFilter(FileExtension.XTCE.getDescription(), FileExtension.XTCE.getExtensionName()) }, false, true, "Import Table(s)", ccddMain.getProgPrefs().get(ModifiablePathInfo.TABLE_EXPORT_PATH.getPreferenceKey(), null), DialogOption.IMPORT_OPTION, createImportPanel(gbc));
// Check if a file was chosen
if (filePath != null) {
// Export the contents of the selected table(s) in the specified
// format
fileIOHandler.importFile(filePath, backupFirstCb.isSelected(), replaceExistingTablesCb.isSelected(), appendExistingFieldsCb.isSelected(), useExistingFieldsCb.isSelected(), CcddTableManagerDialog.this);
}
break;
case EXPORT_CSV:
case EXPORT_XTCE:
case EXPORT_EDS:
case EXPORT_JSON:
// Check if the export panel exists; if so display the dialog
if (showOptionsDialog(caller, dialogPnl, "Export Table(s) in " + fileExtn.getExtensionName().toUpperCase() + " Format", DialogOption.EXPORT_OPTION, true) == OK_BUTTON) {
// Create storage for the list of table paths
List<String> tablePaths = new ArrayList<String>();
// Check if the export command originated from the main menu
if (callingEditorDialog == null) {
// Get the list of selected tables, including children
tablePaths = tableTree.getSelectedTablesWithChildren();
// Add the ancestors of the selected tables to the list
tableTree.addTableAncestors(tablePaths, false);
} else // The export command originated from a table editor dialog menu
{
// Add the table editor's table variable path to the list
tablePaths.add(callingEditorDialog.getTableEditor().getTableInformation().getTablePath());
}
// Export the contents of the selected table(s) in the specified
// format
fileIOHandler.exportSelectedTables(pathFld.getText(), tablePaths.toArray(new String[0]), overwriteFileCb.isSelected(), singleFileRBtn.isSelected(), (replaceMacrosCb != null ? replaceMacrosCb.isSelected() : true), (includeReservedMsgIDsCb != null ? includeReservedMsgIDsCb.isSelected() : false), (includeVariablePaths != null ? includeVariablePaths.isSelected() : false), (includeVariablePaths != null && includeVariablePaths.isSelected() ? ccddMain.getVariableHandler() : null), (varPathSepFld != null ? new String[] { varPathSepFld.getText(), Boolean.toString(hideDataTypeCb.isSelected()), typeNameSepFld.getText() } : null), fileExtn, (bigRBtn.isSelected() ? EndianType.BIG_ENDIAN : EndianType.LITTLE_ENDIAN), versionFld.getText(), validStatFld.getText(), class1Fld.getText(), class2Fld.getText(), class3Fld.getText(), CcddTableManagerDialog.this);
}
break;
}
}
}
});
}
Aggregations