Source Code Cross Referenced for AddNewRecordWindow.java in  » Database-Client » DBBrowser » org » dbbrowser » ui » 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 » DBBrowser » org.dbbrowser.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.dbbrowser.ui;
002:
003:        import infrastructure.internationalization.InternationalizationManager;
004:        import infrastructure.logging.Log;
005:        import infrastructure.propertymanager.PropertyManager;
006:        import java.awt.*;
007:        import java.awt.event.ActionEvent;
008:        import java.awt.event.ActionListener;
009:        import java.util.*;
010:        import java.util.List;
011:        import javax.swing.*;
012:        import org.dbbrowser.db.engine.exception.DBEngineException;
013:        import org.dbbrowser.db.engine.model.ColumnInfo;
014:        import org.dbbrowser.db.engine.model.DBRow;
015:        import org.dbbrowser.db.engine.model.DBTable;
016:        import org.dbbrowser.db.engine.model.DBTableCell;
017:        import org.dbbrowser.ui.panel.ButtonsPanel;
018:        import org.dbbrowser.ui.widget.Button;
019:        import org.dbbrowser.ui.helper.ColumnInfoComparator;
020:
021:        public class AddNewRecordWindow implements  ActionListener {
022:            private static final long serialVersionUID = UIControllerForQueries.version;
023:
024:            private static final String TITLE = InternationalizationManager
025:                    .getInstance().getMessage("dbbrowser-ui",
026:                            "dbbrowser-ui-dbbrowser-window-title-label", null);;
027:
028:            private String ADD_NEW_RECORD_BUTTON_LABEL = InternationalizationManager
029:                    .getInstance()
030:                    .getMessage(
031:                            "dbbrowser-ui",
032:                            "dbbrowser-ui-dbbrowser-browser-add-new-record-window-add-record-button-label",
033:                            null);
034:            private static final String COMMIT_BUTTON_LABEL = InternationalizationManager
035:                    .getInstance()
036:                    .getMessage(
037:                            "dbbrowser-ui",
038:                            "dbbrowser-ui-dbbrowser-sql-tab-commit-button-label",
039:                            null);
040:            private static final String ROLLBACK_BUTTON_LABEL = InternationalizationManager
041:                    .getInstance()
042:                    .getMessage(
043:                            "dbbrowser-ui",
044:                            "dbbrowser-ui-dbbrowser-sql-tab-rollback-button-label",
045:                            null);
046:
047:            private static final String ADD_NEW_RECORD_ICON_FILENAME = PropertyManager
048:                    .getInstance()
049:                    .getProperty(
050:                            "dbbrowser-ui-dbbrowser-window-add-new-record-icon");
051:            private static final String COMMIT_BUTTON_ICON_FILENAME = PropertyManager
052:                    .getInstance()
053:                    .getProperty(
054:                            "dbbrowser-ui-dbbrowser-window-sql-tab-commit-button-icon");
055:            private static final String ROLLBACK_BUTTON_ICON_FILENAME = PropertyManager
056:                    .getInstance()
057:                    .getProperty(
058:                            "dbbrowser-ui-dbbrowser-window-sql-tab-rollback-button-icon");
059:
060:            private JPanel mainPanel = new JPanel();
061:            private JDialog dialog = null;
062:            private UIControllerForUpdates uiControllerForUpdates = null;
063:            private DBTable dbTable = null;
064:            private JPanel panelForData = new JPanel();
065:            private JPanel panelForScrollPane = new JPanel();
066:            private Map mapOfTextFieldToColumnInfos = new HashMap();
067:
068:            public AddNewRecordWindow(
069:                    UIControllerForUpdates uiControllerForUpdates,
070:                    DBTable dbTable) {
071:                this .uiControllerForUpdates = uiControllerForUpdates;
072:                this .dbTable = dbTable;
073:                initialize();
074:            }
075:
076:            private void initialize() {
077:                //Setup the dialog
078:                this .dialog = new JDialog();
079:                this .dialog.setTitle(TITLE);
080:                this .dialog.setModal(true);
081:
082:                //Setup the main panel
083:                this .panelForScrollPane.setLayout(new BoxLayout(
084:                        this .panelForScrollPane, BoxLayout.PAGE_AXIS));
085:                this .panelForScrollPane.setBorder(BorderFactory
086:                        .createTitledBorder(this .dbTable.getTableName()));
087:                this .mainPanel.setLayout(new BoxLayout(this .mainPanel,
088:                        BoxLayout.PAGE_AXIS));
089:                JScrollPane pane = new JScrollPane(this .panelForData);
090:                this .panelForScrollPane.add(pane);
091:                this .mainPanel.add(this .panelForScrollPane);
092:
093:                //Setup the frame
094:                this .dialog.setSize(700, 500);
095:                this .dialog.setLocationRelativeTo(null);
096:                this .dialog.getContentPane().add(this .mainPanel);
097:
098:                //Get the list of column infos
099:                List listOfColumnInfos = this .dbTable.getListOfColumnInfos();
100:
101:                //Sort the list of DBTable Cells
102:                Collections.sort(listOfColumnInfos, new ColumnInfoComparator());
103:
104:                //Iterate through the list of table cells
105:                Iterator i = listOfColumnInfos.iterator();
106:                while (i.hasNext()) {
107:                    ColumnInfo columnInfo = (ColumnInfo) i.next();
108:                    String labelText = columnInfo.getColumnName();
109:                    JTextField textFieldForData = new JTextField(20);
110:
111:                    //if it is not editable, disable it
112:                    if (!columnInfo.isEditable().booleanValue()) {
113:                        textFieldForData.setEnabled(false);
114:                    }
115:
116:                    //if it is primary key, mark it as such
117:                    if (columnInfo.isPrimaryKeyColumn().booleanValue()) {
118:                        labelText = labelText + "(PK)";
119:                    }
120:
121:                    JLabel labelForData = new JLabel(labelText);
122:                    JLabel labelForDataType = null;
123:
124:                    if (ColumnInfo.COLUMN_TYPE_DATE.equals(columnInfo
125:                            .getColumnTypeName())
126:                            || ColumnInfo.COLUMN_TYPE_DATE_TIME
127:                                    .equals(columnInfo.getColumnTypeName())) {
128:                        labelForDataType = new JLabel(columnInfo
129:                                .getColumnTypeName()
130:                                + " - "
131:                                + columnInfo.getNullableNature()
132:                                + " - " + DBTableCell.DATE_FORMAT_STRING);
133:                    } else {
134:                        labelForDataType = new JLabel(columnInfo
135:                                .getColumnTypeName()
136:                                + " - " + columnInfo.getNullableNature());
137:                    }
138:
139:                    //Add to map
140:                    this .mapOfTextFieldToColumnInfos.put(textFieldForData,
141:                            columnInfo);
142:
143:                    //Add the label to the panel for labels
144:                    this .panelForData.add(labelForData);
145:                    this .panelForData.add(labelForDataType);
146:                    this .panelForData.add(textFieldForData);
147:                }
148:
149:                //Set the layout on the panel
150:                this .panelForData.setLayout(new GridLayout(listOfColumnInfos
151:                        .size(), 3));
152:
153:                //Setup the panel for the add new record button
154:                List listOfButtonsInAddNewRecordPanel = new ArrayList();
155:                Button addNewRecordButton = new Button(
156:                        ADD_NEW_RECORD_BUTTON_LABEL, this ,
157:                        ADD_NEW_RECORD_BUTTON_LABEL, new ImageIcon(
158:                                ADD_NEW_RECORD_ICON_FILENAME), Boolean.TRUE);
159:                listOfButtonsInAddNewRecordPanel.add(addNewRecordButton);
160:                Button commitButton = new Button(COMMIT_BUTTON_LABEL, this ,
161:                        COMMIT_BUTTON_LABEL, new ImageIcon(
162:                                COMMIT_BUTTON_ICON_FILENAME), Boolean.TRUE);
163:                listOfButtonsInAddNewRecordPanel.add(commitButton);
164:                Button rollbackButton = new Button(ROLLBACK_BUTTON_LABEL, this ,
165:                        ROLLBACK_BUTTON_LABEL, new ImageIcon(
166:                                ROLLBACK_BUTTON_ICON_FILENAME), Boolean.TRUE);
167:                listOfButtonsInAddNewRecordPanel.add(rollbackButton);
168:
169:                ButtonsPanel addNewRecordButtonPanel = new ButtonsPanel(
170:                        listOfButtonsInAddNewRecordPanel);
171:
172:                //If autocommit is on, disable all buttons
173:                String autoCommitFlag = PropertyManager.getInstance()
174:                        .getProperty("dbbrowser-auto-commit");
175:                if ("true".equals(autoCommitFlag)) {
176:                    //Disable the commit and rollback buttons
177:                    addNewRecordButtonPanel.enableButton(COMMIT_BUTTON_LABEL,
178:                            Boolean.FALSE);
179:                    addNewRecordButtonPanel.enableButton(ROLLBACK_BUTTON_LABEL,
180:                            Boolean.FALSE);
181:                }
182:
183:                //Add the panel to the main panel
184:                this .mainPanel.add(addNewRecordButtonPanel);
185:            }
186:
187:            public void show() {
188:                this .dialog.setVisible(true);
189:            }
190:
191:            public void actionPerformed(ActionEvent e) {
192:                if (ADD_NEW_RECORD_BUTTON_LABEL.equals(e.getActionCommand())) {
193:                    //Get all the text fields
194:                    Iterator i = this .mapOfTextFieldToColumnInfos.keySet()
195:                            .iterator();
196:                    List listOfNewValues = new ArrayList();
197:
198:                    while (i.hasNext()) {
199:                        JTextField textField = (JTextField) i.next();
200:
201:                        //Get the new value typed by the user
202:                        String valueToAdd = textField.getText();
203:
204:                        //If the user has typed a value, then build a table cell
205:                        if ((valueToAdd != null) && (!valueToAdd.equals(""))) {
206:                            //Get the column info from the map
207:                            ColumnInfo ci = (ColumnInfo) this .mapOfTextFieldToColumnInfos
208:                                    .get(textField);
209:                            //Set the new value
210:                            DBTableCell newTableCell = new DBTableCell(ci,
211:                                    valueToAdd, Boolean.TRUE);
212:                            listOfNewValues.add(newTableCell);
213:                        }
214:                    }
215:
216:                    //Build the dbrow which needs to be updated
217:                    DBRow updatedDBRow = new DBRow(listOfNewValues);
218:
219:                    //Add the DBRow
220:                    try {
221:                        if (this .uiControllerForUpdates != null) {
222:                            //Set the auto commit flag
223:                            String autoCommitFlag = PropertyManager
224:                                    .getInstance().getProperty(
225:                                            "dbbrowser-auto-commit");
226:                            if ("false".equals(autoCommitFlag)) {
227:                                this .uiControllerForUpdates
228:                                        .setAutoCommit(false);
229:                            }
230:
231:                            //Add the row
232:                            this .uiControllerForUpdates.addNewRow(this .dbTable
233:                                    .getSchemaName(), this .dbTable
234:                                    .getTableName(), updatedDBRow);
235:                        }
236:                    } catch (DBEngineException exc) {
237:                        Log.getInstance().fatalMessage(exc.getMessage(),
238:                                AddNewRecordWindow.class.getName());
239:                        String sqlFailedLabel = InternationalizationManager
240:                                .getInstance()
241:                                .getMessage(
242:                                        "dbbrowser-ui",
243:                                        "dbbrowser-ui-dbbrowser-window-sql-failed",
244:                                        null);
245:                        JOptionPane.showMessageDialog(null, sqlFailedLabel
246:                                + " - " + exc.getMessage(), TITLE,
247:                                JOptionPane.ERROR_MESSAGE);
248:                    }
249:                }
250:
251:                if (COMMIT_BUTTON_LABEL.equals(e.getActionCommand())) {
252:                    try {
253:                        this .uiControllerForUpdates.commit();
254:                        this .dialog.pack();
255:                        this .dialog.dispose();
256:                        this .dialog = null;
257:                    } catch (DBEngineException exc) {
258:                        Log.getInstance().fatalMessage(exc.getMessage(),
259:                                AddNewRecordWindow.class.getName());
260:                        String sqlFailedLabel = InternationalizationManager
261:                                .getInstance()
262:                                .getMessage(
263:                                        "dbbrowser-ui",
264:                                        "dbbrowser-ui-dbbrowser-window-sql-failed",
265:                                        null);
266:                        JOptionPane.showMessageDialog(null, sqlFailedLabel
267:                                + " - " + exc.getMessage(), TITLE,
268:                                JOptionPane.ERROR_MESSAGE);
269:                    }
270:                }
271:
272:                if (ROLLBACK_BUTTON_LABEL.equals(e.getActionCommand())) {
273:                    try {
274:                        this .uiControllerForUpdates.rollback();
275:                        this .dialog.pack();
276:                        this .dialog.dispose();
277:                        this .dialog = null;
278:                    } catch (DBEngineException exc) {
279:                        Log.getInstance().fatalMessage(exc.getMessage(),
280:                                AddNewRecordWindow.class.getName());
281:                        String sqlFailedLabel = InternationalizationManager
282:                                .getInstance()
283:                                .getMessage(
284:                                        "dbbrowser-ui",
285:                                        "dbbrowser-ui-dbbrowser-window-sql-failed",
286:                                        null);
287:                        JOptionPane.showMessageDialog(null, sqlFailedLabel
288:                                + " - " + exc.getMessage(), TITLE,
289:                                JOptionPane.ERROR_MESSAGE);
290:                    }
291:                }
292:
293:                //Update the main panel
294:                SwingUtilities.updateComponentTreeUI(this.mainPanel);
295:            }
296:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.