Source Code Cross Referenced for DataObjectHelper.java in  » IDE-Netbeans » etl.project » org » netbeans » modules » etl » 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 » IDE Netbeans » etl.project » org.netbeans.modules.etl.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DataObjectHelper.java
003:         *
004:         * Created on June 25, 2006, 5:05 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package org.netbeans.modules.etl.ui;
011:
012:        import java.awt.Cursor;
013:        import java.awt.Frame;
014:        import java.awt.event.MouseAdapter;
015:        import java.awt.event.MouseMotionAdapter;
016:        import java.io.InputStream;
017:        import java.sql.Types;
018:        import java.util.Iterator;
019:        import java.util.List;
020:        import javax.swing.JFrame;
021:        import javax.swing.JPanel;
022:        import javax.swing.SwingUtilities;
023:
024:        import org.netbeans.modules.etl.ui.model.impl.ETLCollaborationModel;
025:        import org.netbeans.modules.etl.ui.view.ETLCollaborationTopPanel;
026:        import org.netbeans.modules.etl.ui.view.property.ETLResourceManager;
027:        import org.netbeans.modules.etl.ui.view.wizards.ETLWizardHelper;
028:        import org.netbeans.modules.sql.framework.model.RuntimeDatabaseModel;
029:        import org.netbeans.modules.sql.framework.model.RuntimeInput;
030:        import org.netbeans.modules.sql.framework.model.RuntimeOutput;
031:        import org.netbeans.modules.sql.framework.model.SQLDBColumn;
032:        import org.netbeans.modules.sql.framework.model.SQLDBModel;
033:        import org.netbeans.modules.sql.framework.model.SQLDBTable;
034:        import org.netbeans.modules.sql.framework.model.SQLDefinition;
035:        import org.netbeans.modules.sql.framework.model.SQLJoinView;
036:        import org.netbeans.modules.sql.framework.model.SQLModelObjectFactory;
037:        import org.netbeans.modules.sql.framework.model.SourceColumn;
038:        import org.netbeans.modules.sql.framework.model.TargetTable;
039:        import org.netbeans.modules.sql.framework.model.impl.RuntimeDatabaseModelImpl;
040:        import org.netbeans.modules.sql.framework.model.impl.RuntimeOutputImpl;
041:        import org.netbeans.modules.sql.framework.model.utils.SQLObjectUtil;
042:        import org.netbeans.modules.sql.framework.ui.editor.property.impl.PropertyViewManager;
043:        import org.netbeans.modules.sql.framework.ui.view.join.JoinUtility;
044:        import org.openide.ErrorManager;
045:        import org.openide.WizardDescriptor;
046:        import org.openide.windows.WindowManager;
047:
048:        import com.sun.sql.framework.exception.BaseException;
049:        import java.io.IOException;
050:        import org.netbeans.modules.sql.framework.model.impl.RuntimeInputImpl;
051:
052:        /**
053:         *
054:         * @author radval
055:         */
056:        public class DataObjectHelper {
057:
058:            private static ETLDataObject mDataObject;
059:
060:            private static PropertyViewManager pvMgr;
061:
062:            /** Creates a new instance of DataObjectHelper */
063:            public DataObjectHelper(ETLDataObject dataObject) {
064:                mDataObject = dataObject;
065:            }
066:
067:            public DataObjectHelper() {
068:            }
069:
070:            public void initializeETLDataObject(WizardDescriptor descriptor,
071:                    ETLDataObject mObj, ETLEditorSupport editorSupport)
072:                    throws Exception {
073:                mDataObject = mObj;
074:                ETLWizardHelper wHelper = new ETLWizardHelper(descriptor);
075:
076:                List sourceDbList = wHelper.getSelectedSourceDb();
077:                List destinationDbList = wHelper.getSelectedDestinationDb();
078:                SQLJoinView joinView = wHelper.getSQLJoinView();
079:                List jVisibleColumns = wHelper.getTableColumnNodes();
080:
081:                // for now we need to have an editor top component so that table can be added to
082:                // it
083:                final ETLCollaborationTopPanel etlEditor = mDataObject
084:                        .getETLEditorTopPanel();
085:                ETLCollaborationModel collabModel = mObj.getModel();
086:
087:                // first add join view
088:                if (joinView != null) {
089:                    JoinUtility.handleNewJoinCreation(joinView,
090:                            jVisibleColumns, etlEditor.getGraphView());
091:
092:                    // WT #67643: Ensure that flatfile tables in join views have filename runtime
093:                    // inputs.
094:                    establishRuntimeInputs(collabModel, joinView
095:                            .getSourceTables());
096:                }
097:
098:                if (sourceDbList != null) {
099:                    addDestinationDb(sourceDbList, collabModel);
100:                }
101:
102:                if (destinationDbList != null) {
103:                    addDestinationDb(destinationDbList, collabModel);
104:                }
105:                establishRuntimeOutputs(mObj);
106:                //make sure editor document has etl content when first time created
107:                try {
108:                    String content = collabModel.getETLDefinition()
109:                            .toXMLString("");
110:                    editorSupport.openDocument();
111:                    editorSupport.getDocument().remove(0,
112:                            editorSupport.getDocument().getLength());
113:                    editorSupport.getDocument().insertString(0, content, null);
114:                } catch (Exception ex) {
115:                    ErrorManager.getDefault().notify(ex);
116:                }
117:            }
118:
119:            private static void addDestinationDb(List db,
120:                    ETLCollaborationModel collabModel) throws BaseException {
121:                for (int i = 0; i < db.size(); i++) {
122:                    SQLDBModel dbModel = (SQLDBModel) db.get(i);
123:
124:                    // Add database model only if at least one table in it was selected by user
125:                    if (dbModel.getTables().size() == 0) {
126:                        continue;
127:                    }
128:
129:                    addTables(dbModel, collabModel);
130:                }
131:            }
132:
133:            private static void addTables(SQLDBModel dbModel,
134:                    ETLCollaborationModel collabModel) throws BaseException {
135:                List tables = dbModel.getTables();
136:                Iterator it = tables.iterator();
137:                while (it.hasNext()) {
138:                    SQLDBTable table = (SQLDBTable) it.next();
139:                    collabModel.addObject(table);
140:                }
141:
142:                establishRuntimeInputs(collabModel, tables);
143:            }
144:
145:            private static void establishRuntimeInputs(
146:                    ETLCollaborationModel collabModel, List tables)
147:                    throws BaseException {
148:                Iterator it = tables.iterator();
149:                while (it.hasNext()) {
150:                    // if table is source table and is a flat file we auto create a run
151:                    SQLDBTable sTable = (SQLDBTable) it.next();
152:                    SourceColumn runtimeArg = SQLObjectUtil.createRuntimeInput(
153:                            sTable, collabModel.getSQLDefinition());
154:                    if (runtimeArg != null) {
155:                        RuntimeInput runtimeInput = (RuntimeInput) runtimeArg
156:                                .getParent();
157:
158:                        if (runtimeInput != null) {
159:                            // if runtime input is not in SQL definition then add it
160:                            if ((collabModel.getSQLDefinition()
161:                                    .isTableExists(runtimeInput)) == null) {
162:                                collabModel.addObject(runtimeInput);
163:                            }
164:                        }
165:                    }
166:                    SQLObjectUtil.setOrgProperties(sTable);
167:                }
168:            }
169:
170:            /**
171:             * Updates selected source and target tables for the given eTL Collaboration
172:             * ProjectElement.
173:             *
174:             * @param dObj etldataobject(representing an eTL Collaboration) whose table
175:             *        selections are to be updated
176:             * @param sourcedb List of source table Databases to be added to <code>element</code>
177:             * @param targetdb List of target table Databases to be added to <code>element</code>
178:             * @throws Exception if error occurs during update
179:             */
180:            public void updateTableSelections(ETLDataObject dObj,
181:                    List sourceDb, List targetDb) throws Exception {
182:                ETLCollaborationModel collabModel = null;
183:                collabModel = dObj.getModel();
184:                if (collabModel == null) {
185:                    return;
186:                }
187:
188:                if (sourceDb != null) {
189:                    addDestinationDb(sourceDb, collabModel);
190:                }
191:
192:                if (targetDb != null) {
193:                    addDestinationDb(targetDb, collabModel);
194:                }
195:            }
196:
197:            /**
198:             * Gets instance of PropertyViewManager.
199:             *
200:             * @return instance of PropertyViewManager
201:             */
202:            public static PropertyViewManager getPropertyViewManager() {
203:                InputStream stream = null;
204:                if (pvMgr == null) {
205:                    try {
206:                        stream = DataObjectHelper.class
207:                                .getClassLoader()
208:                                .getResourceAsStream(
209:                                        "org/netbeans/modules/etl/ui/resources/etl_properties.xml");
210:                        pvMgr = new PropertyViewManager(stream,
211:                                new ETLResourceManager());
212:                    } finally {
213:                        if (stream != null) {
214:                            try {
215:                                stream.close();
216:                            } catch (IOException ignore) {
217:                                // ignore
218:                            }
219:                        }
220:                    }
221:                }
222:                return pvMgr;
223:            }
224:
225:            /**
226:             * Displays default cursor in Editor.
227:             */
228:            public static void setDefaultCursor() {
229:                Runnable r = new Runnable() {
230:                    public synchronized void run() {
231:                        Frame mainWindow = WindowManager.getDefault()
232:                                .getMainWindow();
233:                        if (mainWindow instanceof  JFrame) {
234:                            JFrame frame = (JFrame) mainWindow;
235:                            JPanel glass = (JPanel) frame.getGlassPane();
236:                            glass.setCursor(Cursor.getDefaultCursor());
237:                            glass.setVisible(false);
238:                        }
239:                    }
240:                };
241:
242:                SwingUtilities.invokeLater(r);
243:            }
244:
245:            /**
246:             * Displays wait cursor in Editor.
247:             */
248:            public static void setWaitCursor() {
249:                Runnable r = new Runnable() {
250:                    public synchronized void run() {
251:                        Frame mainWindow = WindowManager.getDefault()
252:                                .getMainWindow();
253:
254:                        if (mainWindow instanceof  JFrame) {
255:                            JFrame frame = (JFrame) mainWindow;
256:                            JPanel glass = (JPanel) frame.getGlassPane();
257:                            glass.addMouseListener(new MouseAdapter() {
258:                            });
259:                            glass
260:                                    .addMouseMotionListener(new MouseMotionAdapter() {
261:                                    });
262:                            glass.setCursor(Cursor
263:                                    .getPredefinedCursor(Cursor.WAIT_CURSOR));
264:                            glass.setVisible(true);
265:                        }
266:                    }
267:                };
268:
269:                SwingUtilities.invokeLater(r);
270:            }
271:
272:            private void establishRuntimeOutputs(ETLDataObject mObj) {
273:                try {
274:                    SQLDefinition sqlDefn = mObj.getETLDefinition()
275:                            .getSQLDefinition();
276:                    RuntimeDatabaseModel rtModel = sqlDefn.getRuntimeDbModel();
277:                    if (rtModel == null) {
278:                        rtModel = new RuntimeDatabaseModelImpl();
279:                    }
280:                    RuntimeOutput rtOutTable = new RuntimeOutputImpl();
281:                    // add STATUS
282:                    SQLDBColumn column = SQLModelObjectFactory.getInstance()
283:                            .createTargetColumn("STATUS", Types.VARCHAR, 0, 0,
284:                                    true);
285:                    column.setEditable(false);
286:                    rtOutTable.addColumn(column);
287:
288:                    // add STARTTIME
289:                    column = SQLModelObjectFactory.getInstance()
290:                            .createTargetColumn("STARTTIME", Types.TIMESTAMP,
291:                                    0, 0, true);
292:                    column.setEditable(false);
293:                    rtOutTable.addColumn(column);
294:
295:                    // add ENDTIME
296:                    column = SQLModelObjectFactory.getInstance()
297:                            .createTargetColumn("ENDTIME", Types.TIMESTAMP, 0,
298:                                    0, true);
299:                    column.setEditable(false);
300:                    rtOutTable.addColumn(column);
301:
302:                    Iterator it = sqlDefn.getTargetTables().iterator();
303:                    while (it.hasNext()) {
304:                        TargetTable targetTable = (TargetTable) it.next();
305:                        String argName = SQLObjectUtil
306:                                .getTargetTableCountRuntimeOutput(targetTable);
307:                        column = SQLModelObjectFactory.getInstance()
308:                                .createTargetColumn(argName, Types.INTEGER, 0,
309:                                        0, true);
310:                        column.setEditable(false);
311:                        rtOutTable.addColumn(column);
312:                    }
313:                    rtModel.addTable(rtOutTable);
314:                    sqlDefn.addObject(rtModel);
315:                } catch (Exception ex) {
316:                    //ignore
317:                }
318:            }
319:
320:            private void establishRuntimeOutputs(SQLDefinition sqlDefn) {
321:                try {
322:                    RuntimeDatabaseModel rtModel = sqlDefn.getRuntimeDbModel();
323:                    if (rtModel == null) {
324:                        rtModel = new RuntimeDatabaseModelImpl();
325:                    }
326:                    RuntimeOutput rtOutTable = new RuntimeOutputImpl();
327:                    // add STATUS
328:                    SQLDBColumn column = SQLModelObjectFactory.getInstance()
329:                            .createTargetColumn("STATUS", Types.VARCHAR, 0, 0,
330:                                    true);
331:                    column.setEditable(false);
332:                    rtOutTable.addColumn(column);
333:
334:                    // add STARTTIME
335:                    column = SQLModelObjectFactory.getInstance()
336:                            .createTargetColumn("STARTTIME", Types.TIMESTAMP,
337:                                    0, 0, true);
338:                    column.setEditable(false);
339:                    rtOutTable.addColumn(column);
340:
341:                    // add ENDTIME
342:                    column = SQLModelObjectFactory.getInstance()
343:                            .createTargetColumn("ENDTIME", Types.TIMESTAMP, 0,
344:                                    0, true);
345:                    column.setEditable(false);
346:                    rtOutTable.addColumn(column);
347:
348:                    Iterator it = sqlDefn.getTargetTables().iterator();
349:                    while (it.hasNext()) {
350:                        TargetTable targetTable = (TargetTable) it.next();
351:                        String argName = SQLObjectUtil
352:                                .getTargetTableCountRuntimeOutput(targetTable);
353:                        column = SQLModelObjectFactory.getInstance()
354:                                .createTargetColumn(argName, Types.INTEGER, 0,
355:                                        0, true);
356:                        column.setEditable(false);
357:                        rtOutTable.addColumn(column);
358:                    }
359:                    rtModel.addTable(rtOutTable);
360:                    sqlDefn.addObject(rtModel);
361:                } catch (Exception ex) {
362:                    //ignore
363:                }
364:            }
365:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.