Search in sources :

Example 16 with GroupInformation

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

the class CcddGroupManagerDialog method copyGroupInformation.

/**
 ********************************************************************************************
 * Store a copy of the group information
 ********************************************************************************************
 */
private void copyGroupInformation() {
    committedGroupFields = new ArrayList<GroupInformation>();
    // Store the group definitions
    committedGroups = groupTree.createDefinitionsFromTree();
    // Step through each group
    for (GroupInformation groupInfo : groupHandler.getGroupInformation()) {
        // Create a copy of the group information and store it in the committed group list
        GroupInformation newInfo = new GroupInformation(groupInfo.getName(), null, null, null, CcddFieldHandler.getFieldInformationCopy(groupInfo.getFieldInformation()));
        committedGroupFields.add(newInfo);
    }
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation)

Example 17 with GroupInformation

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

the class CcddGroupManagerDialog method copyGroup.

/**
 ********************************************************************************************
 * Copy the selected group
 ********************************************************************************************
 */
private void copyGroup() {
    // Get the selected group(s)
    String[] selected = groupTree.getTopLevelSelectedNodeNames();
    // Check that a single node is selected in the group tree
    if (selected.length == 1) {
        // Get the group information for the selected group
        GroupInformation groupInfo = groupHandler.getGroupInformationByName(selected[0]);
        // Create a panel to contain the dialog components
        JPanel dialogPnl = new JPanel(new GridBagLayout());
        // Create the group copying dialog label and field
        addGroupNameField("Copy '" + selected[0] + "' to:", selected[0] + "_copy", dialogPnl);
        // Create the group copying dialog
        CcddDialogHandler groupDlg = new CcddDialogHandler() {

            /**
             ********************************************************************************
             * Verify that the dialog content is valid
             *
             * @return true if the input values are valid
             ********************************************************************************
             */
            @Override
            protected boolean verifySelection() {
                return verifyGroupName(this);
            }
        };
        // Display the group copying dialog
        if (groupDlg.showOptionsDialog(groupMgr, dialogPnl, "Copy Group", DialogOption.COPY_OPTION, true) == OK_BUTTON) {
            // Disable automatically ending the edit sequence. This allows all of the copied
            // group's edits to be grouped into a single sequence so that if undone, all of the
            // group's edits are restored together
            undoHandler.setAutoEndEditSequence(false);
            // Copy the group node in the group tree
            groupTree.copyNodeTree(groupInfo.getName(), groupNameFld.getText(), groupInfo);
            // Copy the target group's data fields to the copy of the group
            groupHandler.getGroupInformationByName(groupNameFld.getText()).setFieldInformation(CcddFieldHandler.getFieldInformationCopy(groupInfo.getFieldInformation()));
            // Step through each data field in the copied group
            for (FieldInformation fieldInfo : groupHandler.getGroupInformationByName(groupNameFld.getText()).getFieldInformation()) {
                // Set the data field owner to the copy's group name
                fieldInfo.setOwnerName(CcddFieldHandler.getFieldGroupName(groupNameFld.getText()));
            }
            // Update the group dialog's change indicator
            updateChangeIndicator();
            // Re-enable automatic edit sequence ending, then end the edit sequence to group
            // the renamed group's edits
            undoHandler.setAutoEndEditSequence(true);
            undoManager.endEditSequence();
        }
    }
}
Also used : JPanel(javax.swing.JPanel) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) GridBagLayout(java.awt.GridBagLayout) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 18 with GroupInformation

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

the class CcddScriptDataAccessHandler method getGroupFields.

/**
 ********************************************************************************************
 * Get an array containing the data field information for the specified group
 *
 * @param groupName
 *            group name
 *
 * @return Array containing the data field information for the specified group; an empty array
 *         if the group has no data fields, or the group doesn't exist. The array in is the
 *         format: field name, description, size, input type, required (true or false),
 *         applicability, value[,...]
 ********************************************************************************************
 */
public String[][] getGroupFields(String groupName) {
    List<String[]> groupFields = new ArrayList<String[]>();
    // Get a reference to the group's information
    GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupName);
    // Check if the group exists
    if (groupInfo != null) {
        // Step through each data field belonging to the group
        for (FieldInformation fieldInfo : groupInfo.getFieldInformation()) {
            // Add the data field information to the list
            groupFields.add(new String[] { fieldInfo.getFieldName(), fieldInfo.getDescription(), Integer.toString(fieldInfo.getSize()), fieldInfo.getInputType().getInputName(), Boolean.toString(fieldInfo.isRequired()), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue() });
        }
    }
    return groupFields.toArray(new String[0][0]);
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) ArrayList(java.util.ArrayList) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 19 with GroupInformation

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

