01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui;
19:
20: import java.awt.event.ActionEvent;
21: import java.awt.event.ActionListener;
22: import java.util.Iterator;
23: import java.util.List;
24: import java.util.Vector;
25: import java.util.logging.Level;
26: import java.util.logging.Logger;
27:
28: import de.finix.contelligent.client.base.ComponentFactory;
29: import de.finix.contelligent.client.base.ComponentNotFoundException;
30:
31: public abstract class AbstractComponentEditor extends
32: AbstractComponentRenderer implements ComponentEditor {
33:
34: private static Logger logger = Logger
35: .getLogger(AbstractComponentEditor.class.getName());
36:
37: protected boolean editable = true;
38:
39: private List<ActionListener> actionListeners = new Vector<ActionListener>();
40:
41: public AbstractComponentEditor() {
42: super ();
43: }
44:
45: public void setEditable(boolean editable) {
46: this .editable = editable;
47: }
48:
49: public boolean isEditable() {
50: return editable;
51: }
52:
53: public void addActionListener(ActionListener listener) {
54: actionListeners.add(listener);
55: }
56:
57: public void removeActionListener(ActionListener listener) {
58: actionListeners.remove(listener);
59: }
60:
61: public Iterator getActionListeners() {
62: return actionListeners.iterator();
63: }
64:
65: public void rollback() {
66: if (getComponent().isModified()
67: || getComponent().isResourceModified()) {
68: try {
69: ComponentFactory.getInstance().reload(getComponent());
70: } catch (ComponentNotFoundException cnfe) {
71: logger.log(Level.SEVERE, "Could not rollback: ", cnfe);
72: }
73: }
74: update();
75: }
76:
77: public void commit() {
78: updateComponent();
79: ComponentFactory.getInstance().save(getComponent());
80: }
81:
82: protected void notifyListeners() {
83: for (Iterator i = getActionListeners(); i.hasNext();) {
84: ((ActionListener) i.next())
85: .actionPerformed(new ActionEvent((Object) this ,
86: ActionEvent.ACTION_PERFORMED,
87: "editing stopped"));
88: }
89: }
90:
91: /**
92: * Counter-part to {@link AbstractComponentRenderer#update}. Store edited
93: * values into component. Must be implemented by sub class.
94: */
95: abstract protected void updateComponent();
96: }
|