KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Set JavaDoc;
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 /**
40  * Dialog for adding entities into persistence unit.
41  *
42  * @author Erno Mononen
43  */

44 public class AddEntityDialog {
45     
46     private Project project;
47     private List JavaDoc existingClassNames;
48     
49     /** Creates a new instance of AddClassDialog */
50     public AddEntityDialog(Project project, String JavaDoc[] existingClassNames) {
51         this.project = project;
52         this.existingClassNames = Arrays.asList(existingClassNames);
53     }
54     
55     /**
56      * Opens dialog for adding entities.
57      * @return fully qualified names of the selected entities' classes.
58      */

59     public List JavaDoc<String JavaDoc> open(){
60         Set JavaDoc<Entity> entities = null;
61         try {
62             entities = new HashSet JavaDoc(PersistenceUtils.getEntityClasses(project));
63             for (Iterator JavaDoc<Entity> i = entities.iterator(); i.hasNext();) {
64                 if (existingClassNames.contains(i.next().getClass2())) {
65                     i.remove();
66                 }
67             }
68         } catch (IOException JavaDoc 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 JavaDoc 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