1 19 20 package org.netbeans.modules.j2ee.persistence.unit; 21 22 import java.io.IOException ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Set ; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.modules.j2ee.persistence.dd.PersistenceUtils; 31 import org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity; 32 import org.openide.DialogDescriptor; 33 import org.openide.DialogDisplayer; 34 import org.openide.ErrorManager; 35 import org.openide.NotifyDescriptor; 36 import org.openide.util.HelpCtx; 37 import org.openide.util.NbBundle; 38 39 44 public class AddEntityDialog { 45 46 private Project project; 47 private List existingClassNames; 48 49 50 public AddEntityDialog(Project project, String [] existingClassNames) { 51 this.project = project; 52 this.existingClassNames = Arrays.asList(existingClassNames); 53 } 54 55 59 public List <String > open(){ 60 Set <Entity> entities = null; 61 try { 62 entities = new HashSet (PersistenceUtils.getEntityClasses(project)); 63 for (Iterator <Entity> i = entities.iterator(); i.hasNext();) { 64 if (existingClassNames.contains(i.next().getClass2())) { 65 i.remove(); 66 } 67 } 68 } catch (IOException e) { 69 ErrorManager.getDefault().notify(e); 70 entities = Collections.emptySet(); 71 } 72 AddEntityPanel panel = new AddEntityPanel(entities); 73 74 final DialogDescriptor nd = new DialogDescriptor( 75 panel, 76 NbBundle.getMessage(AddEntityDialog.class, "LBL_AddEntity"), 77 true, 78 DialogDescriptor.OK_CANCEL_OPTION, 79 DialogDescriptor.OK_OPTION, 80 DialogDescriptor.DEFAULT_ALIGN, 81 new HelpCtx(AddEntityPanel.class), 82 null 83 ); 84 85 Object button = DialogDisplayer.getDefault().notify(nd); 86 if (button != NotifyDescriptor.OK_OPTION) { 87 return Collections.emptyList(); 88 } 89 90 return panel.getSelectedEntityClasses(); 91 } 92 93 } 94 | Popular Tags |