use of CCDD.CcddBackgroundCommand.BackgroundCommand in project CCDD by nasa.
the class CcddFieldTableEditorDialog method displayDataFieldTableEditor.
/**
********************************************************************************************
* Create the data field table editor 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 displayDataFieldTableEditor() {
// Build the data field editor table dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panels to hold the components of the dialog
JPanel dialogPnl = new JPanel(new GridBagLayout());
JPanel buttonPnl = new JPanel();
JButton btnClose;
/**
************************************************************************************
* Build the data field table editor dialog
************************************************************************************
*/
@Override
protected void execute() {
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), 0, 0, 0), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0);
// Define the panel to contain the table
JPanel tablePnl = new JPanel();
tablePnl.setLayout(new BoxLayout(tablePnl, BoxLayout.X_AXIS));
tablePnl.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
tablePnl.add(createDataFieldTableEditorTable());
// Add the table to the dialog
gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 1.0;
dialogPnl.add(tablePnl, gbc);
// Add the field display filter label and a filter check box for each field owner
// type
JLabel fieldFilterLbl = new JLabel("Show fields belonging to:");
fieldFilterLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
fieldFilterLbl.setBorder(emptyBorder);
gbc.gridwidth = 1;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.gridy++;
dialogPnl.add(fieldFilterLbl, gbc);
final JCheckBox projectFilterCbx = new JCheckBox("Project", isProjectFilter);
projectFilterCbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
projectFilterCbx.setBorder(emptyBorder);
gbc.gridx++;
dialogPnl.add(projectFilterCbx, gbc);
final JCheckBox tableFilterCbx = new JCheckBox("Tables", isTableFilter);
tableFilterCbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
tableFilterCbx.setBorder(emptyBorder);
gbc.gridx++;
dialogPnl.add(tableFilterCbx, gbc);
final JCheckBox groupFilterCbx = new JCheckBox("Groups", isGroupFilter);
groupFilterCbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
groupFilterCbx.setBorder(emptyBorder);
gbc.gridx++;
dialogPnl.add(groupFilterCbx, gbc);
final JCheckBox typeFilterCbx = new JCheckBox("Table types", isTypeFilter);
typeFilterCbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
typeFilterCbx.setBorder(emptyBorder);
gbc.gridx++;
dialogPnl.add(typeFilterCbx, gbc);
// Create a row filter for displaying the fields based on selected filter
rowFilter = new RowFilter<TableModel, Object>() {
/**
****************************************************************************
* Override method that determines if a row should be displayed
****************************************************************************
*/
@Override
public boolean include(Entry<? extends TableModel, ? extends Object> owner) {
boolean isFilter = true;
// Get the data field owner's name
String ownerName = highlightFieldOwner(owner.getValue(FieldTableEditorColumnInfo.OWNER.ordinal()).toString(), false);
// Check if this field belongs to the project
if (ownerName.startsWith(CcddFieldHandler.getFieldProjectName())) {
// Show this row if the project filter check box is selected
isFilter = projectFilterCbx.isSelected();
} else // Check if this field belongs to a group
if (ownerName.startsWith(CcddFieldHandler.getFieldGroupName(""))) {
// Show this row if the group filter check box is selected
isFilter = groupFilterCbx.isSelected();
} else // Check if this field belongs to a table type
if (ownerName.startsWith(CcddFieldHandler.getFieldTypeName(""))) {
// Show this row if the table type filter check box is selected
isFilter = typeFilterCbx.isSelected();
} else // The field belongs to a table
{
// Show this row if the table filter check box is selected
isFilter = tableFilterCbx.isSelected();
}
return isFilter;
}
};
// Create a listener for check box selection changes
ActionListener filterListener = new ActionListener() {
/**
****************************************************************************
* Handle check box selection changes
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the table's row sorter based on whether or not any rows are visible
dataFieldTable.setRowSorter(null);
dataFieldTable.setTableSortable();
// Issue a table change event so the rows are filtered
((DefaultTableModel) dataFieldTable.getModel()).fireTableDataChanged();
((DefaultTableModel) dataFieldTable.getModel()).fireTableStructureChanged();
}
};
// Add the listener to the filter check boxes
projectFilterCbx.addActionListener(filterListener);
tableFilterCbx.addActionListener(filterListener);
groupFilterCbx.addActionListener(filterListener);
typeFilterCbx.addActionListener(filterListener);
// Define the buttons for the lower panel: Select data fields button
JButton btnSelect = CcddButtonPanelHandler.createButton("Select", OK_ICON, KeyEvent.VK_L, "Select new data fields");
// Add a listener for the Select button
btnSelect.addActionListener(new ValidateCellActionListener(dataFieldTable) {
/**
****************************************************************************
* Select the data fields and update the data field editor table
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// Confirm discarding pending changes if any exist
if ((!isFieldTableChanged() || new CcddDialogHandler().showMessageDialog(CcddFieldTableEditorDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON)) {
// Store the current filter selections
isProjectFilter = projectFilterCbx.isSelected();
isTableFilter = tableFilterCbx.isSelected();
isGroupFilter = groupFilterCbx.isSelected();
isTypeFilter = typeFilterCbx.isSelected();
// Allow the user to select the data fields to display
selectDataFields();
}
}
});
// Delete data fields button
JButton btnRemove = CcddButtonPanelHandler.createButton("Remove", DELETE_ICON, KeyEvent.VK_R, "Remove the selected data field(s) from their table(s)");
// Add a listener for the Remove button
btnRemove.addActionListener(new ValidateCellActionListener(dataFieldTable) {
/**
****************************************************************************
* Toggle the removal state of the selected data field(s)
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
toggleRemoveFields();
}
});
// Open tables button
JButton btnOpen = CcddButtonPanelHandler.createButton("Open", TABLE_ICON, KeyEvent.VK_O, "Open the table(s) associated with the selected data field(s)");
// Add a listener for the Open button
btnOpen.addActionListener(new ValidateCellActionListener(dataFieldTable) {
/**
****************************************************************************
* Open the table(s) associated with the selected data field(s)
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
openTables();
}
});
// Print data field editor table button
JButton btnPrint = CcddButtonPanelHandler.createButton("Print", PRINT_ICON, KeyEvent.VK_P, "Print the data field editor table");
// Add a listener for the Print button
btnPrint.addActionListener(new ValidateCellActionListener(dataFieldTable) {
/**
****************************************************************************
* Print the data field editor table
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
dataFieldTable.printTable("Data Field Contents", null, CcddFieldTableEditorDialog.this, PageFormat.LANDSCAPE);
}
});
// Undo button
JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
// Create a listener for the Undo command
btnUndo.addActionListener(new ValidateCellActionListener(dataFieldTable) {
/**
****************************************************************************
* Undo the last cell edit
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
dataFieldTable.getUndoManager().undo();
}
});
// Redo button
JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
// Create a listener for the Redo command
btnRedo.addActionListener(new ValidateCellActionListener(dataFieldTable) {
/**
****************************************************************************
* Redo the last cell edit that was undone
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
dataFieldTable.getUndoManager().redo();
}
});
// Store data field values button
JButton btnStore = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store data field changes");
// Add a listener for the Store button
btnStore.addActionListener(new ValidateCellActionListener(dataFieldTable) {
/**
****************************************************************************
* Store changes to the data field values
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// and the user confirms the action
if (isFieldTableChanged() && new CcddDialogHandler().showMessageDialog(CcddFieldTableEditorDialog.this, "<html><b>Store changes in project database?", "Store Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Build the update lists
buildUpdates();
// Store the changes to the data fields in the database
dbTable.modifyDataFields(fieldModifications, fieldDeletions, CcddFieldTableEditorDialog.this);
}
}
});
// Close button
btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the data field editor dialog");
// Add a listener for the Close button
btnClose.addActionListener(new ValidateCellActionListener(dataFieldTable) {
/**
****************************************************************************
* Close the data field editor dialog
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
windowCloseButtonAction();
}
});
// Add the buttons to the panel
buttonPnl.add(btnSelect);
buttonPnl.add(btnOpen);
buttonPnl.add(btnUndo);
buttonPnl.add(btnStore);
buttonPnl.add(btnRemove);
buttonPnl.add(btnPrint);
buttonPnl.add(btnRedo);
buttonPnl.add(btnClose);
// Distribute the buttons across two rows
setButtonRows(2);
}
/**
************************************************************************************
* Data field table editor dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Display the data field table editor dialog
createFrame(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnClose, DIALOG_TITLE, null);
// Reposition the field table editor dialog
positionFieldEditorDialog();
}
});
}
use of CCDD.CcddBackgroundCommand.BackgroundCommand in project CCDD by nasa.
the class CcddTableTypeEditorDialog method initialize.
/**
********************************************************************************************
* Create the table type editor 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
*
* @param typeNames
* array containing the table type names
********************************************************************************************
*/
private void initialize(final String[] typeNames) {
// Build the table type editor dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panel to hold the dialog buttons
JPanel buttonPnl = new JPanel();
/**
************************************************************************************
* Build the table type editor dialog
************************************************************************************
*/
@Override
protected void execute() {
// Menu ///////////////////////////////////////////////////////////////////////////
// Create the table menu bar
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
// Create the File menu and menu items
mnFile = ccddMain.createMenu(menuBar, "File", KeyEvent.VK_F, 1, null);
mntmNewType = ccddMain.createMenuItem(mnFile, "New type", KeyEvent.VK_N, 1, "Create a new table type");
mntmCopyType = ccddMain.createMenuItem(mnFile, "Copy type", KeyEvent.VK_O, 1, "Copy the current table type");
mntmRenameType = ccddMain.createMenuItem(mnFile, "Rename type", KeyEvent.VK_R, 1, "Rename the current table type");
mntmDeleteType = ccddMain.createMenuItem(mnFile, "Delete type", KeyEvent.VK_D, 1, "Delete the current table type");
mnFile.addSeparator();
mntmStore = ccddMain.createMenuItem(mnFile, "Store current", KeyEvent.VK_U, 1, "Store changes to the curent table type in the database");
mntmStoreAll = ccddMain.createMenuItem(mnFile, "Store all", KeyEvent.VK_L, 1, "Store changes to all table types in the database");
mnFile.addSeparator();
mntmPrint = ccddMain.createMenuItem(mnFile, "Print current", KeyEvent.VK_P, 1, "Print the current table type information");
mnFile.addSeparator();
mntmClose = ccddMain.createMenuItem(mnFile, "Close", KeyEvent.VK_C, 1, "Close the table type editor");
// Create the Edit menu and menu items
JMenu mnEdit = ccddMain.createMenu(menuBar, "Edit", 1, KeyEvent.VK_E, null);
mntmCopy = ccddMain.createMenuItem(mnEdit, "Copy", KeyEvent.VK_O, 1, "Copy the currently selected cell(s) to the clipboard");
mntmPaste = ccddMain.createMenuItem(mnEdit, "Paste (Ctrl-V)", KeyEvent.VK_V, 1, "Paste the clipboard contents at the current focus location");
mntmInsert = ccddMain.createMenuItem(mnEdit, "Insert", KeyEvent.VK_I, 1, "Insert the clipboard contents at the current focus location");
mnEdit.addSeparator();
mntmUndo = ccddMain.createMenuItem(mnEdit, "Undo (Ctrl-Z)", KeyEvent.VK_Z, 1, "Undo the last edit operation");
mntmRedo = ccddMain.createMenuItem(mnEdit, "Redo (Ctrl-Y)", KeyEvent.VK_Y, 1, "Redo the last undone edit operation");
mnEdit.addSeparator();
mntmClear = ccddMain.createMenuItem(mnEdit, "Clear data", KeyEvent.VK_L, 1, "Clear the current table type contents");
mntmInsertCmdArgs = ccddMain.createMenuItem(mnEdit, "Add command arguments", KeyEvent.VK_A, 1, "Add the default columns for a command argument");
// Create the Row menu and menu items
JMenu mnRow = ccddMain.createMenu(menuBar, "Row", KeyEvent.VK_R, 1, null);
mntmInsertRow = ccddMain.createMenuItem(mnRow, "Insert row", KeyEvent.VK_I, 1, "Insert a row below the current focus location");
mntmDeleteRow = ccddMain.createMenuItem(mnRow, "Delete row(s)", KeyEvent.VK_D, 1, "Delete the currently selected row(s)");
mnRow.addSeparator();
mntmMoveUp = ccddMain.createMenuItem(mnRow, "Move up", KeyEvent.VK_U, 1, "Move the currently selected row(s) up one row");
mntmMoveDown = ccddMain.createMenuItem(mnRow, "Move down", KeyEvent.VK_N, 1, "Move the currently selected row(s) down one row");
// Create the Field menu and menu items
JMenu mnField = ccddMain.createMenu(menuBar, "Field", KeyEvent.VK_L, 1, null);
mntmManageFields = ccddMain.createMenuItem(mnField, "Manage fields", KeyEvent.VK_M, 1, "Open the data field manager");
mntmClearValues = ccddMain.createMenuItem(mnField, "Clear values", KeyEvent.VK_C, 1, "Clear the data field values");
mntmOverwrite = ccddMain.createCheckBoxMenuItem(mnField, "Overwrite values", KeyEvent.VK_O, 1, "Overwrite/don't overwrite existing data field values", false);
// Add a listener for the New Type command
mntmNewType.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Create a new table type
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
new CcddTableTypeManagerDialog(ccddMain, CcddTableTypeEditorDialog.this, ManagerDialogType.NEW);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Copy Type command
mntmCopyType.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Copy a table type
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
new CcddTableTypeManagerDialog(ccddMain, CcddTableTypeEditorDialog.this, ManagerDialogType.COPY);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Rename Type command
mntmRenameType.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Rename a table type
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
new CcddTableTypeManagerDialog(ccddMain, CcddTableTypeEditorDialog.this, ManagerDialogType.RENAME);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Delete Type command
mntmDeleteType.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Delete a table type
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
new CcddTableTypeManagerDialog(ccddMain, CcddTableTypeEditorDialog.this, ManagerDialogType.DELETE);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Print command
mntmPrint.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Output the type to the printer
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
activeEditor.getTable().printTable("Table Type: " + activeEditor.getTypeName(), activeEditor.getFieldHandler(), CcddTableTypeEditorDialog.this, PageFormat.LANDSCAPE);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Copy command
mntmCopy.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Copy the selected table cell(s) contents into the clipboard
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// Send a Ctrl-C key press
controlKeyAction(KeyEvent.VK_C);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Paste command
mntmPaste.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Paste the clipboard contents in the table, overwriting any existing data in
* the target cells and adding new rows at the end of the table if needed
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// Send a Ctrl-V key press
controlKeyAction(KeyEvent.VK_V);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Insert command
mntmInsert.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Insert the clipboard contents in the table, creating new rows to contain the
* data
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// Send a ctrl-I key press
controlKeyAction(KeyEvent.VK_I);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Clear command
mntmClear.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Clear the table contents
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// Check if there are any rows to clear
if (activeEditor.getTable().getModel().getRowCount() != 0) {
// Select all rows and remove them
activeEditor.getTable().selectAll();
activeEditor.getTable().removeRows(activeEditor.getTable().getSelectedRows());
}
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Insert command arguments command
mntmInsertCmdArgs.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Insert the default columns for a command argument
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
boolean isIndexUsed;
int argumentIndex = 1;
do {
// Set the flag to indicate that the argument index isn't used
isIndexUsed = false;
// Step through each column name in the table type
for (String columnName : activeEditor.getTypeDefinition().getColumnNamesUser()) {
// argument name for this argument index
if (columnName.startsWith(COL_ARGUMENT + " " + argumentIndex + " ")) {
// Set the flag to indicate that the argument index is used,
// increment the argument index, and stop searching
isIndexUsed = true;
argumentIndex++;
break;
}
}
} while (isIndexUsed);
// Continue to search the column names while a match is found
int newArgStartIndex = activeEditor.getTypeDefinition().getColumnCountVisible();
// Create the command argument columns for the next unused argument index
activeEditor.getTypeDefinition().addCommandArgumentColumns(argumentIndex);
// Step through each new command argument column
for (; newArgStartIndex < activeEditor.getTypeDefinition().getColumnCountVisible(); newArgStartIndex++) {
// Insert the column into the table type editor
activeEditor.getTable().insertRow(false, TableInsertionPoint.END, activeEditor.getTypeDefinition().getData()[newArgStartIndex]);
}
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Store All command
mntmStoreAll.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Store the changes to all open table contents, if any, in the database
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// confirms the action
if (isTypesChanged() && new CcddDialogHandler().showMessageDialog(CcddTableTypeEditorDialog.this, "<html><b>Store changes for all?", "Store Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON && ccddMain.ignoreUncommittedChanges("Store Changes", "Discard table changes?", false, changedTypes, CcddTableTypeEditorDialog.this)) {
// Commit the changes for all of the editors
storeAllChanges();
}
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Manage Fields command
mntmManageFields.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Manage the data fields
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
new CcddFieldEditorDialog(ccddMain, activeEditor, CcddFieldHandler.getFieldTypeName(activeEditor.getTypeName()), tableTypeHandler.getTypeDefinition(activeEditor.getTypeName()).isStructure(), MIN_WINDOW_WIDTH);
// Enable/disable the Clear values command depending on if any data fields
// remain
mntmClearValues.setEnabled(!activeEditor.getFieldHandler().getFieldInformation().isEmpty());
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Add a listener for the Clear Values command
mntmClearValues.addActionListener(new ValidateCellActionListener() {
/**
****************************************************************************
* Clear the table data field values
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// Check if there are any data fields to clear
if (!activeEditor.getFieldHandler().getFieldInformation().isEmpty()) {
// Remove all of the data field values
activeEditor.getInputFieldPanelHandler().clearFieldValues();
}
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
});
// Insert new row button
JButton btnInsertRow = CcddButtonPanelHandler.createButton("Ins Row", INSERT_ICON, KeyEvent.VK_I, "Insert a new row into the table");
// Create a listener for the Insert Row command
ActionListener insertAction = new ValidateCellActionListener() {
/**
****************************************************************************
* Insert a new row into the table at the selected location
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
activeEditor.getTable().insertEmptyRow(true);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
};
// Add the insert listener to the Insert Row button and menu command
btnInsertRow.addActionListener(insertAction);
mntmInsertRow.addActionListener(insertAction);
// Delete row button
JButton 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 command
ActionListener deleteAction = new ValidateCellActionListener() {
/**
****************************************************************************
* Delete the selected row(s) from the table
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
activeEditor.getTable().deleteRow(true);
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
};
// Add the delete listener to the Delete Row button and menu command
btnDeleteRow.addActionListener(deleteAction);
mntmDeleteRow.addActionListener(deleteAction);
// Move Up button
JButton btnMoveUp = CcddButtonPanelHandler.createButton("Up", UP_ICON, KeyEvent.VK_U, "Move the selected row(s) up");
// Create a listener for the Move Up command
ActionListener moveUpAction = new ValidateCellActionListener() {
/**
****************************************************************************
* Move the selected row(s) up in the table
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
activeEditor.getTable().moveRowUp();
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
};
// Add the move up listener to the Move Up button and menu command
btnMoveUp.addActionListener(moveUpAction);
mntmMoveUp.addActionListener(moveUpAction);
// Move Down button
JButton btnMoveDown = CcddButtonPanelHandler.createButton("Down", DOWN_ICON, KeyEvent.VK_N, "Move the selected row(s) down");
// Create a listener for the Move Down command
ActionListener moveDownAction = new ValidateCellActionListener() {
/**
****************************************************************************
* Move the selected row(s) down in the table
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
activeEditor.getTable().moveRowDown();
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
};
// Add the move down listener to the Move Down button and menu command
btnMoveDown.addActionListener(moveDownAction);
mntmMoveDown.addActionListener(moveDownAction);
// Undo button
JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
// Create a listener for the Undo command
ActionListener undoAction = new ValidateCellActionListener() {
/**
****************************************************************************
* Undo the last cell edit
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
activeEditor.getFieldPanelUndoManager().undo();
// Update the data field background colors
activeEditor.getInputFieldPanelHandler().setFieldBackgound();
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
};
// Add the undo listener to the Undo button and menu command
mntmUndo.addActionListener(undoAction);
btnUndo.addActionListener(undoAction);
// Redo button
JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
// Create a listener for the Redo command
ActionListener redoAction = new ValidateCellActionListener() {
/**
****************************************************************************
* Redo the last cell edit that was undone
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
activeEditor.getFieldPanelUndoManager().redo();
// Update the data field background colors
activeEditor.getInputFieldPanelHandler().setFieldBackgound();
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
};
// Add the redo listener to the Redo button and menu command
mntmRedo.addActionListener(redoAction);
btnRedo.addActionListener(redoAction);
// Store button
JButton btnStore = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the table type updates in the database");
// Create a listener for the Store command
ActionListener storeAction = new ValidateCellActionListener() {
/**
****************************************************************************
* Store the changes to the table contents, if any, in the database
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// Set the list of changed table types to the active editor's type
changedTypes.clear();
changedTypes.add(activeEditor.getTypeName());
// the action
if (activeEditor.isTableChanged() && !activeEditor.checkForMissingColumns() && new CcddDialogHandler().showMessageDialog(CcddTableTypeEditorDialog.this, "<html><b>Store changes in project database?", "Store Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON && ccddMain.ignoreUncommittedChanges("Store Changes", "Discard table changes?", false, changedTypes, CcddTableTypeEditorDialog.this)) {
// Store the changes for the currently displayed editor in the database
storeChanges(activeEditor);
}
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
};
// Add the store listener to the Store button and menu command
btnStore.addActionListener(storeAction);
mntmStore.addActionListener(storeAction);
// Close button
btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the table type editor");
// Add a listener for the Close table type editor command
ActionListener closeAction = new ValidateCellActionListener() {
/**
****************************************************************************
* Close the type editor
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
windowCloseButtonAction();
}
/**
****************************************************************************
* Get the table for which the action is performed
*
* @return Table for which the action is performed
****************************************************************************
*/
@Override
protected CcddJTableHandler getTable() {
return getActiveTable();
}
};
// Add the close listener to the Close button and menu command
btnClose.addActionListener(closeAction);
mntmClose.addActionListener(closeAction);
// Add buttons in the order in which they'll appear (left to right, top to bottom)
buttonPnl.add(btnInsertRow);
buttonPnl.add(btnMoveUp);
buttonPnl.add(btnUndo);
buttonPnl.add(btnStore);
buttonPnl.add(btnDeleteRow);
buttonPnl.add(btnMoveDown);
buttonPnl.add(btnRedo);
buttonPnl.add(btnClose);
// Distribute the buttons across two rows
setButtonRows(2);
// Table Editors //////////////////////////////////////////////////////////////////
// Create a tabbed pane for the editors to appear in
tabbedPane = new DnDTabbedPane(JTabbedPane.TOP) {
/**
****************************************************************************
* Update the table type editor list order following a tab move
****************************************************************************
*/
@Override
protected Object tabMoveCleanup(int oldTabIndex, int newTabIndex, Object tabContents) {
// Get the reference to the moved tab's original location in the list
CcddTableTypeEditorHandler editor = typeEditors.get(oldTabIndex);
// Remove the tab
typeEditors.remove(oldTabIndex);
// Add the tab at its new location
typeEditors.add(newTabIndex - (newTabIndex > oldTabIndex ? 1 : 0), editor);
// Update the active tab pointer to the moved tab
activeEditor = typeEditors.get(tabbedPane.getSelectedIndex());
return editor;
}
};
tabbedPane.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
// Listen for tab selection changes
tabbedPane.addChangeListener(new ChangeListener() {
/**
****************************************************************************
* Update the editor to the one associated with the selected tab
****************************************************************************
*/
@Override
public void stateChanged(ChangeEvent ce) {
// Check if a table type exists
if (!typeEditors.isEmpty()) {
// Set the active editor to the one indicated by the currently selected
// tab
activeEditor = typeEditors.get(tabbedPane.getSelectedIndex());
} else // No table type exists
{
// initialize the active editor to null
activeEditor = null;
}
// Update the editor controls state
setControlsEnabled(!typeEditors.isEmpty());
}
});
// Add each table as a tab in the editor dialog tabbed pane
addTypePanes(typeNames, dbTable.retrieveInformationTable(InternalTable.FIELDS, CcddTableTypeEditorDialog.this));
// Check if a table type exists
if (!typeEditors.isEmpty()) {
// Set the first tab as the active editor
activeEditor = typeEditors.get(0);
} else // No table type exists
{
// initialize the active editor to null
activeEditor = null;
}
}
/**
************************************************************************************
* Table type editor dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Display the table type editor dialog
createFrame(ccddMain.getMainFrame(), tabbedPane, buttonPnl, null, "Table Type Editor", null);
// Enable the editor controls
setControlsEnabled(true);
}
});
}
use of CCDD.CcddBackgroundCommand.BackgroundCommand in project CCDD by nasa.
the class CcddGroupManagerDialog method initialize.
/**
********************************************************************************************
* Create the group 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 group manager dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panels to hold the components of the dialog
JPanel dialogPnl = new JPanel(new GridBagLayout());
JPanel buttonPnl = new JPanel();
JButton btnClose;
/**
************************************************************************************
* Build the group manager dialog
************************************************************************************
*/
@Override
protected void execute() {
isNodeSelectionChanging = false;
// Set the flag to indicate the group manager dialog is being initialized
isInitializing = true;
// Create borders for the dialog components
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()));
emptyBorder = BorderFactory.createEmptyBorder();
// 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);
selectedGroup = null;
deletedGroups = new ArrayList<String>();
// Add an undo edit manager
undoManager = new CcddUndoManager() {
/**
****************************************************************************
* Update the change indicator if the editor panel has changed
****************************************************************************
*/
@Override
protected void ownerHasChanged() {
// during initialization are ignored
if (!isInitializing) {
updateChangeIndicator();
}
}
};
// Create the undo handler for the components with undoable actions. Disable
// storage of edit actions during dialog creation
undoHandler = new CcddUndoHandler(undoManager);
nodeSelect = undoHandler.new UndoableTreePathSelection();
undoHandler.setAllowUndo(false);
// Build the group tree
groupTree = new CcddGroupTreeHandler(ccddMain, undoHandler, ccddMain.getMainFrame()) {
/**
****************************************************************************
* Respond to changes in selection of a node in the group tree
****************************************************************************
*/
@Override
protected void updateTableSelection() {
// Check that a node selection change is not in progress
if (!isNodeSelectionChanging) {
// Set the flag to prevent link tree updates
isNodeSelectionChanging = true;
// Needed for the group manager dialog's size to be adjusted for the
// data fields
groupMgr.setPreferredSize(null);
// Store any changes to the currently selected group, if applicable
updateSelectedGroupInformation();
// Update the description field text so that it can be undone/redone.
// The focus change, which is usually used to perform the update,
// occurs after the node selection edit and would cause the wrong
// description field to be changed
fieldPnlHndlr.updateDescriptionField(true);
// Get the name of the selected group(s)
String[] selected = getTopLevelSelectedNodeNames();
// If a single group is selected then set the selected group, enable
// and populate the description field, and display the group's data
// fields; otherwise clear the selected group, disable and clear the
// description field, and remove any data fields
setGroupAndFields(selected.length == 1 ? selected[0] : null);
// operation isn't recorded on the undo/redo stack
if (undoHandler.isAllowUndo()) {
// Add the node path selection change to the undo/redo stack and
// store the field information in the undo handler
nodeSelect.selectTreePath(getSelectedPaths());
fieldPnlHndlr.storeCurrentFieldInformation();
}
// Reset the flag to allow link tree updates
isNodeSelectionChanging = false;
}
}
};
// Get the references to the group and data field handlers created by the group
// tree. These are used to shorten subsequent calls
groupHandler = groupTree.getGroupHandler();
fieldHandler = groupTree.getFieldHandler();
// Set the data field handler and group tree references in the undo handler so that
// data field and tree edits can be undone/redone
undoHandler.setFieldHandler(fieldHandler);
undoHandler.setTree(groupTree);
// Store the initial group information
copyGroupInformation();
// Create panels to hold the components of the dialog
JPanel titlePnl = new JPanel(new GridBagLayout());
JPanel treePnl = new JPanel(new GridBagLayout());
dialogPnl.setBorder(emptyBorder);
titlePnl.setBorder(emptyBorder);
treePnl.setBorder(emptyBorder);
// Create the group manager dialog labels and fields
JLabel dlgLabel = new JLabel("Assign tables to groups");
dlgLabel.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
titlePnl.add(dlgLabel, gbc);
// Add the upper panel components to the dialog panel
dialogPnl.add(titlePnl, gbc);
// Build the table tree showing both table prototypes and table instances; i.e.,
// parent tables with their child tables (i.e., parents with children)
tableTree = new CcddTableTreeHandler(ccddMain, null, TableTreeType.TABLES, false, true, ccddMain.getMainFrame()) {
/**
****************************************************************************
* Respond to changes in selection of a node in the table tree
****************************************************************************
*/
@Override
protected void updateTableSelection() {
// Check that a node selection change is not in progress
if (!isNodeSelectionChanging) {
// Select the associated group in the group tree if a table is selected
// in the table tree. Note that below any linked variables are
// deselected, so this call must occur first
selectGroupByTable();
// Set the flag to prevent variable tree updates
isNodeSelectionChanging = true;
// Deselect any nodes that don't represent a table or the level
// immediately above the table level
clearNonTableNodes(1);
// Reset the flag to allow variable tree updates
isNodeSelectionChanging = false;
}
}
};
// Create a table tree panel and add it to another panel (in order to control
// spacing)
gbc.insets.top = 0;
gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 1.0;
treePnl.add(tableTree.createTreePanel("Tables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, ccddMain.getMainFrame()), gbc);
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.insets.bottom = 0;
// Create a split pane containing the table tree in the left pane and the group
// tree in the right pane and add it to the panel. The arrow button panel is used
// as the split pane divider
gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
gbc.gridy++;
dialogPnl.add(new CustomSplitPane(treePnl, groupTree.createTreePanel("Groups", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, false, ccddMain.getMainFrame()), createArrowButtonPanel(), JSplitPane.HORIZONTAL_SPLIT), gbc);
// Create the field panel for the description and data fields
fieldPnlHndlr = new CcddInputFieldPanelHandler() {
/**
****************************************************************************
* Update the group manager change indicator
****************************************************************************
*/
@Override
protected void updateOwnerChangeIndicator() {
updateChangeIndicator();
}
};
// Set the undo/redo manager and handler for the description and data field values
fieldPnlHndlr.setEditPanelUndo(undoManager, undoHandler);
// Create the description and data fields
fieldPnlHndlr.createDescAndDataFieldPanel(groupMgr, null, null, null, fieldHandler);
// Set the modal undo manager in the keyboard handler while the group manager is
// active
ccddMain.getKeyboardHandler().setModalDialogReference(undoManager, null);
// Re-enable storage of edit actions
undoHandler.setAllowUndo(true);
// Add the field panel to the dialog
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.insets.left = 0;
gbc.insets.bottom = 0;
gbc.insets.right = 0;
gbc.weighty = 0.0;
gbc.gridy++;
dialogPnl.add(fieldPnlHndlr.getFieldPanel(), gbc);
// Create a check box for showing/changing the group CFS application status
applicationCb = undoHandler.new UndoableCheckBox("Group represents a CFS application", false);
applicationCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
applicationCb.setBorder(emptyBorder);
applicationCb.setEnabled(false);
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
gbc.gridy = 0;
fieldPnlHndlr.getFieldPanel().add(applicationCb, gbc, 0);
// Add a listener for the application check box
applicationCb.addActionListener(new ActionListener() {
/**
****************************************************************************
* Handle a change in the application check box status
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Check if the application check box is selected and a group is selected
if (((JCheckBox) ae.getSource()).isSelected() && selectedGroup != null) {
// The application check box selection and the added CFS application
// data fields should be a single edit action so that both are removed
// if an undo is performed. Remove the check box selection from the
// undo stack, disable automatic edit sequence ending, then perform the
// check box selection again so that it's added to the undo stack
// without ending the edit sequence
undoManager.undoRemoveEdit();
undoHandler.setAutoEndEditSequence(false);
applicationCb.setSelected(true);
// Get the field information for the group
GroupInformation groupInfo = groupHandler.getGroupInformationByName(selectedGroup.getName());
List<FieldInformation> fieldInformation = groupInfo.getFieldInformation();
// Step through each default application data field
for (DefaultApplicationField field : DefaultApplicationField.values()) {
// Create a new data field
FieldInformation newField = field.createFieldInformation(CcddFieldHandler.getFieldGroupName(selectedGroup.getName()));
boolean isExists = false;
// Step through the group's existing data fields
for (FieldInformation fieldInfo : fieldInformation) {
// Check if the data field already exists
if (newField.getFieldName().equals(fieldInfo.getFieldName())) {
// Set the flag indicating the field exists and stop
// searching
isExists = true;
break;
}
}
// Check if the field doesn't exists
if (!isExists) {
// Add the field to the group
fieldInformation.add(newField);
}
}
// Needed for the group manager dialog's size to be adjusted for the
// data fields
groupMgr.setPreferredSize(null);
// Store the data field additions so that the added fields appear in
// the dialog
fieldHandler.setFieldInformation(CcddFieldHandler.getFieldInformationCopy(fieldInformation));
// Rebuild the data field panel and update the dialog's size
recreateDataFieldPanel(true);
// Re-enable automatic edit sequence ending, then end the edit sequence
// to group the check box and added data fields
undoHandler.setAutoEndEditSequence(true);
undoManager.endEditSequence();
}
}
});
// Define the buttons for the lower panel: New group button
JButton btnNewGroup = CcddButtonPanelHandler.createButton("New", INSERT_ICON, KeyEvent.VK_N, "Create a new group");
// Add a listener for the New button
btnNewGroup.addActionListener(new ActionListener() {
/**
****************************************************************************
* Add a new group
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
newGroup();
}
});
// Delete group button
JButton btnDeleteGroup = CcddButtonPanelHandler.createButton("Delete", DELETE_ICON, KeyEvent.VK_D, "Delete an existing group");
// Add a listener for the Delete button
btnDeleteGroup.addActionListener(new ActionListener() {
/**
****************************************************************************
* Delete the selected group(s)
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
deleteGroup();
}
});
// Rename group button
btnRenameGroup = CcddButtonPanelHandler.createButton("Rename", RENAME_ICON, KeyEvent.VK_D, "Rename an existing group");
// Add a listener for the Rename button
btnRenameGroup.addActionListener(new ActionListener() {
/**
****************************************************************************
* Rename the selected group
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
renameGroup();
}
});
// Copy group button
btnCopyGroup = CcddButtonPanelHandler.createButton("Copy", COPY_ICON, KeyEvent.VK_P, "Copy an existing group");
// Add a listener for the Copy button
btnCopyGroup.addActionListener(new ActionListener() {
/**
****************************************************************************
* Copy the selected group
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
copyGroup();
}
});
// Manage fields button
btnManageFields = CcddButtonPanelHandler.createButton("Fields", FIELD_ICON, KeyEvent.VK_F, "Manage the data fields");
// Add a listener for the Manage Fields command
btnManageFields.addActionListener(new ActionListener() {
/**
****************************************************************************
* Manage the data fields
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Create the field editor dialog showing the fields for this group
new CcddFieldEditorDialog(ccddMain, fieldPnlHndlr, CcddFieldHandler.getFieldGroupName(selectedGroup.getName()), false, ModifiableSizeInfo.MIN_DIALOG_WIDTH.getSize());
// Set the undo manager in the keyboard handler back to the group manager
ccddMain.getKeyboardHandler().setModalDialogReference(undoManager, null);
// Enable/disable the Clear values button depending on if any data fields
// remain
btnClearValues.setEnabled(!fieldHandler.getFieldInformation().isEmpty());
}
});
// Clear fields button
btnClearValues = CcddButtonPanelHandler.createButton("Clear", CLEAR_ICON, KeyEvent.VK_C, "Clear the data fields");
// Add a listener for the Clear values command
btnClearValues.addActionListener(new ActionListener() {
/**
****************************************************************************
* Clear the table data field values
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Clear all of the data field values for the group
fieldPnlHndlr.clearFieldValues();
}
});
// Undo button
JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
// Create a listener for the Undo command
ActionListener undoAction = new ActionListener() {
/**
****************************************************************************
* Undo the last edit
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
undoManager.undo();
// Update the group selection following an undo
undoHandler.setAllowUndo(false);
groupTree.updateTableSelection();
undoHandler.setAllowUndo(true);
// Update the data field background colors
fieldPnlHndlr.setFieldBackgound();
}
};
// Add the undo listener to the Undo button and menu command
btnUndo.addActionListener(undoAction);
// Redo button
JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
// Create a listener for the Redo command
ActionListener redoAction = new ActionListener() {
/**
****************************************************************************
* Redo the last cell that was undone
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
undoManager.redo();
// Update the data field background colors
fieldPnlHndlr.setFieldBackgound();
}
};
// Add the redo listener to the Redo button and menu command
btnRedo.addActionListener(redoAction);
// Store groups button
JButton btnStoreGroups = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store group updates in the database");
// Add a listener for the Store button
btnStoreGroups.addActionListener(new ActionListener() {
/**
****************************************************************************
* Store the groups in the database
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// editor is open and has changes that the user confirms discarding them
if (isGroupsChanged() && new CcddDialogHandler().showMessageDialog(groupMgr, "<html><b>Store groups?", "Store Groups", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON && ignoreFieldTableChanges()) {
// Store the group list into the database
dbTable.storeInformationTableInBackground(InternalTable.GROUPS, currentGroups, updateFields, deletedGroups, null, null, groupMgr);
}
}
});
// Close button
btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the group manager");
// Add a listener for the Close button
btnClose.addActionListener(new ActionListener() {
/**
****************************************************************************
* Close the group selection dialog
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// discard the changes
if (!isGroupsChanged() || new CcddDialogHandler().showMessageDialog(groupMgr, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Close the dialog
closeDialog();
// Clear the modal dialog references in the keyboard handler
ccddMain.getKeyboardHandler().setModalDialogReference(null, null);
}
}
});
// Set the initial enable status of the buttons
setGroupButtonsEnabled(false);
// Add buttons in the order in which they'll appear (left to right, top to bottom)
buttonPnl.add(btnNewGroup);
buttonPnl.add(btnRenameGroup);
buttonPnl.add(btnManageFields);
buttonPnl.add(btnUndo);
buttonPnl.add(btnStoreGroups);
buttonPnl.add(btnDeleteGroup);
buttonPnl.add(btnCopyGroup);
buttonPnl.add(btnClearValues);
buttonPnl.add(btnRedo);
buttonPnl.add(btnClose);
// Distribute the buttons across two rows
setButtonRows(2);
// Update the undo manager so that all group manager edits up to the press of the
// Store button can be undone/redone
fieldPnlHndlr.storeCurrentFieldInformation();
undoManager.endEditSequence();
// Reset the flag now that initialization is complete
isInitializing = false;
}
/**
************************************************************************************
* Group manager dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Display the group manager dialog
showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnClose, DIALOG_TITLE, true);
}
});
}
use of CCDD.CcddBackgroundCommand.BackgroundCommand in project CCDD by nasa.
the class CcddScriptExecutiveDialog method initialize.
/**
********************************************************************************************
* Create the script executive 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() {
// user confirms ignoring the changes
if (ccddMain.ignoreUncommittedChanges("Script Manager", "Ignore changes?", false, null, CcddScriptExecutiveDialog.this)) {
// Build the script executive dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panels to hold the components of the dialog
JPanel dialogPnl = new JPanel(new GridBagLayout());
JPanel buttonPnl = new JPanel();
/**
********************************************************************************
* Build the script executive dialog
********************************************************************************
*/
@Override
protected void execute() {
// 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(), 0, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()), 0, 0);
dialogPnl.setBorder(BorderFactory.createEmptyBorder());
// Create the table group selection dialog labels and fields
JLabel scriptLbl = new JLabel("Select script association(s) to execute");
scriptLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
dialogPnl.add(scriptLbl, gbc);
// Create the list to display the stored script associations and add it to the
// dialog
gbc.weighty = 1.0;
gbc.insets.top = 0;
gbc.gridy++;
dialogPnl.add(scriptHandler.getAssociationsPanel(null, false, CcddScriptExecutiveDialog.this), gbc);
// Execute selected script association(s) button
btnExecute = CcddButtonPanelHandler.createButton("Execute", EXECUTE_ICON, KeyEvent.VK_E, "Execute the selected script association(s)");
// Add a listener for the Execute button
btnExecute.addActionListener(new ActionListener() {
/**
************************************************************************
* Execute the selected script association(s)
************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Execute the selected associations
scriptHandler.executeScriptAssociations(tableTree, CcddScriptExecutiveDialog.this);
}
});
// Close button
btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the script executive");
// Add a listener for the Close button
btnClose.addActionListener(new ActionListener() {
/**
************************************************************************
* Close the script execution dialog
************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Reset the reference to the script associations executive in the
// script handler since the handler remains active)
scriptHandler.setScriptDialog(null);
closeFrame();
}
});
// Add buttons to the button panel
buttonPnl.add(btnExecute);
buttonPnl.add(btnClose);
}
/**
********************************************************************************
* Script executive dialog creation complete
********************************************************************************
*/
@Override
protected void complete() {
// Display the script execution dialog
createFrame(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnExecute, "Execute Script(s)", null);
}
});
}
}
use of CCDD.CcddBackgroundCommand.BackgroundCommand in project CCDD by nasa.
the class CcddLinkManagerDialog method initialize.
/**
********************************************************************************************
* Create the variable link 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 variable link manager dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panels to hold the components of the dialog
JPanel dialogPnl = new JPanel(new GridBagLayout());
JPanel buttonPnl = new JPanel();
JButton btnClose;
/**
************************************************************************************
* Build the variable link manager dialog
************************************************************************************
*/
@Override
protected void execute() {
// Create a border for the dialog components
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()));
// 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 a tabbed pane to contain the rate parameters that are stream-specific
tabbedPane = new DnDTabbedPane(SwingConstants.TOP) {
/**
****************************************************************************
* Update the link manager list order following a tab move
****************************************************************************
*/
@Override
protected Object tabMoveCleanup(int oldTabIndex, int newTabIndex, Object tabContents) {
// Adjust the new tab index if moving the tab to a higher index
newTabIndex -= newTabIndex > oldTabIndex ? 1 : 0;
// Re-order the rate information based on the new tab order
RateInformation[] rateInfoArray = rateHandler.getRateInformation().toArray(new RateInformation[0]);
rateInfoArray = (RateInformation[]) CcddUtilities.moveArrayMember(rateInfoArray, oldTabIndex, newTabIndex);
List<RateInformation> rateInfoList = new ArrayList<RateInformation>(rateInfoArray.length);
rateInfoList.addAll(Arrays.asList(rateInfoArray));
rateHandler.setRateInformation(rateInfoList);
// Get the reference to the moved tab's original location in the list
CcddLinkManagerHandler editor = linkMgrs.get(oldTabIndex);
// Remove the tab
linkMgrs.remove(oldTabIndex);
// Add the tab at its new location
linkMgrs.add(newTabIndex, editor);
// Update the active tab pointer to the moved tab
activeHandler = linkMgrs.get(tabbedPane.getSelectedIndex());
return editor;
}
};
tabbedPane.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
// Listen for tab selection changes
tabbedPane.addChangeListener(new ChangeListener() {
/**
****************************************************************************
* Update the handler to the one associated with the selected tab
****************************************************************************
*/
@Override
public void stateChanged(ChangeEvent ce) {
// Set the active handler to the one indicated by the currently selected
// tab
activeHandler = linkMgrs.get(tabbedPane.getSelectedIndex());
// Get the number of selected links
int numSelectedLinks = activeHandler.getLinkTree().getSelectionCount();
// Update the manager controls state
setLinkButtonsEnabled(numSelectedLinks == 1, numSelectedLinks != 0);
// Set the modal undo manager reference in the keyboard handler while the
// link manager is active
ccddMain.getKeyboardHandler().setModalDialogReference(activeHandler.getUndoManager(), null);
}
});
gbc.gridwidth = 2;
gbc.gridx = 0;
gbc.gridy++;
dialogPnl.add(tabbedPane, gbc);
// Define the buttons for the lower panel: New link button
JButton btnNewLink = CcddButtonPanelHandler.createButton("New", INSERT_ICON, KeyEvent.VK_N, "Create a new link");
// Add a listener for the New button
btnNewLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Add a new link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
createLink();
}
});
// Delete link button
JButton btnDeleteLink = CcddButtonPanelHandler.createButton("Delete", DELETE_ICON, KeyEvent.VK_D, "Delete an existing link");
// Add a listener for the Delete button
btnDeleteLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Delete the selected link(s)
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
deleteLink();
}
});
// Rename link button
btnRenameLink = CcddButtonPanelHandler.createButton("Rename", RENAME_ICON, KeyEvent.VK_D, "Rename an existing link");
// Add a listener for the Rename button
btnRenameLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Rename the selected link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
renameLink();
}
});
// Copy link button
btnCopyLink = CcddButtonPanelHandler.createButton("Copy", COPY_ICON, KeyEvent.VK_P, "Copy an existing link");
// Add a listener for the Copy button
btnCopyLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Copy the selected link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
copyLink();
}
});
// Undo button
JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
// Create a listener for the Undo command
ActionListener undoAction = new ActionListener() {
/**
****************************************************************************
* Undo the last edit
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
activeHandler.getUndoManager().undo();
// Update the link selection following an undo
activeHandler.getUndoHandler().setAllowUndo(false);
activeHandler.getLinkTree().updateTableSelection();
activeHandler.getUndoHandler().setAllowUndo(true);
// Update the link definitions, selected link, link fields, and link tree
// node names
activeHandler.cleanUpLinks();
}
};
// Add the undo listener to the Undo button and menu command
btnUndo.addActionListener(undoAction);
// Redo button
JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
// Create a listener for the Redo command
ActionListener redoAction = new ActionListener() {
/**
****************************************************************************
* Redo the last edit that was undone
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
activeHandler.getUndoManager().redo();
// Update the link definitions, selected link, link fields, and link tree
// node names
activeHandler.cleanUpLinks();
}
};
// Add the redo listener to the Redo button and menu command
btnRedo.addActionListener(redoAction);
// Store links button
JButton btnStoreLinks = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the link updates in the database");
// Add a listener for the Store button
btnStoreLinks.addActionListener(new ActionListener() {
/**
****************************************************************************
* Store the links in the database
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// the user confirms storing the links
if (isLinksChanged() && new CcddDialogHandler().showMessageDialog(CcddLinkManagerDialog.this, "<html><b>Store links?", "Store Links", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Store the links in the project database
storeLinks();
}
}
});
// Close button
btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the link manager");
// Add a listener for the Close button
btnClose.addActionListener(new ActionListener() {
/**
****************************************************************************
* Close the link selection dialog
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// discard the changes
if (!isLinksChanged() || new CcddDialogHandler().showMessageDialog(CcddLinkManagerDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Close the dialog
closeDialog();
// Clear the modal dialog references in the keyboard handler
ccddMain.getKeyboardHandler().setModalDialogReference(null, null);
}
}
});
// Add buttons in the order in which they'll appear (left to right, top to bottom)
buttonPnl.add(btnNewLink);
buttonPnl.add(btnRenameLink);
buttonPnl.add(btnUndo);
buttonPnl.add(btnStoreLinks);
buttonPnl.add(btnDeleteLink);
buttonPnl.add(btnCopyLink);
buttonPnl.add(btnRedo);
buttonPnl.add(btnClose);
// Distribute the buttons across two rows
setButtonRows(2);
// Add the data stream link handlers
addLinkHandlerPanes();
}
/**
************************************************************************************
* Variable link manager dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Display the link management dialog
showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnClose, "Manage Links", true);
}
});
}
Aggregations