Search in sources :

Example 31 with ToolTipTreeNode

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

the class CcddApplicationSchedulerInput method getVariableRelativeIndex.

/**
 ********************************************************************************************
 * Get the index at which the specified application should be inserted in the list of
 * applications provided. The application tree is used to determine the target application's
 * position relative to the applications in the list (if any)
 *
 * @param application
 *            application for which to determine the insertion index
 *
 * @param applications
 *            list of applications into which the application is to be inserted
 *
 * @return Index at which to insert the target application
 ********************************************************************************************
 */
@Override
public int getVariableRelativeIndex(Variable application, List<Variable> applications) {
    int insertIndex = -1;
    // Check if any applications are in the list
    if (!applications.isEmpty()) {
        int targetVarTreeIndex = 0;
        // Step through the application tree's root node's children, if any
        for (Enumeration<?> element = applicationTree.getRootNode().preorderEnumeration(); element.hasMoreElements(); ) {
            // Get the referenced node and its path
            ToolTipTreeNode tableNode = (ToolTipTreeNode) element.nextElement();
            // Check if the target node matches the application tree node
            if (application.getFullName().equals(CcddUtilities.removeHTMLTags(tableNode.getUserObject().toString()))) {
                // The target application is located in the tree; stop searching
                break;
            }
            targetVarTreeIndex++;
        }
        // Step through each application in the list
        for (insertIndex = 0; insertIndex < applications.size(); insertIndex++) {
            int listVarTreeIndex = 0;
            // Step through the application tree's root node's children, if any
            for (Enumeration<?> element = applicationTree.getRootNode().preorderEnumeration(); element.hasMoreElements(); ) {
                // Get the referenced node and its path
                ToolTipTreeNode tableNode = (ToolTipTreeNode) element.nextElement();
                // Check if the target node matches the application tree node
                if (applications.get(insertIndex).getFullName().equals(CcddUtilities.removeHTMLTags(tableNode.getUserObject().toString()))) {
                    // The list application is located in the tree; stop searching
                    break;
                }
                listVarTreeIndex++;
            }
            // position
            if (listVarTreeIndex > targetVarTreeIndex) {
                // determined; stop searching
                break;
            }
        }
    }
    return insertIndex;
}
Also used : ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 32 with ToolTipTreeNode

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

the class CcddInformationTreeHandler method addNode.

/**
 ********************************************************************************************
 * Add a node to the tree
 *
 * @param parentNode
 *            parent node for the new node
 *
 * @param nodeName
 *            name of the node to add
 *
 * @param toolTipText
 *            tool tip text for the new node
 *
 * @param index
 *            index in the parent at which to insert the new node
 *
 * @param order
 *            order in which the added node should be placed relative to the child nodes
 *            already preset
 *
 * @return Reference to the newly added child node
 ********************************************************************************************
 */
