PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/pride-inspector/branches/development/src/main/java/uk/ac/ebi/pride/gui/task/impl/RetrievePeptideTableTask.java

http://pride-toolsuite.googlecode.com/
Java | 125 lines | 70 code | 13 blank | 42 comment | 8 complexity | 04c23b0180d716ec39a0f971fb940ae2 MD5 | raw file
  1. package uk.ac.ebi.pride.gui.task.impl;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import uk.ac.ebi.pride.data.Tuple;
  5. import uk.ac.ebi.pride.data.controller.DataAccessController;
  6. import uk.ac.ebi.pride.data.controller.DataAccessException;
  7. import uk.ac.ebi.pride.data.utils.CollectionUtils;
  8. import uk.ac.ebi.pride.gui.component.exception.ThrowableEntry;
  9. import uk.ac.ebi.pride.gui.component.message.MessageType;
  10. import uk.ac.ebi.pride.gui.component.table.TableDataRetriever;
  11. import uk.ac.ebi.pride.gui.component.table.model.TableContentType;
  12. import java.util.Collection;
  13. import java.util.List;
  14. /**
  15. * Created by IntelliJ IDEA.
  16. * User: rwang
  17. * Date: 08-Sep-2010
  18. * Time: 10:25:11
  19. */
  20. public class RetrievePeptideTableTask extends AbstractDataAccessTask<Void, Tuple<TableContentType, List<Object>>> {
  21. private static final Logger logger = LoggerFactory.getLogger(RetrievePeptideTableTask.class);
  22. /**
  23. * the size of each read iteration, for example: return every 100 spectra
  24. */
  25. private static final int DEFAULT_ITERATION_SIZE = 100;
  26. /**
  27. * the default task title
  28. */
  29. private static final String DEFAULT_TASK_TITLE = "Loading Peptides";
  30. /**
  31. * the default task description
  32. */
  33. private static final String DEFAULT_TASK_DESCRIPTION = "Loading Peptides";
  34. /**
  35. * the start index
  36. */
  37. private int start;
  38. /**
  39. * the number of entries to retrieve
  40. */
  41. private int size;
  42. /**
  43. * Retrieve all the identifications.
  44. *
  45. * @param controller DataAccessController
  46. * @throws uk.ac.ebi.pride.data.controller.DataAccessException
  47. * thrown when there is error while reading the data.
  48. */
  49. public RetrievePeptideTableTask(DataAccessController controller) throws DataAccessException {
  50. this(controller, 0, controller.getNumberOfIdentifications());
  51. }
  52. public RetrievePeptideTableTask(DataAccessController controller, Comparable identId) throws DataAccessException {
  53. this(controller, controller.getIdentificationIndex(identId), 1);
  54. }
  55. /**
  56. * Retrieve a subset of identifications using the default iteration size.
  57. *
  58. * @param controller DataAccessController
  59. * @param start the start index of the identifications.
  60. */
  61. public RetrievePeptideTableTask(DataAccessController controller, int start) {
  62. this(controller, start, DEFAULT_ITERATION_SIZE);
  63. }
  64. /**
  65. * Retrieve a subset of identifications.
  66. *
  67. * @param controller DataAccessController
  68. * @param start the start index of the identifications.
  69. * @param size the total size of the identifications to retrieve.
  70. */
  71. public RetrievePeptideTableTask(DataAccessController controller,
  72. int start,
  73. int size) {
  74. super(controller);
  75. this.start = start;
  76. this.size = size;
  77. this.setName(DEFAULT_TASK_TITLE);
  78. this.setDescription(DEFAULT_TASK_DESCRIPTION);
  79. }
  80. @Override
  81. protected Void retrieve() throws Exception {
  82. try {
  83. Collection<Comparable> identIds = controller.getIdentificationIds();
  84. int identSize = identIds.size();
  85. if (start >= 0 && start < identSize && size > 0) {
  86. int stop = start + size;
  87. stop = stop > identSize ? identSize : stop;
  88. for (int i = start; i < stop; i++) {
  89. Comparable identId = CollectionUtils.getElement(identIds, i);
  90. Collection<Comparable> ids = controller.getPeptideIds(identId);
  91. if (ids != null) {
  92. for (Comparable peptideId : ids) {
  93. List<Object> content = TableDataRetriever.getPeptideTableRow(controller, identId, peptideId);
  94. publish(new Tuple<TableContentType, List<Object>>(TableContentType.PEPTIDE, content));
  95. }
  96. }
  97. // this is important for cancelling
  98. if (Thread.interrupted()) {
  99. throw new InterruptedException();
  100. }
  101. }
  102. }
  103. } catch (DataAccessException dex) {
  104. String msg = "Failed to retrieve peptide related data";
  105. logger.error(msg, dex);
  106. appContext.addThrowableEntry(new ThrowableEntry(MessageType.ERROR, msg, dex));
  107. } catch (InterruptedException e) {
  108. logger.warn("Peptide table update has been cancelled");
  109. }
  110. return null;
  111. }
  112. }