use of org.knime.core.node.tableview.FindPosition.SearchOptions in project knime-core by knime.
the class FindPositionTest method testNormalTable.
@Test
public void testNormalTable() throws Exception {
FindPosition f = new FindPosition(1, 1, new SearchOptions(m_isSearchRowID, m_isSearchColumnName, m_isSearchData));
f.reset();
f.mark();
// coverage is all
f.toString();
if (m_isSearchColumnName) {
assertThat(f.next(), is(true));
assertThat("Expected header row", f.getSearchRow(), is(-1));
assertThat("Expected first column", f.getSearchColumn(), is(0));
assertThat("Not at mark", f.reachedMark(), is(false));
}
if (m_isSearchRowID) {
assertThat(f.next(), is(true));
assertThat("Expected first row key", f.getSearchRow(), is(0));
assertThat("Expected rowID column", f.getSearchColumn(), is(-1));
assertThat("Not at mark", f.reachedMark(), is(false));
}
if (m_isSearchData) {
assertThat(f.next(), is(true));
assertThat("Expected first data element", f.getSearchRow(), is(0));
assertThat("Expected rowID column", f.getSearchColumn(), is(0));
assertThat("Not at mark", f.reachedMark(), is(false));
}
assertThat(f.next(), is(false));
}
use of org.knime.core.node.tableview.FindPosition.SearchOptions in project knime-core by knime.
the class FindPositionTest method testNoRowsTable.
@Test
public void testNoRowsTable() throws Exception {
FindPosition f = new FindPosition(0, 1, new SearchOptions(m_isSearchRowID, m_isSearchColumnName, m_isSearchData));
f.reset();
f.mark();
if (m_isSearchColumnName) {
assertThat(f.next(), is(true));
assertThat("Expected header row", f.getSearchRow(), is(-1));
assertThat("Expected first column", f.getSearchColumn(), is(0));
assertThat("Not at mark", f.reachedMark(), is(false));
}
assertThat(f.next(), is(false));
}
use of org.knime.core.node.tableview.FindPosition.SearchOptions in project knime-core by knime.
the class FindPositionTest method testNoRowsNoColumnsTable.
@Test
public void testNoRowsNoColumnsTable() throws Exception {
FindPosition f = new FindPosition(0, 0, new SearchOptions(m_isSearchRowID, m_isSearchColumnName, m_isSearchData));
f.reset();
f.mark();
assertThat(f.next(), is(false));
}
use of org.knime.core.node.tableview.FindPosition.SearchOptions in project knime-core by knime.
the class TableView method registerFindAction.
/**
* Creates and registers the "Find ..." action on this component. Multiple invocation of this method have no effect
* (lazy initialization).
*
* @return The non-null action representing the find task.
* @see #registerNavigationActions()
*/
public TableAction registerFindAction() {
if (m_findAction == null) {
String name = "Find...";
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
TableAction action = new TableAction(stroke, name) {
@Override
public void actionPerformed(final ActionEvent e) {
if (!hasData()) {
return;
}
if (m_searchPosition == null) {
initNewSearchPostion(new SearchOptions(true, true, true));
}
m_searchPosition.reset();
SearchOptions searchOptions = m_searchPosition.getSearchOptions();
boolean isSearchRowID = searchOptions.isSearchRowID();
boolean isSearchColumnName = searchOptions.isSearchColumnName();
boolean isSearchData = searchOptions.isSearchData();
JCheckBox rowKeyBox = new JCheckBox("Search RowID Column", isSearchRowID);
JCheckBox colNameBox = new JCheckBox("Search Column Names", isSearchColumnName);
JCheckBox dataBox = new JCheckBox("Search Data", isSearchData);
JCheckBox[] asArray = new JCheckBox[] { rowKeyBox, colNameBox, dataBox };
rowKeyBox.addItemListener(new AtLeastOnButtonSelectedItemListener(dataBox, asArray));
colNameBox.addItemListener(new AtLeastOnButtonSelectedItemListener(rowKeyBox, asArray));
dataBox.addItemListener(new AtLeastOnButtonSelectedItemListener(rowKeyBox, asArray));
JCheckBox caseSensitiveBox = new JCheckBox("Case sensitive", m_searchString.map(i -> !i.isIgnoreCase()).orElse(false));
JCheckBox regexBox = new JCheckBox("Regular Expression", m_searchString.map(i -> i.isRegex()).orElse(false));
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("Options: "), BorderLayout.NORTH);
JPanel centerPanel = new JPanel(new GridLayout(0, 1));
centerPanel.add(rowKeyBox);
centerPanel.add(colNameBox);
centerPanel.add(dataBox);
centerPanel.add(new JLabel());
centerPanel.add(caseSensitiveBox);
centerPanel.add(regexBox);
centerPanel.add(new JLabel());
panel.add(centerPanel, BorderLayout.CENTER);
panel.add(new JLabel(" "), BorderLayout.WEST);
panel.add(new JLabel("Find String: "), BorderLayout.SOUTH);
SearchString newSearchString;
while (true) {
String in = (String) JOptionPane.showInputDialog(TableView.this, panel, "Search", JOptionPane.QUESTION_MESSAGE, null, null, m_searchString.map(s -> s.getSearchString()).orElse(""));
if (StringUtils.isEmpty(in)) {
// canceled
return;
}
try {
newSearchString = new SearchString(in, !caseSensitiveBox.isSelected(), regexBox.isSelected());
break;
} catch (PatternSyntaxException pse) {
JOptionPane.showMessageDialog(TableView.this, pse.getMessage(), "Invalid regular expression", JOptionPane.ERROR_MESSAGE);
}
}
searchOptions = new SearchOptions(rowKeyBox.isSelected(), colNameBox.isSelected(), dataBox.isSelected());
find(newSearchString, searchOptions);
}
};
registerAction(action);
m_findAction = action;
}
return m_findAction;
}
use of org.knime.core.node.tableview.FindPosition.SearchOptions in project knime-core by knime.
the class FindPositionTest method testNoColumnsTable.
@Test
public void testNoColumnsTable() throws Exception {
FindPosition f = new FindPosition(1, 0, new SearchOptions(m_isSearchRowID, m_isSearchColumnName, m_isSearchData));
f.reset();
f.mark();
if (m_isSearchRowID) {
assertThat(f.next(), is(true));
assertThat("Expected first row key", f.getSearchRow(), is(0));
assertThat("Expected rowID column", f.getSearchColumn(), is(-1));
assertThat("Not at mark", f.reachedMark(), is(false));
}
assertThat(f.next(), is(false));
}
Aggregations