Skip to content

Commit a3a920f

Browse files
committed
Add class file to common files panel. Some refactoring in
MasterDetailDialogPage. Fixes #218.
1 parent fc43d9e commit a3a920f

File tree

3 files changed

+76
-42
lines changed

3 files changed

+76
-42
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/EditCommonPanel.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class EditCommonPanel extends JPanel implements DetailPanel {
2323

2424
private PathTextField gmtText;
2525
private PathTextField expressionsText;
26+
private PathTextField classText;
2627

2728

2829
@Override
@@ -44,6 +45,7 @@ public JPanel getPanel() {
4445
private void createContents() {
4546
gmtText = pathTextFactory.create("GMT File:", FileBrowser.Filter.GMT);
4647
expressionsText = pathTextFactory.create("Expressions:", FileBrowser.Filter.EXPRESSION);
48+
classText = pathTextFactory.create("Class File:", FileBrowser.Filter.CLASS);
4749

4850
GroupLayout layout = new GroupLayout(this);
4951
setLayout(layout);
@@ -56,14 +58,17 @@ private void createContents() {
5658
.addGroup(layout.createParallelGroup(Alignment.TRAILING)
5759
.addComponent(gmtText.getLabel())
5860
.addComponent(expressionsText.getLabel())
61+
.addComponent(classText.getLabel())
5962
)
6063
.addGroup(layout.createParallelGroup(Alignment.LEADING, true)
6164
.addComponent(gmtText.getTextField())
6265
.addComponent(expressionsText.getTextField())
66+
.addComponent(classText.getTextField())
6367
)
6468
.addGroup(layout.createParallelGroup()
6569
.addComponent(gmtText.getBrowseButton())
6670
.addComponent(expressionsText.getBrowseButton())
71+
.addComponent(classText.getBrowseButton())
6772
)
6873
);
6974

@@ -79,6 +84,11 @@ private void createContents() {
7984
.addComponent(expressionsText.getTextField())
8085
.addComponent(expressionsText.getBrowseButton())
8186
)
87+
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
88+
.addComponent(classText.getLabel())
89+
.addComponent(classText.getTextField())
90+
.addComponent(classText.getBrowseButton())
91+
)
8292
);
8393

8494
if(LookAndFeelUtil.isAquaLAF())
@@ -93,9 +103,11 @@ public List<Message> validateInput(MasterDetailDialogPage parent) {
93103

94104
List<Message> messages = new ArrayList<>(2);
95105
if(!gmtText.emptyOrReadable())
96-
messages.add(Message.error(gmtText.showError("Enrichments file path is not valid.")));
106+
messages.add(Message.error(gmtText.showError("GMT file path is not valid.")));
97107
if(!expressionsText.emptyOrReadable())
98-
messages.add(Message.error(expressionsText.showError("Enrichments 2 file path is not valid.")));
108+
messages.add(Message.error(expressionsText.showError("Expressions file path is not valid.")));
109+
if(!classText.emptyOrReadable())
110+
messages.add(Message.error(expressionsText.showError("Class file path is not valid.")));
99111

100112
return messages;
101113
}
@@ -109,17 +121,26 @@ public String getExpressionFile() {
109121
return expressionsText.getText();
110122
}
111123

124+
public String getClassFile() {
125+
return classText.getText();
126+
}
127+
112128
public boolean hasExpressionFile() {
113129
return !isNullOrEmpty(getExpressionFile());
114130
}
115131

116132
public boolean hasGmtFile() {
117133
return !isNullOrEmpty(getGmtFile());
118134
}
135+
136+
public boolean hasClassFile() {
137+
return !isNullOrEmpty(getClassFile());
138+
}
119139

120140
public void reset() {
121141
gmtText.setText("");
122142
expressionsText.setText("");
143+
classText.setText("");
123144
}
124145

125146
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/EditDataSetPanel.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,29 @@ private Method getMethod() {
350350
return analysisTypeCombo.getItemAt(analysisTypeCombo.getSelectedIndex()).getValue();
351351
}
352352

353-
public String getExpressionFileName() {
353+
public String getExpressionFile() {
354354
return expressionsText.getText();
355355
}
356356

357-
public String getGMTFileName() {
357+
public String getGMTFile() {
358358
return gmtText.getText();
359359
}
360+
361+
public String getClassFile() {
362+
return classesText.getText();
363+
}
364+
365+
public boolean hasExpressionFile() {
366+
return !isNullOrEmpty(getExpressionFile());
367+
}
368+
369+
public boolean hasGmtFile() {
370+
return !isNullOrEmpty(getGMTFile());
371+
}
372+
373+
public boolean hasClassFile() {
374+
return !isNullOrEmpty(getClassFile());
375+
}
376+
360377

361378
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/MasterDetailDialogPage.java

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.baderlab.csplugins.enrichmentmap.view.creation;
22

3-
import static com.google.common.base.Strings.isNullOrEmpty;
4-
53
import java.awt.BorderLayout;
64
import java.awt.CardLayout;
75
import java.awt.Color;
@@ -133,22 +131,20 @@ public void finish() {
133131
.collect(Collectors.toList());
134132

135133
// 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));
141137
}
142-
143138
// 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));
149147
}
150-
151-
// System.out.println(params);
152148

153149
CreateEnrichmentMapTaskFactory taskFactory = taskFactoryFactory.create(params, dataSets);
154150
TaskIterator tasks = taskFactory.createTaskIterator();
@@ -352,38 +348,38 @@ public EditCommonPanel getCommonPanel() {
352348
return commonPanel;
353349
}
354350

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+
355365
private boolean validateInput() {
356366
ErrorMessageDialog dialog = errorMessageDialogFactory.create(callback.getDialogFrame());
357367

358368
// 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");
368371
}
369-
370372
// 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");
380379
}
381380

382381
{ // 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()
387383
.map(EditDataSetPanel::getDataSetName)
388384
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
389385

0 commit comments

Comments
 (0)