01: package net.sourceforge.squirrel_sql.plugins.refactoring.actions;
02:
03: /*
04: * Copyright (C) 2006 Rob Manning
05: * manningr@users.sourceforge.net
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or any later version.
11: *
12: * This program 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
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; 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:
23: import net.sourceforge.squirrel_sql.client.IApplication;
24: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
25: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
26: import net.sourceforge.squirrel_sql.client.session.ISession;
27: import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
28: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
29: import net.sourceforge.squirrel_sql.fw.util.ICommand;
30: import net.sourceforge.squirrel_sql.fw.util.Resources;
31:
32: public abstract class AbstractRefactoringAction extends SquirrelAction
33: implements ISessionAction {
34:
35: /** Current session. */
36: protected ISession _session;
37:
38: /** API for the current tree. */
39: protected IObjectTreeAPI _tree;
40:
41: public AbstractRefactoringAction(IApplication app, Resources rsrc) {
42: super (app, rsrc);
43: }
44:
45: public void actionPerformed(ActionEvent evt) {
46: if (_session != null) {
47: IObjectTreeAPI api = _session
48: .getObjectTreeAPIOfActiveSessionWindow();
49: IDatabaseObjectInfo[] infos = api
50: .getSelectedDatabaseObjects();
51: if (infos.length > 1 && !isMultipleObjectAction()) {
52: _session.showMessage(getErrorMessage());
53: } else {
54: try {
55: getCommand(infos).execute();
56: } catch (Exception e) {
57: _session.showMessage(e);
58: }
59: }
60: }
61: }
62:
63: protected abstract ICommand getCommand(IDatabaseObjectInfo[] info);
64:
65: protected abstract boolean isMultipleObjectAction();
66:
67: protected abstract String getErrorMessage();
68:
69: public void setObjectTree(IObjectTreeAPI tree) {
70: if (null != tree) {
71: _session = tree.getSession();
72: } else {
73: _session = null;
74: }
75: _tree = tree;
76: setEnabled(null != _session);
77: }
78:
79: // ISessionAction implementation
80:
81: /**
82: * Set the current session.
83: *
84: * @param session The current session.
85: */
86: public void setSession(ISession session) {
87: _session = session;
88: }
89: }
|