1 19 20 package org.netbeans.modules.j2ee.persistence.unit; 21 22 import java.awt.Component ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import java.util.Set ; 26 import javax.swing.DefaultListCellRenderer ; 27 import javax.swing.DefaultListModel ; 28 import javax.swing.JList ; 29 import javax.swing.ListCellRenderer ; 30 import org.netbeans.modules.j2ee.persistence.dd.PersistenceUtils; 31 import org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity; 32 33 38 public class AddEntityPanel extends javax.swing.JPanel { 39 40 41 public AddEntityPanel(Set <Entity> entityClasses) { 42 initComponents(); 43 List <Entity> sortedEntityClasses = PersistenceUtils.sortEntityClasses(entityClasses); 44 DefaultListModel model = new DefaultListModel (); 45 for (Entity each : sortedEntityClasses) { 46 model.addElement(each); 47 } 48 this.entityList.setModel(model); 49 this.entityList.setCellRenderer(new EntityListCellRenderer()); 50 } 51 52 55 public List <String > getSelectedEntityClasses(){ 56 List <String > result = new ArrayList <String >(); 57 for (Object elem : entityList.getSelectedValues()) { 58 result.add(((Entity) elem).getClass2()); 59 } 60 return result; 61 } 62 63 68 private void initComponents() { 70 jScrollPane1 = new javax.swing.JScrollPane (); 71 entityList = new javax.swing.JList (); 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 } 93 94 private javax.swing.JList entityList; 96 private javax.swing.JScrollPane jScrollPane1; 97 99 100 private static class EntityListCellRenderer extends DefaultListCellRenderer implements ListCellRenderer { 101 102 public Component getListCellRendererComponent(JList list, Object 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 |