1 15 16 package org.apache.ojb.tools.mapping.reversedb2.gui; 17 import java.awt.dnd.DragGestureListener ; 18 import java.awt.dnd.DragSource ; 19 import java.awt.dnd.DragSourceListener ; 20 21 import org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel.DBMetaCatalogNode; 22 import org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel.DBMetaRootNode; 23 import org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel.DBMetaSchemaNode; 24 import org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel.DBMetaTableNode; 25 import org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel.DatabaseMetaDataTreeModel; 26 import org.apache.ojb.tools.mapping.reversedb2.dnd2.DragHelper; 27 import org.apache.ojb.tools.mapping.reversedb2.dnd2.DropTargetHelper; 28 import org.apache.ojb.tools.mapping.reversedb2.dnd2.ReverseDbNodesDragWorker; 29 import org.apache.ojb.tools.mapping.reversedb2.dnd2.ReverseDbNodesDropWorker; 30 import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.PropertyEditor; 31 import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.PropertyEditorTarget; 32 33 37 public class JIFrmDatabase extends javax.swing.JInternalFrame 38 { 39 private java.sql.Connection jdbcConnection; 40 41 private DragSource dragSource; 42 private DragGestureListener dgListener; 43 private DragSourceListener dsListener; 44 45 private java.util.HashMap hmPropertyEditors = new java.util.HashMap (); 46 47 48 public JIFrmDatabase(java.sql.Connection pjdbcConnection) 49 { 50 this.jdbcConnection = pjdbcConnection; 51 initComponents(); 52 try 53 { 54 this.setTitle("Database: " + jdbcConnection.getMetaData().getURL()); 55 DatabaseMetaDataTreeModel model = new DatabaseMetaDataTreeModel(this.jdbcConnection.getMetaData()); 56 model.addStatusMessageListener(new org.apache.ojb.tools.mapping.reversedb2.events.StatusMessageAdapter() 57 { 58 public void statusMessageReceived(final String s) 59 { 60 javax.swing.SwingUtilities.invokeLater(new Runnable () 61 { 62 public void run() 63 { 64 jTextField1.setText(s); 65 } 66 }); 67 } 68 }); 69 this.jTreeDatabase.setModel(model); 70 } 71 catch (java.sql.SQLException sqlEx) 72 { 73 this.setTitle("Database: unknown"); 74 this.jTreeDatabase.setModel(new javax.swing.tree.DefaultTreeModel (new javax.swing.tree.DefaultMutableTreeNode ("Error..."))); 75 } 76 77 new DragHelper(new ReverseDbNodesDragWorker()).registerComponent(jTreeDatabase); 80 81 DropTargetHelper helper = new DropTargetHelper(); 83 helper.registerDropPasteWorker (new ReverseDbNodesDropWorker()); 84 jTreeDatabase.setDropTarget(helper.getDropTarget ()); 85 86 } 87 88 private java.util.Collection getTableNodes(Object o) 89 { 90 if (o instanceof DBMetaRootNode || 91 o instanceof DBMetaCatalogNode || 92 o instanceof DBMetaSchemaNode) 93 { 94 java.util.ArrayList alTables = new java.util.ArrayList (); 95 java.util.Enumeration e = ((javax.swing.tree.TreeNode )o).children(); 96 while (e.hasMoreElements()) 97 { 98 alTables.addAll(getTableNodes(e.nextElement())); 99 } 100 return alTables; 101 } 102 else if (o instanceof DBMetaTableNode) 103 { 104 return java.util.Collections.singleton(o); 105 } 106 else 107 { 108 return null; 109 } 110 } 111 112 117 private void initComponents() { 119 jSplitPane1 = new javax.swing.JSplitPane (); 120 jScrlTree = new javax.swing.JScrollPane (); 121 jTreeDatabase = new javax.swing.JTree (); 122 jScrlProperty = new javax.swing.JScrollPane (); 123 jToolBar1 = new javax.swing.JToolBar (); 124 jTextField1 = new javax.swing.JTextField (); 125 126 setClosable(true); 127 setIconifiable(true); 128 setMaximizable(true); 129 setResizable(true); 130 setTitle("Database"); 131 setPreferredSize(new java.awt.Dimension (300, 300)); 132 jTreeDatabase.setRootVisible(false); 133 jTreeDatabase.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener () 134 { 135 public void valueChanged(javax.swing.event.TreeSelectionEvent evt) 136 { 137 jTreeDatabaseValueChanged(evt); 138 } 139 }); 140 141 jScrlTree.setViewportView(jTreeDatabase); 142 143 jSplitPane1.setLeftComponent(jScrlTree); 144 145 jSplitPane1.setRightComponent(jScrlProperty); 146 147 getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER); 148 149 jTextField1.setEditable(false); 150 jTextField1.setText("jTextField1"); 151 jTextField1.setBorder(null); 152 jTextField1.setOpaque(false); 153 jToolBar1.add(jTextField1); 154 155 getContentPane().add(jToolBar1, java.awt.BorderLayout.SOUTH); 156 157 pack(); 158 } 160 private void jTreeDatabaseValueChanged (javax.swing.event.TreeSelectionEvent evt) { Object selectedObject = evt.getPath().getLastPathComponent(); 164 if (selectedObject instanceof PropertyEditorTarget) 165 { 166 PropertyEditorTarget p = (PropertyEditorTarget)selectedObject; 167 if (p.getPropertyEditorClass() != null) 168 { 169 try 170 { 171 if(!this.hmPropertyEditors.containsKey(p.getPropertyEditorClass())) 172 { 173 this.hmPropertyEditors.put(p.getPropertyEditorClass(), p.getPropertyEditorClass().newInstance()); 174 } 175 PropertyEditor propertyEditor = (PropertyEditor)hmPropertyEditors.get(p.getPropertyEditorClass()); 176 this.jScrlProperty.setViewportView(propertyEditor); 177 propertyEditor.setEditorTarget(p); 178 } 179 catch (Throwable t) 180 { 181 t.printStackTrace(); 182 this.jScrlProperty.setViewportView(null); 183 } 184 } 185 else 186 { 187 this.jScrlProperty.setViewportView(null); 188 } 189 } 190 else 191 { 192 this.jScrlProperty.setViewportView(null); 193 } 194 } 196 197 private javax.swing.JSplitPane jSplitPane1; 199 private javax.swing.JScrollPane jScrlTree; 200 private javax.swing.JTextField jTextField1; 201 private javax.swing.JScrollPane jScrlProperty; 202 private javax.swing.JTree jTreeDatabase; 203 private javax.swing.JToolBar jToolBar1; 204 206 } 207 | Popular Tags |