1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.common.MessageDestinationRef; 23 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException; 24 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 25 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject; 26 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel; 27 import org.netbeans.modules.xml.multiview.ui.EditDialog; 28 import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel; 29 import org.openide.util.NbBundle; 30 31 36 public class MessageDestRefsTablePanel extends DefaultTablePanel { 37 private MessageDestRefTableModel model; 38 private WebApp webApp; 39 private DDDataObject dObj; 40 41 42 public MessageDestRefsTablePanel(final DDDataObject dObj, final MessageDestRefTableModel model) { 43 super(model); 44 this.model=model; 45 this.dObj=dObj; 46 removeButton.addActionListener(new java.awt.event.ActionListener () { 47 public void actionPerformed(java.awt.event.ActionEvent evt) { 48 dObj.modelUpdatedFromUI(); 49 dObj.setChangedFromUI(true); 50 int row = getTable().getSelectedRow(); 51 model.removeRow(row); 52 dObj.setChangedFromUI(false); 53 } 54 }); 55 editButton.addActionListener(new TableActionListener(false)); 56 addButton.addActionListener(new TableActionListener(true)); 57 } 58 59 void setModel(WebApp webApp, MessageDestinationRef[] params) { 60 model.setData(webApp,params); 61 this.webApp=webApp; 62 } 63 64 private class TableActionListener implements java.awt.event.ActionListener { 65 private boolean add; 66 TableActionListener(boolean add) { 67 this.add=add; 68 } 69 public void actionPerformed(java.awt.event.ActionEvent evt) { 70 71 final int row = (add?-1:getTable().getSelectedRow()); 72 final MessageDestRefPanel dialogPanel = new MessageDestRefPanel(); 73 if (!add) { 74 MessageDestinationRef resRef = model.getMessageDestRef(row); 75 dialogPanel.setMessageDestRefName(resRef.getMessageDestinationRefName()); 76 dialogPanel.setMessageDestRefType(resRef.getMessageDestinationType()); 77 dialogPanel.setUsage(resRef.getMessageDestinationUsage()); 78 dialogPanel.setLink(resRef.getMessageDestinationLink()); dialogPanel.setDescription(resRef.getDefaultDescription()); 80 } 81 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(MessageDestRefsTablePanel.class,"TTL_MessageDestRef"),add) { 82 protected String validate() { 83 String name = dialogPanel.getMessageDestRefName().trim(); 84 if (name.length()==0) { 85 return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_EmptyMessageDestRefName"); 86 } else { 87 try { 88 MessageDestinationRef[] params = webApp.getMessageDestinationRef(); 89 boolean exists=false; 90 for (int i=0;i<params.length;i++) { 91 if (row!=i && name.equals(params[i].getMessageDestinationRefName())) { 92 exists=true; 93 break; 94 } 95 } 96 if (exists) { 97 return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_MessageDestRefNameExists",name); 98 } 99 } catch (VersionNotSupportedException ex) { 100 return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_MessageDestNotSupported"); 101 } 102 } 103 return null; 104 } 105 }; 106 107 if (add) dialog.setValid(false); javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 109 dialogPanel.getNameTF().getDocument().addDocumentListener(docListener);; 110 111 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 112 d.setVisible(true); 113 dialogPanel.getNameTF().getDocument().removeDocumentListener(docListener); 114 115 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 116 dObj.modelUpdatedFromUI(); 117 dObj.setChangedFromUI(true); 118 String name = dialogPanel.getMessageDestRefName().trim(); 119 String type = dialogPanel.getMessageDestRefType(); 120 String usage = dialogPanel.getUsage(); 121 String link = dialogPanel.getLink().trim(); 122 String description = dialogPanel.getDescription(); 123 if (add) model.addRow(new String []{name,type,usage,link,description}); 124 else model.editRow(row,new String []{name,type,usage,link,description}); 125 dObj.setChangedFromUI(false); 126 } 127 } 128 } 129 } 130 | Popular Tags |