KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > gui > JIFrmOJBRepository


1 /* Copyright 2002-2005 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

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 /**
27  *
28  * @author Administrator
29  */

30 public class JIFrmOJBRepository extends javax.swing.JInternalFrame JavaDoc {
31     
32     private javax.swing.tree.DefaultMutableTreeNode JavaDoc rootNode =
33         new javax.swing.tree.DefaultMutableTreeNode JavaDoc("Root");
34     
35     private java.util.HashMap JavaDoc hmCachedPopupMenus = new java.util.HashMap JavaDoc();
36     
37     private java.util.HashMap JavaDoc hmPropertyEditors = new java.util.HashMap JavaDoc();
38     
39     private DescriptorRepository aRepository;
40
41     /** Creates new form JIFrmOJBRepository */
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 /* getGlassPane().setDropTarget(helper.getDropTarget());
51         this.setDropTarget(helper.getDropTarget());
52 */

53         // this.jScrollPane1.setDropTarget(helper.getDropTarget());
54
// this.jSplitPane1.setDropTarget(helper.getDropTarget());
55

56         new DragHelper(new OjbMetaTreeNodesDragWorker()).registerComponent(jTree1);
57         
58         setJMenuBar(this.jMenuBar1);
59         pack();
60     }
61     
62     /** This method is called from within the constructor to
63      * initialize the form.
64      * WARNING: Do NOT modify this code. The content of this method is
65      * always regenerated by the Form Editor.
66      */

67     private void initComponents()//GEN-BEGIN:initComponents
68
{
69         jMenuBar1 = new javax.swing.JMenuBar JavaDoc();
70         mnuFile = new javax.swing.JMenu JavaDoc();
71         mnuFileSave = new javax.swing.JMenuItem JavaDoc();
72         jSplitPane1 = new javax.swing.JSplitPane JavaDoc();
73         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
74         jTree1 = new javax.swing.JTree JavaDoc();
75         jScrlProperty = new javax.swing.JScrollPane JavaDoc();
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 JavaDoc()
89         {
90             public void mousePressed(java.awt.event.MouseEvent JavaDoc evt)
91             {
92                 jTree1MousePressed(evt);
93             }
94             public void mouseReleased(java.awt.event.MouseEvent JavaDoc evt)
95             {
96                 jTree1MousePressed(evt);
97             }
98         });
99
100         jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener JavaDoc()
101         {
102             public void valueChanged(javax.swing.event.TreeSelectionEvent JavaDoc 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     }//GEN-END:initComponents
118

119     private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent JavaDoc evt)//GEN-FIRST:event_jTree1ValueChanged
120
{//GEN-HEADEREND:event_jTree1ValueChanged
121
// Add your handling code here:
122
Object JavaDoc 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 JavaDoc 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     }//GEN-LAST:event_jTree1ValueChanged
154

155     private javax.swing.JPopupMenu JavaDoc createPopupMenuForActionTarget(org.apache.ojb.tools.mapping.reversedb2.ActionTarget at)
156     {
157         javax.swing.JPopupMenu JavaDoc createdMenu = new javax.swing.JPopupMenu JavaDoc();
158         java.util.Iterator JavaDoc it = at.getActions();
159         while (it.hasNext())
160         {
161             createdMenu.add((javax.swing.Action JavaDoc)it.next());
162         }
163         return createdMenu;
164     }
165     
166     private void jTree1MousePressed(java.awt.event.MouseEvent JavaDoc evt)//GEN-FIRST:event_jTree1MousePressed
167
{//GEN-HEADEREND:event_jTree1MousePressed
168
// Add your handling code here:
169
if (evt.isPopupTrigger())
170         {
171             javax.swing.tree.TreePath JavaDoc 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 JavaDoc popupMenu = null;
179                     if (at.actionListStatic())
180                     {
181                         popupMenu = (javax.swing.JPopupMenu JavaDoc) 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 JavaDoc) 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.hide();
210
popupMenu.show(jTree1, evt.getX(), posY);
211                     }
212                 }
213             }
214         }
215         
216     }//GEN-LAST:event_jTree1MousePressed
217

218     
219     // Variables declaration - do not modify//GEN-BEGIN:variables
220
private javax.swing.JScrollPane JavaDoc jScrollPane1;
221     private javax.swing.JMenuItem JavaDoc mnuFileSave;
222     private javax.swing.JSplitPane JavaDoc jSplitPane1;
223     private javax.swing.JScrollPane JavaDoc jScrlProperty;
224     private javax.swing.JTree JavaDoc jTree1;
225     private javax.swing.JMenu JavaDoc mnuFile;
226     private javax.swing.JMenuBar JavaDoc jMenuBar1;
227     // End of variables declaration//GEN-END:variables
228

229 }
230
Popular Tags