use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddTableTreeHandler method createTreePanel.
/**
********************************************************************************************
* Create a table tree panel. The table tree is placed in a scroll pane. A check box is added
* that allows tree expansion/collapse
*
* @param label
* table tree title
*
* @param selectionMode
* tree item selection mode (single versus multiple)
*
* @param parent
* GUI component calling this method
*
* @return JPanel containing the table tree components
********************************************************************************************
*/
protected JPanel createTreePanel(String label, int selectionMode, final Component parent) {
// Create an empty border
Border emptyBorder = BorderFactory.createEmptyBorder();
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
// Set the table tree selection mode
getSelectionModel().setSelectionMode(selectionMode);
// Create a panel to contain the table tree
JPanel treePnl = new JPanel(new GridBagLayout());
treePnl.setBorder(emptyBorder);
// Check if a label is provided
if (label != null && !label.isEmpty()) {
// Create the tree labels
JLabel treeLbl = new JLabel(label);
treeLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
treeLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
treePnl.add(treeLbl, gbc);
gbc.gridy++;
}
// Create the tree scroll pane
JScrollPane treeScroll = new JScrollPane(this);
treeScroll.setBorder(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())));
// Add the tree to the panel
gbc.weighty = 1.0;
treePnl.add(treeScroll, gbc);
// Set the table tree font and number of rows to display
setFont(ModifiableFontInfo.TREE_NODE.getFont());
setVisibleRowCount(10);
// Add a listener for changes to the table tree
addTreeSelectionListener(new TreeSelectionListener() {
/**
************************************************************************************
* Handle a change to the table tree selection
************************************************************************************
*/
@Override
public void valueChanged(TreeSelectionEvent lse) {
// tree selection value changes that should not be processed
if (!isBuilding) {
// Update the groups based on the tables selected
updateTableSelection();
}
}
});
// Add a listener for table tree expand and collapse events
addTreeExpansionListener(new TreeExpansionListener() {
/**
************************************************************************************
* Handle an expansion of the table tree
************************************************************************************
*/
@Override
public void treeExpanded(TreeExpansionEvent tee) {
// Update the table selection based on the selected group
updateGroupSelection();
}
/**
************************************************************************************
* Handle a collapse of the table tree
************************************************************************************
*/
@Override
public void treeCollapsed(TreeExpansionEvent tee) {
// Update the table selection based on the selected group
updateGroupSelection();
}
});
// Create a tree expansion check box
expandChkBx = new JCheckBox("Expand all");
expandChkBx.setBorder(emptyBorder);
expandChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
expandChkBx.setSelected(false);
// Check if this is the last component to add
if (!showGroupFilter && !showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(expandChkBx, gbc);
// Create a listener for changes in selection of the tree expansion check box
expandChkBx.addActionListener(new ActionListener() {
/**
************************************************************************************
* Handle a change to the tree expansion check box selection
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
setTreeExpansion(expandChkBx.isSelected());
}
});
// Check if instance tables are displayed in the tree
if (treeType != TableTreeType.PROTOTYPE_TABLES) {
// Create a hide data type check box
final JCheckBox hideTypeChkBx = new JCheckBox("Hide data type");
hideTypeChkBx.setBorder(emptyBorder);
hideTypeChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
hideTypeChkBx.setSelected(false);
// Check if this is the last component to add
if (!showGroupFilter && !showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(hideTypeChkBx, gbc);
// Create a listener for changes in selection of the hide data type check box
hideTypeChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the hide data type check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
setEnableDataType(!hideTypeChkBx.isSelected());
// Store the tree's current expansion state
String expState = getExpansionState();
// Force the root node to draw with the node additions
((DefaultTreeModel) treeModel).nodeStructureChanged(root);
setExpansionState(expState);
}
});
}
// Create the filtering node prefix storage and check boxes
final List<String> prefixes = new ArrayList<String>();
final JCheckBox groupFilterChkBx = new JCheckBox("Filter by group");
final JCheckBox typeFilterChkBx = new JCheckBox("Filter by type");
// table/variable divisions (e.g., 'Prototype', 'Parents & Children')
for (int index = 0; index < root.getChildCount(); index++) {
// Add the child node name with its path to the prefix list
prefixes.add("[" + root.getUserObject() + ", " + ((ToolTipTreeNode) root.getChildAt(index)).getUserObject());
}
// Check if the group check box is valid for this tree type
if (showGroupFilter) {
// Create a group filter check box
groupFilterChkBx.setBorder(emptyBorder);
groupFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
groupFilterChkBx.setSelected(false);
groupFilterChkBx.setEnabled(!groupHandler.getGroupInformation().isEmpty());
// Check if this is the last component to add
if (!showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.gridy++;
treePnl.add(groupFilterChkBx, gbc);
// Create a listener for changes in selection of the group filter check box
groupFilterChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the group filter check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the filter by group flag based on the check box status
isByGroup = groupFilterChkBx.isSelected();
// Store the tree's current expansion state
String expState = getExpansionState();
// Rebuild the tree based on the filter selection
buildTableTree(expandChkBx.isSelected(), rateName, rateFilter, parent);
// Adjust the expansion state to account for the change in filtering, then
// restore the expansion state
expState = adjustExpansionState(expState, groupFilterChkBx.isSelected(), true, typeFilterChkBx.isSelected(), false, false, prefixes, groupHandler, tableTypeHandler);
setExpansionState(expState);
}
});
}
// Check if the type check box is valid for this tree type
if (showTypeFilter) {
// Create a type filter check box
typeFilterChkBx.setBorder(emptyBorder);
typeFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
typeFilterChkBx.setSelected(false);
// Check if this is the last component to add
if (!addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.gridy++;
treePnl.add(typeFilterChkBx, gbc);
// Create a listener for changes in selection of the type filter check box
typeFilterChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the type filter check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the filter by type flag based on the check box status
isByType = typeFilterChkBx.isSelected();
// Store the tree's current expansion state
String expState = getExpansionState();
// Rebuild the tree based on the filter selection
buildTableTree(expandChkBx.isSelected(), rateName, rateFilter, parent);
// Adjust the expansion state to account for the change in filtering, then
// restore the expansion state
expState = adjustExpansionState(expState, groupFilterChkBx.isSelected(), false, typeFilterChkBx.isSelected(), true, false, prefixes, groupHandler, tableTypeHandler);
setExpansionState(expState);
}
});
}
// tree panel. Check if the flag is set to add this check box
if (addHiddenCheckBox) {
// Create the hidden check box. To prevent display of the check box components an empty
// panel is placed over it
JPanel hiddenPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
hiddenPnl.setBorder(emptyBorder);
JCheckBox hiddenChkBx = new JCheckBox(" ");
hiddenChkBx.setBorder(emptyBorder);
gbc.insets.bottom = 0;
gbc.gridy++;
treePnl.add(hiddenPnl, gbc);
hiddenChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
hiddenChkBx.setFocusable(false);
hiddenChkBx.setDisabledIcon(null);
hiddenChkBx.setEnabled(false);
treePnl.add(hiddenChkBx, gbc);
}
return treePnl;
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddTableTreeHandler method buildTableTree.
/**
********************************************************************************************
* (Re)build the table tree from the currently table information
*
* @param isExpanded
* true if all tree nodes should be expanded, false to collapse all nodes, and null
* to use the current status of the expansion check box (if present; if not present
* then use false)
*
* @param rateName
* rate column name used to filter the table tree for variables with rates; null if
* the tree is not filtered by data rate
*
* @param rateFilter
* data rate used to filter the table tree for variables with rates; null if the
* tree is not filtered by data rate
*
* @param parent
* component building this table tree
********************************************************************************************
*/
protected void buildTableTree(Boolean isExpanded, String rateName, String rateFilter, Component parent) {
this.rateName = rateName;
this.rateFilter = rateFilter;
// Check if a rate filter is in effect and a filter name is provided
if (rateFilter != null && rateName != null) {
// Load all references to rate column values from the custom values table that match
// the rate name
rateValues = new ArrayListMultiple();
rateValues.addAll(dbTable.getCustomValues(rateName, null, parent));
}
// Get the index into the table member rate array
rateIndex = ccddMain.getRateParameterHandler().getRateInformationIndexByRateName(rateName);
// Set the flag to indicate that the table tree is being built. This flag is used to
// inhibit actions involving tree selection value changes during the build process
isBuilding = true;
// Create the tree's root node using the database name. Since the root node isn't visible
// there is no need for a description
root = new ToolTipTreeNode(dbControl.getDatabaseName(), null);
// Set the root node
setModel(new DefaultTreeModel(root));
// Hide the root node (project database name)
setRootVisible(false);
// Create a node to display the prototype tables
ToolTipTreeNode prototype = new ToolTipTreeNode(DEFAULT_PROTOTYPE_NODE_NAME, "Prototype tables");
instance = new ToolTipTreeNode(DEFAULT_INSTANCE_NODE_NAME, treeType == INSTANCE_TABLES ? "Parent and children tables" : "Parent and children tables, with variables");
// Add the prototype and instance nodes to the root node
root.add(prototype);
root.add(instance);
// Check if both groups and table type are to be used to filter the table tree
if (isByGroup && isByType) {
// Step through the groups
for (GroupInformation groupInfo : groupHandler.getGroupInformation()) {
// Create nodes for the group
ToolTipTreeNode protoGroupNode = new ToolTipTreeNode(groupInfo.getName(), getDescriptions ? groupInfo.getDescription() : null);
ToolTipTreeNode instGroupNode = new ToolTipTreeNode(groupInfo.getName(), getDescriptions ? groupInfo.getDescription() : null);
// Add the group node to the prototype and instance nodes
prototype.add(protoGroupNode);
instance.add(instGroupNode);
// Add the group member tables to the group node by table type
addByType(protoGroupNode, instGroupNode, groupInfo, parent);
}
// Add the pseudo-group containing all tables to the prototype and instance nodes
addAllTablesGroup(prototype, instance, parent);
} else // Check if groups are to be used to filter the table tree
if (isByGroup) {
// Step through the groups
for (GroupInformation groupInfo : groupHandler.getGroupInformation()) {
// Create nodes for the group
ToolTipTreeNode protoGroupNode = new ToolTipTreeNode(groupInfo.getName(), getDescriptions ? groupInfo.getDescription() : null);
ToolTipTreeNode instGroupNode = new ToolTipTreeNode(groupInfo.getName(), getDescriptions ? groupInfo.getDescription() : null);
// Add the group node to the instance and prototype nodes
prototype.add(protoGroupNode);
instance.add(instGroupNode);
// / Build the top-level nodes filtered by group
buildTopLevelNodes(groupInfo.getTableMembers(), instGroupNode, protoGroupNode, parent);
}
// Add the pseudo-group containing all tables to the prototype and instance nodes
addAllTablesGroup(prototype, instance, parent);
} else // Check if the table types are to be used to filter the table tree
if (isByType) {
// Add all tables to the prototype and instances nodes by table type
addByType(prototype, instance, null, parent);
} else // Do not use the groups or types to filter the tree
{
// Build the root's top-level nodes
buildTopLevelNodes(null, instance, prototype, parent);
}
// Check if only the prototype node should be displayed
if (treeType == PROTOTYPE_TABLES) {
// Remove the instance node
root.remove(instance);
} else // Check if the only the instance node should be displayed
if (treeType == INSTANCE_TABLES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES || treeType == INSTANCE_TABLES_WITH_PRIMITIVES) {
// Remove the prototype node
root.remove(prototype);
}
// Check if the expansion check box exists
if (expandChkBx != null) {
// Check is the expansion state is not specified
if (isExpanded == null) {
// Set the expansion state to the current expansion check box state
isExpanded = expandChkBx.isSelected();
} else // The expansion state is specified
{
// Update the expansion check box state to match the specified expansion state
expandChkBx.setSelected(isExpanded);
}
} else // Check is the expansion state is not specified
if (isExpanded == null) {
// Set the state to collapse the tree
isExpanded = false;
}
// Force the root node to draw with the node additions
((DefaultTreeModel) treeModel).nodeStructureChanged(root);
// Expand or collapse the tree based on the expansion flag
setTreeExpansion(isExpanded);
// Set the node enable states based on the presence of child nodes
setNodeEnableByChildState(root);
// Clear the flag that indicates the table tree is being built
isBuilding = false;
// Set the renderer for the tree so that the custom icons can be used for the various node
// types
setCellRenderer(new TableTreeCellRenderer() {
/**
************************************************************************************
* Display the variable nodes using a special icon in the tree
************************************************************************************
*/
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
// Display the node name
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
// Check if this node represents a variable
if (leaf && ((ToolTipTreeNode) value).getLevel() > ((CcddTableTreeHandler) tree).getHeaderNodeLevel() && (treeType == STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES)) {
// Set the icon for the variable node
setVariableNodeIcon(this, (ToolTipTreeNode) value, row, linkedVariables.contains(removeExtraText(getFullVariablePath(((ToolTipTreeNode) value).getPath()))));
}
return this;
}
});
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddTableTreeHandler method getSelectedGroups.
/**
********************************************************************************************
* Get a list of the group nodes that are selected. Deselect of the group's child nodes and the
* group node itself
*
* @return List containing the selected group name(s)
********************************************************************************************
*/
protected List<String> getSelectedGroups() {
// Create storage for the group names
List<String> groups = new ArrayList<String>();
// Check if the table tree is filtered by group and if any nodes are selected
if (isByGroup && getSelectionPaths() != null) {
// Step through each selected table in the tree
for (TreePath path : getSelectionPaths()) {
// Check that this node represents a group
if (path.getPathCount() == 3) {
// Get the node for this path
ToolTipTreeNode node = (ToolTipTreeNode) path.getLastPathComponent();
// Add the group name to the list. Remove the HTML tags in case the node is
// disabled
groups.add(removeExtraText(node.getUserObject().toString()));
// Deselect the group and any children of the group
removeDescendantSelectedPaths(path, true);
}
}
}
return groups;
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddTelemetrySchedulerInput method initialize.
/**
********************************************************************************************
* Initialize the variable tree table
********************************************************************************************
*/
@SuppressWarnings("serial")
private void initialize() {
isNodeSelectionChanging = false;
// Initialize the currently selected rate to 1 Hz if present in the list of available
// rates; otherwise choose the first rate if any rates exist, and if none exist set the
// rate to a dummy value
List<String> availableRates = Arrays.asList(getAvailableRates());
selectedRate = availableRates.contains("1") ? "1" : (!availableRates.isEmpty() ? CcddUtilities.removeHTMLTags(availableRates.get(0)) : "0");
// Build a link tree
linkTree = new CcddLinkTreeHandler(ccddMain, null, rateName, ccddMain.getMainFrame()) {
/**
************************************************************************************
* Respond to changes in selection of a node in the link tree
************************************************************************************
*/
@Override
protected void updateTableSelection() {
// Check that a node selection change is not in progress
if (!isNodeSelectionChanging) {
// Set the flag to prevent link tree updates
isNodeSelectionChanging = true;
// Deselect any nodes that don't represent a link
variableTree.clearNonTableNodes(variableTree.isFilteredByGroup() ? 2 : 1);
// Reset the flag to allow link tree updates
isNodeSelectionChanging = false;
}
}
};
// Set the linked selected rate
linkTree.setSelectedRate(selectedRate);
// Build the variable tree that shows tables and their variables for the selected rate. Use
// the first rate in the available rates array to determine which variables to display in
// the tree, or, if none, create the tree showing no variables
variableTree = new CcddTableTreeHandler(ccddMain, new CcddGroupHandler(ccddMain, null, ccddMain.getMainFrame()), TableTreeType.INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES, rateName, selectedRate, excludedVars, ccddMain.getMainFrame()) {
/**
************************************************************************************
* Respond to changes in selection of a node in the variable tree. This replaces the
* placeholder method in CcddTableTreeHandler
************************************************************************************
*/
@Override
protected void updateTableSelection() {
// Check that a node selection change is not in progress
if (!isNodeSelectionChanging) {
// Select the associated message(s) in the scheduler table if a variable is
// selected in the variable tree. Note that below any assigned variables are
// deselected, so this call must occur first
selectMessageByVariable();
// Set the flag to prevent variable tree updates
isNodeSelectionChanging = true;
// Deselect any nodes that are disabled
clearDisabledNodes();
// Deselect any nodes that don't represent a table
clearNonTableNodes(variableTree.isFilteredByGroup() ? 2 : 1);
// Update the telemetry scheduler table text highlighting
schedulerDlg.getSchedulerHandler().updateSchedulerTableHighlight();
// Reset the flag to allow variable tree updates
isNodeSelectionChanging = false;
}
}
/**
************************************************************************************
* Override building the table tree so that the links can be added
************************************************************************************
*/
@Override
protected void buildTableTree(Boolean isExpanded, String rateName, String rateFilter, Component parent) {
// Call to the super to build the tree
super.buildTableTree(isExpanded, rateName, rateFilter, parent);
// Rename the instances node. Indicate that the node changed so that the tree
// redraws the name
getInstancesNode().setUserObject(UNLINKED_VARIABLES_NODE_NAME);
((DefaultTreeModel) getModel()).nodeChanged(getInstancesNode());
// Create a tree showing the links that contain variables with a sample rate
// matching the currently selected rate
ToolTipTreeNode validLinks = linkTree.getLinksMatchingRate(LINKED_VARIABLES_NODE_NAME, "Links containing variables with a sample rate of " + selectedRate);
// Insert the valid links tree into the variable tree
((DefaultTreeModel) getModel()).insertNodeInto(validLinks, getRootNode(), 0);
// Set the linked variables
setLinkedVariables(linkTree.getLinkVariables(null));
// Set the excluded variables
setExcludedVariables(excludedVars);
}
};
// Create the tree panel
treePnl = new JPanel(new GridBagLayout());
// Create the variable and link trees panels with buttons in between and add them to the
// panel
treePnl.add(variableTree.createTreePanel("Variables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, ccddMain.getMainFrame()), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0));
}
Aggregations