Search in sources :

Example 21 with GroupInformation

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

the class CcddWebDataAccessHandler method getGroupDescription.

/**
 ********************************************************************************************
 * Get the description for the specified group or application, or all groups/applications with
 * a description 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 groupHandler
 *            group handler
 *
 * @return JSON encoded string containing the specified group's (application's) description;
 *         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 description
 *         or if all groups/applications are requested but none have a description
 *
 * @throws CCDDException
 *             If an error occurs while parsing the group description
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getGroupDescription(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()) {
        // Get an array containing all group/application names
        String[] groupNames = groupHandler.getGroupNames(applicationOnly);
        // Check if any groups/applications exist
        if (groupNames.length != 0) {
            JSONArray responseJA = new JSONArray();
            JSONParser parser = new JSONParser();
            response = "";
            // Step through each group/application name
            for (String name : groupNames) {
                try {
                    // Get the description 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(getGroupDescription(name, applicationOnly, true, groupHandler)));
                } catch (ParseException pe) {
                    throw new CCDDException("error parsing " + (applicationOnly ? "application" : "group") + " description");
                }
            }
            // 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())) {
            JSONObject groupNameAndDesc = new JSONObject();
            // Check if the group name is to be included
            if (includeNameTag) {
                // Add the group name and description to the output
                groupNameAndDesc.put((applicationOnly ? JSONTags.APPLICATION_NAME.getTag() : JSONTags.GROUP_NAME.getTag()), groupName);
                groupNameAndDesc.put((applicationOnly ? JSONTags.APPLICATION_DESCRIPTION.getTag() : JSONTags.GROUP_DESCRIPTION.getTag()), response);
                response = groupNameAndDesc.toString();
            } else // Don't include the name and description tags
            {
                // Get the description. If no description exists then use a blank
                response = groupInfo.getDescription() != null ? groupInfo.getDescription() : "";
            }
        }
    }
    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)

Example 22 with GroupInformation

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

the class CcddWebDataAccessHandler method getGroupFields.

/**
 ********************************************************************************************
 * Get the data field information for the specified group or application, or for all
 * groups/applications if no group name is provided
 *
 * @param groupName
 *            group name. If blank then every data table's data fields are returned
 *
 * @param applicationOnly
 *            true if only groups that represent applications should be processed
 *
 * @param includeNameTag
 *            true to include the group name item and data field tag
 *
 * @param groupHandler
 *            group handler
 *
 * @return JSON encoded string containing the specified group's data fields; null if the group
 *         doesn't exist or if the project database contains no groups, or blank if the group
 *         contains no data fields
 *
 * @throws CCDDException
 *             If an error occurs while parsing the group data fields
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getGroupFields(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()) {
        // Get an array containing all group/application names
        String[] groupNames = groupHandler.getGroupNames(applicationOnly);
        // Check if any groups/applications exist
        if (groupNames.length != 0) {
            JSONArray responseJA = new JSONArray();
            JSONParser parser = new JSONParser();
            // Step through each group/application name
            for (String name : groupNames) {
                try {
                    // Get the fields 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(getGroupFields(name, applicationOnly, true, groupHandler)));
                } catch (ParseException pe) {
                    throw new CCDDException("error parsing " + (applicationOnly ? "application" : "group") + " data fields");
                }
            }
            // Add the table fields to the response
            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 groupFieldsJA = new JSONArray();
            // Build the field information list for this group
            fieldHandler.buildFieldInformation(CcddFieldHandler.getFieldGroupName(groupName));
            // Check if the group has any fields
            if (!fieldHandler.getFieldInformation().isEmpty()) {
                // Get the group data fields (extract the data field array from the table field
                // tag)
                JSONObject fieldsJO = jsonHandler.getDataFields(CcddFieldHandler.getFieldGroupName(groupName), JSONTags.GROUP_FIELD.getTag(), new JSONObject());
                groupFieldsJA = (JSONArray) fieldsJO.get(JSONTags.GROUP_FIELD.getTag());
            }
            // Check if the name tag is to be included
            if (includeNameTag) {
                // Add the group name and group data fields to the output
                JSONObject groupNameAndFields = new JSONObject();
                groupNameAndFields.put((applicationOnly ? JSONTags.APPLICATION_NAME.getTag() : JSONTags.GROUP_NAME.getTag()), groupName);
                groupNameAndFields.put((applicationOnly ? JSONTags.APPLICATION_FIELD.getTag() : JSONTags.GROUP_FIELD.getTag()), groupFieldsJA);
                response = groupNameAndFields.toString();
            } else // Don't include the name and field tags
            {
                // Add the data fields to the output
                response = groupFieldsJA.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)

Example 23 with GroupInformation

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

the class CcddWebDataAccessHandler method getGroupInformation.

/**
 ********************************************************************************************
 * Get the description, associated table(s), and data fields for the specified group or
 * application
 *
 * @param groupName
 *            group name. If blank then every data table's data fields are returned
 *
 * @param applicationOnly
 *            true if only groups that represent applications should be processed
 *
 * @param groupHandler
 *            group handler
 *
 * @return JSON encoded string containing the specified group/application information; null if
 *         a group name is specified and the group/application doesn't exist or if no
 *         groups/applications exist in the project database
 *
 * @throws CCDDException
 *             If an error occurs while parsing the group information
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getGroupInformation(String groupName, boolean applicationOnly, CcddGroupHandler groupHandler) throws CCDDException {
    JSONArray responseJA = new JSONArray();
    JSONParser parser = new JSONParser();
    String response = null;
    String groupType;
    String nameTag;
    String descriptionTag;
    String dataFieldTag;
    String tableTag;
    // Check if only groups that represent applications are to be processed
    if (applicationOnly) {
        groupType = "application";
        nameTag = JSONTags.APPLICATION_NAME.getTag();
        descriptionTag = JSONTags.APPLICATION_DESCRIPTION.getTag();
        dataFieldTag = JSONTags.APPLICATION_FIELD.getTag();
        tableTag = JSONTags.APPLICATION_TABLE.getTag();
    } else // Process groups of any type
    {
        groupType = "group";
        nameTag = JSONTags.GROUP_NAME.getTag();
        descriptionTag = JSONTags.GROUP_DESCRIPTION.getTag();
        dataFieldTag = JSONTags.GROUP_FIELD.getTag();
        tableTag = JSONTags.GROUP_TABLE.getTag();
    }
    // Check if no group name is provided (i.e., get the fields for all groups/applications)
    if (groupName.isEmpty()) {
        // Get an array containing all group/application names
        String[] groupNames = groupHandler.getGroupNames(applicationOnly);
        // Check if any groups/applications exist
        if (groupNames.length != 0) {
            response = "";
            // Step though each group/application
            for (String name : groupNames) {
                try {
                    // Get the fields 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(getGroupInformation(name, applicationOnly, groupHandler)));
                } catch (ParseException pe) {
                    throw new CCDDException("error parsing " + groupType + " information");
                }
            }
            // 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())) {
            try {
                // Store the group's name, description, tables, and data fields
                JSONObject groupInfoJO = new JSONObject();
                groupInfoJO.put(nameTag, groupName);
                groupInfoJO.put(descriptionTag, getGroupDescription(groupName, applicationOnly, false, groupHandler));
                groupInfoJO.put(tableTag, parser.parse(getGroupTables(groupName, applicationOnly, false, groupHandler)));
                groupInfoJO.put(dataFieldTag, parser.parse(getGroupFields(groupName, applicationOnly, false, groupHandler)));
                // Convert the response object to a JSON string
                response = groupInfoJO.toString();
            } catch (ParseException pe) {
                pe.printStackTrace();
                throw new CCDDException("error parsing " + groupType + " information");
            }
        }
    }
    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)

Example 24 with GroupInformation

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

the class CcddTableTreeHandler method buildTableTree.

/**
 ********************************************************************************************
 * (Re)build the table tree from the currently table information
 *
 * @param isExpanded
 *            true if all tree nodes should be expanded, false to collapse all nodes, and null
 *            to use the current status of the expansion check box (if present; if not present
 *            then use false)
 *
 * @param rateName
 *            rate column name used to filter the table tree for variables with rates; null if
 *            the tree is not filtered by data rate
 *
 * @param rateFilter
 *            data rate used to filter the table tree for variables with rates; null if the
 *            tree is not filtered by data rate
 *
 * @param parent
 *            component building this table tree
 ********************************************************************************************
 */
