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


001:        package net.sourceforge.squirrel_sql.plugins.codecompletion;
002:
003:        /*
004:         * Copyright (C) 2003 Gerd Wagner
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         */
020:        import net.sourceforge.squirrel_sql.client.gui.session.ObjectTreeInternalFrame;
021:        import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
022:        import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
023:        import net.sourceforge.squirrel_sql.client.plugin.PluginException;
024:        import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
025:        import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallback;
026:        import net.sourceforge.squirrel_sql.client.preferences.INewSessionPropertiesPanel;
027:        import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
028:        import net.sourceforge.squirrel_sql.client.session.ISession;
029:        import net.sourceforge.squirrel_sql.client.session.properties.ISessionPropertiesPanel;
030:        import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
031:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
032:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
033:        import net.sourceforge.squirrel_sql.fw.util.Utilities;
034:        import net.sourceforge.squirrel_sql.fw.xml.XMLBeanReader;
035:        import net.sourceforge.squirrel_sql.fw.xml.XMLBeanWriter;
036:        import net.sourceforge.squirrel_sql.plugins.codecompletion.prefs.CodeCompletionPreferences;
037:        import net.sourceforge.squirrel_sql.plugins.codecompletion.prefs.CodeCompletionPreferencesController;
038:
039:        import javax.swing.*;
040:        import java.io.File;
041:        import java.util.Iterator;
042:
043:        /**
044:         * The plugin class.
045:         *
046:         * @author  Gerd Wagner
047:         */
048:        public class CodeCompletionPlugin extends DefaultSessionPlugin {
049:            /** Logger for this class. */
050:            @SuppressWarnings("unused")
051:            private final static ILogger s_log = LoggerController
052:                    .createLogger(CodeCompletionPlugin.class);
053:
054:            /** Resources for this plugin. */
055:            private Resources _resources;
056:            private static final String PREFS_FILE_NAME = "codecompletionprefs.xml";
057:
058:            private CodeCompletionPreferences _newSessionPrefs;
059:            public static final String PLUGIN_OBJECT_PREFS_KEY = "codecompletionprefs";
060:
061:            /**
062:             * Return the internal name of this plugin.
063:             *
064:             * @return  the internal name of this plugin.
065:             */
066:            public String getInternalName() {
067:                return "codecompletion";
068:            }
069:
070:            /**
071:             * Return the descriptive name of this plugin.
072:             *
073:             * @return  the descriptive name of this plugin.
074:             */
075:            public String getDescriptiveName() {
076:                return "SQL Entry Code Completion";
077:            }
078:
079:            /**
080:             * Returns the current version of this plugin.
081:             *
082:             * @return  the current version of this plugin.
083:             */
084:            public String getVersion() {
085:                return "1.0";
086:            }
087:
088:            /**
089:             * Returns a comma separated list of other contributors.
090:             *
091:             * @return      Contributors names.
092:             */
093:            public String getContributors() {
094:                return "Christian Sell";
095:            }
096:
097:            /**
098:             * Returns the authors name.
099:             *
100:             * @return  the authors name.
101:             */
102:            public String getAuthor() {
103:                return "Gerd Wagner";
104:            }
105:
106:            /**
107:             * Returns the name of the change log for the plugin. This should
108:             * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
109:             * directory.
110:             *
111:             * @return	the changelog file name or <TT>null</TT> if plugin doesn't have
112:             * 			a change log.
113:             */
114:            public String getChangeLogFileName() {
115:                return "changes.txt";
116:            }
117:
118:            /**
119:             * Returns the name of the Help file for the plugin. This should
120:             * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
121:             * directory.
122:             *
123:             * @return	the Help file name or <TT>null</TT> if plugin doesn't have
124:             * 			a help file.
125:             */
126:            public String getHelpFileName() {
127:                return "readme.html";
128:            }
129:
130:            /**
131:             * Returns the name of the Licence file for the plugin. This should
132:             * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
133:             * directory.
134:             *
135:             * @return	the Licence file name or <TT>null</TT> if plugin doesn't have
136:             * 			a licence file.
137:             */
138:            public String getLicenceFileName() {
139:                return "licence.txt";
140:            }
141:
142:            /**
143:             * Called on application startup after application started.
144:             */
145:            public void initialize() throws PluginException {
146:                _resources = new Resources(this );
147:                loadPrefs();
148:            }
149:
150:            public void unload() {
151:                savePrefs();
152:            }
153:
154:            private void savePrefs() {
155:                try {
156:                    File prefsFile = new File(getPluginUserSettingsFolder(),
157:                            PREFS_FILE_NAME);
158:                    final XMLBeanWriter wtr = new XMLBeanWriter(
159:                            _newSessionPrefs);
160:                    wtr.save(prefsFile);
161:                } catch (Exception e) {
162:                    throw new RuntimeException(e);
163:                }
164:            }
165:
166:            private void loadPrefs() {
167:                try {
168:                    _newSessionPrefs = new CodeCompletionPreferences();
169:                    File prefsFile = new File(getPluginUserSettingsFolder(),
170:                            PREFS_FILE_NAME);
171:                    if (prefsFile.exists()) {
172:                        XMLBeanReader reader = new XMLBeanReader();
173:                        reader.load(prefsFile, getClass().getClassLoader());
174:
175:                        Iterator<?> it = reader.iterator();
176:
177:                        if (it.hasNext()) {
178:                            _newSessionPrefs = (CodeCompletionPreferences) it
179:                                    .next();
180:                        }
181:
182:                    }
183:                } catch (Exception e) {
184:                    throw new RuntimeException(e);
185:                }
186:            }
187:
188:            /**
189:             * Create preferences panel for the New Session Properties dialog.
190:             *
191:             * @return	preferences panel.
192:             */
193:            public INewSessionPropertiesPanel[] getNewSessionPropertiesPanels() {
194:                return new INewSessionPropertiesPanel[] { new CodeCompletionPreferencesController(
195:                        _newSessionPrefs) };
196:            }
197:
198:            /**
199:             * Create panels for the Session Properties dialog.
200:             *
201:             * @return		Array of panels for the properties dialog.
202:             */
203:            public ISessionPropertiesPanel[] getSessionPropertiesPanels(
204:                    ISession session) {
205:                CodeCompletionPreferences sessionPrefs = (CodeCompletionPreferences) session
206:                        .getPluginObject(this , PLUGIN_OBJECT_PREFS_KEY);
207:
208:                return new ISessionPropertiesPanel[] { new CodeCompletionPreferencesController(
209:                        sessionPrefs) };
210:            }
211:
212:            public void sessionCreated(ISession session) {
213:                CodeCompletionPreferences prefs = (CodeCompletionPreferences) Utilities
214:                        .cloneObject(_newSessionPrefs, getClass()
215:                                .getClassLoader());
216:                session.putPluginObject(this , PLUGIN_OBJECT_PREFS_KEY, prefs);
217:            }
218:
219:            public boolean allowsSessionStartedInBackground() {
220:                return true;
221:            }
222:
223:            /**
224:             * Session has been started.
225:             * 
226:             * @param	session		Session that has started.
227:             */
228:            public PluginSessionCallback sessionStarted(final ISession session) {
229:                ISQLPanelAPI sqlPaneAPI = session.getSessionSheet()
230:                        .getSQLPaneAPI();
231:
232:                initCodeCompletion(sqlPaneAPI, session);
233:
234:                PluginSessionCallback ret = new PluginSessionCallback() {
235:                    public void sqlInternalFrameOpened(
236:                            final SQLInternalFrame sqlInternalFrame,
237:                            final ISession sess) {
238:                        initCodeCompletion(sqlInternalFrame.getSQLPanelAPI(),
239:                                sess);
240:                    }
241:
242:                    public void objectTreeInternalFrameOpened(
243:                            ObjectTreeInternalFrame objectTreeInternalFrame,
244:                            ISession sess) {
245:                    }
246:                };
247:
248:                return ret;
249:            }
250:
251:            private void initCodeCompletion(final ISQLPanelAPI sqlPaneAPI,
252:                    final ISession session) {
253:                GUIUtils.processOnSwingEventThread(new Runnable() {
254:                    public void run() {
255:                        CodeCompletionInfoCollection c = new CodeCompletionInfoCollection(
256:                                session, CodeCompletionPlugin.this );
257:
258:                        CompleteCodeAction cca = new CompleteCodeAction(session
259:                                .getApplication(), CodeCompletionPlugin.this ,
260:                                sqlPaneAPI.getSQLEntryPanel(), session, c);
261:
262:                        JMenuItem item = sqlPaneAPI.addToSQLEntryAreaMenu(cca);
263:
264:                        _resources.configureMenuItem(cca, item);
265:
266:                        JComponent comp = sqlPaneAPI.getSQLEntryPanel()
267:                                .getTextComponent();
268:                        comp.registerKeyboardAction(cca, _resources
269:                                .getKeyStroke(cca),
270:                                JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
271:
272:                        sqlPaneAPI.addToToolsPopUp("completecode", cca);
273:                    }
274:
275:                });
276:            }
277:
278:            /**
279:             * Retrieve plugins resources.
280:             * 
281:             * @return	Plugins resources.
282:             */
283:            public PluginResources getResources() {
284:                return _resources;
285:            }
286:
287:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.