KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > unit > AddEntityPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.persistence.unit;
21
22 import java.awt.Component JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.swing.DefaultListCellRenderer JavaDoc;
27 import javax.swing.DefaultListModel JavaDoc;
28 import javax.swing.JList JavaDoc;
29 import javax.swing.ListCellRenderer JavaDoc;
30 import org.netbeans.modules.j2ee.persistence.dd.PersistenceUtils;
31 import org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity;
32
33 /**
34  * Panel for adding entities to persistence unit.
35  *
36  * @author Erno Mononen
37  */

38 public class AddEntityPanel extends javax.swing.JPanel JavaDoc {
39     
40     /** Creates new form AddClassPanel */
41     public AddEntityPanel(Set JavaDoc<Entity> entityClasses) {
42         initComponents();
43         List JavaDoc<Entity> sortedEntityClasses = PersistenceUtils.sortEntityClasses(entityClasses);
44         DefaultListModel JavaDoc model = new DefaultListModel JavaDoc();
45         for (Entity each : sortedEntityClasses) {
46             model.addElement(each);
47         }
48         this.entityList.setModel(model);
49         this.entityList.setCellRenderer(new EntityListCellRenderer());
50     }
51     
52     /**
53      * @return fully qualified names of the selected entities' classes.
54      */

55     public List JavaDoc<String JavaDoc> getSelectedEntityClasses(){
56         List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>();
57         for (Object JavaDoc elem : entityList.getSelectedValues()) {
58             result.add(((Entity) elem).getClass2());
59         }
60         return result;
61     }
62     
63     /** This method is called from within the constructor to
64      * initialize the form.
65      * WARNING: Do NOT modify this code. The content of this method is
66      * always regenerated by the Form Editor.
67      */

68     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
69
private void initComponents() {
70         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
71         entityList = new javax.swing.JList JavaDoc();
72
73         jScrollPane1.setViewportView(entityList);
74
75         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
76         this.setLayout(layout);
77         layout.setHorizontalGroup(
78             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
79             .add(layout.createSequentialGroup()
80                 .addContainerGap()
81                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
82                 .addContainerGap())
83         );
84         layout.setVerticalGroup(
85             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
86             .add(layout.createSequentialGroup()
87                 .addContainerGap()
88                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 143, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
89                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
90         );
91     }// </editor-fold>//GEN-END:initComponents
92

93     
94     // Variables declaration - do not modify//GEN-BEGIN:variables
95
private javax.swing.JList JavaDoc entityList;
96     private javax.swing.JScrollPane JavaDoc jScrollPane1;
97     // End of variables declaration//GEN-END:variables
98

99
100     private static class EntityListCellRenderer extends DefaultListCellRenderer JavaDoc implements ListCellRenderer JavaDoc{
101         
102         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
103             super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
104             setText(((Entity) value).getClass2());
105             return this;
106         }
107         
108     }
109 }
110
Popular Tags