private ToolTipTreeNode addNode(ToolTipTreeNode parentNode, String nodeName, String toolTipText, TreeChildOrder order) {
    // Create a node for the new child node
    ToolTipTreeNode childNode = new ToolTipTreeNode(nodeName, toolTipText);
    int index = 0;
    switch(order) {
        case NATURAL:
            // Insert the child node below any existing sibling nodes
            index = parentNode.getChildCount();
            break;
        case ALPHABETICAL:
            // Step through the parent node's children
            for (; index < parentNode.getChildCount(); index++) {
                // name
                if (removeExtraText(((ToolTipTreeNode) parentNode.getChildAt(index)).getUserObject().toString()).compareToIgnoreCase(nodeName) > 0) {
                    // Stop searching the node
                    break;
                }
            }
            break;
        case PATH_ORDER:
            // Combine the parent and child paths
            List<TreeNode> path = new ArrayList<TreeNode>();
            path.addAll(Arrays.asList(parentNode.getPath()));
            path.addAll(Arrays.asList(childNode.getPath()));
            // Set the insertion point to the end of the tree in the event the child isn't in
            // the path order list
            index = parentNode.getChildCount();
            // Get the path of the new child node and locate it within the path order list
            int childIndex = treePathOrder.indexOf(createNameFromPath(path.toArray(new Object[0]), getItemNodeLevel()));
            // Check if the child is present in the path order list
            if (childIndex != -1) {
                // Step backwards through the existing sibling nodes
                for (int nodeIndex = parentNode.getChildCount() - 1; nodeIndex >= 0; nodeIndex--) {
                    // Get the path of the sibling node and locate it within the path order
                    // list
                    ToolTipTreeNode siblingPath = (ToolTipTreeNode) parentNode.getChildAt(nodeIndex);
                    int siblingIndex = treePathOrder.indexOf(createNameFromPath(siblingPath.getPath(), getItemNodeLevel()));
                    // Check if the sibling appears in the path order before the new child
                    if (siblingIndex < childIndex) {
                        // Store the insertion index and stop searching
                        index = nodeIndex + 1;
                        break;
                    }
                }
            }
            break;
    }
    // Insert the new child node at the specified index
    infoTreeModel.insertNodeInto(childNode, parentNode, index);
    // Check if this is the first node added to the tree
    if (parentNode.equals(root) && parentNode.getChildCount() == 1) {
        // Force the root node to draw with the node addition
        infoTreeModel.nodeStructureChanged(root);
    }
    return childNode;
}
Also used : TreeNode(javax.swing.tree.TreeNode) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode) ArrayList(java.util.ArrayList) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 33 with ToolTipTreeNode

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

the class CcddInformationTreeHandler method addSourceNodesToTargetNode.

/**
 ********************************************************************************************
 * Add the specified nodes(s) from the source tree to the specified node(s) in the information
 * tree
 *
 * @param sourcePaths
 *            list containing the node paths for the selected nodes in the source tree
 *
 * @param startIndex
 *            tree level at which the desired node names first appear in the source tree
 *
 * @param onlyIfPrimitive
 *            true to only include nodes that end with a reference to primitive data type;
 *            false to include all nodes
 ********************************************************************************************
 */
