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