/*
$Header: /cvsroot/xorm/xorm/tools/src/org/xorm/tools/editor/IterateCollectionAction.java,v 1.5 2002/04/28 00:34:31 wbiggs Exp $
This file is part of XORM.
XORM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
XORM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xorm.tools.editor;
import java.util.Collection;
import java.util.Iterator;
import javax.jdo.PersistenceManager;
import javax.jdo.spi.PersistenceCapable;
public class IterateCollectionAction extends Action {
private Collection collection;
public IterateCollectionAction(PersistenceManager mgr, Collection collection) {
super(mgr);
this.collection = collection;
}
public Object go() {
Iterator i = collection.iterator();
while (i.hasNext()) {
PersistenceCapable pc = (PersistenceCapable) i.next();
System.out.println("Result: " + pc.jdoGetObjectId());
boolean loop = true;
while (loop) {
System.out.print("[E] Edit, [R] Remove, [X] Exit, [N] Next: ");
String choice = readLine();
switch (choice.charAt(0)) {
case 'E':
Action action = new EditAction(mgr, pc);
action.go();
break;
case 'X':
return pc;
case 'R':
i.remove();
case 'N':
loop = false;
break;
}
}
}
return null;
}
}