Search in sources :

Example 1 with UndoableCheckBox

use of CCDD.CcddUndoHandler.UndoableCheckBox in project CCDD by nasa.

the class CcddKeyboardHandler method getActiveUndoManager.

/**
 ********************************************************************************************
 * Get the active component's undo manager
 *
 * @return The active undo manager; null if no undo manager is active or no editor has focus
 ********************************************************************************************
 */
private CcddUndoManager getActiveUndoManager() {
    CellEditor cellEditor = null;
    CcddUndoManager undoManager = null;
    editPnlHandler = null;
    // Check if a modal dialog is active
    if (modalUndoManager != null) {
        // Set the undo manager to the modal dialog's undo manager
        undoManager = modalUndoManager;
        // Check if a modal table is active
        if (modalTable != null) {
            // Get the cell editor for the modal table
            cellEditor = modalTable.getCellEditor();
        }
        // Get a reference to the group manager dialog to shorten subsequent calls
        CcddGroupManagerDialog groupManager = ccddMain.getGroupManager();
        // Check if the group manager is open and has focus
        if (groupManager != null && groupManager.isFocused()) {
            // Get the group manager's editor panel handler
            editPnlHandler = groupManager.getEditorPanelHandler();
        }
    } else // No modal undo manager is active
    {
        // Step through each open table editor dialog
        for (CcddTableEditorDialog editorDialog : ccddMain.getTableEditorDialogs()) {
            // Check if this editor dialog has the keyboard focus
            if (editorDialog.isFocused()) {
                // Get the undo manager, cell editor, and editor panel handler for the active
                // table editor
                undoManager = editorDialog.getTableEditor().getFieldPanelUndoManager();
                cellEditor = editorDialog.getTableEditor().getTable().getCellEditor();
                editPnlHandler = editorDialog.getTableEditor().getInputFieldPanelHandler();
            }
            // Check if an undo manager is active
            if (undoManager != null) {
                // Stop searching
                break;
            }
        }
        // Get a reference to the type editor dialog to shorten subsequent calls
        CcddTableTypeEditorDialog editorDialog = ccddMain.getTableTypeEditor();
        // Check if no table undo manager is applicable and the table type editor is open
        if (undoManager == null && editorDialog != null) {
            // Check if the table type editor has the keyboard focus
            if (editorDialog.isFocused()) {
                // Get the undo manager, cell editor, and editor panel handler for the active
                // table type editor
                undoManager = editorDialog.getTypeEditor().getFieldPanelUndoManager();
                cellEditor = editorDialog.getTypeEditor().getTable().getCellEditor();
                editPnlHandler = editorDialog.getTypeEditor().getInputFieldPanelHandler();
            }
        }
        // Get a reference to the data field table editor dialog to shorten subsequent calls
        CcddFieldTableEditorDialog fieldEditor = ccddMain.getFieldTableEditor();
        // editor is open, and the editor has focus
        if (undoManager == null && fieldEditor != null && fieldEditor.isFocused()) {
            // Get the undo manager and cell editor for the data field table editor
            undoManager = fieldEditor.getTable().getUndoManager();
            cellEditor = fieldEditor.getTable().getCellEditor();
        }
        // Get a reference to the script manager dialog to shorten subsequent calls
        CcddScriptManagerDialog scriptManager = ccddMain.getScriptManager();
        // open, and the editor has focus
        if (undoManager == null && scriptManager != null && scriptManager.isFocused()) {
            // Get the undo manager and cell editor for the script manager
            undoManager = ccddMain.getScriptHandler().getAssociationsTable().getUndoManager();
            cellEditor = ccddMain.getScriptHandler().getAssociationsTable().getCellEditor();
        }
    }
    // Check if a table cell is actively being edited
    if (cellEditor != null) {
        // Incorporate any cell changes and terminate editing
        cellEditor.stopCellEditing();
    } else // No table cell is being edited
    {
        // Get the current owner of the keyboard focus
        Component focusOwner = focusManager.getFocusOwner();
        // Check if the focus is in an edit panel's description or data field
        if (focusOwner != null && (focusOwner instanceof UndoableTextField || focusOwner instanceof UndoableTextArea || focusOwner instanceof UndoableCheckBox)) {
            // Check if the focus owner is a text field data field
            if (focusOwner instanceof UndoableTextField) {
                // Force the text to update so that an undo command starts with this field
                ((JTextField) focusOwner).setText(((JTextField) focusOwner).getText());
            }
            // Clear the keyboard focus so that the current data field value is registered as
            // an edit
            focusManager.clearGlobalFocusOwner();
        }
    }
    return undoManager;
}
Also used : UndoableCheckBox(CCDD.CcddUndoHandler.UndoableCheckBox) CellEditor(javax.swing.CellEditor) UndoableTextArea(CCDD.CcddUndoHandler.UndoableTextArea) UndoableTextField(CCDD.CcddUndoHandler.UndoableTextField) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) JTextField(javax.swing.JTextField)

