1 | |
package org.paneris.jammyjoes.mvp; |
2 | |
|
3 | |
import java.util.LinkedList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.melati.poem.NoSuchRowPoemException; |
7 | |
import org.melati.poem.Selectable; |
8 | |
|
9 | |
public class ProductSelectionFromContext implements Selection { |
10 | |
|
11 | |
Selectable _selectable; |
12 | |
Context _context; |
13 | |
|
14 | 2 | public ProductSelectionFromContext(Selectable selectable, Context context) { |
15 | 2 | _selectable = selectable; |
16 | 2 | _context = context; |
17 | 2 | } |
18 | |
|
19 | |
public void visitEach(Command command) { |
20 | 1 | List selected = new LinkedList(); |
21 | 9 | for (int i = 0; i < 8; i++) { |
22 | 8 | Integer id = (Integer)_context.get(new IntegerConverter(), i + ""); |
23 | 8 | if (id != null) { |
24 | |
try { |
25 | 1 | selected.add(_selectable.getObject(id)); |
26 | 0 | } catch (NoSuchRowPoemException e) { |
27 | 1 | } |
28 | |
} |
29 | |
} |
30 | 1 | new VisitableCollectionAdaptor(selected).visitEach(command); |
31 | 1 | } |
32 | |
|
33 | |
} |