use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddInformationTreeHandler method copySubTree.
/**
********************************************************************************************
* Recursively copy the tree of a source node to a target node
*
* @param source
* source node
*
* @param target
* target node
********************************************************************************************
*/
protected void copySubTree(ToolTipTreeNode source, ToolTipTreeNode target) {
// Step through each child of the source node
for (int index = 0; index < source.getChildCount(); index++) {
// Get the child's node and create a copy of it
ToolTipTreeNode child = (ToolTipTreeNode) source.getChildAt(index);
ToolTipTreeNode clone = new ToolTipTreeNode(child.getUserObject().toString(), "");
// Add the copy of the node to the target sub-tree
target.add(clone);
// Copy this child's sub-tree to the copy
copySubTree(child, clone);
}
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddInformationTreeHandler method copyNodeTree.
/**
********************************************************************************************
* Copy the tree of a source node to a target node
*
* @param originalName
* name of the node to copy
*
* @param nameOfCopy
* name of the copy of the node
*
* @param infoToCopy
* information object to copy
********************************************************************************************
*/
protected void copyNodeTree(String originalName, String nameOfCopy, Object infoToCopy) {
// Step through each row in the information tree
for (int row = 0; row < infoTreeModel.getChildCount(root); row++) {
// Get the path for the row
TreePath path = getPathForRow(row);
// Check if this node represents a top level name and that the name matches the target
if (path.getPathCount() == 2 && path.getLastPathComponent().toString().equals(originalName)) {
// Store the information for the copy
addInformation(infoToCopy, nameOfCopy);
// Create a node for the top level and add it to the information tree
ToolTipTreeNode newNode = addInformationNode(nameOfCopy, "");
// Copy the source node's tree to the copy and stop searching
copySubTree((ToolTipTreeNode) path.getLastPathComponent(), newNode);
break;
}
}
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddLinkManagerDialog method createLink.
/**
********************************************************************************************
* Add a new link to the link tree
********************************************************************************************
*/
private void createLink() {
// Create a panel for the link create components
JPanel createPnl = new JPanel(new GridBagLayout());
// Create the new link dialog label and field
GridBagConstraints gbc = addLinkNameField("Enter new link name", "", createPnl);
// Create the link 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++;
createPnl.add(descriptionLbl, gbc);
// Create the link description input field
final JTextArea linkDescriptionFld = new JTextArea("", 3, 20);
linkDescriptionFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
linkDescriptionFld.setEditable(true);
linkDescriptionFld.setLineWrap(true);
linkDescriptionFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
linkDescriptionFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
linkDescriptionFld.setBorder(BorderFactory.createEmptyBorder());
linkDescriptionFld.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
linkDescriptionFld.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
JScrollPane descScrollPane = new JScrollPane(linkDescriptionFld);
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++;
createPnl.add(descScrollPane, gbc);
// Create a dialog for the new link information
CcddDialogHandler linkInfoDialog = new CcddDialogHandler() {
/**
************************************************************************************
* Verify that the dialog content is valid
*
* @return true if the input values are valid
************************************************************************************
*/
@Override
protected boolean verifySelection() {
// Verify the link name is valid
boolean isValid = verifyLinkName(false);
// Check if the link name is valid
if (isValid) {
// Get the name and remove leading & trailing white space characters
newLinkName = linkNameFld.getText();
newLinkDescription = linkDescriptionFld.getText().trim();
}
return isValid;
}
};
// Display a dialog for the user to provide a link name
if (linkInfoDialog.showOptionsDialog(CcddLinkManagerDialog.this, createPnl, "New Link", DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Disable automatically ending the edit sequence. This allows all of the deleted links
// to be grouped into a single sequence so that if undone, all fields are restored
activeHandler.getUndoHandler().setAutoEndEditSequence(false);
// Add the new link information
activeHandler.getLinkTree().addLinkInformation(activeHandler.getRateName(), newLinkName, "0", newLinkDescription);
// Insert the new link into the link tree
ToolTipTreeNode newNode = activeHandler.getLinkTree().addInformationNode(newLinkName, newLinkDescription);
// Update the link tree node name to show that it's empty
activeHandler.getLinkTree().adjustNodeText(newNode);
// Update the link dialog's change indicator
updateChangeIndicator();
// Re-enable automatic edit sequence ending, then end the edit sequence to group the
// deleted links
activeHandler.getUndoHandler().setAutoEndEditSequence(true);
activeHandler.getUndoManager().endEditSequence();
}
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddLinkManagerDialog method copyLink.
/**
********************************************************************************************
* Copy the selected link(s) to one or more data streams. If a target stream already has a link
* by the same name, or does not support the rate of the copied link, then the link is not
* copied to that stream. Additionally, if a variable's rate isn't the same in the target
* stream then the variable is removed from the link
********************************************************************************************
*/
private void copyLink() {
// Check if there is more that one data stream
if (rateHandler.getNumRateColumns() != 1) {
List<Integer> disabledItems = new ArrayList<Integer>();
String[][] arrayItemData = new String[rateHandler.getNumRateColumns()][2];
// Get a reference to the current link tree in order to shorten subsequent calls
CcddLinkTreeHandler currentTree = activeHandler.getLinkTree();
// Get the selected link(s)
String[] selected = currentTree.getTopLevelSelectedNodeNames();
// Create a panel to contain the dialog components
JPanel streamPnl = new JPanel(new GridBagLayout());
int rateIndex = 0;
// Step through each data stream
for (RateInformation rateInfo : rateHandler.getRateInformation()) {
// Add the associated data stream name to the array
arrayItemData[rateIndex][0] = rateInfo.getStreamName();
rateIndex++;
}
// Add the index of the current data stream to the list of disabled selections
disabledItems.add(tabbedPane.getSelectedIndex());
// Get the name(s) of the link(s) to be copied, minus any HTML tags and rate/size
// information
String linkNames = currentTree.removeExtraText(Arrays.toString(selected).replaceAll("^\\[|\\]$", ""));
// which to choose
if (addCheckBoxes(null, arrayItemData, disabledItems, "Select target data stream(s)", streamPnl)) {
// Create a panel to contain the dialog components
JPanel dialogPnl = new JPanel(new GridBagLayout());
// Create the link copying dialog label and field
GridBagConstraints gbc = addLinkNameField("Link(s) to copy:", linkNames, dialogPnl);
linkNameFld.setEditable(false);
// Add the data stream selection panel to the dialog
gbc.insets.left = 0;
gbc.insets.right = 0;
gbc.gridy++;
dialogPnl.add(streamPnl, gbc);
// Create the link copying dialog
CcddDialogHandler linkDlg = new CcddDialogHandler() {
/**
****************************************************************************
* Verify that the dialog content is valid
*
* @return true if the input values are valid
****************************************************************************
*/
@Override
protected boolean verifySelection() {
return verifyLinkName(true);
}
};
selectedStreams = new ArrayList<String>();
// Display the link copying dialog
if (linkDlg.showOptionsDialog(CcddLinkManagerDialog.this, dialogPnl, "Copy Link(s)", DialogOption.COPY_OPTION, true) == OK_BUTTON) {
notCopiedList = new ArrayList<Object[]>();
// Get the node path(s) that represent the links (skipping the link members)
TreePath[] selectedLinks = currentTree.getTopLevelSelectedPaths();
// Index of the next selected link node to copy
int selectionIndex = 0;
// selectedLinks)
for (TreePath copyLinkPath : selectedLinks) {
// Get the node for this path
ToolTipTreeNode copyLink = (ToolTipTreeNode) copyLinkPath.getLastPathComponent();
// Remove any HTML tags and parenthetical text from the selected link name
String nameOnly = activeHandler.getLinkTree().removeExtraText(copyLink.getUserObject().toString());
// Step through each selected data stream name
for (int index = 0; index < arrayItemData.length; index++) {
// Check if this data stream is selected as a target
if (selectedStreams.contains(arrayItemData[index][0])) {
// Get the reference to this stream's link manager handler to
// shorten subsequent calls
CcddLinkManagerHandler linkMgr = linkMgrs.get(index);
// Get a reference to the target's link tree to shorten subsequent
// calls
CcddLinkTreeHandler targetTree = linkMgr.getLinkTree();
// target data stream
if (targetTree.getLinkInformation(nameOnly) == null) {
// Get the link information for the link being copied
LinkInformation linkInfo = currentTree.getLinkInformation(nameOnly);
// Get the rate information for the copied link's data stream
RateInformation rateInfo = rateHandler.getRateInformationByStreamName(arrayItemData[index][0]);
// sample rate
if (linkInfo.getSampleRate().equals("0") || Arrays.asList(rateInfo.getSampleRates()).contains(linkInfo.getSampleRate())) {
List<ToolTipTreeNode> removedNodes = new ArrayList<ToolTipTreeNode>();
// Create a node for the new link
ToolTipTreeNode newLinkNode = new ToolTipTreeNode(nameOnly, linkInfo.getDescription());
// Copy the top-level nodes from the copied link to the new
// link
targetTree.copySubTree((ToolTipTreeNode) selectedLinks[selectionIndex].getLastPathComponent(), newLinkNode);
// Update the target stream's variable tree to the copied
// link's rate. The variable tree is used to validate the
// variables in the new link
linkMgr.setRateFilter(linkInfo.getSampleRate());
// Step through each member of the new link
for (Enumeration<?> element = newLinkNode.preorderEnumeration(); element.hasMoreElements(); ) {
// Get the node for this variable and convert it to a
// string, removing the link name
ToolTipTreeNode subNode = (ToolTipTreeNode) element.nextElement();
String varPath = targetTree.convertLeafNodePath(subNode.getPath(), 1);
// stream)
if (!varPath.isEmpty() && varPath.contains(".") && !linkMgr.getVariableTree().isNodeInTree(varPath)) {
// Add this node to the list of those to be removed
// from the new link
removedNodes.add(subNode);
// Add the invalid link and data stream to the list
notCopiedList.add(new Object[] { nameOnly, CcddUtilities.highlightDataType(subNode.getUserObject().toString()), arrayItemData[index][0], "Sample rate differs or variable unavailable in target" });
}
}
// Step through the list of variable nodes to be removed
for (ToolTipTreeNode removeNode : removedNodes) {
// Remove the variable node from the tree, and its
// ancestor nodes (up to the link level) if these have
// no siblings
targetTree.removeNodeAndEmptyAncestors(removeNode);
}
// Insert the new link into the link tree
ToolTipTreeNode targetNode = targetTree.addInformationNode(nameOnly, linkInfo.getDescription());
// Copy the link members from the link being copied to the
// copy in the target data stream
targetTree.copySubTree(newLinkNode, targetNode);
// Create the new link in the target data stream
targetTree.addLinkInformation(rateInfo.getRateName(), linkInfo.getName(), linkInfo.getSampleRate(), linkInfo.getDescription());
// Update the link tree node names in the target stream
// (e.g., add the rate/size information)
targetTree.adjustNodeText(targetNode);
// Update the target stream's variable tree to gray out any
// variables now assigned due to the new link
linkMgr.getVariableTree().setExcludedVariables(targetTree.getLinkVariables(null));
// Update the link dialog's change indicator
updateChangeIndicator(index);
} else // The stream does not support the rate of the copied link
{
// Add the invalid link and data stream to the list
notCopiedList.add(new Object[] { nameOnly, "", arrayItemData[index][0], "Sample rate unsupported in target" });
}
} else // The data stream already contains a link with this name
{
// Add the invalid link and data stream to
notCopiedList.add(new Object[] { nameOnly, "", arrayItemData[index][0], "Link name already exists in target" });
}
}
}
selectionIndex++;
}
// Check if any link or link member failed to copy
if (!notCopiedList.isEmpty()) {
// Create a panel for the link copy failure dialog
JPanel notCopyPnl = new JPanel(new GridBagLayout());
// Create the list label and add it to the dialog
JLabel notCopyLbl = new JLabel("Following link(s) and/or link " + "member(s) were not copied:");
notCopyLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
gbc.gridy = 0;
notCopyPnl.add(notCopyLbl, gbc);
// Create the table to display the links & members not copied
CcddJTableHandler notCopiedTable = new CcddJTableHandler() {
/**
********************************************************************
* Allow multiple line display in the specified columns
********************************************************************
*/
@Override
protected boolean isColumnMultiLine(int column) {
return column == LinkCopyErrorColumnInfo.MEMBER.ordinal() || column == LinkCopyErrorColumnInfo.CAUSE.ordinal();
}
/**
************************************************************************************
* Allow HTML-formatted text in the specified column(s)
************************************************************************************
*/
@Override
protected boolean isColumnHTML(int column) {
return column == LinkCopyErrorColumnInfo.MEMBER.ordinal();
}
/**
********************************************************************
* Load the link & members not copied data into the table and format
* the table cells
********************************************************************
*/
@Override
protected void loadAndFormatData() {
// Place the data into the table model along with the column names,
// set up the editors and renderers for the table cells, set up the
// table grid lines, and calculate the minimum width required to
// display the table information
setUpdatableCharacteristics(notCopiedList.toArray(new Object[0][0]), LinkCopyErrorColumnInfo.getColumnNames(), null, LinkCopyErrorColumnInfo.getToolTips(), true, true, true);
}
/**
********************************************************************
* Override the table layout so that extra width is apportioned
* unequally between the columns when the table is resized
********************************************************************
*/
@Override
public void doLayout() {
// Get a reference to the column being resized
if (getTableHeader() != null && getTableHeader().getResizingColumn() == null) {
// Get a reference to the event table's column model to shorten
// subsequent calls
TableColumnModel tcm = getColumnModel();
// Calculate the change in the search dialog's width
int delta = getParent().getWidth() - tcm.getTotalColumnWidth();
// Get the reference to the link copy error table columns
TableColumn linkCol = tcm.getColumn(LinkCopyErrorColumnInfo.LINK.ordinal());
TableColumn memCol = tcm.getColumn(LinkCopyErrorColumnInfo.MEMBER.ordinal());
TableColumn strmCol = tcm.getColumn(LinkCopyErrorColumnInfo.STREAM.ordinal());
TableColumn errCol = tcm.getColumn(LinkCopyErrorColumnInfo.CAUSE.ordinal());
// Set the columns' widths to its current width plus a
// percentage of the the extra width added to the dialog due to
// the resize
linkCol.setPreferredWidth(linkCol.getPreferredWidth() + (int) (delta * 0.125));
linkCol.setWidth(linkCol.getPreferredWidth());
memCol.setPreferredWidth(memCol.getPreferredWidth() + (int) (delta * 0.375));
memCol.setWidth(memCol.getPreferredWidth());
strmCol.setPreferredWidth(strmCol.getPreferredWidth() + (int) (delta * 0.125));
strmCol.setWidth(strmCol.getPreferredWidth());
errCol.setPreferredWidth(errCol.getPreferredWidth() + delta - (int) (delta * 0.125) * 2 - (int) (delta * 0.375));
errCol.setWidth(errCol.getPreferredWidth());
} else // Table header or resize column not available
{
super.doLayout();
}
}
};
// Place the table into a scroll pane
JScrollPane scrollPane = new JScrollPane(notCopiedTable);
// Set up the link copy error table parameters
notCopiedTable.setFixedCharacteristics(scrollPane, false, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, TableSelectionMode.SELECT_BY_CELL, true, ModifiableColorInfo.TABLE_BACK.getColor(), false, true, ModifiableFontInfo.OTHER_TABLE_CELL.getFont(), true);
// Define the panel to contain the table
JPanel resultsTblPnl = new JPanel();
resultsTblPnl.setLayout(new BoxLayout(resultsTblPnl, BoxLayout.X_AXIS));
resultsTblPnl.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
resultsTblPnl.add(scrollPane);
// Add the table to the dialog
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 1.0;
gbc.gridx = 0;
gbc.gridy++;
notCopyPnl.add(resultsTblPnl, gbc);
// Inform the user that the link(s) can't be copied for the reason provided
new CcddDialogHandler().showOptionsDialog(CcddLinkManagerDialog.this, notCopyPnl, "Link Copy Failure", DialogOption.PRINT_OPTION, true);
}
}
}
}
}
use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.
the class CcddLinkManagerHandler method selectLinkByVariable.
/**
********************************************************************************************
* Select the link in the link tree for which the selected variable in the variable tree is a
* member
********************************************************************************************
*/
private void selectLinkByVariable() {
// Get the array of selected paths in the variable tree
TreePath[] selectedPaths = variableTree.getSelectionPaths();
// Check if only a single node is selected
if (selectedPaths != null && selectedPaths.length == 1) {
// Clear any currently selected link(s)
linkTree.clearSelection();
// Get the first selected variable's path
String variablePath = variableTree.getFullVariablePath(variableTree.getSelectionPath().getPath());
// to a link
if (variablePath.contains(DISABLED_TEXT_COLOR)) {
// Remove the HTML flags from the variable path
variablePath = variableTree.removeExtraText(variablePath);
// Step through the link tree nodes that show the link names
for (int linkIndex = 0; linkIndex < linkTree.getRootNode().getChildCount(); linkIndex++) {
// Get the link name node from the link tree
ToolTipTreeNode linkNode = ((ToolTipTreeNode) linkTree.getRootNode().getChildAt(linkIndex));
// Step through the variables belonging to the link
for (String[] linkDefn : linkTree.getLinkHandler().getLinkDefinitionsByName(linkTree.removeExtraText(linkNode.getUserObject().toString()), rateName)) {
// Check if the selected variable matches the link variable
if (variablePath.equals(linkDefn[LinksColumn.MEMBER.ordinal()])) {
// Select the link to which the variable belongs
linkTree.setSelectionPath(CcddCommonTreeHandler.getPathFromNode(linkNode));
// Set the index to the maximum value to force the outer loop to end,
// then exit the inner loop to stop searching this link
linkIndex = linkTree.getRootNode().getChildCount();
break;
}
}
}
}
}
}
Aggregations