1 23 package org.enhydra.kelp.common.deployer; 24 25 import org.enhydra.tool.archive.JarPlan; 27 import org.enhydra.tool.common.PathHandle; 28 29 import javax.swing.table.DefaultTableModel ; 31 32 public class ArchiveTableModel extends DefaultTableModel { 34 public ArchiveTableModel() { 36 super(); 37 addColumn("Built"); 38 addColumn("Path"); 39 } 40 41 public void setPlans(JarPlan[] plans) { 42 PathHandle ph = null; 43 44 clear(); 45 for (int i = 0; i < plans.length; i++) { 46 addPlan(plans[i]); 47 } 48 } 49 50 public JarPlan getPlan(int index) { 51 JarPlan plan = null; 52 if ((index > -1) && (index < getRowCount())) { 53 plan = (JarPlan) getValueAt(index, 1); 54 } 55 return plan; 56 } 57 58 public void setPlan(JarPlan plan, int index) { 59 if ((index > -1) && (index < getRowCount())) { 60 setValueAt(plan, index, 1); 61 } 62 63 } 64 65 public JarPlan[] getPlans() { 66 JarPlan[] plans = new JarPlan[0]; 67 int count = getRowCount(); 68 69 plans = new JarPlan[count]; 70 for (int i = 0; i < count; i++) { 71 plans[i] = (JarPlan) getValueAt(i, 1); 72 } 73 return plans; 74 } 75 76 public int addPlan(JarPlan newPlan) { 77 int count = getRowCount(); 78 int index = -1; 79 JarPlan plan = null; 80 Object [] row = new Object [0]; 81 PathHandle ph = null; 82 83 for (int i = 0; i < count; i++) { 84 plan = (JarPlan) getValueAt(i, 1); 85 if (plan.getArchivePath().equals(newPlan.getArchivePath())) { 86 setValueAt(newPlan, i, 1); 87 index = i; 88 break; 89 } 90 } 91 if (index == -1) { 92 ph = PathHandle.createPathHandle(newPlan.getArchivePath()); 93 row = new Object [2]; 94 row[0] = new Boolean (ph.isFile()); 95 row[1] = newPlan; 96 addRow(row); 97 index = getRowCount() - 1; 98 } 99 return index; 100 } 101 102 public boolean isCellEditable(int row, int col) { 103 return false; 104 } 105 106 protected void clear() { 107 while (getRowCount() > 0) { 108 removeRow(0); 109 } 110 } 111 112 } 113 | Popular Tags |