1 package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel; 2 3 17 18 import org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel.*; 19 import org.apache.ojb.tools.mapping.reversedb2.datatransfer.*; 20 import org.apache.ojb.tools.mapping.reversedb2.dnd2.*; 21 import org.apache.ojb.broker.util.ClassHelper; 22 23 27 public class ReverseDbNodesToOjbMetaDropWorker implements DropPasteWorkerInterface 28 { 29 30 public ReverseDbNodesToOjbMetaDropWorker() 31 { 32 } 33 34 public int getAcceptableActions (java.awt.Component c) 35 { 36 return DnDWorkerConstants.DRAG_MOVE | DnDWorkerConstants.DRAG_COPY ; 37 } 38 39 public int getAcceptableActions (java.awt.Component c, java.awt.datatransfer.DataFlavor [] flavor) 40 { 41 for (int j = 0; j < flavor.length; j++) 42 { 43 System.err.println("ReverseDbNodesToOjbMetaDropWorker.getAcceptableActions() flavor " + flavor[j] + " is " + flavor[j].isMimeTypeEqual(TransferableDBMetaTreeNodes.DBMETATABLENODE_FLAVOR_REMOTE)); 44 if (flavor[j].equals (TransferableDBMetaTreeNodes.DBMETATABLENODE_FLAVOR_REMOTE)) 45 return DnDWorkerConstants.DRAG_MOVE | DnDWorkerConstants.DRAG_COPY; 46 } 47 return DnDWorkerConstants.NONE; 48 } 49 50 public java.awt.datatransfer.DataFlavor getSupportedDataFlavor () 51 { 52 return TransferableDBMetaTreeNodes.DBMETATABLENODE_FLAVOR_REMOTE; 53 } 54 55 private java.util.Enumeration getTableNodes(java.util.Enumeration nodes) 56 { 57 java.util.Vector tableVector = new java.util.Vector (); 58 while(nodes.hasMoreElements()) 59 { 60 ReverseDbTreeNode aNode = (ReverseDbTreeNode)nodes.nextElement(); 61 if (aNode instanceof DBMetaRootNode 62 || aNode instanceof DBMetaCatalogNode) 64 { 65 java.util.Enumeration e = getTableNodes(aNode.children()); 66 while (e.hasMoreElements()) tableVector.add(e.nextElement()); 67 } 68 else if (aNode instanceof DBMetaSchemaNode) 69 { 70 java.util.Enumeration e = aNode.children(); 71 while (e.hasMoreElements()) tableVector.add(e.nextElement()); 72 } 73 else if (aNode instanceof DBMetaTableNode) 74 { 75 return java.util.Collections.enumeration(java.util.Collections.singletonList(aNode)); 76 } 77 } 78 return tableVector.elements(); 79 80 } 81 82 public boolean importData (java.awt.Component c, java.awt.datatransfer.Transferable t, int action) 83 { 84 if (t.isDataFlavorSupported(TransferableDBMetaTreeNodes.DBMETATABLENODE_FLAVOR_REMOTE) && 85 c instanceof javax.swing.JTree && 86 ((javax.swing.JTree )c).getModel() instanceof OjbMetaDataTreeModel) 87 { 88 OjbMetaDataTreeModel treeModel = (OjbMetaDataTreeModel)((javax.swing.JTree )c).getModel(); 89 OjbMetaRootNode rootNode = (OjbMetaRootNode)treeModel.getRoot(); 90 ReverseDbTreeNode[] nodes; 91 try 92 { 93 nodes = (ReverseDbTreeNode[])t.getTransferData(TransferableDBMetaTreeNodes.DBMETATABLENODE_FLAVOR_REMOTE); 94 } 95 catch (java.awt.datatransfer.UnsupportedFlavorException ufex) 96 { 97 ufex.printStackTrace(); 98 return false; 99 } 100 catch (java.io.IOException ioex) 101 { 102 ioex.printStackTrace(); 103 return false; 104 } 105 java.util.Enumeration e = getTableNodes(java.util.Collections.enumeration(java.util.Arrays.asList(nodes))); 106 while (e.hasMoreElements()) 107 { 108 Object o = e.nextElement(); 109 if (o instanceof DBMetaTableNode) 110 { 111 DBMetaTableNode dbTable = (DBMetaTableNode)o; 112 System.err.println("Adding " + dbTable); 113 org.apache.ojb.broker.metadata.ClassDescriptor cld = 114 new org.apache.ojb.broker.metadata.ClassDescriptor(treeModel.getRepository()); 115 cld.setTableName(dbTable.getTableName()); 116 try 117 { 118 cld.setClassOfObject(ClassHelper.getClass(dbTable.getTableName())); 119 } 120 catch (ClassNotFoundException e1) 121 { 122 e1.printStackTrace(); 123 } 124 treeModel.getRepository().put(cld.getClassNameOfObject(), cld); 125 rootNode.addClassDescriptor(cld); 126 } 127 } 128 return true; 129 } 130 else 131 { 132 System.err.println("Cannot import data"); 133 return false; 134 } 135 } 136 } 137 | Popular Tags |