View Javadoc

1   /*   Copyright (C) 2003 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   */
17  
18  package com.finalist.jaggenerator;
19  
20  import com.finalist.jaggenerator.modules.*;
21  
22  import java.util.*;
23  import javax.swing.*;
24  
25  /***
26   *
27   * @author  hillie
28   */
29  public class SelectRefs extends javax.swing.JDialog {
30     private DefaultListModel listModel = new DefaultListModel();
31     private ArrayList refList;
32  
33  
34     /*** Creates new form SelectRefs for Sesson EJBs to design a Session Facade to Entity EJBs. */
35     public SelectRefs(JFrame parent, Session session, ArrayList refList) {
36        super(parent, true);
37        this.setTitle("Select entity bean(s)");
38        this.refList = refList;
39        initComponents();
40        setBounds(50, 10, 200, 700);
41        Root root = (Root) session.getRoot();
42        ArrayList refs = root.getRefs();
43        for (int i = 0; i < refs.size(); i++) {
44           listModel.addElement((String) refs.get(i));
45        }
46        list.setModel(listModel);
47        refList = refs;
48     }
49  
50  
51     /*** Creates new form SelectRefs for CMR in Entity EJBs */
52     public SelectRefs(JFrame parent, Entity entity, ArrayList refList) {
53        super(parent, true);
54        this.refList = refList;
55        initComponents();
56        setBounds(50, 10, 200, 700);
57        Root root = (Root) entity.getRoot();
58        ArrayList refs = root.getRefs();
59        for (int i = 0; i < refs.size(); i++) {
60           listModel.addElement((String) refs.get(i));
61        }
62        list.setModel(listModel);
63        refList = refs;
64     }
65  
66  
67     /*** This method is called from within the constructor to
68      * initialize the form.
69      * WARNING: Do NOT modify this code. The content of this method is
70      * always regenerated by the Form Editor.
71      */
72     private void initComponents() {//GEN-BEGIN:initComponents
73        java.awt.GridBagConstraints gridBagConstraints;
74  
75        selectButton = new javax.swing.JButton();
76        jScrollPane1 = new javax.swing.JScrollPane();
77        list = new javax.swing.JList();
78  
79        getContentPane().setLayout(new java.awt.GridBagLayout());
80  
81        addWindowListener(new java.awt.event.WindowAdapter() {
82           public void windowClosing(java.awt.event.WindowEvent evt) {
83              closeDialog(evt);
84           }
85        });
86  
87        selectButton.setText("Select");
88        selectButton.addActionListener(new java.awt.event.ActionListener() {
89           public void actionPerformed(java.awt.event.ActionEvent evt) {
90              selectButtonActionPerformed(evt);
91           }
92        });
93  
94        gridBagConstraints = new java.awt.GridBagConstraints();
95        gridBagConstraints.gridx = 0;
96        gridBagConstraints.gridy = 1;
97        gridBagConstraints.ipadx = 2;
98        gridBagConstraints.ipady = 2;
99        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
100       gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
101       getContentPane().add(selectButton, gridBagConstraints);
102 
103       jScrollPane1.setViewportView(list);
104 
105       gridBagConstraints = new java.awt.GridBagConstraints();
106       gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
107       gridBagConstraints.weightx = 1.0;
108       gridBagConstraints.weighty = 1.0;
109       getContentPane().add(jScrollPane1, gridBagConstraints);
110 
111       pack();
112    }//GEN-END:initComponents
113 
114 
115    private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
116       Object[] refs = list.getSelectedValues();
117       for (int i = 0; i < refs.length; i++) {
118          listModel.addElement((String) refs[i]);
119          this.refList.add((String) refs[i]);
120       }
121       list.setModel(listModel);
122       dispose();
123    }//GEN-LAST:event_selectButtonActionPerformed
124 
125 
126    /*** Closes the dialog */
127    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
128 
129    }//GEN-LAST:event_closeDialog
130 
131 
132    // Variables declaration - do not modify//GEN-BEGIN:variables
133    private javax.swing.JList list;
134    private javax.swing.JScrollPane jScrollPane1;
135    private javax.swing.JButton selectButton;
136    // End of variables declaration//GEN-END:variables
137 
138 }