01: package net.sourceforge.squirrel_sql.client.session.action;
02:
03: /*
04: * Copyright (C) 2001-2003 Colin Bell
05: * colbell@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import java.awt.event.ActionEvent;
22: import java.beans.PropertyChangeListener;
23: import java.beans.PropertyChangeEvent;
24:
25: import net.sourceforge.squirrel_sql.client.IApplication;
26: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
27: import net.sourceforge.squirrel_sql.client.session.ISession;
28: import net.sourceforge.squirrel_sql.client.session.properties.SessionProperties;
29: import net.sourceforge.squirrel_sql.fw.gui.CursorChanger;
30:
31: /**
32: * This <CODE>Action</CODE> allows the user to commit the current SQL
33: * transaction.
34: *
35: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
36: */
37: public class CommitAction extends SquirrelAction implements
38: ISessionAction {
39: private ISession _session;
40: private PropertyChangeListener _propertyListener;
41:
42: public CommitAction(IApplication app) {
43: super (app);
44:
45: _propertyListener = new PropertyChangeListener() {
46: public void propertyChange(PropertyChangeEvent evt) {
47: if (SessionProperties.IPropertyNames.AUTO_COMMIT
48: .equals(evt.getPropertyName())) {
49: Boolean autoCom = (Boolean) evt.getNewValue();
50: setEnabled(false == autoCom.booleanValue());
51: }
52: }
53: };
54:
55: setEnabled(false);
56:
57: }
58:
59: public void setSession(ISession session) {
60: _session = session;
61:
62: if (null != _session) {
63: _session.getProperties().removePropertyChangeListener(
64: _propertyListener);
65: }
66: _session = session;
67:
68: if (session == null) {
69: setEnabled(false);
70: } else {
71: setEnabled(false == _session.getProperties()
72: .getAutoCommit());
73: _session.getProperties().addPropertyChangeListener(
74: _propertyListener);
75: }
76: }
77:
78: public void actionPerformed(ActionEvent evt) {
79: CursorChanger cursorChg = new CursorChanger(getApplication()
80: .getMainFrame());
81: cursorChg.show();
82: try {
83: new CommitCommand(_session).execute();
84: } finally {
85: cursorChg.restore();
86: }
87: }
88: }
|