use of CCDD.CcddClassesDataTable.LinkInformation 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);
}
}
}
}
}
Aggregations