protected void buildTableTree(Boolean isExpanded, String rateName, String rateFilter, Component parent) {
    this.rateName = rateName;
    this.rateFilter = rateFilter;
    // Check if a rate filter is in effect and a filter name is provided
    if (rateFilter != null && rateName != null) {
        // Load all references to rate column values from the custom values table that match
        // the rate name
        rateValues = new ArrayListMultiple();
        rateValues.addAll(dbTable.getCustomValues(rateName, null, parent));
    }
    // Get the index into the table member rate array
    rateIndex = ccddMain.getRateParameterHandler().getRateInformationIndexByRateName(rateName);
    // Set the flag to indicate that the table tree is being built. This flag is used to
    // inhibit actions involving tree selection value changes during the build process
    isBuilding = true;
    // Create the tree's root node using the database name. Since the root node isn't visible
    // there is no need for a description
    root = new ToolTipTreeNode(dbControl.getDatabaseName(), null);
    // Set the root node
    setModel(new DefaultTreeModel(root));
    // Hide the root node (project database name)
    setRootVisible(false);
    // Create a node to display the prototype tables
    ToolTipTreeNode prototype = new ToolTipTreeNode(DEFAULT_PROTOTYPE_NODE_NAME, "Prototype tables");
    instance = new ToolTipTreeNode(DEFAULT_INSTANCE_NODE_NAME, treeType == INSTANCE_TABLES ? "Parent and children tables" : "Parent and children tables, with variables");
    // Add the prototype and instance nodes to the root node
    root.add(prototype);
    root.add(instance);
    // Check if both groups and table type are to be used to filter the table tree
    if (isByGroup && isByType) {
        // Step through the groups
        for (GroupInformation groupInfo : groupHandler.getGroupInformation()) {
            // Create nodes for the group
            ToolTipTreeNode protoGroupNode = new ToolTipTreeNode(groupInfo.getName(), getDescriptions ? groupInfo.getDescription() : null);
            ToolTipTreeNode instGroupNode = new ToolTipTreeNode(groupInfo.getName(), getDescriptions ? groupInfo.getDescription() : null);
            // Add the group node to the prototype and instance nodes
            prototype.add(protoGroupNode);
            instance.add(instGroupNode);
            // Add the group member tables to the group node by table type
            addByType(protoGroupNode, instGroupNode, groupInfo, parent);
        }
        // Add the pseudo-group containing all tables to the prototype and instance nodes
        addAllTablesGroup(prototype, instance, parent);
    } else // Check if groups are to be used to filter the table tree
    if (isByGroup) {
        // Step through the groups
        for (GroupInformation groupInfo : groupHandler.getGroupInformation()) {
            // Create nodes for the group
            ToolTipTreeNode protoGroupNode = new ToolTipTreeNode(groupInfo.getName(), getDescriptions ? groupInfo.getDescription() : null);
            ToolTipTreeNode instGroupNode = new ToolTipTreeNode(groupInfo.getName(), getDescriptions ? groupInfo.getDescription() : null);
            // Add the group node to the instance and prototype nodes
            prototype.add(protoGroupNode);
            instance.add(instGroupNode);
            // / Build the top-level nodes filtered by group
            buildTopLevelNodes(groupInfo.getTableMembers(), instGroupNode, protoGroupNode, parent);
        }
        // Add the pseudo-group containing all tables to the prototype and instance nodes
        addAllTablesGroup(prototype, instance, parent);
    } else // Check if the table types are to be used to filter the table tree
    if (isByType) {
        // Add all tables to the prototype and instances nodes by table type
        addByType(prototype, instance, null, parent);
    } else // Do not use the groups or types to filter the tree
    {
        // Build the root's top-level nodes
        buildTopLevelNodes(null, instance, prototype, parent);
    }
    // Check if only the prototype node should be displayed
    if (treeType == PROTOTYPE_TABLES) {
        // Remove the instance node
        root.remove(instance);
    } else // Check if the only the instance node should be displayed
    if (treeType == INSTANCE_TABLES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES || treeType == INSTANCE_TABLES_WITH_PRIMITIVES) {
        // Remove the prototype node
        root.remove(prototype);
    }
    // Check if the expansion check box exists
    if (expandChkBx != null) {
        // Check is the expansion state is not specified
        if (isExpanded == null) {
            // Set the expansion state to the current expansion check box state
            isExpanded = expandChkBx.isSelected();
        } else // The expansion state is specified
        {
            // Update the expansion check box state to match the specified expansion state
            expandChkBx.setSelected(isExpanded);
        }
    } else // Check is the expansion state is not specified
    if (isExpanded == null) {
        // Set the state to collapse the tree
        isExpanded = false;
    }
    // Force the root node to draw with the node additions
    ((DefaultTreeModel) treeModel).nodeStructureChanged(root);
    // Expand or collapse the tree based on the expansion flag
    setTreeExpansion(isExpanded);
    // Set the node enable states based on the presence of child nodes
    setNodeEnableByChildState(root);
    // Clear the flag that indicates the table tree is being built
    isBuilding = false;
    // Set the renderer for the tree so that the custom icons can be used for the various node
    // types
    setCellRenderer(new TableTreeCellRenderer() {

        /**
         ************************************************************************************
         * Display the variable nodes using a special icon in the tree
         ************************************************************************************
         */
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            // Display the node name
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            // Check if this node represents a variable
            if (leaf && ((ToolTipTreeNode) value).getLevel() > ((CcddTableTreeHandler) tree).getHeaderNodeLevel() && (treeType == STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES)) {
                // Set the icon for the variable node
                setVariableNodeIcon(this, (ToolTipTreeNode) value, row, linkedVariables.contains(removeExtraText(getFullVariablePath(((ToolTipTreeNode) value).getPath()))));
            }
            return this;
        }
    });
}
Also used : JTree(javax.swing.JTree) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Component(java.awt.Component) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

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