PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/pride-inspector/branches/development/src/main/java/uk/ac/ebi/pride/gui/component/table/model/DatabaseSearchTableModel.java

http://pride-toolsuite.googlecode.com/
Java | 130 lines | 92 code | 15 blank | 23 comment | 8 complexity | b018121527d8011d05815cf1179181a6 MD5 | raw file
  1. package uk.ac.ebi.pride.gui.component.table.model;
  2. import org.bushe.swing.event.annotation.AnnotationProcessor;
  3. import org.bushe.swing.event.annotation.EventSubscriber;
  4. import uk.ac.ebi.pride.gui.event.DatabaseSearchEvent;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. /**
  8. * Table model for database search table
  9. * <p/>
  10. * User: rwang
  11. * Date: 02/06/11
  12. * Time: 15:23
  13. */
  14. public class DatabaseSearchTableModel extends ListTableModel<List<Object>> {
  15. /**
  16. * table column title
  17. */
  18. public enum TableHeader {
  19. ROW_NUMBER_COLUMN("#", "Row Number"),
  20. VIEW("View", "View experiment"),
  21. EXPERIMENT_ACCESSION("Accession", "PRIDE Experiment Accession"),
  22. EXPERIMENT_TITLE("Title", "PRIDE Experiment Title"),
  23. PROJECT("Project", "PRIDE Project Name"),
  24. SPECIES("Species", "Sample Species"),
  25. TAXONOMY_ID("Taxonomy ID", "Sample Taxonomy ID"),
  26. TISSUE("Tissue", "Sample Tissue"),
  27. BRENDA_ID("BRENDA ID (Tissue)", "Tissue's BRENDA ID"),
  28. PTM("PTM", "Post Translational Modifications"),
  29. NUMBER_OF_SPECTRA("#Spectra", "Number of spectra"),
  30. NUMBER_OF_PROTEIN("#Proteins", "Number of proteins"),
  31. NUMBER_OF_PEPTIDE("#Peptides", "Number of peptides"),
  32. REFERENCE("Reference", "Full Reference Line"),
  33. PUBMED_ID("PubMed ID", "PubMed ID");
  34. private final String header;
  35. private final String toolTip;
  36. private TableHeader(String header, String tooltip) {
  37. this.header = header;
  38. this.toolTip = tooltip;
  39. }
  40. public String getHeader() {
  41. return header;
  42. }
  43. public String getToolTip() {
  44. return toolTip;
  45. }
  46. }
  47. public DatabaseSearchTableModel() {
  48. // enable annotation
  49. AnnotationProcessor.process(this);
  50. }
  51. @Override
  52. public void initializeTableModel() {
  53. for (TableHeader tableHeader : TableHeader.values()) {
  54. addColumn(tableHeader.getHeader(), tableHeader.getToolTip());
  55. }
  56. }
  57. @Override
  58. public void addData(List<Object> newData) {
  59. List<Object> content = new ArrayList<Object>();
  60. // row number
  61. int rowCnt = this.getRowCount();
  62. content.add(rowCnt + 1);
  63. content.add(newData.get(0));
  64. content.addAll(newData);
  65. contents.add(content);
  66. fireTableRowsInserted(rowCnt, rowCnt);
  67. }
  68. @Override
  69. public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
  70. List<Object> content = contents.get(rowIndex);
  71. if (content != null) {
  72. content.set(columnIndex, aValue);
  73. }
  74. fireTableCellUpdated(rowIndex, columnIndex);
  75. }
  76. /**
  77. * Get all the values of search results
  78. * Note: the result excludes the the row number, selection column and view column
  79. *
  80. * @return List<List<Object>> all the actual values in the table
  81. */
  82. public List<List<String>> getAllContent() {
  83. List<List<String>> results = new ArrayList<List<String>>();
  84. for (List<Object> content : contents) {
  85. List<String> result = new ArrayList<String>();
  86. for (int i = TableHeader.values().length; i < content.size(); i++) {
  87. result.add(content.get(i).toString());
  88. }
  89. results.add(result);
  90. }
  91. return results;
  92. }
  93. /**
  94. * Get all the headers of the table without the row number, view column
  95. *
  96. * @return List<String> a list of headers
  97. */
  98. public List<String> getAllHeaders() {
  99. List<String> headers = new ArrayList<String>();
  100. int cnt = this.getColumnCount();
  101. for (int i = 2; i < cnt; i++) {
  102. headers.add(this.getColumnName(i));
  103. }
  104. return headers;
  105. }
  106. @EventSubscriber(eventClass = DatabaseSearchEvent.class)
  107. public void onDatabaseSearchEvent(DatabaseSearchEvent evt) {
  108. if (DatabaseSearchEvent.Status.RESULT.equals(evt.getStatus())) {
  109. List<List<Object>> newData = (List<List<Object>>) evt.getResult();
  110. for (List<Object> data : newData) {
  111. addData(data);
  112. }
  113. }
  114. }
  115. }