the class CcddWebDataAccessHandler method getTelemetryInformation.

/**
 ********************************************************************************************
 * Get the path, data type, bit length, description, units, data stream information, and
 * enumeration information for each telemetered variable matching the specified filters
 *
 * @param telemetryFilter
 *            group (or application) name, data stream name, and/or rate value filter(s). A
 *            table must belong to the specified group in order for its telemetered variables
 *            to be returned; blank to get all telemetered variables (regardless of group). A
 *            variable must have a rate assigned for the specified data stream in order to be
 *            included; blank to include all data streams. A variable's rate must match the
 *            specified rate in order to be included; blank to include the variable regardless
 *            of the rate value
 *
 * @return JSON encoded string containing the path, data type, bit length, description, units,
 *         data stream name(s), and enumeration(s) for each telemetered variable matching the
 *         specified filters; empty array if no variables are telemetered
 *
 * @throws CCDDException
 *             If an invalid group name, data stream name, or rate value format is detected
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getTelemetryInformation(String telemetryFilter) throws CCDDException {
    JSONArray telemetryJA = new JSONArray();
    TypeDefinition typeDefn = null;
    String groupFilter = "";
    String streamFilter = "";
    String rateFilter = "";
    int variableNameIndex = -1;
    int dataTypeIndex = -1;
    int bitLengthIndex = -1;
    List<Integer> rateIndices = null;
    List<Integer> enumerationIndices = null;
    int descriptionIndex = -1;
    int unitsIndex = -1;
    List<String> allTableNameList = new ArrayList<String>();
    // Table type name for the previous table type loaded
    String lastType = "";
    // Get the array of data stream names
    String[] dataStreamNames = rateHandler.getDataStreamNames();
    // Check if a filter is specified
    if (!telemetryFilter.isEmpty()) {
        // Separate the filter parameters
        String[] filter = getParts(telemetryFilter, ",", 3, true);
        // if present, is in the expected format
        if ((filter[1].isEmpty() || Arrays.asList(dataStreamNames).contains(filter[1])) && (filter[2].isEmpty() || filter[2].matches("\\d+(?:$|(?:\\.|\\s*/\\s*)\\d+)"))) {
            // Store the group name, stream name, and rate filters
            groupFilter = filter[0];
            streamFilter = filter[1];
            rateFilter = filter[2];
            // Check if a group name filter is specified
            if (!groupFilter.isEmpty()) {
                // Create a group handler and extract the table names belonging to the group
                CcddGroupHandler groupHandler = new CcddGroupHandler(ccddMain, null, ccddMain.getMainFrame());
                GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupFilter);
                // Check if the group doesn't exist
                if (groupInfo == null) {
                    throw new CCDDException("unrecognized group name");
                }
                // Get the tables associated with the group
                allTableNameList = groupInfo.getTablesAndAncestors();
            }
        } else // Unrecognized data stream name or invalid rate value format
        {
            throw new CCDDException("unrecognized stream name or invalid rate value format");
        }
    }
    // Check if no group filter is in effect
    if (groupFilter.isEmpty()) {
        // Get a list of all root and child tables
        tableTreeType = TableTreeType.INSTANCE_TABLES;
        allTableNameList = getTableList();
    }
    // Step through each structure table
    for (String table : allTableNameList) {
        // Get the information from the database for the specified table
        TableInformation tableInfo = dbTable.loadTableData(table, false, false, false, ccddMain.getMainFrame());
        // Check if the table loaded successfully
        if (!tableInfo.isErrorFlag()) {
            // Get the table's type definition
            typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
            // Check if the table represents a structure
            if (typeDefn.isStructure()) {
                // every table
                if (!tableInfo.getType().equals(lastType)) {
                    String descColName;
                    String unitsColName;
                    descriptionIndex = -1;
                    unitsIndex = -1;
                    // Store the table type name
                    lastType = tableInfo.getType();
                    // Get the variable name column
                    variableNameIndex = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
                    // Get the data type column
                    dataTypeIndex = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
                    // Get the bit length column
                    bitLengthIndex = typeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH);
                    // Check if a data stream filter is in effect
                    if (!streamFilter.isEmpty()) {
                        // Get the index of the rate column corresponding to the data stream
                        // filter
                        rateIndices = new ArrayList<Integer>();
                        // Get the index of the rate column with the corresponding data stream
                        // name
                        int rateIndex = typeDefn.getColumnIndexByUserName(rateHandler.getRateInformationByStreamName(streamFilter).getRateName());
                        // Check if the table has the specified rate column
                        if (rateIndex != -1) {
                            // Add the rate column index to the list
                            rateIndices.add(typeDefn.getColumnIndexByUserName(rateHandler.getRateInformationByStreamName(streamFilter).getRateName()));
                        }
                    } else // Include all data streams
                    {
                        // Get the indices for all rate columns
                        rateIndices = typeDefn.getColumnIndicesByInputType(InputDataType.RATE);
                    }
                    // Get the enumeration column(s)
                    enumerationIndices = typeDefn.getColumnIndicesByInputType(InputDataType.ENUMERATION);
                    // Check if a description column exists
                    if ((descColName = typeDefn.getColumnNameByInputType(InputDataType.DESCRIPTION)) != null) {
                        // Get the description column
                        descriptionIndex = typeDefn.getColumnIndexByUserName(descColName);
                    }
                    // Check if a units column exists
                    if ((unitsColName = typeDefn.getColumnNameByInputType(InputDataType.UNITS)) != null) {
                        // Get the units column
                        unitsIndex = typeDefn.getColumnIndexByUserName(unitsColName);
                    }
                }
                // values
                if (isReplaceMacro) {
                    // Replace all macros in the table
                    tableInfo.setData(ccddMain.getMacroHandler().replaceAllMacros(tableInfo.getData()));
                }
                // Step through each variable in the structure table
                for (int row = 0; row < tableInfo.getData().length; row++) {
                    JSONObject structureJO = new JSONObject();
                    String cellValue;
                    // on this row is skipped
                    if (!(cellValue = tableInfo.getData()[row][variableNameIndex]).isEmpty()) {
                        boolean hasRate = false;
                        // Step through the relevant rate columns
                        for (Integer rateIndex : rateIndices) {
                            // rate filter value (or no filter is in effect)
                            if (!tableInfo.getData()[row][rateIndex].isEmpty() && (rateFilter.isEmpty() || tableInfo.getData()[row][rateIndex].equals(rateFilter))) {
                                hasRate = true;
                                // Store the rate in the JSON output
                                structureJO.put(typeDefn.getColumnNamesUser()[rateIndex], tableInfo.getData()[row][rateIndex]);
                            }
                        }
                        // Check if a variable matching the rate filters exists
                        if (hasRate) {
                            // Store the name of the structure table from which this variable
                            // is taken
                            structureJO.put("Structure Table Name", table);
                            // Store the variable name in the JSON output
                            structureJO.put(typeDefn.getColumnNamesUser()[variableNameIndex], cellValue);
                            // Check if the data type is present
                            if (!(cellValue = tableInfo.getData()[row][dataTypeIndex]).isEmpty()) {
                                // Store the data type in the JSON output
                                structureJO.put(typeDefn.getColumnNamesUser()[dataTypeIndex], cellValue);
                            }
                            // Check if the bit length is present
                            if (!(cellValue = tableInfo.getData()[row][bitLengthIndex]).isEmpty()) {
                                // Store the bit length in the JSON output
                                structureJO.put(typeDefn.getColumnNamesUser()[bitLengthIndex], cellValue);
                            }
                            // Step through each enumeration column
                            for (Integer enumerationIndex : enumerationIndices) {
                                // Check if the enumeration is present
                                if (!(cellValue = tableInfo.getData()[row][enumerationIndex]).isEmpty()) {
                                    // Store the enumeration in the JSON output
                                    structureJO.put(typeDefn.getColumnNamesUser()[enumerationIndex], cellValue);
                                }
                            }
                            // Check if the description is present
                            if (descriptionIndex != -1 && !(cellValue = tableInfo.getData()[row][descriptionIndex]).isEmpty()) {
                                // Store the description in the JSON output
                                structureJO.put(typeDefn.getColumnNamesUser()[descriptionIndex], cellValue);
                            }
                            // Check if the units is present
                            if (unitsIndex != -1 && !(cellValue = tableInfo.getData()[row][unitsIndex]).isEmpty()) {
                                // Store the units in the JSON output
                                structureJO.put(typeDefn.getColumnNamesUser()[descriptionIndex], cellValue);
                            }
                            // Add the variable to the JSON array
                            telemetryJA.add(structureJO);
                        }
                    }
                }
            }
        }
    }
    return telemetryJA.toString();
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) CCDDException(CCDD.CcddClassesDataTable.CCDDException) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) JSONObject(org.json.simple.JSONObject) TableInformation(CCDD.CcddClassesDataTable.TableInformation)

