|
1 | 1 | package org.baderlab.csplugins.enrichmentmap.view.creation;
|
2 | 2 |
|
3 |
| -import static com.google.common.base.Strings.isNullOrEmpty; |
4 |
| - |
5 | 3 | import java.awt.BorderLayout;
|
6 | 4 | import java.awt.CardLayout;
|
7 | 5 | import java.awt.Color;
|
@@ -133,22 +131,20 @@ public void finish() {
|
133 | 131 | .collect(Collectors.toList());
|
134 | 132 |
|
135 | 133 | // Overwrite all the expression files if the common file has been provided
|
136 |
| - String exprPath = commonPanel.getExpressionFile(); |
137 |
| - if(!isNullOrEmpty(exprPath)) { |
138 |
| - for(DataSetParameters dsp : dataSets) { |
139 |
| - dsp.getFiles().setExpressionFileName(exprPath); |
140 |
| - } |
| 134 | + if(commonPanel.hasExpressionFile()) { |
| 135 | + String exprPath = commonPanel.getExpressionFile(); |
| 136 | + dataSets.forEach(dsp -> dsp.getFiles().setExpressionFileName(exprPath)); |
141 | 137 | }
|
142 |
| - |
143 | 138 | // Overwrite all the gmt files if a common file has been provided
|
144 |
| - String gmtPath = commonPanel.getGmtFile(); |
145 |
| - if(!isNullOrEmpty(gmtPath)) { |
146 |
| - for(DataSetParameters dsp : dataSets) { |
147 |
| - dsp.getFiles().setGMTFileName(gmtPath); |
148 |
| - } |
| 139 | + if(commonPanel.hasGmtFile()) { |
| 140 | + String gmtPath = commonPanel.getGmtFile(); |
| 141 | + dataSets.forEach(dsp -> dsp.getFiles().setGMTFileName(gmtPath)); |
| 142 | + } |
| 143 | + // Overwrite all the class files if a common file has been provided |
| 144 | + if(commonPanel.hasClassFile()) { |
| 145 | + String classPath = commonPanel.getClassFile(); |
| 146 | + dataSets.forEach(dsp -> dsp.getFiles().setClassFile(classPath)); |
149 | 147 | }
|
150 |
| - |
151 |
| -// System.out.println(params); |
152 | 148 |
|
153 | 149 | CreateEnrichmentMapTaskFactory taskFactory = taskFactoryFactory.create(params, dataSets);
|
154 | 150 | TaskIterator tasks = taskFactory.createTaskIterator();
|
@@ -352,38 +348,38 @@ public EditCommonPanel getCommonPanel() {
|
352 | 348 | return commonPanel;
|
353 | 349 | }
|
354 | 350 |
|
| 351 | + |
| 352 | + private Stream<EditDataSetPanel> editPanelStream() { |
| 353 | + return dataSetListModel.stream() |
| 354 | + .map(DataSetListItem::getDetailPanel) |
| 355 | + .filter(panel -> panel instanceof EditDataSetPanel) |
| 356 | + .map(panel -> (EditDataSetPanel)panel); |
| 357 | + } |
| 358 | + |
| 359 | + private static void addCommonWarnSection(ErrorMessageDialog dialog, DetailPanel panel, String name) { |
| 360 | + String message = "A common " + name + " file has been provided. Per-dataset " + name + " files will be ignored."; |
| 361 | + dialog.addSection(Message.warn(message), panel.getDisplayName(), panel.getIcon()); |
| 362 | + } |
| 363 | + |
| 364 | + |
355 | 365 | private boolean validateInput() {
|
356 | 366 | ErrorMessageDialog dialog = errorMessageDialogFactory.create(callback.getDialogFrame());
|
357 | 367 |
|
358 | 368 | // Check if the user provided a global expression file, warn if there are also per-dataset expression files.
|
359 |
| - if(commonPanel.hasExpressionFile()) { |
360 |
| - for(DataSetListItem item : dataSetListModel.toList()) { |
361 |
| - DetailPanel panel = item.getDetailPanel(); |
362 |
| - if(panel instanceof EditDataSetPanel && !isNullOrEmpty(((EditDataSetPanel)panel).getExpressionFileName())) { |
363 |
| - String message = "A common expression file has been provided. Per-dataset expression files will be ignored."; |
364 |
| - dialog.addSection(Message.warn(message), commonPanel.getDisplayName(), commonPanel.getIcon()); |
365 |
| - break; |
366 |
| - } |
367 |
| - } |
| 369 | + if(commonPanel.hasExpressionFile() && editPanelStream().anyMatch(EditDataSetPanel::hasExpressionFile)) { |
| 370 | + addCommonWarnSection(dialog, commonPanel, "expression"); |
368 | 371 | }
|
369 |
| - |
370 | 372 | // Check if the user provided a global gmt file, warn if there are also per-dataset gmt files.
|
371 |
| - if(commonPanel.hasGmtFile()) { |
372 |
| - for(DataSetListItem item : dataSetListModel.toList()) { |
373 |
| - DetailPanel panel = item.getDetailPanel(); |
374 |
| - if(panel instanceof EditDataSetPanel && !isNullOrEmpty(((EditDataSetPanel)panel).getGMTFileName())) { |
375 |
| - String message = "A common GMT file has been provided. Per-dataset GMT files will be ignored."; |
376 |
| - dialog.addSection(Message.warn(message), commonPanel.getDisplayName(), commonPanel.getIcon()); |
377 |
| - break; |
378 |
| - } |
379 |
| - } |
| 373 | + if(commonPanel.hasGmtFile() && editPanelStream().anyMatch(EditDataSetPanel::hasGmtFile)) { |
| 374 | + addCommonWarnSection(dialog, commonPanel, "GMT"); |
| 375 | + } |
| 376 | + // Check if the user provided a global gmt file, warn if there are also per-dataset gmt files. |
| 377 | + if(commonPanel.hasClassFile() && editPanelStream().anyMatch(EditDataSetPanel::hasClassFile)) { |
| 378 | + addCommonWarnSection(dialog, commonPanel, "class"); |
380 | 379 | }
|
381 | 380 |
|
382 | 381 | { // Check for duplicate data set names
|
383 |
| - Map<String,Long> dataSetNameCount = dataSetListModel.stream() |
384 |
| - .map(DataSetListItem::getDetailPanel) |
385 |
| - .filter(panel -> panel instanceof EditDataSetPanel) |
386 |
| - .map(panel -> (EditDataSetPanel)panel) |
| 382 | + Map<String,Long> dataSetNameCount = editPanelStream() |
387 | 383 | .map(EditDataSetPanel::getDataSetName)
|
388 | 384 | .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
|
389 | 385 |
|
|
0 commit comments