Skip to content

Commit 256c7fb

Browse files
committed
Make ExportPDFTask cancelable
1 parent 427e4e6 commit 256c7fb

File tree

1 file changed

+13
-2
lines changed
  • EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/heatmap

1 file changed

+13
-2
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/heatmap/ExportPDFTask.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ public void setRowToModelRow(IntUnaryOperator rowToModel) {
5757
public void run(TaskMonitor taskMonitor) throws IOException, DocumentException {
5858
taskMonitor.setTitle("Export HeatMap to PDF");
5959

60-
FileOutputStream out = new FileOutputStream(file);
61-
6260
PdfPTable table = createTable();
61+
if(cancelled)
62+
return;
63+
6364
setColumnWidths(table);
6465

6566
float width = table.getTotalWidth() + MARGIN * 2;
6667
float height = table.getTotalHeight() + MARGIN * 2;
6768
Rectangle pageSize = new Rectangle(width, height);
6869

70+
FileOutputStream out = new FileOutputStream(file);
6971
Document document = new Document(pageSize);
7072
PdfWriter.getInstance(document, out);
7173
document.setMargins(MARGIN, MARGIN, MARGIN, MARGIN);
@@ -84,6 +86,9 @@ private PdfPTable createTable() {
8486
PdfPCell descHeaderCell = createDesciptionHeader();
8587
PdfPCell scoreHeaderCell = createScoreHeader();
8688

89+
if(cancelled)
90+
return null;
91+
8792
if(model.getCompress().isNone()) {
8893
geneHeaderCell.setRowspan(2);
8994
descHeaderCell.setRowspan(2);
@@ -103,11 +108,17 @@ private PdfPTable createTable() {
103108
table.addCell(scoreHeaderCell);
104109
}
105110

111+
if(cancelled)
112+
return null;
113+
106114
for(int col = HeatMapTableModel.DESC_COL_COUNT; col < colCount; col++) {
107115
table.addCell(createExpressionHeader(col));
108116
}
109117

110118
for(int row = 0; row < model.getRowCount(); row++) {
119+
if(cancelled)
120+
return null;
121+
111122
int modelRow = rowToModel.applyAsInt(row);
112123

113124
table.addCell(createGeneCell(modelRow));

0 commit comments

Comments
 (0)