Issue #1588 - Fix match any/all in data browser dialog
Change-Id: I30491d170611f3eec44adcf8b2bd99a445c09a49 Former-commit-id:af47a02e47
[formerly0d2c817680
] [formerlyd00a790d7b
] [formerlyaf47a02e47
[formerly0d2c817680
] [formerlyd00a790d7b
] [formerly086d24acc8
[formerlyd00a790d7b
[formerly b9945e70a6b96a2f4b1c24b2308bb424e4cd7ee5]]]] Former-commit-id:086d24acc8
Former-commit-id:f73faee133
[formerlydccb6b94b9
] [formerly f34a7712b345b1738f4e1c4927c8c43d0e321466 [formerly1365596d4d
]] Former-commit-id: 5556e6f398a9c701dd666e73aee68a1b5fe828a7 [formerlyce30c45c88
] Former-commit-id:7fc320844f
This commit is contained in:
parent
e9cbfb8c57
commit
d6fbe05ab7
4 changed files with 493 additions and 68 deletions
|
@ -7,7 +7,7 @@
|
|||
<filterId>Data Provider</filterId>
|
||||
<settings name="availableText" value="Available Providers:"/>
|
||||
<settings name="selectedText" value="Selected Providers:"/>
|
||||
<settings name="showMatch" value="true"/>
|
||||
<settings name="showMatch" value="false"/>
|
||||
<settings name="showDualList" value="true"/>
|
||||
</Filter>
|
||||
<Filter>
|
||||
|
@ -17,7 +17,7 @@
|
|||
<settings name="availableText" value="Available Data Sets:"/>
|
||||
<settings name="selectedText" value="Selected Data Sets:"/>
|
||||
<settings name="showRegEx" value="true"/>
|
||||
<settings name="showMatch" value="false"/>
|
||||
<settings name="showMatch" value="true"/>
|
||||
<settings name="showDualList" value="true"/>
|
||||
</Filter>
|
||||
<Filter>
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.viz.datadelivery.browser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Data Browser Utility Class.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 25, 2013 1588 mpduff Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mpduff
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class DataBrowserUtils {
|
||||
|
||||
private static final Pattern WILDCARD_PATTERN = Pattern.compile("\\*");
|
||||
|
||||
private static final Pattern SPACES_PATTERN = Pattern.compile("\\s+");
|
||||
|
||||
/**
|
||||
* Search a list of items.
|
||||
*
|
||||
* @param search
|
||||
* The search string
|
||||
* @param fullList
|
||||
* List of items to search
|
||||
* @param matchAnyFlag
|
||||
* The match any/all flag, true for match any
|
||||
* @param caseSensitiveFlag
|
||||
* The case sensitive flag, true for case sensitive
|
||||
* @param excludeSearchFlag
|
||||
* The excludeSearchFlag, true for an exclude search
|
||||
* @return List of matching items
|
||||
*/
|
||||
public static List<String> search(String search, String[] fullList,
|
||||
boolean matchAnyFlag, boolean caseSensitiveFlag,
|
||||
boolean excludeSearchFlag) {
|
||||
List<String> results = new ArrayList<String>();
|
||||
|
||||
if (search == null) {
|
||||
return results;
|
||||
}
|
||||
|
||||
// this is used for match all, holds the matched terms to see if all get
|
||||
// matched or not
|
||||
List<String> holder = new ArrayList<String>();
|
||||
String testCaseItem;
|
||||
|
||||
if (!caseSensitiveFlag) {
|
||||
search = search.toLowerCase();
|
||||
}
|
||||
|
||||
String[] searchTerms = SPACES_PATTERN.split(search);
|
||||
|
||||
for (String item : fullList) {
|
||||
for (String term : searchTerms) {
|
||||
if (!caseSensitiveFlag) {
|
||||
testCaseItem = item.toLowerCase();
|
||||
} else {
|
||||
testCaseItem = item;
|
||||
}
|
||||
|
||||
if (term.contains("*")) {
|
||||
String[] parts = WILDCARD_PATTERN.split(term);
|
||||
boolean valid = true;
|
||||
String part;
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
if (valid == false) {
|
||||
break;
|
||||
}
|
||||
part = parts[i];
|
||||
|
||||
if (!testCaseItem.contains(part) != excludeSearchFlag) {
|
||||
valid = false;
|
||||
continue;
|
||||
}
|
||||
if (i > 0) {
|
||||
if (!excludeSearchFlag) {
|
||||
// check the order
|
||||
if (!(testCaseItem.indexOf(parts[i - 1]) < testCaseItem
|
||||
.indexOf(parts[i]))) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
results.add(item);
|
||||
}
|
||||
} else {
|
||||
if (testCaseItem.contains(term) != excludeSearchFlag) {
|
||||
if (matchAnyFlag) {
|
||||
results.add(item);
|
||||
} else {
|
||||
holder.add(term);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchAnyFlag) {
|
||||
if (holder.size() == searchTerms.length) {
|
||||
results.add(item);
|
||||
}
|
||||
holder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
**/
|
||||
package com.raytheon.uf.viz.datadelivery.browser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.FocusAdapter;
|
||||
|
@ -54,6 +54,7 @@ import com.raytheon.viz.ui.widgets.duallist.IUpdate;
|
|||
* Feb 21, 2012 mpduff Initial creation
|
||||
* Aug 08, 2012 863 jpiatt Added new interface method.
|
||||
* Jan 07, 2013 1432 mpduff Fix case sensitive and exclude checkboxes.
|
||||
* Feb 25, 2013 1588 mpduff Fix match any/all.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -280,80 +281,19 @@ public class FilterComp extends AbstractFilterComp implements IUpdate {
|
|||
* Handle the search action.
|
||||
*/
|
||||
private void handleSearch() {
|
||||
boolean excludeSearch = !exclusionBtn.getSelection();
|
||||
boolean excludeSearch = exclusionBtn.getSelection();
|
||||
|
||||
String search = regExTxt.getText();
|
||||
ArrayList<String> tmpFilterList = new ArrayList<String>();
|
||||
if (search != null && search.length() > 0) {
|
||||
|
||||
dualConfig.setSearchField(search);
|
||||
|
||||
String[] parts;
|
||||
|
||||
/* Iterate over the filtered list of items */
|
||||
String[] filteredList = dualConfig.getFullList().toArray(
|
||||
new String[dualConfig.getFullList().size()]);
|
||||
|
||||
// Search contains 1 or more *
|
||||
if (search.contains("*")) {
|
||||
parts = search.split("\\*");
|
||||
if (parts.length > 0) {
|
||||
ITEM: for (String item : filteredList) {
|
||||
for (String part : parts) {
|
||||
if (part.length() > 0) {
|
||||
if (caseBtn.getSelection()) {
|
||||
if (item.contains(part) == excludeSearch) {
|
||||
continue ITEM;
|
||||
}
|
||||
} else {
|
||||
if (!item.toLowerCase().contains(
|
||||
part.toLowerCase()) == excludeSearch) {
|
||||
continue ITEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// all parts are contained in the item, now figure
|
||||
// out if they are in the right order
|
||||
int idx = item.indexOf(parts[0]);
|
||||
for (int i = 1; i < parts.length; i++) {
|
||||
int curIdx = 0;
|
||||
if (caseBtn.getSelection()) {
|
||||
curIdx = item.indexOf(parts[i]);
|
||||
} else {
|
||||
curIdx = item.toLowerCase().indexOf(
|
||||
parts[i].toLowerCase());
|
||||
}
|
||||
|
||||
if (curIdx > idx) {
|
||||
idx = curIdx;
|
||||
} else {
|
||||
break ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
// Made it this far so item is in list
|
||||
tmpFilterList.add(item);
|
||||
}
|
||||
dualList.clearAvailableList(false);
|
||||
dualList.setAvailableItems(tmpFilterList);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
// No * in search
|
||||
for (String item : filteredList) {
|
||||
if (caseBtn.getSelection()) {
|
||||
if (item.contains(search) == excludeSearch) {
|
||||
tmpFilterList.add(item);
|
||||
}
|
||||
} else {
|
||||
if (item.toLowerCase().contains(search.toLowerCase()) == excludeSearch) {
|
||||
tmpFilterList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> tmpFilterList = DataBrowserUtils.search(search,
|
||||
filteredList, matchAnyFlag, caseBtn.getSelection(),
|
||||
excludeSearch);
|
||||
|
||||
// Clear the list and add the newly filtered items
|
||||
dualList.clearAvailableList(false);
|
||||
|
|
|
@ -0,0 +1,344 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.viz.datadelivery.browser;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test the filter functionality of the Dataset Discovery Brower's FilterComps.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 25, 2013 1588 mpduff Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mpduff
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class DataBrowserRegexTest {
|
||||
|
||||
private static final List<String> itemList = Arrays.asList("temp",
|
||||
"surface", "temp2", "temp3", "temp4", "wndSpd", "wndDir", "pres",
|
||||
"dptmp", "dpd");
|
||||
|
||||
private static final String NL = "\n";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSingleTermMatch_NoCase_NoExclude() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp");
|
||||
expected.add("temp2");
|
||||
expected.add("temp3");
|
||||
expected.add("temp4");
|
||||
|
||||
String searchTerm = "Emp";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, false, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSingleTermMatch_Case_NoExclude() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp");
|
||||
expected.add("temp2");
|
||||
expected.add("temp3");
|
||||
expected.add("temp4");
|
||||
|
||||
String searchTerm = "emp";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, true, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSingleTermMatch_NoCase_Exclude() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("dpd");
|
||||
expected.add("dptmp");
|
||||
expected.add("surface");
|
||||
expected.add("wndSpd");
|
||||
expected.add("wndDir");
|
||||
expected.add("pres");
|
||||
|
||||
String searchTerm = "emp";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, false, true);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSingleTermMatch_Case_Exclude() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("dpd");
|
||||
expected.add("dptmp");
|
||||
expected.add("surface");
|
||||
expected.add("wndSpd");
|
||||
expected.add("wndDir");
|
||||
expected.add("pres");
|
||||
|
||||
String searchTerm = "emp";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, true, true);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMultipleTermMatchAnyNoCaseNoExclude() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp");
|
||||
expected.add("temp2");
|
||||
expected.add("temp3");
|
||||
expected.add("temp4");
|
||||
|
||||
String searchTerm = "Te 3";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, false, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMultipleTermMatchAllNoCaseNoExclude() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp3");
|
||||
|
||||
String searchTerm = "Te 3";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
false, false, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMultipleTermMatchAllCase_NoExclude() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp3");
|
||||
|
||||
String searchTerm = "te 3";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
false, true, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSingleTermMatchAnyNoCase_NoExclude_Wildcard() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp3");
|
||||
|
||||
String searchTerm = "T*3";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, false, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSingleTermMatchAnyCase_NoExclude_Wildcard() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp3");
|
||||
|
||||
String searchTerm = "t*3";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, true, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSingleTermMatchAnyNoCase_Exclude_Wildcard() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("surface");
|
||||
expected.add("wndSpd");
|
||||
expected.add("wndDir");
|
||||
expected.add("pres");
|
||||
expected.add("dptmp");
|
||||
expected.add("dpd");
|
||||
|
||||
String searchTerm = "te*3";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, false, true);
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMultipleTermMatchAnyNoCase_NoExclude_Wildcard() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp3");
|
||||
expected.add("wndSpd");
|
||||
expected.add("wndDir");
|
||||
|
||||
String searchTerm = "t*3 wnd";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
true, false, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMultipleTermMatchAllNoCase_NoExclude_Wildcard() {
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("temp3");
|
||||
|
||||
String searchTerm = "t*3 mp";
|
||||
String[] fullList = itemList.toArray(new String[itemList.size()]);
|
||||
|
||||
List<String> results = DataBrowserUtils.search(searchTerm, fullList,
|
||||
false, false, false);
|
||||
|
||||
String msg = checkResults(expected, results);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param expected
|
||||
* The expected results
|
||||
* @param results
|
||||
* The actual results
|
||||
* @return message null if lists match up, otherwise a message stating the
|
||||
* problem with the lists
|
||||
*/
|
||||
private String checkResults(List<String> expected, List<String> actual) {
|
||||
if (actual.containsAll(expected) && expected.containsAll(actual)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// lists don't match, didn't get back what we expected. Construct an
|
||||
// error message
|
||||
List<String> extraActual = new ArrayList<String>();
|
||||
for (String s : actual) {
|
||||
if (!expected.contains(s)) {
|
||||
extraActual.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> extraExpected = new ArrayList<String>();
|
||||
for (String s : expected) {
|
||||
if (!actual.contains(s)) {
|
||||
extraExpected.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (extraActual.size() > 0) {
|
||||
sb.append("Actual contained additional values:\n");
|
||||
for (String s : extraActual) {
|
||||
sb.append(s + NL);
|
||||
}
|
||||
}
|
||||
|
||||
if (extraExpected.size() > 0) {
|
||||
sb.append(NL);
|
||||
sb.append("Expected contained additional values:\n");
|
||||
for (String s : extraExpected) {
|
||||
sb.append(s + NL);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue