Search in sources :

Example 1 with RateInformation

use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.

the class CcddLinkManagerDialog method addLinkHandlerPanes.

/**
 ********************************************************************************************
 * Add a link handler for each data stream
 ********************************************************************************************
 */
private void addLinkHandlerPanes() {
    // Create storage for the link manager handlers
    linkMgrs = new ArrayList<CcddLinkManagerHandler>();
    // Step through each stream
    for (RateInformation rateInfo : rateHandler.getRateInformation()) {
        // Create a link manager for this stream
        CcddLinkManagerHandler linkMgr = new CcddLinkManagerHandler(ccddMain, this, rateInfo.getRateName(), rateHandler.getRatesInUse(rateInfo.getRateName(), CcddLinkManagerDialog.this));
        // Add the link manager to the list of managers
        linkMgrs.add(linkMgr);
        // Create a tab for each data stream
        tabbedPane.addTab(rateInfo.getStreamName(), null, linkMgr.getHandlerPanel(), rateInfo.getRateName());
    }
}
Also used : RateInformation(CCDD.CcddClassesDataTable.RateInformation)

Example 2 with RateInformation

use of CCDD.CcddClassesDataTable.RateInformation 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 RateInformation

use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.

the class CcddDbControlHandler method createStructureColumnFunctions.

/**
 ********************************************************************************************
 * Create the reusable database functions for obtaining structure table members and
 * structure-defining column values
 *
 * @return true if an error occurs creating the structure functions
 ********************************************************************************************
 */
