use of CCDD.CcddUndoHandler.UndoableTreeModel in project CCDD by nasa.
the class CcddLinkTreeHandler method adjustNodeText.
/**
********************************************************************************************
* Append the sample rate and size in bytes to the nodes representing a link name. Set the node
* text color based on the currently selected sample rate and the rate of the link 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) {
// Step through the elements and children of this node
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 link name from the node path
String linkName = removeExtraText(node.getPath()[1].toString());
// Get the reference to the link's information. The link name is the second node in
// the path for this node
LinkInformation linkInfo = getLinkInformation(linkName);
// Check that the node references a link
if (linkInfo != null) {
// Get the node name
String nodeName = removeExtraText(node.getUserObject().toString());
// Check if this node represents a link name
if (level == 1) {
// Assign the link name formatted as HTML
nodeName = "<html>" + linkName + " <i>(";
// Get the link size in bytes
int sizeInBytes = linkHandler.getLinkSizeInBytes(linkInfo.getRateName(), linkName);
// Check if the size is non-zero; i.e., variables are assigned to this link
if (sizeInBytes != 0) {
// Append the link size to the link name
nodeName += linkInfo.getSampleRate() + " Hz, " + sizeInBytes + (sizeInBytes == 1 ? " byte)" : " bytes)");
} else // No variables are assigned to this link
{
// Indicate that the link is empty
nodeName += "empty)";
}
}
// Check if the selected sample rate doesn't match the link's rate
if (!linkInfo.getSampleRate().equals("0") && !selectedRate.equals(linkInfo.getSampleRate())) {
// Gray out the node text
nodeName = DISABLED_TEXT_COLOR + nodeName;
}
// Update the node name. Indicate that the node changed so that the tree
// redraws the name
node.setUserObject(nodeName);
((UndoableTreeModel) getModel()).nodeChanged(node);
}
}
}
}
use of CCDD.CcddUndoHandler.UndoableTreeModel 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;
}
Aggregations