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


001:        package net.sourceforge.squirrel_sql.client.session;
002:
003:        /*
004:         * Copyright (C) 2002-2004 Colin Bell and Johan Compagner
005:         * colbell@users.sourceforge.net
006:         * jcompagner@j-com.nl
007:         *
008:         * Modifications Copyright (C) 2003-2004 Jason Height
009:         *
010:         * This library is free software; you can redistribute it and/or
011:         * modify it under the terms of the GNU Lesser General Public
012:         * License as published by the Free Software Foundation; either
013:         * version 2.1 of the License, or (at your option) any later version.
014:         *
015:         * This library is distributed in the hope that it will be useful,
016:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
017:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
018:         * Lesser General Public License for more details.
019:         *
020:         * You should have received a copy of the GNU Lesser General Public
021:         * License along with this library; if not, write to the Free Software
022:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
023:         */
024:        import java.io.File;
025:        import java.util.ArrayList;
026:
027:        import javax.swing.Action;
028:        import javax.swing.JFrame;
029:        import javax.swing.JMenu;
030:        import javax.swing.JMenuItem;
031:        import javax.swing.JOptionPane;
032:        import javax.swing.event.UndoableEditEvent;
033:        import javax.swing.event.UndoableEditListener;
034:
035:        import net.sourceforge.squirrel_sql.client.IApplication;
036:        import net.sourceforge.squirrel_sql.client.action.ActionCollection;
037:        import net.sourceforge.squirrel_sql.client.gui.session.ToolsPopupController;
038:        import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
039:        import net.sourceforge.squirrel_sql.client.resources.SquirrelResources;
040:        import net.sourceforge.squirrel_sql.client.session.action.*;
041:        import net.sourceforge.squirrel_sql.client.session.event.IResultTabListener;
042:        import net.sourceforge.squirrel_sql.client.session.event.ISQLExecutionListener;
043:        import net.sourceforge.squirrel_sql.client.session.event.ISQLPanelListener;
044:        import net.sourceforge.squirrel_sql.client.session.event.ISQLResultExecuterTabListener;
045:        import net.sourceforge.squirrel_sql.client.session.mainpanel.ISQLResultExecuter;
046:        import net.sourceforge.squirrel_sql.client.session.mainpanel.SQLHistoryItem;
047:        import net.sourceforge.squirrel_sql.client.session.mainpanel.SQLPanel;
048:        import net.sourceforge.squirrel_sql.client.session.mainpanel.SqlPanelListener;
049:        import net.sourceforge.squirrel_sql.client.util.PrintUtilities;
050:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
051:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
052:
053:        /**
054:         * This class is the API through which plugins can work with the SQL Panel.
055:         *
056:         * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
057:         */
058:        public class SQLPanelAPI implements  ISQLPanelAPI {
059:            /** Internationalized strings for this class. */
060:            private static final StringManager s_stringMgr = StringManagerFactory
061:                    .getStringManager(SQLPanelAPI.class);
062:
063:            /** The SQL Panel. */
064:            private SQLPanel _panel;
065:
066:            private ToolsPopupController _toolsPopupController;
067:            private FileManager _fileManager = new FileManager(this );
068:
069:            private boolean fileOpened = false;
070:            private boolean fileSaved = false;
071:            private boolean unsavedEdits = false;
072:
073:            /**
074:             * Ctor specifying the panel.
075:             *
076:             * @param	panel	<TT>SQLPanel</TT> is the SQL Panel.
077:             *
078:             * @throws	IllegalArgumentException
079:             * 			Thrown if <T>null</TT> <TT>SQLPanel</TT> passed.
080:             */
081:            public SQLPanelAPI(SQLPanel panel) {
082:                super ();
083:                if (panel == null) {
084:                    throw new IllegalArgumentException("SQLPanel == null");
085:                }
086:                _panel = panel;
087:                _panel.getSQLEntryPanel().addUndoableEditListener(
088:                        new SQLEntryUndoListener());
089:                initToolsPopUp();
090:
091:                createStandardEntryAreaMenuItems();
092:            }
093:
094:            private void initToolsPopUp() {
095:                _toolsPopupController = new ToolsPopupController(getSession(),
096:                        _panel.getSQLEntryPanel());
097:
098:                ActionCollection ac = getSession().getApplication()
099:                        .getActionCollection();
100:
101:                _toolsPopupController.addAction("undo", _panel.getUndoAction());
102:                _toolsPopupController.addAction("redo", _panel.getRedoAction());
103:                _toolsPopupController.addAction("runsql", ac
104:                        .get(ExecuteSqlAction.class));
105:                _toolsPopupController.addAction("fileopen", ac
106:                        .get(FileOpenAction.class));
107:                _toolsPopupController.addAction("filesave", ac
108:                        .get(FileSaveAction.class));
109:                _toolsPopupController.addAction("filesaveas", ac
110:                        .get(FileSaveAsAction.class));
111:                _toolsPopupController.addAction("filenew", ac
112:                        .get(FileNewAction.class));
113:                _toolsPopupController.addAction("fileappend", ac
114:                        .get(FileAppendAction.class));
115:                _toolsPopupController.addAction("fileprint", ac
116:                        .get(FilePrintAction.class));
117:                _toolsPopupController.addAction("fileclose", ac
118:                        .get(FileCloseAction.class));
119:
120:                _toolsPopupController.addAction("tabnext", ac
121:                        .get(GotoNextResultsTabAction.class));
122:                _toolsPopupController.addAction("tabprevious", ac
123:                        .get(GotoPreviousResultsTabAction.class));
124:                _toolsPopupController.addAction("tabcloseall", ac
125:                        .get(CloseAllSQLResultTabsAction.class));
126:                _toolsPopupController.addAction("tabcloseallbutcur", ac
127:                        .get(CloseAllSQLResultTabsButCurrentAction.class));
128:                _toolsPopupController.addAction("tabclosecur", ac
129:                        .get(CloseCurrentSQLResultTabAction.class));
130:                _toolsPopupController.addAction("tabsticky", ac
131:                        .get(ToggleCurrentSQLResultTabStickyAction.class));
132:
133:                _toolsPopupController.addAction("sqlprevious", ac
134:                        .get(PreviousSqlAction.class));
135:                _toolsPopupController.addAction("sqlnext", ac
136:                        .get(NextSqlAction.class));
137:                _toolsPopupController.addAction("sqlselect", ac
138:                        .get(SelectSqlAction.class));
139:
140:                _toolsPopupController.addAction("sqlhist", ac
141:                        .get(OpenSqlHistoryAction.class));
142:
143:                if (_panel.isInMainSessionWindow()) {
144:                    _toolsPopupController.addAction("viewinobjecttree", ac
145:                            .get(ViewObjectAtCursorInObjectTreeAction.class));
146:                }
147:
148:            }
149:
150:            private void createStandardEntryAreaMenuItems() {
151:                JMenuItem item;
152:                SquirrelResources resources = getSession().getApplication()
153:                        .getResources();
154:
155:                Action toolsPopupAction = _panel.getSession().getApplication()
156:                        .getActionCollection().get(ToolsPopupAction.class);
157:                item = getSQLEntryPanel().addToSQLEntryAreaMenu(
158:                        toolsPopupAction);
159:                resources.configureMenuItem(toolsPopupAction, item);
160:
161:                if (_panel.isInMainSessionWindow()) {
162:                    Action vioAction = _panel.getSession().getApplication()
163:                            .getActionCollection().get(
164:                                    ViewObjectAtCursorInObjectTreeAction.class);
165:                    item = getSQLEntryPanel().addToSQLEntryAreaMenu(vioAction);
166:                    resources.configureMenuItem(vioAction, item);
167:                }
168:
169:            }
170:
171:            public void addToToolsPopUp(String selectionString, Action action) {
172:                _toolsPopupController.addAction(selectionString, action);
173:            }
174:
175:            public boolean fileSave() {
176:                if (_fileManager.save()) {
177:                    fileSaved = true;
178:                    unsavedEdits = false;
179:                    getSession().getActiveSessionWindow()
180:                            .setUnsavedEdits(false);
181:                    ActionCollection actions = getSession().getApplication()
182:                            .getActionCollection();
183:                    actions.enableAction(FileSaveAction.class, false);
184:                    return true;
185:                } else {
186:                    return false;
187:                }
188:            }
189:
190:            /* (non-Javadoc)
191:             * @see net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI#fileAppend()
192:             */
193:            public void fileAppend() {
194:                if (_fileManager.open(true)) {
195:                    fileOpened = true;
196:                    fileSaved = false;
197:                    unsavedEdits = false;
198:                    ActionCollection actions = getSession().getApplication()
199:                            .getActionCollection();
200:                    actions.enableAction(FileSaveAction.class, true);
201:                }
202:            }
203:
204:            /* (non-Javadoc)
205:             * @see net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI#fileClose()
206:             */
207:            public void fileClose() {
208:                if (unsavedEdits) {
209:                    showConfirmSaveDialog();
210:                }
211:                setEntireSQLScript("");
212:                getSession().getActiveSessionWindow().setSqlFile(null);
213:                fileOpened = false;
214:                fileSaved = false;
215:                unsavedEdits = false;
216:                ActionCollection actions = getSession().getApplication()
217:                        .getActionCollection();
218:                actions.enableAction(FileSaveAction.class, true);
219:                _fileManager.clearCurrentFile();
220:            }
221:
222:            /* (non-Javadoc)
223:             * @see net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI#fileNew()
224:             */
225:            public void fileNew() {
226:                fileClose();
227:            }
228:
229:            /* (non-Javadoc)
230:             * @see net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI#fileSaveAs()
231:             */
232:            public void fileSaveAs() {
233:                if (_fileManager.saveAs()) {
234:                    fileSaved = true;
235:                    unsavedEdits = false;
236:                    getSession().getActiveSessionWindow()
237:                            .setUnsavedEdits(false);
238:                    ActionCollection actions = getSession().getApplication()
239:                            .getActionCollection();
240:                    actions.enableAction(FileSaveAction.class, false);
241:                }
242:            }
243:
244:            /* (non-Javadoc)
245:             * @see net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI#fileOpen()
246:             */
247:            public void fileOpen() {
248:                if (unsavedEdits) {
249:                    showConfirmSaveDialog();
250:                }
251:                if (_fileManager.open(false)) {
252:                    fileOpened = true;
253:                    fileSaved = false;
254:                    unsavedEdits = false;
255:                    ActionCollection actions = getSession().getApplication()
256:                            .getActionCollection();
257:                    actions.enableAction(FileSaveAction.class, false);
258:                }
259:            }
260:
261:            public void fileOpen(File f) {
262:                if (unsavedEdits) {
263:                    showConfirmSaveDialog();
264:                }
265:                if (_fileManager.open(f)) {
266:                    fileOpened = true;
267:                    fileSaved = false;
268:                    unsavedEdits = false;
269:                    ActionCollection actions = getSession().getApplication()
270:                            .getActionCollection();
271:                    actions.enableAction(FileSaveAction.class, false);
272:                }
273:
274:            }
275:
276:            /* (non-Javadoc)
277:             * @see net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI#filePrint()
278:             */
279:            public void filePrint() {
280:                if (_panel == null) {
281:                    throw new IllegalStateException("_panel is null");
282:                }
283:                ISQLEntryPanel panel = _panel.getSQLEntryPanel();
284:                if (panel == null) {
285:                    throw new IllegalStateException(
286:                            "_panel.getSQLEntryPanel() is null");
287:                }
288:                PrintUtilities.printComponent(panel.getTextComponent());
289:            }
290:
291:            public void showToolsPopup() {
292:                _toolsPopupController.showToolsPopup();
293:            }
294:
295:            public void addExecutor(ISQLResultExecuter exec) {
296:                _panel.addExecutor(exec);
297:            }
298:
299:            public void removeExecutor(ISQLResultExecuter exec) {
300:                _panel.removeExecutor(exec);
301:            }
302:
303:            /**
304:             * Add a listener listening for SQL Execution.
305:             *
306:             * @param	lis		Listener to add
307:             *
308:             * @throws	IllegalArgumentException
309:             *			Thrown if a null <TT>ISQLExecutionListener</TT> passed.
310:             */
311:            public synchronized void addSQLExecutionListener(
312:                    ISQLExecutionListener lis) {
313:                if (lis == null) {
314:                    throw new IllegalArgumentException(
315:                            "null ISQLExecutionListener passed");
316:                }
317:                _panel.addSQLExecutionListener(lis);
318:            }
319:
320:            /**
321:             * Remove an SQL execution listener.
322:             *
323:             * @param	lis	 Listener
324:             *
325:             * @throws	IllegalArgumentException
326:             *			If a null <TT>ISQLExecutionListener</TT> passed.
327:             */
328:            public synchronized void removeSQLExecutionListener(
329:                    ISQLExecutionListener lis) {
330:                if (lis == null) {
331:                    throw new IllegalArgumentException(
332:                            "null ISQLExecutionListener passed");
333:                }
334:                _panel.removeSQLExecutionListener(lis);
335:            }
336:
337:            /**
338:             * Add a listener for events in this sessions result tabs.
339:             *
340:             * @param	lis		The listener.
341:             */
342:            // JASON: Do we need these?
343:            public synchronized void addResultTabListener(IResultTabListener lis) {
344:                //		if (lis == null)
345:                //		{
346:                //			throw new IllegalArgumentException("null IResultTabListener passed");
347:                //		}
348:                //		_session.getSessionSheet().getSQLPanel().addResultTabListener(lis);
349:            }
350:
351:            /**
352:             * Remove a listener for events in this sessions result tabs.
353:             *
354:             * @param	lis		The listener.
355:             */
356:            //	 JASON: Do we need these?
357:            public synchronized void removeResultTabListener(
358:                    IResultTabListener lis) {
359:                //		if (lis == null)
360:                //		{
361:                //			throw new IllegalArgumentException("null IResultTabListener passed");
362:                //		}
363:                //		_session.getSessionSheet().getSQLPanel().removeResultTabListener(lis);
364:            }
365:
366:            /**
367:             * Add a listener for events in this sql panel executer tabs.
368:             *
369:             * @param	lis		The listener.
370:             *
371:             * @throws	IllegalArgumentException
372:             *			Thrown if a null <TT>ISQLResultExecuterTabListener</TT> passed.
373:             */
374:            public void addExecuterTabListener(ISQLResultExecuterTabListener lis) {
375:                if (lis == null) {
376:                    throw new IllegalArgumentException(
377:                            "ISQLResultExecuterTabListener == null");
378:                }
379:                _panel.addExecuterTabListener(lis);
380:            }
381:
382:            /**
383:             * Remove a listener for events from this sql panel executer tabs.
384:             *
385:             * @param	lis		The listener.
386:             *
387:             * @throws	IllegalArgumentException
388:             *			Thrown if a null <TT>ISQLResultExecuterTabListener</TT> passed.
389:             */
390:            public void removeExecuterTabListener(
391:                    ISQLResultExecuterTabListener lis) {
392:                if (lis == null) {
393:                    throw new IllegalArgumentException(
394:                            "ISQLResultExecuterTabListener == null");
395:                }
396:                _panel.removeExecuterTabListener(lis);
397:            }
398:
399:            /**
400:             * Add a listener for events in this SQL Panel.
401:             *
402:             * @param	lis		Listener to add
403:             *
404:             * @throws	IllegalArgumentException
405:             *			Thrown if a null <TT>ISQLPanelListener</TT> passed.
406:             */
407:            public synchronized void addSQLPanelListener(ISQLPanelListener lis) {
408:                if (lis == null) {
409:                    throw new IllegalArgumentException(
410:                            "ISQLPanelListener == null");
411:                }
412:                _panel.addSQLPanelListener(lis);
413:            }
414:
415:            /**
416:             * Remove a listener.
417:             *
418:             * @param	lis		Listener to remove
419:             *
420:             * @throws	IllegalArgumentException
421:             *			Thrown if a null <TT>ISQLPanelListener</TT> passed.
422:             */
423:            public synchronized void removeSQLPanelListener(
424:                    ISQLPanelListener lis) {
425:                if (lis == null) {
426:                    throw new IllegalArgumentException(
427:                            "ISQLPanelListener == null");
428:                }
429:                _panel.removeSQLPanelListener(lis);
430:            }
431:
432:            public ISQLEntryPanel getSQLEntryPanel() {
433:                return _panel.getSQLEntryPanel();
434:            }
435:
436:            /**
437:             * Returns the result execution panel that stores such things as IResultTabs
438:             * 
439:             * @return an implementation of ISQLResultExecuter 
440:             */
441:            public ISQLResultExecuter getSQLResultExecuter() {
442:                return _panel.getSQLExecPanel();
443:            }
444:
445:            /**
446:             * Return the entire contents of the SQL entry area.
447:             *
448:             * @return	the entire contents of the SQL entry area.
449:             */
450:            public synchronized String getEntireSQLScript() {
451:                return _panel.getSQLEntryPanel().getText();
452:            }
453:
454:            /**
455:             * Return the selected contents of the SQL entry area.
456:             *
457:             * @return	the selected contents of the SQL entry area.
458:             */
459:            public String getSelectedSQLScript() {
460:                return _panel.getSQLEntryPanel().getSelectedText();
461:            }
462:
463:            /**
464:             * Return the SQL script to be executed.
465:             *
466:             * @return	the SQL script to be executed.
467:             */
468:            public synchronized String getSQLScriptToBeExecuted() {
469:                return _panel.getSQLEntryPanel().getSQLToBeExecuted();
470:            }
471:
472:            /**
473:             * Append the passed SQL script to the SQL entry area but don't select
474:             * it.
475:             *
476:             * @param	sqlScript	The script to be appended.
477:             */
478:            public synchronized void appendSQLScript(String sqlScript) {
479:                _panel.getSQLEntryPanel().appendText(sqlScript);
480:            }
481:
482:            /**
483:             * Append the passed SQL script to the SQL entry area and specify
484:             * whether it should be selected.
485:             *
486:             * @param	sqlScript	The script to be appended.
487:             * @param	select		If <TT>true</TT> then select the passed script
488:             * 						in the sql entry area.
489:             */
490:            public synchronized void appendSQLScript(String sqlScript,
491:                    boolean select) {
492:                _panel.getSQLEntryPanel().appendText(sqlScript, select);
493:            }
494:
495:            /**
496:             * Replace the contents of the SQL entry area with the passed
497:             * SQL script without selecting it.
498:             *
499:             * @param	sqlScript	The script to be placed in the SQL entry area.
500:             */
501:            public synchronized void setEntireSQLScript(String sqlScript) {
502:                _panel.getSQLEntryPanel().setText(sqlScript);
503:            }
504:
505:            /**
506:             * Replace the contents of the SQL entry area with the passed
507:             * SQL script and specify whether to select it.
508:             *
509:             * @param	sqlScript	The script to be placed in the SQL entry area.
510:             * @param	select		If <TT>true</TT> then select the passed script
511:             * 						in the sql entry area.
512:             */
513:            public synchronized void setEntireSQLScript(String sqlScript,
514:                    boolean select) {
515:                _panel.getSQLEntryPanel().setText(sqlScript, select);
516:            }
517:
518:            /**
519:             * Replace the currently selected text in the SQL entry area
520:             * with the passed text.
521:             *
522:             * @param	sqlScript	The script to be placed in the SQL entry area.
523:             * @param	select		If <TT>true</TT> then select the passed script
524:             * 						in the sql entry area.
525:             */
526:            public synchronized void replaceSelectedSQLScript(String sqlScript,
527:                    boolean select) {
528:                if (sqlScript == null) {
529:                    sqlScript = "";
530:                }
531:                final ISQLEntryPanel pnl = _panel.getSQLEntryPanel();
532:                int selStart = -1;
533:                if (select) {
534:                    selStart = pnl.getSelectionStart();
535:                }
536:                pnl.replaceSelection(sqlScript);
537:                if (select) {
538:                    int entireLen = getEntireSQLScript().length();
539:                    if (selStart == -1) {
540:                        selStart = 0;
541:                    }
542:                    int selEnd = selStart + sqlScript.length() - 1;
543:                    if (selEnd > entireLen - 1) {
544:                        selEnd = entireLen - 1;
545:                    }
546:                    if (selStart <= selEnd) {
547:                        pnl.setSelectionStart(selStart);
548:                        pnl.setSelectionEnd(selEnd);
549:                    }
550:                }
551:            }
552:
553:            /**
554:             * Return the offset into the SQL entry area where the current select
555:             * starts.
556:             *
557:             * @return	the current selections start position.
558:             */
559:            public synchronized int getSQLScriptSelectionStart() {
560:                return _panel.getSQLEntryPanel().getSelectionStart();
561:            }
562:
563:            /**
564:             * Return the offset into the SQL entry area where the current select
565:             * ends.
566:             *
567:             * @return	the current selections end position.
568:             */
569:            public synchronized int getSQLScriptSelectionEnd() {
570:                return _panel.getSQLEntryPanel().getSelectionEnd();
571:            }
572:
573:            /**
574:             * Set the offset into the SQL entry area where the current select
575:             * starts.
576:             *
577:             * param	start	the new selections start position.
578:             */
579:            public synchronized void setSQLScriptSelectionStart(int start) {
580:                _panel.getSQLEntryPanel().setSelectionStart(start);
581:            }
582:
583:            /**
584:             * Set the offset into the SQL entry area where the current select
585:             * ends.
586:             *
587:             * param	start	the new selections start position.
588:             */
589:            public synchronized void setSQLScriptSelectionEnd(int end) {
590:                _panel.getSQLEntryPanel().setSelectionEnd(end);
591:            }
592:
593:            /**
594:             * Execute the current SQL. Not <TT>synchronized</TT> as multiple SQL statements
595:             * can be executed simultaneously.
596:             */
597:            public void executeCurrentSQL() {
598:                _panel.runCurrentExecuter();
599:            }
600:
601:            /**
602:             * Execute the passed SQL. Not <TT>synchronized</TT> as multiple SQL statements
603:             * can be executed simultaneously.
604:             *
605:             * @param	sql		SQL to be executed.
606:             */
607:            public void executeSQL(String sql) {
608:                //JASON: Remove??
609:                //_session.getSessionSheet().getSQLPanel().executeSQL(sql);
610:            }
611:
612:            /**
613:             * Close all the SQL result tabs.
614:             */
615:            public void closeAllSQLResultTabs() {
616:                _panel.getSQLExecPanel().closeAllSQLResultTabs();
617:            }
618:
619:            public void closeAllButCurrentResultTabs() {
620:                _panel.getSQLExecPanel().closeAllButCurrentResultTabs();
621:            }
622:
623:            public void closeCurrentResultTab() {
624:                _panel.getSQLExecPanel().closeCurrentResultTab();
625:            }
626:
627:            public void toggleCurrentSQLResultTabSticky() {
628:                _panel.getSQLExecPanel().toggleCurrentSQLResultTabSticky();
629:            }
630:
631:            /**
632:             * Close all the "torn off" SQL result frames.
633:             */
634:            public void closeAllSQLResultFrames() {
635:                _panel.getSQLExecPanel().closeAllSQLResultFrames();
636:            }
637:
638:            /**
639:             * Display the next tab in the SQL results.
640:             */
641:            public synchronized void gotoNextResultsTab() {
642:                _panel.getSQLExecPanel().gotoNextResultsTab();
643:            }
644:
645:            /**
646:             * Display the previous tab in the SQL results.
647:             */
648:            public void gotoPreviousResultsTab() {
649:                _panel.getSQLExecPanel().gotoPreviousResultsTab();
650:            }
651:
652:            /**
653:             * The passed SQL should be added to the SQL history.
654:             *
655:             * @param	sql		SQL to be added to history.
656:             *
657:             * @throws	IllegalArgumentException
658:             * 			Thrown if <TT>null</TT> <TT>sql</TT> passed.
659:             */
660:            public synchronized void addSQLToHistory(String sql) {
661:                if (sql == null) {
662:                    throw new IllegalArgumentException("sql == null");
663:                }
664:
665:                final ISession session = _panel.getSession();
666:                final SQLHistoryItem shi = new SQLHistoryItem(sql, session
667:                        .getAlias().getName());
668:                if (session.getProperties().getSQLShareHistory()) {
669:                    session.getApplication().getSQLHistory().add(shi);
670:                }
671:                _panel.addSQLToHistory(shi);
672:            }
673:
674:            /**
675:             * Add a hierarchical menu to the SQL Entry Area popup menu.
676:             *
677:             * @param	menu	The menu that will be added.
678:             *
679:             * @throws	IllegalArgumentException
680:             * 			Thrown if <TT>null</TT> <TT>Menu</TT> passed.
681:             */
682:            public void addToSQLEntryAreaMenu(JMenu menu) {
683:                if (menu == null) {
684:                    throw new IllegalArgumentException("Menu == null");
685:                }
686:                _panel.addToSQLEntryAreaMenu(menu);
687:            }
688:
689:            /**
690:             * Add an <TT>Action</TT> to the SQL Entry Area popup menu.
691:             *
692:             * @param	action	The action to be added.
693:             *
694:             * @return	The newly create menu item.
695:             *
696:             * @throws	IllegalArgumentException
697:             * 			Thrown if <TT>null</TT> <TT>Action</TT> passed.
698:             */
699:            public JMenuItem addToSQLEntryAreaMenu(Action action) {
700:                if (action == null) {
701:                    throw new IllegalArgumentException("Action == null");
702:                }
703:                return _panel.addToSQLEntryAreaMenu(action);
704:            }
705:
706:            /** JASON: Remove once deprecated interface removed*/
707:            public ISession getSession() {
708:                return _panel.getSession();
709:            }
710:
711:            public boolean isInMainSessionWindow() {
712:                return _panel.isInMainSessionWindow();
713:            }
714:
715:            public boolean confirmClose() {
716:                if (unsavedEdits) {
717:                    return showConfirmSaveDialog();
718:                }
719:                return true;
720:            }
721:
722:            public void addSqlPanelListener(SqlPanelListener sqlPanelListener) {
723:                _panel.addSqlPanelListener(sqlPanelListener);
724:            }
725:
726:            public ArrayList<SQLHistoryItem> getSQLHistoryItems() {
727:                return _panel.getSQLHistoryItems();
728:            }
729:
730:            private boolean showConfirmSaveDialog() {
731:                File file = _fileManager.getFile();
732:
733:                // i18n[SQLPanelAPI.untitledLabel=Untitled]
734:                String filename = s_stringMgr
735:                        .getString("SQLPanelAPI.untitledLabel");
736:
737:                if (file != null) {
738:                    filename = file.getAbsolutePath();
739:                }
740:                String msg = s_stringMgr.getString(
741:                        "SQLPanelAPI.unsavedchanges", filename);
742:
743:                String title = s_stringMgr.getString(
744:                        "SQLPanelAPI.unsavedchangestitle", ": "
745:                                + _panel.getSession().getAlias().getName());
746:
747:                JFrame f = getSession().getApplication().getMainFrame();
748:                int option = JOptionPane.showConfirmDialog(f, msg, title,
749:                        JOptionPane.YES_NO_OPTION);
750:                if (option == JOptionPane.YES_OPTION) {
751:                    return fileSave();
752:                }
753:                return true;
754:            }
755:
756:            /**
757:             * A class to listen for events that indicate that the content in the 
758:             * SQLEntryPanel has changed and could be lost.
759:             */
760:            private class SQLEntryUndoListener implements  UndoableEditListener {
761:
762:                /* (non-Javadoc)
763:                 * @see javax.swing.event.UndoableEditListener#undoableEditHappened(javax.swing.event.UndoableEditEvent)
764:                 */
765:                public void undoableEditHappened(UndoableEditEvent e) {
766:                    IApplication app = getSession().getApplication();
767:                    SquirrelPreferences prefs = app.getSquirrelPreferences();
768:
769:                    if (fileOpened || fileSaved) {
770:                        if (prefs.getWarnForUnsavedFileEdits()) {
771:                            unsavedEdits = true;
772:                        }
773:                        getSession().getActiveSessionWindow().setUnsavedEdits(
774:                                true);
775:                        ActionCollection actions = getSession()
776:                                .getApplication().getActionCollection();
777:                        actions.enableAction(FileSaveAction.class, true);
778:                    } else if (prefs.getWarnForUnsavedBufferEdits()) {
779:                        unsavedEdits = true;
780:                    }
781:                }
782:
783:            }
784:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.