Search in sources :

Example 41 with TypeDefinition

use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.

the class CcddSearchDialog method initialize.

/**
 ********************************************************************************************
 * Create the database table or scripts search dialog
 *
 * @param targetRow
 *            row index to match if this is an event log entry search on a table that displays
 *            only a single log entry; null otherwise
 *
 * @param parent
 *            GUI component over which to center the dialog
 ********************************************************************************************
 */
private void initialize(final Long targetRow, Component parent) {
    searchHandler = new CcddSearchHandler(ccddMain, searchDlgType, targetRow, eventLog);
    searchColumns = "";
    // Create a borders for the dialog components
    Border 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()));
    Border emptyBorder = BorderFactory.createEmptyBorder();
    // Set the initial layout manager characteristics
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, (searchDlgType == SearchDialogType.TABLES ? 0.0 : 1.0), 0.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
    // Create panels to hold the components of the dialog
    JPanel dialogPnl = new JPanel(new GridBagLayout());
    JPanel upperPnl = new JPanel(new GridBagLayout());
    JPanel inputPnl = new JPanel(new GridBagLayout());
    dialogPnl.setBorder(emptyBorder);
    upperPnl.setBorder(emptyBorder);
    inputPnl.setBorder(emptyBorder);
    // Create the search dialog labels and fields
    JLabel dlgLbl = new JLabel("Enter search text");
    dlgLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    inputPnl.add(dlgLbl, gbc);
    // Create the auto-completion search field and add it to the dialog panel. The search list
    // is initially empty as it is updated whenever a key is pressed
    searchFld = new AutoCompleteTextField(ModifiableSizeInfo.NUM_REMEMBERED_SEARCHES.getSize());
    searchFld.setCaseSensitive(true);
    searchFld.setText("");
    searchFld.setColumns(25);
    searchFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    searchFld.setEditable(true);
    searchFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    searchFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
    searchFld.setBorder(border);
    // Add a listener for key press events
    searchFld.addKeyListener(new KeyAdapter() {

        /**
         ************************************************************************************
         * Handle a key press event
         ************************************************************************************
         */
        @Override
        public void keyPressed(KeyEvent ke) {
            // Check if this is a visible character
            if (!ke.isActionKey() && ke.getKeyCode() != KeyEvent.VK_ENTER && !ke.isControlDown() && !ke.isAltDown() && !ke.isMetaDown() && ModifiableFontInfo.INPUT_TEXT.getFont().canDisplay(ke.getKeyCode())) {
                // Get the list of remembered searches from the program preferences. This is
                // done as a key press occurs so that the list is updated to the latest one. If
                // multiple search dialogs are open this allows them to 'share' the list rather
                // than overwriting each other
                List<String> searches = new ArrayList<String>(ModifiableSizeInfo.NUM_REMEMBERED_SEARCHES.getSize());
                searches.addAll(Arrays.asList(ccddMain.getProgPrefs().get(SEARCH_STRINGS, "").split(AUTO_COMPLETE_TEXT_SEPARATOR)));
                searchFld.setList(searches);
            }
        }
    });
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    gbc.gridy++;
    inputPnl.add(searchFld, gbc);
    // Create a check box for ignoring the text case
    ignoreCaseCb = new JCheckBox("Ignore text case");
    ignoreCaseCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    ignoreCaseCb.setBorder(emptyBorder);
    ignoreCaseCb.setToolTipText(CcddUtilities.wrapText("Ignore case when matching the search string", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
    // Add a listener for check box selection changes
    ignoreCaseCb.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Handle a change in the ignore case check box state
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            // Change the case sensitivity for the remembered searches to match the case
            // sensitivity check box
            searchFld.setCaseSensitive(!ignoreCaseCb.isSelected());
        }
    });
    gbc.insets.left = 0;
    gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.gridy++;
    inputPnl.add(ignoreCaseCb, gbc);
    // Create a check box for allow a regular expression in the search string
    allowRegexCb = new JCheckBox("Allow regular expression");
    allowRegexCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    allowRegexCb.setBorder(emptyBorder);
    allowRegexCb.setToolTipText(CcddUtilities.wrapText("Allow the search string to contain a regular expression", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
    gbc.gridy++;
    inputPnl.add(allowRegexCb, gbc);
    // Check if this is a table search
    if (searchDlgType == SearchDialogType.TABLES) {
        final ArrayListMultiple columns = new ArrayListMultiple();
        // Create a check box for ignoring matches within the internal tables
        dataTablesOnlyCb = new JCheckBox("Search data table cells only");
        dataTablesOnlyCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
        dataTablesOnlyCb.setBorder(emptyBorder);
        dataTablesOnlyCb.setToolTipText(CcddUtilities.wrapText("Search only the cells in the data tables", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
        gbc.gridy++;
        inputPnl.add(dataTablesOnlyCb, gbc);
        // Step through each defined table type
        for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
            // Step through each visible column in the table type
            for (int index = NUM_HIDDEN_COLUMNS; index < typeDefn.getColumnCountDatabase(); ++index) {
                // Check if the column name isn't already in the list
                if (!columns.contains(typeDefn.getColumnNamesUser()[index])) {
                    // Add the visible column name and its corresponding database name to the
                    // list
                    columns.add(new String[] { typeDefn.getColumnNamesUser()[index], typeDefn.getColumnNamesDatabase()[index] });
                }
            }
        }
        // Check if any columns are defined
        if (columns.size() != 0) {
            ArrayListMultiple columnNames = new ArrayListMultiple();
            // Sort the column names alphabetically
            columns.sort(ArrayListMultipleSortType.STRING);
            // Create the column selection check box and label to display the selected
            // column(s)
            selectedColumnsCb = new JCheckBox("Search selected columns");
            selectedColumnsCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            selectedColumnsCb.setBorder(emptyBorder);
            selectedColumnsCb.setToolTipText(CcddUtilities.wrapText("Search only selected columns in the data tables", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
            selectedColumnsLbl = new MultilineLabel();
            selectedColumnsLbl.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
            // Set the layout manager characteristics for the column selection panel
            GridBagConstraints subgbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
            // Add the column selection check box and label to the column selection panel, then
            // add this panel to the dialog
            JPanel selectedColumnsPnl = new JPanel(new GridBagLayout());
            selectedColumnsPnl.add(selectedColumnsCb, subgbc);
            selectedColumnsPnl.setBorder(emptyBorder);
            subgbc.weightx = 1.0;
            subgbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() * 3;
            subgbc.fill = GridBagConstraints.BOTH;
            subgbc.gridy++;
            selectedColumnsPnl.add(selectedColumnsLbl, subgbc);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridy++;
            inputPnl.add(selectedColumnsPnl, gbc);
            // Create a panel for the column selection pop-up dialog
            final JPanel columnPnl = new JPanel(new GridBagLayout());
            columnPnl.setBorder(emptyBorder);
            // Step through each column
            for (String[] column : columns) {
                // Add the visible name to the list used to create the check box panel
                columnNames.add(new String[] { column[0], null });
            }
            // Create the column name pop-up dialog
            final CcddDialogHandler columnDlg = new CcddDialogHandler();
            // Add the column name check boxes to the dialog
            columnDlg.addCheckBoxes(null, columnNames.toArray(new String[0][0]), null, "", columnPnl);
            // Add a listener for check box selection changes
            selectedColumnsCb.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Handle a change in the selected columns check box state
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // Check if the column selection check box is selected
                    if (selectedColumnsCb.isSelected()) {
                        // Display a pop-up for choosing which table columns to search
                        if (columnDlg.showOptionsDialog(CcddSearchDialog.this, columnPnl, "Select Column(s)", DialogOption.OK_CANCEL_OPTION, true) == OK_BUTTON) {
                            searchColumns = "";
                            // Step through each column name check box
                            for (int index = 0; index < columnDlg.getCheckBoxes().length; index++) {
                                // Check if the check box is selected
                                if (columnDlg.getCheckBoxes()[index].isSelected()) {
                                    // Add the name of the column to the constraint string
                                    searchColumns += columns.get(index)[1] + ",";
                                }
                            }
                            searchColumns = CcddUtilities.removeTrailer(searchColumns, ",");
                            // Set the selected column(s) label to display the selected
                            // column(s)
                            selectedColumnsLbl.setText(searchColumns.replaceAll(",", ", "));
                        }
                        // Check if no column is selected
                        if (searchColumns.isEmpty()) {
                            // Deselect the selected columns check box and blank the selected
                            // column(s) text
                            selectedColumnsCb.setSelected(false);
                            selectedColumnsLbl.setText("");
                        }
                    } else // The column selection check box is not selected
                    {
                        // Blank the column constraint string and the selected column(s) text
                        searchColumns = "";
                        selectedColumnsLbl.setText("");
                    }
                }
            });
        }
    }
    // Add the inputs panel, containing the search field and check boxes, to the upper panel
    gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    gbc.gridy = 0;
    upperPnl.add(inputPnl, gbc);
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    gbc.fill = GridBagConstraints.BOTH;
    // Check if this is a table search
    if (searchDlgType == SearchDialogType.TABLES) {
        // Build the table tree showing both table prototypes and table instances; i.e., parent
        // tables with their child tables (i.e., parents with children)
        tableTree = new CcddTableTreeHandler(ccddMain, new CcddGroupHandler(ccddMain, null, parent), TableTreeType.TABLES, true, false, parent);
        // Add the tree to the upper panel
        gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridx++;
        upperPnl.add(tableTree.createTreePanel("Tables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, parent), gbc);
        gbc.gridwidth = 1;
    }
    gbc.insets.right = 0;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    dialogPnl.add(upperPnl, gbc);
    // Create the results and number of results found labels
    JLabel resultsLbl = new JLabel("Search results");
    resultsLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    resultsLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
    numResultsLbl = new JLabel();
    numResultsLbl.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    gbc.insets.bottom = 0;
    gbc.weighty = 0.0;
    gbc.gridy++;
    // Add the results labels to the dialog
    JPanel resultsPnl = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    resultsPnl.add(resultsLbl);
    resultsPnl.add(numResultsLbl);
    dialogPnl.add(resultsPnl, gbc);
    // Create the table to display the search results
    resultsTable = new CcddJTableHandler() {

        /**
         ************************************************************************************
         * Allow multiple line display in the specified columns, depending on search type
         ************************************************************************************
         */
        @Override
        protected boolean isColumnMultiLine(int column) {
            return searchDlgType == SearchDialogType.TABLES || (searchDlgType == SearchDialogType.LOG && column == SearchResultsColumnInfo.CONTEXT.ordinal()) || (searchDlgType == SearchDialogType.SCRIPTS && (column == SearchResultsColumnInfo.OWNER.ordinal() || column == SearchResultsColumnInfo.CONTEXT.ordinal()));
        }

        /**
         ************************************************************************************
         * Allow HTML-formatted text in the specified column(s)
         ************************************************************************************
         */
        @Override
        protected boolean isColumnHTML(int column) {
            return searchDlgType == SearchDialogType.TABLES && column == SearchResultsColumnInfo.OWNER.ordinal();
        }

        /**
         ************************************************************************************
         * Allow the specified column's cells to be displayed with the text highlighted
         ************************************************************************************
         */
        @Override
        protected boolean isColumnHighlight(int column) {
            return column == SearchResultsColumnInfo.CONTEXT.ordinal();
        }

        /**
         ************************************************************************************
         * Load the search results data into the table and format the table cells
         ************************************************************************************
         */
        @Override
        protected void loadAndFormatData() {
            // Place the data into the table model along with the column names, set up the
            // editors and renderers for the table cells, set up the table grid lines, and
            // calculate the minimum width required to display the table information
            setUpdatableCharacteristics(resultsData, SearchResultsColumnInfo.getColumnNames(searchDlgType), null, SearchResultsColumnInfo.getToolTips(searchDlgType), true, true, true);
        }

        /**
         ************************************************************************************
         * Override the table layout so that extra width is apportioned unequally between the
         * columns when the table is resized
         ************************************************************************************
         */
        @Override
        public void doLayout() {
            // Get a reference to the column being resized
            if (getTableHeader() != null && getTableHeader().getResizingColumn() == null) {
                // Get a reference to the event table's column model to shorten subsequent
                // calls
                TableColumnModel tcm = getColumnModel();
                // Calculate the change in the search dialog's width
                int delta = getParent().getWidth() - tcm.getTotalColumnWidth();
                // Get the reference to the search results table columns
                TableColumn tgtColumn = tcm.getColumn(SearchResultsColumnInfo.OWNER.ordinal());
                TableColumn locColumn = tcm.getColumn(SearchResultsColumnInfo.LOCATION.ordinal());
                TableColumn cntxtColumn = tcm.getColumn(SearchResultsColumnInfo.CONTEXT.ordinal());
                // Set the columns' widths to its current width plus a percentage of the the
                // extra width added to the dialog due to the resize
                tgtColumn.setPreferredWidth(tgtColumn.getPreferredWidth() + (int) (delta * 0.25));
                tgtColumn.setWidth(tgtColumn.getPreferredWidth());
                locColumn.setPreferredWidth(locColumn.getPreferredWidth() + (int) (delta * 0.25));
                locColumn.setWidth(locColumn.getPreferredWidth());
                cntxtColumn.setPreferredWidth(cntxtColumn.getPreferredWidth() + delta - (int) (delta * 0.25) * 2);
                cntxtColumn.setWidth(cntxtColumn.getPreferredWidth());
            } else // Table header or resize column not available
            {
                super.doLayout();
            }
        }

        /**
         ************************************************************************************
         * Highlight the matching search text in the context column cells
         *
         * @param component
         *            reference to the table cell renderer component
         *
         * @param value
         *            cell value
         *
         * @param isSelected
         *            true if the cell is to be rendered with the selection highlighted
         *
         * @param int
         *            row cell row, view coordinates
         *
         * @param column
         *            cell column, view coordinates
         ************************************************************************************
         */
        @Override
        protected void doSpecialRendering(Component component, String text, boolean isSelected, int row, int column) {
            // Check if highlighting is enabled and if the column allows text highlighting
            if (isColumnHighlight(column)) {
                Pattern pattern;
                // Create a highlighter painter
                DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(isSelected ? ModifiableColorInfo.INPUT_TEXT.getColor() : ModifiableColorInfo.TEXT_HIGHLIGHT.getColor());
                // Check if case is to be ignored
                if (ignoreCaseCb.isSelected()) {
                    // Create the match pattern with case ignored
                    pattern = Pattern.compile(allowRegexCb.isSelected() ? searchFld.getText() : Pattern.quote(searchFld.getText()), Pattern.CASE_INSENSITIVE);
                } else // Only highlight matches with the same case
                {
                    // Create the match pattern, preserving case
                    pattern = Pattern.compile(allowRegexCb.isSelected() ? searchFld.getText() : Pattern.quote(searchFld.getText()));
                }
                // Create the pattern matcher from the pattern
                Matcher matcher = pattern.matcher(text);
                // Find each match in the text string
                while (matcher.find()) {
                    try {
                        // Highlight the matching text. Adjust the highlight color to account
                        // for the cell selection highlighting so that the search text is
                        // easily readable
                        ((JTextComponent) component).getHighlighter().addHighlight(matcher.start(), matcher.end(), painter);
                    } catch (BadLocationException ble) {
                    // Ignore highlighting failure
                    }
                }
            }
        }
    };
    // Place the table into a scroll pane
    JScrollPane scrollPane = new JScrollPane(resultsTable);
    // Set up the search results table parameters
    resultsTable.setFixedCharacteristics(scrollPane, false, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, TableSelectionMode.SELECT_BY_CELL, true, ModifiableColorInfo.TABLE_BACK.getColor(), false, true, ModifiableFontInfo.OTHER_TABLE_CELL.getFont(), true);
    // Define the panel to contain the table
    JPanel resultsTblPnl = new JPanel();
    resultsTblPnl.setLayout(new BoxLayout(resultsTblPnl, BoxLayout.X_AXIS));
    resultsTblPnl.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
    resultsTblPnl.add(scrollPane);
    // Add the table to the dialog
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1.0;
    gbc.gridx = 0;
    gbc.gridy++;
    dialogPnl.add(resultsTblPnl, gbc);
    // Search database tables button
    JButton btnSearch = CcddButtonPanelHandler.createButton("Search", SEARCH_ICON, KeyEvent.VK_O, "Search the project database");
    // Add a listener for the Search button
    btnSearch.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Search the database tables and display the results
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            // Check if the search field is blank
            if (searchFld.getText().isEmpty()) {
                // Inform the user that the input value is invalid
                new CcddDialogHandler().showMessageDialog(CcddSearchDialog.this, "<html><b>Search text cannot be blank", "Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
            } else // The search field contains text
            {
                List<Object[]> resultsDataList = null;
                // Update the search string list
                searchFld.updateList(searchFld.getText());
                // Store the search list in the program preferences
                ccddMain.getProgPrefs().put(SEARCH_STRINGS, searchFld.getListAsString());
                switch(searchDlgType) {
                    case TABLES:
                    case SCRIPTS:
                        // Search the database tables or scripts and display the results
                        resultsDataList = searchHandler.searchTablesOrScripts(searchFld.getText(), ignoreCaseCb.isSelected(), allowRegexCb.isSelected(), (searchDlgType == SearchDialogType.TABLES ? dataTablesOnlyCb.isSelected() : false), searchColumns);
                        break;
                    case LOG:
                        // Search the event log and display the results
                        resultsDataList = searchHandler.searchEventLogFile(searchFld.getText(), ignoreCaseCb.isSelected(), targetRow);
                        break;
                }
                // Check if this is a table search
                if (searchDlgType == SearchDialogType.TABLES) {
                    List<Object[]> removeResults = new ArrayList<Object[]>();
                    // Get the list of selected tables
                    List<String> filterTables = tableTree.getSelectedTablesWithChildren();
                    // Add the ancestors (instances and prototype) of the selected tables to
                    // the list of filter tables
                    tableTree.addTableAncestors(filterTables, true);
                    // Check if tables were selected to filter the search results
                    if (!filterTables.isEmpty()) {
                        // Step through the search results
                        for (Object[] result : resultsDataList) {
                            // Separate the target into the target type and owner
                            String[] typeAndOwner = CcddUtilities.removeHTMLTags(result[SearchResultsColumnInfo.OWNER.ordinal()].toString()).split(": ");
                            // if owner isn't one of the selected tables or its prototype
                            if (!((typeAndOwner[0].equals(SearchTarget.TABLE.getTargetName(false)) || typeAndOwner[0].equals(SearchTarget.TABLE_FIELD.getTargetName(false))) && filterTables.contains(typeAndOwner[1]))) {
                                // Add the search result to the list of those to remove
                                removeResults.add(result);
                            }
                        // TODO Since prototype tables are automatically added (needed
                        // since a child only returns matches in the values table), a false
                        // match can occur if the filter table is a child, the hit is in
                        // the child's prototype, and the child has overridden the
                        // prototype's value where the match occurs
                        }
                        // Remove the search results that aren't in the selected table(s)
                        resultsDataList.removeAll(removeResults);
                    }
                }
                // Convert the results list to an array and display the results in the dialog's
                // search results table
                resultsData = resultsDataList.toArray(new Object[0][0]);
                resultsTable.loadAndFormatData();
            }
            // Update the number of results found label
            numResultsLbl.setText("  (" + resultsData.length + " found)");
        }
    });
    JButton btnOpen = null;
    // Check if this is the table search dialog
    if (searchDlgType == SearchDialogType.TABLES) {
        // Open table(s) button
        btnOpen = CcddButtonPanelHandler.createButton("Open", TABLE_ICON, KeyEvent.VK_O, "Open the table(s) associated with the selected search result(s)");
        // Add a listener for the Open button
        btnOpen.addActionListener(new ActionListener() {

            /**
             ************************************************************************************
             * Open the selected table(s)
             ************************************************************************************
             */
            @Override
            public void actionPerformed(ActionEvent ae) {
                openTables();
            }
        });
    }
    // Print inconsistencies button
    JButton btnPrint = CcddButtonPanelHandler.createButton("Print", PRINT_ICON, KeyEvent.VK_P, "Print the search results list");
    // Add a listener for the Print button
    btnPrint.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Print the search results list
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            resultsTable.printTable("Search Results", null, CcddSearchDialog.this, PageFormat.LANDSCAPE);
        }
    });
    // Close search dialog button
    JButton btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the search dialog");
    // Add a listener for the Close button
    btnClose.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Close the search dialog
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            CcddSearchDialog.this.closeFrame();
        }
    });
    // Create a panel for the dialog buttons and add the buttons to the panel
    JPanel buttonPnl = new JPanel();
    buttonPnl.setBorder(BorderFactory.createEmptyBorder());
    buttonPnl.add(btnSearch);
    // Check if this is the table search dialog
    if (searchDlgType == SearchDialogType.TABLES) {
        buttonPnl.add(btnOpen);
    }
    buttonPnl.add(btnPrint);
    buttonPnl.add(btnClose);
    // Get the dialog title based on the search type
    String title = null;
    switch(searchDlgType) {
        case TABLES:
            title = "Search Tables";
            break;
        case SCRIPTS:
            title = "Search Scripts";
            break;
        case LOG:
            title = getLogTitle();
            break;
    }
    // Display the search dialog
    createFrame(parent, dialogPnl, buttonPnl, btnSearch, title, null);
}
Also used : MultilineLabel(CCDD.CcddClassesComponent.MultilineLabel) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) Matcher(java.util.regex.Matcher) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) BoxLayout(javax.swing.BoxLayout) DefaultHighlighter(javax.swing.text.DefaultHighlighter) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) JTextComponent(javax.swing.text.JTextComponent) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) KeyEvent(java.awt.event.KeyEvent) AutoCompleteTextField(CCDD.CcddClassesComponent.AutoCompleteTextField) List(java.util.List) ArrayList(java.util.ArrayList) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) DefaultHighlightPainter(javax.swing.text.DefaultHighlighter.DefaultHighlightPainter) JScrollPane(javax.swing.JScrollPane) Pattern(java.util.regex.Pattern) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) JCheckBox(javax.swing.JCheckBox) DefaultHighlightPainter(javax.swing.text.DefaultHighlighter.DefaultHighlightPainter) ActionListener(java.awt.event.ActionListener) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder) EtchedBorder(javax.swing.border.EtchedBorder) BadLocationException(javax.swing.text.BadLocationException)

