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