01: /*
02: $Header: /cvsroot/xorm/xorm/tools/src/org/xorm/tools/editor/IterateCollectionAction.java,v 1.5 2002/04/28 00:34:31 wbiggs Exp $
03:
04: This file is part of XORM.
05:
06: XORM is free software; you can redistribute it and/or modify
07: it under the terms of the GNU General Public License as published by
08: the Free Software Foundation; either version 2 of the License, or
09: (at your option) any later version.
10:
11: XORM is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with Foobar; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package org.xorm.tools.editor;
21:
22: import java.util.Collection;
23: import java.util.Iterator;
24: import javax.jdo.PersistenceManager;
25: import javax.jdo.spi.PersistenceCapable;
26:
27: public class IterateCollectionAction extends Action {
28: private Collection collection;
29:
30: public IterateCollectionAction(PersistenceManager mgr,
31: Collection collection) {
32: super (mgr);
33: this .collection = collection;
34: }
35:
36: public Object go() {
37: Iterator i = collection.iterator();
38: while (i.hasNext()) {
39: PersistenceCapable pc = (PersistenceCapable) i.next();
40: System.out.println("Result: " + pc.jdoGetObjectId());
41: boolean loop = true;
42: while (loop) {
43: System.out
44: .print("[E] Edit, [R] Remove, [X] Exit, [N] Next: ");
45: String choice = readLine();
46: switch (choice.charAt(0)) {
47: case 'E':
48: Action action = new EditAction(mgr, pc);
49: action.go();
50: break;
51: case 'X':
52: return pc;
53: case 'R':
54: i.remove();
55: case 'N':
56: loop = false;
57: break;
58: }
59: }
60: }
61: return null;
62: }
63: }
|