1 19 20 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres; 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import java.io.IOException ; 24 import java.util.LinkedList ; 25 import java.util.List ; 26 import javax.swing.Action ; 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 51 public class CallEjbDialog { 52 53 public boolean open(FileObject fileObject, String className, String title) throws IOException { 54 Project enterpriseProject = FileOwnerQuery.getOwner(fileObject); 55 56 Project[] allProjects = Utils.getCallableEjbProjects(enterpriseProject); 57 List <Node> ejbProjectNodes = new LinkedList <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 [] getActions(boolean context) { 63 return new Action [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 () { 92 public void propertyChange(PropertyChangeEvent evt) { 93 if (evt.getPropertyName().equals(CallEjbPanel.IS_VALID)) { 94 Object newvalue = evt.getNewValue(); 95 if ((newvalue != null) && (newvalue instanceof Boolean )) { 96 dialogDescriptor.setValid(((Boolean )newvalue).booleanValue()); 97 } 98 } 99 } 100 }); 101 102 panel.validateReferences(); 103 104 Object 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 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" ); super.setName( ProjectUtils.getInformation( project ).getDisplayName() ); 129 } 130 } 131 132 } 133 | Popular Tags |