Search in sources :

Example 1 with DnDTabbedPane

use of CCDD.CcddClassesComponent.DnDTabbedPane in project CCDD by nasa.

the class CcddTableEditorDialog method initialize.

/**
 ********************************************************************************************
 * Create the data table editor dialog
 *
 * @param tableInformation
 *            list containing information for each table
 *
 * @param editor
 *            reference to an existing table editor
 ********************************************************************************************
 */
private void initialize(List<TableInformation> tableInformation, CcddTableEditorHandler editor) {
    // Menu ///////////////////////////////////////////////////////////////////////////////////
    // Create the data table menu bar
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    // Create the File menu and menu items
    JMenu mnFile = ccddMain.createMenu(menuBar, "File", KeyEvent.VK_F, 1, null);
    mntmOpen = ccddMain.createMenuItem(mnFile, "Edit table(s)", KeyEvent.VK_E, 1, "Open one or more data tables for editing");
    mntmOpenPrototype = ccddMain.createMenuItem(mnFile, "Edit prototype", KeyEvent.VK_T, 2, "Open the prototype for the current table");
    mnFile.addSeparator();
    mntmStore = ccddMain.createMenuItem(mnFile, "Store current", KeyEvent.VK_U, 1, "Store changes to the current editor table");
    mntmStoreAll = ccddMain.createMenuItem(mnFile, "Store all", KeyEvent.VK_L, 1, "Store the changes to all tables in this editor");
    mnFile.addSeparator();
    mntmImport = ccddMain.createMenuItem(mnFile, "Import data", KeyEvent.VK_I, 1, "Import data from a CSV, EDS XML, JSON, or XTCE XML file into the current editor table");
    JMenu mnExport = ccddMain.createSubMenu(mnFile, "Export table", KeyEvent.VK_X, 1, null);
    mntmExportCSV = ccddMain.createMenuItem(mnExport, "CSV", KeyEvent.VK_C, 1, "Export the current editor table in CSV format");
    mntmExportEDS = ccddMain.createMenuItem(mnExport, "EDS", KeyEvent.VK_E, 1, "Export the current editor table in EDS XML format");
    mntmExportJSON = ccddMain.createMenuItem(mnExport, "JSON", KeyEvent.VK_J, 1, "Export the current editor table in JSON format");
    mntmExportXTCE = ccddMain.createMenuItem(mnExport, "XTCE", KeyEvent.VK_X, 1, "Export the current editor table in XTCE XML format");
    mnFile.addSeparator();
    mntmPrint = ccddMain.createMenuItem(mnFile, "Print current", KeyEvent.VK_P, 1, "Print the current editor table information");
    mntmSearchTable = ccddMain.createMenuItem(mnFile, "Search tables", KeyEvent.VK_S, 1, "Search the project database tables");
    mnFile.addSeparator();
    mntmCloseActive = ccddMain.createMenuItem(mnFile, "Close current", KeyEvent.VK_C, 2, "Close the current editor table");
    mntmCloseAll = ccddMain.createMenuItem(mnFile, "Close all", KeyEvent.VK_A, 1, "Close all tables in this editor");
    // Create the Edit menu and menu items
    JMenu mnEdit = ccddMain.createMenu(menuBar, "Edit", KeyEvent.VK_E, 1, null);
    mntmCopy = ccddMain.createMenuItem(mnEdit, "Copy", KeyEvent.VK_C, 1, "Copy the 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();
    mntmInsertMacro = ccddMain.createMenuItem(mnEdit, "Insert macro", KeyEvent.VK_M, 1, "Insert a macro selected from the pop-up list");
    mntmShowMacros = ccddMain.createCheckBoxMenuItem(mnEdit, "Show macros", KeyEvent.VK_S, 1, "Temporarily replace macro(s) with the corresponding value(s)", false);
    mnEdit.addSeparator();
    JMenu mnClearSelected = ccddMain.createSubMenu(mnEdit, "Replace selected", KeyEvent.VK_L, 1, null);
    mntmWithBlanks = ccddMain.createMenuItem(mnClearSelected, "With blank", KeyEvent.VK_B, 1, "Replace the values in the selected cells with blanks");
    mntmWithPrototype = ccddMain.createMenuItem(mnClearSelected, "With prototype", KeyEvent.VK_P, 1, "Replace the values in the selected cells with the prototype's values");
    // 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");
    mnRow.addSeparator();
    mntmExpColArray = ccddMain.createCheckBoxMenuItem(mnRow, "Expand arrays", KeyEvent.VK_E, 1, "Expand/collapse display of array members", false);
    JMenu mnOverwrite = ccddMain.createSubMenu(mnRow, "Array overwrite", KeyEvent.VK_O, 1, null);
    mntmOverwriteAll = ccddMain.createRadioButtonMenuItem(mnOverwrite, "Overwrite all", KeyEvent.VK_A, 1, "Copy array definition value change to all members", true);
    mntmOverwriteEmpty = ccddMain.createRadioButtonMenuItem(mnOverwrite, "Overwrite empty", KeyEvent.VK_E, 3, "Copy array definition value change only to empty members", false);
    mntmOverwriteNone = ccddMain.createRadioButtonMenuItem(mnOverwrite, "Overwrite none", KeyEvent.VK_N, 1, "Do not copy definition value change to members", false);
    ButtonGroup rbtnGroup = new ButtonGroup();
    rbtnGroup.add(mntmOverwriteAll);
    rbtnGroup.add(mntmOverwriteEmpty);
    rbtnGroup.add(mntmOverwriteNone);
    // Create the Column menu and menu items
    JMenu mnColumn = ccddMain.createMenu(menuBar, "Column", KeyEvent.VK_M, 1, null);
    mntmMoveLeft = ccddMain.createMenuItem(mnColumn, "Move left", KeyEvent.VK_L, 1, "Move the currently selected column(s) left one column");
    mntmMoveRight = ccddMain.createMenuItem(mnColumn, "Move right", KeyEvent.VK_R, 1, "Move the currently selected column(s) right one column");
    mntmResetOrder = ccddMain.createMenuItem(mnColumn, "Reset order", KeyEvent.VK_O, 1, "Reset the column order to the default");
    // 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");
    // Add a listener for the Open Table command
    mntmOpen.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Open a table in this editor dialog
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // Open a table and add it to the tabbed pane. This calls TableSelectDialog, but
            // doesn't spawn a separate editor
            new CcddTableManagerDialog(ccddMain, ManagerDialogType.EDIT, CcddTableEditorDialog.this);
        }
    });
    // Add a listener for the Open Prototype Table command
    mntmOpenPrototype.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Open the currently displayed table's prototype table in this editor dialog
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // Open the active table's prototype table
            dbTable.loadTableDataInBackground(activeEditor.getTableInformation().getPrototypeName(), CcddTableEditorDialog.this);
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Import command
    mntmImport.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Import a file into the table
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            fileIOHandler.importSelectedFileIntoTable(activeEditor);
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Export - CSV command
    mntmExportCSV.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Export the table to a file in CSV format
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            new CcddTableManagerDialog(ccddMain, ManagerDialogType.EXPORT_CSV, CcddTableEditorDialog.this);
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Export - EDS command
    mntmExportEDS.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Export the table to a file in EDS XML format
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            new CcddTableManagerDialog(ccddMain, ManagerDialogType.EXPORT_EDS, CcddTableEditorDialog.this);
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Export - JSON command
    mntmExportJSON.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Export the table to a file in JSON format
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            new CcddTableManagerDialog(ccddMain, ManagerDialogType.EXPORT_JSON, CcddTableEditorDialog.this);
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Export - XTCE command
    mntmExportXTCE.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Export the table to a file in XTCE XML format
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            new CcddTableManagerDialog(ccddMain, ManagerDialogType.EXPORT_XTCE, CcddTableEditorDialog.this);
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Print command
    mntmPrint.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Output the table to the printer
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // Print the table
            activeEditor.getTable().printTable("Table: " + activeEditor.getOwnerName(), activeEditor.getFieldHandler(), CcddTableEditorDialog.this, PageFormat.LANDSCAPE);
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Search tables menu item
    mntmSearchTable.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Display the search tables dialog
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            ccddMain.showSearchDialog(SearchDialogType.TABLES, CcddTableEditorDialog.this);
        }
    });
    // 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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // 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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // 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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Clear selected | With blanks command
    mntmWithBlanks.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Erase the data in the selected cell(s)
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // Check if there are any rows to clear
            if (activeEditor.getTableModel().getRowCount() != 0) {
                // Clear the selected cell(s)
                activeEditor.getTable().deleteCell(false);
            }
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Clear selected | With prototype command
    mntmWithPrototype.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Erase the data in the selected cell(s) and the corresponding entry(s) in the custom
         * values table
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // Check if there are any rows to clear
            if (activeEditor.getTableModel().getRowCount() != 0) {
                // Clear the selected cell(s)
                activeEditor.getTable().deleteCell(true);
            }
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the insert macro command
    mntmInsertMacro.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Insert the macro chosen from the pop-up list into the current cell
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // and end values are valid
            if (getTable().getLastSelectionStart() != -1 && getTable().getLastSelectionEnd() != -1) {
                // Initiate editing in the selected cell
                getTable().editCellAt(getTable().getSelectedRow(), getTable().getSelectedColumn());
                // Get the cell's component
                final Component comp = getTable().getEditorComponent();
                // Check if the cell represents a text component (text area, text field, etc.)
                if (comp instanceof JTextComponent) {
                    // Set the focus to the cell
                    comp.requestFocusInWindow();
                    // Execute the event after any pending events
                    EventQueue.invokeLater(new Runnable() {

                        /**
                         ********************************************************************
                         * Set the selected text start and end positions
                         ********************************************************************
                         */
                        @Override
                        public void run() {
                            // Set the text selected text to the last known positions
                            ((JTextComponent) comp).setSelectionStart(getTable().getLastSelectionStart());
                            ((JTextComponent) comp).setSelectionEnd(getTable().getLastSelectionEnd());
                        }
                    });
                }
                // Send a Ctrl-M key press to display the insert macro pop-up
                controlKeyAction(KeyEvent.VK_M);
            }
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Show macros command
    mntmShowMacros.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Temporarily replace any macros with the corresponding values
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // If the check box is selected then disable the controls that are not allowed
            // while macros are shown, else enable the controls
            setControlsEnabled(!mntmShowMacros.isSelected());
            // Step through each table opened in the editor dialog
            for (CcddTableEditorHandler editor : tableEditors) {
                // Expand all macros in the table if the check box is selected and disable
                // editing for the table, else restore all macros and enable editing
                editor.expandMacros(mntmShowMacros.isSelected(), false);
                editor.setTableEditEnable(!mntmShowMacros.isSelected());
            }
            // Redraw the visible table
            activeEditor.getTable().repaint();
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // 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) {
            // action
            if (isTablesChanged() && new CcddDialogHandler().showMessageDialog(CcddTableEditorDialog.this, "<html><b>Store changes for all?", "Store Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                // Update the database for every table that has changes
                storeAllChanges();
            }
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Reset Order command
    mntmResetOrder.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Reset the column order to the default
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            activeEditor.resetColumnOrder();
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add a listener for the Manage Fields command
    mntmManageFields.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Manage the data fields
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // Create the field editor dialog showing the fields for this table
            new CcddFieldEditorDialog(ccddMain, activeEditor, activeEditor.getTableInformation().getTablePath(), (activeEditor.getTableTypeDefinition().isStructure() && !activeEditor.getTableInformation().getTablePath().contains(",")), MIN_WINDOW_WIDTH);
            // Enable/disable the Clear values command depending on if any data fields remain
            mntmClearValues.setEnabled(!activeEditor.getFieldHandler().getFieldInformation().isEmpty());
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // 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 from the table
                activeEditor.getInputFieldPanelHandler().clearFieldValues();
            }
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Create the lower (button) panel
    JPanel buttonPnl = new JPanel();
    // Define the buttons for the lower panel: New button
    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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the insert listener to the Insert Row button and menu command
    btnInsertRow.addActionListener(insertAction);
    mntmInsertRow.addActionListener(insertAction);
    // Delete button
    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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the delete listener to the Delete Row button and menu command
    btnDeleteRow.addActionListener(deleteAction);
    mntmDeleteRow.addActionListener(deleteAction);
    // Create a listener for the Expand arrays command
    mntmExpColArray.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Expand or collapse the array members
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // Toggle between showing and hiding the array member rows
            activeEditor.showHideArrayMembers();
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Move Up button
    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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the move up listener to the Move Up button and menu command
    btnMoveUp.addActionListener(moveUpAction);
    mntmMoveUp.addActionListener(moveUpAction);
    // Move Down button
    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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the move down listener to the Move Down button and menu command
    btnMoveDown.addActionListener(moveDownAction);
    mntmMoveDown.addActionListener(moveDownAction);
    // Move Left button
    btnMoveLeft = CcddButtonPanelHandler.createButton("Left", LEFT_ICON, KeyEvent.VK_L, "Move the selected column(s) left");
    // Create a listener for the Move Left command
    ActionListener moveLeftAction = new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Move the selected column(s) left in the table
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            activeEditor.getTable().moveColumnLeft();
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the move left listener to the Move Left button and menu command
    btnMoveLeft.addActionListener(moveLeftAction);
    mntmMoveLeft.addActionListener(moveLeftAction);
    // Move Right button
    btnMoveRight = CcddButtonPanelHandler.createButton("Right", RIGHT_ICON, KeyEvent.VK_R, "Move the selected column(s) right");
    // Create a listener for the Move Right command
    ActionListener moveRightAction = new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Move the selected column(s) right in the table
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            activeEditor.getTable().moveColumnRight();
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the move right listener to the Move Right button and menu command
    btnMoveRight.addActionListener(moveRightAction);
    mntmMoveRight.addActionListener(moveRightAction);
    // Undo button
    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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the undo listener to the Undo button and menu command
    mntmUndo.addActionListener(undoAction);
    btnUndo.addActionListener(undoAction);
    // Redo button
    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 reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the redo listener to the Redo button and menu command
    mntmRedo.addActionListener(redoAction);
    btnRedo.addActionListener(redoAction);
    // Store button
    btnStore = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the table 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) {
            // required columns are empty, and the user confirms the action
            if (activeEditor.isTableChanged() && !activeEditor.checkForMissingColumns() && new CcddDialogHandler().showMessageDialog(CcddTableEditorDialog.this, "<html><b>Store changes in project database?", "Store Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                // Store the changes for the currently displayed editor in the database
                storeChanges(activeEditor);
            }
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the store listener to the Store button and menu command
    btnStore.addActionListener(storeAction);
    mntmStore.addActionListener(storeAction);
    // Close button
    btnCloseActive = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the table editor");
    // Add a listener for the Close active table command
    ActionListener closeAction = new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Close the active editor
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            // confirm discarding the changes
            if (activeEditor.getTable().isLastCellValid() && (!activeEditor.isTableChanged() || new CcddDialogHandler().showMessageDialog(CcddTableEditorDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON)) {
                // Close the active table. If this is the only table in the editor then close
                // the editor
                closeTableEditor(activeEditor.getOwnerName());
            }
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    };
    // Add the close listener to the Close button and menu command
    btnCloseActive.addActionListener(closeAction);
    mntmCloseActive.addActionListener(closeAction);
    // Create a listener for the Close All menu command
    mntmCloseAll.addActionListener(new ValidateCellActionListener() {

        /**
         ************************************************************************************
         * Close the table editor
         ************************************************************************************
         */
        @Override
        protected void performAction(ActionEvent ae) {
            windowCloseButtonAction();
        }

        /**
         ************************************************************************************
         * Get the reference to the currently displayed table
         ************************************************************************************
         */
        @Override
        protected CcddJTableHandler getTable() {
            return activeEditor.getTable();
        }
    });
    // Add buttons in the order in which they'll appear (left to right, top to bottom)
    buttonPnl.add(btnInsertRow);
    buttonPnl.add(btnMoveUp);
    buttonPnl.add(btnMoveLeft);
    buttonPnl.add(btnUndo);
    buttonPnl.add(btnStore);
    buttonPnl.add(btnDeleteRow);
    buttonPnl.add(btnMoveDown);
    buttonPnl.add(btnMoveRight);
    buttonPnl.add(btnRedo);
    buttonPnl.add(btnCloseActive);
    // 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, CcddTableEditorDialog.class, true) {

        /**
         ************************************************************************************
         * Update the table editor list order following a tab move
         ************************************************************************************
         */
        @Override
        protected Object tabMoveCleanup(int oldTabIndex, int newTabIndex, Object tabContents) {
            CcddTableEditorHandler editor = (CcddTableEditorHandler) tabContents;
            // Check if the tab originated in the editor dialog
            if (oldTabIndex != -1) {
                // Get the reference to the moved tab's original location in the list
                editor = tableEditors.get(oldTabIndex);
                // Remove the table editor reference associated with the tab
                tableEditors.remove(oldTabIndex);
            } else // The tab originated in another editor dialog
            {
                // Bring the editor dialog to the foreground
                CcddTableEditorDialog.this.toFront();
            }
            // Check if the tab is to be placed within this editor
            if (newTabIndex != -1) {
                // Update the editor's reference to the dialog that owns it to this editor
                // dialog
                editor.setEditorDialog(CcddTableEditorDialog.this);
                // Add the table editor reference at the specified location
                tableEditors.add(newTabIndex - (oldTabIndex != -1 && newTabIndex > oldTabIndex ? 1 : 0), editor);
            }
            // Check if the last editor was removed from the dialog
            if (tableEditors.isEmpty()) {
                // Close the editor dialog
                CcddTableEditorDialog.this.closeFrame();
            } else // An editor remains in the dialog
            {
                // Update the active tab pointer
                activeEditor = tableEditors.get(tabbedPane.getSelectedIndex());
            }
            return editor;
        }

        /**
         ************************************************************************************
         * Move the specified tab's table to a new table editor dialog
         ************************************************************************************
         */
        @Override
        protected void spawnContainer(int tabIndex, Object tabContents) {
            // Create a new table editor dialog and place the editor from the other dialog into
            // it
            ccddMain.getTableEditorDialogs().add(new CcddTableEditorDialog(ccddMain, (CcddTableEditorHandler) tabContents));
        }
    };
    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 the tab index is within bounds
            if (tabbedPane.getSelectedIndex() >= 0 && tabbedPane.getSelectedIndex() < tableEditors.size()) {
                // Set the active editor to the selected tab
                activeEditor = tableEditors.get(tabbedPane.getSelectedIndex());
                // Change the dialog's title to the active table's name
                (CcddTableEditorDialog.this).setTitle(activeEditor.getOwnerName());
                // Update the expand/collapse arrays check box
                updateExpandArrayCheckBox();
                // Check if the Show macros command is not in effect
                if (!mntmShowMacros.isSelected()) {
                    // Update the editor controls state
                    setControlsEnabled(true);
                }
            }
        }
    });
    // Add each table as a tab in the editor dialog tabbed pane
    addTablePanes(tableInformation, editor);
    // Set the first tab as the active editor
    activeEditor = tableEditors.get(0);
    // Display the table editor dialog
    createFrame(ccddMain.getMainFrame(), tabbedPane, buttonPnl, null, activeEditor.getOwnerName(), null);
    // Enable the editor controls
    setControlsEnabled(true);
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JTextComponent(javax.swing.text.JTextComponent) DnDTabbedPane(CCDD.CcddClassesComponent.DnDTabbedPane) ActionListener(java.awt.event.ActionListener) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ButtonGroup(javax.swing.ButtonGroup) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) ChangeListener(javax.swing.event.ChangeListener) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 2 with DnDTabbedPane

