Search in sources :

Example 11 with ArrayListMultiple

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

the class CcddScriptDataAccessHandler method getCopyTableEntries.

/**
 ********************************************************************************************
 * Get the copy table for the messages of the specified data stream. Any macro embedded in a
 * variable name is replaced by its corresponding value
 *
 * @param streamName
 *            data stream name
 *
 * @param headerSize
 *            size of the message header in bytes. For example, the CCSDS header size is 12
 *
 * @param tlmMessageIDs
 *            array containing string array entries giving the structure table path+name and
 *            the table's associated message ID name
 *
 * @param optimize
 *            true to combine memory copy calls for consecutive variables in the copy table
 *
 * @return Array containing the copy table entries; returns blank if there are no entries for
 *         the specified data stream or if data stream name is invalid. Any macro embedded in a
 *         variable name is replaced by its corresponding value
 ********************************************************************************************
 */
public String[][] getCopyTableEntries(String streamName, int headerSize, String[][] tlmMessageIDs, boolean optimize) {
    // Convert the array of structure tables and their message ID names to a list
    ArrayListMultiple tlmMessageIDsList = new ArrayListMultiple();
    tlmMessageIDsList.addAll(Arrays.asList(tlmMessageIDs));
    // Create the copy table with macros expanded
    return getCopyTableEntries(streamName, headerSize, null, tlmMessageIDsList, optimize, true);
}
Also used : ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple)

Example 12 with ArrayListMultiple

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

the class CcddWebDataAccessHandler method getTableNames.

