use of CCDD.CcddClassesComponent.ValidateCellActionListener 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.CcddClassesComponent.ValidateCellActionListener 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.CcddClassesComponent.ValidateCellActionListener in project CCDD by nasa.
the class CcddMacroEditorDialog method initialize.
/**
********************************************************************************************
* Create the macro 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 initialize() {
// Build the macro editor dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panels to hold the components of the dialog
JPanel editorPnl = new JPanel(new GridBagLayout());
JPanel buttonPnl = new JPanel();
JButton btnClose;
/**
************************************************************************************
* Build the macro editor dialog
************************************************************************************
*/
@Override
protected void execute() {
modifications = new ArrayList<TableModification>();
loadedReferences = new ArrayList<MacroReference>();
// 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 copy of the macro data so it can be used to determine if changes are
// made
storeCurrentData();
// Define the panel to contain the table and place it in the editor
JPanel tablePnl = new JPanel();
tablePnl.setLayout(new BoxLayout(tablePnl, BoxLayout.X_AXIS));
tablePnl.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
tablePnl.add(createMacroTable());
editorPnl.add(tablePnl, gbc);
editorPnl.setBorder(BorderFactory.createEmptyBorder());
// Set the modal undo manager and table references in the keyboard handler while
// the macro editor is active
ccddMain.getKeyboardHandler().setModalDialogReference(macroTable.getUndoManager(), macroTable);
// New 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 button
btnInsertRow.addActionListener(new ValidateCellActionListener(macroTable) {
/**
****************************************************************************
* Insert a new row into the table at the selected location
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
macroTable.insertEmptyRow(true);
}
});
// Delete 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 button
btnDeleteRow.addActionListener(new ValidateCellActionListener(macroTable) {
/**
****************************************************************************
* Delete the selected row(s) from the table
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// Step through each row selected for deletion
for (int row : macroTable.getSelectedRows()) {
// Get the macro name
String name = macroTable.getValueAt(row, MacrosColumn.MACRO_NAME.ordinal()).toString();
// Check if the macro is used in any of the data tables
if (!name.isEmpty() && macroHandler.getMacroReferences(name, CcddMacroEditorDialog.this).length != 0) {
// Deselect the macro
macroTable.removeRowSelectionInterval(row, row);
// Inform the user that the macro can't be deleted
new CcddDialogHandler().showMessageDialog(CcddMacroEditorDialog.this, "<html><b>Cannot delete macro '" + name + "'; macro is referenced by a data table", "Delete Macro", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_OPTION);
}
}
macroTable.deleteRow(true);
}
});
// 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 button
btnMoveUp.addActionListener(new ValidateCellActionListener(macroTable) {
/**
****************************************************************************
* Move the selected row(s) up in the table
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
macroTable.moveRowUp();
}
});
// Move Down button
JButton btnMoveDown = CcddButtonPanelHandler.createButton("Down", DOWN_ICON, KeyEvent.VK_W, "Move the selected row(s) down");
// Create a listener for the Move Down button
btnMoveDown.addActionListener(new ValidateCellActionListener(macroTable) {
/**
****************************************************************************
* Move the selected row(s) down in the table
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
macroTable.moveRowDown();
}
});
// Undo button
JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit");
// Create a listener for the Undo button
btnUndo.addActionListener(new ValidateCellActionListener(macroTable) {
/**
****************************************************************************
* Undo the last cell edit
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
macroTable.getUndoManager().undo();
}
});
// Redo button
JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit");
// Create a listener for the Redo button
btnRedo.addActionListener(new ValidateCellActionListener(macroTable) {
/**
****************************************************************************
* Redo the last cell edit that was undone
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
macroTable.getUndoManager().redo();
}
});
// Store the macros button
JButton btnStore = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the macro(s)");
// Create a listener for the Store button
btnStore.addActionListener(new ValidateCellActionListener(macroTable) {
/**
****************************************************************************
* Store the macros
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
// the action
if (macroTable.isTableChanged(committedData) && !checkForMissingColumns() && new CcddDialogHandler().showMessageDialog(CcddMacroEditorDialog.this, "<html><b>Store changes in project database?", "Store Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Get a list of the macro modifications
buildUpdates();
// Update the tables affected by the changes to the macro(s)
dbTable.modifyTablePerDataTypeOrMacroChanges(modifications, getUpdatedData(), CcddMacroEditorDialog.this);
}
}
});
// Close button
btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the macro editor");
// Create a listener for the Close button
btnClose.addActionListener(new ValidateCellActionListener(macroTable) {
/**
****************************************************************************
* Close the macro editor dialog
****************************************************************************
*/
@Override
protected void performAction(ActionEvent ae) {
windowCloseButtonAction();
}
});
// Add buttons in the order in which they'll appear (left to right, top to bottom)
buttonPnl.add(btnInsertRow);
buttonPnl.add(btnMoveUp);
buttonPnl.add(btnUndo);
buttonPnl.add(btnStore);
buttonPnl.add(btnDeleteRow);
buttonPnl.add(btnMoveDown);
buttonPnl.add(btnRedo);
buttonPnl.add(btnClose);
// Distribute the buttons across two rows
setButtonRows(2);
}
/**
************************************************************************************
* Macro editor dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Display the macro editor dialog
showOptionsDialog(ccddMain.getMainFrame(), editorPnl, buttonPnl, btnClose, DIALOG_TITLE, true);
}
});
}
Aggregations