001: /* Copyright 2002-2005 The Apache Software Foundation
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.apache.ojb.tools.mapping.reversedb2.gui;
017:
018: import org.apache.ojb.broker.metadata.DescriptorRepository;
019: import org.apache.ojb.tools.mapping.reversedb2.actions.ActionSaveAsOJBRepository;
020: import org.apache.ojb.tools.mapping.reversedb2.dnd2.DragHelper;
021: import org.apache.ojb.tools.mapping.reversedb2.dnd2.DropTargetHelper;
022: import org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel.OjbMetaTreeNodesDragWorker;
023: import org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel.ReverseDbNodesToOjbMetaDropWorker;
024: import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.PropertyEditor;
025: import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.PropertyEditorTarget;
026:
027: /**
028: *
029: * @author Administrator
030: */
031: public class JIFrmOJBRepository extends javax.swing.JInternalFrame {
032:
033: private javax.swing.tree.DefaultMutableTreeNode rootNode = new javax.swing.tree.DefaultMutableTreeNode(
034: "Root");
035:
036: private java.util.HashMap hmCachedPopupMenus = new java.util.HashMap();
037:
038: private java.util.HashMap hmPropertyEditors = new java.util.HashMap();
039:
040: private DescriptorRepository aRepository;
041:
042: /** Creates new form JIFrmOJBRepository */
043: public JIFrmOJBRepository(DescriptorRepository repository) {
044: this .aRepository = repository;
045: initComponents();
046: jTree1
047: .setModel(new org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel.OjbMetaDataTreeModel(
048: repository));
049: DropTargetHelper helper = new DropTargetHelper();
050: helper
051: .registerDropPasteWorker(new ReverseDbNodesToOjbMetaDropWorker());
052: jTree1.setDropTarget(helper.getDropTarget());
053: /* getGlassPane().setDropTarget(helper.getDropTarget());
054: this.setDropTarget(helper.getDropTarget());
055: */
056: // this.jScrollPane1.setDropTarget(helper.getDropTarget());
057: // this.jSplitPane1.setDropTarget(helper.getDropTarget());
058: new DragHelper(new OjbMetaTreeNodesDragWorker())
059: .registerComponent(jTree1);
060:
061: setJMenuBar(this .jMenuBar1);
062: pack();
063: }
064:
065: /** This method is called from within the constructor to
066: * initialize the form.
067: * WARNING: Do NOT modify this code. The content of this method is
068: * always regenerated by the Form Editor.
069: */
070: private void initComponents()//GEN-BEGIN:initComponents
071: {
072: jMenuBar1 = new javax.swing.JMenuBar();
073: mnuFile = new javax.swing.JMenu();
074: mnuFileSave = new javax.swing.JMenuItem();
075: jSplitPane1 = new javax.swing.JSplitPane();
076: jScrollPane1 = new javax.swing.JScrollPane();
077: jTree1 = new javax.swing.JTree();
078: jScrlProperty = new javax.swing.JScrollPane();
079:
080: mnuFile.setMnemonic('F');
081: mnuFile.setText("File");
082: mnuFileSave
083: .setAction(new ActionSaveAsOJBRepository(aRepository));
084: mnuFile.add(mnuFileSave);
085:
086: jMenuBar1.add(mnuFile);
087:
088: setClosable(true);
089: setIconifiable(true);
090: setMaximizable(true);
091: setResizable(true);
092: jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
093: public void mousePressed(java.awt.event.MouseEvent evt) {
094: jTree1MousePressed(evt);
095: }
096:
097: public void mouseReleased(java.awt.event.MouseEvent evt) {
098: jTree1MousePressed(evt);
099: }
100: });
101:
102: jTree1
103: .addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
104: public void valueChanged(
105: javax.swing.event.TreeSelectionEvent evt) {
106: jTree1ValueChanged(evt);
107: }
108: });
109:
110: jScrollPane1.setViewportView(jTree1);
111:
112: jSplitPane1.setLeftComponent(jScrollPane1);
113:
114: jSplitPane1.setRightComponent(jScrlProperty);
115:
116: getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);
117:
118: pack();
119: }//GEN-END:initComponents
120:
121: private void jTree1ValueChanged(
122: javax.swing.event.TreeSelectionEvent evt)//GEN-FIRST:event_jTree1ValueChanged
123: {//GEN-HEADEREND:event_jTree1ValueChanged
124: // Add your handling code here:
125: Object selectedObject = evt.getPath().getLastPathComponent();
126: if (selectedObject instanceof PropertyEditorTarget) {
127: PropertyEditorTarget p = (PropertyEditorTarget) selectedObject;
128: if (p.getPropertyEditorClass() != null) {
129: try {
130: if (!this .hmPropertyEditors.containsKey(p
131: .getPropertyEditorClass())) {
132: this .hmPropertyEditors
133: .put(p.getPropertyEditorClass(), p
134: .getPropertyEditorClass()
135: .newInstance());
136: }
137: PropertyEditor propertyEditor = (PropertyEditor) hmPropertyEditors
138: .get(p.getPropertyEditorClass());
139: this .jScrlProperty.setViewportView(propertyEditor);
140: propertyEditor.setEditorTarget(p);
141: } catch (Throwable t) {
142: t.printStackTrace();
143: this .jScrlProperty.setViewportView(null);
144: }
145: } else {
146: this .jScrlProperty.setViewportView(null);
147: }
148: } else {
149: this .jScrlProperty.setViewportView(null);
150: }
151: }//GEN-LAST:event_jTree1ValueChanged
152:
153: private javax.swing.JPopupMenu createPopupMenuForActionTarget(
154: org.apache.ojb.tools.mapping.reversedb2.ActionTarget at) {
155: javax.swing.JPopupMenu createdMenu = new javax.swing.JPopupMenu();
156: java.util.Iterator it = at.getActions();
157: while (it.hasNext()) {
158: createdMenu.add((javax.swing.Action) it.next());
159: }
160: return createdMenu;
161: }
162:
163: private void jTree1MousePressed(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTree1MousePressed
164: {//GEN-HEADEREND:event_jTree1MousePressed
165: // Add your handling code here:
166: if (evt.isPopupTrigger()) {
167: javax.swing.tree.TreePath selPath = jTree1
168: .getPathForLocation(evt.getX(), evt.getY());
169: if (selPath != null) {
170: if (selPath.getLastPathComponent() instanceof org.apache.ojb.tools.mapping.reversedb2.ActionTarget) {
171: org.apache.ojb.tools.mapping.reversedb2.ActionTarget at = (org.apache.ojb.tools.mapping.reversedb2.ActionTarget) selPath
172: .getLastPathComponent();
173: javax.swing.JPopupMenu popupMenu = null;
174: if (at.actionListStatic()) {
175: popupMenu = (javax.swing.JPopupMenu) this .hmCachedPopupMenus
176: .get(at.getClass());
177: if (popupMenu == null) {
178: popupMenu = createPopupMenuForActionTarget(at);
179: this .hmCachedPopupMenus.put(at.getClass(),
180: popupMenu);
181: }
182: } else if (at.actionListCachable()) {
183: popupMenu = (javax.swing.JPopupMenu) this .hmCachedPopupMenus
184: .get(at);
185: if (popupMenu == null) {
186: popupMenu = createPopupMenuForActionTarget(at);
187: this .hmCachedPopupMenus.put(at, popupMenu);
188: }
189: } else {
190: popupMenu = createPopupMenuForActionTarget(at);
191: }
192: jTree1.setSelectionPath(selPath);
193: popupMenu.show(jTree1, evt.getX(), evt.getY());
194: int posY = evt.getY();
195: while ((popupMenu.getLocationOnScreen().y + popupMenu
196: .getSize().height) > getToolkit()
197: .getScreenSize().height) {
198: posY--;
199: // popupMenu.hide();
200: popupMenu.show(jTree1, evt.getX(), posY);
201: }
202: }
203: }
204: }
205:
206: }//GEN-LAST:event_jTree1MousePressed
207:
208: // Variables declaration - do not modify//GEN-BEGIN:variables
209: private javax.swing.JScrollPane jScrollPane1;
210: private javax.swing.JMenuItem mnuFileSave;
211: private javax.swing.JSplitPane jSplitPane1;
212: private javax.swing.JScrollPane jScrlProperty;
213: private javax.swing.JTree jTree1;
214: private javax.swing.JMenu mnuFile;
215: private javax.swing.JMenuBar jMenuBar1;
216: // End of variables declaration//GEN-END:variables
217:
218: }
|