Author: rwhitcomb Date: Mon Oct 1 19:29:22 2012 New Revision: 1392539 URL: http://svn.apache.org/viewvc?rev=1392539&view=rev Log: PIVOT-874: StockTracker: removing multiple symbols may remove unselected ones too
Applied patch from user, tested StockTracker application standalone. Modified: pivot/trunk/ (props changed) pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/StockTrackerWindow.java Propchange: pivot/trunk/ ------------------------------------------------------------------------------ Merged /pivot/branches/2.0.x:r1392533 Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/StockTrackerWindow.java URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/StockTrackerWindow.java?rev=1392539&r1=1392538&r2=1392539&view=diff ============================================================================== --- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/StockTrackerWindow.java (original) +++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/StockTrackerWindow.java Mon Oct 1 19:29:22 2012 @@ -31,6 +31,7 @@ import org.apache.pivot.beans.BeanAdapte import org.apache.pivot.beans.Bindable; import org.apache.pivot.collections.ArrayList; import org.apache.pivot.collections.List; +import org.apache.pivot.collections.List.ItemIterator; import org.apache.pivot.collections.Map; import org.apache.pivot.collections.Sequence; import org.apache.pivot.json.JSON; @@ -103,9 +104,16 @@ public class StockTrackerWindow extends @Override public void perform(Component source) { int selectedIndex = stocksTableView.getFirstSelectedIndex(); - int selectionLength = stocksTableView.getLastSelectedIndex() - selectedIndex + 1; - stocksTableView.getTableData().remove(selectedIndex, selectionLength); - symbols.remove(selectedIndex, selectionLength); + ArrayList<Span> spanList = new ArrayList<Span>(stocksTableView.getSelectedRanges()); + + // remove spans in reverse order to prevent IndexOutOfBoundsException + ItemIterator<Span> it = spanList.iterator(); + it.toEnd(); + while (it.hasPrevious()) { + Span span = it.previous(); + stocksTableView.getTableData().remove(span.start, (int) span.getLength()); + symbols.remove(span.start, (int) span.getLength()); + } if (selectedIndex >= symbols.getLength()) { selectedIndex = symbols.getLength() - 1;