protected boolean createStructureColumnFunctions() {
    boolean errorFlag = false;
    // Check if connected to a project database
    if (isDatabaseConnected()) {
        try {
            // Structure-defining column names, as used by the database
            String dbVariableName = null;
            String dbDataType = null;
            String dbArraySize = null;
            String dbBitLength = null;
            String dbRate = null;
            String dbEnumeration = null;
            String compareColumns = "";
            // Use the default structure column names for certain default columns
            dbVariableName = DefaultColumn.VARIABLE_NAME.getDbName();
            dbDataType = DefaultColumn.DATA_TYPE.getDbName();
            dbArraySize = DefaultColumn.ARRAY_SIZE.getDbName();
            dbBitLength = DefaultColumn.BIT_LENGTH.getDbName();
            // Create a string containing the partial command for determining if the columns
            // that are necessary to define a structure table are present in a table
            String defStructCols = "(column_name = '" + dbVariableName + "' OR " + "column_name = '" + dbDataType + "' OR " + "column_name = '" + dbArraySize + "' OR " + "column_name = '" + dbBitLength + "' OR ";
            List<String> rateAndEnums = new ArrayList<String>();
            // Step through each table type definition
            for (TypeDefinition typeDefn : ccddMain.getTableTypeHandler().getTypeDefinitions()) {
                // Check if the type represents a structure
                if (typeDefn.isStructure()) {
                    // Get this type's first rate and enumeration column names
                    dbRate = typeDefn.getDbColumnNameByInputType(InputDataType.RATE);
                    dbEnumeration = typeDefn.getDbColumnNameByInputType(InputDataType.ENUMERATION);
                    // Create the portion of the command comparing the column name to the first
                    // rate and enumeration column names
                    String rateAndEnum = "column_name = '" + dbRate + "' OR " + "column_name = '" + dbEnumeration + "') OR ";
                    // exist in the comparison
                    if (!rateAndEnums.contains(rateAndEnum)) {
                        // Add the rate and enumeration name pair so that it won't be added
                        // again
                        rateAndEnums.add(rateAndEnum);
                        // Create a string containing the partial command for determining if
                        // the columns that are necessary to define a structure table are
                        // present in a table
                        compareColumns += defStructCols + "column_name = '" + dbRate + "' OR " + "column_name = '" + dbEnumeration + "') OR ";
                    }
                }
            }
            // Check if no structure table type exists
            if (compareColumns.isEmpty()) {
                // Get the default rate and enumeration column names
                dbRate = DefaultColumn.RATE.getDbName();
                dbEnumeration = DefaultColumn.ENUMERATION.getDbName();
                // Create a string containing the partial command for determining if the
                // columns that are necessary to define a structure table are present in a
                // table
                compareColumns = defStructCols + "column_name = '" + dbRate + "' OR " + "column_name = '" + dbEnumeration + "')";
            } else // At least one structure table type exists
            {
                compareColumns = CcddUtilities.removeTrailer(compareColumns, " OR ");
            }
            // alphabetically by name or numerically by row index
            for (String[] functionParm : functionParameters) {
                // Create function to get the table name, data type, variable name, bit length,
                // sample rate, and enumeration for all structure tables that contain at least
                // one row, sorted by table name or index, and then by variable name. For
                // arrays, only the members are retrieved; the array definitions are ignored
                dbCommand.executeDbCommand(deleteFunction("get_table_members_by_" + functionParm[0]) + "CREATE FUNCTION get_table_members_by_" + functionParm[0] + "() RETURNS TABLE(tbl_name text, data_type " + "text, variable_name text, bit_length text, " + "rate text, enumeration text) AS $$ BEGIN " + "DECLARE row record; BEGIN DROP TABLE IF EXISTS " + TEMP_TABLES + "; CREATE TEMP TABLE " + TEMP_TABLES + " AS SELECT t.tablename AS real_name FROM " + "pg_tables AS t WHERE t.schemaname = 'public' " + "AND substr(t.tablename, 1, 2) != '" + INTERNAL_TABLE_PREFIX + "' ORDER BY real_name ASC; FOR row IN SELECT * FROM " + TEMP_TABLES + " LOOP IF EXISTS (SELECT * FROM " + "(SELECT COUNT(*) FROM information_schema.columns " + "WHERE table_name = row.real_name AND (" + compareColumns + ")) AS alias1 WHERE count = '" + DefaultColumn.getTypeRequiredColumnCount(TYPE_STRUCTURE) + "') THEN RETURN QUERY EXECUTE E'SELECT ''' || " + "row.real_name || '''::text, * FROM get_def_columns_by_" + functionParm[0] + "(''' || row.real_name || ''')'; END IF; " + "END LOOP; END; END; $$ LANGUAGE plpgsql; " + buildOwnerCommand(DatabaseObject.FUNCTION, "get_table_members_by_" + functionParm[0] + "()"), ccddMain.getMainFrame());
            }
            String rateCol = "";
            String rateJoin = "";
            // Check if any rate columns are defined
            if (ccddMain.getRateParameterHandler().getNumRateColumns() != 0) {
                // Step through each data stream
                for (RateInformation rateInfo : ccddMain.getRateParameterHandler().getRateInformation()) {
                    // Get the rate column name (in its database form)
                    String rateColName = DefaultColumn.convertVisibleToDatabase(rateInfo.getRateName(), InputDataType.RATE, true);
                    // Add detection for the rate column. If the column doesn't exist in the
                    // table then a blank is returned for that column's rate value
                    rateCol += "CASE WHEN " + rateColName + "_exists THEN " + rateColName + "::text ELSE ''''::text END || '','' || ";
                    rateJoin += " CROSS JOIN (SELECT EXISTS (SELECT 1 FROM " + "pg_catalog.pg_attribute WHERE attrelid = ''' " + "|| name || '''::regclass AND attname  = ''" + rateColName + "'' " + "AND NOT attisdropped AND attnum > 0) AS " + rateColName + "_exists) " + rateColName;
                }
                // Remove the trailing separator text
                rateCol = CcddUtilities.removeTrailer(rateCol, " || '','' || ");
            } else // No rate columns exist
            {
                // Return a blank for the rate column value
                rateCol = "''''::text";
            }
            String enumCol = "";
            String enumJoin = "";
            // Get the unique structure enumeration column names
            List<String> enumColumns = ccddMain.getTableTypeHandler().getStructEnumColNames(true);
            // Check if any enumeration columns are defined
            if (enumColumns.size() != 0) {
                // Build the enumeration separator (triple backslashes) portion of the command
                String enumSep = " || E''' || E'\\\\\\\\\\\\\\\\\\\\\\\\' || ''' || ";
                // Step through each enumeration column name (in its database form)
                for (String enumColName : enumColumns) {
                    // Add detection for the enumeration column. If the column doesn't exist in
                    // the table then a blank is returned for that column's enumeration value
                    enumCol += "CASE WHEN " + enumColName + "_exists THEN " + enumColName + "::text ELSE ''''::text END" + enumSep;
                    enumJoin += " CROSS JOIN (SELECT EXISTS (SELECT 1 FROM " + "pg_catalog.pg_attribute WHERE attrelid = ''' " + "|| name || '''::regclass AND attname  = ''" + enumColName + "'' " + "AND NOT attisdropped AND attnum > 0) AS " + enumColName + "_exists) " + enumColName;
                }
                // Remove the trailing separator text
                enumCol = CcddUtilities.removeTrailer(enumCol, enumSep);
            } else // No enumeration columns exist
            {
                // Return a blank for the enumeration column value
                enumCol += "''''::text";
            }
            // alphabetically by name or numerically by row index
            for (String[] functionParm : functionParameters) {
                // Create function to get the data type and variable name column data for the
                // specified table, sorted by variable name. For arrays, only the members are
                // retrieved; the array definitions are ignored
                dbCommand.executeDbCommand(deleteFunction("get_def_columns_by_" + functionParm[0]) + "CREATE FUNCTION get_def_columns_by_" + functionParm[0] + "(name text) RETURNS TABLE(data_type " + "text, variable_name text, bit_length text, " + "rate text, enumeration text) AS $$ " + "BEGIN RETURN QUERY EXECUTE 'SELECT " + dbDataType + ", " + dbVariableName + ", " + dbBitLength + ", " + rateCol + ", " + enumCol + " FROM ' || name || '" + rateJoin + enumJoin + " WHERE " + dbArraySize + " = E'''' OR (array_size ~ E''^" + MACRO_IDENTIFIER + "'' AND (SELECT EXISTS (SELECT " + MacrosColumn.VALUE.getColumnName() + " FROM " + InternalTable.MACROS.getTableName() + " WHERE " + MacrosColumn.MACRO_NAME.getColumnName() + " = replace('''' || array_size || '''', ''" + MACRO_IDENTIFIER + "'', '''') AND " + MacrosColumn.VALUE.getColumnName() + " = ''''))) OR " + dbVariableName + " ~ E''^.+]'' ORDER BY " + functionParm[1] + " ASC'; END $$ LANGUAGE plpgsql; " + buildOwnerCommand(DatabaseObject.FUNCTION, "get_def_columns_by_" + functionParm[0] + "(name text)"), ccddMain.getMainFrame());
            }
            // Database function to search for all tables containing a data type column, and
            // replace a target value with a new value
            dbCommand.executeDbCommand(deleteFunction("update_data_type_names") + "CREATE FUNCTION update_data_type_names(oldType text, " + "newType text) RETURNS VOID AS $$ BEGIN DECLARE row " + "record; BEGIN DROP TABLE IF EXISTS " + TEMP_TABLES + "; CREATE TEMP TABLE " + TEMP_TABLES + " AS SELECT t.tablename AS real_name " + "FROM pg_tables AS t WHERE t.schemaname = 'public' " + "AND substr(t.tablename, 1, " + INTERNAL_TABLE_PREFIX.length() + ") != '" + INTERNAL_TABLE_PREFIX + "'; FOR row IN SELECT * FROM " + TEMP_TABLES + " LOOP IF EXISTS (SELECT 1 FROM " + "information_schema.columns WHERE table_name = " + "row.real_name AND column_name = '" + dbDataType + "') THEN EXECUTE E'UPDATE ' || row.real_name || E' SET " + dbDataType + " = ''' || newType || E''' WHERE " + dbDataType + " = ''' || oldType || E''''; END IF; " + "END LOOP; END; END; $$ LANGUAGE plpgsql; " + buildOwnerCommand(DatabaseObject.FUNCTION, "update_data_type_names(oldType text," + " newType text)"), ccddMain.getMainFrame());
            // Inform the user that the database function creation succeeded
            eventLog.logEvent(SUCCESS_MSG, "Database structure functions created");
        } catch (SQLException se) {
            // Inform the user that creating the database functions failed
            eventLog.logFailEvent(ccddMain.getMainFrame(), "Cannot create structure functions in project database '" + activeDatabase + "' as user '" + activeUser + "'; cause '" + se.getMessage() + "'", "<html><b>Cannot create structure functions in project database '</b>" + activeDatabase + "<b>'");
            errorFlag = true;
        }
    }
    return errorFlag;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) RateInformation(CCDD.CcddClassesDataTable.RateInformation) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Example 4 with RateInformation

