01: /*
02: $Header: /cvsroot/xorm/xorm/tools/src/org/xorm/tools/editor/EditCollectionAction.java,v 1.4 2002/04/26 22:01:05 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 org.xorm.RelationshipProxy;
25: import org.xorm.XORM;
26: import javax.jdo.PersistenceManager;
27:
28: public class EditCollectionAction extends Action {
29: private Collection collection;
30: private Class targetClass;
31:
32: public EditCollectionAction(PersistenceManager mgr,
33: Collection collection) {
34: super (mgr);
35: this .collection = collection;
36: this .targetClass = Object.class;
37: if (collection instanceof RelationshipProxy) {
38: this .targetClass = ((RelationshipProxy) collection)
39: .getElementType();
40: }
41: }
42:
43: public Object go() {
44: System.out.println("EDIT COLLECTION");
45:
46: // Add to collection,
47: // Remove from iterator
48: // Edit via iterator
49: Object obj = null;
50: while (true) {
51: System.out.println("Collection<" + targetClass.getName()
52: + ">, size " + collection.size());
53: System.out.println("[A] Add an item");
54: System.out.println("[C] Clear all items");
55: System.out.println("[I] Iterate through items");
56: System.out.println("[X] Exit");
57:
58: String optLine = readLine();
59: switch (optLine.charAt(0)) {
60: case 'A':
61: Action action = new MainMenu(mgr);
62: obj = action.go();
63: collection.add(obj);
64: break;
65: case 'C':
66: collection.clear();
67: obj = null;
68: break;
69: case 'I':
70: Action it = new IterateCollectionAction(mgr, collection);
71: obj = it.go();
72: break;
73: case 'X':
74: return obj;
75: }
76: }
77: }
78:
79: }
|