Example 20 with GroupInformation

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

the class CcddWebDataAccessHandler method getGroupTables.

/**
 ********************************************************************************************
 * Get the tables associated with the specified group or application, or for all
 * groups/applications if no group name is provided
 *
 * @param groupName
 *            group name. If blank then every group's (application's) descriptions are returned
 *
 * @param applicationOnly
 *            true if only groups that represent applications should be processed
 *
 * @param includeNameTag
 *            true to include the group name item
 *
 * @param groupHandler
 *            group handler
 *
 * @return JSON encoded string containing the specified group's (application's) table members;
 *         null if the specified group/application doesn't exist or the project has no
 *         groups/applications, or blank if the specified group/application has no table member
 *         or if all groups/applications are requested but none have a table member
 *
 * @throws CCDDException
 *             If an error occurs while parsing the group tables
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getGroupTables(String groupName, boolean applicationOnly, boolean includeNameTag, CcddGroupHandler groupHandler) throws CCDDException {
    String response = null;
    // Check if no group name is provided (i.e., get the fields for all groups/applications)
    if (groupName.isEmpty()) {
        JSONArray responseJA = new JSONArray();
        JSONParser parser = new JSONParser();
        // Get an array containing all group/application names
        String[] groupNames = groupHandler.getGroupNames(applicationOnly);
        // Check if any groups/applications exist
        if (groupNames.length != 0) {
            // Step through each group/application name
            for (String name : groupNames) {
                try {
                    // Get the data for this group as a JSON string, then format it as a JSON
                    // object so that is can be added to the response array. This is needed to
                    // get the brackets and commas in the JSON formatted string correct
                    responseJA.add(parser.parse(getGroupTables(name, applicationOnly, true, groupHandler)));
                } catch (ParseException pe) {
                    throw new CCDDException("error parsing " + (applicationOnly ? "application" : "group") + " tables");
                }
            }
            // Convert the response array to a JSON string
            response = responseJA.toString();
        }
    } else // A group name is provided
    {
        // Get the group information for the specified group
        GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupName);
        // application is requested and this group represents an application
        if (groupInfo != null && (!applicationOnly || groupInfo.isApplication())) {
            JSONArray dataJA = new JSONArray();
            // Get the list of the group's tables
            List<String> tables = groupInfo.getTablesAndAncestors();
            // Step through each table
            for (String table : tables) {
                // Add the table to the array
                dataJA.add(table);
            }
            // Add the group name and description to the list. An array is used to preserve the
            // order of the items
            JSONObject groupNameAndTable;
            // Add the group tables. If the group has no tables then the table data is blank
            groupNameAndTable = new JSONObject();
            // Check if the group name is to be included
            if (includeNameTag) {
                // Add the group name and tables to the output
                groupNameAndTable.put((applicationOnly ? JSONTags.APPLICATION_NAME.getTag() : JSONTags.GROUP_NAME.getTag()), groupName);
                groupNameAndTable.put((applicationOnly ? JSONTags.APPLICATION_TABLE.getTag() : JSONTags.GROUP_TABLE.getTag()), dataJA);
                response = groupNameAndTable.toString();
            } else // Don't include the name and table tags
            {
                // Add the tables to the output
                response = dataJA.toString();
            }
        }
    }
    return response;
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Aggregations

GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)24 FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)7 ArrayList (java.util.ArrayList)7 CCDDException (CCDD.CcddClassesDataTable.CCDDException)6 JSONArray (org.json.simple.JSONArray)6 JSONObject (org.json.simple.JSONObject)6 JSONParser (org.json.simple.parser.JSONParser)4 ParseException (org.json.simple.parser.ParseException)4 ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)3 GridBagLayout (java.awt.GridBagLayout)3 JPanel (javax.swing.JPanel)3 TableInformation (CCDD.CcddClassesDataTable.TableInformation)2 DefaultApplicationField (CCDD.CcddConstants.DefaultApplicationField)2 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)2 Component (java.awt.Component)2 GridBagConstraints (java.awt.GridBagConstraints)2 JLabel (javax.swing.JLabel)2 JTree (javax.swing.JTree)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)1