01: package net.sourceforge.squirrel_sql.plugins.dataimport.action;
02:
03: /*
04: * Copyright (C) 2007 Thorsten Mürell
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or any later version.
10: *
11: * This program 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
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: */
20: import java.awt.event.ActionEvent;
21:
22: import net.sourceforge.squirrel_sql.client.IApplication;
23: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
24: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
25: import net.sourceforge.squirrel_sql.client.session.ISession;
26: import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
27: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
28: import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
29: import net.sourceforge.squirrel_sql.fw.util.Resources;
30:
31: /**
32: * An action to import table data from a file.
33: *
34: * @author Thorsten Mürell
35: */
36: public class ImportTableDataAction extends SquirrelAction implements
37: ISessionAction {
38: private static final long serialVersionUID = -8807675482631144975L;
39: private ISession session;
40:
41: /**
42: * The standard constructor.
43: *
44: * @param app The application
45: * @param resources The resources to work with
46: */
47: public ImportTableDataAction(IApplication app, Resources resources) {
48: super (app, resources);
49: }
50:
51: /**
52: * Sets the session.
53: *
54: * @param session The session
55: */
56: public void setSession(ISession session) {
57: this .session = session;
58: }
59:
60: /**
61: * This method is the actual action method.
62: *
63: * @param ev The action event
64: */
65: public void actionPerformed(ActionEvent ev) {
66: if (session != null) {
67: IObjectTreeAPI treeAPI = session.getSessionInternalFrame()
68: .getObjectTreeAPI();
69: IDatabaseObjectInfo[] tables = treeAPI
70: .getSelectedDatabaseObjects();
71: if (tables.length == 1 && tables[0] instanceof ITableInfo) {
72: try {
73: new ImportTableDataCommand(session,
74: (ITableInfo) tables[0]).execute();
75: } catch (Throwable th) {
76: session.showErrorMessage(th);
77: }
78: } else {
79: session.showErrorMessage("Wrong object");
80: }
81: }
82: }
83:
84: }
|