Search in sources :

Example 1 with CellSelectionHandler

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();
                    }
                }
            }
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) CellSelectionHandler(CCDD.CcddClassesComponent.CellSelectionHandler) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) List(java.util.List) ArrayList(java.util.ArrayList) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand)

Aggregations

BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)1 CellSelectionHandler (CCDD.CcddClassesComponent.CellSelectionHandler)1 ValidateCellActionListener (CCDD.CcddClassesComponent.ValidateCellActionListener)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JCheckBox (javax.swing.JCheckBox)1 JPanel (javax.swing.JPanel)1