use of CCDD.CcddClassesComponent.CellSelectionHandler in project CCDD by nasa.
the class CcddFieldTableEditorDialog method selectDataFields.
/**
********************************************************************************************
* Display a dialog for the user to select the data fields to display in the editor table. 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 selectDataFields() {
// Build the data field selection dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panels to hold the components of the dialog
JPanel selectPnl = new JPanel(new GridBagLayout());
/**
************************************************************************************
* Build the data field selection dialog
************************************************************************************
*/
@Override
protected void execute() {
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0, 0), 0, 0);
// Load the data field information from the database
getDataFieldInformation();
// Create a selection dialog, a panel for the table selection tree, and a panel to
// contain a check box for each unique data field name
selectDlg = new CcddDialogHandler() {
/**
****************************************************************************
* Verify input fields
*
* @return true if the dialog input is valid
****************************************************************************
*/
@Override
protected boolean verifySelection() {
// Assume the dialog input is valid
boolean isValid = true;
// Check if no data field check box is selected
if (selectDlg.getCheckBoxSelected().length == 0) {
// Inform the user that a field must be selected
new CcddDialogHandler().showMessageDialog(this, "<html><b>Must select at least one data field", "No Data Field Selected", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
isValid = false;
}
return isValid;
}
};
JPanel fieldPnl = new JPanel(new GridBagLayout());
selectPnl.setBorder(emptyBorder);
fieldPnl.setBorder(emptyBorder);
// from which to choose
if (selectDlg.addCheckBoxes(null, getDataFieldNames(), null, "Select data fields to display/edit", fieldPnl)) {
// Check if more than one data field name check box exists
if (selectDlg.getCheckBoxes().length > 2) {
// Create a Select All check box
final JCheckBox selectAllCb = new JCheckBox("Select all data fields", false);
selectAllCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
selectAllCb.setBorder(emptyBorder);
// Create a listener for changes to the Select All check box selection
// status
selectAllCb.addActionListener(new ActionListener() {
/**
********************************************************************
* Handle a change to the Select All check box selection status
********************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Step through each data field name check box
for (JCheckBox fieldCb : selectDlg.getCheckBoxes()) {
// Set the check box selection status to match the Select All
// check box selection status
fieldCb.setSelected(selectAllCb.isSelected());
}
}
});
// Add the Select All checkbox to the field name panel
gbc.gridy++;
fieldPnl.add(selectAllCb, gbc);
}
// the Select button)
if (columnNames != null) {
// Step through the list of check boxes representing the data fields
for (JCheckBox cb : selectDlg.getCheckBoxes()) {
// Select the data field check box if the field was displayed when the
// Select button was pressed
cb.setSelected(Arrays.asList(columnNames).contains(cb.getText()));
}
}
// Add the field panel to the selection panel
gbc.insets.top = 0;
gbc.insets.left = 0;
gbc.weighty = 0.0;
gbc.gridy = 0;
selectPnl.add(fieldPnl, 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, new CcddGroupHandler(ccddMain, null, CcddFieldTableEditorDialog.this), TableTreeType.TABLES, true, false, CcddFieldTableEditorDialog.this);
// Add the tree to the selection panel
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridx++;
selectPnl.add(tableTree.createTreePanel("Tables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, ccddMain.getMainFrame()), gbc);
} else // No data field exists to choose
{
// Inform the user that no data field is defined
new CcddDialogHandler().showMessageDialog((isVisible() ? CcddFieldTableEditorDialog.this : ccddMain.getMainFrame()), "<html><b>No data field exists", "No Data Field", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
}
}
/**
************************************************************************************
* Data field selection dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Display the data field selection dialog if any fields are available for display
if (!dataFields.isEmpty() && selectDlg.showOptionsDialog((isVisible() ? CcddFieldTableEditorDialog.this : ccddMain.getMainFrame()), selectPnl, "Select Data Field(s)", DialogOption.OK_CANCEL_OPTION, true) == OK_BUTTON) {
// Create a list for the column names. Add the default columns (table name and
// path)
List<String> columnNamesList = new ArrayList<String>();
columnNamesList.add(FieldTableEditorColumnInfo.OWNER.getColumnName());
columnNamesList.add(FieldTableEditorColumnInfo.PATH.getColumnName());
// Step through each selected data field name
for (String name : selectDlg.getCheckBoxSelected()) {
// Add the data field name to the column name list
columnNamesList.add(name);
}
// Convert the list of column names to an array
columnNames = columnNamesList.toArray(new String[0]);
// Create the cell selection container
selectedCells = new CellSelectionHandler();
// Clear any removal selections
selectedCells.clear();
// Check if this is the initial display of the selection dialog
if (dataFieldTable == null) {
// Create the data field editor dialog
displayDataFieldTableEditor();
} else // The selection dialog is spawned from the data field table editor
{
// Reload the data field table
dataFieldTable.loadAndFormatData();
// Check if the field table editor dialog is already open
if (CcddFieldTableEditorDialog.this.isVisible()) {
// Reposition the field table editor dialog
positionFieldEditorDialog();
}
}
}
}
});
}
Aggregations