Example 42 with TypeDefinition

use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.

the class CcddJSONHandler method getTableTypeDefinitions.

/**
 ********************************************************************************************
 * Add the table type definition(s) corresponding to the supplied table type name(s) to the
 * specified JSON object. If no table type is provided, or if none are recognized, then nothing
 * is added to the JSON object
 *
 * @param tableTypeNames
 *            names of the table types to add; null to include all defined table types
 *
 * @param outputJO
 *            JSON object to which the data types are added
 *
 * @return The supplied JSON object, with the table type definitions added (if any)
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
protected JSONObject getTableTypeDefinitions(List<String> tableTypeNames, JSONObject outputJO) {
    // included
    if (tableTypeNames == null) {
        tableTypeNames = new ArrayList<String>();
        // Step through each table type definition
        for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
            // Add the table type name to the list
            tableTypeNames.add(typeDefn.getName());
        }
    }
    // Check if any table types are referenced
    if (!tableTypeNames.isEmpty()) {
        JSONArray tableTypeJA = new JSONArray();
        // Step through each referenced table type
        for (String refTableType : tableTypeNames) {
            // Get the table type definition
            TypeDefinition tableTypeDefn = tableTypeHandler.getTypeDefinition(refTableType);
            // Check if the table type exists
            if (tableTypeDefn != null) {
                JSONArray typeDefnJA = new JSONArray();
                JSONObject tableTypeJO;
                // key and row index columns
                for (int column = NUM_HIDDEN_COLUMNS; column < tableTypeDefn.getColumnCountDatabase(); column++) {
                    tableTypeJO = new JSONObject();
                    tableTypeJO.put(TableTypeEditorColumnInfo.NAME.getColumnName(), tableTypeDefn.getColumnNamesUser()[column]);
                    tableTypeJO.put(TableTypeEditorColumnInfo.DESCRIPTION.getColumnName(), tableTypeDefn.getColumnToolTips()[column]);
                    tableTypeJO.put(TableTypeEditorColumnInfo.INPUT_TYPE.getColumnName(), tableTypeDefn.getInputTypes()[column].getInputName());
                    tableTypeJO.put(TableTypeEditorColumnInfo.UNIQUE.getColumnName(), tableTypeDefn.isRowValueUnique()[column]);
                    tableTypeJO.put(TableTypeEditorColumnInfo.REQUIRED.getColumnName(), tableTypeDefn.isRequired()[column]);
                    tableTypeJO.put(CcddUtilities.removeHTMLTags(TableTypeEditorColumnInfo.STRUCTURE_ALLOWED.getColumnName()), tableTypeDefn.isStructureAllowed()[column]);
                    tableTypeJO.put(CcddUtilities.removeHTMLTags(TableTypeEditorColumnInfo.POINTER_ALLOWED.getColumnName()), tableTypeDefn.isPointerAllowed()[column]);
                    // Add the table type definition to the array
                    typeDefnJA.add(tableTypeJO);
                }
                // Add the wrapper for the table type name and put the table type description,
                // column definitions, and data fields (if any) in it
                tableTypeJO = new JSONObject();
                tableTypeJO.put(JSONTags.TABLE_TYPE_NAME.getTag(), refTableType);
                tableTypeJO.put(JSONTags.TABLE_TYPE_DESCRIPTION.getTag(), tableTypeDefn.getDescription());
                tableTypeJO.put(JSONTags.TABLE_TYPE_COLUMN.getTag(), typeDefnJA);
                tableTypeJO = getDataFields(CcddFieldHandler.getFieldTypeName(refTableType), JSONTags.TABLE_TYPE_FIELD.getTag(), tableTypeJO);
                tableTypeJA.add(tableTypeJO);
            }
        }
        // Check if a table type definition was recognized
        if (!tableTypeJA.isEmpty()) {
            // Add the table type definition(s) to the JSON output
            outputJO.put(JSONTags.TABLE_TYPE_DEFN.getTag(), tableTypeJA);
        }
    }
    return outputJO;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) TableTypeDefinition(CCDD.CcddClassesDataTable.TableTypeDefinition) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Example 43 with TypeDefinition

use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.

the class CcddRateParameterHandler method setRateInformation.

/**
 ********************************************************************************************
 * Set the rate information list based on the unique rate columns
 *
 * @return true if the number of rate columns changed
 ********************************************************************************************
 */