protected void addSourceNodesToTargetNode(List<Object[]> sourcePaths, int startIndex, boolean onlyIfPrimitive) {
    // selected in the information tree
    if (sourcePaths != null && getSelectionCount() != 0) {
        List<ToolTipTreeNode> infoNodes = new ArrayList<ToolTipTreeNode>();
        // Step through each selected information node's path
        for (TreePath infoPath : getSelectionPaths()) {
            // Get the top level node for this path
            ToolTipTreeNode infoNode = (ToolTipTreeNode) infoPath.getPathComponent(getGroupNodeLevel());
            // than one node in the top level node's tree is selected
            if (!infoNodes.contains(infoNode)) {
                // Add the top level node to the list so that it won't be checked again
                infoNodes.add(infoNode);
                // Step through each selected node path in the source tree
                for (Object[] sourcePath : sourcePaths) {
                    boolean isPrimitive = false;
                    // should be included
                    if (onlyIfPrimitive) {
                        // Get the name of the last node in the path
                        String lastNode = sourcePath[sourcePath.length - 1].toString();
                        // Get the index that bounds the variable's data type
                        int lastPeriod = lastNode.lastIndexOf(".");
                        // before checking the data type
                        if (lastPeriod != -1 && dataTypeHandler.isPrimitive(removeExtraText(lastNode.substring(0, lastPeriod)))) {
                            // Set the flag to indicate this node references a primitive data
                            // type
                            isPrimitive = true;
                        }
                    }
                    // primitive data type
                    if (!onlyIfPrimitive || isPrimitive) {
                        // Add the source node to this top level node in the information tree
                        addNodeToInfoNode(infoNode, sourcePath, startIndex);
                    }
                }
            }
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 34 with ToolTipTreeNode

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

the class CcddInformationTreeHandler method addNodeToInfoNode.

/**
 ********************************************************************************************
 * Add the specified variable(s) to the specified information node(s)
 *
 * @param node
 *            parent information node for this variable
 *
 * @param sourcePath
 *            array containing the source node path
 *
 * @param startIndex
 *            tree level at which the variable names first appear in the array
 ********************************************************************************************
 */
protected void addNodeToInfoNode(ToolTipTreeNode node, Object[] sourcePath, int startIndex) {
    // Check if the tree is filtered by table type
    if (isFilterByType) {
        // Get the source node's prototype table name
        String protoName = sourcePath[startIndex].toString().split(Pattern.quote("."))[0];
        // Step through each data table comment
        for (String[] tableComment : tableComments) {
            // Check if the table name matches the source node's prototype name
            if (tableComment[TableCommentIndex.NAME.ordinal()].equals(protoName)) {
                int typeIndex = 0;
                // Step through each table type
                for (String type : tableTypeHandler.getTypes()) {
                    // table
                    if (type.equals(tableComment[TableCommentIndex.TYPE.ordinal()])) {
                        // Set the node to the table type node and stop searching
                        node = (ToolTipTreeNode) node.getChildAt(typeIndex);
                        break;
                    }
                    typeIndex++;
                }
                break;
            }
        }
    }
    // Step through the source path
    for (int index = startIndex; index < sourcePath.length; index++) {
        boolean isFound = false;
        // Get the node name at this tree level
        String nodeName = sourcePath[index].toString();
        // Step through the current node's children
        for (int childIndex = 0; childIndex < node.getChildCount(); childIndex++) {
            // Check if the node already contains this source tree's node
            if (node.getChildAt(childIndex).toString().equals(nodeName)) {
                // Update the node to this child node and set the flag indicating the tree node
                // already exists, then stop searching
                node = (ToolTipTreeNode) node.getChildAt(childIndex);
                isFound = true;
                break;
            }
        }
        // Check if this node doesn't exist in the information tree
        if (!isFound) {
            // Add the node to the information tree
            node = addNode(node, nodeName, "", treePathOrder == null ? TreeChildOrder.NATURAL : TreeChildOrder.PATH_ORDER);
            // Expand the tree to display the added node
            expandPath(new TreePath(((ToolTipTreeNode) node.getParent()).getPath()));
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 35 with ToolTipTreeNode

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

the class CcddInformationTreeHandler method removeSelectedTopLevelNodes.

/**
 ********************************************************************************************
 * Remove the currently selected top level node(s) and all of its child nodes from the
 * information tree
 ********************************************************************************************
 */
protected void removeSelectedTopLevelNodes() {
    List<ToolTipTreeNode> removedNodes = new ArrayList<ToolTipTreeNode>();
    // Step through each selected path
    for (TreePath path : getSelectionPaths()) {
        // Get the node for this path
        ToolTipTreeNode node = (ToolTipTreeNode) path.getPathComponent(1);
        // Check if this node has already been removed
        if (!removedNodes.contains(node)) {
            // Add the node to the list of those removed
            removedNodes.add(node);
            // Remove the node from the tree
            infoTreeModel.removeNodeFromParent(node);
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Aggregations

ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)44 ArrayList (java.util.ArrayList)15 TreePath (javax.swing.tree.TreePath)15 BitPackNodeIndex (CCDD.CcddClassesDataTable.BitPackNodeIndex)6 GridBagLayout (java.awt.GridBagLayout)6 JPanel (javax.swing.JPanel)6 Component (java.awt.Component)5 GridBagConstraints (java.awt.GridBagConstraints)5 LinkInformation (CCDD.CcddClassesDataTable.LinkInformation)4 JLabel (javax.swing.JLabel)4 JScrollPane (javax.swing.JScrollPane)4 JTree (javax.swing.JTree)4 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)3 TableMembers (CCDD.CcddClassesDataTable.TableMembers)3 Insets (java.awt.Insets)3 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)3 UndoableTreeModel (CCDD.CcddUndoHandler.UndoableTreeModel)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JTextArea (javax.swing.JTextArea)2