use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.
the class CcddLinkManagerDialog method initialize.
/**
********************************************************************************************
* Create the variable link manager dialog. This is executed in a separate thread since it can
* take a noticeable amount time to complete, and by using a separate thread the GUI is allowed
* to continue to update. The GUI menu commands, however, are disabled until the telemetry
* scheduler initialization completes execution
********************************************************************************************
*/
private void initialize() {
// Build the variable link manager dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panels to hold the components of the dialog
JPanel dialogPnl = new JPanel(new GridBagLayout());
JPanel buttonPnl = new JPanel();
JButton btnClose;
/**
************************************************************************************
* Build the variable link manager dialog
************************************************************************************
*/
@Override
protected void execute() {
// Create a border for the dialog components
border = 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()));
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0);
// Create a tabbed pane to contain the rate parameters that are stream-specific
tabbedPane = new DnDTabbedPane(SwingConstants.TOP) {
/**
****************************************************************************
* Update the link manager list order following a tab move
****************************************************************************
*/
@Override
protected Object tabMoveCleanup(int oldTabIndex, int newTabIndex, Object tabContents) {
// Adjust the new tab index if moving the tab to a higher index
newTabIndex -= newTabIndex > oldTabIndex ? 1 : 0;
// Re-order the rate information based on the new tab order
RateInformation[] rateInfoArray = rateHandler.getRateInformation().toArray(new RateInformation[0]);
rateInfoArray = (RateInformation[]) CcddUtilities.moveArrayMember(rateInfoArray, oldTabIndex, newTabIndex);
List<RateInformation> rateInfoList = new ArrayList<RateInformation>(rateInfoArray.length);
rateInfoList.addAll(Arrays.asList(rateInfoArray));
rateHandler.setRateInformation(rateInfoList);
// Get the reference to the moved tab's original location in the list
CcddLinkManagerHandler editor = linkMgrs.get(oldTabIndex);
// Remove the tab
linkMgrs.remove(oldTabIndex);
// Add the tab at its new location
linkMgrs.add(newTabIndex, editor);
// Update the active tab pointer to the moved tab
activeHandler = linkMgrs.get(tabbedPane.getSelectedIndex());
return editor;
}
};
tabbedPane.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
// Listen for tab selection changes
tabbedPane.addChangeListener(new ChangeListener() {
/**
****************************************************************************
* Update the handler to the one associated with the selected tab
****************************************************************************
*/
@Override
public void stateChanged(ChangeEvent ce) {
// Set the active handler to the one indicated by the currently selected
// tab
activeHandler = linkMgrs.get(tabbedPane.getSelectedIndex());
// Get the number of selected links
int numSelectedLinks = activeHandler.getLinkTree().getSelectionCount();
// Update the manager controls state
setLinkButtonsEnabled(numSelectedLinks == 1, numSelectedLinks != 0);
// Set the modal undo manager reference in the keyboard handler while the
// link manager is active
ccddMain.getKeyboardHandler().setModalDialogReference(activeHandler.getUndoManager(), null);
}
});
gbc.gridwidth = 2;
gbc.gridx = 0;
gbc.gridy++;
dialogPnl.add(tabbedPane, gbc);
// Define the buttons for the lower panel: New link button
JButton btnNewLink = CcddButtonPanelHandler.createButton("New", INSERT_ICON, KeyEvent.VK_N, "Create a new link");
// Add a listener for the New button
btnNewLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Add a new link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
createLink();
}
});
// Delete link button
JButton btnDeleteLink = CcddButtonPanelHandler.createButton("Delete", DELETE_ICON, KeyEvent.VK_D, "Delete an existing link");
// Add a listener for the Delete button
btnDeleteLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Delete the selected link(s)
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
deleteLink();
}
});
// Rename link button
btnRenameLink = CcddButtonPanelHandler.createButton("Rename", RENAME_ICON, KeyEvent.VK_D, "Rename an existing link");
// Add a listener for the Rename button
btnRenameLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Rename the selected link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
renameLink();
}
});
// Copy link button
btnCopyLink = CcddButtonPanelHandler.createButton("Copy", COPY_ICON, KeyEvent.VK_P, "Copy an existing link");
// Add a listener for the Copy button
btnCopyLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Copy the selected link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
copyLink();
}
});
// Undo button
JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
// Create a listener for the Undo command
ActionListener undoAction = new ActionListener() {
/**
****************************************************************************
* Undo the last edit
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
activeHandler.getUndoManager().undo();
// Update the link selection following an undo
activeHandler.getUndoHandler().setAllowUndo(false);
activeHandler.getLinkTree().updateTableSelection();
activeHandler.getUndoHandler().setAllowUndo(true);
// Update the link definitions, selected link, link fields, and link tree
// node names
activeHandler.cleanUpLinks();
}
};
// Add the undo listener to the Undo button and menu command
btnUndo.addActionListener(undoAction);
// Redo button
JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
// Create a listener for the Redo command
ActionListener redoAction = new ActionListener() {
/**
****************************************************************************
* Redo the last edit that was undone
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
activeHandler.getUndoManager().redo();
// Update the link definitions, selected link, link fields, and link tree
// node names
activeHandler.cleanUpLinks();
}
};
// Add the redo listener to the Redo button and menu command
btnRedo.addActionListener(redoAction);
// Store links button
JButton btnStoreLinks = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the link updates in the database");
// Add a listener for the Store button
btnStoreLinks.addActionListener(new ActionListener() {
/**
****************************************************************************
* Store the links in the database
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// the user confirms storing the links
if (isLinksChanged() && new CcddDialogHandler().showMessageDialog(CcddLinkManagerDialog.this, "<html><b>Store links?", "Store Links", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Store the links in the project database
storeLinks();
}
}
});
// Close button
btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the link manager");
// Add a listener for the Close button
btnClose.addActionListener(new ActionListener() {
/**
****************************************************************************
* Close the link selection dialog
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// discard the changes
if (!isLinksChanged() || new CcddDialogHandler().showMessageDialog(CcddLinkManagerDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Close the dialog
closeDialog();
// Clear the modal dialog references in the keyboard handler
ccddMain.getKeyboardHandler().setModalDialogReference(null, null);
}
}
});
// Add buttons in the order in which they'll appear (left to right, top to bottom)
buttonPnl.add(btnNewLink);
buttonPnl.add(btnRenameLink);
buttonPnl.add(btnUndo);
buttonPnl.add(btnStoreLinks);
buttonPnl.add(btnDeleteLink);
buttonPnl.add(btnCopyLink);
buttonPnl.add(btnRedo);
buttonPnl.add(btnClose);
// Distribute the buttons across two rows
setButtonRows(2);
// Add the data stream link handlers
addLinkHandlerPanes();
}
/**
************************************************************************************
* Variable link manager dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Display the link management dialog
showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnClose, "Manage Links", true);
}
});
}
use of CCDD.CcddClassesDataTable.RateInformation 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