KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ui > logicalview > entres > CallEjbDialog


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.ejbcore.ui.logicalview.entres;
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.List JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import org.netbeans.api.project.FileOwnerQuery;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.api.project.ProjectUtils;
30 import org.netbeans.modules.j2ee.api.ejbjar.EjbReference;
31 import org.openide.DialogDescriptor;
32 import org.openide.loaders.DataObject;
33 import org.openide.nodes.Children;
34 import org.openide.nodes.Node;
35 import org.openide.util.HelpCtx;
36 import org.openide.util.NbBundle;
37 import org.netbeans.modules.j2ee.ejbcore.Utils;
38 import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer;
39 import org.openide.DialogDisplayer;
40 import org.openide.NotifyDescriptor;
41 import org.openide.filesystems.FileObject;
42 import org.openide.nodes.AbstractNode;
43 import org.openide.nodes.FilterNode;
44
45 /**
46  * Handling of CallEjbDialog used from CallEjbAction and
47  * EjbReferenceTableModel from DDLoaders
48  *
49  * @author Martin Adamek
50  */

51 public class CallEjbDialog {
52     
53     public boolean open(FileObject fileObject, String JavaDoc className, String JavaDoc title) throws IOException JavaDoc {
54         Project enterpriseProject = FileOwnerQuery.getOwner(fileObject);
55         
56         Project[] allProjects = Utils.getCallableEjbProjects(enterpriseProject);
57         List JavaDoc<Node> ejbProjectNodes = new LinkedList JavaDoc<Node>();
58         
59         for (int i = 0; i < allProjects.length; i++) {
60             Node projectView = new EjbsNode(allProjects[i]);
61             ejbProjectNodes.add(new FilterNode(projectView, new EjbChildren(projectView)) {
62                 public Action JavaDoc[] getActions(boolean context) {
63                     return new Action JavaDoc[0];
64                 }
65             });
66         }
67         
68         Children.Array children = new Children.Array();
69         children.add(ejbProjectNodes.toArray(new Node[ejbProjectNodes.size()]));
70         Node root = new AbstractNode(children);
71         root.setDisplayName(NbBundle.getMessage(CallEjbDialog.class, "LBL_EJBModules"));
72         EnterpriseReferenceContainer erc = (EnterpriseReferenceContainer)
73         enterpriseProject.getLookup().lookup(EnterpriseReferenceContainer.class);
74         boolean isJavaEE5orHigher = Utils.isJavaEE5orHigher(enterpriseProject);
75         CallEjbPanel panel = new CallEjbPanel(fileObject, root, isJavaEE5orHigher ? null : erc.getServiceLocatorName(), className);
76         if (isJavaEE5orHigher) {
77             panel.disableServiceLocator();
78         }
79         
80         final DialogDescriptor dialogDescriptor = new DialogDescriptor(
81                 panel,
82                 title,
83                 true,
84                 DialogDescriptor.OK_CANCEL_OPTION,
85                 DialogDescriptor.OK_OPTION,
86                 DialogDescriptor.DEFAULT_ALIGN,
87                 new HelpCtx(CallEjbPanel.class),
88                 null
89                 );
90         
91         panel.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
92             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
93                 if (evt.getPropertyName().equals(CallEjbPanel.IS_VALID)) {
94                     Object JavaDoc newvalue = evt.getNewValue();
95                     if ((newvalue != null) && (newvalue instanceof Boolean JavaDoc)) {
96                         dialogDescriptor.setValid(((Boolean JavaDoc)newvalue).booleanValue());
97                     }
98                 }
99             }
100         });
101         
102         panel.validateReferences();
103         
104         Object JavaDoc button = DialogDisplayer.getDefault().notify(dialogDescriptor);
105         if (button != NotifyDescriptor.OK_OPTION) {
106             return false;
107         }
108         Node ejbNode = panel.getEjb();
109         boolean throwExceptions = !panel.convertToRuntime();
110         EjbReference ref = (EjbReference) ejbNode.getCookie(EjbReference.class);
111         String JavaDoc referenceNameFromPanel = panel.getReferenceName();
112         if (referenceNameFromPanel != null && referenceNameFromPanel.trim().equals("")) {
113             referenceNameFromPanel = null;
114         }
115         DataObject dataObject = (DataObject) ejbNode.getCookie(DataObject.class);
116         Project nodeProject = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
117         
118         Utils.addReference(fileObject, className, ref, panel.getServiceLocator(),
119                 panel.isRemoteInterfaceSelected(), throwExceptions,
120                 referenceNameFromPanel, nodeProject);
121         return true;
122     }
123     
124     private class EjbsNode extends AbstractNode {
125         public EjbsNode(Project project) {
126             super(new EJBListViewChildren(project));
127             setIconBaseWithExtension( "org/netbeans/modules/j2ee/ejbjarproject/ui/resources/ejbjarProjectIcon.gif" ); // NOI18N
128
super.setName( ProjectUtils.getInformation( project ).getDisplayName() );
129         }
130     }
131     
132 }
133
Popular Tags