diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/browser/FilterComp.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/browser/FilterComp.java index 5976c54c7a..3cd7bfbe1c 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/browser/FilterComp.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/browser/FilterComp.java @@ -41,6 +41,7 @@ import com.raytheon.uf.viz.datadelivery.filter.IFilterUpdate; import com.raytheon.viz.ui.widgets.duallist.DualList; import com.raytheon.viz.ui.widgets.duallist.DualListConfig; import com.raytheon.viz.ui.widgets.duallist.IUpdate; +import com.raytheon.viz.ui.widgets.duallist.SearchUtils; /** * Standard Filter Composite @@ -55,6 +56,7 @@ import com.raytheon.viz.ui.widgets.duallist.IUpdate; * 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. + * Aug 20, 2013 1733 mpduff Match any/all now executes the search on selection. * * * @@ -223,9 +225,10 @@ public class FilterComp extends AbstractFilterComp implements IUpdate { matchAnyBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - if (matchAnyBtn.getSelection() == true) { + if (matchAnyBtn.getSelection()) { matchAnyFlag = true; } + handleSearch(); } }); @@ -235,9 +238,10 @@ public class FilterComp extends AbstractFilterComp implements IUpdate { matchAllBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - if (matchAllBtn.getSelection() == true) { + if (matchAllBtn.getSelection()) { matchAnyFlag = false; } + handleSearch(); } }); } @@ -284,26 +288,36 @@ public class FilterComp extends AbstractFilterComp implements IUpdate { boolean excludeSearch = exclusionBtn.getSelection(); String search = regExTxt.getText(); + dualConfig.setSearchField(search); + dualConfig.setMatchAny(matchAnyFlag); + List fullList = dualConfig.getFullList(); + if (search != null && search.length() > 0) { - - dualConfig.setSearchField(search); - String[] filteredList = dualConfig.getFullList().toArray( new String[dualConfig.getFullList().size()]); - List tmpFilterList = DataBrowserUtils.search(search, + List tmpFilterList = SearchUtils.search(search, filteredList, matchAnyFlag, caseBtn.getSelection(), excludeSearch); // Clear the list and add the newly filtered items dualList.clearAvailableList(false); + for (String s : dualList.getSelectedListItems()) { + tmpFilterList.remove(s); + } dualList.setAvailableItems(tmpFilterList); return; + } else { + + // Clear the list and repopulate with the full list + dualList.clearAvailableList(false); + for (String s : dualList.getSelectedListItems()) { + fullList.remove(s); + } + dualList.setAvailableItems(fullList); } - // Clear the list and repopulate with the full list - dualList.clearAvailableList(false); - dualList.setAvailableItems(dualConfig.getFullList()); + dualList.enableDisableLeftRightButtons(); } /** diff --git a/cave/com.raytheon.viz.ui/.classpath b/cave/com.raytheon.viz.ui/.classpath index 0c34460164..1fa3e6803d 100644 --- a/cave/com.raytheon.viz.ui/.classpath +++ b/cave/com.raytheon.viz.ui/.classpath @@ -3,6 +3,5 @@ - diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/DualList.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/DualList.java index d6a2f8c032..951a019e73 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/DualList.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/DualList.java @@ -56,6 +56,7 @@ import com.raytheon.viz.ui.widgets.duallist.ButtonImages.ButtonImage; * Sep 07, 2012 684 mpduff Deselect selection prior to selecting new items. * Dec 17, 2012 1431 mpduff Fix filter problem when deselecting items. * Jan 07, 2013 1456 bgonzale Added setSelectedList(ArrayList). + * Aug 20, 2013 1733 mpduff Search now uses SearchUtils. * * * @@ -258,11 +259,7 @@ public class DualList extends Composite { availableList.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - if (availableList.getSelectionCount() > 0) { - moveRightBtn.setEnabled(true); - } else { - moveRightBtn.setEnabled(false); - } + enableDisableLeftRightButtons(); } }); @@ -375,12 +372,7 @@ public class DualList extends Composite { selectedList.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - if (selectedList.getSelectionCount() > 0) { - moveLeftBtn.setEnabled(true); - } else { - moveLeftBtn.setEnabled(false); - } - + enableDisableLeftRightButtons(); enableDisableUpDownButtons(); } }); @@ -487,13 +479,7 @@ public class DualList extends Composite { } } - if (availableList.getItemCount() > 0) { - moveAllRightBtn.setEnabled(true); - } - - if (selectedList.getItemCount() > 0) { - moveAllLeftBtn.setEnabled(true); - } + enableDisableLeftRightButtons(); entriesUpdated(); } @@ -551,14 +537,11 @@ public class DualList extends Composite { } else { selectedList.setSelection(selectedList.getItemCount() - 1); } - } else { - moveLeftBtn.setEnabled(false); } - moveAllRightBtn.setEnabled(true); - entriesUpdated(); enableDisableUpDownButtons(); + enableDisableLeftRightButtons(); } /** @@ -570,23 +553,19 @@ public class DualList extends Composite { moveAllLeft = true; for (String sl : selectedList.getItems()) { - if (!list.contains(sl)) { selectedList.remove(sl); } - } reloadAvailableList(); - moveLeftBtn.setEnabled(false); - moveAllLeftBtn.setEnabled(false); - moveAllRightBtn.setEnabled(true); if (callEntriesUpdated == true) { entriesUpdated(); } enableDisableUpDownButtons(); + enableDisableLeftRightButtons(); } /** @@ -621,12 +600,10 @@ public class DualList extends Composite { } availableList.removeAll(); - moveRightBtn.setEnabled(false); - moveAllRightBtn.setEnabled(false); - moveAllLeftBtn.setEnabled(true); entriesUpdated(); enableDisableUpDownButtons(); + enableDisableLeftRightButtons(); } /** @@ -647,9 +624,7 @@ public class DualList extends Composite { availableList.remove(availableList.getSelectionIndices()); - if (availableList.getItemCount() == 0) { - moveRightBtn.setEnabled(false); - } else { + if (availableList.getItemCount() > 0) { if (firstIdxSelected > availableList.getItemCount() - 1) { availableList.select(availableList.getItemCount() - 1); } else { @@ -657,10 +632,9 @@ public class DualList extends Composite { } } - moveAllLeftBtn.setEnabled(true); - entriesUpdated(); enableDisableUpDownButtons(); + enableDisableLeftRightButtons(); } /** @@ -702,7 +676,6 @@ public class DualList extends Composite { String[] selectedStrings = availableList.getSelection(); ArrayList availableListNew = new ArrayList(); - String search = config.getSearchField(); String[] selectedItemArray = selectedList.getItems(); ArrayList selectedItemList = new ArrayList(); @@ -745,29 +718,15 @@ public class DualList extends Composite { if (moveAllLeft) { availableList.removeAll(); - // Add all matching search field text to available list - for (String s : config.getFullList()) { - if (!config.isCaseFlag()) { - if (s.toLowerCase().contains(search.toLowerCase())) { - if (!config.isExcludeFlag()) { - availableList.add(s); - } - } else { - if (config.isExcludeFlag()) { - availableList.add(s); - } - } - } else { - if (s.contains(search)) { - if (!config.isExcludeFlag()) { - availableList.add(s); - } - } else { - if (config.isExcludeFlag()) { - availableList.add(s); - } - } - } + String[] fullList = config.getFullList().toArray( + new String[config.getFullList().size()]); + java.util.List filteredList = SearchUtils.search( + config.getSearchField(), fullList, + config.getMatchAny(), config.isCaseFlag(), + config.isExcludeFlag()); + + for (String s : filteredList) { + availableList.add(s); } } else if (moveLeft) { // Add selected item matching search field text to available @@ -969,4 +928,14 @@ public class DualList extends Composite { public void setConfig(DualListConfig config) { this.config = config; } + + /** + * Enable/disable left/right movement buttons + */ + public void enableDisableLeftRightButtons() { + moveAllRightBtn.setEnabled(availableList.getItemCount() > 0); + moveAllLeftBtn.setEnabled(selectedList.getItemCount() > 0); + moveRightBtn.setEnabled(availableList.getSelectionCount() > 0); + moveLeftBtn.setEnabled(selectedList.getSelectionCount() > 0); + } } \ No newline at end of file diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/DualListConfig.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/DualListConfig.java index 5314d4c36f..ccfbfbc468 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/DualListConfig.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/DualListConfig.java @@ -35,6 +35,7 @@ import java.util.List; * May 31, 2012 mpduff Initial creation. * Aug 10, 2012 1002 mpduff Added numeric flag for sorting. * Jan 07, 2013 1431 mpduff Add case sensitive and exclude flags. + * Aug 20, 2013 1733 mpduff Add match flag. * * * @@ -104,6 +105,12 @@ public class DualListConfig { /** Flag for numeric data */ private boolean numericData = false; + /** + * Match any/all flag. True is match any, false is match all. Only used when + * searchField != null; + */ + private boolean matchAny = true; + /** * Constructor. */ @@ -250,7 +257,7 @@ public class DualListConfig { * @return The array of all available items. */ public List getFullList() { - return fullList; + return new ArrayList(fullList); } /** @@ -334,4 +341,23 @@ public class DualListConfig { public void setExcludeFlag(boolean excludeFlag) { this.excludeFlag = excludeFlag; } + + /** + * true is match any, false is match all + * + * @return the matchAny + */ + public boolean getMatchAny() { + return matchAny; + } + + /** + * true is match any, false is match all + * + * @param matchAny + * the matchAny to set + */ + public void setMatchAny(boolean matchAny) { + this.matchAny = matchAny; + } } diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/browser/DataBrowserUtils.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/SearchUtils.java similarity index 94% rename from cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/browser/DataBrowserUtils.java rename to cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/SearchUtils.java index b08de8856f..8e2595495f 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/browser/DataBrowserUtils.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/widgets/duallist/SearchUtils.java @@ -17,7 +17,7 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.viz.datadelivery.browser; +package com.raytheon.viz.ui.widgets.duallist; import java.util.ArrayList; import java.util.List; @@ -33,6 +33,7 @@ import java.util.regex.Pattern; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Feb 25, 2013 1588 mpduff Initial creation. + * Aug 20, 2013 1733 mpduff Moved and renamed. * * * @@ -40,7 +41,7 @@ import java.util.regex.Pattern; * @version 1.0 */ -public class DataBrowserUtils { +public class SearchUtils { private static final Pattern WILDCARD_PATTERN = Pattern.compile("\\*"); @@ -120,7 +121,9 @@ public class DataBrowserUtils { } else { if (testCaseItem.contains(term) != excludeSearchFlag) { if (matchAnyFlag) { - results.add(item); + if (!results.contains(item)) { + results.add(item); + } } else { holder.add(term); } diff --git a/tests/.classpath b/tests/.classpath index 49efdea148..9a6f52328f 100644 --- a/tests/.classpath +++ b/tests/.classpath @@ -160,5 +160,6 @@ + diff --git a/cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/RGBColorsTest.java b/tests/manual/com/raytheon/viz/ui/RGBColorsTest.java similarity index 100% rename from cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/RGBColorsTest.java rename to tests/manual/com/raytheon/viz/ui/RGBColorsTest.java diff --git a/cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/widgets/LabeledDoubleScaleTest.java b/tests/manual/com/raytheon/viz/ui/widgets/LabeledDoubleScaleTest.java similarity index 100% rename from cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/widgets/LabeledDoubleScaleTest.java rename to tests/manual/com/raytheon/viz/ui/widgets/LabeledDoubleScaleTest.java diff --git a/cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/widgets/LabeledScaleTest.java b/tests/manual/com/raytheon/viz/ui/widgets/LabeledScaleTest.java similarity index 100% rename from cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/widgets/LabeledScaleTest.java rename to tests/manual/com/raytheon/viz/ui/widgets/LabeledScaleTest.java diff --git a/cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/widgets/SpinScaleTest.java b/tests/manual/com/raytheon/viz/ui/widgets/SpinScaleTest.java similarity index 100% rename from cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/widgets/SpinScaleTest.java rename to tests/manual/com/raytheon/viz/ui/widgets/SpinScaleTest.java diff --git a/cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/widgets/ToggleSelectListTest.java b/tests/manual/com/raytheon/viz/ui/widgets/ToggleSelectListTest.java similarity index 100% rename from cave/com.raytheon.viz.ui/tests/com/raytheon/viz/ui/widgets/ToggleSelectListTest.java rename to tests/manual/com/raytheon/viz/ui/widgets/ToggleSelectListTest.java diff --git a/tests/unit/com/raytheon/uf/viz/datadelivery/browser/DataBrowserRegexTest.java b/tests/unit/com/raytheon/viz/ui/widgets/duallist/SearchUtilsTest.java similarity index 84% rename from tests/unit/com/raytheon/uf/viz/datadelivery/browser/DataBrowserRegexTest.java rename to tests/unit/com/raytheon/viz/ui/widgets/duallist/SearchUtilsTest.java index 8e98e6fe94..77cbcf3f4f 100644 --- a/tests/unit/com/raytheon/uf/viz/datadelivery/browser/DataBrowserRegexTest.java +++ b/tests/unit/com/raytheon/viz/ui/widgets/duallist/SearchUtilsTest.java @@ -17,7 +17,7 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.viz.datadelivery.browser; +package com.raytheon.viz.ui.widgets.duallist; import static org.junit.Assert.assertNull; @@ -27,6 +27,8 @@ import java.util.List; import org.junit.Test; +import com.raytheon.viz.ui.widgets.duallist.SearchUtils; + /** * Test the filter functionality of the Dataset Discovery Brower's FilterComps. * @@ -37,6 +39,7 @@ import org.junit.Test; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Feb 25, 2013 1588 mpduff Initial creation. + * Aug 20, 2013 1733 mpduff Moved and renamed. * * * @@ -44,7 +47,7 @@ import org.junit.Test; * @version 1.0 */ -public class DataBrowserRegexTest { +public class SearchUtilsTest { private static final List itemList = Arrays.asList("temp", "surface", "temp2", "temp3", "temp4", "wndSpd", "wndDir", "pres", @@ -66,8 +69,8 @@ public class DataBrowserRegexTest { String searchTerm = "Emp"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, false, false); + List results = SearchUtils.search(searchTerm, fullList, true, + false, false); String msg = checkResults(expected, results); assertNull(msg); @@ -87,8 +90,8 @@ public class DataBrowserRegexTest { String searchTerm = "emp"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, true, false); + List results = SearchUtils.search(searchTerm, fullList, true, + true, false); String msg = checkResults(expected, results); assertNull(msg); @@ -110,8 +113,8 @@ public class DataBrowserRegexTest { String searchTerm = "emp"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, false, true); + List results = SearchUtils.search(searchTerm, fullList, true, + false, true); String msg = checkResults(expected, results); assertNull(msg); @@ -133,8 +136,8 @@ public class DataBrowserRegexTest { String searchTerm = "emp"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, true, true); + List results = SearchUtils.search(searchTerm, fullList, true, + true, true); String msg = checkResults(expected, results); assertNull(msg); @@ -154,8 +157,8 @@ public class DataBrowserRegexTest { String searchTerm = "Te 3"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, false, false); + List results = SearchUtils.search(searchTerm, fullList, true, + false, false); String msg = checkResults(expected, results); assertNull(msg); @@ -172,8 +175,8 @@ public class DataBrowserRegexTest { String searchTerm = "Te 3"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - false, false, false); + List results = SearchUtils.search(searchTerm, fullList, false, + false, false); String msg = checkResults(expected, results); assertNull(msg); @@ -190,8 +193,8 @@ public class DataBrowserRegexTest { String searchTerm = "te 3"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - false, true, false); + List results = SearchUtils.search(searchTerm, fullList, false, + true, false); String msg = checkResults(expected, results); assertNull(msg); @@ -208,8 +211,8 @@ public class DataBrowserRegexTest { String searchTerm = "T*3"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, false, false); + List results = SearchUtils.search(searchTerm, fullList, true, + false, false); String msg = checkResults(expected, results); assertNull(msg); @@ -226,8 +229,8 @@ public class DataBrowserRegexTest { String searchTerm = "t*3"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, true, false); + List results = SearchUtils.search(searchTerm, fullList, true, + true, false); String msg = checkResults(expected, results); assertNull(msg); @@ -249,8 +252,8 @@ public class DataBrowserRegexTest { String searchTerm = "te*3"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, false, true); + List results = SearchUtils.search(searchTerm, fullList, true, + false, true); String msg = checkResults(expected, results); assertNull(msg); } @@ -268,8 +271,8 @@ public class DataBrowserRegexTest { String searchTerm = "t*3 wnd"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - true, false, false); + List results = SearchUtils.search(searchTerm, fullList, true, + false, false); String msg = checkResults(expected, results); assertNull(msg); @@ -286,8 +289,8 @@ public class DataBrowserRegexTest { String searchTerm = "t*3 mp"; String[] fullList = itemList.toArray(new String[itemList.size()]); - List results = DataBrowserUtils.search(searchTerm, fullList, - false, false, false); + List results = SearchUtils.search(searchTerm, fullList, false, + false, false); String msg = checkResults(expected, results); assertNull(msg);