protected boolean setRateInformation() {
    // Store the current number of rate columns
    int oldNumRateColumns = rateInformation.size();
    // Step through any existing rate column information
    for (RateInformation rateInfo : rateInformation) {
        // Set the number of table types referencing this rate to zero. This is used to
        // determine if a rate is still in use
        rateInfo.setNumSharedTableTypes(0);
    }
    // Step through each table type
    for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
        // Check if the type represents a structure
        if (typeDefn.isStructure()) {
            // Step through each column in the type definition
            for (int index = 0; index < typeDefn.getColumnCountDatabase(); index++) {
                // Check if the column is a sample rate
                if (typeDefn.getInputTypes()[index] == InputDataType.RATE) {
                    // Get the column's visible name
                    String colName = typeDefn.getColumnNamesUser()[index];
                    // Get the rate information for this rate column name
                    RateInformation rateInfo = getRateInformationByRateName(colName);
                    // Check if the column name hasn't been added
                    if (rateInfo == null) {
                        // Add the rate column name to the list
                        rateInformation.add(new RateInformation(colName));
                    } else // The rate column already exists
                    {
                        // Increment the share counter for the existing rate information
                        rateInfo.setNumSharedTableTypes(rateInfo.getNumSharedTableTypes() + 1);
                    }
                }
            }
        }
    }
    // Create a list to store any rate column information that no longer exists
    List<RateInformation> removedRates = new ArrayList<RateInformation>();
    // Step through each rate column's information
    for (RateInformation rateInfo : rateInformation) {
        // Check if the rate is not referenced by a table type
        if (rateInfo.getNumSharedTableTypes() == 0) {
            // Add the non-referenced rate to the list of those to remove
            removedRates.add(rateInfo);
        }
    }
    // Remove any rate information that's no longer valid
    rateInformation.removeAll(removedRates);
    return rateInformation.size() != oldNumRateColumns;
}
Also used : ArrayList(java.util.ArrayList) RateInformation(CCDD.CcddClassesDataTable.RateInformation) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Example 44 with TypeDefinition

