001: package jtaDiscRack.presentation;
002:
003: import jtaDiscRack.presentation.delements.*;
004: import jtaDiscRack.presentation.dpanels.*;
005: import org.enhydra.dods.exceptions.AssertionDataObjectException;
006:
007: import jtaDiscRack.business.JtaDiscRackBusinessException;
008: import jtaDiscRack.business.disc.*;
009:
010: import javax.swing.*;
011:
012: /**
013: * Used to manage Disc DO data.
014: *
015: * @author Sasa Bojanic
016: * @version 1.0
017: */
018: public class Disc extends DCollectionElement {
019: private DSimpleElement refTitle = new DSimpleElement("Title");
020:
021: private DSimpleElement refArtist = new DSimpleElement("Artist");
022:
023: private DSimpleElement refGenre = new DSimpleElement("Genre");
024:
025: private DSimpleElement refIsLiked = new DSimpleElement("Is Liked",
026: true);
027:
028: private jtaDiscRack.business.disc.Disc myDisc;
029:
030: public Disc(Discs discs, jtaDiscRack.business.disc.Disc d) {
031: super ("Disc", discs);
032: myDisc = d;
033: fillData();
034: fillStructure();
035: }
036:
037: protected void fillStructure() {
038: super .fillStructure();
039: refTitle.setRequired(true);
040: refArtist.setRequired(true);
041: complexStructure.add(refTitle);
042: complexStructure.add(refArtist);
043: complexStructure.add(refGenre);
044: complexStructure.add(refIsLiked);
045: }
046:
047: private void fillData() {
048: try {
049: attrId.setValue(myDisc.getHandle());
050: refTitle.setValue(myDisc.getTitle());
051: refArtist.setValue(myDisc.getArtist());
052: refGenre.setValue(myDisc.getGenre());
053: refIsLiked.setValue(new Boolean(myDisc.isLiked()));
054: } catch (Exception ex) {
055: }
056: }
057:
058: /**
059: * This method is called only if user doesn't press Cancel button within
060: * the dialog for editing properties, so the changes are applied here.
061: * @param groupPanel The panel for editing parameters.
062: * @return always returns <tt>true</tt>.
063: */
064: public boolean setDODSElements(DPanel p) {
065: DGroupPanel dgp = (DGroupPanel) p;
066: DTextPanel idtp = (DTextPanel) dgp.getPanel(0);
067: DTextPanel ttp = (DTextPanel) dgp.getPanel(1);
068: DTextPanel atp = (DTextPanel) dgp.getPanel(2);
069: DTextPanel gtp = (DTextPanel) dgp.getPanel(3);
070: DCheckPanel ilcp = (DCheckPanel) dgp.getPanel(4);
071:
072: String title = ttp.getText();
073: String artist = atp.getText();
074: String genre = gtp.getText();
075:
076: boolean isLiked = ilcp.getCheckBox().isSelected();
077:
078: try {
079: jtaDiscRack.business.disc.Disc tempDisc = null;
080:
081: try {
082: tempDisc = DiscFactory.findDiscByID(myDisc.getHandle());
083: } catch (JtaDiscRackBusinessException ex) {
084: tempDisc = new jtaDiscRack.business.disc.Disc();
085: }
086:
087: if (!tempDisc.isDONull()
088: && (tempDisc.getVersion() != myDisc.getVersion())) {
089: JOptionPane.showMessageDialog(p.getWindow(),
090: "Data are allredy changed by another user.",
091: "Disc error", JOptionPane.ERROR_MESSAGE);
092: return false;
093: } else {
094: myDisc.setTitle(title);
095: myDisc.setArtist(artist);
096: myDisc.setGenre(genre);
097: myDisc.setLiked(isLiked);
098: myDisc.save();
099: return true;
100: }
101: } catch (AssertionDataObjectException ex) {
102: JOptionPane.showMessageDialog(p.getWindow(),
103: "Read-only cache: DML opertions not allowed.",
104: "Disc error", JOptionPane.ERROR_MESSAGE);
105: return false;
106: } catch (Exception ex) {
107: JOptionPane.showMessageDialog(p.getWindow(),
108: "Something went wrong, please try again !",
109: "Disc error", JOptionPane.ERROR_MESSAGE);
110: return false;
111: }
112: }
113:
114: public jtaDiscRack.business.disc.Disc getMyDisc() {
115: return myDisc;
116: }
117: }
|