Source Code Cross Referenced for DbObjectSourcePanel.java in  » Database-Client » SQL-Workbench » workbench » gui » dbobjects » 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 » SQL Workbench » workbench.gui.dbobjects 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DbObjectSourcePanel.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.gui.dbobjects;
013:
014:        import java.awt.BorderLayout;
015:        import java.awt.EventQueue;
016:        import java.awt.event.ActionEvent;
017:        import java.awt.event.ActionListener;
018:        import javax.swing.JPanel;
019:        import workbench.db.SourceStatementsHelp;
020:        import workbench.db.WbConnection;
021:        import workbench.gui.MainWindow;
022:        import workbench.gui.WbSwingUtilities;
023:        import workbench.gui.actions.ReloadAction;
024:        import workbench.gui.components.DropDownButton;
025:        import workbench.gui.components.FocusIndicator;
026:        import workbench.gui.components.WbToolbar;
027:        import workbench.gui.sql.EditorPanel;
028:        import workbench.gui.sql.PanelContentSender;
029:        import workbench.interfaces.Reloadable;
030:        import workbench.interfaces.Resettable;
031:        import workbench.log.LogMgr;
032:        import workbench.resource.ResourceMgr;
033:        import workbench.resource.Settings;
034:        import workbench.util.StringUtil;
035:
036:        /**
037:         * @author support@sql-workbench.net
038:         */
039:        public class DbObjectSourcePanel extends JPanel implements 
040:                ActionListener, Resettable {
041:            protected EditorPanel sourceEditor;
042:            protected ReloadAction reloadSource;
043:            protected DropDownButton editButton;
044:            private EditorTabSelectMenu selectTabMenu;
045:            private MainWindow parentWindow;
046:
047:            public DbObjectSourcePanel(MainWindow parent, Reloadable reloader) {
048:                parentWindow = parent;
049:                if (reloader != null) {
050:                    reloadSource = new ReloadAction(reloader);
051:                    reloadSource.setEnabled(false);
052:                }
053:
054:                this .sourceEditor = EditorPanel.createSqlEditor();
055:                this .sourceEditor.showFindOnPopupMenu();
056:                this .sourceEditor.setEditable(false);
057:                this .setLayout(new BorderLayout());
058:                WbToolbar toolbar = new WbToolbar();
059:
060:                if (reloadSource != null) {
061:                    toolbar.add(reloadSource);
062:                    reloadSource.addToInputMap(sourceEditor);
063:                }
064:
065:                this .add(this .sourceEditor, BorderLayout.CENTER);
066:                if (reloadSource != null) {
067:                    this .add(toolbar, BorderLayout.NORTH);
068:                }
069:                if (parentWindow != null) {
070:                    editButton = new DropDownButton("Edit in");
071:                    selectTabMenu = new EditorTabSelectMenu(this , ResourceMgr
072:                            .getString("LblEditScriptSource"),
073:                            "LblEditInNewTab", "LblEditInTab", parent);
074:                    editButton.setDropDownMenu(selectTabMenu.getPopupMenu());
075:                    toolbar.add(editButton);
076:                }
077:                if (Settings.getInstance().showFocusInDbExplorer()) {
078:                    new FocusIndicator(sourceEditor, sourceEditor);
079:                }
080:            }
081:
082:            public void actionPerformed(ActionEvent e) {
083:                String command = e.getActionCommand();
084:
085:                if (command.startsWith(EditorTabSelectMenu.PANEL_CMD_PREFIX)
086:                        && this .parentWindow != null) {
087:                    try {
088:                        final int panelIndex = Integer.parseInt(command
089:                                .substring(EditorTabSelectMenu.PANEL_CMD_PREFIX
090:                                        .length()));
091:
092:                        // Allow the selection change to finish so that
093:                        // we have the correct table name in the instance variables
094:                        EventQueue.invokeLater(new Runnable() {
095:                            public void run() {
096:                                editText(panelIndex, false);
097:                            }
098:                        });
099:                    } catch (Exception ex) {
100:                        LogMgr.logError("TableListPanel().actionPerformed()",
101:                                "Error when accessing editor tab", ex);
102:                    }
103:                }
104:            }
105:
106:            private void editText(final int panelIndex, final boolean appendText) {
107:                if (this .parentWindow != null) {
108:                    PanelContentSender sender = new PanelContentSender(
109:                            this .parentWindow);
110:                    sender.sendContent(getText(), panelIndex, appendText);
111:                }
112:            }
113:
114:            public void setPlainText(final String sql) {
115:                setEditorText(sql, false);
116:            }
117:
118:            /**
119:             * Set the SQL source. If the text contains an error message
120:             * indicating that the source is not available (as returned by DbMetadata
121:             * if the SQL Queries have not been configured for e.g. stored procedures)
122:             * syntax highlighting will be disabled.
123:             */
124:            public void setText(final String sql) {
125:                boolean hasText = !StringUtil.isEmptyString(sql);
126:                if (reloadSource != null)
127:                    reloadSource.setEnabled(hasText);
128:
129:                if (editButton != null)
130:                    editButton.setEnabled(hasText);
131:                if (hasText
132:                        && sql
133:                                .startsWith(SourceStatementsHelp.VIEW_ERROR_START)
134:                        || sql
135:                                .startsWith(SourceStatementsHelp.PROC_ERROR_START)
136:                        || sql.startsWith(ResourceMgr
137:                                .getString("MsgSynonymSourceNotImplemented"))) {
138:                    setEditorText(sql, false);
139:                } else {
140:                    setEditorText(sql, true);
141:                }
142:            }
143:
144:            private void setEditorText(final String text,
145:                    final boolean enableHighlight) {
146:                if (enableHighlight) {
147:                    sourceEditor.enableSqlHighlight();
148:                } else {
149:                    sourceEditor.disableSqlHighlight();
150:                }
151:
152:                WbSwingUtilities.invoke(new Runnable() {
153:                    public void run() {
154:                        sourceEditor.setText(text == null ? "" : text);
155:                    }
156:                });
157:
158:            }
159:
160:            public String getText() {
161:                return sourceEditor.getText();
162:            }
163:
164:            public void requestFocus() {
165:                this .sourceEditor.requestFocus();
166:            }
167:
168:            public boolean requestFocusInWindow() {
169:                return this .sourceEditor.requestFocusInWindow();
170:            }
171:
172:            public void setCaretPosition(int pos, boolean selectLine) {
173:                sourceEditor.setCaretPosition(pos);
174:                if (selectLine) {
175:                    int line = sourceEditor.getCaretLine();
176:                    int length = sourceEditor.getLineLength(line);
177:                    int lineStart = sourceEditor.getLineStartOffset(line);
178:                    if (lineStart > 0 && length > 0) {
179:                        sourceEditor.select(lineStart, lineStart + length);
180:                    }
181:                }
182:            }
183:
184:            public void scrollToCaret() {
185:                sourceEditor.scrollToCaret();
186:            }
187:
188:            public void setDatabaseConnection(WbConnection con) {
189:                sourceEditor.setDatabaseConnection(con);
190:            }
191:
192:            public void setEditable(boolean flag) {
193:                sourceEditor.setEditable(flag);
194:            }
195:
196:            public void reset() {
197:                this .setText("");
198:            }
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.