use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.

the class CcddRateParameterHandler method getRatesInUse.

/**
 ********************************************************************************************
 * Get the array of the sample rate values for the specified rate column name with those rates
 * not assigned to any telemetry parameter in the structure tables grayed out
 *
 * @param rateName
 *            rate column name
 *
 * @param parent
 *            GUI component calling this method
 *
 * @return Array of the sample rate values for the specified rate column name with those rates
 *         not assigned to any telemetry parameter in the structure tables grayed out; an empty
 *         array if the rate name isn't valid
 ********************************************************************************************
 */
protected String[] getRatesInUse(String rateName, Component parent) {
    String[] availableRates = new String[0];
    // Create the string array list using the second column (rate values) for comparison
    // purposes
    ArrayListMultiple ratesInUse = new ArrayListMultiple(1);
    // Get the rate information for the specified rate
    RateInformation rateInfo = getRateInformationByRateName(rateName);
    // Check if the rate name is recognized
    if (rateInfo != null) {
        // Get a copy of the array of sample rates for this rate. If a copy isn't used then the
        // stored sample rates can be altered to show as disabled below; subsequent calls to
        // get the sample rates will have the disable tags
        availableRates = Arrays.copyOf(rateInfo.getSampleRates(), rateInfo.getSampleRates().length);
        // Query the database for those values of the specified rate that are in use in all
        // tables with a table type representing a structure, including any references in the
        // custom values table. Only unique rate values are returned
        ratesInUse.addAll(dbTable.queryDatabase("SELECT DISTINCT ON (2) * FROM find_columns_by_name('" + rateName + "', '" + DefaultColumn.convertVisibleToDatabase(rateName, InputDataType.RATE, true) + "', '{" + Arrays.toString(tableTypeHandler.getStructureTableTypes()).replaceAll("[\\[\\]]", "") + "}');", parent));
        // Step through the available sample rates
        for (int index = 0; index < availableRates.length; index++) {
            // Check if the rate isn't used by any telemetry parameter
            if (!ratesInUse.contains(availableRates[index])) {
                // Flag the rate as disabled
                availableRates[index] = DISABLED_TEXT_COLOR + availableRates[index];
            }
        }
    }
    return availableRates;
}
Also used : ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) RateInformation(CCDD.CcddClassesDataTable.RateInformation)