use of CCDD.CcddClassesComponent.DnDTabbedPane in project CCDD by nasa.

the class CcddRateParameterDialog method initialize.

/**
 ********************************************************************************************
 * Create the rate parameter assignment dialog
 ********************************************************************************************
 */
private void initialize() {
    // Set the initial layout manager characteristics
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2), 0, 0);
    // Create borders for the input fields
    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();
    // Create a panel to contain the dialog components
    JPanel dialogPnl = new JPanel(new GridBagLayout());
    dialogPnl.setBorder(emptyBorder);
    // Create the maximum seconds per message label
    JLabel maxSecPerMsgLbl = new JLabel("Maximum seconds per message");
    maxSecPerMsgLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    dialogPnl.add(maxSecPerMsgLbl, gbc);
    // Create the maximum seconds per message input field
    maxSecPerMsgFld = new JTextField(String.valueOf(rateHandler.getMaxSecondsPerMsg()), 7);
    maxSecPerMsgFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    maxSecPerMsgFld.setEditable(true);
    maxSecPerMsgFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    maxSecPerMsgFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
    maxSecPerMsgFld.setBorder(border);
    // Set the field's input verifier
    maxSecPerMsgFld.setInputVerifier(new InputVerifier() {

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

        /**
         ************************************************************************************
         * Verify the contents of the input field
         ************************************************************************************
         */
        @Override
        public boolean verify(JComponent input) {
            // Verify the field contents
            InputVerificationResult doneIt = verifyInputField((JTextField) input, lastValid);
            // Update the last valid value
            lastValid = doneIt.getLastValid();
            return doneIt.isValid();
        }
    });
    gbc.gridx++;
    dialogPnl.add(maxSecPerMsgFld, gbc);
    // Create the maximum messages per second label
    JLabel maxMsgsPerSecLbl = new JLabel("Maximum messages per second");
    maxMsgsPerSecLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    gbc.gridx = 0;
    gbc.gridy++;
    dialogPnl.add(maxMsgsPerSecLbl, gbc);
    // Create the maximum messages per second input field
    maxMsgsPerSecFld = new JTextField(String.valueOf(rateHandler.getMaxMsgsPerSecond()), 7);
    maxMsgsPerSecFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    maxMsgsPerSecFld.setEditable(true);
    maxMsgsPerSecFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    maxMsgsPerSecFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
    maxMsgsPerSecFld.setBorder(border);
    // Set the field's input verifier
    maxMsgsPerSecFld.setInputVerifier(new InputVerifier() {

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

        /**
         ************************************************************************************
         * Verify the contents of the input field
         ************************************************************************************
         */
        @Override
        public boolean verify(JComponent input) {
            // Verify the field contents
            InputVerificationResult doneIt = verifyInputField((JTextField) input, lastValid);
            // Update the last valid value
            lastValid = doneIt.getLastValid();
            return doneIt.isValid();
        }
    });
    gbc.gridx++;
    dialogPnl.add(maxMsgsPerSecFld, gbc);
    // Get the rate information for all data streams
    List<RateInformation> rateInformation = rateHandler.getRateInformation();
    // Create text fields for the stream-specific rate parameters
    streamNameFld = new JTextField[rateInformation.size()];
    maxMsgsPerCycleFld = new JTextField[rateInformation.size()];
    maxBytesPerSecFld = new JTextField[rateInformation.size()];
    availRatesFld = new JTextArea[rateInformation.size()];
    // Create a tabbed pane to contain the rate parameters that are stream-specific
    tabbedPane = new DnDTabbedPane(SwingConstants.TOP) {

        /**
         ************************************************************************************
         * Update the rate arrays order following a tab move
         ************************************************************************************
         */
        @Override
        protected Object tabMoveCleanup(int oldTabIndex, int newTabIndex, Object tabContents) {
            // Adjust the new tab index if moving the tab to a higher index
            newTabIndex -= newTabIndex > oldTabIndex ? 1 : 0;
            // Re-order the rate information based on the new tab order
            RateInformation[] rateInfoArray = rateHandler.getRateInformation().toArray(new RateInformation[0]);
            rateInfoArray = (RateInformation[]) CcddUtilities.moveArrayMember(rateInfoArray, oldTabIndex, newTabIndex);
            List<RateInformation> rateInfoList = new ArrayList<RateInformation>(rateInfoArray.length);
            rateInfoList.addAll(Arrays.asList(rateInfoArray));
            rateHandler.setRateInformation(rateInfoList);
            // Re-order the fields based on the new tab order
            maxMsgsPerCycleFld = (JTextField[]) CcddUtilities.moveArrayMember(maxMsgsPerCycleFld, oldTabIndex, newTabIndex);
            maxBytesPerSecFld = (JTextField[]) CcddUtilities.moveArrayMember(maxBytesPerSecFld, oldTabIndex, newTabIndex);
            streamNameFld = (JTextField[]) CcddUtilities.moveArrayMember(streamNameFld, oldTabIndex, newTabIndex);
            availRatesFld = (JTextArea[]) CcddUtilities.moveArrayMember(availRatesFld, oldTabIndex, newTabIndex);
            return null;
        }
    };
    tabbedPane.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    // Create a tab for each stream
    addStreamTabs(rateInformation);
    gbc.insets.left = 0;
    gbc.insets.right = 0;
    gbc.insets.bottom = 0;
    gbc.gridwidth = 2;
    gbc.gridx = 0;
    gbc.gridy++;
    dialogPnl.add(tabbedPane, gbc);
    // Create a panel for the uneven check box
    JPanel unevenPnl = new JPanel(new FlowLayout(FlowLayout.LEFT, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, 0));
    unevenPnl.setBorder(emptyBorder);
    // Create a check box for including/excluding unevenly time-spaced sample rates
    unevenCb = new JCheckBox("Include unevenly time-spaced rates");
    unevenCb.setBorder(emptyBorder);
    unevenCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    unevenCb.setSelected(rateHandler.isIncludeUneven() ? true : false);
    unevenCb.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Handle a change in the include uneven rates check box status
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            updateAvailableRates();
        }
    });
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
    gbc.gridwidth = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy++;
    unevenPnl.add(unevenCb);
    dialogPnl.add(unevenPnl, gbc);
    // Listen for tab selection changes
    tabbedPane.addChangeListener(new ChangeListener() {

        /**
         ************************************************************************************
         * Update the available rates using the values in the selected tab
         ************************************************************************************
         */
        @Override
        public void stateChanged(ChangeEvent ce) {
            // Display the available rates for the currently selected rate column
            updateAvailableRates();
        }
    });
    // Display the available rates for the initially selected rate column
    updateAvailableRates();
    // Get the user's input
    if (showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, "Rate Parameters", DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
        // Convert the common rate parameters to integers
        int maxSecPerMsg = Integer.valueOf(maxSecPerMsgFld.getText());
        int maxMsgsPerSec = Integer.valueOf(maxMsgsPerSecFld.getText());
        // Create storage for the stream-specific parameters
        String[] streamNames = new String[tabbedPane.getTabCount()];
        int[] maxMsgsPerCycle = new int[tabbedPane.getTabCount()];
        int[] maxBytesPerSec = new int[tabbedPane.getTabCount()];
        // Step through each stream
        for (int index = 0; index < tabbedPane.getTabCount(); index++) {
            // Store the stream name, convert the rate parameters to numeric form, and
            // calculate the available rates
            streamNames[index] = streamNameFld[index].getText();
            maxMsgsPerCycle[index] = Integer.valueOf(maxMsgsPerCycleFld[index].getText());
            maxBytesPerSec[index] = Integer.valueOf(maxBytesPerSecFld[index].getText());
        }
        // Check if any rate parameter changed
        if (isRateChanges(maxSecPerMsg, maxMsgsPerSec, streamNames, maxMsgsPerCycle, maxBytesPerSec, unevenCb.isSelected())) {
            // Store the rate parameters and update the sample rates
            rateHandler.setRateParameters(maxSecPerMsg, maxMsgsPerSec, streamNames, maxMsgsPerCycle, maxBytesPerSec, unevenCb.isSelected(), CcddRateParameterDialog.this);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) RateInformation(CCDD.CcddClassesDataTable.RateInformation) JTextField(javax.swing.JTextField) ArrayList(java.util.ArrayList) List(java.util.List) ChangeListener(javax.swing.event.ChangeListener) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) InputVerifier(javax.swing.InputVerifier) JCheckBox(javax.swing.JCheckBox) DnDTabbedPane(CCDD.CcddClassesComponent.DnDTabbedPane) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent)

