Search in sources :

Example 11 with ToolTipTreeNode

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

the class CcddGroupTreeHandler method buildTree.

/**
 ********************************************************************************************
 * Build the group tree from the database
 *
 * @param filterByType
 *            true if the tree is filtered by table type
 *
 * @param filterByApp
 *            true if the tree is filtered by application status
 *
 * @param scheduleRate
 *            schedule rate used to filter the groups; blank or null if not filtering by
 *            schedule rate
 *
 * @param isApplicationOnly
 *            true to only display groups that represent a CFS application
 *
 * @param parent
 *            GUI component calling this method
 ********************************************************************************************
 */
@Override
protected void buildTree(boolean filterByType, boolean filterByApp, String scheduleRate, boolean isApplicationOnly, Component parent) {
    this.isFilterByType = filterByType;
    this.isFilterByApp = filterByApp;
    this.scheduleRate = scheduleRate;
    super.buildTree(isFilterByType, isFilterByApp, scheduleRate, isApplicationOnly, parent);
    // Get the tree's root node
    root = getRootNode();
    // Build the group information using the group definitions and group data fields from the
    // database
    groupHandler.buildGroupInformation(groupDefinitions);
    buildFieldInformation(parent);
    // Register the tool tip manager for the group tree (otherwise the tool tips aren't
    // displayed)
    ToolTipManager.sharedInstance().registerComponent(this);
    // Set the flag to indicate that the group tree is being built. This flag is used to
    // inhibit actions involving tree selection value changes during the build process
    isBuilding = true;
    // Set the renderer for the tree so that 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);
            // Get the tree level for this node
            int level = ((ToolTipTreeNode) value).getLevel();
            // Check if this node represents a group name
            if (level == 1) {
                // Display an icon indicating a variable
                setIcon(new ImageIcon(getClass().getResource(GROUP_ICON)));
            }
            return this;
        }
    });
    // Check if the table types are to be used to filter the table tree
    if (isFilterByType) {
        // Create the node storage for the table types
        typeNodes = new ToolTipTreeNode[tableTypeHandler.getTypes().length];
    }
    // Check if the application statuses are to be used to filter the group tree
    if (isFilterByApp) {
        // Create the node storage for the application statuses
        appNodes = new ToolTipTreeNode[2];
        appNodes[0] = addInformationNode(APP_NODE, "Groups representing a CFS application");
        appNodes[1] = addInformationNode(OTHER_NODE, "Groups not representing a CFS application");
    }
    // Step through each group
    for (GroupInformation groupInfo : groupHandler.getGroupInformation()) {
        // Extract the group name
        String groupName = groupInfo.getName();
        // application
        if (!isApplicationOnly || groupInfo.isApplication()) {
            // Create a node for the group and add it to the group tree
            ToolTipTreeNode groupNode = addInformationNode(groupName, groupInfo.getDescription(), groupInfo.isApplication());
            // supplied)
            if (scheduleRate == null || scheduleRate.isEmpty()) {
                // Check if the table types are to be used to filter the table tree
                if (isFilterByType) {
                    int index = 0;
                    // Step through each table type
                    for (String type : tableTypeHandler.getTypes()) {
                        // Create the node for this table type and add it to the tree model
                        typeNodes[index] = new ToolTipTreeNode(type, tableTypeHandler.getTypeDefinition(type).getDescription());
                        ((UndoableTreeModel) getModel()).insertNodeInto(typeNodes[index], groupNode, index);
                        index++;
                    }
                }
                // Step through each table belonging to the group
                for (String table : groupInfo.getTablesAndAncestors()) {
                    // Check if the groups are filtered by application status
                    if (isFilterByApp) {
                        boolean isFound = false;
                        // match is found
                        for (int nodeIndex = 0; nodeIndex < appNodes.length && !isFound; nodeIndex++) {
                            // Step through each current group node
                            for (int index = 0; index < appNodes[nodeIndex].getChildCount(); index++) {
                                // Check if the group name matches the node name
                                if (groupName.equals(appNodes[nodeIndex].getChildAt(index).toString())) {
                                    // Add the indicating a match is found, and stop searching
                                    addNodeToInfoNode((ToolTipTreeNode) appNodes[nodeIndex].getChildAt(index), table.split(","), 0);
                                    isFound = true;
                                    break;
                                }
                            }
                        }
                    } else // Groups are not filtered by application status
                    {
                        // Step through each current group node
                        for (int index = 0; index < root.getChildCount(); index++) {
                            // Check if the group name matches the node name
                            if (groupName.equals(root.getChildAt(index).toString())) {
                                // Add the table to the node and stop searching
                                addNodeToInfoNode((ToolTipTreeNode) root.getChildAt(index), table.split(","), 0);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    // Expand or collapse the tree based on the expansion flag
    setTreeExpansion(isExpanded);
    // Clear the flag that indicates the group tree is being built
    isBuilding = false;
}
Also used : ImageIcon(javax.swing.ImageIcon) JTree(javax.swing.JTree) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) UndoableTreeModel(CCDD.CcddUndoHandler.UndoableTreeModel) Component(java.awt.Component) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 12 with ToolTipTreeNode

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

the class CcddDbVerificationHandler method verifyDataTables.

/**
 ********************************************************************************************
 * Check that the tables' data are consistent with their type definitions. If any
 * inconsistencies are detected then get user approval to alter the table(s)
 ********************************************************************************************
 */
private void verifyDataTables() {
    // Build the table tree
    CcddTableTreeHandler tableTree = new CcddTableTreeHandler(ccddMain, TableTreeType.PROTOTYPE_TABLES, ccddMain.getMainFrame());
    // Initialize the storage for each table's information and committed data
    tableStorage = new ArrayList<TableStorage>();
    // Initialize the progress bar within-step value counters
    int count = 0;
    int startProgress = progBar.getValue();
    // Get the total number of rows in the table tree
    int total = tableTree.getNodeCount(tableTree.getRootNode());
    // Step through the root node's children
    for (Enumeration<?> element = tableTree.getRootNode().preorderEnumeration(); element.hasMoreElements(); ) {
        count++;
        // Check if the user canceled verification
        if (canceled) {
            break;
        }
        // Get the referenced node and the path to the node
        ToolTipTreeNode tableNode = (ToolTipTreeNode) element.nextElement();
        TreePath path = new TreePath(tableNode.getPath());
        // Check if the path references a table
        if (path.getPathCount() > tableTree.getHeaderNodeLevel()) {
            // Get the information from the database for the specified table
            TableInformation tableInfo = dbTable.loadTableData(tableTree.getFullVariablePath(path.getPath()), false, false, false, ccddMain.getMainFrame());
            // Check if the table loaded successfully and that the table has data
            if (!tableInfo.isErrorFlag() && tableInfo.getData().length > 0) {
                // Add the table information and data to the list. This stores a copy of the
                // data (as it appears in the database) so that any changes made can be
                // detected
                tableStorage.add(new TableStorage(tableInfo, tableInfo.getData()));
                // Get the table's type definition
                typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
                // Get the variable name, data type, and array size column indices for this
                // table type
                variableNameIndex = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
                dataTypeIndex = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
                arraySizeIndex = typeDefn.getColumnIndexByInputType(InputDataType.ARRAY_INDEX);
                // Initialize the array check parameters: array data type, name, number of
                // members, array dimension sizes, and current index position
                String dataType = "";
                String arrayName = "";
                membersRemaining = 0;
                totalArraySize = new int[0];
                currentArrayIndex = new int[0];
                // Initialize the array definition and last missing array member row indices
                definitionRow = 0;
                int lastMissingRow = 0;
                // Step through each row in the table
                for (int row = 0; row < tableInfo.getData().length && !canceled; row++) {
                    // Step through each column in the table
                    for (int column = 0; column < tableInfo.getData()[row].length && !canceled; column++) {
                        // Check if the cell value doesn't match the cell's input type
                        checkInputType(tableInfo, row, column);
                    }
                    // Check if the user canceled verification
                    if (canceled) {
                        continue;
                    }
                    // Check if this is a structure table
                    if (typeDefn.isStructure()) {
                        // Check if the array size isn't blank
                        if (tableInfo.getData()[row][arraySizeIndex] != null && !tableInfo.getData()[row][arraySizeIndex].isEmpty()) {
                            // definition is expected
                            if (membersRemaining == 0) {
                                // Get the variable name for this row
                                arrayName = tableInfo.getData()[row][variableNameIndex];
                                // Store the index of the array definition row
                                definitionRow = row;
                                // Store the row number for use if other members are found to
                                // be missing after all other rows have been checked
                                lastMissingRow = row;
                                // Check that no extra array member exists
                                if (!checkExcessArrayMember(tableInfo, row, arrayName)) {
                                    // Get the number of array members remaining and data type
                                    // for this row and initialize the array index
                                    totalArraySize = ArrayVariable.getArrayIndexFromSize(macroHandler.getMacroExpansion(tableInfo.getData()[row][arraySizeIndex]));
                                    // Get the total number of members for this array
                                    membersRemaining = ArrayVariable.getNumMembersFromArrayDimension(totalArraySize);
                                    // Initialize the current array index values
                                    currentArrayIndex = new int[totalArraySize.length];
                                    // Get the data type
                                    dataType = tableInfo.getData()[row][dataTypeIndex];
                                    // Check if the expected array definition is missing
                                    if (checkForArrayDefinition(tableInfo, row, arrayName)) {
                                        // Remove the array index from the array variable name
                                        // and back up a row so that the array members can be
                                        // checked
                                        arrayName = ArrayVariable.removeArrayIndex(arrayName);
                                        row--;
                                    }
                                }
                            } else // This is not the first pass through this array; i.e., an array
                            // member is expected
                            {
                                // have the same variable name
                                if (checkArrayNamesMatch(tableInfo, row, arrayName)) {
                                    // Back up a row so that it can be checked as a separate
                                    // variable
                                    row--;
                                } else // The array names match
                                {
                                    // Check if the array definition and all of its members
                                    // have the same array size
                                    checkArraySizesMatch(tableInfo, row, arrayName, tableInfo.getData()[row][arraySizeIndex]);
                                    // Check if the array definition and all of its members
                                    // have the same data type
                                    checkDataTypesMatch(tableInfo, row, arrayName, dataType);
                                    // Store the row number for use if other members are found
                                    // to be missing after all other rows have been checked
                                    lastMissingRow = row;
                                }
                                // Update the array member counters
                                membersRemaining--;
                                // Update the current array index value(s)
                                goToNextArrayMember();
                            }
                        } else // Check if there are remaining array members that don't exist
                        {
                            // Check if an array member is expected but not present
                            checkForMissingArrayMember(tableInfo, row, arrayName);
                        }
                    }
                }
                // Check if this is a structure table
                if (typeDefn.isStructure()) {
                    // Perform for each remaining missing array member
                    while (membersRemaining != 0) {
                        // Check if there are remaining array members that don't exist
                        checkForMissingArrayMember(tableInfo, lastMissingRow + 1, arrayName);
                    }
                }
                // Check if the flag to make changes is not already set
                if (!isChanges) {
                    // Check if a row is missing based on the row indices
                    checkForRowIndexMismatch(tableInfo);
                }
                // Check if columns marked as unique contain duplicate values
                checkForDuplicates(tableInfo);
            }
        }
        // Update the within-step progress value
        progBar.setValue(startProgress + (numDivisionPerStep * count / total));
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TableInformation(CCDD.CcddClassesDataTable.TableInformation) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 13 with ToolTipTreeNode

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

the class CcddAssignmentTreeHandler method buildTree.

/**
 ********************************************************************************************
 * Build the assignment tree from the database. Retain the tree's current expansion state
 *
 * @param filterByType
 *            true if the tree is filtered by table type. This is not applicable to the
 *            assignment tree, which can only contain structure references
 *
 * @param filterByApp
 *            true if the tree is filtered by application. This is not applicable to the
 *            assignment tree, which can only contain structure references
 *
 * @param filterValue
 *            rate column name and message name, separated by a back slash
 *
 * @param filterFlag
 *            flag used to filter the tree content. Not used for the assignment tree
 *
 * @param parent
 *            GUI component calling this method
 ********************************************************************************************
 */
@Override
protected void buildTree(boolean filterByType, boolean filterByApp, String filterValue, boolean filterFlag, Component parent) {
    // Store the tree's current expansion state
    String expState = getExpansionState();
    super.buildTree(false, false, filterValue, filterFlag, parent);
    // Get the tree's root node
    ToolTipTreeNode root = getRootNode();
    // Register the tool tip manager for the assignment tree (otherwise the tool tips aren't
    // displayed)
    ToolTipManager.sharedInstance().registerComponent(this);
    // Set the flag to indicate that the assignment tree is being built. This flag is used to
    // inhibit actions involving tree selection value changes during the build process
    isBuilding = true;
    // Set the renderer for the tree so that 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) {
                // Set the icon for the variable node
                setVariableNodeIcon(this, (ToolTipTreeNode) value, row, linkHandler.getVariableLink(getFullVariablePath(((ToolTipTreeNode) value).getPath()), rateName) != null);
            }
            return this;
        }
    });
    // Check if a filter value is provided
    if (filterValue != null) {
        // Parent message name; remains blank if the definition is not a sub-message
        String parentMessage = "";
        // Separate the rate and message name from the filter value
        String[] rateAndMessage = filterValue.split("\\" + TLM_SCH_SEPARATOR);
        // Store the rate
        rateName = rateAndMessage[0];
        // Get the sub-message separator index
        int subIndex = rateAndMessage[1].indexOf(".");
        // Check if this is a sub-message definition
        if (subIndex != -1) {
            // Extract the parent message name from the sub-message name
            parentMessage = rateAndMessage[1].substring(0, subIndex);
        }
        // Step through each assignment definition
        for (String[] assignDefn : assignDefinitions) {
            // name
            if (assignDefn[TlmSchedulerColumn.RATE_NAME.ordinal()].equals(rateAndMessage[0]) && !assignDefn[TlmSchedulerColumn.MEMBER.ordinal()].isEmpty() && (assignDefn[TlmSchedulerColumn.MESSAGE_NAME.ordinal()].equals(rateAndMessage[1]) || assignDefn[TlmSchedulerColumn.MESSAGE_NAME.ordinal()].equals(parentMessage))) {
                // Add the variable to the node
                addNodeToInfoNode(root, assignDefn[TlmSchedulerColumn.MEMBER.ordinal()].split("\\" + TLM_SCH_SEPARATOR, 2)[1].split(","), 0);
            }
        }
        // Expand or collapse the tree based on the expansion flag
        setTreeExpansion(isExpanded);
        // Restore the expansion state
        setExpansionState(expState);
    }
    // Clear the flag that indicates the assignment tree is being built
    isBuilding = false;
}
Also used : JTree(javax.swing.JTree) Component(java.awt.Component) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 14 with ToolTipTreeNode

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

the class CcddCommonTreeHandler method addChildNodes.

/**
 ********************************************************************************************
 * Recursively add the children of the specified node to the path list. If these are variable
 * paths and the node represents a bit-wise or string variable then add the bit-packed/string
 * members as well
 *
 * @param node
 *            current child node to check
 *
 * @param selectedPaths
 *            list containing the selected paths
 *
 * @param excludedPaths
 *            list of paths to be excluded from the tree
 *
 * @param isVariable
 *            true if the tree contains variables
 ********************************************************************************************
 */
protected void addChildNodes(ToolTipTreeNode node, List<Object[]> selectedPaths, List<String> excludedPaths, boolean isVariable) {
    // Check if this node has no children
    if (node.getChildCount() == 0) {
        boolean isAdded = false;
        // Get the node name to shorten subsequent calls
        String nodeName = node.getUserObject().toString();
        // as excluded (i.e., starts with an HTML tag)
        if (excludedPaths == null || !nodeName.startsWith("<html>")) {
            // siblings
            if (node.getSiblingCount() > 1) {
                BitPackNodeIndex nodeIndex = null;
                // Check if this is a variable tree
                if (isVariable) {
                    // Check if it represents a bit-wise variable
                    if (nodeName.contains(":")) {
                        // Get the node indices that encompass the packed variables (if
                        // applicable)
                        nodeIndex = getBitPackedVariables(node);
                    } else // Not a bit-wise variable
                    {
                        // Extract the data type name form the node name
                        String dataType = nodeName.substring(0, nodeName.indexOf("."));
                        // Check if this is a string
                        if (dataTypeHandler.isString(dataType)) {
                            // Get the node indices that encompass the string array members
                            nodeIndex = getStringVariableMembers(node);
                        }
                    }
                }
                // Check if packed variables or string members are present
                if (nodeIndex != null) {
                    // Calculate the tree node index for the first packed/string variable
                    int treeIndex = node.getParent().getIndex(node) - (nodeIndex.getTableIndex() - nodeIndex.getFirstIndex());
                    // Step through each packed/string variable
                    for (int index = nodeIndex.getFirstIndex(); index <= nodeIndex.getLastIndex(); index++, treeIndex++) {
                        boolean isInList = false;
                        // Get the path for the variable
                        Object[] path = ((ToolTipTreeNode) node.getParent().getChildAt(treeIndex)).getPath();
                        // Step through the paths already added
                        for (Object[] selPath : selectedPaths) {
                            // Check if the path is already in the list
                            if (Arrays.equals(path, selPath)) {
                                // Set the flag to indicate the path is already in the list and
                                // stop searching
                                isInList = true;
                                break;
                            }
                        }
                        // Check if the variable wasn't already in the list
                        if (!isInList) {
                            // Add the variable to the selected variables list
                            selectedPaths.add(path);
                        }
                    }
                    // Set the flag indicating the variable is added
                    isAdded = true;
                }
            }
            // Check if the variable isn't already added above
            if (!isAdded) {
                // Add the variable path to the list
                selectedPaths.add(node.getPath());
            }
        }
    } else // The node has child nodes
    {
        // Step through each child node
        for (int index = 0; index < node.getChildCount(); index++) {
            // Check if the child node has children
            addChildNodes((ToolTipTreeNode) node.getChildAt(index), selectedPaths, excludedPaths, isVariable);
        }
    }
}
Also used : BitPackNodeIndex(CCDD.CcddClassesDataTable.BitPackNodeIndex) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 15 with ToolTipTreeNode

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

the class CcddScriptManagerDialog method initialize.

/**
 ********************************************************************************************
 * Create the script association manager dialog. This is executed in a separate thread since it
 * can take a noticeable amount time to complete, and by using a separate thread the GUI is
 * allowed to continue to update. The GUI menu commands, however, are disabled until the
 * telemetry scheduler initialization completes execution
 ********************************************************************************************
 */
private void initialize() {
    // user confirms ignoring the changes
    if (ccddMain.ignoreUncommittedChanges("Script Manager", "Ignore changes?", false, null, CcddScriptManagerDialog.this)) {
        // Build the script association manager dialog in the background
        CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {

            // Create panels to hold the components of the dialog
            JPanel dialogPnl = new JPanel(new GridBagLayout());

            JPanel buttonPnl = new JPanel();

            /**
             ********************************************************************************
             * Build the script association manager dialog
             ********************************************************************************
             */
            @Override
            protected void execute() {
                isNodeSelectionChanging = false;
                // 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()));
                Border emptyBorder = BorderFactory.createEmptyBorder();
                // Set the initial layout manager characteristics
                GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()), 0, 0);
                dialogPnl.setBorder(emptyBorder);
                // Create a panel to contain the script file name, association name, and
                // association description labels and fields
                JPanel inputPnl = new JPanel(new GridBagLayout());
                // Add the script file selection components to the input panel
                inputPnl.add(createScriptSelectionPanel(), gbc);
                // Create the name label and field, and add these to the input panel
                JLabel nameLbl = new JLabel("Script association name");
                nameLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
                gbc.gridy++;
                inputPnl.add(nameLbl, gbc);
                nameFld = new JTextField("", 1);
                nameFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
                nameFld.setEditable(true);
                nameFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
                nameFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
                nameFld.setBorder(border);
                gbc.insets.top = 0;
                gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
                gbc.weightx = 1.0;
                gbc.gridy++;
                inputPnl.add(nameFld, gbc);
                // Create the description label and field, and add these to the input panel
                JLabel descriptionLbl = new JLabel("Script association description");
                descriptionLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
                gbc.insets.left = 0;
                gbc.weightx = 0.0;
                gbc.gridy++;
                inputPnl.add(descriptionLbl, gbc);
                descriptionFld = new JTextArea("", 3, 1);
                descriptionFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
                descriptionFld.setEditable(true);
                descriptionFld.setWrapStyleWord(true);
                descriptionFld.setLineWrap(true);
                descriptionFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
                descriptionFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
                descriptionFld.setBorder(emptyBorder);
                JScrollPane scrollPane = new JScrollPane(descriptionFld);
                scrollPane.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
                scrollPane.setBorder(emptyBorder);
                scrollPane.setViewportBorder(border);
                scrollPane.setMinimumSize(scrollPane.getPreferredSize());
                gbc.insets.top = 0;
                gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
                gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() * 2;
                gbc.gridwidth = GridBagConstraints.REMAINDER;
                gbc.weightx = 1.0;
                gbc.weighty = 1.0;
                gbc.gridy++;
                inputPnl.add(scrollPane, gbc);
                // Add the input panel and the table selection components to the inputs pane
                // within a horizontally split pane. Use a separator to denote the split pane's
                // drag component
                JSeparator inputSep = new JSeparator(SwingConstants.VERTICAL);
                inputSep.setForeground(dialogPnl.getBackground().darker());
                CustomSplitPane inputsPane = new CustomSplitPane(inputPnl, createSelectionPanel("Select associated tables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION), inputSep, JSplitPane.HORIZONTAL_SPLIT);
                // Add the inputs pane and the script association table components to the
                // dialog within a vertically split pane. Use a separator to denote the split
                // pane's drag component
                JSeparator assnSep = new JSeparator();
                assnSep.setForeground(dialogPnl.getBackground().darker());
                gbc.weighty = 1.0;
                gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
                gbc.insets.bottom = 0;
                gbc.gridy = 0;
                dialogPnl.add(new CustomSplitPane(inputsPane, scriptHandler.getAssociationsPanel("Script Associations", true, CcddScriptManagerDialog.this), assnSep, JSplitPane.VERTICAL_SPLIT), gbc);
                // Get a reference to the script associations table to shorten subsequent calls
                assnsTable = scriptHandler.getAssociationsTable();
                // Store the initial table data
                doAssnUpdatesComplete(false);
                // Add a listener for script association table row selection changes
                assnsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                    /**
                     ************************************************************************
                     * Handle a table row selection change. Populate the script description
                     * field, file field, and table tree based on the first selected
                     * associations table row
                     ************************************************************************
                     */
                    @Override
                    public void valueChanged(ListSelectionEvent lse) {
                        // for a keyboard input this returns false)
                        if (!lse.getValueIsAdjusting()) {
                            // Get the first selected table row
                            int row = assnsTable.getSelectedRow();
                            // Check if a table row item is selected
                            if (row != -1) {
                                // Store the association name in the the name field
                                nameFld.setText(assnsTable.getValueAt(row, assnsTable.convertColumnIndexToView(AssociationsTableColumnInfo.NAME.ordinal())).toString());
                                // Store the association description in the the description
                                // field
                                descriptionFld.setText(assnsTable.getValueAt(row, assnsTable.convertColumnIndexToView(AssociationsTableColumnInfo.DESCRIPTION.ordinal())).toString());
                                // Store the script file name with path in the the script file
                                // field
                                scriptFld.setText(assnsTable.getValueAt(row, assnsTable.convertColumnIndexToView(AssociationsTableColumnInfo.SCRIPT_FILE.ordinal())).toString());
                                // Separate the table member portion into the individual table
                                // names. The line breaks used for HTML formatting must be
                                // replaced by line feed characters so that the split is made
                                // correctly
                                String[] tableNames = CcddUtilities.removeHTMLTags(assnsTable.getValueAt(row, assnsTable.convertColumnIndexToView(AssociationsTableColumnInfo.MEMBERS.ordinal())).toString().replaceAll("<br>", "\n")).split(Pattern.quote(ASSN_TABLE_SEPARATOR));
                                List<TreePath> paths = new ArrayList<>();
                                // Step through each table name
                                for (String tableName : tableNames) {
                                    ToolTipTreeNode node;
                                    // Check if the name refers to a group
                                    if (tableName.startsWith(GROUP_DATA_FIELD_IDENT)) {
                                        // Get the node in the table tree for this group
                                        node = tableTree.getNodeByNodeName(tableName.substring(GROUP_DATA_FIELD_IDENT.length()));
                                    } else // The name refers to a table
                                    {
                                        // Get the node in the table tree for this table name
                                        node = tableTree.getNodeByNodePath(tableName);
                                    }
                                    // Check if the table name is in the tree
                                    if (node != null) {
                                        // Add the path to the list
                                        paths.add(CcddCommonTreeHandler.getPathFromNode(node));
                                    }
                                }
                                // Select the associated tables in the table tree
                                tableTree.setSelectionPaths(paths.toArray(new TreePath[0]));
                            }
                        }
                    }
                });
                // Define the buttons for the lower panel: Add association button
                JButton btnAddAssn = CcddButtonPanelHandler.createButton("Add", INSERT_ICON, KeyEvent.VK_A, "Add the currently defined script association");
                // Add a listener for the Add button
                btnAddAssn.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Add a new script association
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        // Check that a script is specified
                        if (!scriptFld.getText().trim().isEmpty()) {
                            addAssociation(TableInsertionPoint.START);
                        } else // The script file field is blank
                        {
                            // Inform the user that a script must be selected
                            new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>Must enter or select a script", "Script Missing", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                        }
                    }
                });
                // Remove script association(s) button
                JButton btnRemoveAssn = CcddButtonPanelHandler.createButton("Remove", DELETE_ICON, KeyEvent.VK_R, "Remove the selected script association(s)");
                // Add a listener for the Remove button
                btnRemoveAssn.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Remove the selected script association(s)
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        removeAssociations();
                    }
                });
                // Replace script association(s) button
                JButton btnReplaceAssn = CcddButtonPanelHandler.createButton("Replace", REPLACE_ICON, KeyEvent.VK_P, "Replace the selected script association");
                // Add a listener for the Replace button
                btnReplaceAssn.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Replace the selected script association
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        replaceAssociation();
                    }
                });
                // Move Up button
                JButton btnMoveUp = CcddButtonPanelHandler.createButton("Up", UP_ICON, KeyEvent.VK_U, "Move the selected row(s) up");
                // Create a listener for the Move Up command
                btnMoveUp.addActionListener(new ValidateCellActionListener() {

                    /**
                     ************************************************************************
                     * Move the selected row(s) up in the table
                     ************************************************************************
                     */
                    @Override
                    protected void performAction(ActionEvent ae) {
                        assnsTable.moveRowUp();
                    }

                    /**
                     ************************************************************************
                     * Get the reference to the currently displayed table
                     ************************************************************************
                     */
                    @Override
                    protected CcddJTableHandler getTable() {
                        return assnsTable;
                    }
                });
                // Move Down button
                JButton btnMoveDown = CcddButtonPanelHandler.createButton("Down", DOWN_ICON, KeyEvent.VK_W, "Move the selected row(s) down");
                // Create a listener for the Move Down command
                btnMoveDown.addActionListener(new ValidateCellActionListener() {

                    /**
                     ************************************************************************
                     * Move the selected row(s) down in the table
                     ************************************************************************
                     */
                    @Override
                    protected void performAction(ActionEvent ae) {
                        assnsTable.moveRowDown();
                    }

                    /**
                     ************************************************************************
                     * Get the reference to the currently displayed table
                     ************************************************************************
                     */
                    @Override
                    protected CcddJTableHandler getTable() {
                        return assnsTable;
                    }
                });
                // Undo button
                JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
                // Create a listener for the Undo command
                btnUndo.addActionListener(new ValidateCellActionListener() {

                    /**
                     ************************************************************************
                     * Undo the last addition to the script association table
                     ************************************************************************
                     */
                    @Override
                    protected void performAction(ActionEvent ae) {
                        assnsTable.getUndoManager().undo();
                    }

                    /**
                     ************************************************************************
                     * Get the reference to the currently displayed table
                     ************************************************************************
                     */
                    @Override
                    protected CcddJTableHandler getTable() {
                        return assnsTable;
                    }
                });
                // Redo button
                JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
                // Create a listener for the Redo command
                btnRedo.addActionListener(new ValidateCellActionListener() {

                    /**
                     ************************************************************************
                     * Redo the last addition to the script association table that was undone
                     ************************************************************************
                     */
                    @Override
                    protected void performAction(ActionEvent ae) {
                        assnsTable.getUndoManager().redo();
                    }

                    /**
                     ************************************************************************************
                     * Get the reference to the currently displayed table
                     ************************************************************************************
                     */
                    @Override
                    protected CcddJTableHandler getTable() {
                        return assnsTable;
                    }
                });
                // Script execution button
                btnExecute = CcddButtonPanelHandler.createButton("Execute", EXECUTE_ICON, KeyEvent.VK_E, "Execute the selected script association(s)");
                // Add a listener for the Execute button
                btnExecute.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Execute the selected script association(s)
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        // Execute the selected associations
                        scriptHandler.executeScriptAssociations(tableTree, CcddScriptManagerDialog.this);
                    }
                });
                // Store script associations button
                JButton btnStoreAssns = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the updated script associations to the database");
                // Add a listener for the Store button
                btnStoreAssns.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Store the script associations in the database
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        // associations
                        if (assnsTable.isTableChanged(committedAssnsData, Arrays.asList(new Integer[] { AssociationsTableColumnInfo.AVAILABLE.ordinal() })) && new CcddDialogHandler().showMessageDialog(CcddScriptManagerDialog.this, "<html><b>Store script associations?", "Store Associations", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                            // Disable the dialog buttons until the updates complete
                            setControlsEnabled(false);
                            // Store the script associations list into the database
                            dbTable.storeInformationTableInBackground(InternalTable.ASSOCIATIONS, createAssociationsFromTable(), null, CcddScriptManagerDialog.this);
                        }
                    }
                });
                // Close button
                JButton btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the script association manager");
                // Add a listener for the Close button
                btnClose.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Close the script association dialog
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        // user elects to discard the changes
                        if (!isAssociationsChanged() || new CcddDialogHandler().showMessageDialog(CcddScriptManagerDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                            // Reset the reference to the script associations manager in the
                            // script handler since the handler remains active)
                            scriptHandler.setScriptDialog(null);
                            // Close the dialog
                            closeFrame();
                        }
                    }
                });
                // Add buttons in the order in which they'll appear (left to right, top to
                // bottom)
                buttonPnl.add(btnAddAssn);
                buttonPnl.add(btnReplaceAssn);
                buttonPnl.add(btnMoveUp);
                buttonPnl.add(btnUndo);
                buttonPnl.add(btnStoreAssns);
                buttonPnl.add(btnRemoveAssn);
                buttonPnl.add(btnExecute);
                buttonPnl.add(btnMoveDown);
                buttonPnl.add(btnRedo);
                buttonPnl.add(btnClose);
                // Distribute the buttons across two rows
                setButtonRows(2);
            }

            /**
             ********************************************************************************
             * Script association manager dialog creation complete
             ********************************************************************************
             */
            @Override
            protected void complete() {
                // Display the script association management dialog
                createFrame(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnExecute, DIALOG_TITLE, null);
            }
        });
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) CustomSplitPane(CCDD.CcddClassesComponent.CustomSplitPane) JSeparator(javax.swing.JSeparator) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) TableInsertionPoint(CCDD.CcddConstants.TableInsertionPoint) ListSelectionListener(javax.swing.event.ListSelectionListener) TreePath(javax.swing.tree.TreePath) ActionListener(java.awt.event.ActionListener) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder)

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