Example 5 with RateInformation

use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.

the class CcddRateParameterHandler method renameRateInformation.

/**
 ********************************************************************************************
 * Change the rate column name for in the rate information list. If the original rate column
 * name matches one in another table type then create a new rate entry instead of renaming the
 * existing one. If the new rate column name matches one in another table type then merge it
 * with the existing one and delete the original
 *
 * @param oldRateName
 *            current rate column name
 *
 * @param newRateName
 *            new rate column name
 ********************************************************************************************
 */
protected void renameRateInformation(String oldRateName, String newRateName) {
    // Get the rate information for the original rate column name
    RateInformation rateInfo = getRateInformationByRateName(oldRateName);
    // Check if rate information with this name exists
    if (rateInfo != null) {
        // Check if only a single table type references this rate column name
        if (rateInfo.getNumSharedTableTypes() == 1) {
            // Get the rate information for the new rate column name
            RateInformation rateInfoNew = getRateInformationByRateName(newRateName);
            // Check if the new rate column doesn't already exist
            if (rateInfoNew == null) {
                // Rename the specified rate column and set the flag to indicate a rate is
                // renamed
                rateInfo.setRateName(newRateName);
                // implies the user hasn't chosen a name for the stream
                if (oldRateName.equals(rateInfo.getStreamName())) {
                    // Set the stream name to the new name as well
                    rateInfo.setStreamName(newRateName);
                }
            } else // A rate column by this name already exists
            {
                // Delete the original rate column's information and increment the counter for
                // the 'new' rate column
                deleteRateInformation(oldRateName);
                rateInfoNew.setNumSharedTableTypes(rateInfoNew.getNumSharedTableTypes() + 1);
            }
        } else // This rate column is referenced by another table type
        {
            // Create new rate column information so that the shared one is unchanged and
            // decrement the share counter for the existing rate information
            addRateInformation(newRateName);
            rateInfo.setNumSharedTableTypes(rateInfo.getNumSharedTableTypes() - 1);
        }
    }
}
Also used : RateInformation(CCDD.CcddClassesDataTable.RateInformation)

Aggregations

RateInformation (CCDD.CcddClassesDataTable.RateInformation)22 ArrayList (java.util.ArrayList)7 JPanel (javax.swing.JPanel)5 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 ActionEvent (java.awt.event.ActionEvent)4 DnDTabbedPane (CCDD.CcddClassesComponent.DnDTabbedPane)3 Insets (java.awt.Insets)3 ActionListener (java.awt.event.ActionListener)3 JLabel (javax.swing.JLabel)3 ChangeEvent (javax.swing.event.ChangeEvent)3 ChangeListener (javax.swing.event.ChangeListener)3 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)2 PaddedComboBox (CCDD.CcddClassesComponent.PaddedComboBox)2 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)2 JScrollPane (javax.swing.JScrollPane)2 TableColumn (javax.swing.table.TableColumn)2 ArrayListMultiple (CCDD.CcddClassesComponent.ArrayListMultiple)1 CustomSplitPane (CCDD.CcddClassesComponent.CustomSplitPane)1 ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)1