Example 3 with DnDTabbedPane

use of CCDD.CcddClassesComponent.DnDTabbedPane in project CCDD by nasa.

the class CcddTelemetrySchedulerDialog method initialize.

/**
 ********************************************************************************************
 * Create the telemetry scheduler 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 telemetry scheduler dialog in the background
    CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {

        // Create a button panel
        JPanel buttonPnl = new JPanel();

        /**
         ************************************************************************************
         * Build the telemetry scheduler dialog
         ************************************************************************************
         */
        @Override
        protected void execute() {
            // Create a tree containing all of the variables. This is used for determining
            // bit-packing and variable relative position
            allVariableTree = new CcddTableTreeHandler(ccddMain, TableTreeType.INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES, ccddMain.getMainFrame());
            // Expand the tree so that all nodes are 'visible'
            allVariableTree.setTreeExpansion(true);
            allVariableTreePaths = new ArrayList<String>();
            // Step through all of the nodes in the variable tree
            for (Enumeration<?> element = allVariableTree.getRootNode().preorderEnumeration(); element.hasMoreElements(); ) {
                // Convert the variable path to a string and add it to the list
                allVariableTreePaths.add(allVariableTree.getFullVariablePath(((ToolTipTreeNode) element.nextElement()).getPath()));
            }
            // Load the stored telemetry scheduler data from the project database
            schedulerDb.loadStoredData();
            // Auto-fill button
            btnAutoFill = CcddButtonPanelHandler.createButton("Auto-fill", AUTO_CREATE_ICON, KeyEvent.VK_F, "Auto-fill the message table with the variables");
            // Create a listener for the Auto-fill button
            btnAutoFill.addActionListener(new ValidateCellActionListener() {

                /**
                 ****************************************************************************
                 * Auto-fill the variables into the telemetry scheduler for the currently
                 * selected data stream
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    // Run auto-fill
                    activeSchHandler.autoFill();
                }

                /**
                 ****************************************************************************
                 * Get the reference to the currently displayed table
                 ****************************************************************************
                 */
                @Override
                protected CcddJTableHandler getTable() {
                    return activeSchHandler.getSchedulerEditor().getTable();
                }
            });
            // Clear Rate button
            btnClearRate = CcddButtonPanelHandler.createButton("Clear Rate", UNDO_ICON, KeyEvent.VK_R, "Remove the variables of the currently selected rate from all messages");
            // Add a listener for the Clear Rate button
            btnClearRate.addActionListener(new ValidateCellActionListener() {

                /**
                 ****************************************************************************
                 * Remove the variables of the currently selected rate from all messages in the
                 * currently selected data stream
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    activeSchHandler.getSchedulerEditor().clearVariablesFromMessages(activeSchHandler.getSchedulerInput().getSelectedRate());
                }

                /**
                 ****************************************************************************
                 * Get the reference to the currently displayed table
                 ****************************************************************************
                 */
                @Override
                protected CcddJTableHandler getTable() {
                    return activeSchHandler.getSchedulerEditor().getTable();
                }
            });
            // Clear Msgs button
            btnClear = CcddButtonPanelHandler.createButton("Clear Msgs", UNDO_ICON, KeyEvent.VK_R, "Remove the variables from all messages");
            // Add a listener for the Clear Msgs button
            btnClear.addActionListener(new ValidateCellActionListener() {

                /**
                 ****************************************************************************
                 * Remove the variables from all messages in the currently selected data stream
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    activeSchHandler.getSchedulerEditor().clearVariablesFromMessages(null);
                }

                /**
                 ****************************************************************************
                 * Get the reference to the currently displayed table
                 ****************************************************************************
                 */
                @Override
                protected CcddJTableHandler getTable() {
                    return activeSchHandler.getSchedulerEditor().getTable();
                }
            });
            // Add Sub-msg button
            btnAddSubMessage = CcddButtonPanelHandler.createButton("Add Sub-msg", INSERT_ICON, KeyEvent.VK_A, "Add a sub-message to the currently selected message");
            // Create a listener for the Add Sub-msg button
            btnAddSubMessage.addActionListener(new ValidateCellActionListener() {

                /**
                 ****************************************************************************
                 * Add a sub-message to the current message
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    activeSchHandler.getSchedulerEditor().addSubMessage();
                }

                /**
                 ****************************************************************************
                 * Get the reference to the currently displayed table
                 ****************************************************************************
                 */
                @Override
                protected CcddJTableHandler getTable() {
                    return activeSchHandler.getSchedulerEditor().getTable();
                }
            });
            // Del Sub-msg button
            btnDeleteSubMessage = CcddButtonPanelHandler.createButton("Del Sub-msg", DELETE_ICON, KeyEvent.VK_D, "Delete the currently selected sub-message");
            // Create a listener for the Del Sub-msg button
            btnDeleteSubMessage.addActionListener(new ValidateCellActionListener() {

                /**
                 ****************************************************************************
                 * Delete the current sub-message
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    activeSchHandler.getSchedulerEditor().deleteSubMessage();
                }

                /**
                 ****************************************************************************
                 * Get the reference to the currently displayed table
                 ****************************************************************************
                 */
                @Override
                protected CcddJTableHandler getTable() {
                    return activeSchHandler.getSchedulerEditor().getTable();
                }
            });
            // Assign message names and IDs button
            btnAssign = CcddButtonPanelHandler.createButton("Assign Msgs", AUTO_CREATE_ICON, KeyEvent.VK_M, "Automatically assign message names and/or IDs to the messages and sub-messages");
            // Add a listener for the Assign Msgs button
            btnAssign.addActionListener(new ValidateCellActionListener() {

                /**
                 ****************************************************************************
                 * Automatically assign names and/or IDs to the telemetry messages and
                 * sub-messages
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    new CcddAssignMessageIDDialog(ccddMain, activeSchHandler.getCurrentMessages(), CcddTelemetrySchedulerDialog.this);
                }

                /**
                 ****************************************************************************
                 * Get the reference to the currently displayed table
                 ****************************************************************************
                 */
                @Override
                protected CcddJTableHandler getTable() {
                    return activeSchHandler.getSchedulerEditor().getTable();
                }
            });
            // Store button
            btnStore = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the message updates in the project database");
            // Add a listener for the Store button
            btnStore.addActionListener(new ValidateCellActionListener() {

                /**
                 ****************************************************************************
                 * Store the data from the various data streams into the database
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    // storing the changes
                    if (isChanges() && new CcddDialogHandler().showMessageDialog(CcddTelemetrySchedulerDialog.this, "<html><b>Store changes?", "Store Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                        // Store the messages in the project database
                        storeData();
                    }
                }

                /**
                 ****************************************************************************
                 * Get the reference to the currently displayed table
                 ****************************************************************************
                 */
                @Override
                protected CcddJTableHandler getTable() {
                    return activeSchHandler.getSchedulerEditor().getTable();
                }
            });
            // Create a button to close the dialog
            btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the telemetry scheduler");
            // Add a listener for the Close button
            btnClose.addActionListener(new ValidateCellActionListener() {

                /**
                 ****************************************************************************
                 * Close the telemetry scheduler dialog
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    windowCloseButtonAction();
                }

                /**
                 ****************************************************************************
                 * Get the reference to the currently displayed table
                 ****************************************************************************
                 */
                @Override
                protected CcddJTableHandler getTable() {
                    return activeSchHandler.getSchedulerEditor().getTable();
                }
            });
            // Add buttons in the order in which they'll appear (left to right, top to bottom)
            buttonPnl.add(btnAutoFill);
            buttonPnl.add(btnClearRate);
            buttonPnl.add(btnAddSubMessage);
            buttonPnl.add(btnStore);
            buttonPnl.add(btnAssign);
            buttonPnl.add(btnClear);
            buttonPnl.add(btnDeleteSubMessage);
            buttonPnl.add(btnClose);
            // Create two rows of buttons
            setButtonRows(2);
            // Create a tabbed pane in which to place the scheduler handlers
            tabbedPane = new DnDTabbedPane(SwingConstants.TOP) {

                /**
                 ****************************************************************************
                 * Update the scheduler list order following a tab move
                 ****************************************************************************
                 */
                @Override
                protected Object tabMoveCleanup(int oldTabIndex, int newTabIndex, Object tabContents) {
                    // Adjust the new tab index if moving the tab to a higher index
                    newTabIndex -= newTabIndex > oldTabIndex ? 1 : 0;
                    // Re-order the rate information based on the new tab order
                    // Re-order the rate information based on the new tab order
                    RateInformation[] rateInfoArray = rateHandler.getRateInformation().toArray(new RateInformation[0]);
                    rateInfoArray = (RateInformation[]) CcddUtilities.moveArrayMember(rateInfoArray, oldTabIndex, newTabIndex);
                    List<RateInformation> rateInfoList = new ArrayList<RateInformation>(rateInfoArray.length);
                    rateInfoList.addAll(Arrays.asList(rateInfoArray));
                    rateHandler.setRateInformation(rateInfoList);
                    // Get the reference to the moved tab's original location in the list
                    CcddSchedulerHandler editor = schHandlers.get(oldTabIndex);
                    // Remove the tab
                    schHandlers.remove(oldTabIndex);
                    // Add the tab at its new location
                    schHandlers.add(newTabIndex, editor);
                    // Update the active tab pointer to the moved tab
                    activeSchHandler = schHandlers.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) {
                    // Set the active editor to the one indicated by the currently selected tab
                    activeSchHandler = schHandlers.get(tabbedPane.getSelectedIndex());
                }
            });
            // Add the scheduler handlers to the tabbed pane
            addDataStreams();
            // Set the first tab as the active editor
            activeSchHandler = schHandlers.get(0);
        }

        /**
         ************************************************************************************
         * Telemetry scheduler dialog creation complete
         ************************************************************************************
         */
        @Override
        protected void complete() {
            // Display the telemetry scheduler dialog
            showOptionsDialog(ccddMain.getMainFrame(), tabbedPane, buttonPnl, btnClose, "Telemetry Scheduler", true);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) Enumeration(java.util.Enumeration) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) RateInformation(CCDD.CcddClassesDataTable.RateInformation) DnDTabbedPane(CCDD.CcddClassesComponent.DnDTabbedPane) ChangeEvent(javax.swing.event.ChangeEvent) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) ChangeListener(javax.swing.event.ChangeListener) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand)

