Source Code Cross Referenced for DBCopyPlugin.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » dbcopy » 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 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.dbcopy;
002:
003:        /*
004:         * Copyright (C) 2005 Rob Manning
005:         * manningr@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library 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 GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:
022:        import javax.swing.SwingUtilities;
023:
024:        import net.sourceforge.squirrel_sql.client.IApplication;
025:        import net.sourceforge.squirrel_sql.client.action.ActionCollection;
026:        import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
027:        import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
028:        import net.sourceforge.squirrel_sql.client.plugin.PluginException;
029:        import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
030:        import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallback;
031:        import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
032:        import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
033:        import net.sourceforge.squirrel_sql.client.session.ISession;
034:        import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
035:        import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
036:        import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
037:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
038:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
039:        import net.sourceforge.squirrel_sql.plugins.dbcopy.actions.CopyTableAction;
040:        import net.sourceforge.squirrel_sql.plugins.dbcopy.actions.PasteTableAction;
041:        import net.sourceforge.squirrel_sql.plugins.dbcopy.gui.DBCopyGlobalPreferencesTab;
042:        import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
043:
044:        /**
045:         * The class that sets up the various resources required by SQuirreL to 
046:         * implement a plugin.  This plugin implements the ability to copy tables and 
047:         * various other table-related objects from one database to another.
048:         */
049:        public class DBCopyPlugin extends DefaultSessionPlugin implements 
050:                SessionInfoProvider {
051:
052:            /** Logger for this class. */
053:            private final static ILogger s_log = LoggerController
054:                    .createLogger(DBCopyPlugin.class);
055:
056:            private PluginResources _resources;
057:
058:            private ISession copySourceSession = null;
059:
060:            private ISession copyDestSession = null;
061:
062:            private IDatabaseObjectInfo[] selectedDatabaseObjects = null;
063:
064:            private IDatabaseObjectInfo selectedDestDatabaseObject = null;
065:
066:            /* (non-Javadoc)
067:             * @see net.sourceforge.squirrel_sql.client.plugin.ISessionPlugin#sessionStarted(net.sourceforge.squirrel_sql.client.session.ISession)
068:             */
069:            public PluginSessionCallback sessionStarted(final ISession session) {
070:                IObjectTreeAPI api = session
071:                        .getObjectTreeAPIOfActiveSessionWindow();
072:                addMenuItemsToContextMenu(api);
073:                return new DBCopyPluginSessionCallback(this );
074:            }
075:
076:            public void sessionEnding(final ISession session) {
077:                if (session.equals(copySourceSession)) {
078:                    copySourceSession = null;
079:                    // Can't paste from a session that is no longer around.
080:                    setPasteMenuEnabled(false);
081:                }
082:            }
083:
084:            /* (non-Javadoc)
085:             * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getInternalName()
086:             */
087:            public String getInternalName() {
088:                return "dbcopy";
089:            }
090:
091:            /* (non-Javadoc)
092:             * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getDescriptiveName()
093:             */
094:            public String getDescriptiveName() {
095:                return "DBCopy Plugin";
096:            }
097:
098:            /* (non-Javadoc)
099:             * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getAuthor()
100:             */
101:            public String getAuthor() {
102:                return "Rob Manning";
103:            }
104:
105:            /* (non-Javadoc)
106:             * @see net.sourceforge.squirrel_sql.client.plugin.DefaultPlugin#getContributors()
107:             */
108:            public String getContributors() {
109:                return "Dan Dragut";
110:            }
111:
112:            /* (non-Javadoc)
113:             * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getVersion()
114:             */
115:            public String getVersion() {
116:                return "1.13";
117:            }
118:
119:            /**
120:             * Returns the name of the Help file for the plugin. This should
121:             * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
122:             * directory.
123:             *
124:             * @return  the Help file name or <TT>null</TT> if plugin doesn't have
125:             * a help file.
126:             */
127:            public String getHelpFileName() {
128:                return "readme.html";
129:            }
130:
131:            /**
132:             * Returns the name of the change log for the plugin. This should
133:             * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
134:             * directory.
135:             *
136:             * @return  the changelog file name or <TT>null</TT> if plugin doesn't have
137:             *          a change log.
138:             */
139:            public String getChangeLogFileName() {
140:                return "changes.txt";
141:            }
142:
143:            public void initialize() throws PluginException {
144:                super .initialize();
145:                //md = new MemoryDiagnostics();
146:                if (s_log.isDebugEnabled()) {
147:                    s_log.debug("Initializing DB Copy Plugin");
148:                }
149:                _resources = new DBCopyPluginResources(
150:                        "net.sourceforge.squirrel_sql.plugins.dbcopy.dbcopy",
151:                        this );
152:                PreferencesManager.initialize(this );
153:
154:                IApplication app = getApplication();
155:                ActionCollection coll = app.getActionCollection();
156:                coll.add(new CopyTableAction(app, _resources, this ));
157:                coll.add(new PasteTableAction(app, _resources, this ));
158:
159:                setPasteMenuEnabled(false);
160:            }
161:
162:            public void unload() {
163:                super .unload();
164:                copySourceSession = null;
165:                setPasteMenuEnabled(false);
166:                PreferencesManager.unload();
167:            }
168:
169:            public void setCopyMenuEnabled(boolean enabled) {
170:                final ActionCollection coll = getApplication()
171:                        .getActionCollection();
172:                CopyTableAction copyAction = (CopyTableAction) coll
173:                        .get(CopyTableAction.class);
174:                copyAction.setEnabled(enabled);
175:            }
176:
177:            public void setPasteMenuEnabled(final boolean enabled) {
178:                GUIUtils.processOnSwingEventThread(new Runnable() {
179:                    public void run() {
180:                        final ActionCollection coll = getApplication()
181:                                .getActionCollection();
182:                        PasteTableAction pasteAction = (PasteTableAction) coll
183:                                .get(PasteTableAction.class);
184:                        pasteAction.setEnabled(enabled);
185:                    }
186:                });
187:            }
188:
189:            /**
190:             * @param selectedDatabaseObjects The selectedDatabaseObjects to set.
191:             */
192:            public void setSelectedDatabaseObjects(
193:                    IDatabaseObjectInfo[] dbObjArr) {
194:                if (dbObjArr != null) {
195:                    selectedDatabaseObjects = dbObjArr;
196:                    for (int i = 0; i < dbObjArr.length; i++) {
197:                        if (s_log.isDebugEnabled()) {
198:                            s_log
199:                                    .debug("setSelectedDatabaseObjects: IDatabaseObjectInfo["
200:                                            + i + "]=" + dbObjArr[i]);
201:                        }
202:                    }
203:                }
204:            }
205:
206:            /**
207:             * Create panel for the Global Properties dialog.
208:             * 
209:             * @return  properties panel.
210:             */
211:            public IGlobalPreferencesPanel[] getGlobalPreferencePanels() {
212:                DBCopyGlobalPreferencesTab tab = new DBCopyGlobalPreferencesTab();
213:                return new IGlobalPreferencesPanel[] { tab };
214:            }
215:
216:            /**
217:             * @param coll
218:             * @param api
219:             */
220:            protected void addMenuItemsToContextMenu(final IObjectTreeAPI api) {
221:                //final IObjectTreeAPI api = Compat.getIObjectTreeAPI(session, this);
222:                final ActionCollection coll = getApplication()
223:                        .getActionCollection();
224:
225:                if (SwingUtilities.isEventDispatchThread()) {
226:                    addToPopup(api, coll);
227:                } else {
228:                    SwingUtilities.invokeLater(new Runnable() {
229:                        public void run() {
230:                            addToPopup(api, coll);
231:                        }
232:                    });
233:                }
234:            }
235:
236:            private void addToPopup(IObjectTreeAPI api, ActionCollection coll) {
237:
238:                api.addToPopup(DatabaseObjectType.TABLE_TYPE_DBO, coll
239:                        .get(CopyTableAction.class));
240:
241:                api.addToPopup(DatabaseObjectType.TABLE_TYPE_DBO, coll
242:                        .get(PasteTableAction.class));
243:
244:                // Copy action object tree types
245:                api.addToPopup(DatabaseObjectType.TABLE, coll
246:                        .get(CopyTableAction.class));
247:
248:                api.addToPopup(DatabaseObjectType.TABLE, coll
249:                        .get(PasteTableAction.class));
250:
251:                // Paste action object tree types
252:                api.addToPopup(DatabaseObjectType.SCHEMA, coll
253:                        .get(PasteTableAction.class));
254:
255:                // MySQL shows databases as "CATALOGS" not "SCHEMAS"
256:                api.addToPopup(DatabaseObjectType.CATALOG, coll
257:                        .get(PasteTableAction.class));
258:
259:                api.addToPopup(DatabaseObjectType.SESSION, coll
260:                        .get(PasteTableAction.class));
261:
262:            }
263:
264:            private class DBCopyPluginResources extends PluginResources {
265:                DBCopyPluginResources(String rsrcBundleBaseName, IPlugin plugin) {
266:                    super (rsrcBundleBaseName, plugin);
267:                }
268:            }
269:
270:            // Interface SessionInfoProvider implementation
271:
272:            /* (non-Javadoc)
273:             * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getCopySourceSession()
274:             */
275:            public ISession getCopySourceSession() {
276:                return copySourceSession;
277:            }
278:
279:            /* (non-Javadoc)
280:             * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setCopySourceSession(net.sourceforge.squirrel_sql.client.session.ISession)
281:             */
282:            public void setCopySourceSession(ISession session) {
283:                if (session != null) {
284:                    copySourceSession = session;
285:                }
286:            }
287:
288:            /* (non-Javadoc)
289:             * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getSelectedDatabaseObjects()
290:             */
291:            public IDatabaseObjectInfo[] getSourceSelectedDatabaseObjects() {
292:                return selectedDatabaseObjects;
293:            }
294:
295:            /* (non-Javadoc)
296:             * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getCopyDestSession()
297:             */
298:            public ISession getCopyDestSession() {
299:                return copyDestSession;
300:            }
301:
302:            /* (non-Javadoc)
303:             * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setDestCopySession(net.sourceforge.squirrel_sql.client.session.ISession)
304:             */
305:            public void setDestCopySession(ISession session) {
306:                copyDestSession = session;
307:            }
308:
309:            /* (non-Javadoc)
310:             * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getDestSelectedDatabaseObject()
311:             */
312:            public IDatabaseObjectInfo getDestSelectedDatabaseObject() {
313:                return selectedDestDatabaseObject;
314:            }
315:
316:            public void setDestSelectedDatabaseObject(IDatabaseObjectInfo info) {
317:                selectedDestDatabaseObject = info;
318:            }
319:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.