Source Code Cross Referenced for PasteTableAction.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » dbcopy » actions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.dbcopy.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.dbcopy.actions;
002:
003:        /*
004:         * Copyright (C) 2005 Rob Manning
005:         * manningr@users.sourceforge.net
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:        import java.awt.event.ActionEvent;
022:
023:        import net.sourceforge.squirrel_sql.client.IApplication;
024:        import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
025:        import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
026:        import net.sourceforge.squirrel_sql.client.session.ISession;
027:        import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
028:        import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
029:        import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
030:        import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
031:        import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
032:        import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
033:        import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
034:        import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
035:        import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
036:        import net.sourceforge.squirrel_sql.fw.util.Resources;
037:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
038:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
039:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
040:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
041:        import net.sourceforge.squirrel_sql.plugins.dbcopy.DBCopyPlugin;
042:        import net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider;
043:        import net.sourceforge.squirrel_sql.plugins.dbcopy.commands.PasteTableCommand;
044:
045:        public class PasteTableAction extends SquirrelAction implements 
046:                ISessionAction {
047:
048:            /** Current plugin. */
049:            private final SessionInfoProvider sessionInfoProv;
050:
051:            /** The IApplication that we can use to display error dialogs */
052:            private IApplication app = null;
053:
054:            /** Logger for this class. */
055:            private final static ILogger log = LoggerController
056:                    .createLogger(PasteTableAction.class);
057:
058:            /** Internationalized strings for this class */
059:            private static final StringManager s_stringMgr = StringManagerFactory
060:                    .getStringManager(PasteTableAction.class);
061:
062:            /**
063:             * Creates a new SQuirreL action that gets fired whenever the user chooses
064:             * the paste operation.
065:             * 
066:             * @param app
067:             * @param rsrc
068:             * @param plugin
069:             */
070:            public PasteTableAction(IApplication app, Resources rsrc,
071:                    DBCopyPlugin plugin) {
072:                super (app, rsrc);
073:                this .app = app;
074:                sessionInfoProv = plugin;
075:            }
076:
077:            /* (non-Javadoc)
078:             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
079:             */
080:            public void actionPerformed(ActionEvent evt) {
081:                ISession destSession = sessionInfoProv.getCopyDestSession();
082:                IObjectTreeAPI api = destSession
083:                        .getObjectTreeAPIOfActiveSessionWindow();
084:                if (api == null) {
085:                    return;
086:                }
087:                IDatabaseObjectInfo[] dbObjs = api.getSelectedDatabaseObjects();
088:                if (dbObjs.length > 1) {
089:                    sessionInfoProv.setDestSelectedDatabaseObject(null);
090:                    //i18n[PasteTableAction.error.multischemapaste=The paste 
091:                    //operation may only be applied to one schema at a time]
092:                    String msg = s_stringMgr
093:                            .getString("PasteTableAction.error.multischemapaste");
094:                    app.showErrorDialog(msg);
095:
096:                    return;
097:                } else {
098:                    // When the user pastes on a TABLE label which is located under a 
099:                    // schema/catalog, build the schema DatabaseObjectInfo.
100:                    if (DatabaseObjectType.TABLE_TYPE_DBO.equals(dbObjs[0]
101:                            .getDatabaseObjectType())) {
102:                        IDatabaseObjectInfo tableLabelInfo = dbObjs[0];
103:                        ISQLConnection destCon = destSession.getSQLConnection();
104:                        SQLDatabaseMetaData md = null;
105:                        if (destCon != null) {
106:                            md = destCon.getSQLMetaData();
107:                        }
108:                        IDatabaseObjectInfo schema = new DatabaseObjectInfo(
109:                                null, tableLabelInfo.getSchemaName(),
110:                                tableLabelInfo.getSchemaName(),
111:                                DatabaseObjectType.SCHEMA, md);
112:                        sessionInfoProv.setDestSelectedDatabaseObject(schema);
113:                    } else {
114:                        sessionInfoProv
115:                                .setDestSelectedDatabaseObject(dbObjs[0]);
116:                    }
117:
118:                }
119:
120:                try {
121:                    IDatabaseObjectInfo info = sessionInfoProv
122:                            .getDestSelectedDatabaseObject();
123:                    if (info == null || destSession == null) {
124:                        return;
125:                    }
126:                    if (!checkSession(destSession, info)) {
127:                        return;
128:                    }
129:                } catch (UserCancelledOperationException e) {
130:                    return;
131:                }
132:                if (sessionInfoProv.getCopySourceSession() == null) {
133:                    return;
134:                }
135:                if (!sourceDestSchemasDiffer()) {
136:                    // TODO: tell the user that the selected destination schema is 
137:                    // the same as the source schema.
138:                    //monitor.showMessageDialog(...)            
139:                    return;
140:                }
141:                new PasteTableCommand(sessionInfoProv).execute();
142:            }
143:
144:            /**
145:             * Set the current session.
146:             * 
147:             * @param	session		The current session.
148:             */
149:            public void setSession(ISession session) {
150:                sessionInfoProv.setDestCopySession(session);
151:            }
152:
153:            /**
154:             * This a work-around for the fact that some databases in SQuirreL show 
155:             * "schemas" as catalogs (MySQL) while most others show them as "schemas".
156:             * If we restrict the Paste menu-item to schemas, then it won't appear in
157:             * the context menu in the MySQL object tree.  However, if add catalogs to
158:             * the list of database objects that the paste menu item appears in, then 
159:             * we must be careful not to attempt the copy operation on databases where
160:             * schema != catalog.(Otherwise the copy operation will fail as the qualified
161:             * name will be [catalog].[tablename] instead of [schema].[tablename]
162:             * 
163:             * @param session
164:             * @param dbObjs
165:             * 
166:             * @return true if it is ok to proceed with the copy operation; false otherwise.
167:             */
168:            private boolean checkSession(ISession session,
169:                    IDatabaseObjectInfo dbObj)
170:                    throws UserCancelledOperationException {
171:                if (session == null || dbObj == null) {
172:                    return true;
173:                }
174:                String typeName = dbObj.getDatabaseObjectType().getName();
175:
176:                log.debug("PasteTableAction.checkSession: dbObj type="
177:                        + typeName + " name=" + dbObj.getSimpleName());
178:
179:                HibernateDialect d = DialectFactory.getDialect(
180:                        DialectFactory.DEST_TYPE, session.getApplication()
181:                                .getMainFrame(), session.getMetaData());
182:                if (!d.canPasteTo(dbObj)) {
183:                    //i18n[PasteTableAction.error.destdbobj=The destination database 
184:                    //doesn't support copying tables into '{0}' objects.\n Please 
185:                    //select a schema to paste into.]
186:                    String errmsg = s_stringMgr.getString(
187:                            "PasteTableAction.error.destdbobj",
188:                            new Object[] { typeName });
189:                    app.showErrorDialog(errmsg);
190:                    return false;
191:                }
192:                return true;
193:            }
194:
195:            /**
196:             * Returns a boolean value indicating whether or not the source and 
197:             * destination sessions refer to the same schema.
198:             * 
199:             * @return
200:             */
201:            private boolean sourceDestSchemasDiffer() {
202:                //ISession sourceSession = sessionInfoProv.getCopySourceSession();
203:                //ISession destSession = sessionInfoProv.getCopyDestSession();
204:
205:                // TODO: check to be sure that the source and destination schemas are
206:                // different. Abort if they are the same and inform the user.
207:
208:                return true;
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.