Source Code Cross Referenced for StaticDataEditor.java in  » XML-UI » xui32 » com » xoetrope » carousel » services » 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 » XML UI » xui32 » com.xoetrope.carousel.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.services;
002:
003:        import java.util.Enumeration;
004:        import java.util.Hashtable;
005:        import java.util.StringTokenizer;
006:        import java.util.Vector;
007:
008:        import java.awt.BorderLayout;
009:        import java.awt.Color;
010:        import java.awt.GridLayout;
011:        import java.awt.event.ActionEvent;
012:        import java.awt.event.ActionListener;
013:        import java.awt.event.ItemEvent;
014:        import java.awt.event.ItemListener;
015:        import java.awt.event.KeyEvent;
016:        import java.awt.event.KeyListener;
017:        import java.awt.event.MouseEvent;
018:        import java.awt.event.MouseListener;
019:        import javax.swing.DefaultListModel;
020:        import javax.swing.JButton;
021:        import javax.swing.JCheckBox;
022:        import javax.swing.JComboBox;
023:        import javax.swing.JLabel;
024:        import javax.swing.JList;
025:        import javax.swing.JMenuItem;
026:        import javax.swing.JPanel;
027:        import javax.swing.JPopupMenu;
028:        import javax.swing.JScrollPane;
029:        import javax.swing.JTable;
030:        import javax.swing.JTextField;
031:        import javax.swing.JTree;
032:        import javax.swing.border.LineBorder;
033:        import javax.swing.event.TableModelEvent;
034:        import javax.swing.event.TableModelListener;
035:        import javax.swing.event.TreeModelEvent;
036:        import javax.swing.event.TreeModelListener;
037:        import javax.swing.event.TreeSelectionEvent;
038:        import javax.swing.event.TreeSelectionListener;
039:        import javax.swing.table.DefaultTableModel;
040:        import javax.swing.tree.DefaultMutableTreeNode;
041:        import javax.swing.tree.DefaultTreeModel;
042:
043:        import net.xoetrope.optional.data.sql.DatabaseTableModel;
044:        import com.xoetrope.carousel.services.dialog.DatabaseObjects;
045:        import com.xoetrope.carousel.services.events.ModelListener;
046:        import net.xoetrope.editor.project.XEditorProject;
047:        import net.xoetrope.xml.XmlElement;
048:        import net.xoetrope.xml.nanoxml.NanoXmlElement;
049:        import net.xoetrope.xui.data.XBaseModel;
050:        import net.xoetrope.xui.data.XModel;
051:
052:        /**
053:         * <p>Title: Xui</p>
054:         * <p>Description: This screen is used to edit static data file. The dropdown
055:         * on the top of the screen allows the user to select the file that they want
056:         * to edit. The tree on the left allows them to select, add and delete dataitems.
057:         * The panel on the right allows data to be edited.</p>
058:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
059:         * the GNU Public License (GPL), please see license.txt for more details. If
060:         * you make commercial use of this software you must purchase a commercial
061:         * license from Xoetrope.</p>
062:         * <p> $Revision: 1.4 $</p>
063:         */
064:        public class StaticDataEditor extends JPanel implements  ActionListener,
065:                TreeSelectionListener, MouseListener, TreeModelListener,
066:                TableModelListener, KeyListener, ItemListener {
067:
068:            private JPanel mainPanel, pnlControls;
069:            private JPanel pnlEditor;
070:            private JPanel pnlData, pnlDataItem, pnlList;
071:            private JTextField txtDataItemValue;
072:            private JButton btnNewListItem, btnRemoveListItem;
073:            private JTable tblListItems;
074:            private DefaultTableModel listTableModel;
075:            private JTree dataTree;
076:
077:            private JButton btnAdd, btnSave, btnCancel;
078:            private String fileName;
079:            private String filePath;
080:            private XBaseModel editModel;
081:            private XModel amendModel, mainModel;
082:            private ModelListener modelListener;
083:            private JPopupMenu mnuDatasets, mnuDataset, mnuDelete;
084:
085:            /* connection controls */
086:            private JPanel pnlConnection, pnlResultSet;
087:            private JTextField txtConnURL, txtConnUser, txtConnPwd;
088:            private JTextField txtFromTable, txtWhere;
089:            private JList lstFields;
090:            private JCheckBox chkUpdateRS;
091:            private JComboBox cmbConnections;
092:            private NanoXmlElement currentDBElement;
093:            private JButton btnSelectTable, btnSelectFields;
094:
095:            private JPopupMenu mnuDatabase;
096:
097:            public static final String MNU_NEW_DATASET = "New Dataset";
098:            public static final String MNU_NEW_DATAITEM = "New item";
099:            public static final String MNU_NEW_DATALIST = "New List";
100:            public static final String MNU_NEW_DELETE = "Delete";
101:
102:            public static final String MNU_NEW_CONNECTION = "New Connection";
103:            public static final String MNU_NEW_RESULTSET = "New Resultset";
104:
105:            private int amendType = 0;
106:
107:            public static final int AMEND_STATIC = 1;
108:            public static final int AMEND_DATABASE = 2;
109:            public static final int AMEND_SELECT = 3;
110:
111:            private String currentDatabaseName;
112:
113:            private XEditorProject currentProject;
114:
115:            public StaticDataEditor(XEditorProject project) {
116:                currentProject = project;
117:                setLayout(new BorderLayout());
118:                mainPanel = new JPanel(new BorderLayout());
119:                add(mainPanel, BorderLayout.CENTER);
120:                createEditPanels();
121:                createPopupMenus();
122:            }
123:
124:            private ModelManager getModelManager() {
125:                RouteManager routeMgr = (RouteManager) currentProject
126:                        .getObject(ProjectRouteManager.ROUTE_MGR_LOOKUP);
127:                return routeMgr.getModelMgr();
128:            }
129:
130:            public void setModelListener(ModelListener listener) {
131:                modelListener = listener;
132:            }
133:
134:            public void setTree(JTree tree, int type) {
135:                amendType = type;
136:                dataTree = tree;
137:                dataTree.addTreeSelectionListener(this );
138:                dataTree.getModel().addTreeModelListener(this );
139:                dataTree.addMouseListener(this );
140:            }
141:
142:            public void treeStructureChanged(TreeModelEvent evt) {
143:            }
144:
145:            public void treeNodesRemoved(TreeModelEvent evt) {
146:            }
147:
148:            public void treeNodesInserted(TreeModelEvent evt) {
149:            }
150:
151:            /*private ModelManager getModelManager()
152:            {
153:              return ( ModelManager ) currentProject.getObject( ProjectRouteManager.MODEL_MGR_LOOKUP );
154:            }*/
155:
156:            public void treeNodesChanged(TreeModelEvent evt) {
157:                if (evt.getChildren() == null) {
158:                } else {
159:                    if (amendType == AMEND_STATIC) {
160:                        String currentNode = evt.getChildren()[0].toString();
161:                        amendModel.setId(currentNode);
162:                        mainModel.setId(currentNode);
163:                        modelListener.modelChanged();
164:                    } else if (amendType == AMEND_DATABASE) {
165:                        Hashtable table = getModelManager().getDatabaseNodes();
166:                        XmlElement ele = (XmlElement) table
167:                                .remove(currentDatabaseName);
168:                        String newName = evt.getChildren()[0].toString();
169:                        ele.setAttribute("name", newName);
170:                        table.put(newName, ele);
171:                        if (ele.getName().compareTo("Connection") == 0) {
172:                            cmbConnections.removeItem(currentDatabaseName);
173:                            cmbConnections.addItem(newName);
174:                        }
175:                        currentDatabaseName = newName;
176:                        // This case is for the database connection node as it won't exist in
177:                        // the model.
178:                        if (mainModel != null) {
179:                            mainModel.setId(newName);
180:                            modelListener.modelChanged();
181:                        }
182:                    }
183:                }
184:            }
185:
186:            public void tableChanged(TableModelEvent evt) {
187:                ((XBaseModel) amendModel).removeChildren();
188:                saveList();
189:            }
190:
191:            public void setEditModel(XBaseModel model, String name, String path) {
192:                editModel = model;
193:                fileName = name;
194:                filePath = path;
195:            }
196:
197:            private void createPopupMenus() {
198:                mnuDatasets = new JPopupMenu();
199:                mnuDatasets.add(createMenuItem(MNU_NEW_DATASET));
200:
201:                mnuDataset = new JPopupMenu();
202:                mnuDataset.add(createMenuItem(MNU_NEW_DATAITEM));
203:                mnuDataset.add(createMenuItem(MNU_NEW_DATALIST));
204:                mnuDataset.add(createMenuItem(MNU_NEW_DELETE));
205:
206:                mnuDelete = new JPopupMenu();
207:                mnuDelete.add(createMenuItem(MNU_NEW_DELETE));
208:
209:                mnuDatabase = new JPopupMenu();
210:                mnuDatabase.add(createMenuItem(MNU_NEW_CONNECTION));
211:                mnuDatabase.add(createMenuItem(MNU_NEW_RESULTSET));
212:            }
213:
214:            private JMenuItem createMenuItem(String caption) {
215:                JMenuItem item = new JMenuItem(caption);
216:                item.addActionListener(this );
217:                return item;
218:            }
219:
220:            private void createEditPanels() {
221:                pnlEditor = new JPanel(new BorderLayout());
222:
223:                pnlData = new JPanel(new BorderLayout());
224:                pnlEditor.add(pnlData, BorderLayout.CENTER);
225:                mainPanel.add(pnlEditor, BorderLayout.CENTER);
226:
227:                pnlDataItem = createDataItemPanel();
228:                pnlList = createDataListPanel();
229:                pnlConnection = createConnectionPanel();
230:                pnlResultSet = createResultSetPanel();
231:
232:                hideDataPanels(null);
233:            }
234:
235:            private JPanel createDataItemPanel() {
236:                pnlDataItem = new JPanel(new BorderLayout());
237:                JPanel tempPanel = new JPanel(new GridLayout(2, 2, 10, 10));
238:                pnlDataItem.add(tempPanel, BorderLayout.NORTH);
239:
240:                tempPanel.add(new JLabel("Dataitem value:"));
241:                txtDataItemValue = new JTextField();
242:                txtDataItemValue.addKeyListener(this );
243:                tempPanel.add(txtDataItemValue);
244:
245:                return pnlDataItem;
246:            }
247:
248:            private JPanel createDataListPanel() {
249:                pnlList = new JPanel(new BorderLayout());
250:                JPanel tempPanel = new JPanel(new GridLayout(3, 1));
251:
252:                listTableModel = new DefaultTableModel();
253:                listTableModel.addColumn("name");
254:                listTableModel.addColumn("Value");
255:                tblListItems = new JTable(listTableModel);
256:                tblListItems.getModel().addTableModelListener(this );
257:                JScrollPane listPane = new JScrollPane(tblListItems);
258:
259:                JPanel pnlListButtons = new JPanel(new GridLayout(1, 2));
260:                btnNewListItem = new JButton("New");
261:                btnRemoveListItem = new JButton("Remove");
262:                btnNewListItem.addActionListener(this );
263:                btnRemoveListItem.addActionListener(this );
264:                pnlListButtons.add(btnNewListItem);
265:                pnlListButtons.add(btnRemoveListItem);
266:
267:                pnlList.add(tempPanel, BorderLayout.NORTH);
268:                pnlList.add(listPane, BorderLayout.CENTER);
269:                pnlList.add(pnlListButtons, BorderLayout.SOUTH);
270:                return pnlList;
271:            }
272:
273:            private JPanel createConnectionPanel() {
274:                pnlConnection = new JPanel(new BorderLayout());
275:
276:                JPanel pnlTemp = new JPanel(new GridLayout(4, 2));
277:                txtConnURL = new JTextField();
278:                txtConnUser = new JTextField();
279:                txtConnPwd = new JTextField();
280:
281:                txtConnURL.addKeyListener(this );
282:                txtConnUser.addKeyListener(this );
283:                txtConnPwd.addKeyListener(this );
284:
285:                pnlTemp.add(new JLabel(""));
286:                pnlTemp.add(new JLabel(""));
287:                pnlTemp.add(new JLabel(" URL :"));
288:                pnlTemp.add(txtConnURL);
289:                pnlTemp.add(new JLabel(" User ID :"));
290:                pnlTemp.add(txtConnUser);
291:                pnlTemp.add(new JLabel(" Password :"));
292:                pnlTemp.add(txtConnPwd);
293:                pnlConnection.add(pnlTemp, BorderLayout.NORTH);
294:                return pnlConnection;
295:            }
296:
297:            private JPanel createResultSetPanel() {
298:                pnlResultSet = new JPanel(new BorderLayout());
299:                JPanel pnlTable = new JPanel(new BorderLayout());
300:                JPanel pnlFields = new JPanel(new BorderLayout());
301:                JPanel pnlContTop = new JPanel(new GridLayout(2, 3));
302:                JPanel pnlContCenter = new JPanel(new GridLayout(1, 3));
303:                JPanel pnlContBottom = new JPanel(new GridLayout(2, 3));
304:
305:                txtFromTable = new JTextField();
306:                btnSelectTable = new JButton("...");
307:                lstFields = new JList();
308:                btnSelectFields = new JButton("...");
309:                txtWhere = new JTextField();
310:                chkUpdateRS = new JCheckBox("Update");
311:                chkUpdateRS.setAlignmentX(JCheckBox.RIGHT_ALIGNMENT);
312:
313:                btnSelectTable = new JButton("...");
314:                lstFields = new JList();
315:                lstFields.setBorder(new LineBorder(Color.black));
316:                btnSelectFields = new JButton("Select Fields...");
317:                txtWhere = new JTextField();
318:                chkUpdateRS = new JCheckBox("Update");
319:                cmbConnections = new JComboBox(getConnectionNodes());
320:                cmbConnections.addItemListener(this );
321:
322:                txtFromTable.addKeyListener(this );
323:                btnSelectTable.addActionListener(this );
324:                btnSelectFields.addActionListener(this );
325:                txtWhere.addKeyListener(this );
326:                chkUpdateRS.addActionListener(this );
327:
328:                pnlTable.add(txtFromTable, BorderLayout.WEST);
329:                pnlTable.add(btnSelectTable, BorderLayout.CENTER);
330:                pnlFields.add(lstFields, BorderLayout.CENTER);
331:                pnlFields.add(btnSelectFields, BorderLayout.SOUTH);
332:
333:                pnlContTop.add(new JLabel(" Connection :"));
334:                pnlContTop.add(cmbConnections);
335:                pnlContTop.add(new JLabel(" Table :"));
336:                pnlContTop.add(pnlTable);
337:                pnlContCenter.add(new JLabel(" Fields :"));
338:                pnlContCenter.add(pnlFields);
339:                pnlContBottom.add(new JLabel(" Where :"));
340:                pnlContBottom.add(txtWhere);
341:                pnlContBottom.add(chkUpdateRS);
342:
343:                pnlResultSet.add(pnlContTop, BorderLayout.NORTH);
344:                pnlResultSet.add(pnlContCenter, BorderLayout.CENTER);
345:                pnlResultSet.add(pnlContBottom, BorderLayout.SOUTH);
346:
347:                return pnlResultSet;
348:            }
349:
350:            private Vector getConnectionNodes() {
351:                Vector conns = new Vector();
352:                Hashtable nodes = getModelManager().getDatabaseNodes();
353:                Enumeration e = nodes.elements();
354:                while (e.hasMoreElements()) {
355:                    XmlElement ele = (XmlElement) e.nextElement();
356:                    if (ele.getName().compareTo("Connection") == 0)
357:                        conns.add(ele.getAttribute("name"));
358:                }
359:                return conns;
360:            }
361:
362:            void hideDataPanels(JPanel visiblePnl) {
363:                pnlDataItem.setVisible(false);
364:                pnlList.setVisible(false);
365:                pnlConnection.setVisible(false);
366:                pnlResultSet.setVisible(false);
367:                if (visiblePnl != null) {
368:                    if (pnlData.getComponentCount() > 0)
369:                        pnlData.remove(pnlData.getComponent(0));
370:                    visiblePnl.setVisible(true);
371:                    pnlData.add(visiblePnl, BorderLayout.CENTER);
372:                }
373:            }
374:
375:            public void actionPerformed(ActionEvent evt) {
376:                if (evt.getSource().equals(btnNewListItem)) {
377:                    String[] rowData = { "", "" };
378:                    listTableModel.addRow(rowData);
379:                } else if (evt.getSource().equals(btnRemoveListItem)) {
380:                    listTableModel.removeRow(tblListItems.getSelectedRow());
381:                }
382:
383:                if (evt.getActionCommand().compareTo(MNU_NEW_DATASET) == 0) {
384:                    hideDataPanels(null);
385:                    createDataSet();
386:                } else if (evt.getActionCommand().compareTo(MNU_NEW_DATAITEM) == 0) {
387:                    hideDataPanels(null);
388:                    createDataItem();
389:                } else if (evt.getActionCommand().compareTo(MNU_NEW_DATALIST) == 0) {
390:                    hideDataPanels(null);
391:                    createDataList();
392:                } else if (evt.getActionCommand().compareTo(MNU_NEW_CONNECTION) == 0) {
393:                    hideDataPanels(null);
394:                    createConnection();
395:                } else if (evt.getActionCommand().compareTo(MNU_NEW_RESULTSET) == 0) {
396:                    hideDataPanels(null);
397:                    createResultset();
398:                } else if (evt.getActionCommand().compareTo(MNU_NEW_DELETE) == 0) {
399:                    if (amendType == AMEND_STATIC) {
400:                        String dataName = getTreePath();
401:                        XModel model = (XModel) editModel.get(dataName);
402:                        XBaseModel parent = (XBaseModel) ((XBaseModel) model)
403:                                .getParent();
404:                        parent.removeChild(model.getId());
405:                    } else if (amendType == AMEND_DATABASE) {
406:                        Hashtable table = getModelManager().getDatabaseNodes();
407:                        table.remove(dataTree.getSelectionPath()
408:                                .getLastPathComponent().toString());
409:                    }
410:                    ((DefaultTreeModel) dataTree.getModel())
411:                            .removeNodeFromParent((DefaultMutableTreeNode) dataTree
412:                                    .getSelectionPath().getLastPathComponent());
413:                }
414:
415:                if (evt.getSource().equals(chkUpdateRS)) {
416:                    currentDBElement.setAttribute("update", String
417:                            .valueOf(chkUpdateRS.isSelected()));
418:                } else if (evt.getSource().equals(btnSelectTable)) {
419:                    XmlElement ele = getConnectionNode(cmbConnections
420:                            .getSelectedItem().toString());
421:                    DatabaseObjects dlg = new DatabaseObjects();
422:                    dlg.setLocationRelativeTo(this );
423:                    if (dlg.showDlg(txtFromTable.getText(), ele)) {
424:                        txtFromTable.setText(dlg.getSelectedObject());
425:                        currentDBElement.setAttribute("from", txtFromTable
426:                                .getText());
427:                    }
428:                } else if (evt.getSource().equals(btnSelectFields)) {
429:                    XmlElement ele = getConnectionNode(cmbConnections
430:                            .getSelectedItem().toString());
431:                    DatabaseObjects dlg = new DatabaseObjects();
432:                    dlg.setLocationRelativeTo(this );
433:                    String[] fields = new String[lstFields.getModel().getSize()];
434:                    for (int i = 0; i < fields.length; i++) {
435:                        fields[i] = (String) lstFields.getModel().getElementAt(
436:                                i);
437:                    }
438:                    if (dlg.showDlg(txtFromTable.getText(), fields, ele)) {
439:                        Object[] selectedFields = dlg.getSelectedFields();
440:                        StringBuffer saveFields = new StringBuffer("");
441:                        DefaultListModel model = new DefaultListModel();
442:                        for (int i = 0; i < selectedFields.length; i++) {
443:                            model.addElement(selectedFields[i]);
444:                            saveFields.append(selectedFields[i]);
445:                            saveFields.append(",");
446:                        }
447:                        lstFields.setModel(model);
448:                        if (selectedFields.length > 0)
449:                            currentDBElement
450:                                    .setAttribute("fields", saveFields
451:                                            .toString().substring(
452:                                                    0,
453:                                                    saveFields.toString()
454:                                                            .length() - 1));
455:                        else
456:                            currentDBElement.setAttribute("fields", "");
457:                    }
458:                }
459:            }
460:
461:            private XmlElement getConnectionNode(String connName) {
462:                XmlElement ele = (XmlElement) getModelManager()
463:                        .getDatabaseNodes().get(connName);
464:                return ele;
465:            }
466:
467:            private void createDataItem() {
468:                createNewModelNode("data", "New dataitem", amendModel);
469:                createNewModelNode("data", "New dataitem", mainModel);
470:                hideDataPanels(pnlDataItem);
471:            }
472:
473:            private void createDataSet() {
474:                createNewModelNode("dataset", "New dataset", editModel);
475:                createNewModelNode("dataset", "New dataset", mainModel);
476:            }
477:
478:            private void createDataList() {
479:                createNewModelNode("list", "New list", amendModel);
480:                createNewModelNode("list", "New list", mainModel);
481:                hideDataPanels(pnlList);
482:            }
483:
484:            private void createConnection() {
485:                NanoXmlElement ele = new NanoXmlElement("Connection");
486:                ele.setAttribute("name", "new connection");
487:                ele.setAttribute("driver", "sun.jdbc.odbc.JdbcOdbcDriver");
488:                getModelManager().getDatabaseNodes().put("new connection", ele);
489:                insertChildNode("new connection");
490:            }
491:
492:            private void createResultset() {
493:                NanoXmlElement ele = new NanoXmlElement("ResultSet");
494:                ele.setAttribute("name", "new resultset");
495:                getModelManager().getDatabaseNodes().put("new resultset", ele);
496:                insertChildNode("new resultset");
497:
498:                DatabaseTableModel tableModel = new DatabaseTableModel(
499:                        currentProject);
500:                tableModel.setName("new resultset");
501:                currentProject.getModel().append(tableModel);
502:                modelListener.modelChanged();
503:            }
504:
505:            private void addNodeToModel(XBaseModel child) {
506:                String path = getTreePath();
507:                XModel parent;
508:
509:                if (path.length() == 0) {
510:                    parent = currentProject.getModel();
511:                } else {
512:                    parent = (XModel) currentProject.getModel().get(path);
513:                }
514:                parent.append(child);
515:            }
516:
517:            private void createNewModelNode(String tagName, String name,
518:                    XModel parent) {
519:                XBaseModel dataset = new XBaseModel();
520:                dataset.setTagName(tagName);
521:                dataset.setId(name);
522:                parent.append(dataset);
523:                if (!parent.equals(mainModel))
524:                    insertChildNode(name);
525:                modelListener.modelChanged();
526:            }
527:
528:            private void insertChildNode(String text) {
529:                DefaultTreeModel treemodel = (DefaultTreeModel) dataTree
530:                        .getModel();
531:                DefaultMutableTreeNode nodParent = (DefaultMutableTreeNode) dataTree
532:                        .getSelectionPath().getLastPathComponent();
533:                DefaultMutableTreeNode nodChild = new DefaultMutableTreeNode(
534:                        text);
535:                treemodel.insertNodeInto(nodChild, nodParent, 0);
536:            }
537:
538:            private void updateTable() {
539:                hideDataPanels(null);
540:                repaint();
541:            }
542:
543:            private void saveDataItem() {
544:                if (amendModel == null) {
545:                    XModel model = (XModel) editModel.get(getTreePath());
546:                } else {
547:                    amendModel.set(txtDataItemValue.getText());
548:                }
549:            }
550:
551:            private void saveList() {
552:                for (int i = 0; i < tblListItems.getModel().getRowCount(); i++) {
553:                    XBaseModel itemModel = new XBaseModel();
554:                    itemModel.setTagName("item");
555:                    itemModel.setId((String) tblListItems.getModel()
556:                            .getValueAt(i, 0));
557:                    itemModel.set(tblListItems.getModel().getValueAt(i, 1));
558:                    amendModel.append(itemModel);
559:                }
560:                modelListener.modelChanged();
561:            }
562:
563:            private String getTreePath() {
564:                return getTreePath(false);
565:            }
566:
567:            private String getTreePath(boolean startAtRoot) {
568:                String modelName = null;
569:                if (dataTree.getSelectionPath() != null) {
570:                    Object path[] = dataTree.getSelectionPath().getPath();
571:
572:                    modelName = "";
573:                    int start = startAtRoot ? 0 : 1;
574:                    for (int i = start; i < path.length; i++) {
575:                        modelName += "/" + path[i].toString();
576:                    }
577:                }
578:                if (modelName == null)
579:                    return "";
580:                else if (modelName.trim().compareTo("") != 0)
581:                    return modelName.substring(1);
582:                else
583:                    return "";
584:            }
585:
586:            public void valueChanged(TreeSelectionEvent evt) {
587:                if (amendType == AMEND_STATIC)
588:                    staticValueChanged(evt);
589:                else
590:                    databaseValueChanged(evt);
591:            }
592:
593:            private void staticValueChanged(TreeSelectionEvent evt) {
594:                String dataName = getTreePath();
595:
596:                if (dataName.compareTo("") == 0) {
597:                    hideDataPanels(null);
598:                    mainModel = currentProject.getModel();
599:                } else {
600:                    XModel model = (XModel) editModel.get(dataName);
601:                    if (model.getTagName() == null) {
602:                        hideDataPanels(null);
603:                    } else if (model.getTagName().compareTo("dataset") == 0) {
604:                        hideDataPanels(null);
605:                        amendModel = (XBaseModel) model;
606:                        mainModel = (XModel) currentProject.getModel().get(
607:                                dataName);
608:                    } else if (model.getTagName().compareTo("data") == 0) {
609:                        amendModel = (XBaseModel) model;
610:                        mainModel = (XModel) currentProject.getModel().get(
611:                                dataName);
612:                        hideDataPanels(pnlDataItem);
613:                        txtDataItemValue.setText((String) model.get());
614:                    } else if (model.getTagName().compareTo("list") == 0) {
615:                        amendModel = (XBaseModel) model;
616:                        mainModel = (XModel) currentProject.getModel().get(
617:                                dataName);
618:                        hideDataPanels(pnlList);
619:                        populateList(model);
620:                    }
621:                }
622:            }
623:
624:            private void databaseValueChanged(TreeSelectionEvent evt) {
625:                currentDatabaseName = getTreePath();
626:
627:                if (evt.getPath().getPath().length > 1) {
628:                    currentDBElement = (NanoXmlElement) getModelManager()
629:                            .getDatabaseNodes().get(
630:                                    evt.getPath().getLastPathComponent()
631:                                            .toString());
632:                    if (currentDBElement.getName().compareTo("Connection") == 0) {
633:                        hideDataPanels(pnlConnection);
634:                        txtConnURL
635:                                .setText(currentDBElement.getAttribute("url"));
636:                        txtConnUser.setText(currentDBElement
637:                                .getAttribute("user"));
638:                        txtConnPwd
639:                                .setText(currentDBElement.getAttribute("pwd"));
640:                    } else if (currentDBElement.getName()
641:                            .compareTo("ResultSet") == 0) {
642:                        hideDataPanels(pnlResultSet);
643:                        cmbConnections.setSelectedItem(currentDBElement
644:                                .getAttribute("conn"));
645:                        txtFromTable.setText(currentDBElement
646:                                .getAttribute("from"));
647:                        populateFieldList(currentDBElement
648:                                .getAttribute("fields"));
649:                        txtWhere
650:                                .setText(currentDBElement.getAttribute("where"));
651:                        chkUpdateRS.setSelected(Boolean.valueOf(
652:                                currentDBElement.getAttribute("update"))
653:                                .booleanValue());
654:                        mainModel = (XModel) currentProject.getModel().get(
655:                                currentDatabaseName);
656:                    }
657:                }
658:            }
659:
660:            private void populateFieldList(String fields) {
661:                if (fields == null) {
662:                    lstFields.setModel(new DefaultListModel());
663:                } else {
664:                    DefaultListModel model = new DefaultListModel();
665:                    StringTokenizer token = new StringTokenizer(fields, ",");
666:                    while (token.hasMoreElements()) {
667:                        model.addElement(token.nextElement());
668:                    }
669:                    lstFields.setModel(model);
670:                }
671:            }
672:
673:            private void populateList(XModel model) {
674:                listTableModel.removeTableModelListener(this );
675:                for (int i = listTableModel.getRowCount() - 1; i >= 0; i--)
676:                    listTableModel.removeRow(i);
677:
678:                for (int i = 0; i < model.getNumChildren(); i++) {
679:                    XModel item = model.get(i);
680:                    String[] row = { item.getId(), (String) item.get() };
681:                    listTableModel.addRow(row);
682:                }
683:                listTableModel.addTableModelListener(this );
684:            }
685:
686:            public void mouseExited(MouseEvent evt) {
687:            }
688:
689:            public void mouseEntered(MouseEvent evt) {
690:            }
691:
692:            public void mouseReleased(MouseEvent evt) {
693:            }
694:
695:            public void mousePressed(MouseEvent evt) {
696:                if (evt.getButton() == evt.BUTTON3) {
697:                    if (amendType == AMEND_STATIC) {
698:                        showStaticPopup(evt);
699:                    } else if (amendType == AMEND_DATABASE) {
700:                        showDatabasePopup(evt);
701:                    }
702:                }
703:            }
704:
705:            public void showStaticPopup(MouseEvent evt) {
706:                String dataName = getTreePath();
707:                if (dataName.compareTo("") == 0) {
708:                    hideDataPanels(null);
709:                    mnuDatasets.show(dataTree, evt.getX(), evt.getY());
710:                } else {
711:                    XModel model = (XModel) editModel.get(dataName);
712:                    if (model.getTagName() == null) {
713:                        hideDataPanels(null);
714:                        mnuDatasets.show(dataTree, evt.getX(), evt.getY());
715:                    } else if (model.getTagName().compareTo("dataset") == 0) {
716:                        amendModel = (XBaseModel) model;
717:                        mainModel = (XModel) currentProject.getModel().get(
718:                                dataName);
719:                        mnuDataset.show(dataTree, evt.getX(), evt.getY());
720:                    } else if (model.getTagName().compareTo("data") == 0) {
721:                        hideDataPanels(pnlDataItem);
722:                        txtDataItemValue.setText((String) model.get());
723:                        amendModel = (XBaseModel) model;
724:                        mainModel = (XModel) currentProject.getModel().get(
725:                                dataName);
726:                        mnuDelete.show(dataTree, evt.getX(), evt.getY());
727:                    } else if (model.getTagName().compareTo("list") == 0) {
728:                        hideDataPanels(pnlList);
729:                        populateList(model);
730:                        amendModel = (XBaseModel) model;
731:                        mainModel = (XModel) currentProject.getModel().get(
732:                                dataName);
733:                        mnuDelete.show(dataTree, evt.getX(), evt.getY());
734:                    }
735:                }
736:            }
737:
738:            public void showDatabasePopup(MouseEvent evt) {
739:                DefaultMutableTreeNode nod = (DefaultMutableTreeNode) dataTree
740:                        .getSelectionPath().getLastPathComponent();
741:
742:                if (nod.isRoot())
743:                    mnuDatabase.show(dataTree, evt.getX(), evt.getY());
744:                else
745:                    mnuDelete.show(dataTree, evt.getX(), evt.getY());
746:            }
747:
748:            public void keyReleased(KeyEvent evt) {
749:                if (evt.getSource().equals(txtDataItemValue)) {
750:                    amendModel.set(txtDataItemValue.getText());
751:                    mainModel.set(txtDataItemValue.getText());
752:                } else if (evt.getSource().equals(txtConnURL)) {
753:                    currentDBElement.setAttribute("url", txtConnURL.getText());
754:                } else if (evt.getSource().equals(txtConnUser)) {
755:                    currentDBElement
756:                            .setAttribute("user", txtConnUser.getText());
757:                } else if (evt.getSource().equals(txtConnPwd)) {
758:                    currentDBElement.setAttribute("pwd", txtConnPwd.getText());
759:                } else if (evt.getSource().equals(txtFromTable)) {
760:                    currentDBElement.setAttribute("from", txtFromTable
761:                            .getText());
762:                } else if (evt.getSource().equals(txtWhere)) {
763:                    currentDBElement.setAttribute("where", txtWhere.getText());
764:                }
765:            }
766:
767:            public void mouseClicked(MouseEvent evt) {
768:            }
769:
770:            public void keyPressed(KeyEvent evt) {
771:            }
772:
773:            public void keyTyped(KeyEvent evt) {
774:            }
775:
776:            public void itemStateChanged(ItemEvent evt) {
777:                if (cmbConnections.getSelectedItem() != null)
778:                    currentDBElement.setAttribute("conn", cmbConnections
779:                            .getSelectedItem().toString());
780:            }
781:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.