1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 27 import org.netbeans.modules.j2ee.dd.api.common.ResourceRef; 28 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 29 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 30 import org.openide.util.NbBundle; 31 32 public class ResRefTableModel extends DDBeanTableModel 33 { 34 private static final String [] columnNames = { 35 NbBundle.getMessage(ResRefTableModel.class,"TTL_ResRefName"), 36 NbBundle.getMessage(ResRefTableModel.class,"TTL_ResType"), 37 NbBundle.getMessage(ResRefTableModel.class,"TTL_ResAuth"), 38 NbBundle.getMessage(ResRefTableModel.class,"TTL_ResSharingScope"), 39 NbBundle.getMessage(ResRefTableModel.class,"TTL_Description") 40 }; 41 42 protected String [] getColumnNames() { 43 return columnNames; 44 } 45 46 public void setValueAt(Object value, int row, int column) 47 { 48 ResourceRef param = getResourceRef(row); 49 50 if (column == 0) param.setResRefName((String )value); 51 else if (column == 1) param.setResType((String )value); 52 else if (column == 2) param.setResAuth((String )value); 53 else if (column == 3) param.setResSharingScope((String )value); 54 else param.setDescription((String )value); 55 } 56 57 58 public Object getValueAt(int row, int column) 59 { 60 ResourceRef param = getResourceRef(row); 61 62 if (column == 0) return param.getResRefName(); 63 else if (column == 1) return param.getResType(); 64 else if (column == 2) return param.getResAuth(); 65 else if (column == 3) { 66 String scope = param.getResSharingScope(); 67 return ("Unshareable".equals(scope)?scope:"Shareable"); } 69 else { 70 String desc = param.getDefaultDescription(); 71 return desc==null?null:desc.trim(); 72 } 73 } 74 75 public CommonDDBean addRow(Object [] values) 76 { 77 try { 78 WebApp webApp = (WebApp)getParent(); 79 ResourceRef param=(ResourceRef)webApp.createBean("ResourceRef"); param.setResRefName((String )values[0]); 81 param.setResType((String )values[1]); 82 param.setResAuth((String )values[2]); 83 param.setResSharingScope((String )values[3]); 84 String desc = (String )values[4]; 85 param.setDescription(desc.length()>0?desc:null); 86 webApp.addResourceRef(param); 87 getChildren().add(param); 88 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); 89 return param; 90 } catch (ClassNotFoundException ex) {} 91 return null; 92 } 93 94 public void editRow(int row, Object [] values) 95 { 96 ResourceRef param = getResourceRef(row); 97 param.setResRefName((String )values[0]); 98 param.setResType((String )values[1]); 99 param.setResAuth((String )values[2]); 100 String scope = (String )values[3]; 101 String oldScope = param.getResSharingScope(); 102 if (oldScope==null && "Unshareable".equals(scope)) param.setResSharingScope(scope); else if (!oldScope.equals(scope)) param.setResSharingScope(scope); 104 String desc = (String )values[4]; 105 param.setDescription(desc.length()>0?desc:null); 106 fireTableRowsUpdated(row,row); 107 } 108 109 public void removeRow(int row) 110 { 111 WebApp webApp = (WebApp)getParent(); 112 webApp.removeResourceRef(getResourceRef(row)); 113 getChildren().remove(row); 114 fireTableRowsDeleted(row, row); 115 116 } 117 118 ResourceRef getResourceRef(int row) { 119 return (ResourceRef)getChildren().get(row); 120 } 121 } | Popular Tags |