1 2 24 package org.enhydra.tool.archive.wizard; 25 26 import org.enhydra.tool.archive.WebApplication; 28 import org.enhydra.tool.common.PathHandle; 29 30 import java.awt.Component ; 32 import java.util.ArrayList ; 33 import javax.swing.JTable ; 34 import javax.swing.table.AbstractTableModel ; 35 36 public class WarSelector extends OneColumnFileSelector { 38 private JTable table = null; 39 40 public WarSelector() { 41 super(); 42 warInit(); 43 } 44 45 protected void removeSelection() { 47 int index = table.getSelectedRow(); 48 49 if ((index > -1) && (index < getTableModel().getRowCount())) { 50 getTableModel().removeRow(index); 51 } 52 } 53 54 protected void addToModel(PathHandle path) { 56 int count = getTableModel().getRowCount(); 57 ArrayList list = new ArrayList (); 58 59 for (int i = 0; i < count; i++) { 60 list.add(getTableModel().getValueAt(i, 1).toString()); 61 } 62 if (!list.contains(path.getPath())) { 63 WebApplication webApp = null; 64 65 webApp = new WebApplication(path.getPath()); 66 getTableModel().addWebApplication(webApp); 67 } 68 } 69 70 protected void setWebApplications(WebApplication[] webApps) { 71 int count = getTableModel().getRowCount(); 72 73 for (int i = 0; i < count; i++) { 74 getTableModel().removeRow(i); 75 } 76 for (int i = 0; i < webApps.length; i++) { 77 getTableModel().addWebApplication(webApps[i]); 78 } 79 } 80 81 protected WebApplication[] getWebApplications() { 82 int count = getTableModel().getRowCount(); 83 WebApplication[] webApps = new WebApplication[count]; 84 85 for (int i = 0; i < count; i++) { 86 webApps[i] = new WebApplication(getTableModel().getValueAt(i, 87 1).toString()); 88 webApps[i].setContextRoot(getTableModel().getValueAt(i, 89 0).toString()); 90 } 91 return webApps; 92 } 93 94 private void warInit() { 95 Component [] comps = getScrollPane().getViewport().getComponents(); 96 97 for (int i = 0; i < comps.length; i++) { 98 getScrollPane().getViewport().remove(comps[i]); 99 } 100 table = new JTable (); 101 table.setModel(new WarTableModel()); 102 getScrollPane().getViewport().add(table, null); 103 table.getColumnModel().getColumn(0).setPreferredWidth(40); 104 table.getColumnModel().getColumn(1).setPreferredWidth(250); 105 getTableModel().addTableModelListener(table); 106 } 107 108 private WarTableModel getTableModel() { 109 return (WarTableModel) table.getModel(); 110 } 111 112 private class WarTableModel extends AbstractTableModel { 113 ArrayList tableList = new ArrayList (); 114 115 public WarTableModel() { 116 super(); 117 } 118 119 public String getColumnName(int column) { 120 String cn = "Unknown"; 121 122 switch (column) { 123 case 0: 124 cn = "Context Root"; 125 break; 126 case 1: 127 cn = "Web Application"; 128 break; 129 } 130 return cn; 131 } 132 133 public void removeRow(int index) { 134 tableList.remove(index); 135 fireTableRowsDeleted(index, index); 136 } 137 138 public Object getValueAt(int row, int column) { 139 WebApplication webApp = (WebApplication) tableList.get(row); 140 Object value = "Unknown"; 141 142 switch (column) { 143 case 0: 144 value = webApp.getContextRoot(); 145 break; 146 case 1: 147 value = webApp.getArchive(); 148 break; 149 } 150 return value; 151 } 152 153 public void setValueAt(Object value, int row, int column) { 154 WebApplication webApp = (WebApplication) tableList.get(row); 155 156 switch (column) { 157 case 0: 158 webApp.setContextRoot(value.toString()); 159 break; 160 case 1: 161 webApp.setArchive(value.toString()); 162 break; 163 } 164 } 165 166 167 public int getColumnCount() { 168 return 2; 169 } 170 171 public boolean isCellEditable(int row, int col) { 172 return (col == 0); 173 } 174 175 public int getRowCount() { 176 return tableList.size(); 177 } 178 179 protected void addWebApplication(WebApplication webApp) { 180 int index = tableList.size(); 181 182 tableList.add(webApp); 183 fireTableRowsInserted(index, index); 184 } 185 186 } 187 } 188 | Popular Tags |