1 /*********************************************************************************
2 * *
3 * Raptor - Rapid prototyping of Swing GUIs based on JavaBeans like Java objects *
4 * Copyright (C) 2003 XCOM AG *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 * *
20 *********************************************************************************/
21 package net.sf.raptor.ui.panels.persistence;
22
23 import java.beans.BeanInfo;
24
25 import javax.swing.JOptionPane;
26
27 import net.sf.hibernate.HibernateException;
28 import net.sf.raptor.hibernate.PersistenceManager;
29 import net.sf.raptor.logging.Trace;
30 import net.sf.raptor.ui.components.InvalidValueException;
31 import net.sf.raptor.ui.panels.BeanEditPanel;
32
33 /**
34 * @author thomasg
35 *
36 * To change the template for this generated type comment go to
37 * Window>Preferences>Java>Code Generation>Code and Comments
38 */
39 public class DetailPanel extends BeanEditPanel {
40
41 private static PersistenceManager persistenceManager = null;
42
43 /**
44 * @param toEdit
45 */
46 public DetailPanel(Object toEdit) {
47 this(toEdit, null);
48 }
49
50 /**
51 * @param toEdit
52 * @param beanInfoValue
53 */
54 public DetailPanel(Object toEdit, BeanInfo beanInfoValue) {
55 super(toEdit, beanInfoValue);
56 }
57
58 /**
59 * doCommitAction
60 */
61 public void commit() throws InvalidValueException {
62 super.commit();
63 if( persistenceManager!=null ) {
64 try {
65 persistenceManager.saveOrUpdate(getEditObject());
66 } catch (HibernateException e) {
67 Trace.error(e);
68 JOptionPane.showMessageDialog(this, "Das Objekt konnte nicht abgespeichert werden.\n" +
69 "Vermutlich haben Sie ein ben?tigtes Feld vergessen.");
70 throw new InvalidValueException(e.getLocalizedMessage());
71 }
72 }
73 }
74
75 /**
76 * getPersistenceManager
77 *
78 * @return
79 */
80 public static PersistenceManager getPersistenceManager() {
81 return persistenceManager;
82 }
83
84 /**
85 * setPersistenceManager
86 *
87 * @param manager
88 */
89 public static void setPersistenceManager(PersistenceManager manager) {
90 persistenceManager = manager;
91 if( persistenceManager==null ) {
92 Trace.warn("The persistenceManager set to <null>.");
93 } else {
94 Trace.info("The persistenceManager was set.");
95 }
96 }
97
98 }