1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.api.project.FileOwnerQuery; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 25 import org.netbeans.modules.j2ee.dd.api.common.EjbRef; 26 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef; 27 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 28 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject; 29 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel; 30 import org.netbeans.modules.xml.multiview.ui.EditDialog; 31 import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel; 32 import org.openide.util.NbBundle; 33 34 39 public class EjbRefsTablePanel extends DefaultTablePanel { 40 private EjbRefTableModel model; 41 private WebApp webApp; 42 private DDDataObject dObj; 43 46 private boolean javaEE5; 47 48 49 public EjbRefsTablePanel(final DDDataObject dObj, final EjbRefTableModel model) { 50 super(model); 51 this.model=model; 52 this.dObj=dObj; 53 Project project = FileOwnerQuery.getOwner(dObj.getPrimaryFile()); 54 this.javaEE5 = org.netbeans.modules.j2ee.common.Util.isJavaEE5orHigher(project); 55 56 removeButton.addActionListener(new java.awt.event.ActionListener () { 57 public void actionPerformed(java.awt.event.ActionEvent evt) { 58 dObj.modelUpdatedFromUI(); 59 dObj.setChangedFromUI(true); 60 int row = getTable().getSelectedRow(); 61 model.removeRow(row); 62 dObj.setChangedFromUI(false); 63 } 64 }); 65 editButton.addActionListener(new TableActionListener(false)); 66 addButton.addActionListener(new TableActionListener(true)); 67 } 68 69 void setModel(WebApp webApp, EjbRef[] params1, EjbLocalRef[] params2) { 70 CommonDDBean[] params = new CommonDDBean[params1.length+params2.length]; 71 int k=0; 72 for (int i=0;i<params1.length;i++) { 73 params[i]=params1[i]; 74 k++; 75 } 76 for (int j=0;j<params2.length;j++) { 77 params[k+j]=params2[j]; 78 } 79 model.setData(webApp,params); 80 this.webApp=webApp; 81 } 82 83 private class TableActionListener implements java.awt.event.ActionListener { 84 private boolean add; 85 TableActionListener(boolean add) { 86 this.add=add; 87 } 88 public void actionPerformed(java.awt.event.ActionEvent evt) { 89 final int row = (add?-1:getTable().getSelectedRow()); 90 final EjbRefPanel dialogPanel = new EjbRefPanel(); 91 if (!add) { 92 CommonDDBean ref = model.getEjbRef(row); 93 if (ref instanceof EjbRef) { 94 EjbRef ejbRef = (EjbRef)ref; 95 dialogPanel.setEjbName(ejbRef.getEjbRefName()); 96 dialogPanel.setBeanType(ejbRef.getEjbRefType()); 97 dialogPanel.setInterfaceType("Remote"); dialogPanel.setHome(ejbRef.getHome()); 99 dialogPanel.setInterface(ejbRef.getRemote()); 100 dialogPanel.setLink(ejbRef.getEjbLink()); 101 dialogPanel.setDescription(ejbRef.getDefaultDescription()); 102 } else { 103 EjbLocalRef ejbRef = (EjbLocalRef)ref; 104 dialogPanel.setEjbName(ejbRef.getEjbRefName()); 105 dialogPanel.setBeanType(ejbRef.getEjbRefType()); 106 dialogPanel.setInterfaceType("Local"); dialogPanel.setHome(ejbRef.getLocalHome()); 108 dialogPanel.setInterface(ejbRef.getLocal()); 109 dialogPanel.setLink(ejbRef.getEjbLink()); 110 dialogPanel.setDescription(ejbRef.getDefaultDescription()); 111 } 112 } 113 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(EjbRefsTablePanel.class,"TTL_EjbRef"),add) { 114 protected String validate() { 115 String name = dialogPanel.getEjbName().trim(); 116 String home = dialogPanel.getHome().trim(); 117 String remote = dialogPanel.getInterface().trim(); 118 if (name.length()==0) { 119 return NbBundle.getMessage(EjbRefsTablePanel.class,"TXT_EmptyEjbRefName"); 120 } else { 121 EjbRef[] refs = webApp.getEjbRef(); 122 boolean exists=false; 123 int countEjbRef=refs.length; 124 for (int i=0;i<countEjbRef;i++) { 125 if (row!=i && name.equals(refs[i].getEjbRefName())) { 126 exists=true; 127 break; 128 } 129 } 130 if (!exists) { 131 EjbLocalRef[] localRefs = webApp.getEjbLocalRef(); 132 for (int i=0;i<localRefs.length;i++) { 133 if (row!=i+countEjbRef && name.equals(localRefs[i].getEjbRefName())) { 134 exists=true; 135 break; 136 } 137 } 138 } 139 if (exists) { 140 return NbBundle.getMessage(EjbRefsTablePanel.class,"TXT_EjbRefNameExists",name); 141 } 142 } 143 if (home.length()==0 && !javaEE5) { 144 return NbBundle.getMessage(EjbRefsTablePanel.class,"TXT_EmptyEjbHome"); 145 } 146 if (remote.length()==0) { 147 return NbBundle.getMessage(EjbRefsTablePanel.class,"TXT_EmptyEjbInterface"); 148 } 149 return null; 150 } 151 }; 152 153 if (add) dialog.setValid(false); else dialogPanel.getInterfaceTypeCB().setEnabled(false); 155 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 156 dialogPanel.getNameTF().getDocument().addDocumentListener(docListener); 157 dialogPanel.getHomeTF().getDocument().addDocumentListener(docListener); 158 dialogPanel.getInterfaceTF().getDocument().addDocumentListener(docListener); 159 160 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 161 d.setVisible(true); 162 dialogPanel.getNameTF().getDocument().removeDocumentListener(docListener); 163 dialogPanel.getHomeTF().getDocument().removeDocumentListener(docListener); 164 dialogPanel.getInterfaceTF().getDocument().removeDocumentListener(docListener); 165 166 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 167 dObj.modelUpdatedFromUI(); 168 dObj.setChangedFromUI(true); 169 String name = dialogPanel.getEjbName().trim(); 170 String beanType = dialogPanel.getBeanType(); 171 String interfaceType = dialogPanel.getInterfaceType(); 172 String home = dialogPanel.getHome().trim(); 173 String remote = dialogPanel.getInterface().trim(); 174 String link = dialogPanel.getLink().trim(); 175 String description = dialogPanel.getDescription(); 176 if (add) model.addRow(new String []{name,beanType,interfaceType,home,remote,link,description}); 177 else model.editRow(row,new String []{name,beanType,interfaceType,home,remote,link,description}); 178 dObj.setChangedFromUI(false); 179 } 180 } 181 } 182 } 183 | Popular Tags |