Search in sources :

Example 1 with GroupInformation

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

the class CcddGroupManagerDialog method isGroupsChanged.

/**
 ********************************************************************************************
 * Check if the groups differ from those last committed to the database
 *
 * @return true if the group definitions have changed
 ********************************************************************************************
 */
private boolean isGroupsChanged() {
    // Store any changes to the currently selected group, if applicable
    updateSelectedGroupInformation();
    // Get the current group definitions from the group tree
    currentGroups = groupTree.createDefinitionsFromTree();
    // Initialize the change flag to true if the number of current and committed group
    // definitions differ
    boolean hasChanges = currentGroups.size() != committedGroups.size();
    // Check if the number of groups is the same
    if (!hasChanges) {
        // Step through the current group list
        for (String[] curGrp : currentGroups) {
            boolean isFound = false;
            // Step through the committed group list
            for (String[] comGrp : committedGroups) {
                // Check if the current group entry matches the committed group entry
                if (Arrays.equals(curGrp, comGrp)) {
                    // Set the flag indicating a match and stop searching
                    isFound = true;
                    break;
                }
            }
            // Check if no matching entry was found
            if (!isFound) {
                // Set the flag indicating a group has changed and stop searching
                hasChanges = true;
                break;
            }
        }
    }
    // Get the reference to the updated group information
    List<GroupInformation> currentGroupFields = groupHandler.getGroupInformation();
    // Create storage for the updated data fields
    updateFields = new ArrayList<List<FieldInformation>>();
    // Step through each current group
    for (GroupInformation currentInfo : currentGroupFields) {
        boolean isDiffers = false;
        // Get the group name
        String groupName = currentInfo.getName();
        // Get a reference to the group's committed information
        GroupInformation committedInfo = groupHandler.getGroupInformationByName(committedGroupFields, groupName);
        // Check if the group isn't new
        if (committedInfo != null) {
            // Set the flag if the number of fields, field attributes, or field contents have
            // changed
            isDiffers = CcddFieldHandler.isFieldChanged(currentInfo.getFieldInformation(), committedInfo.getFieldInformation(), true);
        } else // This is a new group
        {
            // Set the flag indicating that the new group's data fields should be added to the
            // change list
            isDiffers = true;
        }
        // Check if the group is new or an existing group's data field changed
        if (isDiffers) {
            // Check if the group has any data fields
            if (!currentInfo.getFieldInformation().isEmpty()) {
                // Add the data fields for this group to the list of those changed
                updateFields.add(currentInfo.getFieldInformation());
            }
            // Set the flag indicating a group has changes
            hasChanges = true;
        }
    }
    return hasChanges;
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with GroupInformation

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

the class CcddGroupManagerDialog method newGroup.

/**
 ********************************************************************************************
 * Add a new group to the group tree
 ********************************************************************************************
 */
private void newGroup() {
    // Create a panel to contain the dialog components
    JPanel dialogPnl = new JPanel(new GridBagLayout());
    // Create the group name input dialog label and field
    GridBagConstraints gbc = addGroupNameField("Enter new group name", "", dialogPnl);
    // Create the group description label
    JLabel descriptionLbl = new JLabel("Description");
    descriptionLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    descriptionLbl.setForeground(ModifiableColorInfo.LABEL_TEXT.getColor());
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
    gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.weighty = 0.0;
    gbc.gridy++;
    dialogPnl.add(descriptionLbl, gbc);
    // Create the group description input field
    final JTextArea descriptionFld = new JTextArea("", 3, 1);
    descriptionFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    descriptionFld.setEditable(true);
    descriptionFld.setLineWrap(true);
    descriptionFld.setWrapStyleWord(true);
    descriptionFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    descriptionFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
    descriptionFld.setBorder(emptyBorder);
    descriptionFld.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    descriptionFld.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    JScrollPane descScrollPane = new JScrollPane(descriptionFld);
    descScrollPane.setBorder(border);
    // Add the description field to the dialog panel
    gbc.insets.top = 0;
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy++;
    dialogPnl.add(descScrollPane, gbc);
    // Create a check box for setting the group as an application
    JCheckBox appCb = new JCheckBox("Group represents a CFS application");
    appCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    appCb.setBorder(emptyBorder);
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    gbc.gridy++;
    dialogPnl.add(appCb, gbc);
    // Create a dialog for the new group information
    CcddDialogHandler groupDlg = new CcddDialogHandler() {

        /**
         ************************************************************************************
         * Verify that the dialog content is valid
         *
         * @return true if the input values are valid
         ************************************************************************************
         */
        @Override
        protected boolean verifySelection() {
            descriptionFld.setText(descriptionFld.getText().trim());
            return verifyGroupName(this);
        }
    };
    // Display a dialog for the user to provide a group name and description
    if (groupDlg.showOptionsDialog(groupMgr, dialogPnl, "New Group", DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
        // Disable automatically ending the edit sequence. This allows the added group's edits
        // to be grouped into a single sequence so that if undone, all edits are removed
        // together
        undoHandler.setAutoEndEditSequence(false);
        // Add the new group information
        groupHandler.addGroupInformation(groupNameFld.getText(), descriptionFld.getText(), appCb.isSelected());
        // Insert the new group into the group tree
        groupTree.addInformationNode(groupNameFld.getText(), descriptionFld.getText(), appCb.isSelected());
        // Check if the check box indicating this group represents an application is selected
        if (appCb.isSelected()) {
            // Get the field information and data fields for the new group
            GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupNameFld.getText());
            List<FieldInformation> fieldInfo = CcddFieldHandler.getFieldInformationCopy(groupInfo.getFieldInformation());
            // Step through each default application data field
            for (DefaultApplicationField field : DefaultApplicationField.values()) {
                // Add the field to the group
                fieldInfo.add(field.createFieldInformation(CcddFieldHandler.getFieldGroupName(groupNameFld.getText())));
            }
        }
        // Update the group dialog's change indicator
        updateChangeIndicator();
        // Re-enable automatic edit sequence ending, then end the edit sequence to group the
        // added group's edits
        undoHandler.setAutoEndEditSequence(true);
        undoManager.endEditSequence();
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) DefaultApplicationField(CCDD.CcddConstants.DefaultApplicationField) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 3 with GroupInformation

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

the class CcddGroupHandler method buildGroupInformation.

/**
 ********************************************************************************************
 * Build the group information using the group definitions and the field information in the
 * database
 *
 * @param groupDefinitions
 *            list of group definitions
 ********************************************************************************************
 */
protected void buildGroupInformation(List<String[]> groupDefinitions) {
    // Clear the groups from the list
    groupInformation.clear();
    // Check if a group definition exists
    if (groupDefinitions != null) {
        // Step through the group definitions
        for (String[] groupDefn : groupDefinitions) {
            // Extract the link name and rate/description or member
            String groupName = groupDefn[GroupsColumn.GROUP_NAME.ordinal()];
            String groupMember = groupDefn[GroupsColumn.MEMBERS.ordinal()];
            // CFS application
            if (groupMember.matches("\\d.*")) {
                // Separate the CFS application identifier and description text
                String[] appAndDesc = groupMember.split(",", 2);
                // Create the group with its description and application status
                groupInformation.add(new GroupInformation(groupName, appAndDesc[1], !appAndDesc[0].equals("0"), null));
            } else // This is a group's variable path
            {
                // Get the reference to this group's information
                GroupInformation groupInfo = getGroupInformationByName(groupName);
                // Check that the group exists
                if (groupInfo != null) {
                    // Add the table to the group's table list
                    groupInfo.addTable(groupMember);
                }
            }
        }
        // Sort the group information by group name
        sortGroupInformation();
    }
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation)

Example 4 with GroupInformation

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

the class CcddGroupTreeHandler method adjustNodeText.

/**
 ********************************************************************************************
 * Set the node text color based on the currently selected schedule rate and the rate of the
 * group to which the node belongs: black for a match and gray for a mismatch
 *
 * @param startNode
 *            starting node for which to adjust the text and color
 ********************************************************************************************
 */
protected void adjustNodeText(ToolTipTreeNode startNode, List<String> excludes) {
    // Step through the node's children, if any
    for (Enumeration<?> element = startNode.preorderEnumeration(); element.hasMoreElements(); ) {
        // Get the node reference
        ToolTipTreeNode node = (ToolTipTreeNode) element.nextElement();
        // Get the tree level for this node
        int level = node.getLevel();
        // called when no nodes exist
        if (level > 0) {
            // Get the group name from the node. The group name is the second node in the path
            // for this node
            String groupName = removeExtraText(node.getPath()[1].toString());
            // Get the reference to the group's information
            GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupName);
            // Check that the node references a group
            if (groupInfo != null) {
                // Get the node name
                String nodeName = node.getUserObject().toString();
                // Set to true if the group in this path is not excluded (as evidenced by
                // having a HTML tag)
                boolean wasExcluded = nodeName.contains(DISABLED_TEXT_COLOR);
                // Remove any HTML tags or other extra text from the node name
                nodeName = removeExtraText(nodeName);
                // Get the reference to the schedule rate field information
                fieldHandler.setFieldInformation(groupInfo.getFieldInformation());
                FieldInformation rateInfo = fieldHandler.getFieldInformationByName(CcddFieldHandler.getFieldGroupName(groupName), DefaultApplicationField.SCHEDULE_RATE.getFieldName());
                // Set the flag indicating the group is excluded if it's in the exclusion list
                boolean isExcluded = rateInfo == null || rateInfo.getValue().isEmpty() || !scheduleRate.equals(rateInfo.getValue()) || excludes.contains(nodeName);
                // Check if the group's exclusion state has changed
                if (wasExcluded != isExcluded) {
                    // Reset the node name to indicate its inclusion/exclusion state. If
                    // excluded, prepend the HTML tag to gray out the name. Indicate that the
                    // node changed so that the tree redraws the name
                    node.setUserObject((isExcluded ? DISABLED_TEXT_COLOR : "") + nodeName);
                    ((DefaultTreeModel) getModel()).nodeChanged(node);
                }
            }
        }
    }
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 5 with GroupInformation

use of CCDD.CcddClassesDataTable.GroupInformation 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)

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