1 package net.sf.jhylafax; 2 3 import static net.sf.jhylafax.JHylaFAX.i18n; 4 import java.util.ArrayList; 5 import java.util.Date; 6 import java.util.List; 7 import javax.swing.table.AbstractTableModel; 8 import javax.swing.table.TableModel; 9 import net.sf.jhylafax.JobHelper.FileStat; 10 import net.sf.jhylafax.fax.Document; 11 import org.xnap.commons.gui.Builder; 12 import org.xnap.commons.gui.util.DoubleClickListener; 13 14 public class DocumentQueuePanel extends AbstractQueuePanel { 15 16 private ViewAction viewAction; 17 private SaveAction saveAction; 18 private DeleteAction deleteAction; 19 private DocTableModel docTableModel; 20 21 public DocumentQueuePanel(String queueName) { 22 super(queueName); 23 24 viewAction = new ViewAction(); 25 saveAction = new SaveAction(); 26 deleteAction = new DeleteAction(); 27 28 getButtonPanel().add(Builder.createButton(viewAction)); 29 getButtonPanel().add(Builder.createButton(saveAction)); 30 getButtonPanel().add(Builder.createButton(deleteAction)); 31 32 getTablePopupMenu().add(Builder.createMenuItem(viewAction)); 33 getTablePopupMenu().add(Builder.createMenuItem(saveAction)); 34 getTablePopupMenu().add(Builder.createMenuItem(deleteAction)); 35 36 getTable().addMouseListener(new DoubleClickListener(viewAction)); 37 38 updateLabels(); 39 updateActions(); 40 } 41 42 @Override 43 public FileStat getSelectedFile() 44 { 45 int row = getSelectedRow(); 46 if (row == -1) { 47 return null; 48 } 49 else { 50 Document doc = docTableModel.getDocument(row); 51 return new FileStat(doc.getFilename(), doc.getFilesize()); 52 } 53 } 54 55 @Override 56 protected TableModel getTableModel() 57 { 58 if (docTableModel == null) { 59 docTableModel = new DocTableModel(); 60 } 61 return docTableModel; 62 } 63 64 @Override 65 protected void initializeTableLayout() { 66 getTableLayout().setColumnProperties(0, "permissions", 40); 67 getTableLayout().setColumnProperties(1, "owner", 40); 68 getTableLayout().setColumnProperties(2, "created", 80); 69 getTableLayout().setColumnProperties(3, "modified", 80); 70 getTableLayout().setColumnProperties(4, "accessed", 80); 71 getTableLayout().setColumnProperties(5, "filename", 120); 72 getTableLayout().setColumnProperties(6, "filesize", 20); 73 } 74 75 public void setData(List<Document> data) 76 { 77 docTableModel.setData(data); 78 } 79 80 @Override 81 public void updateActions() { 82 FileStat file = getSelectedFile(); 83 viewAction.setEnabled(file != null); 84 saveAction.setEnabled(file != null); 85 deleteAction.setEnabled(file != null); 86 } 87 88 @Override 89 public void updateLabels() { 90 super.updateLabels(); 91 92 viewAction.updateLabels(); 93 saveAction.updateLabels(); 94 deleteAction.updateLabels(); 95 96 getTableLayout().setColumnNames(new String[] { 97 i18n.tr("Permissions"), 98 i18n.tr("Owner"), 99 i18n.tr("Created"), 100 i18n.tr("Modified"), 101 i18n.tr("Accessed"), 102 i18n.tr("Name"), 103 i18n.tr("Size"), }); 104 } 105 106 private static class DocTableModel extends AbstractTableModel { 107 108 private static final Class[] columnClasses= { 109 Integer.class, 110 String.class, 111 Date.class, 112 Date.class, 113 Date.class, 114 String.class, 115 Long.class, 116 }; 117 118 private List<Document> data = new ArrayList<Document>(0); 119 120 public DocTableModel() { 121 } 122 123 public Class<?> getColumnClass(int column) { 124 return columnClasses[column]; 125 } 126 127 public int getColumnCount() { 128 return columnClasses.length; 129 } 130 131 public Document getDocument(int row) { 132 return data.get(row); 133 } 134 135 public int getRowCount() 136 { 137 return data.size(); 138 } 139 140 public Object getValueAt(int row, int column) 141 { 142 Document doc = data.get(row); 143 switch (column) { 144 case 0: 145 return doc.getPermissions(); 146 case 1: 147 return doc.getOwner(); 148 case 2: 149 return doc.getCreationTime(); 150 case 3: 151 return doc.getLastModificationTime(); 152 case 4: 153 return doc.getLastAccessTime(); 154 case 5: 155 return doc.getFilename(); 156 case 6: 157 return doc.getFilesize(); 158 default: 159 return null; 160 } 161 } 162 163 public void setData(List<Document> data) 164 { 165 this.data = data; 166 fireTableDataChanged(); 167 } 168 169 } 170 171 }