use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.

the class CcddScriptDataAccessHandler method getCommandArgArraySize.

/**
 ********************************************************************************************
 * Get the argument array size for the command argument specified at the specified row in the
 * command data. Macro expansion is controlled by the input flag
 *
 * @param argumentNumber
 *            command argument index. The first argument is 0
 *
 * @param row
 *            table data row index
 *
 * @param expandMacros
 *            true to replace any macros with their corresponding value; false to return the
 *            data with any macro names in place
 *
 * @return Argument array size for the command argument specified at the specified row in the
 *         command data; null if the argument number or row index is invalid
 ********************************************************************************************
 */
private String getCommandArgArraySize(int argumentNumber, int row, boolean expandMacros) {
    String argArraySize = null;
    // Get the table type definition for the command table referenced in the specified row
    TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(getCommandTypeNameByRow(row));
    // Check if the table type exists and represents a command
    if (typeDefn != null && typeDefn.isCommand()) {
        // Get the list of command arguments associated with this command table type
        List<AssociatedColumns> commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
        // Check if the argument number is valid and that the argument array size exists
        if (argumentNumber < commandArguments.size() && commandArguments.get(argumentNumber).getArraySize() != -1) {
            // Get the reference to the table information
            TableInformation tableInfo = getTableInformation(TYPE_COMMAND);
            // Get the argument array size
            argArraySize = tableInfo.getData()[row][commandArguments.get(argumentNumber).getArraySize()];
            // Check if any macros should be expanded
            if (expandMacros) {
                // Expand any macros
                argArraySize = macroHandler.getMacroExpansion(argArraySize);
            }
        }
    }
    return argArraySize;
}
Also used : AssociatedColumns(CCDD.CcddClassesDataTable.AssociatedColumns) TableInformation(CCDD.CcddClassesDataTable.TableInformation) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Example 45 with TypeDefinition

