KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > Disc


1 package discRack.presentation;
2
3 import discRack.presentation.delements.*;
4 import discRack.presentation.dpanels.*;
5 import org.enhydra.dods.exceptions.AssertionDataObjectException;
6 import discRack.business.disc.*;
7
8 import java.util.*;
9 import java.io.*;
10 import javax.swing.*;
11
12 /**
13  * Used to manage Disc DO data.
14  *
15  * @author Sasa Bojanic
16  * @version 1.0
17  */

18 public class Disc extends DCollectionElement {
19    private DSimpleElement refTitle=new DSimpleElement("Title");
20    private DSimpleElement refArtist=new DSimpleElement("Artist");
21    private DSimpleElement refGenre=new DSimpleElement("Genre");
22    private DSimpleElement refIsLiked=new DSimpleElement("Is Liked",true);
23
24    private discRack.business.disc.Disc myDisc;
25
26    public Disc (Discs discs,discRack.business.disc.Disc d) {
27       super("Disc",discs);
28       myDisc=d;
29       fillData();
30       fillStructure();
31    }
32
33    protected void fillStructure () {
34       super.fillStructure();
35       refTitle.setRequired(true);
36       refArtist.setRequired(true);
37       complexStructure.add(refTitle);
38       complexStructure.add(refArtist);
39       complexStructure.add(refGenre);
40       complexStructure.add(refIsLiked);
41    }
42
43    private void fillData () {
44       try {
45          attrId.setValue(myDisc.getHandle());
46          refTitle.setValue(myDisc.getTitle());
47          refArtist.setValue(myDisc.getArtist());
48          refGenre.setValue(myDisc.getGenre());
49          refIsLiked.setValue(new Boolean JavaDoc(myDisc.isLiked()));
50       } catch (Exception JavaDoc ex) {}
51    }
52
53    /**
54      * This method is called only if user doesn't press Cancel button within
55      * the dialog for editing properties, so the changes are applied here.
56      * @param groupPanel The panel for editing parameters.
57      * @return always returns <tt>true</tt>.
58      */

59    public boolean setDODSElements (DPanel p) {
60        DGroupPanel dgp=(DGroupPanel)p;
61        DTextPanel idtp=(DTextPanel)dgp.getPanel(0);
62        DTextPanel ttp=(DTextPanel)dgp.getPanel(1);
63        DTextPanel atp=(DTextPanel)dgp.getPanel(2);
64        DTextPanel gtp=(DTextPanel)dgp.getPanel(3);
65        DCheckPanel ilcp=(DCheckPanel)dgp.getPanel(4);
66
67        String JavaDoc title=ttp.getText();
68        String JavaDoc artist=atp.getText();
69        String JavaDoc genre=gtp.getText();
70
71        boolean isLiked=ilcp.getCheckBox().isSelected();
72
73        try {
74           discRack.business.disc.Disc tempDisc = DiscFactory.findDiscByID(myDisc.getHandle());
75           if (!tempDisc.isDONull() && (tempDisc.getVersion()!=myDisc.getVersion())){
76               JOptionPane.showMessageDialog(p.getWindow(),
77               "Data are allredy changed by another user.","Disc error",
78               JOptionPane.ERROR_MESSAGE);
79               return false;
80           }else{
81           myDisc.setTitle(title);
82           myDisc.setArtist(artist);
83           myDisc.setGenre(genre);
84           myDisc.setLiked(isLiked);
85           myDisc.save();
86           return true;
87          }
88        } catch (AssertionDataObjectException ex) {
89           JOptionPane.showMessageDialog(p.getWindow(),
90                 "Read-only cache: DML opertions not allowed.","Disc error",
91                 JOptionPane.ERROR_MESSAGE);
92           return false;
93        } catch (Exception JavaDoc ex) {
94           JOptionPane.showMessageDialog(p.getWindow(),
95                 "Something went wrong, please try again !","Disc error",
96                 JOptionPane.ERROR_MESSAGE);
97           return false;
98        }
99     }
100
101     public discRack.business.disc.Disc getMyDisc () {
102        return myDisc;
103     }
104 }
105
Popular Tags