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


001:        package org.jsqltool.gui.tableplugins;
002:
003:        import javax.swing.*;
004:        import java.awt.*;
005:        import javax.swing.event.*;
006:        import javax.swing.table.*;
007:        import java.awt.event.*;
008:        import org.jsqltool.conn.DbConnectionUtil;
009:        import org.jsqltool.model.CustomTableModel;
010:        import java.sql.*;
011:        import java.util.*;
012:        import org.jsqltool.gui.*;
013:        import org.jsqltool.*;
014:        import org.jsqltool.gui.tablepanel.*;
015:        import org.jsqltool.gui.panel.*;
016:        import org.jsqltool.utils.Options;
017:
018:        /**
019:         * <p>Title: JSqlTool Project</p>
020:         * <p>Description: Panel that shows table columns.
021:         * </p>
022:         * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
023:         *
024:         * <p> This file is part of JSqlTool project.
025:         * This library is free software; you can redistribute it and/or
026:         * modify it under the terms of the (LGPL) Lesser General Public
027:         * License as published by the Free Software Foundation;
028:         *
029:         *                GNU LESSER GENERAL PUBLIC LICENSE
030:         *                 Version 2.1, February 1999
031:         *
032:         * This library is distributed in the hope that it will be useful,
033:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
034:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
035:         * Library General Public License for more details.
036:         *
037:         * You should have received a copy of the GNU Library General Public
038:         * License along with this library; if not, write to the Free
039:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
040:         *
041:         *       The author may be contacted at:
042:         *           maurocarniel@tin.it</p>
043:         *
044:         * @author Mauro Carniel
045:         * @version 1.0
046:         */
047:        public class ColumnsTablePanel extends JPanel implements  TablePlugin {
048:
049:            private String tableName = null;
050:            private Hashtable pk = null;
051:            JPanel buttonsPanel = new JPanel();
052:            FlowLayout flowLayout1 = new FlowLayout();
053:            DataPanel dataPanel = null;
054:            BorderLayout borderLayout1 = new BorderLayout();
055:            private DbConnectionUtil dbConnUtil = null;
056:            private JFrame parent = null;
057:            GridBagLayout gridBagLayout1 = new GridBagLayout();
058:
059:            public ColumnsTablePanel() {
060:                try {
061:                    jbInit();
062:                } catch (Exception e) {
063:                    e.printStackTrace();
064:                }
065:            }
066:
067:            private void jbInit() throws Exception {
068:                this .setLayout(gridBagLayout1);
069:                flowLayout1.setVgap(0);
070:                this .add(buttonsPanel, new GridBagConstraints(0, 0, 1, 1, 1.0,
071:                        0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
072:                        new Insets(5, 5, 0, 0), 0, 0));
073:                buttonsPanel.setLayout(flowLayout1);
074:                flowLayout1.setAlignment(FlowLayout.LEFT);
075:                flowLayout1.setHgap(0);
076:            }
077:
078:            public final void resetPanel() {
079:                dataPanel.resetPanel();
080:            }
081:
082:            /**
083:             * @return panel position inside the JTabbedPane related to the table detail
084:             */
085:            public int getTabbedPosition() {
086:                return 0;
087:            }
088:
089:            /**
090:             * @return folder name of the plugin panel, inside the JTabbedPane related to the table detail
091:             */
092:            public String getTabbedName() {
093:                return Options.getInstance().getResource("columns");
094:            }
095:
096:            /**
097:             * This method is called from the table detail to inizialize the plugin panel
098:             */
099:            public void initPanel(MainFrame parent, DbConnectionUtil dbConnUtil) {
100:                this .parent = parent;
101:                this .dbConnUtil = dbConnUtil;
102:                this .dataPanel = new DataPanel(dbConnUtil,
103:                        new TableModelListener() {
104:                            public void tableChanged(TableModelEvent e) {
105:                            }
106:                        });
107:                this .dataPanel.getTable().setAutoResizeMode(
108:                        JTable.AUTO_RESIZE_OFF);
109:                this .add(dataPanel, new GridBagConstraints(0, 1, 1, 1, 1.0,
110:                        1.0, GridBagConstraints.CENTER,
111:                        GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
112:                init();
113:            }
114:
115:            private void init() {
116:                // pop-up menu creation...
117:                final JPopupMenu tableMenu = new JPopupMenu();
118:                JMenuItem addColMenu = new JMenuItem(Options.getInstance()
119:                        .getResource("add column"));
120:                JMenuItem dropColMenu = new JMenuItem(Options.getInstance()
121:                        .getResource("drop column"));
122:                JMenuItem dropTableMenu = new JMenuItem(Options.getInstance()
123:                        .getResource("drop table"));
124:                addColMenu.addActionListener(new ActionListener() {
125:                    public void actionPerformed(ActionEvent e) {
126:                        new AddColumnDialog(parent, tableName, dbConnUtil);
127:                        updateContent();
128:                    }
129:                });
130:
131:                dropColMenu.addActionListener(new ActionListener() {
132:                    public void actionPerformed(ActionEvent e) {
133:                        if (dataPanel.getTable().getSelectedRow() != -1)
134:                            try {
135:                                PreparedStatement pstmt = dbConnUtil
136:                                        .getConn()
137:                                        .prepareStatement(
138:                                                "ALTER TABLE "
139:                                                        + tableName
140:                                                        + " DROP COLUMN "
141:                                                        + dataPanel
142:                                                                .getTable()
143:                                                                .getModel()
144:                                                                .getValueAt(
145:                                                                        dataPanel
146:                                                                                .getTable()
147:                                                                                .getSelectedRow(),
148:                                                                        0));
149:                                pstmt.execute();
150:                                pstmt.close();
151:                                updateContent();
152:                            } catch (Exception ex) {
153:                                JOptionPane.showMessageDialog(parent, Options
154:                                        .getInstance().getResource(
155:                                                "error while dropping table:")
156:                                        + "\n" + ex.getMessage(), Options
157:                                        .getInstance().getResource("error"),
158:                                        JOptionPane.ERROR_MESSAGE);
159:                            }
160:
161:                    }
162:                });
163:
164:                dropTableMenu.addActionListener(new ActionListener() {
165:                    public void actionPerformed(ActionEvent e) {
166:                        if (JOptionPane.showConfirmDialog(parent, Options
167:                                .getInstance().getResource(
168:                                        "confirm drop table?"), Options
169:                                .getInstance().getResource("attention"),
170:                                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
171:
172:                            try {
173:                                PreparedStatement pstmt = dbConnUtil.getConn()
174:                                        .prepareStatement(
175:                                                "DROP TABLE " + tableName);
176:                                pstmt.execute();
177:                                pstmt.close();
178:                                tableName = null;
179:                                updateContent();
180:                            } catch (Exception ex) {
181:                                JOptionPane.showMessageDialog(parent, Options
182:                                        .getInstance().getResource(
183:                                                "error while dropping table:")
184:                                        + "\n" + ex.getMessage(), Options
185:                                        .getInstance().getResource("error"),
186:                                        JOptionPane.ERROR_MESSAGE);
187:                            }
188:
189:                        }
190:                    }
191:                });
192:
193:                tableMenu.add(addColMenu);
194:                tableMenu.add(dropColMenu);
195:                tableMenu.add(dropTableMenu);
196:
197:                dataPanel.getTable().addMouseListener(new MouseAdapter() {
198:                    public void mouseClicked(MouseEvent e) {
199:                        if (SwingUtilities.isRightMouseButton(e)) { // right mouse click
200:                            // show pop-up menu...
201:                            tableMenu
202:                                    .show(e.getComponent(), e.getX(), e.getY());
203:                        }
204:                    }
205:                });
206:            }
207:
208:            /**
209:             * This method is called from the table detail to update the plugin panel content.
210:             * @param tableName table name (edventualy including catalog name) that table plugin have to show
211:             */
212:            public final void updateContent() {
213:                if (tableName == null || tableName.equals("")) {
214:                    dataPanel.getTable().setModel(
215:                            new DefaultTableModel(
216:                                    new String[] {
217:                                            Options.getInstance().getResource(
218:                                                    "column"),
219:                                            Options.getInstance().getResource(
220:                                                    "data type"),
221:                                            Options.getInstance().getResource(
222:                                                    "pK"),
223:                                            Options.getInstance().getResource(
224:                                                    "null?") }, 0));
225:                } else {
226:                    dataPanel.getTable().setModel(
227:                            dbConnUtil.getTableColumns(tableName));
228:                }
229:                dataPanel.getTable().getColumnModel().getColumn(0)
230:                        .setPreferredWidth(200);
231:                dataPanel.getTable().getColumnModel().getColumn(1)
232:                        .setPreferredWidth(140);
233:                dataPanel.getTable().getColumnModel().getColumn(2)
234:                        .setPreferredWidth(50);
235:                dataPanel.getTable().getColumnModel().getColumn(3)
236:                        .setPreferredWidth(50);
237:                dataPanel.getTable().getColumnModel().getColumn(4)
238:                        .setPreferredWidth(50);
239:                //    dataPanel.getTable().setColumnSelectionAllowed(false);
240:                //    dataPanel.getTable().setRowSelectionAllowed(false);
241:            }
242:
243:            /**
244:             * This method is called from the table detail to set entity name.
245:             * @param tableName table name (edventualy including catalog name) that table plugin have to show
246:             */
247:            public final void setTableName(String tableName) {
248:                this .tableName = tableName;
249:            }
250:
251:            /**
252:             * @return entity name
253:             */
254:            public String getTableName() {
255:                return tableName;
256:            }
257:
258:            /**
259:             * @return infos about the author of the plugin panel; "" or null does not report any info about the plugin panel
260:             */
261:            public String getAuthor() {
262:                return "";
263:            }
264:
265:            /**
266:             * @return plugin panel version
267:             */
268:            public String getVersion() {
269:                return "1.0";
270:            }
271:
272:            /**
273:             * @return plugin panel name, reported into the about window
274:             */
275:            public String getName() {
276:                return Options.getInstance()
277:                        .getResource("table columns plugin");
278:            }
279:
280:            public boolean equals(Object o) {
281:                return (o instanceof  TablePlugin && ((TablePlugin) o).getName()
282:                        .equals(getName()));
283:            }
284:
285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.