Example 4 with DnDTabbedPane

use of CCDD.CcddClassesComponent.DnDTabbedPane in project CCDD by nasa.

the class CcddPreferencesDialog method initialize.

/**
 ********************************************************************************************
 * Create the preferences dialog
 ********************************************************************************************
 */
private void initialize() {
    maxScrollPaneHeight = 0;
    // Create an empty border for use with the dialog components
    emptyBorder = BorderFactory.createEmptyBorder();
    // Create a tabbed pane
    tabbedPane = new DnDTabbedPane(SwingConstants.TOP);
    tabbedPane.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    // Add the tabs to the tabbed pane
    addLafTab();
    addFontTab();
    addColorTab();
    addSizeTab();
    addSpacingTab();
    addPathTab();
    addOtherTab();
    // Create a panel for the preference dialog buttons
    JPanel buttonPnl = new JPanel();
    // Update button
    final JButton btnUpdateAll = CcddButtonPanelHandler.createButton("Update", STORE_ICON, KeyEvent.VK_U, "Update the program preference values");
    // Add a listener for the Update button
    btnUpdateAll.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Update the program preference values
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            int index = 0;
            // Base the action on the name of the tab selected
            switch(tabbedPane.getTitleAt(tabbedPane.getSelectedIndex())) {
                case LAF:
                case FONT:
                case COLOR:
                    // preference value
                    break;
                case SIZE:
                    // size
                    for (ModifiableSizeInfo modSize : ModifiableSizeInfo.values()) {
                        // Get the current value from the size text field
                        int currentValue = Integer.valueOf(sizeFld[index].getText());
                        // Check if the size has changed
                        if (modSize.getSize() != currentValue) {
                            // Update the size to the new value
                            modSize.setSize(currentValue, ccddMain.getProgPrefs());
                        }
                        index++;
                    }
                    break;
                case SPACING:
                    // modifiable spacing
                    for (ModifiableSpacingInfo modSpacing : ModifiableSpacingInfo.values()) {
                        // Get the current value from the spacing text field
                        int currentValue = Integer.valueOf(spacingFld[index].getText());
                        // Check if the spacing has changed
                        if (modSpacing.getSpacing() != currentValue) {
                            // Update the spacing to the new value
                            modSpacing.setSpacing(currentValue, ccddMain.getProgPrefs());
                        }
                        index++;
                    }
                    break;
                case PATH:
                    // Update the program path preference. Step through each modifiable path
                    for (ModifiablePathInfo modPath : ModifiablePathInfo.values()) {
                        // Get the current path from the path text field
                        String currentPath = pathFld[index].getText().trim();
                        // Check if the path has changed
                        if (!modPath.getPath().equals(currentPath)) {
                            // Store the path in the program preferences backing store
                            CcddFileIOHandler.storePath(ccddMain, currentPath, false, modPath);
                        }
                        index++;
                    }
                    break;
                case OTHER:
                    // setting
                    for (ModifiableOtherSettingInfo modOther : ModifiableOtherSettingInfo.values()) {
                        // Get the current setting value from the other setting text field
                        String currentValue = otherFld[index].getText().trim();
                        // Check if the setting value has changed
                        if (!modOther.getValue().equals(currentValue)) {
                            // Update the other setting to the new value
                            modOther.setValue(currentValue, ccddMain.getProgPrefs());
                        }
                        index++;
                    }
                    break;
            }
        }
    });
    // Close button
    JButton btnCloseDlg = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the program preferences dialog");
    // Add a listener for the Close button
    btnCloseDlg.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Close the program preferences dialog
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            // Close the dialog
            closeDialog();
        }
    });
    // Listen for tab selection changes
    tabbedPane.addChangeListener(new ChangeListener() {

        /**
         ************************************************************************************
         * Handle a tab selection change
         ************************************************************************************
         */
        @Override
        public void stateChanged(ChangeEvent ce) {
            // Get the index of the selected tab
            int tabIndex = tabbedPane.getSelectedIndex();
            // Check if a tab is selected
            if (tabIndex != -1) {
                // Base the action of the name of the tab selected
                switch(tabbedPane.getTitleAt(tabIndex)) {
                    case LAF:
                    case FONT:
                    case COLOR:
                        // Hide the update button
                        btnUpdateAll.setVisible(false);
                        break;
                    case SIZE:
                    case SPACING:
                    case PATH:
                    case OTHER:
                        // Show the update button
                        btnUpdateAll.setVisible(true);
                        break;
                }
            }
        }
    });
    // Add the buttons to the dialog panel
    buttonPnl.add(btnUpdateAll);
    buttonPnl.add(btnCloseDlg);
    // Toggle the tab selection so that the first tab is selected and the Update button
    // visibility is set accordingly
    tabbedPane.setSelectedIndex(-1);
    tabbedPane.setSelectedIndex(0);
    // Set the initial size of the preferences dialog based on the individual panes' contents
    tabbedPane.setPreferredSize(new Dimension(tabbedPane.getPreferredSize().width + LAF_SCROLL_BAR_WIDTH, maxScrollPaneHeight));
    // Display the Preferences dialog
    showOptionsDialog(ccddMain.getMainFrame(), tabbedPane, buttonPnl, btnCloseDlg, "Preferences", true);
}
Also used : JPanel(javax.swing.JPanel) ModifiableOtherSettingInfo(CCDD.CcddConstants.ModifiableOtherSettingInfo) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ModifiablePathInfo(CCDD.CcddConstants.ModifiablePathInfo) Dimension(java.awt.Dimension) DnDTabbedPane(CCDD.CcddClassesComponent.DnDTabbedPane) ActionListener(java.awt.event.ActionListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) ModifiableSizeInfo(CCDD.CcddConstants.ModifiableSizeInfo) ModifiableSpacingInfo(CCDD.CcddConstants.ModifiableSpacingInfo) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 5 with DnDTabbedPane