/**
 ********************************************************************************************
 * Get the names of all tables of the specified table type, or all tables names and their types
 * if no table type is provided
 *
 * @param tableType
 *            table type. The type is case insensitive. If blank then every data table and its
 *            type is returned
 *
 * @return JSON encoded string containing all table names of the specified table type; blank if
 *         the type is valid but no tables of the type exist, and null if the specified table
 *         type doesn't exist or if no data tables exist in the project database
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getTableNames(String tableType) {
    String response = null;
    // Get the list of table names and their associated table type
    ArrayListMultiple protoNamesAndTableTypes = new ArrayListMultiple();
    protoNamesAndTableTypes.addAll(dbTable.queryTableAndTypeList(ccddMain.getMainFrame()));
    // Check that at least one data table exists
    if (protoNamesAndTableTypes.size() != 0) {
        JSONArray responseJA = new JSONArray();
        JSONObject responseJO = null;
        // Get the list of table types
        String[] tableTypes = dbTable.queryTableTypesList(ccddMain.getMainFrame());
        // Set the flag to indicate if only one table type is specified or exists
        boolean isSingle = !tableType.isEmpty() || tableTypes.length == 1;
        // Step through each valid table type
        for (String type : tableTypes) {
            // matches the one specified
            if (tableType.isEmpty() || type.equalsIgnoreCase(tableType)) {
                // Check if this is the first valid table type match
                if (response == null) {
                    // Initialize the output; this causes a blank to be returned if the type is
                    // valid but no tables of the type exist
                    response = "";
                }
                responseJO = new JSONObject();
                JSONArray namesJA = new JSONArray();
                // Step through each table name
                for (String tableName : getTableList()) {
                    // Locate the table's prototype in the list
                    int index = protoNamesAndTableTypes.indexOf(tableName.replaceFirst(",.*$", ""));
                    // Check if the root table name matches that in the types list
                    if (type.equalsIgnoreCase(protoNamesAndTableTypes.get(index)[2])) {
                        // Add the table to the list for this table type
                        namesJA.add(tableName);
                    }
                }
                // Store the table type and associated table name(s)
                responseJO.put(JSONTags.TABLE_TYPE.getTag(), type);
                responseJO.put(JSONTags.TABLE_NAMES.getTag(), namesJA);
                // Check if only one table type is being processed
                if (isSingle) {
                    // Stop searching
                    break;
                }
                // More than one table is in the response; add the type and names to the array
                responseJA.add(responseJO);
            }
        }
        // Check if the specified table type exists, or any type exists if none is specified
        if (response != null) {
            // Set the response based of if a single or multiple types are included in the
            // response. If single then the JSON object is used to prevent the extraneous
            // brackets from enclosing the response
            response = (isSingle) ? responseJO.toString() : responseJA.toString();
        }
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) JSONArray(org.json.simple.JSONArray)

Example 13 with ArrayListMultiple

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

the class CcddWebDataAccessHandler method getStructureSize.

/**
 ********************************************************************************************
 * Get the number of bytes for the prototype of the specified structure table, or for all
 * prototype structure tables if no table is specified
 *
 * @param tableName
 *            structure table name or path
 *
 * @return JSON encoded string containing the structure table name(s) and corresponding size(s)
 *         in bytes; null if a table name is specified and the table doesn't exist or isn't a
 *         structure, or if no structure tables exist in the project database
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getStructureSize(String tableName) {
    String response = null;
    JSONObject responseJO = null;
    JSONArray responseJA = new JSONArray();
    // Get the list of table names and their associated table type
    ArrayListMultiple protoNamesAndTableTypes = new ArrayListMultiple();
    protoNamesAndTableTypes.addAll(dbTable.queryTableAndTypeList(ccddMain.getMainFrame()));
    // Get the specified table's prototype table name
    String prototypeName = TableInformation.getPrototypeName(tableName);
    // Flag indicating if a single table is requested
    boolean isSingle = !prototypeName.isEmpty();
    // Step through each prototype table name/type
    for (String[] namesAndType : protoNamesAndTableTypes) {
        // specified name
        if (!isSingle || prototypeName.equalsIgnoreCase(namesAndType[0])) {
            // Get the table's type definition
            TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(namesAndType[2]);
            // Check if the table represents a structure
            if (typeDefn.isStructure()) {
                responseJO = new JSONObject();
                // Check if the link handler exists
                if (linkHandler == null) {
                    // Create a link handler
                    linkHandler = new CcddLinkHandler(ccddMain, ccddMain.getMainFrame());
                }
                // Store the table name and its size in bytes
                responseJO.put(JSONTags.TABLE_NAME.getTag(), (isSingle ? tableName : namesAndType[0]));
                responseJO.put(JSONTags.TABLE_BYTE_SIZE.getTag(), variableHandler.getDataTypeSizeInBytes(namesAndType[0]));
                // Check if only one table is being processed
                if (isSingle) {
                    // Stop searching
                    break;
                }
                // More than one table is in the response; add the name and size to the array
                responseJA.add(responseJO);
            }
        }
    }
    // none is specified
    if (responseJO != null) {
        // Set the response based of if a single or multiple types are included in the
        // response. If single then the JSON object is used to prevent the extraneous brackets
        // from enclosing the response
        response = (isSingle) ? responseJO.toString() : responseJA.toString();
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) JSONArray(org.json.simple.JSONArray) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Example 14 with ArrayListMultiple

use of CCDD.CcddClassesComponent.ArrayListMultiple 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

ArrayListMultiple (CCDD.CcddClassesComponent.ArrayListMultiple)14 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)4 ArrayList (java.util.ArrayList)3 Component (java.awt.Component)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 BoxLayout (javax.swing.BoxLayout)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 AutoCompleteTextField (CCDD.CcddClassesComponent.AutoCompleteTextField)1 MultilineLabel (CCDD.CcddClassesComponent.MultilineLabel)1 ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)1 CCDDException (CCDD.CcddClassesDataTable.CCDDException)1 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)1 RateInformation (CCDD.CcddClassesDataTable.RateInformation)1 TableTypeDefinition (CCDD.CcddClassesDataTable.TableTypeDefinition)1 AvailabilityType (CCDD.CcddConstants.AvailabilityType)1