Example 2 with UndoableCheckBox

use of CCDD.CcddUndoHandler.UndoableCheckBox in project CCDD by nasa.

the class CcddInputFieldPanelHandler method createDataFieldPanel.

/**
 ********************************************************************************************
 * Create the data fields for display in the description and data field panel
 *
 * @param undoable
 *            true if the change(s) to the data fields should be stored for possible undo/redo
 *            operations; false to not store the changes
 ********************************************************************************************
 */
protected void createDataFieldPanel(boolean undoable) {
    maxFieldWidth = 0;
    // Set the preferred size so that the layout manager uses its default sizing
    fieldPnlHndlrOwner.setPreferredSize(null);
    // Check if the data fields are already displayed
    if (fieldPnl != null) {
        // Remove the existing data fields
        inputPnl.remove(fieldPnl);
    }
    // Check if this is a data table
    if (isDataTable) {
        // Build the data field information so that only applicable fields are displayed
        dataFieldHandler.buildFieldInformation(((CcddTableEditorHandler) this).getTableInformation().getTablePath(), ((CcddTableEditorHandler) this).getTableInformation().isRootStructure(), false);
    }
    // Check if any data fields exist
    if (dataFieldHandler.getFieldInformation() != null && !dataFieldHandler.getFieldInformation().isEmpty()) {
        // Create a panel to contain the data fields. As the editor is resized the field panel
        // is resized to contain the data fields, wrapping them to new lines as needed
        fieldPnl = new JPanel(new WrapLayout(FlowLayout.LEADING));
        // Adjust the border to align the first field with the description label
        fieldPnl.setBorder(BorderFactory.createEmptyBorder(-ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), -ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0, 0));
        // Step through each data field
        for (final FieldInformation fieldInfo : dataFieldHandler.getFieldInformation()) {
            switch(fieldInfo.getInputType().getInputFormat()) {
                case PAGE_FORMAT:
                    switch(fieldInfo.getInputType()) {
                        case BREAK:
                            // Create a text field for the separator so it can be handled like
                            // other fields
                            fieldInfo.setInputFld(undoHandler.new UndoableTextField());
                            // Add a vertical separator to the field panel
                            fieldPnl.add(new JSeparator(SwingConstants.VERTICAL));
                            break;
                        case SEPARATOR:
                            // Create a text field for the separator so it can be handled like
                            // other fields
                            fieldInfo.setInputFld(undoHandler.new UndoableTextField());
                            // Add a horizontal separator to the field panel
                            fieldPnl.add(new JSeparator());
                            break;
                        default:
                            break;
                    }
                    break;
                case BOOLEAN:
                    // Create the data field check box
                    fieldInfo.setInputFld(undoHandler.new UndoableCheckBox(fieldInfo.getFieldName(), Boolean.valueOf(fieldInfo.getValue())));
                    UndoableCheckBox booleanCb = (UndoableCheckBox) fieldInfo.getInputFld();
                    booleanCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                    booleanCb.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
                    // Set the check box's name so that the undo handler can identify the check
                    // box, even if it's destroyed and recreated
                    booleanCb.setName(fieldInfo.getOwnerName() + DATA_FIELD_IDENTIFIER_SEPARATOR + fieldInfo.getFieldName());
                    // Adjust the left and right padding around the check box so that it is
                    // spaced the same as a text field data field
                    booleanCb.setBorder(BorderFactory.createEmptyBorder(0, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()));
                    // Check if a description exists for this field
                    if (!fieldInfo.getDescription().isEmpty()) {
                        // Set the description as the tool tip text for this check box
                        booleanCb.setToolTipText(CcddUtilities.wrapText(fieldInfo.getDescription(), ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
                    }
                    // And the check box to the field panel
                    fieldPnl.add(booleanCb);
                    // Store this check box's width if it is the largest data field width
                    maxFieldWidth = Math.max(maxFieldWidth, booleanCb.getPreferredSize().width);
                    break;
                default:
                    final JTextComponent inputFld;
                    // Create a panel for a single label and text field pair. This is necessary
                    // so that the two will stay together if line wrapping occurs due to a
                    // window size change
                    JPanel singleFldPnl = new JPanel(new FlowLayout(FlowLayout.LEADING, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 4));
                    singleFldPnl.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
                    // Create the data field label
                    JLabel fieldLbl = new JLabel(fieldInfo.getFieldName());
                    fieldLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                    fieldLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
                    singleFldPnl.add(fieldLbl);
                    // Check if the input type is for multi-line text
                    if (fieldInfo.getInputType().equals(InputDataType.TEXT_MULTI)) {
                        // Create the data field input field as a text area, which allows new
                        // line characters which cause the field to be displayed in multiple
                        // rows
                        fieldInfo.setInputFld(undoHandler.new UndoableTextArea(fieldInfo.getValue(), 1, fieldInfo.getSize()));
                        inputFld = (UndoableTextArea) fieldInfo.getInputFld();
                    } else // The input type is one other than for multi-line text
                    {
                        // Create the data field input field as a text field, which allows a
                        // single rows
                        fieldInfo.setInputFld(undoHandler.new UndoableTextField(fieldInfo.getValue(), fieldInfo.getSize()));
                        inputFld = (UndoableTextField) fieldInfo.getInputFld();
                    }
                    inputFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
                    inputFld.setEditable(true);
                    inputFld.setBorder(border);
                    inputFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
                    inputFld.setBackground(fieldInfo.getValue().isEmpty() && fieldInfo.isRequired() ? ModifiableColorInfo.REQUIRED_BACK.getColor() : ModifiableColorInfo.INPUT_BACK.getColor());
                    // Set the text field's name so that the undo handler can identify the text
                    // field, even if it's destroyed and recreated
                    inputFld.setName(fieldInfo.getOwnerName() + DATA_FIELD_IDENTIFIER_SEPARATOR + fieldInfo.getFieldName());
                    // Check if a description exists for this field
                    if (!fieldInfo.getDescription().isEmpty()) {
                        // Set the description as the tool tip text for this text field
                        inputFld.setToolTipText(CcddUtilities.wrapText(fieldInfo.getDescription(), ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
                    }
                    // Add the data field to the single field panel
                    singleFldPnl.add(inputFld);
                    // And the single field to the field panel
                    fieldPnl.add(singleFldPnl);
                    // Store this field's width if it is the largest data field width
                    maxFieldWidth = Math.max(maxFieldWidth, singleFldPnl.getPreferredSize().width);
                    // Create an input field verifier for the data field
                    inputFld.setInputVerifier(new InputVerifier() {

                        // Storage for the last valid value entered; used to restore the data
                        // field value if an invalid value is entered. Initialize to the value
                        // at the time the field is created
                        String lastValid = inputFld.getText();

                        /**
                         ********************************************************************
                         * Verify the contents of a the data field
                         ********************************************************************
                         */
                        @Override
                        public boolean verify(JComponent input) {
                            boolean isValid = true;
                            // Get the data field reference to shorten subsequent calls
                            JTextComponent inFld = (JTextComponent) input;
                            // Get the data field contents
                            String inputTxt = inFld.getText();
                            // trailing white space characters
                            if (fieldInfo.getInputType() != InputDataType.TEXT_WHT_SPC && fieldInfo.getInputType() != InputDataType.TEXT_MULTI_WHT_SPC) {
                                // Remove leading and trailing white space characters
                                inputTxt = inputTxt.trim();
                            }
                            // Check if the field contains an illegal character
                            if (!fieldInfo.getInputType().getInputMatch().isEmpty() && !inputTxt.isEmpty() && !inputTxt.matches(fieldInfo.getInputType().getInputMatch())) {
                                // Inform the user that the data field contents is invalid
                                new CcddDialogHandler().showMessageDialog(fieldPnlHndlrOwner, "<html><b>Invalid characters in field '</b>" + fieldInfo.getFieldName() + "<b>'; characters consistent with input type '" + fieldInfo.getInputType().getInputName() + "' expected", "Invalid " + fieldInfo.getInputType().getInputName(), JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                                // redrawn correctly
                                if (fieldPnlHndlrOwner instanceof CcddFrameHandler) {
                                    ((CcddFrameHandler) fieldPnlHndlrOwner).setControlsEnabled(false);
                                    ((CcddFrameHandler) fieldPnlHndlrOwner).setControlsEnabled(true);
                                } else if (fieldPnlHndlrOwner instanceof CcddDialogHandler) {
                                    ((CcddDialogHandler) fieldPnlHndlrOwner).setControlsEnabled(false);
                                    ((CcddDialogHandler) fieldPnlHndlrOwner).setControlsEnabled(true);
                                }
                                // Check if the data field is a text field
                                if (input instanceof UndoableTextField) {
                                    // Restore the previous value in the data field
                                    ((UndoableTextField) inFld).setText(lastValid, false);
                                } else // Check if the data field is a text area (multi-line)
                                if (input instanceof UndoableTextArea) {
                                    // Restore the previous value in the data field
                                    ((UndoableTextArea) inFld).setText(lastValid);
                                }
                                // Set the flag to indicate an invalid value was entered
                                isValid = false;
                            } else // The input is valid
                            {
                                // Store the 'cleaned' text back into the text field. For
                                // numeric types, reformat the input value
                                inFld.setText(fieldInfo.getInputType().formatInput(inputTxt));
                                fieldInfo.setValue(inFld.getText());
                                // Store the new value as the last valid value
                                lastValid = inFld.getText();
                                // Set the text field background color. If the field is empty
                                // and is flagged as required then set the background to
                                // indicate a value should be supplied
                                setFieldBackground(fieldInfo);
                            }
                            return isValid;
                        }
                    });
                    break;
            }
        }
        // Check that at least one field exists
        if (fieldPnl.getComponentCount() != 0) {
            // Add the data field panel to the dialog
            inputPnl.add(fieldPnl, gbc);
        }
    }
    // Check if this is a data table
    if (isDataTable) {
        // Build the data field information so that all fields are included
        dataFieldHandler.buildFieldInformation(((CcddTableEditorHandler) this).getTableInformation().getTablePath(), ((CcddTableEditorHandler) this).getTableInformation().isRootStructure(), true);
    }
    // Check if the data field panel change should be put in the undo/redo stack
    if (undoable) {
        // Store the field information in the undo handler in case the update needs to be
        // undone
        undoFieldPnl.addDataFieldEdit(this, dataFieldHandler.getFieldInformationCopy());
    }
    // Force the owner of the editor panel to redraw so that changes to the fields are
    // displayed and the owner's size is adjusted
    fieldPnlHndlrOwner.revalidate();
    fieldPnlHndlrOwner.repaint();
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) JTextComponent(javax.swing.text.JTextComponent) UndoableTextField(CCDD.CcddUndoHandler.UndoableTextField) InputVerifier(javax.swing.InputVerifier) WrapLayout(CCDD.CcddClassesComponent.WrapLayout) JSeparator(javax.swing.JSeparator) UndoableCheckBox(CCDD.CcddUndoHandler.UndoableCheckBox) UndoableTextArea(CCDD.CcddUndoHandler.UndoableTextArea) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 3 with UndoableCheckBox

use of CCDD.CcddUndoHandler.UndoableCheckBox in project CCDD by nasa.

the class CcddInputFieldPanelHandler method clearFieldValues.

/**
 ********************************************************************************************
 * Clear the values from all fields
 ********************************************************************************************
 */
protected void clearFieldValues() {
    // Disable automatically ending the edit sequence. This allows all of the cleared fields to
    // be grouped into a single sequence so that if undone, all fields are restored
    undoHandler.setAutoEndEditSequence(false);
    for (FieldInformation fieldInfo : dataFieldHandler.getFieldInformation()) {
        // Check if this is a boolean input (check box) data field
        if (fieldInfo.getInputType().getInputFormat() == InputTypeFormat.BOOLEAN) {
            // Set the field value to 'false'
            fieldInfo.setValue("false");
            // Set the check box
            ((UndoableCheckBox) fieldInfo.getInputFld()).setSelected(false);
        } else // Not a boolean input (check box) data field
        {
            // Get the reference to the data field
            JTextComponent inputFld = (JTextComponent) fieldInfo.getInputFld();
            // Clear the field value
            fieldInfo.setValue("");
            inputFld.setText("");
            // Set the text field background color. If the field is flagged as required then
            // set the background to indicate a value should be supplied
            setFieldBackground(fieldInfo);
        }
    }
    // Re-enable automatic edit sequence ending, then end the edit sequence to group the
    // cleared fields
    undoHandler.setAutoEndEditSequence(true);
    undoManager.endEditSequence();
}
Also used : UndoableCheckBox(CCDD.CcddUndoHandler.UndoableCheckBox) JTextComponent(javax.swing.text.JTextComponent) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 4 with UndoableCheckBox

use of CCDD.CcddUndoHandler.UndoableCheckBox 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);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) DefaultApplicationField(CCDD.CcddConstants.DefaultApplicationField) CustomSplitPane(CCDD.CcddClassesComponent.CustomSplitPane) UndoableCheckBox(CCDD.CcddUndoHandler.UndoableCheckBox) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) UndoableTreePathSelection(CCDD.CcddUndoHandler.UndoableTreePathSelection) JLabel(javax.swing.JLabel) ActionListener(java.awt.event.ActionListener) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Aggregations

UndoableCheckBox (CCDD.CcddUndoHandler.UndoableCheckBox)4 FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)3 JTextComponent (javax.swing.text.JTextComponent)3 UndoableTextArea (CCDD.CcddUndoHandler.UndoableTextArea)2 UndoableTextField (CCDD.CcddUndoHandler.UndoableTextField)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)1 CustomSplitPane (CCDD.CcddClassesComponent.CustomSplitPane)1 WrapLayout (CCDD.CcddClassesComponent.WrapLayout)1 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)1 DefaultApplicationField (CCDD.CcddConstants.DefaultApplicationField)1 UndoableTreePathSelection (CCDD.CcddUndoHandler.UndoableTreePathSelection)1 Component (java.awt.Component)1 FlowLayout (java.awt.FlowLayout)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