1 15 16 package org.apache.ojb.tools.mapping.reversedb2.gui; 17 import org.apache.ojb.broker.metadata.DescriptorRepository; 18 import org.apache.ojb.tools.mapping.reversedb2.actions.ActionSaveAsOJBRepository; 19 import org.apache.ojb.tools.mapping.reversedb2.dnd2.DragHelper; 20 import org.apache.ojb.tools.mapping.reversedb2.dnd2.DropTargetHelper; 21 import org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel.OjbMetaTreeNodesDragWorker; 22 import org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel.ReverseDbNodesToOjbMetaDropWorker; 23 import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.PropertyEditor; 24 import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.PropertyEditorTarget; 25 26 30 public class JIFrmOJBRepository extends javax.swing.JInternalFrame { 31 32 private javax.swing.tree.DefaultMutableTreeNode rootNode = 33 new javax.swing.tree.DefaultMutableTreeNode ("Root"); 34 35 private java.util.HashMap hmCachedPopupMenus = new java.util.HashMap (); 36 37 private java.util.HashMap hmPropertyEditors = new java.util.HashMap (); 38 39 private DescriptorRepository aRepository; 40 41 42 public JIFrmOJBRepository(DescriptorRepository repository) 43 { 44 this.aRepository = repository; 45 initComponents(); 46 jTree1.setModel(new org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel.OjbMetaDataTreeModel(repository)); 47 DropTargetHelper helper = new DropTargetHelper(); 48 helper.registerDropPasteWorker (new ReverseDbNodesToOjbMetaDropWorker()); 49 jTree1.setDropTarget(helper.getDropTarget ()); 50 53 56 new DragHelper(new OjbMetaTreeNodesDragWorker()).registerComponent(jTree1); 57 58 setJMenuBar(this.jMenuBar1); 59 pack(); 60 } 61 62 67 private void initComponents() { 69 jMenuBar1 = new javax.swing.JMenuBar (); 70 mnuFile = new javax.swing.JMenu (); 71 mnuFileSave = new javax.swing.JMenuItem (); 72 jSplitPane1 = new javax.swing.JSplitPane (); 73 jScrollPane1 = new javax.swing.JScrollPane (); 74 jTree1 = new javax.swing.JTree (); 75 jScrlProperty = new javax.swing.JScrollPane (); 76 77 mnuFile.setMnemonic('F'); 78 mnuFile.setText("File"); 79 mnuFileSave.setAction(new ActionSaveAsOJBRepository(aRepository)); 80 mnuFile.add(mnuFileSave); 81 82 jMenuBar1.add(mnuFile); 83 84 setClosable(true); 85 setIconifiable(true); 86 setMaximizable(true); 87 setResizable(true); 88 jTree1.addMouseListener(new java.awt.event.MouseAdapter () 89 { 90 public void mousePressed(java.awt.event.MouseEvent evt) 91 { 92 jTree1MousePressed(evt); 93 } 94 public void mouseReleased(java.awt.event.MouseEvent evt) 95 { 96 jTree1MousePressed(evt); 97 } 98 }); 99 100 jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener () 101 { 102 public void valueChanged(javax.swing.event.TreeSelectionEvent evt) 103 { 104 jTree1ValueChanged(evt); 105 } 106 }); 107 108 jScrollPane1.setViewportView(jTree1); 109 110 jSplitPane1.setLeftComponent(jScrollPane1); 111 112 jSplitPane1.setRightComponent(jScrlProperty); 113 114 getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER); 115 116 pack(); 117 } 119 private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt) { Object selectedObject = evt.getPath().getLastPathComponent(); 123 if (selectedObject instanceof PropertyEditorTarget) 124 { 125 PropertyEditorTarget p = (PropertyEditorTarget)selectedObject; 126 if (p.getPropertyEditorClass() != null) 127 { 128 try 129 { 130 if(!this.hmPropertyEditors.containsKey(p.getPropertyEditorClass())) 131 { 132 this.hmPropertyEditors.put(p.getPropertyEditorClass(), p.getPropertyEditorClass().newInstance()); 133 } 134 PropertyEditor propertyEditor = (PropertyEditor)hmPropertyEditors.get(p.getPropertyEditorClass()); 135 this.jScrlProperty.setViewportView(propertyEditor); 136 propertyEditor.setEditorTarget(p); 137 } 138 catch (Throwable t) 139 { 140 t.printStackTrace(); 141 this.jScrlProperty.setViewportView(null); 142 } 143 } 144 else 145 { 146 this.jScrlProperty.setViewportView(null); 147 } 148 } 149 else 150 { 151 this.jScrlProperty.setViewportView(null); 152 } 153 } 155 private javax.swing.JPopupMenu createPopupMenuForActionTarget(org.apache.ojb.tools.mapping.reversedb2.ActionTarget at) 156 { 157 javax.swing.JPopupMenu createdMenu = new javax.swing.JPopupMenu (); 158 java.util.Iterator it = at.getActions(); 159 while (it.hasNext()) 160 { 161 createdMenu.add((javax.swing.Action )it.next()); 162 } 163 return createdMenu; 164 } 165 166 private void jTree1MousePressed(java.awt.event.MouseEvent evt) { if (evt.isPopupTrigger()) 170 { 171 javax.swing.tree.TreePath selPath = jTree1.getPathForLocation(evt.getX(), evt.getY()); 172 if (selPath != null) 173 { 174 if (selPath.getLastPathComponent() instanceof org.apache.ojb.tools.mapping.reversedb2.ActionTarget) 175 { 176 org.apache.ojb.tools.mapping.reversedb2.ActionTarget at = 177 (org.apache.ojb.tools.mapping.reversedb2.ActionTarget)selPath.getLastPathComponent(); 178 javax.swing.JPopupMenu popupMenu = null; 179 if (at.actionListStatic()) 180 { 181 popupMenu = (javax.swing.JPopupMenu ) this.hmCachedPopupMenus.get(at.getClass()); 182 if (popupMenu == null) 183 { 184 popupMenu = createPopupMenuForActionTarget(at); 185 this.hmCachedPopupMenus.put(at.getClass(), popupMenu); 186 } 187 } 188 else if (at.actionListCachable()) 189 { 190 popupMenu = (javax.swing.JPopupMenu ) this.hmCachedPopupMenus.get(at); 191 if (popupMenu == null) 192 { 193 popupMenu = createPopupMenuForActionTarget(at); 194 this.hmCachedPopupMenus.put(at, popupMenu); 195 } 196 } 197 else 198 { 199 popupMenu = createPopupMenuForActionTarget(at); 200 } 201 jTree1.setSelectionPath(selPath); 202 popupMenu.show(jTree1, evt.getX(), evt.getY()); 203 int posY = evt.getY(); 204 while ((popupMenu.getLocationOnScreen().y + 205 popupMenu.getSize().height) > 206 getToolkit().getScreenSize().height) 207 { 208 posY--; 209 popupMenu.show(jTree1, evt.getX(), posY); 211 } 212 } 213 } 214 } 215 216 } 218 219 private javax.swing.JScrollPane jScrollPane1; 221 private javax.swing.JMenuItem mnuFileSave; 222 private javax.swing.JSplitPane jSplitPane1; 223 private javax.swing.JScrollPane jScrlProperty; 224 private javax.swing.JTree jTree1; 225 private javax.swing.JMenu mnuFile; 226 private javax.swing.JMenuBar jMenuBar1; 227 229 } 230 | Popular Tags |