use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.
the class CcddDuplicateMsgIDDialog method initialize.
/**
********************************************************************************************
* Display the duplicate message ID dialog
*
* @param msgIDHandler
* message ID handler reference
*
* @param parent
* GUI component calling this method
********************************************************************************************
*/
private void initialize(CcddMessageIDHandler msgIDHandler, Component parent) {
// Get the list of message IDs in use - this creates the duplicates list
msgIDHandler.getMessageIDsInUse(true, true, true, true, true, false, null, true, parent);
// Get the list of duplicate message IDs
duplicates = new ArrayListMultiple(1);
duplicates.addAll(msgIDHandler.getDuplicates());
// Sort the list based on the message ID values
duplicates.sort(ArrayListMultipleSortType.HEXADECIMAL);
// 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(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()), 0, 0);
// Create panels to hold the components of the dialog
JPanel dialogPnl = new JPanel(new GridBagLayout());
dialogPnl.setBorder(BorderFactory.createEmptyBorder());
// Create the table to display the duplicate message IDs
CcddJTableHandler duplicatesTable = new CcddJTableHandler() {
/**
************************************************************************************
* Allow multiple line display in the specified column(s)
************************************************************************************
*/
@Override
protected boolean isColumnMultiLine(int column) {
return column == DuplicateMsgIDColumnInfo.OWNERS.ordinal();
}
/**
************************************************************************************
* Allow HTML-formatted text in the specified column(s)
************************************************************************************
*/
@Override
protected boolean isColumnHTML(int column) {
return column == DuplicateMsgIDColumnInfo.OWNERS.ordinal();
}
/**
************************************************************************************
* Load the duplicate message ID 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(duplicates.toArray(new String[0][0]), DuplicateMsgIDColumnInfo.getColumnNames(), "1:0", DuplicateMsgIDColumnInfo.getToolTips(), true, true, true);
}
};
// Place the table into a scroll pane
JScrollPane scrollPane = new JScrollPane(duplicatesTable);
// Set up the field table parameters
duplicatesTable.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++;
dialogPnl.add(resultsTblPnl, gbc);
showOptionsDialog(parent, dialogPnl, "Duplicate Message IDs", DialogOption.PRINT_OPTION, true);
}
use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.
the class CcddFieldTableEditorDialog method getDataFieldNames.
/**
********************************************************************************************
* Get the unique project data field names in alphabetical order
*
* @return Array containing the unique project data field names in alphabetical order
********************************************************************************************
*/
private String[][] getDataFieldNames() {
ArrayListMultiple nameList = new ArrayListMultiple();
// Step through each data field
for (String[] dataField : dataFields) {
boolean found = false;
// Step through the list of data fields in the list to this point
for (String[] item : nameList) {
// Check if the current data field's name is in the list
if (item[0].equals(dataField[FieldsColumn.FIELD_NAME.ordinal()])) {
// Set the flag indicating the data field name is already in the list and stop
// searching
found = true;
break;
}
}
// Check if the data field name isn't in the list
if (!found) {
// Add the data field name to the list. Set the description field to null
nameList.add(new String[] { dataField[FieldsColumn.FIELD_NAME.ordinal()], null });
}
}
// Sort the list based on the data field name
nameList.sort(ArrayListMultipleSortType.STRING);
return nameList.toArray(new String[0][0]);
}
use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.
the class CcddSearchDialog method initialize.
/**
********************************************************************************************
* Create the database table or scripts search dialog
*
* @param targetRow
* row index to match if this is an event log entry search on a table that displays
* only a single log entry; null otherwise
*
* @param parent
* GUI component over which to center the dialog
********************************************************************************************
*/
private void initialize(final Long targetRow, Component parent) {
searchHandler = new CcddSearchHandler(ccddMain, searchDlgType, targetRow, eventLog);
searchColumns = "";
// Create a borders for the dialog components
Border 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()));
Border emptyBorder = BorderFactory.createEmptyBorder();
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, (searchDlgType == SearchDialogType.TABLES ? 0.0 : 1.0), 0.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
// Create panels to hold the components of the dialog
JPanel dialogPnl = new JPanel(new GridBagLayout());
JPanel upperPnl = new JPanel(new GridBagLayout());
JPanel inputPnl = new JPanel(new GridBagLayout());
dialogPnl.setBorder(emptyBorder);
upperPnl.setBorder(emptyBorder);
inputPnl.setBorder(emptyBorder);
// Create the search dialog labels and fields
JLabel dlgLbl = new JLabel("Enter search text");
dlgLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
inputPnl.add(dlgLbl, gbc);
// Create the auto-completion search field and add it to the dialog panel. The search list
// is initially empty as it is updated whenever a key is pressed
searchFld = new AutoCompleteTextField(ModifiableSizeInfo.NUM_REMEMBERED_SEARCHES.getSize());
searchFld.setCaseSensitive(true);
searchFld.setText("");
searchFld.setColumns(25);
searchFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
searchFld.setEditable(true);
searchFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
searchFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
searchFld.setBorder(border);
// Add a listener for key press events
searchFld.addKeyListener(new KeyAdapter() {
/**
************************************************************************************
* Handle a key press event
************************************************************************************
*/
@Override
public void keyPressed(KeyEvent ke) {
// Check if this is a visible character
if (!ke.isActionKey() && ke.getKeyCode() != KeyEvent.VK_ENTER && !ke.isControlDown() && !ke.isAltDown() && !ke.isMetaDown() && ModifiableFontInfo.INPUT_TEXT.getFont().canDisplay(ke.getKeyCode())) {
// Get the list of remembered searches from the program preferences. This is
// done as a key press occurs so that the list is updated to the latest one. If
// multiple search dialogs are open this allows them to 'share' the list rather
// than overwriting each other
List<String> searches = new ArrayList<String>(ModifiableSizeInfo.NUM_REMEMBERED_SEARCHES.getSize());
searches.addAll(Arrays.asList(ccddMain.getProgPrefs().get(SEARCH_STRINGS, "").split(AUTO_COMPLETE_TEXT_SEPARATOR)));
searchFld.setList(searches);
}
}
});
gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
gbc.gridy++;
inputPnl.add(searchFld, gbc);
// Create a check box for ignoring the text case
ignoreCaseCb = new JCheckBox("Ignore text case");
ignoreCaseCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
ignoreCaseCb.setBorder(emptyBorder);
ignoreCaseCb.setToolTipText(CcddUtilities.wrapText("Ignore case when matching the search string", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
// Add a listener for check box selection changes
ignoreCaseCb.addActionListener(new ActionListener() {
/**
************************************************************************************
* Handle a change in the ignore case check box state
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Change the case sensitivity for the remembered searches to match the case
// sensitivity check box
searchFld.setCaseSensitive(!ignoreCaseCb.isSelected());
}
});
gbc.insets.left = 0;
gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.gridy++;
inputPnl.add(ignoreCaseCb, gbc);
// Create a check box for allow a regular expression in the search string
allowRegexCb = new JCheckBox("Allow regular expression");
allowRegexCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
allowRegexCb.setBorder(emptyBorder);
allowRegexCb.setToolTipText(CcddUtilities.wrapText("Allow the search string to contain a regular expression", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
gbc.gridy++;
inputPnl.add(allowRegexCb, gbc);
// Check if this is a table search
if (searchDlgType == SearchDialogType.TABLES) {
final ArrayListMultiple columns = new ArrayListMultiple();
// Create a check box for ignoring matches within the internal tables
dataTablesOnlyCb = new JCheckBox("Search data table cells only");
dataTablesOnlyCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
dataTablesOnlyCb.setBorder(emptyBorder);
dataTablesOnlyCb.setToolTipText(CcddUtilities.wrapText("Search only the cells in the data tables", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
gbc.gridy++;
inputPnl.add(dataTablesOnlyCb, gbc);
// Step through each defined table type
for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
// Step through each visible column in the table type
for (int index = NUM_HIDDEN_COLUMNS; index < typeDefn.getColumnCountDatabase(); ++index) {
// Check if the column name isn't already in the list
if (!columns.contains(typeDefn.getColumnNamesUser()[index])) {
// Add the visible column name and its corresponding database name to the
// list
columns.add(new String[] { typeDefn.getColumnNamesUser()[index], typeDefn.getColumnNamesDatabase()[index] });
}
}
}
// Check if any columns are defined
if (columns.size() != 0) {
ArrayListMultiple columnNames = new ArrayListMultiple();
// Sort the column names alphabetically
columns.sort(ArrayListMultipleSortType.STRING);
// Create the column selection check box and label to display the selected
// column(s)
selectedColumnsCb = new JCheckBox("Search selected columns");
selectedColumnsCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
selectedColumnsCb.setBorder(emptyBorder);
selectedColumnsCb.setToolTipText(CcddUtilities.wrapText("Search only selected columns in the data tables", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
selectedColumnsLbl = new MultilineLabel();
selectedColumnsLbl.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
// Set the layout manager characteristics for the column selection panel
GridBagConstraints subgbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
// Add the column selection check box and label to the column selection panel, then
// add this panel to the dialog
JPanel selectedColumnsPnl = new JPanel(new GridBagLayout());
selectedColumnsPnl.add(selectedColumnsCb, subgbc);
selectedColumnsPnl.setBorder(emptyBorder);
subgbc.weightx = 1.0;
subgbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() * 3;
subgbc.fill = GridBagConstraints.BOTH;
subgbc.gridy++;
selectedColumnsPnl.add(selectedColumnsLbl, subgbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridy++;
inputPnl.add(selectedColumnsPnl, gbc);
// Create a panel for the column selection pop-up dialog
final JPanel columnPnl = new JPanel(new GridBagLayout());
columnPnl.setBorder(emptyBorder);
// Step through each column
for (String[] column : columns) {
// Add the visible name to the list used to create the check box panel
columnNames.add(new String[] { column[0], null });
}
// Create the column name pop-up dialog
final CcddDialogHandler columnDlg = new CcddDialogHandler();
// Add the column name check boxes to the dialog
columnDlg.addCheckBoxes(null, columnNames.toArray(new String[0][0]), null, "", columnPnl);
// Add a listener for check box selection changes
selectedColumnsCb.addActionListener(new ActionListener() {
/**
****************************************************************************
* Handle a change in the selected columns check box state
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Check if the column selection check box is selected
if (selectedColumnsCb.isSelected()) {
// Display a pop-up for choosing which table columns to search
if (columnDlg.showOptionsDialog(CcddSearchDialog.this, columnPnl, "Select Column(s)", DialogOption.OK_CANCEL_OPTION, true) == OK_BUTTON) {
searchColumns = "";
// Step through each column name check box
for (int index = 0; index < columnDlg.getCheckBoxes().length; index++) {
// Check if the check box is selected
if (columnDlg.getCheckBoxes()[index].isSelected()) {
// Add the name of the column to the constraint string
searchColumns += columns.get(index)[1] + ",";
}
}
searchColumns = CcddUtilities.removeTrailer(searchColumns, ",");
// Set the selected column(s) label to display the selected
// column(s)
selectedColumnsLbl.setText(searchColumns.replaceAll(",", ", "));
}
// Check if no column is selected
if (searchColumns.isEmpty()) {
// Deselect the selected columns check box and blank the selected
// column(s) text
selectedColumnsCb.setSelected(false);
selectedColumnsLbl.setText("");
}
} else // The column selection check box is not selected
{
// Blank the column constraint string and the selected column(s) text
searchColumns = "";
selectedColumnsLbl.setText("");
}
}
});
}
}
// Add the inputs panel, containing the search field and check boxes, to the upper panel
gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
gbc.gridy = 0;
upperPnl.add(inputPnl, gbc);
gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
gbc.fill = GridBagConstraints.BOTH;
// Check if this is a table search
if (searchDlgType == SearchDialogType.TABLES) {
// Build the table tree showing both table prototypes and table instances; i.e., parent
// tables with their child tables (i.e., parents with children)
tableTree = new CcddTableTreeHandler(ccddMain, new CcddGroupHandler(ccddMain, null, parent), TableTreeType.TABLES, true, false, parent);
// Add the tree to the upper panel
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridx++;
upperPnl.add(tableTree.createTreePanel("Tables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, parent), gbc);
gbc.gridwidth = 1;
}
gbc.insets.right = 0;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;
dialogPnl.add(upperPnl, gbc);
// Create the results and number of results found labels
JLabel resultsLbl = new JLabel("Search results");
resultsLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
resultsLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
numResultsLbl = new JLabel();
numResultsLbl.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
gbc.insets.bottom = 0;
gbc.weighty = 0.0;
gbc.gridy++;
// Add the results labels to the dialog
JPanel resultsPnl = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
resultsPnl.add(resultsLbl);
resultsPnl.add(numResultsLbl);
dialogPnl.add(resultsPnl, gbc);
// Create the table to display the search results
resultsTable = new CcddJTableHandler() {
/**
************************************************************************************
* Allow multiple line display in the specified columns, depending on search type
************************************************************************************
*/
@Override
protected boolean isColumnMultiLine(int column) {
return searchDlgType == SearchDialogType.TABLES || (searchDlgType == SearchDialogType.LOG && column == SearchResultsColumnInfo.CONTEXT.ordinal()) || (searchDlgType == SearchDialogType.SCRIPTS && (column == SearchResultsColumnInfo.OWNER.ordinal() || column == SearchResultsColumnInfo.CONTEXT.ordinal()));
}
/**
************************************************************************************
* Allow HTML-formatted text in the specified column(s)
************************************************************************************
*/
@Override
protected boolean isColumnHTML(int column) {
return searchDlgType == SearchDialogType.TABLES && column == SearchResultsColumnInfo.OWNER.ordinal();
}
/**
************************************************************************************
* Allow the specified column's cells to be displayed with the text highlighted
************************************************************************************
*/
@Override
protected boolean isColumnHighlight(int column) {
return column == SearchResultsColumnInfo.CONTEXT.ordinal();
}
/**
************************************************************************************
* Load the search results 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(resultsData, SearchResultsColumnInfo.getColumnNames(searchDlgType), null, SearchResultsColumnInfo.getToolTips(searchDlgType), 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 search results table columns
TableColumn tgtColumn = tcm.getColumn(SearchResultsColumnInfo.OWNER.ordinal());
TableColumn locColumn = tcm.getColumn(SearchResultsColumnInfo.LOCATION.ordinal());
TableColumn cntxtColumn = tcm.getColumn(SearchResultsColumnInfo.CONTEXT.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
tgtColumn.setPreferredWidth(tgtColumn.getPreferredWidth() + (int) (delta * 0.25));
tgtColumn.setWidth(tgtColumn.getPreferredWidth());
locColumn.setPreferredWidth(locColumn.getPreferredWidth() + (int) (delta * 0.25));
locColumn.setWidth(locColumn.getPreferredWidth());
cntxtColumn.setPreferredWidth(cntxtColumn.getPreferredWidth() + delta - (int) (delta * 0.25) * 2);
cntxtColumn.setWidth(cntxtColumn.getPreferredWidth());
} else // Table header or resize column not available
{
super.doLayout();
}
}
/**
************************************************************************************
* Highlight the matching search text in the context column cells
*
* @param component
* reference to the table cell renderer component
*
* @param value
* cell value
*
* @param isSelected
* true if the cell is to be rendered with the selection highlighted
*
* @param int
* row cell row, view coordinates
*
* @param column
* cell column, view coordinates
************************************************************************************
*/
@Override
protected void doSpecialRendering(Component component, String text, boolean isSelected, int row, int column) {
// Check if highlighting is enabled and if the column allows text highlighting
if (isColumnHighlight(column)) {
Pattern pattern;
// Create a highlighter painter
DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(isSelected ? ModifiableColorInfo.INPUT_TEXT.getColor() : ModifiableColorInfo.TEXT_HIGHLIGHT.getColor());
// Check if case is to be ignored
if (ignoreCaseCb.isSelected()) {
// Create the match pattern with case ignored
pattern = Pattern.compile(allowRegexCb.isSelected() ? searchFld.getText() : Pattern.quote(searchFld.getText()), Pattern.CASE_INSENSITIVE);
} else // Only highlight matches with the same case
{
// Create the match pattern, preserving case
pattern = Pattern.compile(allowRegexCb.isSelected() ? searchFld.getText() : Pattern.quote(searchFld.getText()));
}
// Create the pattern matcher from the pattern
Matcher matcher = pattern.matcher(text);
// Find each match in the text string
while (matcher.find()) {
try {
// Highlight the matching text. Adjust the highlight color to account
// for the cell selection highlighting so that the search text is
// easily readable
((JTextComponent) component).getHighlighter().addHighlight(matcher.start(), matcher.end(), painter);
} catch (BadLocationException ble) {
// Ignore highlighting failure
}
}
}
}
};
// Place the table into a scroll pane
JScrollPane scrollPane = new JScrollPane(resultsTable);
// Set up the search results table parameters
resultsTable.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++;
dialogPnl.add(resultsTblPnl, gbc);
// Search database tables button
JButton btnSearch = CcddButtonPanelHandler.createButton("Search", SEARCH_ICON, KeyEvent.VK_O, "Search the project database");
// Add a listener for the Search button
btnSearch.addActionListener(new ActionListener() {
/**
************************************************************************************
* Search the database tables and display the results
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Check if the search field is blank
if (searchFld.getText().isEmpty()) {
// Inform the user that the input value is invalid
new CcddDialogHandler().showMessageDialog(CcddSearchDialog.this, "<html><b>Search text cannot be blank", "Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
} else // The search field contains text
{
List<Object[]> resultsDataList = null;
// Update the search string list
searchFld.updateList(searchFld.getText());
// Store the search list in the program preferences
ccddMain.getProgPrefs().put(SEARCH_STRINGS, searchFld.getListAsString());
switch(searchDlgType) {
case TABLES:
case SCRIPTS:
// Search the database tables or scripts and display the results
resultsDataList = searchHandler.searchTablesOrScripts(searchFld.getText(), ignoreCaseCb.isSelected(), allowRegexCb.isSelected(), (searchDlgType == SearchDialogType.TABLES ? dataTablesOnlyCb.isSelected() : false), searchColumns);
break;
case LOG:
// Search the event log and display the results
resultsDataList = searchHandler.searchEventLogFile(searchFld.getText(), ignoreCaseCb.isSelected(), targetRow);
break;
}
// Check if this is a table search
if (searchDlgType == SearchDialogType.TABLES) {
List<Object[]> removeResults = new ArrayList<Object[]>();
// Get the list of selected tables
List<String> filterTables = tableTree.getSelectedTablesWithChildren();
// Add the ancestors (instances and prototype) of the selected tables to
// the list of filter tables
tableTree.addTableAncestors(filterTables, true);
// Check if tables were selected to filter the search results
if (!filterTables.isEmpty()) {
// Step through the search results
for (Object[] result : resultsDataList) {
// Separate the target into the target type and owner
String[] typeAndOwner = CcddUtilities.removeHTMLTags(result[SearchResultsColumnInfo.OWNER.ordinal()].toString()).split(": ");
// if owner isn't one of the selected tables or its prototype
if (!((typeAndOwner[0].equals(SearchTarget.TABLE.getTargetName(false)) || typeAndOwner[0].equals(SearchTarget.TABLE_FIELD.getTargetName(false))) && filterTables.contains(typeAndOwner[1]))) {
// Add the search result to the list of those to remove
removeResults.add(result);
}
// TODO Since prototype tables are automatically added (needed
// since a child only returns matches in the values table), a false
// match can occur if the filter table is a child, the hit is in
// the child's prototype, and the child has overridden the
// prototype's value where the match occurs
}
// Remove the search results that aren't in the selected table(s)
resultsDataList.removeAll(removeResults);
}
}
// Convert the results list to an array and display the results in the dialog's
// search results table
resultsData = resultsDataList.toArray(new Object[0][0]);
resultsTable.loadAndFormatData();
}
// Update the number of results found label
numResultsLbl.setText(" (" + resultsData.length + " found)");
}
});
JButton btnOpen = null;
// Check if this is the table search dialog
if (searchDlgType == SearchDialogType.TABLES) {
// Open table(s) button
btnOpen = CcddButtonPanelHandler.createButton("Open", TABLE_ICON, KeyEvent.VK_O, "Open the table(s) associated with the selected search result(s)");
// Add a listener for the Open button
btnOpen.addActionListener(new ActionListener() {
/**
************************************************************************************
* Open the selected table(s)
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
openTables();
}
});
}
// Print inconsistencies button
JButton btnPrint = CcddButtonPanelHandler.createButton("Print", PRINT_ICON, KeyEvent.VK_P, "Print the search results list");
// Add a listener for the Print button
btnPrint.addActionListener(new ActionListener() {
/**
************************************************************************************
* Print the search results list
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
resultsTable.printTable("Search Results", null, CcddSearchDialog.this, PageFormat.LANDSCAPE);
}
});
// Close search dialog button
JButton btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the search dialog");
// Add a listener for the Close button
btnClose.addActionListener(new ActionListener() {
/**
************************************************************************************
* Close the search dialog
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
CcddSearchDialog.this.closeFrame();
}
});
// Create a panel for the dialog buttons and add the buttons to the panel
JPanel buttonPnl = new JPanel();
buttonPnl.setBorder(BorderFactory.createEmptyBorder());
buttonPnl.add(btnSearch);
// Check if this is the table search dialog
if (searchDlgType == SearchDialogType.TABLES) {
buttonPnl.add(btnOpen);
}
buttonPnl.add(btnPrint);
buttonPnl.add(btnClose);
// Get the dialog title based on the search type
String title = null;
switch(searchDlgType) {
case TABLES:
title = "Search Tables";
break;
case SCRIPTS:
title = "Search Scripts";
break;
case LOG:
title = getLogTitle();
break;
}
// Display the search dialog
createFrame(parent, dialogPnl, buttonPnl, btnSearch, title, null);
}
use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.
the class CcddTableTypeHandler method getTypeInformation.
/**
********************************************************************************************
* Get an array of the type names and descriptions, sorted by type name
*
* @return Array of the type names and descriptions, sorted by type name
********************************************************************************************
*/
protected String[][] getTypeInformation() {
ArrayListMultiple typeInfo = new ArrayListMultiple();
// Step through each table type definition
for (TypeDefinition typeDefn : typeDefinitions) {
// Add the table type name and description to the list
typeInfo.add(new String[] { typeDefn.getName(), typeDefn.getDescription() });
}
// Sort the list based on the table type name
typeInfo.sort(ArrayListMultipleSortType.STRING);
return typeInfo.toArray(new String[0][0]);
}
use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getCopyTableEntriesWithMacros.
/**
********************************************************************************************
* Get the copy table for the messages of the specified data stream. Any macro embedded in a
* variable name is left in place
*
* @param streamName
* data stream name
*
* @param headerSize
* size of the message header in bytes. For example, the CCSDS header size is 12
*
* @param tlmMessageIDs
* array containing string array entries giving the structure table path+name and
* the table's associated message ID name
*
* @param optimize
* true to combine memory copy calls for consecutive variables in the copy table
*
* @return Array containing the copy table entries with any macro embedded in a variable name
* left in place; returns blank if there are no entries for the specified data stream
* or if data stream name is invalid
********************************************************************************************
*/
public String[][] getCopyTableEntriesWithMacros(String streamName, int headerSize, String[][] tlmMessageIDs, boolean optimize) {
// Convert the array of structure tables and their message ID names to a list
ArrayListMultiple tlmMessageIDsList = new ArrayListMultiple();
tlmMessageIDsList.addAll(Arrays.asList(tlmMessageIDs));
// Create the copy table with macros unexpanded
return getCopyTableEntries(streamName, headerSize, null, tlmMessageIDsList, optimize, false);
}
Aggregations