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


001:        package net.sourceforge.squirrel_sql.client.gui.db.aliasproperties;
002:
003:        import net.sourceforge.squirrel_sql.client.IApplication;
004:        import net.sourceforge.squirrel_sql.client.session.schemainfo.SchemaInfoCacheSerializer;
005:        import net.sourceforge.squirrel_sql.client.mainframe.action.ConnectToAliasCommand;
006:        import net.sourceforge.squirrel_sql.client.gui.db.SQLAlias;
007:        import net.sourceforge.squirrel_sql.client.gui.db.SQLAliasSchemaProperties;
008:        import net.sourceforge.squirrel_sql.client.gui.db.ConnectToAliasCallBack;
009:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
010:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
011:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
012:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
013:        import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
014:
015:        import javax.swing.*;
016:        import javax.swing.table.TableColumn;
017:        import javax.swing.table.TableColumnModel;
018:        import javax.swing.table.TableCellEditor;
019:        import java.awt.*;
020:        import java.awt.event.ActionListener;
021:        import java.awt.event.ActionEvent;
022:        import java.io.File;
023:
024:        public class SchemaPropertiesController implements 
025:                IAliasPropertiesPanelController {
026:            private static final StringManager s_stringMgr = StringManagerFactory
027:                    .getStringManager(SchemaPropertiesController.class);
028:
029:            private static final ILogger s_log = LoggerController
030:                    .createLogger(SchemaPropertiesController.class);
031:
032:            private SchemaPropertiesPanel _pnl;
033:
034:            private JComboBox _cboTables = new JComboBox();
035:            private JComboBox _cboView = new JComboBox();
036:            private JComboBox _cboFunction = new JComboBox();
037:            private Color _origTblColor;
038:            private SQLAlias _alias;
039:            private IApplication _app;
040:            private SchemaTableModel _schemaTableModel;
041:
042:            public SchemaPropertiesController(SQLAlias alias, IApplication app) {
043:                _alias = alias;
044:                _app = app;
045:                _pnl = new SchemaPropertiesPanel();
046:
047:                _schemaTableModel = new SchemaTableModel(alias
048:                        .getSchemaProperties().getSchemaDetails());
049:                _pnl.tblSchemas.setModel(_schemaTableModel);
050:
051:                TableColumnModel cm = _pnl.tblSchemas.getColumnModel();
052:
053:                TableColumn tc;
054:                tc = new TableColumn(SchemaTableModel.IX_SCHEMA_NAME);
055:                // i18n[SchemaPropertiesController.tableHeader.schema=Schema]
056:                tc
057:                        .setHeaderValue(s_stringMgr
058:                                .getString("SchemaPropertiesController.tableHeader.schema"));
059:                cm.addColumn(tc);
060:
061:                tc = new TableColumn(SchemaTableModel.IX_TABLE);
062:                // i18n[SchemaPropertiesController.tableHeader.tables=Tables]
063:                tc
064:                        .setHeaderValue(s_stringMgr
065:                                .getString("SchemaPropertiesController.tableHeader.tables"));
066:                tc.setCellEditor(new DefaultCellEditor(initCbo(_cboTables)));
067:                cm.addColumn(tc);
068:
069:                tc = new TableColumn(SchemaTableModel.IX_VIEW);
070:                // i18n[SchemaPropertiesController.tableHeader.views=Views]
071:                tc
072:                        .setHeaderValue(s_stringMgr
073:                                .getString("SchemaPropertiesController.tableHeader.views"));
074:                tc.setCellEditor(new DefaultCellEditor(initCbo(_cboView)));
075:                cm.addColumn(tc);
076:
077:                tc = new TableColumn(SchemaTableModel.IX_PROCEDURE);
078:                // i18n[SchemaPropertiesController.tableHeader.procedures=Procedures]
079:                tc
080:                        .setHeaderValue(s_stringMgr
081:                                .getString("SchemaPropertiesController.tableHeader.procedures"));
082:                tc.setCellEditor(new DefaultCellEditor(initCbo(_cboFunction)));
083:                cm.addColumn(tc);
084:
085:                _pnl.radLoadAllAndCacheNone
086:                        .setSelected(alias.getSchemaProperties()
087:                                .getGlobalState() == SQLAliasSchemaProperties.GLOBAL_STATE_LOAD_ALL_CACHE_NONE);
088:                _pnl.radLoadAndCacheAll
089:                        .setSelected(alias.getSchemaProperties()
090:                                .getGlobalState() == SQLAliasSchemaProperties.GLOBAL_STATE_LOAD_AND_CACHE_ALL);
091:                _pnl.radSpecifySchemas
092:                        .setSelected(alias.getSchemaProperties()
093:                                .getGlobalState() == SQLAliasSchemaProperties.GLOBAL_STATE_SPECIFY_SCHEMAS);
094:
095:                _pnl.chkCacheSchemaIndepndentMetaData.setSelected(alias
096:                        .getSchemaProperties()
097:                        .isCacheSchemaIndependentMetaData());
098:
099:                _pnl.cboSchemaTableUpdateWhat
100:                        .addItem(SchemaTableUpdateWhatItem.ALL);
101:                _pnl.cboSchemaTableUpdateWhat
102:                        .addItem(SchemaTableUpdateWhatItem.TABLES);
103:                _pnl.cboSchemaTableUpdateWhat
104:                        .addItem(SchemaTableUpdateWhatItem.VIEWS);
105:                _pnl.cboSchemaTableUpdateWhat
106:                        .addItem(SchemaTableUpdateWhatItem.PROCEDURES);
107:
108:                for (int i = 0; i < SchemaTableCboItem.items.length; i++) {
109:                    _pnl.cboSchemaTableUpdateTo
110:                            .addItem(SchemaTableCboItem.items[i]);
111:                }
112:
113:                _pnl.btnSchemaTableUpdateApply
114:                        .addActionListener(new ActionListener() {
115:                            public void actionPerformed(ActionEvent e) {
116:                                onSchemaTableUpdateApply();
117:                            }
118:                        });
119:
120:                updateEnabled();
121:
122:                _pnl.radLoadAllAndCacheNone
123:                        .addActionListener(new ActionListener() {
124:                            public void actionPerformed(ActionEvent e) {
125:                                updateEnabled();
126:                            }
127:                        });
128:                _pnl.radLoadAndCacheAll.addActionListener(new ActionListener() {
129:                    public void actionPerformed(ActionEvent e) {
130:                        updateEnabled();
131:                    }
132:                });
133:                _pnl.radSpecifySchemas.addActionListener(new ActionListener() {
134:                    public void actionPerformed(ActionEvent e) {
135:                        updateEnabled();
136:                    }
137:                });
138:
139:                _pnl.btnUpdateSchemas.addActionListener(new ActionListener() {
140:                    public void actionPerformed(ActionEvent e) {
141:                        onRefreshSchemaTable();
142:                    }
143:                });
144:
145:                _pnl.btnPrintCacheFileLocation
146:                        .addActionListener(new ActionListener() {
147:                            public void actionPerformed(ActionEvent e) {
148:                                onPrintCacheFileLocation();
149:                            }
150:                        });
151:
152:                _pnl.btnDeleteCache.addActionListener(new ActionListener() {
153:                    public void actionPerformed(ActionEvent e) {
154:                        onDeleteCache();
155:                    }
156:                });
157:
158:            }
159:
160:            private void onDeleteCache() {
161:                File schemaCacheFile = SchemaInfoCacheSerializer
162:                        .getSchemaCacheFile(_alias);
163:
164:                String aliasName = null == _alias.getName()
165:                        || 0 == _alias.getName().trim().length() ? "<unnamed>"
166:                        : _alias.getName();
167:
168:                if (schemaCacheFile.exists()) {
169:                    if (schemaCacheFile.delete()) {
170:                        // i18n[SchemaPropertiesController.cacheDeleted=Deleted {0}]
171:                        _app
172:                                .getMessageHandler()
173:                                .showMessage(
174:                                        s_stringMgr
175:                                                .getString(
176:                                                        "SchemaPropertiesController.cacheDeleted",
177:                                                        schemaCacheFile
178:                                                                .getPath()));
179:                    } else {
180:                        // i18n[SchemaPropertiesController.cacheDeleteFailed=Could not delete {0}]
181:                        _app
182:                                .getMessageHandler()
183:                                .showWarningMessage(
184:                                        s_stringMgr
185:                                                .getString(
186:                                                        "SchemaPropertiesController.cacheDeleteFailed",
187:                                                        schemaCacheFile
188:                                                                .getPath()));
189:                    }
190:
191:                } else {
192:                    // i18n[SchemaPropertiesController.cacheToDelNotExists=Cache file for Alias "{0}" does not exist. No file was deleted]
193:                    _app
194:                            .getMessageHandler()
195:                            .showWarningMessage(
196:                                    s_stringMgr
197:                                            .getString(
198:                                                    "SchemaPropertiesController.cacheToDelNotExists",
199:                                                    aliasName));
200:                }
201:
202:            }
203:
204:            private void onPrintCacheFileLocation() {
205:                File schemaCacheFile = SchemaInfoCacheSerializer
206:                        .getSchemaCacheFile(_alias);
207:
208:                String aliasName = null == _alias.getName()
209:                        || 0 == _alias.getName().trim().length() ? "<unnamed>"
210:                        : _alias.getName();
211:                String[] params = new String[] { aliasName,
212:                        schemaCacheFile.getPath() };
213:
214:                if (schemaCacheFile.exists()) {
215:                    // i18n[SchemaPropertiesController.cacheFilePath=Cache file path for Alias "{0}": {1}]
216:                    _app.getMessageHandler().showMessage(
217:                            s_stringMgr.getString(
218:                                    "SchemaPropertiesController.cacheFilePath",
219:                                    params));
220:                } else {
221:                    // i18n[SchemaPropertiesController.cacheFilePathNotExists=Cache file for Alias "{0}" does not exist. If it existed the path would be: {1}]
222:                    _app
223:                            .getMessageHandler()
224:                            .showMessage(
225:                                    s_stringMgr
226:                                            .getString(
227:                                                    "SchemaPropertiesController.cacheFilePathNotExists",
228:                                                    params));
229:                }
230:            }
231:
232:            private void onRefreshSchemaTable() {
233:                ConnectToAliasCallBack cb = new ConnectToAliasCallBack(_app,
234:                        _alias) {
235:                    public void connected(ISQLConnection conn) {
236:                        onConnected(conn);
237:                    }
238:                };
239:
240:                ConnectToAliasCommand cmd = new ConnectToAliasCommand(_app,
241:                        _alias, false, cb);
242:                cmd.execute();
243:            }
244:
245:            private void onSchemaTableUpdateApply() {
246:                TableCellEditor cellEditor = _pnl.tblSchemas.getCellEditor();
247:                if (null != cellEditor) {
248:                    cellEditor.stopCellEditing();
249:                }
250:
251:                SchemaTableUpdateWhatItem selWhatItem = (SchemaTableUpdateWhatItem) _pnl.cboSchemaTableUpdateWhat
252:                        .getSelectedItem();
253:
254:                SchemaTableCboItem selToItem = (SchemaTableCboItem) _pnl.cboSchemaTableUpdateTo
255:                        .getSelectedItem();
256:
257:                if (SchemaTableUpdateWhatItem.TABLES == selWhatItem) {
258:                    _schemaTableModel.setColumnTo(SchemaTableModel.IX_TABLE,
259:                            selToItem);
260:                } else if (SchemaTableUpdateWhatItem.VIEWS == selWhatItem) {
261:                    _schemaTableModel.setColumnTo(SchemaTableModel.IX_VIEW,
262:                            selToItem);
263:                } else if (SchemaTableUpdateWhatItem.PROCEDURES == selWhatItem) {
264:                    _schemaTableModel.setColumnTo(
265:                            SchemaTableModel.IX_PROCEDURE, selToItem);
266:                } else {
267:                    _schemaTableModel.setColumnTo(SchemaTableModel.IX_TABLE,
268:                            selToItem);
269:                    _schemaTableModel.setColumnTo(SchemaTableModel.IX_VIEW,
270:                            selToItem);
271:                    _schemaTableModel.setColumnTo(
272:                            SchemaTableModel.IX_PROCEDURE, selToItem);
273:                }
274:            }
275:
276:            /**
277:             * synchronized because the user may connect twice from within the Schema Properties Panel.
278:             * @param conn
279:             */
280:            private synchronized void onConnected(ISQLConnection conn) {
281:                try {
282:                    String[] schemas = _app.getSessionManager()
283:                            .getAllowedSchemas(conn, _alias);
284:
285:                    _schemaTableModel.updateSchemas(schemas);
286:
287:                    updateEnabled();
288:                } catch (Exception e) {
289:                    s_log.error("Failed to load Schemas", e);
290:                }
291:            }
292:
293:            private void updateEnabled() {
294:                if (null == _origTblColor) {
295:                    _origTblColor = _pnl.tblSchemas.getForeground();
296:                }
297:
298:                _pnl.btnUpdateSchemas.setEnabled(_pnl.radSpecifySchemas
299:                        .isSelected());
300:
301:                _pnl.tblSchemas.setEnabled(_pnl.radSpecifySchemas.isSelected());
302:
303:                _pnl.cboSchemaTableUpdateWhat.setEnabled(_pnl.radSpecifySchemas
304:                        .isSelected());
305:                _pnl.cboSchemaTableUpdateTo.setEnabled(_pnl.radSpecifySchemas
306:                        .isSelected());
307:                _pnl.btnSchemaTableUpdateApply
308:                        .setEnabled(_pnl.radSpecifySchemas.isSelected());
309:
310:                if (_pnl.radSpecifySchemas.isSelected()) {
311:                    _pnl.tblSchemas.setForeground(_origTblColor);
312:                } else {
313:                    _pnl.tblSchemas.setForeground(Color.lightGray);
314:                }
315:            }
316:
317:            private JComboBox initCbo(JComboBox cbo) {
318:                cbo.setEditable(false);
319:
320:                for (int i = 0; i < SchemaTableCboItem.items.length; i++) {
321:                    cbo.addItem(SchemaTableCboItem.items[i]);
322:                }
323:                cbo.setSelectedIndex(0);
324:                return cbo;
325:            }
326:
327:            public void applyChanges() {
328:
329:                TableCellEditor cellEditor = _pnl.tblSchemas.getCellEditor();
330:                if (null != cellEditor) {
331:                    cellEditor.stopCellEditing();
332:                }
333:
334:                if (_pnl.radLoadAllAndCacheNone.isSelected()) {
335:                    _alias
336:                            .getSchemaProperties()
337:                            .setGlobalState(
338:                                    SQLAliasSchemaProperties.GLOBAL_STATE_LOAD_ALL_CACHE_NONE);
339:                } else if (_pnl.radLoadAndCacheAll.isSelected()) {
340:                    _alias
341:                            .getSchemaProperties()
342:                            .setGlobalState(
343:                                    SQLAliasSchemaProperties.GLOBAL_STATE_LOAD_AND_CACHE_ALL);
344:                } else if (_pnl.radSpecifySchemas.isSelected()) {
345:                    _alias
346:                            .getSchemaProperties()
347:                            .setGlobalState(
348:                                    SQLAliasSchemaProperties.GLOBAL_STATE_SPECIFY_SCHEMAS);
349:                }
350:
351:                _alias.getSchemaProperties().setSchemaDetails(
352:                        _schemaTableModel.getData());
353:
354:                _alias.getSchemaProperties().setCacheSchemaIndependentMetaData(
355:                        _pnl.chkCacheSchemaIndepndentMetaData.isSelected());
356:
357:            }
358:
359:            public String getTitle() {
360:                // i18n[SchemaPropertiesController.title=Schemas]
361:                return s_stringMgr
362:                        .getString("SchemaPropertiesController.title");
363:            }
364:
365:            public String getHint() {
366:                // i18n[SchemaPropertiesController.hint=Schemas (loading and caching)]
367:                return s_stringMgr.getString("SchemaPropertiesController.hint");
368:            }
369:
370:            public Component getPanelComponent() {
371:                return _pnl;
372:            }
373:
374:            private static class SchemaTableUpdateWhatItem {
375:                // i18n[SchemaTableUpdateWhatItem.tables=Tables]
376:                public static final SchemaTableUpdateWhatItem TABLES = new SchemaTableUpdateWhatItem(
377:                        s_stringMgr
378:                                .getString("SchemaTableUpdateWhatItem.tables"));
379:                // i18n[SchemaTableUpdateWhatItem.views=Views]
380:                public static final SchemaTableUpdateWhatItem VIEWS = new SchemaTableUpdateWhatItem(
381:                        s_stringMgr
382:                                .getString("SchemaTableUpdateWhatItem.views"));
383:                // i18n[SchemaTableUpdateWhatItem.procedures=Procedures]
384:                public static final SchemaTableUpdateWhatItem PROCEDURES = new SchemaTableUpdateWhatItem(
385:                        s_stringMgr
386:                                .getString("SchemaTableUpdateWhatItem.procedures"));
387:                // i18n[SchemaTableUpdateWhatItem.allObjects=All Objects]
388:                public static final SchemaTableUpdateWhatItem ALL = new SchemaTableUpdateWhatItem(
389:                        s_stringMgr
390:                                .getString("SchemaTableUpdateWhatItem.allObjects"));
391:
392:                private String _name;
393:
394:                private SchemaTableUpdateWhatItem(String name) {
395:                    _name = name;
396:                }
397:
398:                public String toString() {
399:                    return _name;
400:                }
401:            }
402:
403:        }
w___w___w___.ja__va_2__s___._c__o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.