01: package jtaDiscRack.presentation;
02:
03: import jtaDiscRack.presentation.delements.*;
04: import jtaDiscRack.business.disc.DiscFactory;
05:
06: /**
07: * Used to manage collection of Disc DO data.
08: *
09: * @author Sasa Bojanic
10: * @version 1.0
11: */
12: public class Discs extends DCollection {
13:
14: private jtaDiscRack.business.person.Person myPerson;
15:
16: public Discs(jtaDiscRack.business.person.Person person) {
17: super ("Disc management");
18: this .myPerson = person;
19: fillCollection();
20: }
21:
22: /**
23: * Generates a new element of the class which instances
24: * are members of collection of this class.
25: *
26: * return The generated instance of class that makes collection.
27: */
28: public DSimpleElement generateNewElement() {
29: Disc d = null;
30: try {
31: jtaDiscRack.business.disc.Disc db = new jtaDiscRack.business.disc.Disc();
32: db.setOwner(myPerson);
33: d = new Disc(this , db);
34: d.setRequired(true);
35: } catch (Exception ex) {
36: }
37: return d;
38: }
39:
40: private void fillCollection() {
41: try {
42: jtaDiscRack.business.disc.Disc[] discs = DiscFactory
43: .findDiscsForPerson(myPerson);
44: if (discs != null && discs.length > 0) {
45: for (int i = 0; i < discs.length; i++) {
46: Disc d = new Disc(this , discs[i]);
47: add(d);
48: }
49: }
50: } catch (Exception ex) {
51: }
52: }
53:
54: public void onElementDeleted(DSimpleElement del) throws Exception {
55: ((Disc) del).getMyDisc().delete();
56: }
57:
58: }
|