1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp; 26 27 import java.util.ArrayList ; 28 import java.util.List ; 29 import java.util.ResourceBundle ; 30 31 import javax.swing.table.AbstractTableModel ; 32 import javax.swing.event.EventListenerList ; 33 34 import org.netbeans.modules.j2ee.sun.dd.api.web.CacheMapping; 35 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion; 36 37 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory; 38 39 40 44 public class CacheMappingTableModel extends AbstractTableModel { 45 46 private static final ResourceBundle webappBundle = ResourceBundle.getBundle( 47 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); 49 private static final String [] columnNames = { 50 webappBundle.getString("LBL_CacheTarget"), webappBundle.getString("LBL_TargetValue"), webappBundle.getString("LBL_CacheReference"), webappBundle.getString("LBL_ReferenceValue"), }; 55 56 private static final String [] cacheTargetType = { 57 webappBundle.getString("LBL_ServletName"), webappBundle.getString("LBL_URLPattern"), }; 60 61 private static final String [] cacheReferenceType = { 62 webappBundle.getString("LBL_CacheHelperReference"), webappBundle.getString("LBL_CachePolicyDefinition"), }; 65 66 67 protected EventListenerList listenerList = new EventListenerList (); 68 69 70 private List rows; 71 72 73 private ASDDVersion appServerVersion; 74 75 public CacheMappingTableModel() { 76 rows = new ArrayList (); 77 } 78 79 82 public int addRow() { 83 rows.add(StorageBeanFactory.getStorageBeanFactory(appServerVersion).createCacheMapping_NoDefaults()); 84 int newIndex = rows.size()-1; 85 fireTableRowsInserted(newIndex, newIndex); 86 return newIndex; 87 } 88 89 public CacheMapping removeRow(int rowIndex) { 90 CacheMapping removedMapping = null; 91 92 if(rowIndex >= 0 && rowIndex < rows.size()) { 93 removedMapping = (CacheMapping) rows.remove(rowIndex); 94 fireTableRowsDeleted(rowIndex, rowIndex); 95 } 96 97 return removedMapping; 98 } 99 100 public void setData(List data, ASDDVersion asVersion) { 101 appServerVersion = asVersion; 102 103 if(data != null && data.size() > 0) { 104 rows = new ArrayList (data); 105 } else { 106 rows = new ArrayList (); 107 } 108 } 109 110 public List getData() { 111 return rows; 112 } 113 114 117 121 public String getColumnName(int columnIndex) { 122 assert(columnIndex >= 0 && columnIndex < 4); 123 return columnNames[columnIndex]; 124 } 125 126 public int getColumnCount() { 127 return 4; 128 } 129 130 public int getRowCount() { 131 return rows.size(); 133 } 134 135 public Object getValueAt(int rowIndex, int columnIndex) { 136 Object result = null; 137 138 if(rowIndex >= 0 && rowIndex < rows.size() && columnIndex >= 0 && columnIndex < 4) { 140 CacheMapping mapping = (CacheMapping) rows.get(rowIndex); 141 if(columnIndex < 2) { 142 String servletName = mapping.getServletName(); 144 String urlPattern = mapping.getUrlPattern(); 145 if(columnIndex == 0) { 146 result = (servletName != null) ? cacheTargetType[0] : cacheTargetType[1]; 147 } else { 148 result = (servletName != null) ? servletName : urlPattern; 149 } 150 } else { 151 String helperRef = mapping.getCacheHelperRef(); 153 if(columnIndex == 2) { 154 result = (helperRef != null) ? cacheReferenceType[0] : cacheReferenceType[1]; 155 } else { 156 result = (helperRef != null) ? helperRef : webappBundle.getString("LBL_PolicyLabel"); } 158 } 159 } 160 161 return result; 162 } 163 } 164 | Popular Tags |