Issue #1733 - Fix issue with moving items between selected and available in dual list, moved some test code to test project

Change-Id: Ic46ce9adabf8a922066c2a2d58596504e244332c

Former-commit-id: 8a14be26db146b44fd364b26a694c2531ec843a4
This commit is contained in:
Mike Duff 2013-08-20 13:44:29 -05:00
parent 158b0f8564
commit a7b6f116bd
12 changed files with 114 additions and 99 deletions

View file

@ -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.DualList;
import com.raytheon.viz.ui.widgets.duallist.DualListConfig; import com.raytheon.viz.ui.widgets.duallist.DualListConfig;
import com.raytheon.viz.ui.widgets.duallist.IUpdate; import com.raytheon.viz.ui.widgets.duallist.IUpdate;
import com.raytheon.viz.ui.widgets.duallist.SearchUtils;
/** /**
* Standard Filter Composite * Standard Filter Composite
@ -55,6 +56,7 @@ import com.raytheon.viz.ui.widgets.duallist.IUpdate;
* Aug 08, 2012 863 jpiatt Added new interface method. * Aug 08, 2012 863 jpiatt Added new interface method.
* Jan 07, 2013 1432 mpduff Fix case sensitive and exclude checkboxes. * Jan 07, 2013 1432 mpduff Fix case sensitive and exclude checkboxes.
* Feb 25, 2013 1588 mpduff Fix match any/all. * Feb 25, 2013 1588 mpduff Fix match any/all.
* Aug 20, 2013 1733 mpduff Match any/all now executes the search on selection.
* *
* </pre> * </pre>
* *
@ -223,9 +225,10 @@ public class FilterComp extends AbstractFilterComp implements IUpdate {
matchAnyBtn.addSelectionListener(new SelectionAdapter() { matchAnyBtn.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (matchAnyBtn.getSelection() == true) { if (matchAnyBtn.getSelection()) {
matchAnyFlag = true; matchAnyFlag = true;
} }
handleSearch();
} }
}); });
@ -235,9 +238,10 @@ public class FilterComp extends AbstractFilterComp implements IUpdate {
matchAllBtn.addSelectionListener(new SelectionAdapter() { matchAllBtn.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (matchAllBtn.getSelection() == true) { if (matchAllBtn.getSelection()) {
matchAnyFlag = false; matchAnyFlag = false;
} }
handleSearch();
} }
}); });
} }
@ -284,26 +288,36 @@ public class FilterComp extends AbstractFilterComp implements IUpdate {
boolean excludeSearch = exclusionBtn.getSelection(); boolean excludeSearch = exclusionBtn.getSelection();
String search = regExTxt.getText(); String search = regExTxt.getText();
dualConfig.setSearchField(search);
dualConfig.setMatchAny(matchAnyFlag);
List<String> fullList = dualConfig.getFullList();
if (search != null && search.length() > 0) { if (search != null && search.length() > 0) {
dualConfig.setSearchField(search);
String[] filteredList = dualConfig.getFullList().toArray( String[] filteredList = dualConfig.getFullList().toArray(
new String[dualConfig.getFullList().size()]); new String[dualConfig.getFullList().size()]);
List<String> tmpFilterList = DataBrowserUtils.search(search, List<String> tmpFilterList = SearchUtils.search(search,
filteredList, matchAnyFlag, caseBtn.getSelection(), filteredList, matchAnyFlag, caseBtn.getSelection(),
excludeSearch); excludeSearch);
// Clear the list and add the newly filtered items // Clear the list and add the newly filtered items
dualList.clearAvailableList(false); dualList.clearAvailableList(false);
for (String s : dualList.getSelectedListItems()) {
tmpFilterList.remove(s);
}
dualList.setAvailableItems(tmpFilterList); dualList.setAvailableItems(tmpFilterList);
return; 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.enableDisableLeftRightButtons();
dualList.clearAvailableList(false);
dualList.setAvailableItems(dualConfig.getFullList());
} }
/** /**

View file

@ -3,6 +3,5 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -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. * Sep 07, 2012 684 mpduff Deselect selection prior to selecting new items.
* Dec 17, 2012 1431 mpduff Fix filter problem when deselecting items. * Dec 17, 2012 1431 mpduff Fix filter problem when deselecting items.
* Jan 07, 2013 1456 bgonzale Added setSelectedList(ArrayList<String>). * Jan 07, 2013 1456 bgonzale Added setSelectedList(ArrayList<String>).
* Aug 20, 2013 1733 mpduff Search now uses SearchUtils.
* *
* </pre> * </pre>
* *
@ -258,11 +259,7 @@ public class DualList extends Composite {
availableList.addSelectionListener(new SelectionAdapter() { availableList.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (availableList.getSelectionCount() > 0) { enableDisableLeftRightButtons();
moveRightBtn.setEnabled(true);
} else {
moveRightBtn.setEnabled(false);
}
} }
}); });
@ -375,12 +372,7 @@ public class DualList extends Composite {
selectedList.addSelectionListener(new SelectionAdapter() { selectedList.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (selectedList.getSelectionCount() > 0) { enableDisableLeftRightButtons();
moveLeftBtn.setEnabled(true);
} else {
moveLeftBtn.setEnabled(false);
}
enableDisableUpDownButtons(); enableDisableUpDownButtons();
} }
}); });
@ -487,13 +479,7 @@ public class DualList extends Composite {
} }
} }
if (availableList.getItemCount() > 0) { enableDisableLeftRightButtons();
moveAllRightBtn.setEnabled(true);
}
if (selectedList.getItemCount() > 0) {
moveAllLeftBtn.setEnabled(true);
}
entriesUpdated(); entriesUpdated();
} }
@ -551,14 +537,11 @@ public class DualList extends Composite {
} else { } else {
selectedList.setSelection(selectedList.getItemCount() - 1); selectedList.setSelection(selectedList.getItemCount() - 1);
} }
} else {
moveLeftBtn.setEnabled(false);
} }
moveAllRightBtn.setEnabled(true);
entriesUpdated(); entriesUpdated();
enableDisableUpDownButtons(); enableDisableUpDownButtons();
enableDisableLeftRightButtons();
} }
/** /**
@ -570,23 +553,19 @@ public class DualList extends Composite {
moveAllLeft = true; moveAllLeft = true;
for (String sl : selectedList.getItems()) { for (String sl : selectedList.getItems()) {
if (!list.contains(sl)) { if (!list.contains(sl)) {
selectedList.remove(sl); selectedList.remove(sl);
} }
} }
reloadAvailableList(); reloadAvailableList();
moveLeftBtn.setEnabled(false);
moveAllLeftBtn.setEnabled(false);
moveAllRightBtn.setEnabled(true);
if (callEntriesUpdated == true) { if (callEntriesUpdated == true) {
entriesUpdated(); entriesUpdated();
} }
enableDisableUpDownButtons(); enableDisableUpDownButtons();
enableDisableLeftRightButtons();
} }
/** /**
@ -621,12 +600,10 @@ public class DualList extends Composite {
} }
availableList.removeAll(); availableList.removeAll();
moveRightBtn.setEnabled(false);
moveAllRightBtn.setEnabled(false);
moveAllLeftBtn.setEnabled(true);
entriesUpdated(); entriesUpdated();
enableDisableUpDownButtons(); enableDisableUpDownButtons();
enableDisableLeftRightButtons();
} }
/** /**
@ -647,9 +624,7 @@ public class DualList extends Composite {
availableList.remove(availableList.getSelectionIndices()); availableList.remove(availableList.getSelectionIndices());
if (availableList.getItemCount() == 0) { if (availableList.getItemCount() > 0) {
moveRightBtn.setEnabled(false);
} else {
if (firstIdxSelected > availableList.getItemCount() - 1) { if (firstIdxSelected > availableList.getItemCount() - 1) {
availableList.select(availableList.getItemCount() - 1); availableList.select(availableList.getItemCount() - 1);
} else { } else {
@ -657,10 +632,9 @@ public class DualList extends Composite {
} }
} }
moveAllLeftBtn.setEnabled(true);
entriesUpdated(); entriesUpdated();
enableDisableUpDownButtons(); enableDisableUpDownButtons();
enableDisableLeftRightButtons();
} }
/** /**
@ -702,7 +676,6 @@ public class DualList extends Composite {
String[] selectedStrings = availableList.getSelection(); String[] selectedStrings = availableList.getSelection();
ArrayList<String> availableListNew = new ArrayList<String>(); ArrayList<String> availableListNew = new ArrayList<String>();
String search = config.getSearchField();
String[] selectedItemArray = selectedList.getItems(); String[] selectedItemArray = selectedList.getItems();
ArrayList<String> selectedItemList = new ArrayList<String>(); ArrayList<String> selectedItemList = new ArrayList<String>();
@ -745,29 +718,15 @@ public class DualList extends Composite {
if (moveAllLeft) { if (moveAllLeft) {
availableList.removeAll(); availableList.removeAll();
// Add all matching search field text to available list String[] fullList = config.getFullList().toArray(
for (String s : config.getFullList()) { new String[config.getFullList().size()]);
if (!config.isCaseFlag()) { java.util.List<String> filteredList = SearchUtils.search(
if (s.toLowerCase().contains(search.toLowerCase())) { config.getSearchField(), fullList,
if (!config.isExcludeFlag()) { config.getMatchAny(), config.isCaseFlag(),
availableList.add(s); config.isExcludeFlag());
}
} else { for (String s : filteredList) {
if (config.isExcludeFlag()) { availableList.add(s);
availableList.add(s);
}
}
} else {
if (s.contains(search)) {
if (!config.isExcludeFlag()) {
availableList.add(s);
}
} else {
if (config.isExcludeFlag()) {
availableList.add(s);
}
}
}
} }
} else if (moveLeft) { } else if (moveLeft) {
// Add selected item matching search field text to available // Add selected item matching search field text to available
@ -969,4 +928,14 @@ public class DualList extends Composite {
public void setConfig(DualListConfig config) { public void setConfig(DualListConfig config) {
this.config = 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);
}
} }

View file

@ -35,6 +35,7 @@ import java.util.List;
* May 31, 2012 mpduff Initial creation. * May 31, 2012 mpduff Initial creation.
* Aug 10, 2012 1002 mpduff Added numeric flag for sorting. * Aug 10, 2012 1002 mpduff Added numeric flag for sorting.
* Jan 07, 2013 1431 mpduff Add case sensitive and exclude flags. * Jan 07, 2013 1431 mpduff Add case sensitive and exclude flags.
* Aug 20, 2013 1733 mpduff Add match flag.
* *
* </pre> * </pre>
* *
@ -104,6 +105,12 @@ public class DualListConfig {
/** Flag for numeric data */ /** Flag for numeric data */
private boolean numericData = false; 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. * Constructor.
*/ */
@ -250,7 +257,7 @@ public class DualListConfig {
* @return The array of all available items. * @return The array of all available items.
*/ */
public List<String> getFullList() { public List<String> getFullList() {
return fullList; return new ArrayList<String>(fullList);
} }
/** /**
@ -334,4 +341,23 @@ public class DualListConfig {
public void setExcludeFlag(boolean excludeFlag) { public void setExcludeFlag(boolean excludeFlag) {
this.excludeFlag = 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;
}
} }

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information. * further licensing information.
**/ **/
package com.raytheon.uf.viz.datadelivery.browser; package com.raytheon.viz.ui.widgets.duallist;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -33,6 +33,7 @@ import java.util.regex.Pattern;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Feb 25, 2013 1588 mpduff Initial creation. * Feb 25, 2013 1588 mpduff Initial creation.
* Aug 20, 2013 1733 mpduff Moved and renamed.
* *
* </pre> * </pre>
* *
@ -40,7 +41,7 @@ import java.util.regex.Pattern;
* @version 1.0 * @version 1.0
*/ */
public class DataBrowserUtils { public class SearchUtils {
private static final Pattern WILDCARD_PATTERN = Pattern.compile("\\*"); private static final Pattern WILDCARD_PATTERN = Pattern.compile("\\*");
@ -120,7 +121,9 @@ public class DataBrowserUtils {
} else { } else {
if (testCaseItem.contains(term) != excludeSearchFlag) { if (testCaseItem.contains(term) != excludeSearchFlag) {
if (matchAnyFlag) { if (matchAnyFlag) {
results.add(item); if (!results.contains(item)) {
results.add(item);
}
} else { } else {
holder.add(term); holder.add(term);
} }

View file

@ -160,5 +160,6 @@
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="/awips2/edex/lib/dependencies/meteolib.jni.linux32"/> <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="/awips2/edex/lib/dependencies/meteolib.jni.linux32"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="/opt/uframe-eclipse/plugins/org.eclipse.jface_3.6.1.M20100825-0800.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information. * further licensing information.
**/ **/
package com.raytheon.uf.viz.datadelivery.browser; package com.raytheon.viz.ui.widgets.duallist;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -27,6 +27,8 @@ import java.util.List;
import org.junit.Test; import org.junit.Test;
import com.raytheon.viz.ui.widgets.duallist.SearchUtils;
/** /**
* Test the filter functionality of the Dataset Discovery Brower's FilterComps. * Test the filter functionality of the Dataset Discovery Brower's FilterComps.
* *
@ -37,6 +39,7 @@ import org.junit.Test;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Feb 25, 2013 1588 mpduff Initial creation. * Feb 25, 2013 1588 mpduff Initial creation.
* Aug 20, 2013 1733 mpduff Moved and renamed.
* *
* </pre> * </pre>
* *
@ -44,7 +47,7 @@ import org.junit.Test;
* @version 1.0 * @version 1.0
*/ */
public class DataBrowserRegexTest { public class SearchUtilsTest {
private static final List<String> itemList = Arrays.asList("temp", private static final List<String> itemList = Arrays.asList("temp",
"surface", "temp2", "temp3", "temp4", "wndSpd", "wndDir", "pres", "surface", "temp2", "temp3", "temp4", "wndSpd", "wndDir", "pres",
@ -66,8 +69,8 @@ public class DataBrowserRegexTest {
String searchTerm = "Emp"; String searchTerm = "Emp";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, false, false); false, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -87,8 +90,8 @@ public class DataBrowserRegexTest {
String searchTerm = "emp"; String searchTerm = "emp";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, true, false); true, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -110,8 +113,8 @@ public class DataBrowserRegexTest {
String searchTerm = "emp"; String searchTerm = "emp";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, false, true); false, true);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -133,8 +136,8 @@ public class DataBrowserRegexTest {
String searchTerm = "emp"; String searchTerm = "emp";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, true, true); true, true);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -154,8 +157,8 @@ public class DataBrowserRegexTest {
String searchTerm = "Te 3"; String searchTerm = "Te 3";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, false, false); false, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -172,8 +175,8 @@ public class DataBrowserRegexTest {
String searchTerm = "Te 3"; String searchTerm = "Te 3";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, false,
false, false, false); false, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -190,8 +193,8 @@ public class DataBrowserRegexTest {
String searchTerm = "te 3"; String searchTerm = "te 3";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, false,
false, true, false); true, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -208,8 +211,8 @@ public class DataBrowserRegexTest {
String searchTerm = "T*3"; String searchTerm = "T*3";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, false, false); false, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -226,8 +229,8 @@ public class DataBrowserRegexTest {
String searchTerm = "t*3"; String searchTerm = "t*3";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, true, false); true, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -249,8 +252,8 @@ public class DataBrowserRegexTest {
String searchTerm = "te*3"; String searchTerm = "te*3";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, false, true); false, true);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
} }
@ -268,8 +271,8 @@ public class DataBrowserRegexTest {
String searchTerm = "t*3 wnd"; String searchTerm = "t*3 wnd";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, true,
true, false, false); false, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);
@ -286,8 +289,8 @@ public class DataBrowserRegexTest {
String searchTerm = "t*3 mp"; String searchTerm = "t*3 mp";
String[] fullList = itemList.toArray(new String[itemList.size()]); String[] fullList = itemList.toArray(new String[itemList.size()]);
List<String> results = DataBrowserUtils.search(searchTerm, fullList, List<String> results = SearchUtils.search(searchTerm, fullList, false,
false, false, false); false, false);
String msg = checkResults(expected, results); String msg = checkResults(expected, results);
assertNull(msg); assertNull(msg);