use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.

the class CcddScriptDataAccessHandler method getCommandCode.

/**
 ********************************************************************************************
 * Get the command code (as a string) at the specified row in the command data. Macro expansion
 * is controlled by the input flag
 *
 * @param row
 *            table data row index
 *
 * @param expandMacros
 *            true to replace any macros with their corresponding value; false to return the
 *            data with any macro names in place
 *
 * @return Command code (as a string) at the specified row in the command data; null if the row
 *         index is invalid
 ********************************************************************************************
 */
private String getCommandCode(int row, boolean expandMacros) {
    String commandCode = null;
    // Get the table type definition for the command table referenced in the specified row
    TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(getCommandTypeNameByRow(row));
    // Check if the table type exists and represents a command
    if (typeDefn != null && typeDefn.isCommand()) {
        // Get the reference to the table information
        TableInformation tableInfo = getTableInformation(TYPE_COMMAND);
        // Get the command code
        commandCode = tableInfo.getData()[row][typeDefn.getColumnIndexByInputType(InputDataType.COMMAND_CODE)];
        // Check if any macros should be expanded
        if (expandMacros) {
            // Expand any macros
            commandCode = macroHandler.getMacroExpansion(commandCode);
        }
    }
    return commandCode;
}
Also used : TableInformation(CCDD.CcddClassesDataTable.TableInformation) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Aggregations

TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)64 TableInformation (CCDD.CcddClassesDataTable.TableInformation)30 ArrayList (java.util.ArrayList)24 CCDDException (CCDD.CcddClassesDataTable.CCDDException)18 AssociatedColumns (CCDD.CcddClassesDataTable.AssociatedColumns)10 SQLException (java.sql.SQLException)9 JSONArray (org.json.simple.JSONArray)8 JSONObject (org.json.simple.JSONObject)8 TableTypeDefinition (CCDD.CcddClassesDataTable.TableTypeDefinition)6 IOException (java.io.IOException)6 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)5 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)4 ArrayListMultiple (CCDD.CcddClassesComponent.ArrayListMultiple)4 FileEnvVar (CCDD.CcddClassesComponent.FileEnvVar)3 FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)3 Component (java.awt.Component)3 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3 Insets (java.awt.Insets)3 ResultSet (java.sql.ResultSet)3