use of CCDD.CcddClassesComponent.DnDTabbedPane 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);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) TableInsertionPoint(CCDD.CcddConstants.TableInsertionPoint) DnDTabbedPane(CCDD.CcddClassesComponent.DnDTabbedPane) ActionListener(java.awt.event.ActionListener) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) ChangeListener(javax.swing.event.ChangeListener) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

DnDTabbedPane (CCDD.CcddClassesComponent.DnDTabbedPane)6 ActionEvent (java.awt.event.ActionEvent)6 JPanel (javax.swing.JPanel)6 ChangeEvent (javax.swing.event.ChangeEvent)6 ChangeListener (javax.swing.event.ChangeListener)6 ActionListener (java.awt.event.ActionListener)5 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)3 ValidateCellActionListener (CCDD.CcddClassesComponent.ValidateCellActionListener)3 RateInformation (CCDD.CcddClassesDataTable.RateInformation)3 ArrayList (java.util.ArrayList)3 JButton (javax.swing.JButton)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 JMenu (javax.swing.JMenu)2 JMenuBar (javax.swing.JMenuBar)2 ModifiableOtherSettingInfo (CCDD.CcddConstants.ModifiableOtherSettingInfo)1 ModifiablePathInfo (CCDD.CcddConstants.ModifiablePathInfo)1 ModifiableSizeInfo (CCDD.CcddConstants.ModifiableSizeInfo)1 ModifiableSpacingInfo (CCDD.CcddConstants.ModifiableSpacingInfo)1