1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.common.ResourceRef; 23 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 24 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject; 25 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel; 26 import org.netbeans.modules.xml.multiview.ui.EditDialog; 27 import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel; 28 import org.openide.util.NbBundle; 29 30 35 public class ResRefsTablePanel extends DefaultTablePanel { 36 private ResRefTableModel model; 37 private WebApp webApp; 38 private DDDataObject dObj; 39 40 41 public ResRefsTablePanel(final DDDataObject dObj, final ResRefTableModel model) { 42 super(model); 43 this.model=model; 44 this.dObj=dObj; 45 removeButton.addActionListener(new java.awt.event.ActionListener () { 46 public void actionPerformed(java.awt.event.ActionEvent evt) { 47 dObj.modelUpdatedFromUI(); 48 dObj.setChangedFromUI(true); 49 int row = getTable().getSelectedRow(); 50 model.removeRow(row); 51 dObj.setChangedFromUI(false); 52 } 53 }); 54 editButton.addActionListener(new TableActionListener(false)); 55 addButton.addActionListener(new TableActionListener(true)); 56 } 57 58 void setModel(WebApp webApp, ResourceRef[] params) { 59 model.setData(webApp,params); 60 this.webApp=webApp; 61 } 62 63 private class TableActionListener implements java.awt.event.ActionListener { 64 private boolean add; 65 TableActionListener(boolean add) { 66 this.add=add; 67 } 68 public void actionPerformed(java.awt.event.ActionEvent evt) { 69 70 final int row = (add?-1:getTable().getSelectedRow()); 71 final ResRefPanel dialogPanel = new ResRefPanel(); 72 if (!add) { 73 ResourceRef resRef = model.getResourceRef(row); 74 dialogPanel.setResRefName(resRef.getResRefName()); 75 dialogPanel.setResType(resRef.getResType()); 76 String auth = resRef.getResAuth(); 77 dialogPanel.setResAuth(auth==null?"Container":auth); 78 String scope = resRef.getResSharingScope(); 79 dialogPanel.setResScope(scope==null?"Shareable":scope); dialogPanel.setDescription(resRef.getDefaultDescription()); 81 } 82 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(ResRefsTablePanel.class,"TTL_ResourceRef"),add) { 83 protected String validate() { 84 String name = dialogPanel.getResRefName().trim(); 85 String type = dialogPanel.getResType().trim(); 86 if (name.length()==0) { 87 return NbBundle.getMessage(ResRefsTablePanel.class,"TXT_EmptyResRefName"); 88 } else { 89 ResourceRef[] params = webApp.getResourceRef(); 90 boolean exists=false; 91 for (int i=0;i<params.length;i++) { 92 if (row!=i && name.equals(params[i].getResRefName())) { 93 exists=true; 94 break; 95 } 96 } 97 if (exists) { 98 return NbBundle.getMessage(ResRefsTablePanel.class,"TXT_ResRefNameExists",name); 99 } 100 } 101 if (type.length()==0) { 102 return NbBundle.getMessage(ResRefsTablePanel.class,"TXT_EmptyResTypeValue"); 103 } 104 return null; 105 } 106 }; 107 108 if (add) dialog.setValid(false); javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 110 dialogPanel.getNameTF().getDocument().addDocumentListener(docListener); 111 dialogPanel.getTypeTF().getDocument().addDocumentListener(docListener); 112 113 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 114 d.setVisible(true); 115 dialogPanel.getNameTF().getDocument().removeDocumentListener(docListener); 116 dialogPanel.getTypeTF().getDocument().removeDocumentListener(docListener); 117 118 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 119 dObj.modelUpdatedFromUI(); 120 dObj.setChangedFromUI(true); 121 String name = dialogPanel.getResRefName().trim(); 122 String type = dialogPanel.getResType().trim(); 123 String auth = dialogPanel.getResAuth(); 124 String scope = dialogPanel.getResScope(); 125 String description = dialogPanel.getDescription(); 126 if (add) model.addRow(new String []{name,type,auth,scope,description}); 127 else model.editRow(row,new String []{name,type,auth,scope,description}); 128 dObj.setChangedFromUI(false); 129 } 130 } 131 } 132 } 133 | Popular Tags |