Source Code Cross Referenced for ParametersDialog.java in  » Database-Client » JSqlTool » org » jsqltool » gui » 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 » JSqlTool » org.jsqltool.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jsqltool.gui;
002:
003:        import javax.swing.*;
004:        import java.awt.*;
005:        import java.awt.event.*;
006:        import java.util.*;
007:        import java.math.BigDecimal;
008:        import org.jsqltool.utils.Options;
009:        import org.jsqltool.utils.ImageLoader;
010:        import org.jsqltool.gui.graphics.CalendarCombo;
011:
012:        /**
013:         * <p>Title: JSqlTool Project</p>
014:         * <p>Description: Dialog used by SQLFrame to find out sql parameters and prompt user to set them.
015:         * </p>
016:         * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
017:         *
018:         * <p> This file is part of JSqlTool project.
019:         * This library is free software; you can redistribute it and/or
020:         * modify it under the terms of the (LGPL) Lesser General Public
021:         * License as published by the Free Software Foundation;
022:         *
023:         *                GNU LESSER GENERAL PUBLIC LICENSE
024:         *                 Version 2.1, February 1999
025:         *
026:         * This library is distributed in the hope that it will be useful,
027:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
028:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
029:         * Library General Public License for more details.
030:         *
031:         * You should have received a copy of the GNU Library General Public
032:         * License along with this library; if not, write to the Free
033:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
034:         *
035:         *       The author may be contacted at:
036:         *           maurocarniel@tin.it</p>
037:         *
038:         * @author Mauro Carniel
039:         * @version 1.0
040:         */
041:        public class ParametersDialog extends JDialog {
042:
043:            JPanel mainPanel = new JPanel();
044:            JPanel buttonsPanel = new JPanel();
045:            BorderLayout borderLayout1 = new BorderLayout();
046:            JButton okButton = new JButton();
047:            JLabel typeLabel = new JLabel();
048:            JComboBox typeComboBox = new JComboBox();
049:            JLabel valueLabel = new JLabel();
050:            GridBagLayout gridBagLayout1 = new GridBagLayout();
051:
052:            private static final String TEXT = Options.getInstance()
053:                    .getResource("text");
054:            private static final String NUM = Options.getInstance()
055:                    .getResource("numeric");
056:            private static final String DATE = Options.getInstance()
057:                    .getResource("date");
058:
059:            private CalendarCombo date = new CalendarCombo();
060:            private JTextField text = new JTextField();
061:            private JTextField num = new JTextField();
062:
063:            /** current input control */
064:            private Component currentControl = null;
065:
066:            /** current value */
067:            private Object value = null;
068:
069:            /** position of parameter */
070:            private int pos = -1;
071:
072:            /** values used by query */
073:            private Vector values = null;
074:
075:            /** sql to analyze */
076:            private String sql = null;
077:
078:            /** parent frame */
079:            private SQLFrame frame = null;
080:
081:            /** MDI frame */
082:            private JFrame parent = null;
083:
084:            /**
085:             * Constructor called by SQLFrame.
086:             */
087:            public ParametersDialog(JFrame parent, SQLFrame frame, String sql,
088:                    Vector values) {
089:                super (parent, Options.getInstance().getResource("variable"),
090:                        false);
091:                this .parent = parent;
092:                this .frame = frame;
093:                this .sql = sql;
094:                this .values = values;
095:                try {
096:                    init();
097:                    jbInit();
098:                    setSize(300, 170);
099:                    setLocation(parent.getWidth() / 2 - 200,
100:                            parent.getHeight() / 2 - 70);
101:
102:                    // find thr first occurrence of ?
103:                    findNextVar();
104:                } catch (Exception e) {
105:                    e.printStackTrace();
106:                }
107:            }
108:
109:            /**
110:             * Find the next occurrence of ? in sql.
111:             * If no other ? are found, then execute the sql, i.e. execute the method executeSQLWithValues.
112:             */
113:            private void findNextVar() {
114:                if (currentControl != null)
115:                    mainPanel.remove(currentControl);
116:                currentControl = null;
117:                typeComboBox.setSelectedIndex(-1);
118:                while ((pos = sql.indexOf("?", pos + 1)) != -1) {
119:                    if (isParameter(sql, pos)) {
120:                        break;
121:                    }
122:                }
123:                if (pos != -1)
124:                    setVisible(true);
125:                else
126:                    frame.executeSQLWithValues(sql, values);
127:            }
128:
129:            public ParametersDialog() {
130:                try {
131:                    jbInit();
132:                } catch (Exception e) {
133:                    e.printStackTrace();
134:                }
135:            }
136:
137:            /**
138:             * @param sql sql which contains patterns of type "=?" or ">?" or "<?"
139:             * @param pos position inside sql of ? character
140:             * @return <code>true</code> if no space character at the left of pos is "=" or "<" or ">"
141:             */
142:            private boolean isParameter(String sql, int pos) {
143:                if (pos == 0)
144:                    return false;
145:                for (int i = pos - 1; i >= 0; i--)
146:                    if (sql.charAt(i) == '=' || sql.charAt(i) == '<'
147:                            || sql.charAt(i) == '>')
148:                        return true;
149:                    else if (sql.charAt(i) != ' ')
150:                        return false;
151:                return false;
152:            }
153:
154:            /**
155:             * Initialize type combo.
156:             */
157:            private void init() {
158:                typeComboBox.addItem(TEXT);
159:                typeComboBox.addItem(NUM);
160:                typeComboBox.addItem(DATE);
161:                typeComboBox.setSelectedIndex(-1);
162:
163:                text.addKeyListener(new KeyAdapter() {
164:                    public void keyReleased(KeyEvent e) {
165:                        if (e.getKeyChar() == '\n')
166:                            okButton_actionPerformed(null);
167:                    }
168:                });
169:            }
170:
171:            private void jbInit() throws Exception {
172:                this .getContentPane().setLayout(borderLayout1);
173:                mainPanel.setBorder(BorderFactory.createEtchedBorder());
174:                mainPanel.setLayout(gridBagLayout1);
175:                buttonsPanel.setBorder(BorderFactory.createEtchedBorder());
176:                okButton.setText(Options.getInstance().getResource(
177:                        "okbutton.text"));
178:                okButton.setMnemonic(Options.getInstance().getResource(
179:                        "okbutton.mnemonic").charAt(0));
180:                okButton
181:                        .addActionListener(new ParametersDialog_okButton_actionAdapter(
182:                                this ));
183:                typeLabel.setText(Options.getInstance().getResource("type"));
184:                typeComboBox
185:                        .addItemListener(new ParametersDialog_typeComboBox_itemAdapter(
186:                                this ));
187:                valueLabel.setText(Options.getInstance().getResource("value"));
188:                this .getContentPane().add(mainPanel, BorderLayout.CENTER);
189:                this .getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
190:                buttonsPanel.add(okButton, null);
191:                mainPanel.add(typeLabel, new GridBagConstraints(0, 0, 1, 1,
192:                        0.0, 0.0, GridBagConstraints.NORTHWEST,
193:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
194:                mainPanel.add(typeComboBox, new GridBagConstraints(1, 0, 1, 1,
195:                        1.0, 0.0, GridBagConstraints.NORTHWEST,
196:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
197:                        0, 0));
198:                mainPanel.add(valueLabel, new GridBagConstraints(0, 1, 1, 1,
199:                        0.0, 1.0, GridBagConstraints.NORTHWEST,
200:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
201:            }
202:
203:            void okButton_actionPerformed(ActionEvent e) {
204:                value = null;
205:                if (TEXT.equals(typeComboBox.getSelectedItem())) {
206:                    value = text.getText();
207:                    if (value.equals(""))
208:                        value = null;
209:                } else if (NUM.equals(typeComboBox.getSelectedItem())) {
210:                    value = new BigDecimal(num.getText());
211:                } else if (DATE.equals(typeComboBox.getSelectedItem())) {
212:                    value = date.getDate();
213:                    if (value != null && value instanceof  java.util.Date)
214:                        value = new java.sql.Date(((java.util.Date) value)
215:                                .getTime());
216:                }
217:                if (value == null) {
218:                    JOptionPane.showMessageDialog(parent, Options.getInstance()
219:                            .getResource("value is required"), Options
220:                            .getInstance().getResource("attention"),
221:                            JOptionPane.WARNING_MESSAGE);
222:                    return;
223:                } else {
224:                    values.add(value);
225:                    text.setText(null);
226:                    num.setText(null);
227:                    date.setDate(null);
228:                    setVisible(false);
229:                    typeComboBox.setSelectedIndex(-1);
230:                    findNextVar();
231:                }
232:            }
233:
234:            void typeComboBox_itemStateChanged(ItemEvent e) {
235:                if (e.getStateChange() == e.SELECTED) {
236:                    if (currentControl != null)
237:                        mainPanel.remove(currentControl);
238:
239:                    if (typeComboBox.getSelectedItem().equals(TEXT)) {
240:                        currentControl = text;
241:                    } else if (typeComboBox.getSelectedItem().equals(NUM)) {
242:                        currentControl = num;
243:                    } else if (typeComboBox.getSelectedItem().equals(DATE)) {
244:                        if (currentControl != null)
245:                            mainPanel.remove(currentControl);
246:                        currentControl = date;
247:                    }
248:
249:                    if (currentControl != null) {
250:                        mainPanel.add(currentControl, new GridBagConstraints(1,
251:                                1, 1, 1, 1.0, 0.0,
252:                                GridBagConstraints.NORTHWEST,
253:                                GridBagConstraints.HORIZONTAL, new Insets(5, 0,
254:                                        5, 5), 0, 0));
255:                        currentControl.requestFocus();
256:                    }
257:                    mainPanel.revalidate();
258:                    mainPanel.repaint();
259:                }
260:            }
261:
262:        }
263:
264:        class ParametersDialog_okButton_actionAdapter implements 
265:                java.awt.event.ActionListener {
266:            ParametersDialog adaptee;
267:
268:            ParametersDialog_okButton_actionAdapter(ParametersDialog adaptee) {
269:                this .adaptee = adaptee;
270:            }
271:
272:            public void actionPerformed(ActionEvent e) {
273:                adaptee.okButton_actionPerformed(e);
274:            }
275:        }
276:
277:        class ParametersDialog_typeComboBox_itemAdapter implements 
278:                java.awt.event.ItemListener {
279:            ParametersDialog adaptee;
280:
281:            ParametersDialog_typeComboBox_itemAdapter(ParametersDialog adaptee) {
282:                this .adaptee = adaptee;
283:            }
284:
285:            public void itemStateChanged(ItemEvent e) {
286:                adaptee.typeComboBox_itemStateChanged(e);
287:            }
288:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.